File MozillaFirefox.spec of Package MozillaFirefox

#
# spec file for package MozillaFirefox
#
# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany.
#               2006-2015 Wolfgang Rosenauer
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#


%define major 52
%define mainver %major.9.0esr
%define loclver %major
%define update_channel esr

%define prefix  /usr/%{_lib}/firefox

#######################################
# definitions
%define progname firefox
%define progdir %{_prefix}/%_lib/%{progname}
%define gnome_dir     %{_prefix}
# see bsc#916196 for why we have different .desktop file names on SLE12+
%if %{suse_version} > 1200
%define desktop_file_name %{progname}
%else
%define desktop_file_name %{name}
%endif
%define firefox_appid \{ec8030f7-c20a-464f-9b0e-13a3a9e97384\}
%define _use_internal_dependency_generator 0
%define __find_requires sh %{SOURCE4}
%global provfind sh -c "grep -v '.so' | %__find_provides"
%global __find_provides %provfind

### build configuration options
%if 0%{?suse_version} > 1300
%define firefox_use_gtk3 1
#%define firefox_use_rust 1
%else
%define firefox_use_gtk3 0
%endif
%if 0%{?suse_version} > 1310
%define gstreamer_ver 1.0
%define gstreamer 1
%else
    %if 0%{?suse_version} > 1210
%define gstreamer_ver 0.10
    %endif
%endif

%define branding 1
%define localize 1
%define crashreporter 0
%ifarch %ix86 x86_64
%define no_webm_turbojpeg   0
%define no_webrtc 0
%else #ifarch ppc ppc64 s390 s390x ia64
# no YASM for non-x86 archs
%define no_webm_turbojpeg 1
%define no_webrtc 1
%endif
### build options end

#######################################
# real .spec starts here
Name:           MozillaFirefox
Version:        %{mainver}
Release:        0
%define         releasedate 20180627000000
Summary:        Mozilla Firefox Web Browser
License:        MPL-2.0
Group:          Productivity/Networking/Web/Browsers
Url:            http://www.mozilla.org/

#######################################
# packages required for building
BuildRequires:  Mesa-devel
BuildRequires:  autoconf213
BuildRequires:  dbus-1-glib-devel
BuildRequires:  fdupes
%if %{suse_version} > 1300
BuildRequires:  gcc5-c++
%else
BuildRequires:  firefox-gcc5-c++
%endif
%if %{suse_version} > 1300
BuildRequires:  libXcomposite-devel
%else
BuildRequires:  xorg-x11-devel
%endif
BuildRequires:  libcurl-devel
BuildRequires:  libgnomeui-devel
BuildRequires:  libidl-devel
BuildRequires:  libnotify-devel
BuildRequires:  memory-constraints
%if %{suse_version} > 1200
BuildRequires:  makeinfo
%else
BuildRequires:  texinfo
%endif
%if %{suse_version} > 1200
BuildRequires:  python-devel
%else
BuildRequires:  firefox-fontconfig-devel
BuildRequires:  firefox-python-base
%endif
BuildRequires:  startup-notification-devel
BuildRequires:  unzip
BuildRequires:  update-desktop-files
BuildRequires:  xorg-x11-libXt-devel
%if %{suse_version} > 1200
%else
BuildRequires:  xz
%endif

# Added libffi-devel-gcc5 buildrequires to enforce copying of the libffi.pc file to the pkgconfig/ directory
# used for non-tier-one architectures (non x86, x86_64, arm, aarch64)
%if %{suse_version} > 1300
BuildRequires:  libffi-devel-gcc5
%else
BuildRequires:  firefox-libffi-devel-gcc5
%endif

%ifarch %ix86 x86_64
BuildRequires:  yasm >= 1.0.1
%endif
BuildRequires:  zip

%if %{suse_version} > 1110
BuildRequires:  libiw-devel
BuildRequires:  libproxy-devel
%else
BuildRequires:  wireless-tools
%endif

BuildRequires:  mozilla-nspr-devel >= 4.13.1
BuildRequires:  mozilla-nss-devel >= 3.29.5
BuildRequires:  nss-shared-helper-devel
%if %{suse_version} > 1210
BuildRequires:  pkgconfig(libpulse)
%else
BuildRequires:  libpulse-devel
%endif

%if %{suse_version} > 1210
BuildRequires:  pkgconfig(gstreamer-%gstreamer_ver)
BuildRequires:  pkgconfig(gstreamer-app-%gstreamer_ver)
BuildRequires:  pkgconfig(gstreamer-plugins-base-%gstreamer_ver)
BuildRequires:  pkgconfig(libpulse)
%endif

%if 0%{?firefox_use_gtk3}
BuildRequires:  pkgconfig(glib-2.0)
BuildRequires:  pkgconfig(gobject-2.0)
BuildRequires:  pkgconfig(gtk+-3.0) >= 3.4.0
BuildRequires:  pkgconfig(gtk+-unix-print-3.0)
%endif

#######################################
# atoms needed by the package at run time
Requires:       %{name}-branding >= %{major}
%if %{suse_version} > 1210
    %if 0%{?gstreamer} == 1
Requires:       libgstreamer-1_0-0
Recommends:     gstreamer-fluendo-mp3
Recommends:     gstreamer-plugin-libav
    %else
Requires:       libgstreamer-0_10-0
Recommends:     gstreamer-0_10-fluendo-mp3
Recommends:     gstreamer-0_10-plugins-ffmpeg
    %endif
%endif

%if %{suse_version} > 1300
Requires:       libffi4 > 5
%else
Requires:       firefox-fontconfig
Requires:       firefox-libffi4
Requires:       firefox-libstdc++6
%endif
Requires:       mozilla-nspr >= %(rpm -q --queryformat '%{VERSION}' mozilla-nspr)
Requires:       mozilla-nss >= %(rpm -q --queryformat '%{VERSION}' mozilla-nss)
Requires(post):   coreutils shared-mime-info desktop-file-utils
Requires(postun): shared-mime-info desktop-file-utils

Recommends:     libcanberra0
Recommends:     libpulse0

#######################################
# obsoleted packages
# libproxy's mozjs pacrunner crashes FF (bnc#759123)
#%if %{suse_version} < 1220
#Obsoletes:      libproxy1-pacrunner-mozjs <= 0.4.7
#%endif

#######################################
# symbols provided by the package
Provides:       firefox = %{mainver}
Provides:       firefox = %{version}-%{release}
Provides:       web_browser
Provides:       browser(npapi)
# this is needed to match this package with the kde4 helper package without the
# main package having a hard requirement on the kde4 package
%define kde_helper_version 6
Provides:       mozilla-kde4-version = %{kde_helper_version}

#######################################
# package sources
Source:         firefox-%{version}-source.tar.xz
Source1:        MozillaFirefox.desktop
Source2:        MozillaFirefox-rpmlintrc
Source3:        mozilla.sh.in
Source4:        find-external-requires.sh
Source5:        source-stamp.txt
Source6:        kde.js
Source7:        l10n-%{loclver}.tar.xz
Source8:        firefox-mimeinfo.xml
Source9:        firefox.js
Source10:       compare-locales.tar.xz
Source11:       firefox.1
Source12:       mozilla-get-app-id
Source13:       spellcheck.js
Source14:       create-tar.sh
Source15:       firefox-appdata.xml
Source16:       MozillaFirefox.changes
Source20:       README.SUSE
# This should be removed when bmo#1322212 and bmo#1264836 are resolved:
# Missing ICU big-endian data file in firefox source:
Source21:       icudt58b.dat.xz

#######################################
# patches
Patch1:         toolkit-download-folder.patch
Patch2:         mozilla-nongnome-proxies.patch
Patch3:         mozilla-prefer_plugin_pref.patch
Patch4:         mozilla-shared-nss-db.patch
Patch5:         mozilla-kde.patch
Patch6:         mozilla-preferences.patch
Patch7:         mozilla-language.patch
Patch8:         mozilla-ntlm-full-path.patch
Patch9:         mozilla-arm-disable-edsp.patch
Patch10:        mozilla-openaes-decl.patch
Patch11:        mozilla-bmo1005535.patch
Patch12:        mozilla-sle11.patch
Patch13:        mozilla-no-stdcxx-check.patch
Patch14:        mozilla-libproxy-compat.patch
Patch15:        mozilla-reduce-files-per-UnifiedBindings.patch
Patch16:        mozilla-s390-nojit.patch

Patch101:       firefox-kde.patch
Patch102:       firefox-no-default-ualocale.patch
Patch103:       firefox-branded-icons.patch

# SLE patches
Patch202:       mozilla-aarch64-startup-crash.patch
Patch203:       mozilla-break_hanging_glxtest.patch
Patch204:       firefox-glibc-getrandom.patch
Patch205:       mozilla-aarch64_getrandom.patch
# This should be removed when bmo#1322212 and bmo#1264836 are resolved:
Patch206:       mozilla-s390-bigendian.patch

#######################################
# buildsystem settings
BuildRoot:      %{_tmppath}/%{name}-%{version}-build

%description
Mozilla Firefox ESR is a standalone web browser, designed for
standards compliance and performance.  Its functionality can
be enhanced via a plethora of extensions.

#######################################
# subpackages
%package devel
Summary:        Devel package for Firefox
Group:          Development/Tools/Other
Provides:       firefox-devel = %{version}-%{release}
Requires:       %{name} = %{version}
Requires:       perl(Archive::Zip)
Requires:       perl(XML::Simple)

%description devel
Development files for Firefox to make packaging of addons easier.

%if %{localize}

%package translations
Summary:        Translations for Firefox
Group:          System/Localization
Provides:       locale(%{name}:ach;af;an;ar;as;ast;az;be;bg;bn-BD;bn-IN;br;bs;ca;cs;cy;da;de;dsb;el;en-GB;en-ZA;eo;es-AR;es-CL;es-ES;es-MX;et;eu;fa;ff;fi;fr;fy-NL;ga-IE;gd;gl;gn;gu-IN;he;hi-IN;hr;hsb;hu;hy-AM;id;is;it;ja;ja-JP-mac;kk;km;kn;ko;lij;lt;lv;mai);
Requires:       %{name} = %{version}
Obsoletes:      %{name}-translations-common <= %{version}-%{release}
Obsoletes:      %{name}-translations-other  <= %{version}-%{release}

%description translations
This package contains various languages for the user interface of Firefox.

%endif

# this package does not need to provide files but is needed to fulfill
# requirements if no other branding package is to be installed
%package branding-upstream
Summary:        Upstream branding for MozillaFirefox
Group:          Productivity/Networking/Web/Browsers
Provides:       %{name}-branding = %{version}
Conflicts:      otherproviders(%{name}-branding)
Supplements:    packageand(%{name}:branding-upstream)
#BRAND: Provide three files -
#BRAND: /usr/lib/firefox/browserconfig.properties that contains the
#BRAND: default homepage and some other default configuration options
#BRAND: /usr/lib/firefox/defaults/profile/bookmarks.html that contains
#BRAND: the list of default bookmarks
#BRAND: It's also possible to create a file
#BRAND: /usr/lib/firefox/defaults/preferences/firefox-$vendor.js to set
#BRAND: custom preference overrides.
#BRAND: It's also possible to drop files in /usr/lib/firefox/searchplugins

%description branding-upstream
This package provides upstream look and feel for MozillaFirefox.


%if %{crashreporter}

%package buildsymbols
Summary:        Breakpad buildsymbols for %{name}
Group:          Development/Debug

%description buildsymbols
This subpackage contains the Breakpad created and compatible debugging
symbols meant for upload to Mozilla's crash collector database.

%endif

#######################################
%prep
%if %{localize}
%setup -q -n mozilla -b 7 -b 10
%else
%setup -q -n mozilla
%endif
cp %{S:15} %{S:20} .
cd $RPM_BUILD_DIR/mozilla
%patch1 -p1
%patch2 -p1
%patch3 -p1
%patch4 -p1
%patch5 -p1
%patch6 -p1
%patch7 -p1
%patch8 -p1
%patch9 -p1
%patch10 -p1
%patch11 -p1
%if %{suse_version} < 1120
%patch12 -p1
%endif
%patch13 -p1
%patch14 -p1
%patch15 -p1
%patch16 -p1
%patch101 -p1
%patch102 -p1
%patch103 -p1

## SLE patches
%patch202 -p1
%patch203 -p1
%patch204 -p1
%patch205 -p1

# This should be removed when bmo#1322212 and bmo#1264836 are resolved:
%ifarch s390x
%patch206 -p1
%endif

%if %{suse_version} < 1200
%patch208 -p1
%patch209 -p1
%endif

cp -v %{SOURCE15} .

# This should be removed when bmo#1322212 and bmo#1264836 are resolved:
xz -dk %{SOURCE21}
DATFILE=%{SOURCE21}
DATFILE="${DATFILE%.xz}"
mv -v ${DATFILE} ./config/external/icu/data/

#######################################
%build
%ifarch x86_64
# x86_64 has often problems of too many concurrent jobs
# it seems 1.epsilon GB per build job is enough
%limit_build -m 1100
%endif
export CC=gcc-5
export CXX=g++-5
%if %{suse_version} < 1200
# link against comapt packages first
export LDFLAGS="-L%{prefix}/%{_lib}"
export LD_LIBRARY_PATH=%{prefix}/%{_lib}:$LD_LIBRARY_PATH
export PKG_CONFIG_PATH=%{prefix}/%{_lib}/pkgconfig:$PKG_CONFIG_PATH
export PATH=%{prefix}/bin:$PATH
#?? # fix linking against libxul that links to anything not directly in /usr/lib
#?? sed -r '/^MOZ_FIX_LINK_PATHS=/s@(/bin)( -Wl,-rpath-link,)@\1\2%{prefix}/%{_lib}\2@' -i configure.in
%endif

# no need to add build time to binaries
modified="$(sed -n '/^----/n;s/ - .*$//;p;q' "%{_sourcedir}/%{name}.changes")"
DATE="\"$(date -d "${modified}" "+%%b %%e %%Y")\""
TIME="\"$(date -d "${modified}" "+%%R")\""
find . -regex ".*\.c\|.*\.cpp\|.*\.h" -exec sed -i "s/__DATE__/${DATE}/g;s/__TIME__/${TIME}/g" {} +

kdehelperversion=$(cat toolkit/xre/nsKDEUtils.cpp | grep '#define KMOZILLAHELPER_VERSION' | cut -d ' ' -f 3)
if test "$kdehelperversion" != %{kde_helper_version}; then
  echo fix kde helper version in the .spec file
  exit 1
fi

# set build environment
source %{SOURCE5}
export MOZ_SOURCE_STAMP=$REV
export SOURCE_REPO=$REPO
export source_repo=$REPO
export MOZ_SOURCE_REPO=$REPO
export MOZ_BUILD_DATE=%{releasedate}
export MOZILLA_OFFICIAL=1
export BUILD_OFFICIAL=1
export MOZ_TELEMETRY_REPORTING=0
export CFLAGS="$RPM_OPT_FLAGS -Os -fno-strict-aliasing"
export CFLAGS=${CFLAGS/-fstack-clash-protection/}

%ifarch %arm
    export CFLAGS="${CFLAGS/-g / }"
%endif

%if %{suse_version} < 1200
%ifarch %arm ppc ppc64 ppc64le s390 %ix86
# Limit RAM usage during link
    export LDFLAGS="${LDFLAGS} -Wl,--no-keep-memory -Wl,--reduce-memory-overheads"
%endif
%ifarch ia64
# Limit RAM usage during link - Itanium ld doesn't make it with --no-keep-memory
    export LDFLAGS="${LDFLAGS} -Wl,--reduce-memory-overheads"
%endif
%endif

%ifarch ppc64 ppc64le
    export CFLAGS="$CFLAGS -mminimal-toc"
%endif

export CXXFLAGS="$CFLAGS"

%ifarch %arm ia64 ppc ppc64 ppc64le s390 %ix86
    # Limit RAM usage during link on anything else than x86_64
    export LDFLAGS="${LDFLAGS} -Wl,--no-keep-memory -Wl,--reduce-memory-overheads"
%endif

export MOZCONFIG=$RPM_BUILD_DIR/mozconfig
cat << EOF > $MOZCONFIG
mk_add_options MOZILLA_OFFICIAL=1
mk_add_options BUILD_OFFICIAL=1
mk_add_options MOZ_MAKE_FLAGS=%{?jobs:-j%jobs}
mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/../obj
. \$topsrcdir/browser/config/mozconfig
ac_add_options --prefix=%{_prefix}
ac_add_options --libdir=%{_libdir}
#ac_add_options --sysconfdir=%{_sysconfdir}
#ac_add_options --mandir=%{_mandir}
ac_add_options --includedir=%{_includedir}
ac_add_options --enable-release
%if 0%{?firefox_use_gtk3}
ac_add_options --enable-default-toolkit=cairo-gtk3
%else
ac_add_options --enable-default-toolkit=cairo-gtk2
%endif
ac_add_options --disable-stdcxx-compat
%ifarch ppc ppc64 ppc64le
ac_add_options --enable-optimize="-g -O2"
%endif
%ifnarch ppc ppc64 ppc64le aarch64
    ac_add_options --enable-elf-hack
%endif
ac_add_options --with-system-nspr
ac_add_options --with-system-nss
%if %{localize}
    ac_add_options --with-l10n-base=$RPM_BUILD_DIR/l10n
%endif
#ac_add_options --with-system-jpeg    # libjpeg-turbo is used internally
#ac_add_options --with-system-png     # doesn't work because of missing APNG support
ac_add_options --with-system-zlib
#ac_add_options --disable-installer
ac_add_options --disable-updater
ac_add_options --disable-tests
ac_add_options --disable-debug
ac_add_options --enable-startup-notification
#ac_add_options --enable-chrome-format=jar
ac_add_options --enable-update-channel=%{update_channel}

%if 0%{?gstreamer} == 1
#    ac_add_options --enable-gstreamer=1.0
%endif

%ifarch s390x
    # jemalloc is currently broken on S390
    ac_add_options --disable-jemalloc
%endif

# Disable neon for arm as it does not build correctly
%ifarch %arm
    ac_add_options --disable-neon
%endif

# try to use OpenGL-ES on ARM
#%ifarch %arm aarch64
#    ac_add_options --with-gl-provider=EGL
#%endif

%if %{no_webm_turbojpeg}
    # WebM and turbo libjpeg optimizations require x86 architecture
    #ac_add_options --disable-webm
    #ac_add_options --disable-libjpeg-turbo
%endif

%if %{no_webrtc}
    ac_add_options --disable-webrtc
%endif

# dependencies not available on older code streams
%if %{suse_version} > 1130
#    ac_add_options --disable-gnomevfs
    ac_add_options --enable-gio
%endif

%if %{suse_version} < 1220
    ac_add_options --disable-gstreamer
%endif

%if %{suse_version} > 1110
    ac_add_options --enable-libproxy
%endif

# generic package configuration
%if %{branding}
    ac_add_options --enable-official-branding
%endif

%if ! %{crashreporter}
    ac_add_options --disable-crashreporter
%endif

EOF

make -f client.mk build

%install
%if %{suse_version} < 1200
export LD_LIBRARY_PATH=%{prefix}/%_lib:$LD_LIBRARY_PATH
export PKG_CONFIG_PATH=%{prefix}/%_lib/pkgconfig:$PKG_CONFIG_PATH
export PATH=%{prefix}/bin:$PATH
%endif
cd $RPM_BUILD_DIR/obj
source %{SOURCE5}
export MOZ_SOURCE_STAMP=$REV
export MOZ_SOURCE_REPO=$REPO
make -C browser/installer STRIP=/bin/true MOZ_PKG_FATAL_WARNINGS=0
#DEBUG (break the build if searchplugins are missing / temporary)
grep amazondotcom dist/firefox/browser/omni.ja
# copy tree into RPM_BUILD_ROOT
mkdir -p %{buildroot}%{progdir}
cp -rf $RPM_BUILD_DIR/obj/dist/firefox/* %{buildroot}%{progdir}
mkdir -p %{buildroot}%{progdir}/distribution/extensions
mkdir -p %{buildroot}%{progdir}/browser/searchplugins
mkdir -p %{buildroot}%{progdir}/browser/defaults/preferences/
# install gre prefs
install -m 644 %{SOURCE13} %{buildroot}%{progdir}/defaults/pref/
# install browser prefs
%if %{suse_version} >= 1110
# install kde.js
install -m 644 %{SOURCE6} %{buildroot}%{progdir}/browser/defaults/preferences/kde.js
install -m 644 %{SOURCE9} %{buildroot}%{progdir}/browser/defaults/preferences/firefox.js
%endif
# install additional locales

%if %{localize}
rm -f %{_tmppath}/translations
touch %{_tmppath}/translations

sed -r '/^(ja-JP-mac|en-US)$/d;s/ .*$//' ../mozilla/browser/locales/shipped-locales \
    | xargs -P 8 -n 1 -I {} /bin/sh -c '
    locale=$1
#    case $locale in
#        ja-JP-mac|en-US)
#            ;;
#        *)
            pushd $RPM_BUILD_DIR/compare-locales
            PYTHONPATH=lib \
%if %{suse_version} < 1200
                %{prefix}/bin/python \
%endif
                scripts/compare-locales -m ../l10n-merged/$locale \
                ../mozilla/browser/locales/l10n.ini ../l10n $locale
            popd
            LOCALE_MERGEDIR=$RPM_BUILD_DIR/l10n-merged/$locale \
                make -C browser/locales langpack-$locale
            # TODO: temporary workaround for bsc#909563                                                                                              
            # - remove empty lines at the beginning of install.rdf                                                                                   
            sed -r -n  "/^<\?xml.*$/,$p" -i dist/xpi-stage/locale-$locale/install.rdf                                                               
            cp -rL dist/xpi-stage/locale-$locale \
                %{buildroot}%{progdir}/browser/extensions/langpack-$locale@firefox.mozilla.org
            # remove prefs, profile defaults, and hyphenation from langpack
            rm -rf %{buildroot}%{progdir}/browser/extensions/langpack-$locale@firefox.mozilla.org/defaults
            rm -rf %{buildroot}%{progdir}/browser/extensions/langpack-$locale@firefox.mozilla.org/hyphenation
            # check against the fixed common list and sort into the right filelist
            _matched=0
            echo %{progdir}/browser/extensions/langpack-$locale@firefox.mozilla.org \
                >> %{_tmppath}/translations
#            ;;
#  esac
' -- {}
%endif

# remove some executable permissions
find %{buildroot}%{progdir} \
     -name "*.js" -o \
     -name "*.jsm" -o \
     -name "*.rdf" -o \
     -name "*.properties" -o \
     -name "*.dtd" -o \
     -name "*.txt" -o \
     -name "*.xml" -o \
     -name "*.css" | xargs chmod a-x
# remove mkdir.done files from installed base
find %{buildroot}%{progdir} -name ".mkdir.done" | xargs rm -vf
# overwrite the mozilla start-script and link it to /usr/bin
mkdir --parents %{buildroot}/usr/bin
sed "s:%%PREFIX:%{_prefix}:g
s:%%PROGDIR:%{progdir}:g
s:%%APPNAME:firefox:g
s:%%PROFILE:.mozilla/firefox:g" \
    %{SOURCE3} > %{buildroot}%{progdir}/%{progname}.sh
chmod 755 %{buildroot}%{progdir}/%{progname}.sh
ln -sf ../..%{progdir}/%{progname}.sh %{buildroot}%{_bindir}/%{progname}
# desktop file
mkdir -p %{buildroot}%{_datadir}/applications
install -m 644 %{SOURCE1} \
    %{buildroot}%{_datadir}/applications/%{desktop_file_name}.desktop
# additional mime-types
mkdir -p %{buildroot}%{_datadir}/mime/packages
cp %{SOURCE8} %{buildroot}%{_datadir}/mime/packages/%{progname}.xml
# install man-page
mkdir -p %{buildroot}%{_mandir}/man1/
cp %{SOURCE11} %{buildroot}%{_mandir}/man1/%{progname}.1
##########
# ADDONS
#
mkdir -p %{buildroot}%{_datadir}/mozilla/extensions/%{firefox_appid}
mkdir -p %{buildroot}%{_libdir}/mozilla/extensions/%{firefox_appid}
mkdir -p %{buildroot}/usr/share/pixmaps/
ln -sf %{progdir}/browser/icons/mozicon128.png %{buildroot}/usr/share/pixmaps/%{progname}.png
ln -sf %{progdir}/browser/icons/mozicon128.png %{buildroot}/usr/share/pixmaps/%{progname}-gnome.png

%if %{branding}
    for size in 16 22 24 32 48 256; do
%else
    for size in 16 32 48; do
%endif
    mkdir -p %{buildroot}%{gnome_dir}/share/icons/hicolor/${size}x${size}/apps/
    ln -sf %{progdir}/browser/chrome/icons/default/default$size.png \
         %{buildroot}%{gnome_dir}/share/icons/hicolor/${size}x${size}/apps/%{progname}.png
done
%suse_update_desktop_file %{desktop_file_name} Network WebBrowser GTK
# excludes
rm -f %{buildroot}%{progdir}/updater.ini
rm -f %{buildroot}%{progdir}/removed-files
rm -f %{buildroot}%{progdir}/README.txt
rm -f %{buildroot}%{progdir}/old-homepage-default.properties
rm -f %{buildroot}%{progdir}/run-mozilla.sh
rm -f %{buildroot}%{progdir}/LICENSE
rm -f %{buildroot}%{progdir}/precomplete
rm -f %{buildroot}%{progdir}/dictionaries/en-US*
rm -f %{buildroot}%{progdir}/update-settings.ini
# devel
mkdir -p %{buildroot}%{_bindir}
install -m 755 %SOURCE12 %{buildroot}%{_bindir}
# inspired by mandriva
mkdir -p %{buildroot}/etc/rpm
cat <<'FIN' >%{buildroot}/etc/rpm/macros.%{progname}
# Macros from %{name} package
%%firefox_major              %{major}
%%firefox_version            %{version}
%%firefox_mainver            %{mainver}
%%firefox_mozillapath        %%{_libdir}/%{progname}
%%firefox_pluginsdir         %%{_libdir}/browser-plugins
%%firefox_appid              \{ec8030f7-c20a-464f-9b0e-13a3a9e97384\}
%%firefox_extdir             %%(if [ "%%_target_cpu" = "noarch" ]; then echo %%{_datadir}/mozilla/extensions/%%{firefox_appid}; else echo %%{_libdir}/mozilla/extensions/%%{firefox_appid}; fi)

%%firefox_ext_install() \
    extdir="%%{buildroot}%%{firefox_extdir}/`mozilla-get-app-id '%%1'`" \
    mkdir -p "$extdir" \
    %%{__unzip} -q -d "$extdir" "%%1" \
    %%{nil}
FIN
# just dumping an xpi file there doesn't work...
#%%firefox_ext_install() \
#       extdir="%%{buildroot}%%{firefox_extdir}" \
#       mkdir -p "$extdir" \
#       cp "%%1" "$extdir" \
#       %%{nil}
# fdupes
%fdupes %{buildroot}%{progdir}
%fdupes %{buildroot}%{_datadir}

# create breakpad debugsymbols
%if %crashreporter
SYMBOLS_NAME="firefox-%{version}-%{release}.%{_arch}-%{suse_version}-symbols"
make buildsymbols \
  SYMBOL_INDEX_NAME="$SYMBOLS_NAME.txt" \
  SYMBOL_FULL_ARCHIVE_BASENAME="$SYMBOLS_NAME-full" \
  SYMBOL_ARCHIVE_BASENAME="$SYMBOLS_NAME"
if [ -e dist/*symbols.zip ]; then
  mkdir -p %{buildroot}%{_datadir}/mozilla/
  cp dist/*symbols.zip %{buildroot}%{_datadir}/mozilla/
fi
%endif

%clean
rm -rf %{buildroot}
%if %{localize}
rm -rf %{_tmppath}/translations.*
%endif

%post
# update mime and desktop database
%if %{suse_version} > 1130
%mime_database_post
%desktop_database_post
%icon_theme_cache_post
%else
if [ -f usr/bin/update-mime-database ] ; then
    usr/bin/update-mime-database %{_datadir}/mime > /dev/null || :
fi
if [ -f usr/bin/update-desktop-database ] ; then
    usr/bin/update-desktop-database > /dev/null || :
fi
%endif
exit 0

%postun
%if %{suse_version} > 1130
%icon_theme_cache_postun
%desktop_database_postun
%mime_database_postun
%else
if [ -f usr/bin/update-mime-database ] ; then
    usr/bin/update-mime-database %{_datadir}/mime > /dev/null || :
fi
if [ -f usr/bin/update-desktop-database ] ; then
    usr/bin/update-desktop-database > /dev/null || :
fi
%endif
exit 0

%posttrans

%preun

%files
%defattr(-,root,root)
%doc README.SUSE
%dir %{progdir}
%dir %{progdir}/browser/
%dir %{progdir}/browser/chrome/
%dir %{progdir}/browser/extensions/
%{progdir}/browser/defaults
%{progdir}/browser/features/
%{progdir}/browser/icons/
%{progdir}/browser/chrome/icons
%{progdir}/browser/extensions/{972ce4c6-7e08-4474-a285-3208198ce6fd}.xpi
%{progdir}/browser/blocklist.xml
%{progdir}/browser/chrome.manifest
%{progdir}/browser/omni.ja
%dir %{progdir}/distribution/
%{progdir}/distribution/extensions/
%{progdir}/defaults/
%{progdir}/dictionaries/
%if 0%{?firefox_use_gtk3}
%dir %{progdir}/gtk2
%{progdir}/gtk2/libmozgtk.so
%endif
%{progdir}/gmp-clearkey/
%attr(755,root,root) %{progdir}/%{progname}.sh
%{progdir}/firefox
%{progdir}/firefox-bin
%{progdir}/application.ini
%{progdir}/chrome.manifest
%{progdir}/dependentlibs.list
%{progdir}/icudt58*.dat
%{progdir}/*.so
%{progdir}/omni.ja
%{progdir}/fonts/
%{progdir}/platform.ini
%{progdir}/plugin-container
%if %{crashreporter}
%{progdir}/crashreporter
%{progdir}/crashreporter.ini
%{progdir}/Throbber-small.gif
%{progdir}/minidump-analyzer
%{progdir}/browser/crashreporter-override.ini
%endif
%{_datadir}/applications/%{desktop_file_name}.desktop
%{_datadir}/mime/packages/%{progname}.xml
%{_datadir}/pixmaps/firefox*
%dir %{_datadir}/mozilla
%dir %{_datadir}/mozilla/extensions
%dir %{_datadir}/mozilla/extensions/%{firefox_appid}
%dir %{_libdir}/mozilla
%dir %{_libdir}/mozilla/extensions
%dir %{_libdir}/mozilla/extensions/%{firefox_appid}
%{gnome_dir}/share/icons/hicolor/
%{_bindir}/%{progname}
%doc %{_mandir}/man1/%{progname}.1.gz

%files devel
%defattr(-,root,root)
%{_bindir}/mozilla-get-app-id
%config %{_sysconfdir}/rpm/macros.%{progname}

%if %{localize}

%files translations -f %{_tmppath}/translations
%defattr(-,root,root)
%dir %{progdir}
%dir %{progdir}/browser/extensions/

%endif

# this package does not need to provide files but is needed to fulfill
# requirements if no other branding package is to be installed
%files branding-upstream
%defattr(-,root,root)
%dir %{progdir}

#%if %{crashreporter}
#
#%files buildsymbols
#%defattr(-,root,root)
#%{_datadir}/mozilla/*.zip
#%endif

%changelog
openSUSE Build Service is sponsored by