Blob Blame History Raw
### Naming ###
# Set to true if it's going to be submitted as update
%global release_build 1

# Set new source-code build version
# This tag indicates a new rebuild for Fedora
%global redhat_ver rh1

# Exclude ARM for the following error:
#  terminate called after throwing an instance of 'std::bad_alloc'
#   what():  std::bad_alloc
#   error: could not compile `gkrust`
ExcludeArch: %{arm}

# Build is failing because of
# include/mozilla/FloatingPoint.h:212:31: error: inlining failed in call to ‘always_inline’ ‘bool mozilla::IsNegativeZero(T) [with T = double]’: indirect function call with a yet undetermined callee
%if 0%{?fedora}
ExcludeArch: s390x


### Optimization ###
# Builds for debugging
%global debug_build   0

# Downgrade optimization
%global less_optbuild 0

# Use mozilla hardening option?
%global hardened_build 1

# Build PGO+LTO on x86_64 and aarch64 only due to build issues
# on other arches.
%ifarch x86_64
%if 0%{?release_build}
%global build_with_pgo 0
%global pgo_wayland    0
%global build_with_pgo 0

%global launch_wayland_compositor 0
%if 0%{?build_with_pgo}
%global launch_wayland_compositor 1

# Disable LTO to work around rhbz#1883904
%define _lto_cflags %{nil}

# Active/Deactive language files handling
%global build_langpacks 1

# Define installation directories
%global icecatappdir %{_libdir}/%{name}
%global icecat_ver   %{name}-%{version}
%global icecat_devel %{name}-devel-%{version}

# Define language files directory
%global langpackdir  %{icecatappdir}/langpacks

%global toolkit_gtk3  1

# Big endian platforms
%ifarch ppc64 s390x
# Javascript Intl API is not supported on big endian platforms right now:
%global big_endian    1

%if 0%{?fedora}
%global system_nss  1
%global system_nss  0
%if %{?system_nss}
%global nspr_version 4.32
%global nspr_build_version %{nspr_version}
%global nss_version 3.88
%global nss_build_version %{nss_version}

# Audio backends
%bcond_without pulseaudio
%bcond_with alsa

%global with_vpx 1
%if %{?with_vpx}
%global libvpx_version 1.8.2

%global disable_elfhack 1

# cbingen
%global use_bundled_cbindgen 1

# Use clang?
%global build_with_clang  0

%global __provides_exclude_from ^%{icecatappdir}
%global __requires_exclude_from ^%{icecatappdir}

Name:    icecat
Epoch:   2
Version: 115.5.0
Release: %autorelease -e %{redhat_ver}
Summary: GNU version of Firefox browser

# Tri-licensing scheme for Gnuzilla/IceCat in parentheses, and licenses for the extensions included
License: (MPL-1.1 or GPL-2.0-or-later or LGPL-2.1-or-later) and GPL-3.0-or-later and MIT and BSD and ISC and Apache-2.0 and MPL-2.0

## Source archive created by scripts based on Gnuzilla files.
## Modified files are hosted in a dedicated fork repository:
Source0: %{name}-%{version}-%{redhat_ver}.tar.bz2

Source2: %{name}.png
Source3: %{name}-mozconfig-common

# Language files downloaded by source7 script
%if 0%{?build_langpacks}
Source4:  %{name}-%{version}-langpacks.tar.gz

# All license files
# Download from
# Download from
# Download from
Source5: %{name}-COPYING-licensefiles.tar.gz

Source7: %{name}

# Desktop files
Source9:  %{name}-wayland.desktop
Source10: %{name}.appdata.xml
Source12: %{name}
Source13: %{name}
Source14: %{name}.desktop
Source15: %{name}
Source16: %{name}-x11.desktop

# cbingen
Source17: cbindgen-vendor.tar.xz
Source18: node-stdout-nonblocking-wrapper

Source19: run-wayland-compositor

# Build patches
# Fixes installation of those addons which don't have ID on IceCat ("Cannot find id for addon" error).
Patch1: %{name}-fix_addon_installation.patch
Patch2: %{name}-commasplit.patch
Patch5: rhbz-1219542-s390-build.patch

# With clang LLVM 16 rust-bindgen 0.56.0 is too old, combined
Patch7:  rust-bindgen-2319-2339.patch

# Needed with rust 1.70
Patch8:  mp4parse-rust-8b5b652d38e007e736bb442ccd5aa5ed699db100.patch 

Patch40: build-aarch64-skia.patch
Patch41: build-disable-elfhack.patch
Patch44: build-arm-libopus.patch
Patch54: mozilla-1669639.patch

# Fedora specific patches
Patch219: rhbz-1173156.patch
Patch220: firefox-nss-version.patch
Patch221: firefox-nss-addon-hack.patch
Patch223: %{name}-glibc-dynstack.patch
Patch224: %{name}-GLIBCXX-fix-for-GCC-12.patch

# ARM run-time patch
Patch226: rhbz-1354671.patch

# Upstream patches
Patch401: icecat-1742849.patch
Patch402: mozilla-1196777.patch
Patch403: icecat-python3.11-open-U.patch
Patch404: icecat-python3.11-regex-inline-flags.patch
Patch412: mozilla-1337988.patch
Patch422: mozilla-1580174-webrtc-popup.patch

# Fix crash on ppc64le (mozilla#1512162)
Patch423: mozilla-1512162.patch

# PGO/LTO patches
Patch600: %{name}-pgo.patch
Patch602: mozilla-1516803.patch

BuildRequires: alsa-lib-devel
BuildRequires: autoconf213
BuildRequires: bzip2-devel
BuildRequires: cairo-devel
BuildRequires: cargo
%if !0%{?use_bundled_cbindgen}
BuildRequires: cbindgen	
BuildRequires: ccache
BuildRequires: dbus-devel
BuildRequires: dbus-glib-devel
BuildRequires: dbus-x11
BuildRequires: dconf
BuildRequires: desktop-file-utils
BuildRequires: dos2unix
BuildRequires: gcc, gcc-c++
BuildRequires: make
BuildRequires: freetype-devel
BuildRequires: gdk-pixbuf2
BuildRequires: glib2-devel
BuildRequires: pkgconfig(gtk+-2.0)
%if 0%{?toolkit_gtk3}
BuildRequires: pkgconfig(gtk+-3.0)
BuildRequires: gstreamer1-devel
BuildRequires: gstreamer1-plugins-base-devel
BuildRequires: hunspell-devel
BuildRequires: ImageMagick, autotrace
BuildRequires: intltool
BuildRequires: libappstream-glib
BuildRequires: libavcodec-free-devel
BuildRequires: libevent-devel
BuildRequires: libjpeg-turbo-devel
BuildRequires: libjpeg-devel
BuildRequires: libX11-devel
BuildRequires: libXt-devel
BuildRequires: libXrender-devel
BuildRequires: libyuv-devel
BuildRequires: libXinerama-devel
BuildRequires: libffi-devel
BuildRequires: libnotify-devel
BuildRequires: libpng-devel
%if %{?with_vpx}
BuildRequires: libvpx-devel >= %{libvpx_version}
BuildRequires: libzip-devel
BuildRequires: mesa-libGL-devel
BuildRequires: nodejs
BuildRequires: nasm >= 1.13
BuildRequires: strace

%if %{?system_nss}
BuildRequires: pkgconfig(nspr) >= %{nspr_version}
BuildRequires: pkgconfig(nss) >= %{nss_version}
BuildRequires: nss-static >= %{nss_version}

BuildRequires: pango-devel
BuildRequires: pipewire-devel
BuildRequires: python3-devel
BuildRequires: python3-setuptools
BuildRequires: python3.11-devel
BuildRequires: perl-interpreter
BuildRequires: pkgconfig(xrender)
BuildRequires: pkgconfig(libstartup-notification-1.0)
BuildRequires: pkgconfig(dri)
BuildRequires: pkgconfig(libcurl)
%if %{with pulseaudio}
BuildRequires: pulseaudio-libs-devel
BuildRequires: yasm
BuildRequires: llvm
BuildRequires: llvm-devel
BuildRequires: clang
BuildRequires: clang-libs
BuildRequires: clang-devel
%if 0%{?build_with_clang}
BuildRequires: lld
BuildRequires: rust
%if 0%{?pgo_wayland}
BuildRequires:  mutter
BuildRequires:  gsettings-desktop-schemas
BuildRequires:  gnome-settings-daemon
BuildRequires:  mesa-dri-drivers
BuildRequires:  xorg-x11-server-Xwayland
%if 0%{?build_with_pgo}
BuildRequires:  xorg-x11-server-Xvfb

%if 0%{?big_endian}
BuildRequires: icu

Requires: dconf
Requires: mozilla-filesystem
Requires: p11-kit-trust

%if %{?system_nss}
Requires: nspr >= %{nspr_build_version}
Requires: nss >= %{nss_build_version}

%if 0%{?fedora}
BuildRequires: fedora-bookmarks
Requires: fedora-bookmarks

Suggests: mozilla-ublock-origin
Provides: webclient

GNU IceCat is the GNU version of the Firefox ESR browser.
Extensions included to this version of IceCat:

 * LibreJS
   GNU LibreJS aims to address the JavaScript problem described in the article
   "The JavaScript Trap" of Richard Stallman.

 * HTTPS Everywhere
   HTTPS Everywhere is an extension that encrypts your communications with
   many major websites, making your browsing more secure.

 * A set of companion extensions for LibreJS by Nathan Nichols
   are pre-installed, and provide workarounds to use some services at USPS,,,, McDonalds, and Google Docs
   without using nonfree JavaScript.

 * A series of configuration changes and tweaks were applied to ensure that
   IceCat does not initiate network connections that the user has not explicitly
   requested. This implies not downloading feeds, updates, blacklists or any
   other similar data needed during startup.

%package x11
Summary: GNU IceCat X11 launcher
Requires: %{name}%{?_isa}
%description x11
The %{name}-x11 package contains launcher and desktop file
to run GNU IceCat native on X11.

%package wayland
Summary: GNU IceCat Wayland launcher
Requires: %{name}%{?_isa}
Obsoletes: %{name} < 0:78.6.1-1
%description wayland
The icecat-wayland package contains launcher and desktop file
to run GNU IceCat native on Wayland.

%autosetup -N -n %{name}-%{version}

# Copy license files
tar -xf %{SOURCE5}

%patch -P 1 -p 1 -b .fix_addon_installation
%patch -P 2 -p 1 -b .commasplit
%ifarch s390
%patch -P 5 -p 1 -b .rhbz-1219542-s390

%if 0%{?disable_elfhack}
%patch -P 41 -p 1 -b .disable-elfhack

# Fedora patches
%patch -P 219 -p 1 -b .rhbz-1173156
%if 0%{?fedora}
%patch -P 221 -p 1 -b .firefox-nss-addon-hack
%patch -P 224 -p 1 -b .glibcxx

# ARM run-time patch
%ifarch aarch64
%patch -P 40 -p 1 -b .aarch64-skia
%patch -P 226 -p 1 -b .1354671

%ifarch %{arm}
%patch -P 44  -p 1 -b .build-arm-libopus

%patch -P 402 -p 1 -b .1196777
%ifarch %{power64}
%patch -P 423 -p 1 -b .1512162

%patch -P 54 -p 1 -b .1669639

# PGO patches
%if 0%{?build_with_pgo}
%if !%{build_with_clang}
%patch -P 600 -p 1 -b .pgo
%patch -P 602 -p 1 -b .1516803

# Remove default configuration and copy the customized one
rm -f .mozconfig
cp -p %{SOURCE3} .mozconfig

# Disable signature checking for extensions that are bundled with IceCat.
# Add these options to allow loading unsigned add-ons in app and system scopes.
echo "ac_add_options --with-unsigned-addon-scopes=app,system" >> .mozconfig
echo "ac_add_options --allow-addon-sideload" >> .mozconfig

echo "ac_add_options --enable-default-toolkit=cairo-gtk3-wayland" >> .mozconfig
echo "ac_add_options --enable-official-branding" >> .mozconfig
echo "ac_add_options --disable-webrtc" >> .mozconfig

# Hide DRM Content option
# This option does not work on other architectures
%ifarch x86_64 %{ix86}
echo "ac_add_options --disable-eme" >> .mozconfig

%if %{with pulseaudio}
echo "ac_add_options --enable-pulseaudio" >> .mozconfig

%if %{with alsa}
echo "ac_add_options --enable-alsa" >> .mozconfig

%ifarch s390x
echo "ac_add_options --disable-jemalloc" >> .mozconfig

%if %{?system_nss}
echo "ac_add_options --with-system-nspr" >> .mozconfig
echo "ac_add_options --with-system-nss" >> .mozconfig
echo 'ac_add_options BINDGEN_CFLAGS="%(pkg-config nspr pixman-1 --cflags)"' >> .mozconfig
echo "ac_add_options --without-system-nspr" >> .mozconfig
echo "ac_add_options --without-system-nss" >> .mozconfig
# Workaround for mozbz#1341234
echo "ac_add_options --allow-addon-sideload" >> .mozconfig
echo "ac_add_options --enable-system-pixman" >> .mozconfig
echo "ac_add_options --with-system-libevent" >> .mozconfig
%if %{?with_vpx}
echo "ac_add_options --with-system-libvpx" >> .mozconfig
echo "ac_add_options --without-system-libvpx" >> .mozconfig

echo "ac_add_options --with-system-jpeg" >> .mozconfig
echo "ac_add_options --enable-ffmpeg" >> .mozconfig

# This option works on these architectures only
%ifarch %{arm}
echo "ac_add_options --disable-elf-hack" >> .mozconfig
echo "ac_add_options --disable-av1" >> .mozconfig
echo 'export NEON_FLAGS=-mfpu=vfpv3-d16' >> .mozconfig
%ifnarch %{arm}
echo "ac_add_options --enable-av1" >> .mozconfig

%if 0%{?debug_build}
echo "ac_add_options --enable-debug" >> .mozconfig
echo "ac_add_options --disable-optimize" >> .mozconfig
echo "ac_add_options --enable-rust-debug" >> .mozconfig
%global optimize_flags "none"
%ifarch %{arm} s390x
# ARMv7 need that (rhbz#1426850)
%define optimize_flags " -fno-schedule-insns"
%if %{?optimize_flags} != "none"
echo 'ac_add_options --enable-optimize=%{?optimize_flags}' >> .mozconfig
echo 'ac_add_options --enable-optimize' >> .mozconfig
echo "ac_add_options --disable-debug" >> .mozconfig
echo "ac_add_options --disable-strip" >> .mozconfig
echo "ac_add_options --disable-install-strip" >> .mozconfig
echo "ac_add_options --disable-tests" >> .mozconfig
echo "ac_add_options --disable-crashreporter" >> .mozconfig

# Localization
%if 0%{?build_langpacks}
echo "ac_add_options --with-l10n-base=$PWD/l10n" >> .mozconfig

# Clang
echo "ac_add_options --with-libclang-path=%{_libdir}" >> .mozconfig

%ifarch s390x
echo "ac_add_options --disable-jit" >> .mozconfig

%if 0%{?build_with_pgo}
echo "ac_add_options MOZ_PGO=1" >> .mozconfig
echo "ac_add_options --enable-lto" >> .mozconfig
echo "ac_add_options --disable-lto" >> .mozconfig

echo 'export NODEJS="%{_buildrootdir}/bin/node-stdout-nonblocking-wrapper"' >> .mozconfig

# Remove executable bit to make brp-mangle-shebangs happy.
chmod -x third_party/rust/itertools/src/
chmod a-x third_party/rust/ash/src/extensions/ext/*.rs
chmod a-x third_party/rust/ash/src/extensions/khr/*.rs
chmod a-x third_party/rust/ash/src/extensions/nv/*.rs

# Remove unrecognized files
find extensions/gnu -name cose.manifest -delete


# cbindgen
%if 0%{?use_bundled_cbindgen}

mkdir -p my_rust_vendor
cd my_rust_vendor
%{__tar} xf %{SOURCE17}
cd -
mkdir -p .cargo
cat > .cargo/config <<EOL
replace-with = "vendored-sources"

directory = "`pwd`/my_rust_vendor"

env CARGO_HOME=.cargo cargo install cbindgen
export PATH=`pwd`/.cargo/bin:$PATH

mkdir %{_buildrootdir}/bin || :
cp %{SOURCE18} %{_buildrootdir}/bin || :

# Update the various config.guess to upstream release for aarch64 support
find ./ -path ./third_party/rust -prune -o -name config.guess -exec cp /usr/lib/rpm/config.guess {} ';'

MOZ_OPT_FLAGS=$(echo "%{optflags}" | %{__sed} -e 's/-Wall//')
%if %{?less_optbuild}
MOZ_OPT_FLAGS=$(echo "$MOZ_OPT_FLAGS" | %{__sed} -e 's/-O2/-O1/')
%if %{?debug_build}
MOZ_OPT_FLAGS=$(echo "$MOZ_OPT_FLAGS" | %{__sed} -e 's/-O2/-O0/')

# -Werror=format-security causes build failures when -Wno-format is explicitly given
# for some sources
# Explicitly force the hardening flags for Firefox so it passes the checksec test;
# See also
# Workaround for mozbz#1531309
MOZ_OPT_FLAGS=$(echo "$MOZ_OPT_FLAGS" | %{__sed} -e 's/-Werror=format-security//')

# Use hardened build?
%if %{?hardened_build}
MOZ_OPT_FLAGS="$MOZ_OPT_FLAGS -fPIC -Wl,-z,relro -Wl,-z,now"

%ifarch s390x
MOZ_OPT_FLAGS=$(echo "$MOZ_OPT_FLAGS" | %{__sed} -e 's/-g/-g1/')
# If MOZ_DEBUG_FLAGS is empty, firefox's build will default it to "-g" which
# overrides the -g1 from line above and breaks building on s390
# (OOM when linking, rhbz#1238225)
export MOZ_DEBUG_FLAGS=" "

%ifarch %{arm} %{ix86}
MOZ_OPT_FLAGS=$(echo "$MOZ_OPT_FLAGS" | %{__sed} -e 's/-g/-g0/')
# If MOZ_DEBUG_FLAGS is empty, firefox's build will default it to "-g" which
# overrides the -g1 from line above and breaks building on s390
# (OOM when linking, rhbz#1238225)
export MOZ_DEBUG_FLAGS=" "

# We don't wantfirefox to use CK_GCM_PARAMS_V3 in nss

%if !0%{?build_with_clang}
%ifarch s390x %{power64} aarch64 %{ix86}
MOZ_LINK_FLAGS="-Wl,--no-keep-memory -Wl,--reduce-memory-overheads -Wl,--print-memory-usage"
%ifarch %{arm}
echo "ac_add_options --enable-linker=gold" >> .mozconfig
%ifarch %{arm} %{ix86} s390x
export RUSTFLAGS="-Cdebuginfo=0"

%ifarch %{arm}
# disable hard-coded LTO due to RAM constraints
sed -i '/cargo_rustc_flags += -Clto/d' config/makefiles/
sed -i '/RUSTFLAGS += -Cembed-bitcode=yes/d' config/makefiles/
sed -i 's/codegen-units=1/codegen-units=16/' config/makefiles/

# make sure "-g0" is the last flag so there's no debug info

export CXXFLAGS="$MOZ_OPT_FLAGS -fpermissive"

export PREFIX='%{_prefix}'
export LIBDIR='%{_libdir}'
export PKG_CONFIG='%{_bindir}/pkg-config'
export PYTHON='%{__python3}'

%if 0%{?build_with_clang}
export LLVM_PROFDATA="llvm-profdata"
export AR="llvm-ar"
export NM="llvm-nm"
export RANLIB="llvm-ranlib"
echo "ac_add_options --enable-linker=lld" >> .mozconfig
export CC=gcc
export CXX=g++
export AR="gcc-ar"
export NM="gcc-nm"
export RANLIB="gcc-ranlib"

%if %{?less_optbuild}
# On x86_64 architectures, Mozilla can build up to 4 jobs at once in parallel,
# however builds tend to fail on other arches when building in parallel.
%ifarch %{ix86} s390x %{arm} aarch64
[ -z "$RPM_BUILD_NCPUS" ] && \
     RPM_BUILD_NCPUS="`/usr/bin/getconf _NPROCESSORS_ONLN`"
[ "$RPM_BUILD_NCPUS" -ge 2 ] && MOZ_SMP_FLAGS=-j2
%ifarch x86_64 ppc ppc64 ppc64le
[ -z "$RPM_BUILD_NCPUS" ] && \
     RPM_BUILD_NCPUS="`/usr/bin/getconf _NPROCESSORS_ONLN`"
[ "$RPM_BUILD_NCPUS" -ge 2 ] && MOZ_SMP_FLAGS=-j2
[ "$RPM_BUILD_NCPUS" -ge 4 ] && MOZ_SMP_FLAGS=-j4
[ "$RPM_BUILD_NCPUS" -ge 8 ] && MOZ_SMP_FLAGS=-j8
[ "$RPM_BUILD_NCPUS" -ge 16 ] && MOZ_SMP_FLAGS=-j16
[ "$RPM_BUILD_NCPUS" -ge 24 ] && MOZ_SMP_FLAGS=-j24
[ "$RPM_BUILD_NCPUS" -ge 32 ] && MOZ_SMP_FLAGS=-j32
[ "$RPM_BUILD_NCPUS" -ge 64 ] && MOZ_SMP_FLAGS=-j64

echo "mk_add_options MOZ_MAKE_FLAGS=\"$MOZ_SMP_FLAGS\"" >> .mozconfig
echo "mk_add_options MOZ_SERVICES_SYNC=1" >> .mozconfig
echo "export STRIP=/bin/true" >> .mozconfig

%if 0%{?launch_wayland_compositor}
cp -p %{SOURCE19} .
. ./run-wayland-compositor	

%if %{?debug_build}

#Use python 3.11 for mach
sed -i -e 's|#!/usr/bin/env python3|#!/usr/bin/env python3.11|' mach
%if 0%{?build_with_pgo}
%if 0%{?pgo_wayland}
env | grep "WAYLAND"
MOZ_ENABLE_WAYLAND=1 ./mach build -v 2>&1 | cat - && exit 1
xvfb-run ./mach build  2>&1 | cat - || exit 1
./mach build -v 2>&1 | cat - || exit 1

# set up our default bookmarks
%if 0%{?fedora}
%global default_bookmarks_file %{_datadir}/bookmarks/default-bookmarks.html
cp -p %{default_bookmarks_file} objdir/dist/bin/browser/chrome/en-US/locale/browser/bookmarks.html

%make_install -C objdir

##Resize IceCat icon
for i in 16 22 24 32 36 48 64 72 96 128 256 ; do
  mkdir -p %{buildroot}%{_datadir}/icons/hicolor/${i}x${i}/apps
  convert -geometry ${i} %{SOURCE2} %{buildroot}%{_datadir}/icons/hicolor/${i}x${i}/apps/%{name}.png

##desktop file installation
mkdir -p %{buildroot}%{_datadir}/applications
desktop-file-install --dir %{buildroot}%{_datadir}/applications %{SOURCE14}

rm -rf %{buildroot}%{_bindir}/%{name}
%{__sed} -e 's,/__PREFIX__,%{_prefix},g' %{SOURCE13} > %{buildroot}%{_bindir}/%{name}
chmod 755 %{buildroot}%{_bindir}/%{name}

%{__sed} -e 's,/__PREFIX__,%{_prefix},g' %{SOURCE15} > %{buildroot}%{_bindir}/%{name}-x11
chmod 755 %{buildroot}%{_bindir}/%{name}-x11
desktop-file-install --dir %{buildroot}%{_datadir}/applications %{SOURCE16}

%{__sed} -e 's,/__PREFIX__,%{_prefix},g' %{SOURCE12} > %{buildroot}%{_bindir}/%{name}-wayland
chmod 755 %{buildroot}%{_bindir}/%{name}-wayland
desktop-file-install --dir %{buildroot}%{_datadir}/applications %{SOURCE9}


# Install man page
#mkdir -p %%{buildroot}%%{_mandir}/man1
#install -p -m 644 %%{name}.1 %%{buildroot}%%{_mandir}/man1/

##Extract langpacks, make any mods needed, repack the langpack, and install it.
%if 0%{?build_langpacks}
echo > %{name}.lang
mkdir -p %{buildroot}%{langpackdir}
tar xf %{SOURCE4}
 for langpack in `ls langpacks/*.xpi`; do
  language=`basename $langpack .xpi`
  mkdir -p $extensionID
  unzip -qq $langpack -d $extensionID
  find $extensionID -type f | xargs chmod 644

  cd $extensionID
  zip -qq -r9mX ../${extensionID}.xpi *
  cd -

  install -p -m 644 ${extensionID}.xpi %{buildroot}%{langpackdir}
  language=`echo $language | sed -e 's/-/_/g'`
  echo "%%lang($language) %{langpackdir}/${extensionID}.xpi" >> %{name}.lang
rm -rf %{name}-langpacks

##Install langpack workaround (see #707100, #821169)
function create_default_langpack() {
cd %{buildroot}%{langpackdir}
ln -s langpack-$ langpack-$
cd -
echo "%%lang($language_short) %{langpackdir}/langpack-$" >> %{name}.lang

# Table of fallbacks for each language
#create_default_langpack "bn-IN" "bn"
create_default_langpack "es-AR" "es"
create_default_langpack "fy-NL" "fy"
create_default_langpack "ga-IE" "ga"
create_default_langpack "gu-IN" "gu"
create_default_langpack "hi-IN" "hi"
create_default_langpack "hy-AM" "hy"
create_default_langpack "nb-NO" "nb"
create_default_langpack "nn-NO" "nn"
create_default_langpack "pa-IN" "pa"
create_default_langpack "pt-PT" "pt"
create_default_langpack "sv-SE" "sv"
create_default_langpack "zh-TW" "zh"

# Remove copied libraries to speed up build
rm -f ${RPM_BUILD_ROOT}%{_libdir}/%{icecat_devel}/sdk/lib/
rm -f ${RPM_BUILD_ROOT}%{_libdir}/%{icecat_devel}/sdk/lib/
rm -f ${RPM_BUILD_ROOT}%{_libdir}/%{icecat_devel}/sdk/lib/

# Remove useless backup files
rm -rf ${RPM_BUILD_ROOT}%{icecatappdir}/browser/extensions/

# Link identical binaries
ln -sf %{icecatappdir}/%{name}-bin ${RPM_BUILD_ROOT}%{icecatappdir}/%{name}

# Use the system hunspell dictionaries
rm -rf ${RPM_BUILD_ROOT}%{icecatappdir}/dictionaries
ln -s %{_datadir}/hunspell ${RPM_BUILD_ROOT}%{icecatappdir}/dictionaries

# Copy over
cp -p build/unix/run-%{name}.sh %{buildroot}%{icecatappdir}/

# Remove unused directories
rm -rf %{buildroot}%{_libdir}/%{icecat_devel}
rm -rf %{buildroot}%{_datadir}/idl/%{icecat_ver}
rm -rf %{buildroot}%{_includedir}/%{icecat_ver}
rm -rf %{buildroot}%{icecatappdir}/removed-files

# Remove gtk2 support as flash plugin is no longer supported
rm -rf %{buildroot}%{icecatappdir}/gtk2

mkdir -p %{buildroot}%{_metainfodir}
install -pm 644 %{SOURCE10} %{buildroot}%{_metainfodir}/

# Moves defaults/preferences to browser/defaults/preferences
%pretrans -p <lua>
require 'posix'
require 'os'
if (posix.stat("%{icecatappdir}/browser/defaults/preferences", "type") == "link") then
  if (posix.stat("%{icecatappdir}/defaults/preferences", "type") == "directory") then
    for i,filename in pairs(posix.dir("%{icecatappdir}/defaults/preferences")) do
      os.rename("%{icecatappdir}/defaults/preferences/"..filename, "%{icecatappdir}/browser/defaults/preferences/"..filename)
    f ="%{icecatappdir}/defaults/preferences/README","w")
    if f then
      f:write("Content of this directory has been moved to %{icecatappdir}/browser/defaults/preferences.")

appstream-util validate-relax --nonet %{buildroot}%{_metainfodir}/*.appdata.xml
desktop-file-validate %{buildroot}%{_datadir}/applications/*.desktop

%if 0%{?build_langpacks}
%files -f %{name}.lang
%dir %{icecatappdir}
%if 0%{?build_langpacks}
%dir %{langpackdir}

%files x11

%files wayland