summaryrefslogtreecommitdiff
path: root/PKGBUILD
blob: 7ac6001daa2e05056d5e6a03cd7e7598d9fadee4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# Maintainer: jc_gargma <jc_gargma@iserlohn-fortress.net>
# Maintainer (Arch): Jan Alexander Steffens (heftig) <heftig@archlinux.org>
# Contributor: Aqua-sama <aqua@iserlohn-fortress.net>
# Contributor (Arch): Ionut Biru <ibiru@archlinux.org>
# Contributor (Arch): Jakub Schmidtke <sjakub@gmail.com>

# # I maintain this because:
# Arch version uses eme
# Arch version uses git
# Arch version uses python2
# Arch version uses clang
# Arch version requires signed addons
# Arch version doesn't remove system addons
# Arch version enables debug symbols
# Arch version lacks privacy and security by default

_modclang=1
_modpgo=0

pkgname=firefox
pkgver=93.0
pkgrel=1
pkgdesc="Standalone web browser from mozilla.org"
arch=(x86_64 aarch64)
license=(MPL GPL LGPL)
url="https://www.mozilla.org/firefox/"
depends=(gtk3 libxt mime-types dbus-glib ffmpeg ttf-font libpulse alsa-lib
         bzip2 libffi icu libjpeg-turbo libevent libvpx nspr nss pixman libpng sqlite libwebp zlib)
makedepends=(unzip zip diffutils yasm mesa imake inetutils xorg-server-xvfb
             autoconf2.13 rust clang llvm jack nodejs cbindgen nasm
             python-setuptools python-psutil python-zstandard lld dump_syms)
optdepends=('networkmanager: Location detection via available WiFi networks'
            'libnotify: Notification integration'
            'alsa-utils: ALSA support'
            'jack: Jack support'
            'pulseaudio: PulseAudio support'
            'speech-dispatcher: Text-to-Speech'
            'hunspell-en_CA: Spell checking, Canadian English'
            'xdg-desktop-portal: Screensharing with Wayland'
            'firefox-preferences: Custom vendor.js with security by default'
            'firefox-preferences-basic: Custom vendor.js with less breaking changes')
options=(!emptydirs !makeflags)
conflicts=(firefox-esr)
source=(
        "https://archive.mozilla.org/pub/$pkgname/releases/$pkgver/source/$pkgname-$pkgver.source.tar.xz"{,.asc}
        0001-Use-remoting-name-for-GDK-application-names.patch
        $pkgname.desktop
        identity-icons-brand.svg
        distribution.ini
        mozconfig.in.gcc
        mozconfig.in.clang
        mozconfig.common.override
        arc4_enable-lto-for-gcc.patch
        firefox-gcc-build.patch
        arc4_enable-pgo-for-gcc.patch
        pgo.patch
        arc4_remove-health-reporting.patch
        arc4_remove-system-addons.patch
        )
b2sums=('f4315a81ea5709fbf622ea39a4b259e44e8bafad95468d3f41fa8413dd1d5d92e260f549aacafe8b6af04f0c036fb9d59fe8531f0e2fa8de5dffcc403b33f2e1'
        'SKIP'
        'cfd09442eb344fb80b2233da86a101082926b9942849d988d0e43cac4cb6c15690dc8eae42514e114260b712c206cacd81f773e401cf8f861ee4b805fb872643'
        'e18f2c22e394ca3b6758bc130245b254947e4d15921be3da443d6d7c3c4b0d22ead1b39fbc10a4f896edd19e2a1dffbd1cbb34dc4beb0621a6ddb70ccc53b3a7'
        '63a8dd9d8910f9efb353bed452d8b4b2a2da435857ccee083fc0c557f8c4c1339ca593b463db320f70387a1b63f1a79e709e9d12c69520993e26d85a3d742e34'
        '877eda442eb4730600dccf209a6e961ad3122ab456bbfda4ff041e8493ebaaf96224ac218360931259ff4214482f6bf65b3a3052f977ade1a274f38ffd859535'
        'b75aa686d66fe5fe1aec0c40878183e5a367b429daddc697d9c30183ee4666d8f72bb753f5cdb4c2fd167a288358e99a8eeb7ca78149625462902180d751ab65'
        '46db9cd9c902370b174bd919d8aff4f4e37b03b4d9f91ba251eaa651abce5ad2c04f5a86d2950601c61653ef37fe84d04ad205a42f9a38211c7640c0b122717c'
        '1c7ac58af8b817067c7d79ffef8d9100f513d77f4fc1a2bce2684ff8d8d3cbc3d37b31865c7e5d873fd71d4649374bbd25ca08166d8afb25ffbd597759655063'
        '3b76cfb76a3e527d4c77d61a127606aef0b46826d7a0f7866164e0b490098714cc11429002fc35ac32b75ffbc61f76596a5e984aea37f8876bcd939030bcfa21'
        '69624493c96e98caecf5286ed77946f104feff9b61679bcc842f6d989a2b4b28acce47324f805925f55170935a37a0bc10c596b82b41391f9f8ef342c09a3d0e'
        '1250b2d4a713b241d9768dc386ecf9130d295587efd5070c2e494185436ca9d99a465b97ed80fe23ab14d6d07ecde8537a3a3d11ba843c4e3791b4df52e08f27'
        '87dd810443be6acf41dad2cbdf8b14ba6ae68d55364e80560e96200e1acb866858068234088bae261c26e65e171b49d4f530ee4098f41e5c8cf855d1f2fe0e12'
        '1dce1277c0c8b83089551057ed61c8794aa65242d0c19573dab96081f00b1042af73fbc0a40ba49dfa31eff46f4636ffd985cf8e6bd28db614a639ca6c11c74e'
        '379adf3726664668f6167eaeab35dec40342d9288ff081d22a8363f163ab0945b17ce69e7d4276a31e99e56f690afa070c410c51a5060ed835356fd216256e7b')
validpgpkeys=('14F26682D0916CDD81E37B6D61B7B526D98F0353')  # Mozilla Software Releases

prepare() {
  mkdir mozbuild
  cd ${pkgname}-${pkgver}

  # https://bugzilla.mozilla.org/show_bug.cgi?id=1530052
  patch -Np1 -i ../0001-Use-remoting-name-for-GDK-application-names.patch


  if [ "${_modclang}" == "0" ]; then
    # Apply gcc lto patches
    patch -Np1 -i ../arc4_enable-lto-for-gcc.patch
    patch -Np1 -i ../firefox-gcc-build.patch
  fi

  if [ "${_modclang}" == "0" ] && [ "${_modpgo}" == "1" ]; then
    # Apply gcc pgo patches
    patch -Np1 -i ../arc4_enable-pgo-for-gcc.patch
    patch -Np1 -i ../pgo.patch
  fi

  if [ "${_modclang}" == "1" ] && [ "${_modpgo}" == "1" ]; then
    # Add the custom mozconfig for clang pgo
    cp $srcdir/mozconfig.in.clang $srcdir/${pkgname}-${pkgver}/.mozconfig
  cat >$srcdir/${pkgname}-${pkgver}/.mozconfig - <<END
mk_add_options MOZ_OBJDIR=${PWD@Q}/obj
ac_add_options --enable-profile-generate=cross
END
  elif [ "${_modclang}" == "1" ] && [ "${_modpgo}" == "0" ]; then
    # Add the custom mozconfig for clang
    cp $srcdir/mozconfig.in.clang $srcdir/${pkgname}-${pkgver}/.mozconfig
  cat >$srcdir/${pkgname}-${pkgver}/.mozconfig - <<END
mk_add_options MOZ_OBJDIR=${PWD@Q}/obj
END
  elif [ "${_modclang}" == "0" ] &&  [ "${_modpgo}" == "1" ]; then
    # Add the custom mozconfig for gcc pgo
    cp $srcdir/mozconfig.in.gcc $srcdir/${pkgname}-${pkgver}/.mozconfig
  cat >$srcdir/${pkgname}-${pkgver}/.mozconfig - <<END
mk_add_options MOZ_OBJDIR=${PWD@Q}/obj
ac_add_options --enable-profile-generate=cross
END
  else
    # Add the custom mozconfig for gcc
    cp $srcdir/mozconfig.in.gcc $srcdir/${pkgname}-${pkgver}/.mozconfig
  fi

  # MOZ_TELEMETRY_REPORTING only applied correctly when set in this override file
  cp $srcdir/mozconfig.common.override $srcdir/${pkgname}-${pkgver}/build/mozconfig.common.override


  # Disable various components at the source level
  sed -i 's|[;]1|;0|' $srcdir/${pkgname}-${pkgver}/toolkit/components/telemetry/TelemetryStartup.manifest
  sed -i 's/;1/;0/' $srcdir/${pkgname}-${pkgver}/toolkit/components/telemetry/components.conf

  # Patch out health reporting so that MOZ_DATA_REPORTING=0 can be applied.
  patch -Np1 -i ../arc4_remove-health-reporting.patch

  # Remove @RESPATH@/browser/features/* to prevent system addons from being part of the output package.
  patch -Np1 -i ../arc4_remove-system-addons.patch


  # Hide mobile promo
#  echo ".fxaMobilePromo {  display: none !important; }" >> browser/themes/shared/incontentprefs/preferences.inc.css
  # Hide plugindeprecation-notice
  echo "#plugindeprecation-notice {  display: none !important; }" >> toolkit/mozapps/extensions/content/extensions.css
  # Hide warnings on unsigned extensions
  echo ".warning{display: none!important; } .addon[notification=warning]{background-image: none!important;}" >> toolkit/mozapps/extensions/content/extensions.css
}

build() {
  cd ${pkgname}-${pkgver}

  export MOZ_NOSPAM=1
  export MOZBUILD_STATE_PATH="$srcdir/mozbuild"
  export MACH_USE_SYSTEM_PYTHON=1

  # firefox is prone to OOM, use 1 thread per 2GB ram
  #export MOZ_MAKE_FLAGS="${MAKEFLAGS}"
  export MOZ_MAKE_FLAGS="-j16"

  # -flto breaks cargo
  # -fPIE and -pie break compiling
  export CFLAGS="$CFLAGS -O3 -fstack-protector-all -fPIC"
  export CXXFLAGS="$CXXFLAGS -O3 -fstack-protector-all -fPIC"

  # LTO needs more open files
  ulimit -n 4096


  if [ "${_modclang}" == "1" ] && [ "${_modclangpgo}" == "1" ]; then
  # clang does not support -fstack-clash-protection, so remove it
  #export CFLAGS="$(echo $CFLAGS | sed 's/ -fstack-clash-protection//' - )"
  #export CXXFLAGS="$(echo $CXXFLAGS | sed 's/ -fstack-clash-protection//' - )"

  # Do 3-tier PGO
  echo "Building instrumented browser..."
  ./mach build

  echo "Profiling instrumented browser..."
  ./mach package
  LLVM_PROFDATA=llvm-profdata \
    JARLOG_FILE="$PWD/jarlog" \
    xvfb-run -s "-screen 0 1920x1080x24 -nolisten local" \
    ./mach python build/pgo/profileserver.py

  stat -c "Profile data found (%s bytes)" merged.profdata
  test -s merged.profdata

  stat -c "Jar log found (%s bytes)" jarlog
  test -s jarlog

  echo "Removing instrumented browser..."
  ./mach clobber

  echo "Building optimized browser..."
  # Add the custom mozconfig
  cp $srcdir/mozconfig.in.clang $srcdir/${pkgname}-${pkgver}/.mozconfig
  cat >$srcdir/${pkgname}-${pkgver}/.mozconfig - <<END
mk_add_options MOZ_OBJDIR=${PWD@Q}/obj
ac_add_options --enable-lto=cross
ac_add_options --enable-profile-use=cross
ac_add_options --with-pgo-profile-path=${PWD@Q}/merged.profdata
ac_add_options --with-pgo-jarlog=${PWD@Q}/jarlog
END
  ./mach build

  elif [ "${_modclang}" == "0" ] &&  [ "${_modpgo}" == "1" ]; then

  # Do 3-tier PGO
  echo "Building instrumented browser..."
  ./mach build

  echo "Profiling instrumented browser..."
  ./mach package
  LLVM_PROFDATA=llvm-profdata \
    JARLOG_FILE="$PWD/jarlog" \
    xvfb-run -s "-screen 0 1920x1080x24 -nolisten local" \
    ./mach python build/pgo/profileserver.py

  stat -c "Profile data found (%s bytes)" merged.profdata
  test -s merged.profdata

  stat -c "Jar log found (%s bytes)" jarlog
  test -s jarlog

  echo "Removing instrumented browser..."
  ./mach clobber

  echo "Building optimized browser..."
  # Add the custom mozconfig
  cp $srcdir/mozconfig.in.gcc $srcdir/${pkgname}-${pkgver}/.mozconfig
  cat >.mozconfig - <<END
mk_add_options MOZ_OBJDIR=${PWD@Q}/obj
ac_add_options --with-pgo-profile-path=${PWD@Q}/merged.profdata
ac_add_options --with-pgo-jarlog=${PWD@Q}/jarlog
ac_add_options --enable-lto=cross
ac_add_options --enable-profile-use=cross
END
  ./mach build

  else
    echo "Building optimized browser..."
    xvfb-run -s "-screen 0 1920x1080x24 -nolisten local" ./mach build
  fi
}

package() {
  cd ${pkgname}-${pkgver}
  DESTDIR="$pkgdir" ./mach install

  # Don't install in /usr/local
  rm -rf "$pkgdir/usr/local/bin"
  mkdir "$pkgdir/usr/lib"
  mkdir "$pkgdir/usr/bin"
  cp -r --reflink "$pkgdir/usr/local/lib/firefox" "$pkgdir/usr/lib/firefox"
  rm -rf "$pkgdir/usr/local/lib/firefox"

  install -Dm644 $srcdir/distribution.ini \
  "$pkgdir/usr/lib/$pkgname/distribution/distribution.ini"

  # use a symlink in /usr/bin instead
  ln -sf "/usr/lib/$pkgname/firefox" "$pkgdir/usr/bin/firefox"


  # icons
  local i theme=official
  for i in 16 22 24 32 48 64 128 256; do
    install -Dvm644 browser/branding/$theme/default$i.png \
      "$pkgdir/usr/share/icons/hicolor/${i}x${i}/apps/$pkgname.png"
  done
  install -Dvm644 browser/branding/$theme/content/about-logo.png \
    "$pkgdir/usr/share/icons/hicolor/192x192/apps/$pkgname.png"
  install -Dvm644 browser/branding/$theme/content/about-logo@2x.png \
    "$pkgdir/usr/share/icons/hicolor/384x384/apps/$pkgname.png"
  install -Dvm644 browser/branding/$theme/content/about-logo.svg \
    "$pkgdir/usr/share/icons/hicolor/scalable/apps/$pkgname.svg"
  install -Dvm644 ../identity-icons-brand.svg \
    "$pkgdir/usr/share/icons/hicolor/symbolic/apps/$pkgname-symbolic.svg"

  # install desktop file
  install -Dvm644 ../$pkgname.desktop \
    "$pkgdir/usr/share/applications/$pkgname.desktop"

   # Use system certificates
  local nssckbi="$pkgdir/usr/lib/$pkgname/libnssckbi.so"
  if [[ -e $nssckbi ]]; then
    ln -srfv "$pkgdir/usr/lib/libnssckbi.so" "$nssckbi"
  fi
}