File palemoon.spec of Package palemoon

#
# spec file for package palemoon
#
# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany.
#
# 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/
#


Name:           palemoon
Version:        28.8.4
Release:        0

%define unofficial 1
%define lversion 28.9.0
%define _locale_ver %{lversion}_RC1
%define _locale %(zcat %{_sourcedir}/pale-moon-localization-%{_locale_ver}.tar.gz | sed -n '/set\ LOCALES/s/.*\=//p')
%define _locale_dir pale-moon-localization-%{_locale_ver}
%define _localeprov %(echo %_locale | tr ' ' ';')
# filtering provides and requires
%define _use_internal_dependency_generator 0
%define __find_provides sh %{SOURCE98}
%define __find_requires sh %{SOURCE99}
#
# define version of package
%define version_number() %(\\
rpm -q --whatprovides %1 --qf '%%{VERSION}' \\
| awk 'match($0,/[0-9]+\.?[.0-9]+?[0-9]?/,a){print a[0]; exit}' \\
| awk 'BEGIN{FS="."}{print $1 * 1000000 + $2 * 1000 + $3}'\\
)
#
# use gold linker
%bcond_with gold
#
# build with clang
%bcond_without clang
%define gcc_version %{version_number gcc}
%if 0%{?gcc_version} < 9000000
%bcond_without gcc9
%endif
%if 0%{?suse_version} >= 1500
%bcond_without gcc7
%endif
#
# use browser prefs
%define prefs 1
#
# unofficial build
%if 0%{?unofficial}
## use system libs
### version of package
%define icu_ver %{version_number libicu-devel}
%define sqlite_ver %{version_number sqlite3-devel}
%define vpx_ver %{version_number libvpx-devel}
%if 0%{?icu_ver} >= 58002000
%bcond_without system_icu
%endif
%if 0%{?sqlite_ver} < 3029000 || 0%{?suse_version} < 1550
%bcond_without system_sqlite
%endif
%if 0%{?vpx_ver} < 1005000
%bcond_without system_libvpx
%endif
%bcond_without system_hunspell
%bcond_without system_libevent
%bcond_without system_nss
%bcond_without system_nspr
###
%bcond_with system_bz2
%bcond_with system_cairo
%bcond_with system_ffi
%bcond_with system_pixman
%bcond_with system_zlib
%endif
#

Summary:        Goanna-based, efficient and easy to use web browser
License:        MPL-2.0 and GPL-2.0 and LGPL-2.1
Group:          Productivity/Networking/Web/Browsers
Url:            http://www.palemoon.org/
Source0:        https://github.com/MoonchildProductions/UXP/archive/PM%{version}_Release/UXP-PM%{version}_Release.tar.gz
Source1:        https://github.com/JustOff/pale-moon-localization/archive/%{_locale_ver}/pale-moon-localization-%{_locale_ver}.tar.gz
Source11:       palemoon.in
Source12:       palemoon.desktop
Source13:       palemoon-mimeinfo.xml
Source14:       spellcheck.js
Source15:       default-prefs.js
Source16:       distribution.ini.in
Source98:       find-internal-provides.sh
Source99:       find-external-requires.sh
# PATCH-FIX-OPENSUSE -- Remove spaces from path
Patch0:         palemoon_ini.patch
# PATCH-FIX-OPENSUSE -- Change default preferences
Patch1:         palemoon_profile.patch
# PATCH-FIX-UPSTREAM -- Don't use gconf for proxy settings
Patch2:         palemoon_nongnome-proxies.patch
#
ExclusiveArch:  %ix86 x86_64
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
BuildRequires:  autoconf213
BuildRequires:  fdupes
BuildRequires:  gcc-c++
BuildRequires:  hicolor-icon-theme
BuildRequires:  pkgconfig
BuildRequires:  unzip
BuildRequires:  update-desktop-files
BuildRequires:  yasm
BuildRequires:  zip
BuildRequires:  pkgconfig(alsa)
BuildRequires:  pkgconfig(bzip2)
BuildRequires:  pkgconfig(cairo)
BuildRequires:  pkgconfig(dbus-glib-1)
BuildRequires:  pkgconfig(gl)
#BuildRequires:  pkgconfig(gstreamer-1.0)
#BuildRequires:  pkgconfig(gstreamer-app-1.0)
#BuildRequires:  pkgconfig(gstreamer-plugins-base-1.0)
BuildRequires:  pkgconfig(gtk+-2.0)
BuildRequires:  pkgconfig(hunspell)
BuildRequires:  pkgconfig(icu-io)
BuildRequires:  pkgconfig(libIDL-2.0)
BuildRequires:  pkgconfig(libevent)
BuildRequires:  pkgconfig(libffi)
BuildRequires:  pkgconfig(libnotify)
BuildRequires:  pkgconfig(libpulse)
BuildRequires:  pkgconfig(libstartup-notification-1.0)
#BuildRequires:  pkgconfig(libwebp)
BuildRequires:  pkgconfig(vpx)
BuildRequires:  pkgconfig(nspr)
BuildRequires:  pkgconfig(nss)
BuildRequires:  pkgconfig(pixman-1)
BuildRequires:  pkgconfig(python)
BuildRequires:  pkgconfig(sqlite3)
BuildRequires:  pkgconfig(xext)
BuildRequires:  pkgconfig(xt)
BuildRequires:  pkgconfig(zlib)
BuildRequires:  python-xml
#
%{!?with_gold:BuildRequires:  binutils-gold}
%{!?with_clang:BuildRequires:  clang}
%{!?with_clang:BuildRequires:  libc++.so}
%{!?with_gcc7:BuildRequires:  gcc7-c++}
#
Requires:       mozilla-nspr >= %(rpm -q --queryformat '%%{VERSION}' mozilla-nspr)
Requires:       mozilla-nss >= %(rpm -q --queryformat '%%{VERSION}' mozilla-nss)
#
Requires(post): desktop-file-utils
Requires(post): shared-mime-info
Requires(postun): desktop-file-utils
Requires(postun): shared-mime-info
#Recommends:     gstreamer-plugins-bad
#Recommends:     gstreamer-plugins-good
#Recommends:     gstreamer-plugins-libav
#Recommends:     gstreamer-plugins-ugly
#
%py_requires

%description
Pale Moon offers you a browsing experience in a browser completely built
from its own, independently developed source that has been forked off from
Firefox/Mozilla code, with carefully selected features and optimizations to
improve the browser's speed*, resource use, stability and user experience,
while offering full customization and a growing collection of extensions
and themes to make the browser truly your own.

%{expand:%(\
for lang in %{_locale}; do \
echo "%%{expand:%%(cat << EOF >&1

%package -n     %{name}-trans-$lang
Summary:        Translation for package %{name}
Group:          System/Localization
Provides:       locale(%{name}:$lang)
Requires:       %{name} = %{version}

%description -n %{name}-trans-$lang
This package contains translation for the user interface of %{name}.

%files -n %{name}-trans-$lang -f $lang.lang
%defattr(-,root,root)
EOF)}"; \
done)}

%prep
%setup -q -n UXP-PM%{version}_Release -b1
%patch0
%patch1
%patch2

# create .desktop file
#for _file in %{SOURCE3}; do
#  sed -e 's|@NAME@|NewMoon|g' \
#      -e 's|@EXEC@|%{pkgname}|g' \
#      -e 's|@ICON@|%{pkgname}|g' \
#      < $_file > %{pkgname}.desktop
#done
#
# set plugindir default
sed -e 's|%{_libdir}/mozilla/plugins|%{_libdir}/browser-plugins|g' \
    -i $(grep -wrl '%{_libdir}/mozilla/plugins')
#
# don't compile in DATE and TIME
BUILDDATE=$(LC_ALL=C date -ur %{_sourcedir}/%{name}.changes +'%b %d %Y')
BUILDTIME=$(LC_ALL=C date -ur %{_sourcedir}/%{name}.changes +'%H:%M')
sed -e "s/__DATE__/\"$BUILDDATE\"/g" \
    -e "s/__TIME__/\"$BUILDTIME\"/g" \
    -i $(grep -rl '__DATE__\|__TIME__')
#
#
# openSUSE info
%if 0%{?is_opensuse}
DISTRIBUTION=openSUSE
%else
DISTRIBUTION=SLE
%endif
VERSION=%{suse_version}
BUILDTIME="$BUILDDATE $BUILDTIME"
sed -e "s/@DISTRIBUTION@/$DISTRIBUTION/" \
    -e "s/@VERSION@/$VERSION/" \
    -e "s/@BUILDTIME@/$BUILDTIME/" \
    < %{S:16} > distribution.ini
#
# use RPM_OPT_FLAGS
sed -e '/^OS_CFLAGS/s/$/\ \$\(NSS_OPT_FLAGS\)/' \
    -i $(find -iname linux.mk | xargs grep -l '^OS_CFLAGS.*=')

sed -e '/^AM_CFLAGS.=/s/$/\ \$\(FFI_OPT_FLAGS\)/' \
    -i $(grep -rl 'JC1FLAGS' js)
#

%build
%{!?with_clang:export CC=clang}
%{!?with_clang:export CXX=clang++}
%{!?with_gcc7:export CC=gcc-7}
%{!?with_gcc7:export CXX=g++-7}
export MOZILLA_OFFICIAL=1
CFLAGS="$(echo %{optflags} | sed 's/\ \-\<g\>//;s/\ -fstack-clash-protection//')"
%ifarch %ix86
CFLAGS="$CFLAGS -msse2 -mfpmath=sse"
export PM_OPT_FLAGS="-O2 -msse2 -mfpmath=sse"
%else
export PM_OPT_FLAGS="-O2"
%endif
# Add -Wno-address -- https://github.com/MoonchildProductions/Pale-Moon/issues/1581
# Add -Wno-error=format-overflow -- https://forum.palemoon.org/viewtopic.php?t=21745
export CFLAGS="$CFLAGS %{!?with_gcc:-Wno-address} %{!?with_gcc9:-Wno-format-overflow} -fno-strict-aliasing -fstack-protector"
export CXXFLAGS="$CFLAGS -std=gnu++11 %{!?with_clang:-stdlib=libc++}"
export LDFLAGS="%{!?with_clang:-lc++abi} %{!?with_gold:-fuse-ld=gold} -Wl,--as-needed -Wl,-z,now"
export NSS_OPT_FLAGS="$CFLAGS"
export FFI_OPT_FLAGS="$CFLAGS"
#export MC_OFFICIAL=0
#export MC_PALEMOON=0
#export MOZILLA_OFFICIAL=0
#export BUILD_OFFICIAL=0
export MOZ_TELEMETRY_REPORTING=0
export MOZCONFIG=$PWD/mozconfig
cat << EOF > $MOZCONFIG
# base options
# (similar to official build):
mk_add_options MOZILLA_OFFICIAL=1
mk_add_options MOZ_CO_PROJECT=%{name}
mk_add_options MOZ_MAKE_FLAGS=%{?_smp_mflags}
mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/../pmbuild
ac_add_options --prefix=%{_prefix}
ac_add_options --libdir=%{_libdir}
#ac_add_options --enable-official-branding
ac_add_options --enable-application=%{name}
ac_add_options --enable-default-toolkit=cairo-gtk2
ac_add_options --enable-ffmpeg
%{!?with_gold:  ac_add_options --enable-gold}
ac_add_options --enable-jemalloc
#ac_add_options --enable-jemalloc-lib
ac_add_options --enable-optimize="$PM_OPT_FLAGS"
ac_add_options --enable-pie
#ac_add_options --enable-shared-js
#ac_add_options --enable-gstreamer
ac_add_options --enable-startup-notification
ac_add_options --enable-strip
#disable
ac_add_options --disable-debug
ac_add_options --disable-debug-symbols
ac_add_options --disable-gconf
#ac_add_options --disable-installer
#ac_add_options --disable-official-branding
#ac_add_options --disable-parental-controls
ac_add_options --disable-tests
ac_add_options --disable-updater
#ac_add_options --disable-mochitests
ac_add_options --with-pthreads
ac_add_options --x-libraries=%{_libdir}
## additional options
ac_add_options --enable-alsa
ac_add_options --disable-accessibility
ac_add_options --disable-eme
ac_add_options --disable-elf-hack
ac_add_options --disable-gamepad
ac_add_options --disable-necko-wifi
ac_add_options --disable-webrtc
#
# unofficial build
%if 0%{?unofficial}
#with
%{!?with_system_bz2:        ac_add_options --with-system-bz2}
%{!?with_system_icu:        ac_add_options --with-system-icu}
%{!?with_system_libevent:   ac_add_options --with-system-libevent}
%{!?with_system_libvpx:     ac_add_options --with-system-libvpx}
%{!?with_system_nspr:       ac_add_options --with-system-nspr}
%{!?with_system_nss:        ac_add_options --with-system-nss}
%{!?with_system_zlib:       ac_add_options --with-system-zlib}
#enable
%{!?with_system_cairo:      ac_add_options --enable-system-cairo}
%{!?with_system_ffi:        ac_add_options --enable-system-ffi}
%{!?with_system_hunspell:   ac_add_options --enable-system-hunspell}
%{!?with_system_pixman:     ac_add_options --enable-system-pixman}
%{!?with_system_sqlite:     ac_add_options --enable-system-sqlite}
%endif
#
EOF

make -f client.mk \
        STRIP="/bin/true" \
        clobber

make -f client.mk \
        STRIP="/bin/true" \
        build

%install
%{!?with_gcc7:export CC=gcc-7}
%{!?with_gcc7:export CXX=g++-7}
# see: config/baseconfig.mk
make -f client.mk \
        DESTDIR=%{buildroot} \
        idldir=%{_datadir}/idl/%{name} \
        includedir=%{_includedir}/%{name} \
        installdir=%{_libdir}/%{name} \
        sdkdir=%{_libdir}/%{name}-devel \
        STRIP="/bin/true" \
        install

rm -rf  %{buildroot}%{_datadir}/idl/%{name} \
        %{buildroot}%{_includedir}/%{name} \
        %{buildroot}%{_libdir}/%{name}-devel
#
# startup script
pushd %{buildroot}
app_launcher() {
    rm -f .%{_libdir}/%{name}/%{name}
    install -Dm0755 %{SOURCE11} .%{_libdir}/%{name}/%{name}
    ln -sf ../%{_lib}/%{name}/%{name} .%{_bindir}/%{name}
}
if [ -L .%{_bindir}/%{name} ]; then
    find -name "%{name}*" \
    | xargs file | grep ELF | grep exec | cut -f 1 -d : | while read bin; do
        if $(echo $bin | grep -q %{name}-bin); then
            app_launcher
        elif ! ls .%{_libdir}/%{name}/%{name}-bin &> /dev/null; then
            install -Dm0755 $bin .%{_libdir}/%{name}/%{name}-bin
            app_launcher
        fi
    done
fi
## set LD_LIBRARY_PATH
#pushd .%{_libdir}/%{pkgname}
#libs=$(find ./*/ -name \*.so \
#      | xargs dirname \
#      | uniq \
#      | sed 's/^\./\$HERE/' \
#      | tr '\n' ':')
#if [ -n "$libs" ]; then
#  sed -i "/LD_LIBRARY_PATH/s|\"\(.*\)\"|\"$libs\1\"|" %{pkgname}
#fi
popd
#
# install gre prefs
install -Dm0644 \
%{SOURCE14} %{buildroot}%{_libdir}/%{name}/defaults/pref/spellcheck.js
#
# install browser prefs
%if 0%{?prefs}
install -Dm0644 \
%{SOURCE15} %{buildroot}/%{_libdir}/%{name}/browser/defaults/preferences/%{name}.js
%endif
#
# openSUSE bookmarks, homepage and info
install -Dm0644 {,%{buildroot}%{_libdir}/%{name}/distribution/}distribution.ini
# additional mime-types
install -Dm0644 \
%{SOURCE13} %{buildroot}%{_datadir}/mime/packages/%{name}.xml
#
# install icon files
pushd application/palemoon/branding/official
for size in 16 32 48 128 256; do
    find -name \*$size.png | while read icon; do
        size=$(echo $icon | sed 's/[^0-9]//g')
        install -Dm0644 \
        $icon %{buildroot}%{_datadir}/icons/hicolor/${size}x${size}/apps/%{name}.png
        if $(echo $size | grep -q 128); then
            install -Dm0644 \
            $icon %{buildroot}%{_datadir}/pixmaps/%{name}.png
        fi
    done
done
popd
#
# install .desktop files
%suse_update_desktop_file -i %{name}
#
%fdupes -s %{buildroot}%{_libdir}
%fdupes -s %{buildroot}%{_datadir}

# get a list of files
# $2 - dirlist
# $3 - dir of filelist
# $4 - excludelist
filelist() {
  filelist=$PWD/$1
  pushd %{buildroot}
    find ./ | while read list; do
      if [ -n "$4" ]; then
        ! echo $list | grep "$4" || continue
      fi
      _file=$(echo $list | sed 's/[^/]//')
      _dir=$(dirname $_file)
      if echo $_dir | grep "$2"; then
        grep -xqs "\%dir\ $_dir" $filelist || echo "%dir $_dir" >> $filelist
      fi
      if echo $_file | grep "$3"; then
        [ -d "$list" ] || echo $_file >> $filelist
      fi
    done
  popd
}

#filelist file.lst %{name} usr langpack
#
# install langs
perl -p -i -e 's|\r\n|\n|' ../*/pack.cmd
find ../*/ -type f -iname '.*' -exec rm -f {} \;
for lang in %{_locale}; do
  #find ../*/$lang \( -name brand.properties -o -name brand.dtd \) \
  #  -exec sed -i '/brand/s/Pale\ Moon/New Moon/' {} \;
  find ../*/$lang -depth -name AB-CD -type d | while read _dir; do
    mv ${_dir%/*}/{${_dir##*/},$lang}
  done
  cp -rL \
    ../*/$lang \
    %{buildroot}%{_libdir}/%{name}/browser/extensions/langpack-$lang@palemoon.org
  filelist $lang.lang langpack.$lang langpack.$lang
done
#

%pre
if [ "$1" -eq 1 ] ; then
    grep ^flags /proc/cpuinfo | grep -qs sse2
    if [ $? -ne 0 ]; then
        echo "This computer cannot run %{name} because its hardware is no longer \
        supported." 1>&2; exit 1
    fi
fi

%post
%mime_database_post
%icon_theme_cache_post
%desktop_database_post

%postun
%mime_database_postun
%icon_theme_cache_postun
%desktop_database_postun

%files
%defattr(-,root,root)
%doc AUTHORS LICENSE README.md
%{_bindir}/%{name}
%{_libdir}/%{name}/
# exclude lang packs
%exclude %{_libdir}/%{name}/browser/extensions/langpack*
%{_datadir}/applications/%{name}.desktop
%{_datadir}/icons/hicolor/*/apps/%{name}.png
%{_datadir}/pixmaps/%{name}.png
%{_datadir}/mime/packages/%{name}.xml

%changelog
openSUSE Build Service is sponsored by