summaryrefslogtreecommitdiff
path: root/libre/iceweasel/PKGBUILD
blob: ddd0471586fd80a3cbb584a181a651ff7adb3b63 (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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
# Maintainer (arch): Jan Alexander Steffens (heftig) <jan.steffens@gmail.com>
# Contributor (arch): Ionut Biru <ibiru@archlinux.org>
# Contributor (arch): Jakub Schmidtke <sjakub@gmail.com>
# Maintainer (connochaetos): Henry Jensen <hjensen@connochaetos.org>
# Maintainer (alarm): Kevin Mihelich <kevin@archlinuxarm.org>
# Maintainer (arch32): Andreas Baumann <mail@andreasbaumann.cc>
# Contributor (arch32): Erich Eckner <git@eckner.net>
# Contributor: Andreas Grapentin <andreas@grapentin.org>
# Contributor: Luke Shumaker <lukeshu@parabola.nu>
# Contributor: André Silva <emulatorman@hyperbola.info>
# Contributor: Márcio Silva <coadde@hyperbola.info>
# Contributor: fauno <fauno@kiwwwi.com.ar>
# Contributor: vando <facundo@esdebian.org>
# Contributor: Figue <ffigue at gmail>
# Contributor: evr <evanroman at gmail>
# Contributor: Muhammad 'MJ' Jassim <UnbreakableMJ@gmail.com>
# Contributor: taro-k <taro-k@movasense_com>
# Contributor: Michał Masłowski <mtjm@mtjm.eu>
# Contributor: Luke R. <g4jc@openmailbox.org>
# Contributor: Isaac David <isacdaavid@isacdaavid.info>
# Contributor: bill-auger <bill-auger@programmer.net>
# Contributor: grizzlyuser <grizzlyuser@protonmail.com>


# Rational for inclusion in [libre]:
#  - Modify the addons pages to use GNU IceCat plugins sources, rather
#    than addons.mozilla.org, which hosts non-free addons.
#  - Disable EME, which is implemented via the non-free libWideVine
#    CDM.
#
# The above changes cause us to run afoul of the Firefox trademark
# policy[1], so making those changes also requires us to:
#  - Rebrand to Iceweasel
#
# technical:
#  - build i686 with GCC instead of clang
#  - disable rust-SIMD, LTO, PGO, and skip profiling build for armv7h and i686
# 
# privacy:
#  - Remove Google API keys and usage
#  - Disable Mozilla telemetry and crash reporting (good manners
#    because of all of the other patching we're doing)
#
# [1]: https://www.mozilla.org/en-US/foundation/trademarks/policy/


pkgname=iceweasel
replaces=('firefox')
epoch=1
pkgver=74.0.1
pkgrel=1
pkgrel+=.parabola1
_brandingver=73.0
_brandingrel=1
pkgdesc="Standalone web browser derived from Mozilla Firefox"
arch=(x86_64)
arch+=(i686 armv7h)
license=(MPL GPL LGPL)
url="https://wiki.parabola.nu/Iceweasel"
depends=(gtk3 libxt startup-notification mime-types dbus-glib ffmpeg nss
         ttf-font libpulse)
depends+=(sqlite icu)
makedepends=(unzip zip diffutils python2-setuptools yasm mesa imake inetutils
             xorg-server-xvfb autoconf2.13 rust clang llvm jack gtk2 python
             nodejs python2-psutil cbindgen nasm)
# FIXME: 'mozilla-serarchplugins' package needs re-working (see note in prepare())
makedepends+=(quilt libxslt imagemagick)
optdepends=('networkmanager: Location detection via available WiFi networks'
            'libnotify: Notification integration'
            'pulseaudio: Audio support'
            'speech-dispatcher: Text-to-Speech'
            'hunspell-en_US: Spell checking, American English')
options=(!emptydirs !makeflags !strip)
source=(https://archive.mozilla.org/pub/firefox/releases/$pkgver/source/firefox-$pkgver.source.tar.xz{,.asc}
        0001-Use-remoting-name-for-GDK-application-names.patch
        $pkgname.desktop)
source+=(https://repo.parabola.nu/other/iceweasel/${pkgname}_${_brandingver}-${_brandingrel}.branding.tar.xz{,.sig}
         libre.patch
         libre-searchengines.patch
         vendor.js.in)
source_armv7h=(arm.patch
               build-arm-libopus.patch)
source_i686=('rust-static-disable-network-test-on-static-libraries.patch'
             'avoid-libxul-OOM-python-check.patch')
sha256sums=('62e4297b682fad1ea50d8e32fc51c811169f8edec8d12d2aab0ea60b3197f011'
            'SKIP'
            '5f7ac724a5c5afd9322b1e59006f4170ea5354ca1e0e60dab08b7784c2d8463c'
            'f573d00835afe066ef1887bfea35099933ee07aeadc4c0d603972127e600cfc4'
            '091b32290e1cbb8597bd31c770f3b850d2cecc0e8ca591bb50956fde67c0a449'
            'SKIP'
            'dcc25e04627842bbd160059f1c576397d688418198a225210fae8a5ea6c32a7a'
            'd783225c311a4d64a9196d573627aeecaf02365395eea9783b1175b7613bdf6e'
            'f42b329e96cdf15d09844ca2541d096f56a5ca946f3d94d72dd10e3411fd5e85')
sha256sums_i686=('4da71f6614dce71db8e9ec2d317514aae90838c2c65620d435f0df06b45b578b'
                 '1882cd2a1689d41c3111abe45dab7215a5b292d5fff24fdde9af25af7b891a59')
sha256sums_armv7h=('bc00516032330760444939c516a60c78f868631e1b37f075f0fe71a53737b966'
                   '2d4d91f7e35d0860225084e37ec320ca6cae669f6c9c8fe7735cdbd542e3a7c9')
validpgpkeys=('14F26682D0916CDD81E37B6D61B7B526D98F0353') # Mozilla Software Releases <release@mozilla.com>
validpgpkeys+=('BFA8008A8265677063B11BF47171986E4B745536') # Andreas Grapentin

prepare() {
  mkdir mozbuild
  cd firefox-$pkgver

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

  cat >../mozconfig <<END
ac_add_options --enable-application=browser

ac_add_options --prefix=/usr
ac_add_options --enable-release
ac_add_options --enable-hardening
ac_add_options --enable-optimize
ac_add_options --enable-rust-simd
export CC='clang --target=x86_64-unknown-linux-gnu'
export CXX='clang++ --target=x86_64-unknown-linux-gnu'
export AR=llvm-ar
export NM=llvm-nm
export RANLIB=llvm-ranlib

# Branding
ac_add_options --disable-official-branding
ac_add_options --with-branding=browser/branding/iceweasel
ac_add_options --enable-update-channel=release
ac_add_options --with-distribution-id=nu.parabola
ac_add_options --with-unsigned-addon-scopes=app,system
ac_add_options --allow-addon-sideload
export MOZ_APP_REMOTINGNAME=${pkgname//-/}
export MOZ_TELEMETRY_REPORTING=
export MOZ_REQUIRE_SIGNING=

# System libraries
ac_add_options --with-system-nspr
ac_add_options --with-system-nss

# Features
ac_add_options --enable-alsa
ac_add_options --enable-jack
ac_add_options --enable-startup-notification
ac_add_options --disable-crashreporter
ac_add_options --disable-gconf
ac_add_options --disable-updater
ac_add_options --disable-tests
ac_add_options --disable-eme
END

  ## [ARCH-SPECIFIC CONFIG] ##
  case ${CARCH} in
    armv7h)
      sed -i '
        /--enable-hardening/d
        /--enable-optimize/d
        /--enable-rust-simd/d
      ' ../mozconfig

      cat >>../mozconfig <<END
export CC=clang
export CXX=clang++
ac_add_options --disable-webrtc
ac_add_options --disable-elf-hack

# https://bugzilla.redhat.com/show_bug.cgi?id=1641623
ac_add_options --disable-av1
ac_add_options --enable-optimize="-g0 -O2"
END
# mk_add_options MOZ_MAKE_FLAGS=${MAKEFLAGS} # from archlinuxarm

      # mozbuild.configure.options.InvalidOptionError: --disable-eme is not available in this configuration
      # EME is disabled anyway in the built package, but better check if it exists for ARM each new release.
      sed -i 's|ac_add_options --disable-eme||' ../mozconfig

      echo "applying arm.patch"
      patch -p1 -i ../arm.patch
      echo "applying build-arm-libopus.patch"
      patch -p1 -i ../build-arm-libopus.patch
    ;;
    i686)
      # disable LTO and use gcc toolchain (clang has issues on IA32)
      export MOZ_SOURCE_CHANGESET="DEVEDITION_${pkgver//./_}_RELEASE"
      cat >>../mozconfig <<END
ac_add_options --disable-rust-simd
ac_add_options --disable-lto
export CC=gcc
export CXX=g++
export AR=gcc-ar
export NM=gcc-nm
export RANLIB=gcc-ranlib
END

      # test failure in rust code (complaining about network functions) when PGO is used,
      # see https://bugzilla.mozilla.org/show_bug.cgi?id=1565757
      echo "applying rust-static-disable-network-test-on-static-libraries.patch"
      patch -p1 -i "$srcdir"/rust-static-disable-network-test-on-static-libraries.patch

      # readelf: Error: Unable to seek to 0x801db328 for section headers
      echo "applying avoid-libxul-OOM-python-check.patch"
      patch -p1 -i "$srcdir"/avoid-libxul-OOM-python-check.patch
    ;;
    x86_64)
    ;;
    *) echo "no [ARCH-SPECIFIC CONFIG] for arch: ${CARCH}" ; return 1 ;
    ;;
  esac


  ## branding ##

  echo "applying parabola branding"
  local brandingsrcdir="${srcdir}/${pkgname}-${_brandingver}"
  local brandingdestdir=browser/branding/${pkgname}
  rm -rf -- ${brandingdestdir}
  cp -aT -- ${brandingsrcdir}/branding ${brandingdestdir}
  # TODO: dont know what aboutlogins.svg is supposed to be or where it is presented
  #         but it seems to be essential
  cp ${brandingdestdir}/iceweasel_logo.svg ${brandingdestdir}/content/aboutlogins.svg

  # custom new tab page
  # FIXME: the newtab page (aka "Start Page") has changed significantly
  #        the new upstream start page ('activity-streams') is an add-on now
  #        it must be forked and customized externally, then copied into the browser tree
  #        see: the branding-dev-build/ dir on the '68.0' branch of the branding git repo
  #        that will also be useful for creating a replacement 'mozilla-searchplugins' package
  #        some of the branding components above and commented out below may no longer be used
  #        the following section aims to restore something similar
  #          to the previous parabola-branded "start page"
  #        once it is working well, all of these comments should be removed
  #          and any unused branding components may be deleted from the branding package
  # Put "Start Page" branding images in the source code
  #install -m644 -t browser/base/content/abouthome -- \
  #  "${brandingsrcdir}/branding"/{drm-free,gnu_headshadow,parabola-banner}.png
  #install -m644 -t browser/extensions/onboarding/content/img -- \
  #   "${brandingsrcdir}/branding/watermark.svg"

  # produce icons
  for i in 16 22 24 32 48 64 128 192 256 384; do
    rsvg-convert -w $i -h $i "${brandingsrcdir}/branding/${pkgname}_icon.svg" \
      -o "${brandingdestdir}/default$i.png"
  done

  # apply branding patches
  export QUILT_PATCHES="${brandingsrcdir}"/patches
  export QUILT_REFRESH_ARGS='-p ab --no-timestamps --no-index'
  export QUILT_DIFF_ARGS='--no-timestamps'
  quilt push -av


  ## libre patching ##

  # Remove remaining non-free bits
  echo "applying libre.patch"
  patch -Np1 -i "$srcdir/libre.patch"

  # Disable various components at the source level
  sed -i 's/;1/;0/' toolkit/components/telemetry/components.conf
  #sed -i 's/;1/;0/' browser/experiments/Experiments.manifest
  #sed -i '/pocket/d'          browser/extensions/moz.build
  #sed -i '/activity-stream/d' browser/extensions/moz.build

  # Load custom searchplugins
  # FIXME: no longer applicable - replace with (broken) replacement fo libre/mozilla-searchplugins
  #        https://git.parabola.nu/packages/iceweasel.git/tree/branding-dev-build/mozilla-searchplugins?h=68.0
#   rm -rvf -- browser/components/search/searchplugins/{*.xml,images/}
#   cp -av -- /usr/lib/mozilla/searchplugins/* browser/components/search/searchplugins/

  # Patch search-engines config
  # FIXME: custom searchplugins ID per new format above ("ddg" is standard)
  #        browser/components/search/extensions/<ID>/
#   local _remove_engines_sed='s|.*oogle.*|          "ddg", "duckduckgo-html", "duckduckgo-lite", "internet-archive", "parabola-labs", "parabola-packages", "parabola-wiki-en", "searx", "wikipedia", "yacy"|g'
  local _remove_engines_sed='s|.*oogle.*|          "ddg", "wikipedia"|g'
  local _search_config_file=browser/components/search/extensions/list.json
  echo "applying libre-searchengines.patch"
  patch -Np1 -i "$srcdir/libre-searchengines.patch"
  sed -i "${_remove_engines_sed}" ${_search_config_file}

  # Sanity-check search-engines patching
  _removed_engines_regex='Bing|Google|Seznam|Twitter|Yahoo|Yandex|Яндекс|amazon|bing|google|ebay|twitter'
  _err_msg="search-engines patch needs re-working"
  ! grep -E ${_removed_engines_regex} ${_search_config_file} > /dev/null || ! echo "${_err_msg}"
}

build() {
  cd firefox-$pkgver

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

  # LTO needs more open files
  ulimit -n 4096

  if [[ $CARCH != armv7h ]]; then
    # -fno-plt with cross-LTO causes obscure LLVM errors
    # LLVM ERROR: Function Import: link error
    CFLAGS="${CFLAGS/-fno-plt/}"
    CXXFLAGS="${CXXFLAGS/-fno-plt/}"
  fi

  if [[ $CARCH != i686 ]]; then
    # DEBUG: clang-9: error: unknown argument: '-fvar-tracking-assignments'
    CFLAGS="${CFLAGS/-fvar-tracking-assignments/}"
    CXXFLAGS="${CXXFLAGS/-fvar-tracking-assignments/}"
  fi

  ## [ARCH-SPECIFIC CONFIG] ##
  case ${CARCH} in
    armv7h)
      export MOZ_DEBUG_FLAGS=" "
      export CFLAGS+=" -g0"
      export CXXFLAGS+=" -g0"
      export LDFLAGS+=" -Wl,--no-keep-memory -Wl,--reduce-memory-overheads"
      export RUSTFLAGS="-Cdebuginfo=0"

      # skipping PGO "instrumented browser"; so we have the final .mozconfig now
      cp ../mozconfig .mozconfig
    ;;
    i686)
      # do not do profiling on i686: ..or it will for sure run out of memory - it doesn't find libraries:
      # "XPCOMGlueLoad error for file /build/firefox/src/firefox-70.0/obj-i686-pc-linux-gnu/dist/firefox/libxul.so:
      # libmozsandbox.so: cannot open shared object file: No such file or directory
      # Couldn't load XPCOM."

      # disable LTO and use gcc toolchain (clang has issues on IA32)
      export RUSTFLAGS+=" -Cdebuginfo=0 -Clto=off"
      export LDFLAGS+=" -Wl,--no-keep-memory -Wl,--reduce-memory-overheads"

      # avoid excessive debug symbols in rust leading to out-of-memory situations
      sed -i "s/debug_info = '\''2'\''/debug_info = '\''0'\''/" build/moz.configure/toolchain.configure

      # skipping PGO "instrumented browser"; so we have the final .mozconfig now
      cp ../mozconfig .mozconfig
    ;;
    x86_64)
      # Do 3-tier PGO
      echo "Building instrumented browser..."
      cat >.mozconfig ../mozconfig - <<END
ac_add_options --enable-profile-generate=cross
END
      ./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

      if [[ ! -s merged.profdata ]]; then
        echo "No profile data produced."
        return 1
      fi

      if [[ ! -s jarlog ]]; then
        echo "No jar log produced."
        return 1
      fi

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

      cat >.mozconfig ../mozconfig - <<END
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
    ;;
    *) echo "no [ARCH-SPECIFIC CONFIG] for arch: ${CARCH}" ; return 1 ;
    ;;
  esac

  # sanity checks
  # each of the [ARCH-SPECIFIC CONFIG] branches above should have created .mozconfig
  [[ ! -f .mozconfig ]] && echo ".mozconfig file not found in source root" && return 1

  echo "Building optimized browser..."
  ./mach build

  echo "Building symbol archive..."
  ./mach buildsymbols
}

package() {
  local _icu_ver
  _icu_ver=$(pacman -S --print-format='%v' icu)
  depends+=("icu>=${_icu_ver}" "icu<$((${_icu_ver%%.*} + 1))")

  cd firefox-$pkgver
  DESTDIR="$pkgdir" ./mach install

  local vendorjs="$pkgdir/usr/lib/$pkgname/browser/defaults/preferences/vendor.js"
  install -Dvm644 /dev/stdin "$vendorjs" <<END
// Use LANG environment variable to choose locale
pref("intl.locale.requested", "");

// Use system-provided dictionaries
pref("spellchecker.dictionary_path", "/usr/share/hunspell");

// Disable default browser checking.
pref("browser.shell.checkDefaultBrowser", false);

// Don't disable extensions in the application directory
pref("extensions.autoDisableScopes", 11);
END

  # Parabola additions to vendor.js
  local _shortver=$(cut -d. -f1,2 <<<"$pkgver")
  cat "${srcdir}"/vendor.js.in >> "$vendorjs"
  sed -i "s|@_SHORTVER_@|$_shortver|g" "$vendorjs"

  local distini="$pkgdir/usr/lib/$pkgname/distribution/distribution.ini"
  install -Dvm644 /dev/stdin "$distini" <<END
[Global]
id=parabola
version=1.0
about=Iceweasel for Parabola GNU/Linux-libre

[Preferences]
app.distributor=parabola
app.distributor.channel=$pkgname
app.partner.parabola=parabola
END

  local i
  for i in 16 22 24 32 48 64 128 192 256 384; do
    install -Dvm644 browser/branding/$pkgname/default$i.png \
      "$pkgdir/usr/share/icons/hicolor/${i}x${i}/apps/$pkgname.png"
  done
  install -Dvm644 "browser/branding/$pkgname/${pkgname}_icon.svg" \
    "$pkgdir/usr/share/icons/hicolor/scalable/apps/$pkgname.svg"

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

  # Install a wrapper to avoid confusion about binary path
  install -Dvm755 /dev/stdin "$pkgdir/usr/bin/$pkgname" <<END
#!/bin/sh
exec /usr/lib/$pkgname/$pkgname "\$@"
END

  ## [ARCH-SPECIFIC INSTALL] ##
  case ${CARCH} in
    armv7h)
    ;;
    i686)
      # libxul.so cannot find it's libraries
      install -dm 755 "${pkgdir}"/etc/ld.so.conf.d
      echo "/usr/lib/${pkgname}" > "${pkgdir}"/etc/ld.so.conf.d/${pkgname}.conf
    ;;
    x86_64)
    ;;
    *) echo "no [ARCH-SPECIFIC INSTALL] for arch: ${CARCH}" ; return 1 ;
    ;;
  esac

  # Replace duplicate binary with wrapper
  # https://bugzilla.mozilla.org/show_bug.cgi?id=658850
  ln -srfv "$pkgdir/usr/bin/$pkgname" "$pkgdir/usr/lib/$pkgname/$pkgname-bin"

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

# vim:set sw=2 et: