summaryrefslogtreecommitdiff
path: root/libre/icecat/PKGBUILD
blob: c128a81d86c4685a2e86f4553c6f1d3e97b3e85a (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
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
# Maintainer (Arch): Jan Alexander Steffens (heftig) <jan.steffens@gmail.com>
# Contributor (Arch): Ionut Biru <ibiru@archlinux.org>
# Contributor (Arch): Jakub Schmidtke <sjakub@gmail.com>
# Contributor: Figue <ffigue at gmail>
# Contributor: fauno <fauno@kiwwwi.com.ar>
# Contributor: evr <evanroman at gmail>
# Contributor: Muhammad 'MJ' Jassim <UnbreakableMJ@gmail.com>
# Contributor: vando <facundo@esdebian.org>
# Contributor: André Silva <emulatorman@hyperbola.info>
# Contributor: Henry Jensen <hjensen@connochaetos.org>
# Contributor: Luke Shumaker <lukeshu@parabola.nu>
# Contributor: Márcio Silva <coadde@hyperbola.info>
# Maintainer: Andreas Grapentin <andreas@grapentin.org>


# NOTE: icecat (60.7 < V <= 78.4) are not upstream releases
#       upstream releases would normally have '-gnu' appended to $_upstream_ver
#       this build is based on gnuzilla VCS developement sources
#       rev: 05adddbf87a5ee11de7cd90794c331a178bcfd5c


# needed for the !(...) matching in prepare()
shopt -s extglob

pkgname=icecat
_upstream_ver=78.4.0 # -gnu
pkgver=${_upstream_ver//-/_}
pkgrel=1
pkgdesc="GNU IceCat - a libre standalone web browser based on Mozilla Firefox ESR"
arch=(x86_64 i686 armv7h)
license=(MPL GPL LGPL)
url=http://www.gnu.org/software/gnuzilla/
depends=(gtk3 libxt mime-types dbus-glib ffmpeg nss ttf-font libpulse)
makedepends=(unzip zip diffutils yasm mesa imake inetutils xorg-server-xvfb
             autoconf2.13 rust clang llvm jack gtk2 nodejs cbindgen nasm
             python-setuptools python-psutil lld)
makedepends+=(mozilla-searchplugins jq)
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://repo.parabola.nu/other/${pkgname}/${pkgname}-${_upstream_ver}-pre.tar.bz2{,.sig}
        ${pkgname}.desktop
        0001-Use-remoting-name-for-GDK-application-names.patch
        rust-1.48_icecat-78.6.0.patch)
source+=(libre.patch
         mozilla-1663715.patch)
source_i686=('avoid-libxul-OOM-python-check.patch'
             'rust-static-disable-network-test-on-static-libraries.patch')
sha256sums=('314171bb68cd8b0fb7b880a77f3a2daa65acd660fc6f2a7d6871c5a5ba44be52'
            'SKIP'
            'f9f954fd06739e70a72ccf4774cfa71f349a4b133ec8f5dea0a3bcca2cf7321d'
            '3bb7463471fb43b2163a705a79a13a3003d70fff4bbe44f467807ca056de9a75'
            'd90faa59dc59f457c5770b3cc1ee4caa5b255e754ab9ab3993af894992c007e4'
            '28029afa3201e1be8138be06f741c59d64869edf0c9e90dbb05cfa6b5fff4ecd'
            '665cf25255fd240f79d5d010b3c3764f2d80aa81fdc7b6e9a9728e4a7970685b')
sha256sums_i686=('80b6461579398398c28f9b72b0c55220f261d9bf6c5a253e3bc66dc8a65131f6'
                 'e661665ee00ecec66c33e115b0af3474452022f0d8ceda634a6315dc8cb99014')
validpgpkeys=('318C679D94F17700CC847DE646A70073E4E50D4E'  # Ruben Rodriguez
              '3954A7AB837D0EA9CFA9798925DB7D9B5A8D4B40') # bill-auger


# PGO requires networking
_should_skip_pgo_armv7h=1 # disable for armv7h - always
_should_skip_pgo_i686=1   # disable for i686   - always
_should_skip_pgo_x86_64=0 # disable for x86_64 - libremakepkg
eval "_should_skip_pgo=\$_should_skip_pgo_${CARCH}"


_check_build_config() {
  pushd "${srcdir}"/${pkgname}-${pkgver%_*} > /dev/null

  echo "Checking build configuration..."

  # Configure produces mozinfo.json that reflects current configuration.
  # See build/docs/mozinfo.rst
  ./mach configure

  # In this test, jq collects values of the following keys of mozinfo.json into array,
  # and checks if any of them are not equal to false, in which case it returns "true".
  # E.g. if the value of any key is true or null (in case the key is missing from mozinfo.json),
  # that means the build configuration has to be reworked.
  declare -A antifeatures=( [.crashreporter]=true \
                            [.datareporting]=true \
                            [.healthreport]=true  \
                            [.normandy]=true      \
                            [.telemetry]=true     \
                            [.updater]=true       )
  local obj_directory=$(./mach environment | sed -En '/object directory:/{n;s/^\s+//;p;}')
  local config_file="${obj_directory}"/mozinfo.json
  echo "verifying disabled anti-features in: ${config_file}"
  for key in ${!antifeatures[@]}
  do  jq -e "${key} != false" "${config_file}" > /dev/null || unset antifeatures[${key}]
  done
  if   (( ${#antifeatures[@]} ))
  then echo "Some anti-features are not disabled in build configuration files - aborting:"
       for key in ${!antifeatures[@]} ; do echo "  - ${key} is enabled" ; done ;
# FIXME: '- .datareporting is enabled' - this build may not be FSDG-fit
# TODO: investigate the implications of this
#        return 1
  fi

  popd > /dev/null
}

prepare() {
  mkdir -p mozbuild
  cd "$srcdir/$pkgname-${pkgver%_*}"

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

  # https://bugzilla.mozilla.org/show_bug.cgi?id=1667736
  patch -Np1 -i ../rust-1.48_icecat-78.6.0.patch

  # https://bugzilla.mozilla.org/show_bug.cgi?id=1663715
  patch -Np1 -i ../mozilla-1663715.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
ac_add_options --enable-linker=lld
ac_add_options --disable-elf-hack
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 --enable-official-branding
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_NAME=icecat
export MOZ_APP_REMOTINGNAME=${pkgname//-/}
export MOZ_TELEMETRY_REPORTING=
export MOZ_REQUIRE_SIGNING=

ac_add_options --with-app-basename=icecat
ac_add_options --with-app-name=icecat

# 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 --disable-crashreporter
ac_add_options --disable-updater
ac_add_options --disable-eme
END


  ## [ARCH-SPECIFIC CONFIG] ##

  # TODO: this per-arch handling is yet to be re-worked for armv7h
  case "${CARCH}" in
  armv*)
#    sed -i '/--enable-linker=gold/d' ../mozconfig
#    sed -i '/--enable-rust-simd/d' ../mozconfig
#
#    # https://bugzilla.mozilla.org/show_bug.cgi?id=1463035
#    patch -Np1 -i "$srcdir"/mozilla-1463035.patch
#
#    cat >> ../mozconfig <<END
#ac_add_options --enable-optimize="-g -O2 -fno-schedule-insns"
#ac_add_options --disable-elf-hack
#ac_add_options --disable-webrtc
#ac_add_options --disable-av1
#END
    ;;
  i686)
      # disable LTO and use gcc toolchain (clang has issues on IA32)
      # disable SIMD (SSE20 for i686)
      export MOZ_SOURCE_CHANGESET="DEVEDITION_${pkgver//./_}_RELEASE"
      cat >>../mozconfig <<END
ac_add_options --disable-linker=lld
ac_add_options --enable-linker=bfd
ac_add_options --disable-lto
ac_add_options --disable-rust-simd
export CC=gcc
export CXX=g++
export AR=gcc-ar
export NM=gcc-nm
export RANLIB=gcc-ranlib
END

#       sed -i '/--enable-linker=gold/d' ../mozconfig

      # readelf: Error: Unable to seek to 0x801db328 for section headers
#       echo "applying avoid-libxul-OOM-python-check.patch"
#       patch -p1 -i ../avoid-libxul-OOM-python-check.patch

      # 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 ../rust-static-disable-network-test-on-static-libraries.patch
    ;;
  *) echo "no [ARCH-SPECIFIC CONFIG] for arch: ${CARCH}" ; return 1 ;
    ;;
  esac


  ## searchengines ##

  # install our searchengines
  locales=( $(jq ".locales|keys|.[]" < browser/components/search/extensions/list.json) )
  rm -rv browser/components/search/extensions/!(wikipedia)
  cp -rv /usr/share/mozilla/searchplugins/* browser/components/search/extensions/
  cat > browser/components/search/extensions/list.json << EOF
{
  "default": {
    "visibleDefaultEngines": [
      "duckduckgo-html", "duckduckgo-lite", "internet-archive", "parabola-packages", "parabola-wiki", "searx", "wikipedia", "yacy"
    ]
  },
  "regionOverrides": {
  },
  "locales": {
EOF

  comma=","
  for locale in "${locales[@]}"; do
    [ "$locale" != "${locales[-1]}" ] || comma=""
    cat >> browser/components/search/extensions/list.json << EOF
    $locale: {
      "default": {
        "visibleDefaultEngines": [
          "duckduckgo-html", "duckduckgo-lite", "internet-archive", "parabola-packages", "parabola-wiki", "searx", "wikipedia", "yacy"
        ]
      }
    }$comma
EOF
  done

  cat >> browser/components/search/extensions/list.json << EOF
  }
}
EOF
  # Sanity-check search-engines patching
  local engines_err_msg="search-engines patching needs re-working"
  jq < browser/components/search/extensions/list.json || ! echo "${engines_err_msg}"

  # Patch and remove anything that's left
  echo "applying libre.patch"
  patch -Np1 -i "${srcdir}"/libre.patch
}

build() {
  cd "$srcdir/$pkgname-${pkgver%_*}"

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

  # LTO needs more open files
  ulimit -n 4096

  # clang-{9,10,11} -> error: unknown argument: '-fvar-tracking-assignments'
  CFLAGS="${CFLAGS/-fvar-tracking-assignments/}"
  CXXFLAGS="${CXXFLAGS/-fvar-tracking-assignments/}"


  ## [ARCH-SPECIFIC BUILD ENV] ##

  # TODO: this per-arch handling is yet to be re-worked for armv7h
  case "${CARCH}" in
    armv*)
#       export RUSTFLAGS+=" -Cdebuginfo=0 -Clto=off"
#       export LDFLAGS+=" -Wl,--no-keep-memory -Wl,--reduce-memory-overheads"
#       export CFLAGS
#       export CXXFLAGS
      ;;
    i686)
      # -fno-plt with cross-LTO -> LLVM ERROR: Function Import: link error
      CFLAGS="${CFLAGS/-fno-plt/}"
      CXXFLAGS="${CXXFLAGS/-fno-plt/}"

      export RUSTFLAGS+=" -Cdebuginfo=0 -Clto=off"
#       export LDFLAGS+=" -Wl,--no-keep-memory -Wl,--reduce-memory-overheads" # ld.lld: error: unknown argument '--reduce-memory-overheads'
      export LDFLAGS+=" -Wl,--no-keep-memory"
      export CFLAGS
      export CXXFLAGS
      ;;
    x86_64)
      # TODO: this may only be needed for v78
      # -fno-plt with cross-LTO causes obscure LLVM errors
      # LLVM ERROR: Function Import: link error
      CFLAGS="${CFLAGS/-fno-plt/}"
      CXXFLAGS="${CXXFLAGS/-fno-plt/}"

      export CFLAGS
      export CXXFLAGS
      ;;
    *) echo "no [ARCH-SPECIFIC BUILD ENV] for arch: ${CARCH}" ; return 1 ;
      ;;
  esac


  ## [ARCH-SPECIFIC BUILD CONFIG] ##

  # TODO: this per-arch handling is yet to be re-worked for armv7h
  case ${CARCH} in
  armv7h)
    ;;
  i686)
    # 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
    ;;
  x86_64)
    ;;
  *) echo "no [ARCH-SPECIFIC BUILD CONFIG] for arch: ${CARCH}" ; return 1 ;
    ;;
  esac


  ## PGO build ##

  if (( $_should_skip_pgo ))
  then
    # skipping "3-tier PGO" "instrumented browser", to avoid OOM problems;
    # so we have the final .mozconfig now
    cp ../mozconfig .mozconfig
  else
    # Do 3-tier PGO
    echo "Building instrumented browser..."
    cat >.mozconfig ../mozconfig - <<END
ac_add_options --enable-profile-generate=cross
END
    _check_build_config
    ./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

    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
  fi # $_should_skip_pgo


  ## sanity checks ##

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


  ## main build ##

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

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

package() {
  cd "$srcdir/$pkgname-${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);
pref("extensions.shownSelectionUI", true);

// Disable "alt" as a shortcut key to open full menu bar. Conflicts with "alt" as a modifier
pref("ui.key.menuAccessKeyFocuses", false);

// Make sure that Firefox Social stuff are empty
pref("social.whitelist", "");
pref("social.directories", "");

// Disable the GeoLocation API for content
pref("geo.enabled", false);

// Make sure that the request URL of the GeoLocation backend is empty
pref("geo.wifi.uri", "");

// Disable the least secure encryption protocols
pref("security.ssl3.ecdhe_ecdsa_rc4_128_sha", false);
pref("security.ssl3.ecdhe_rsa_rc4_128_sha", false);
pref("security.ssl3.rsa_rc4_128_md5", false);
pref("security.ssl3.rsa_rc4_128_sha", false);
END

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

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

  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/icon64.png \
    "$pkgdir/usr/share/icons/hicolor/64x64/apps/$pkgname.png"
  install -Dvm644 browser/branding/$theme/mozicon128.png \
    "$pkgdir/usr/share/icons/hicolor/128x128/apps/$pkgname.png"
  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/identity-icons-brand.svg \
    "$pkgdir/usr/share/icons/hicolor/symbolic/apps/$pkgname-symbolic.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

  # 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


  ## [ARCH-SPECIFIC INSTALL] ##

  # TODO: this per-arch handling is yet to be re-worked for armv7h
  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
}