summaryrefslogtreecommitdiff
path: root/libre/iceweasel/PKGBUILD
blob: 24d34f236adeb21f141d382887d9afacf668d826 (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
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
# Maintainer (arch): Jan Alexander Steffens (heftig) <heftig@archlinux.org>
# Contributor: Ionut Biru <ibiru@archlinux.org>
# Contributor: Jakub Schmidtke <sjakub@gmail.com>
# Contributor: Henry Jensen <hjensen@connochaetos.org>
# Maintainer (archarm): Kevin Mihelich <kevin@archlinuxarm.org>
# Maintainer (arch32): Andreas Baumann <mail@andreasbaumann.cc>
# Contributor: 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: vando <facundo@esdebian.org>
# 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>


# parabola changes and rationale
# 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
#  - Disable Normandy that let Mozilla push messages with recommendations
#    of nonfree software
#  - Make Remote Settings work completely offline using local data
#  - Use system python libs. The arch package uses 'pip' to download
#    dependencies from the internet at build-time, despite that those needed
#    dependencies are already packaged in the arch repos. So strictly-speaking,
#    the package is not built from source, as some sources will be missing
#    from the published source package, and will not be required as makedepends.
#
# technical:
#  - build i686 with GCC instead of clang
#  - disable rust-SIMD, LTO, PGO, and skip profiling build for armv7h and i686
#  - allow skipping profiling build for x86_64 (_x86_64_skip_pgo).
#    this is to avoid OOM problems, and occasional deadlocks in some versions,
#    which expect active netwokring or internet access at build time.
#  - prefer as many system libs as possible, over their vendored couterparts
#  - Rebrand to Iceweasel, per the mozilla trademark policy, due to the FSDG changes
#  - set user profile directory to ~/.mozilla/iceweasel
#
# 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)
#  - do not compile/upload remote debug symbols


# NOTE: This PKGBUILD is kept in-sync, as closely as possible,
#       with arch{,arm,32} (firefox), and parabola {iceweasel,icecat},
#       for the sake of documentation and cleaner diffs.
#       That also helps to identify which changes were made by Parabola vs upstream.
#       Therefore, this PKGBUILD may declare blacklisted dependencies, non-free sources,
#       or include code for anti-features; but those will be filtered-out subsequently.
#       Any code which implements an anti-feature should be commented-out;
#       and include an 'anti-feature' comment, for clarity.
#       Any blacklisted dependencies and non-free sources should be filtered,
#       and include a 'non-free' comment, for clarity.
#       Without those over-rides, the resulting program may not be FSDG-fit.
#       Do not circumvent those over-rides, if compiling for the Parabola repos.


pkgname=iceweasel
epoch=1
pkgver=107.0.1
pkgrel=1
pkgrel+=.parabola1
_brandingver=102.0-1
pkgdesc="Standalone web browser derived from Mozilla Firefox"
url=https://wiki.parabola.nu/Iceweasel
arch=(x86_64)
arch+=(
  armv7h
  i686)
license=(
  GPL
  LGPL
  MPL
)
depends=(
  dbus-glib
  ffmpeg
  gtk3
  libpulse
  libxt
  mime-types
  nss
  ttf-font
)
makedepends=(
  cbindgen
  clang
  diffutils
  dump_syms
  imake
  inetutils
  jack
  lld
  llvm
  mesa
  nasm
  nodejs
  python
  rust
  unzip
  wasi-compiler-rt
  wasi-libc
  wasi-libc++
  wasi-libc++abi
  xorg-server-xvfb
  yasm
  zip
)
makedepends+=(
  git
  imagemagick
  jq
  libxslt
  python-jsonschema
  python-setuptools
  python-typing-extensions
  python-zstandard
  quilt
)
optdepends=(
  'hunspell-en_US: Spell checking, American English'
  'libnotify: Notification integration'
  'networkmanager: Location detection via available WiFi networks'
  'pulseaudio: Audio support'
  'speech-dispatcher: Text-to-Speech'
  'xdg-desktop-portal: Screensharing with Wayland'
)
# provides=('firefox') # TODO: redmine #2164 - currently conflicts with 'your-freedom'
replaces=('firefox')
options=(
  !debug
  !emptydirs
  !lto
  !makeflags
  !strip
)
source=(
  https://archive.mozilla.org/pub/firefox/releases/$pkgver/source/firefox-$pkgver.source.tar.xz{,.asc}
  $pkgname.desktop
  identity-icons-brand.svg
  0001-libwebrtc-screen-cast-sync.patch
)
source=(${source[*]/identity-icons-brand.svg/})
source+=(
  https://repo.parabola.nu/other/iceweasel/${pkgname}_${_brandingver}.branding.tar.xz{,.sig}
  9001-FSDG-sync-remote-settings-with-local-dump.patch
  9002-FSDG-preference-defaults.patch
  9003-FSDG-urihandlers.patch
  9004-FSDG-misc.patch
  process-json-files.py
  vendor.js.in
  zstandard-0.19.0.diff
)
source_armv7h=(build-arm-libopus.patch)
source_i686=(
  avoid-libxul-OOM-python-check.patch
  rust-static-disable-network-test-on-static-libraries.patch
  firefox-106.0.1-fdlibm.patch
  simd_avx2.patch
  fix-i686-build-moz-1792159.patch
)
validpgpkeys=(
  '14F26682D0916CDD81E37B6D61B7B526D98F0353'  # Mozilla Software Releases <release@mozilla.com>
)
validpgpkeys+=(
  'BFA8008A8265677063B11BF47171986E4B745536' # Andreas Grapentin
  '3954A7AB837D0EA9CFA9798925DB7D9B5A8D4B40' # bill-auger
)
sha256sums=('e29950b9ba9143b0d683dc18779bbe70bbd082533aff8f6a7af69b19533e0647'
            'SKIP'
            '9cdc2602661717712092d28bb494e5b48e518cb930898aca85eaf21f91f7ef58'
            '5c164f6dfdf2d97f3f317e417aaa2e6ae46a9b3a160c3162d5073fe39d203286')
sha256sums+=('d29c194ed7b3b4fa0f511866723118938c2be40077b4e9aadf8b3e6bfff91049'
             'SKIP'
             '77cfa1e135ba6884ee343468075491b67fe148077e4aebe8bb5ff7b5f6e022c2'
             'a2c71759290dd48c87bf8aacb681040dcaefdabe0d57317de361d2d2d509664b'
             'e192458a2a9878483984e1400bb3c66df369adfbf6f144b90445f80973c32ed1'
             '0c5333c4fc28ba9ca5b4d00127918d662fe8c570d4ebc0a64e5174e0ef41ae01'
             '6a0250c20a6f4cbf0ff1320c194342fe691ece56959d87de41be8f82a8feca65'
             '5095942e37c4d9814788b7ac5a48661fbcf1d2ced56a02b74e5a58e7e8a5bd45'
             '8f5ae64094170978ff97f2c14a14a3ef5e69083aa8b513630725aeaa7e892e8f')
sha256sums_armv7h=('2d4d91f7e35d0860225084e37ec320ca6cae669f6c9c8fe7735cdbd542e3a7c9')
sha256sums_i686=('2f0c81a38c4578f68f5456b618fe84a78974072821488173eb55e0e72287e353'
                 '10c5276eab2e87f400a6ec15d7ffbef3b0407ee888dea36f1128927ca55b9041'
                 'ddc0945f2414828668dd922b6b8203f7fb54d7b1f0aac3e18299bccb5c2facab'
                 'e68f8a9858f14a75813df608510e1f8143fd6eb1fcf233df8239d16d935e80f8'
                 '2fb39374fd3d80eea9e346032a2a4b2bc2e357dee7380855b24bcf19b1335d06')
b2sums=('cab3d7e723c9927518a3acfbf8d0db7846074000933074309b9bea1dcc2e182b579a7a6b2763bafeaf813d9846c4539d6e73cf75734844f3207525aff7e5c8be'
        'SKIP'
        'f86353bbba05d8994db34c6abb66094aa61d2c37c8599930dbe9d215413f0f718a1ce55a8f2d07a65074c3947e28fc80d44c925bd9be239a870f82d2a1803635'
        '28a22a11572fba86bf8412f86a2eca8dc34ce42e790d9c9b1e0b1a66959b2b0240353e0aef22741d6d2baa08bc7ff35ddfd3770b706654ffa8089a26495e4ee3')
b2sums+=('c2a2ead1b44c563583abb5cd3579e8f2724ea79e12aba1b315f201a09547d611b4a3c98de12f063b25826fd1520562d411ab917780bab4d78a1240fe56096b1b'
         'SKIP'
         'fc681f1abbcdb669e60f7d40a43749f16e0693e18b790c259367f64212a28981246e01cbf269b6b9c05e9ea3a9fcb4fb7ee35340769676f3051da5585982ae5d'
         '2eaacb9fb15391557a36cae10ec6d70b5a4ab6f71c4b24d268f5c0df78b272f0d88c9c7498ae92c60f1436dff82dc8c49e94b0a535535329a2419302aee7b7a8'
         '48b23fcf1e5fe3e8e0d2f85e1e43c79700449838d39a962110d30f5f7acdefcd1db6f80ccade2ab1eb7e26e5651cbfb37d8358d7f87f9e820d4a395cce8b0454'
         '42e08d0872dffa94ec73d29c08b60ce4d966be2f785e07a01ec3ef2ac05bbe895675655b60e85f9c705878291df7ead69e7ef9d7bce8c95a47b6a124231f889c'
         '2a746251ffdbe91bc8933c798242a32dfda7f9621d26924a752e5fa9b5f97a1b8cd83fbb0e9063d62fc36e08f8222371ac7873202c2ce5f8498c12024b4ccdc4'
         '5f0bb717734f94594e146d72a95e65bf631716affca84c5cdd1d3777f2c9ddd1a9ec243c806f7a846a5cfcaa5793d8f84b0e0720d4f868ae6368857a69506427'
         '1b8ace4e8fc6ebc99d527c33781182218c4b8c640914cc8e800616a1e370cb1ea6da890bcf45fb753a4594513755585290141fe9c12fbc039c00f56ade6cf0c4'
         'dfce473a5492e79faf9120ff4026861623cfb89d39046f96ea52ef83e01d1288ec0bf46b5bde4a68b24c9562493e66028621555f69a783e5f89cb2d0897bb4aa')
b2sums_armv7h=('6e5980e56343a23bce4fcda58f6abc8f2debca0c278c87b09e53abb17ff15849c26e8df3bbff2388985f8fe5a4e9be9982c602ef7159546f0ae335fca1000a41')
b2sums_i686=('97035e44cd1deae7bb2422c81eec7294feb51f43f460b4d7ddba083e1d8a48d265a36ca43cf1d9dee49b01ee6df0c76e0f6916cc73cb7ad9caa1c235a59da0e4'
             '009789d3bb93ba418929019135804fc3de7de161e5be8efba7fc75646fbde395720be5b7a7d3f5d1671f459fdd2944dd14aca306bbf1c975436d4f7765d62d15'
             '4492e991d25c0603b8deb25484d891c1bfc70ec71dc63a76eb56189873a66a508a00a7f98edc295da18e017909a4591863e820c2041beea0c00724687f25867d'
             '611454f7943cce37acee31234d887d9e58e3d1f4745e811968e42aea8ec5d655f0081a594a233e663db17c95b264083891562e12f098ac261d57a0ae1c3c1c3d'
             'd20ce3eff595f85df86eaa0dfb665fc356f8987117a771f76adc4ac12046a7e82b0af182fa99f87ea1362a5026c9d0216c7b714649fef0c7294c61c8e8f4d790')


# Google API keys (see http://www.chromium.org/developers/how-tos/api-keys)  # anti-feature
# Note: These are for Arch Linux use ONLY. For your own distribution, please # anti-feature
# get your own set of keys. Feel free to contact foutrelis@archlinux.org for # anti-feature
# more information.                                                          # anti-feature
# _google_api_key=AIzaSyDwr302FpOSkGRpLlUpPThNTDPbXcIn_FM                    # anti-feature

# Mozilla API keys (see https://location.services.mozilla.com/api)           # anti-feature
# Note: These are for Arch Linux use ONLY. For your own distribution, please # anti-feature
# get your own set of keys. Feel free to contact heftig@archlinux.org for    # anti-feature
# more information.                                                          # anti-feature
# _mozilla_api_key=e05d56db0a694edc8b5aaebda3f2db6a                          # anti-feature


## dependency tweaks ##

# disable PGO for 32-bit arches
_should_skip_pgo=0 # for x86_64 (try '1' if the build hangs indefinitely)

case "${CARCH}" in
armv7h)
  _should_skip_pgo=1

  makedepends=( ${makedepends[*]/wasi*/} ) # armv7h has no wasi compiler

  depends+=( icu=72.1 ) # --with-system-icu
  ;;
i686)
  _should_skip_pgo=1

  echo "FIXME: v105 fails to build - v106 fails to build without --disable-webrtc"
  ;;
esac


## helpers ##

_check_build_config() {
  pushd "${srcdir}"/firefox-${pkgver} > /dev/null

  echo "Checking build configuration..."

  # Each of the [ARCH-SPECIFIC CONFIG] branches in prepare(), should have prepared a
  # $srcdir/mozconfig file with any arch-specific changes to the Arch x86_64 PKGBUILD.
  # Finally, that file should have been copied to $srcdir/firefox-$pkgver/.mozconfig
  grep '^ac_add_options --with-distribution-id=nu.parabola' .mozconfig &> /dev/null || \
  ! echo "cannot continue without a .mozconfig file"                                || return 1

  if ! [[ "${CARCH}" =~ ^(aarch64|armv7h)$ ]] # ARM has no --disable-eme option
  then grep '^ac_add_options --disable-eme' .mozconfig &> /dev/null   || \
       ! echo ".mozconfig file was not properly treated per the FSDG" || return 1
  fi

  # 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.
  local obj_directory=$(./mach environment | sed -En '/object directory:/{n;s/^\s+//;p;}')
  local antifeature_keys=(.crashreporter .datareporting .healthreport .normandy .telemetry .updater)
  local antifeatures=()
  echo "obj_directory is: ${obj_directory}"
  for key in ${antifeature_keys[@]}
  do  if   jq -e "${key} != false" "${obj_directory}"/mozinfo.json &> /dev/null
      then antifeatures+=(${key})
      fi
  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 ;
       return 1
  fi

  popd > /dev/null
}

_check_patching() {
  pushd "${srcdir}"/firefox-${pkgver} > /dev/null

  echo "verifying libre patching"

  # URI protocol handlers
  local uri_handlers=uriloader/exthandler/HandlerList.jsm
  local webmails='google|yahoo'
  grep   'name:'          $uri_handlers | grep    '"KiwiIRC",' &> /dev/null && \
  ! grep 'name:'          $uri_handlers | grep -v '"KiwiIRC",' &> /dev/null && \
  ! grep -E "($webmails)" $uri_handlers                        &> /dev/null || \
  ! echo "9003-FSDG-misc.patch needs reworking"                             || \
  return 1

  # Remote Settings
  local settings_server='firefox.settings.services.mozilla.com'
  ! grep -qr $settings_server &> /dev/null                                      || \
  ! echo '9001-FSDG-sync-remote-settings-with-local-dump.patch needs reworking' || \
  return 1

  popd > /dev/null
}


## business ##

prepare() {
  mkdir mozbuild
  cd firefox-$pkgver

  # https://bugs.archlinux.org/task/76231
  # https://bugzilla.mozilla.org/show_bug.cgi?id=1790496
  # https://src.fedoraproject.org/rpms/firefox/blob/rawhide/f/libwebrtc-screen-cast-sync.patch
  patch -Np1 -i ../0001-libwebrtc-screen-cast-sync.patch

  ## technical patching ##

  # Unbreak build with python-zstandard 0.19.0
  echo "applying zstandard-0.19.0.diff"
  patch -Np1 -i ../zstandard-0.19.0.diff

  case ${CARCH} in
  aarch64|armv7h)
    # Error: immediate expression requires a # prefix -- `pld [r0,1792]'
    #        mozilla #1787405 and #1791267
    sed -i "s|# 'LIBYUV_DISABLE_NEON',|'LIBYUV_DISABLE_NEON',|" media/libyuv/libyuv/libyuv.gyp
    ! grep "# 'LIBYUV_DISABLE_NEON'," media/libyuv/libyuv/libyuv.gyp || ! echo "error patching media/libyuv/libyuv/libyuv.gyp" || exit 1
    ;;
  i686)
    ;;
  x86_64)
    ;;
  esac


  ## general configuration ##

  # echo -n "$_google_api_key" >google-api-key   # anti-feature
  # echo -n "$_mozilla_api_key" >mozilla-api-key # anti-feature

  cat >../mozconfig <<END
ac_add_options --enable-application=browser
mk_add_options MOZ_OBJDIR=${PWD@Q}/obj

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
ac_add_options --disable-bootstrap
ac_add_options --with-wasi-sysroot=/usr/share/wasi-sysroot

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

# Keys
# ac_add_options --with-google-location-service-api-keyfile=${PWD@Q}/google-api-key # anti-feature
# ac_add_options --with-google-safebrowsing-api-keyfile=${PWD@Q}/google-api-key     # anti-feature
# ac_add_options --with-mozilla-api-keyfile=${PWD@Q}/mozilla-api-key                # anti-feature

# 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 # anti-feature
ac_add_options --disable-updater
ac_add_options --disable-tests
ac_add_options --disable-eme           # anti-feature
END


  ## [ARCH-SPECIFIC CONFIG] ##

  case ${CARCH} in
  aarch64|armv7h)
    # experimental/version-specific hacks #

    # use GCC (not LLVM - gcc 12 failed to build v106)
    cat >> ../mozconfig <<EOF
export CC=gcc
export CXX=g++
export AR=gcc-ar
export NM=gcc-nm
export RANLIB=gcc-ranlib
EOF

    # ld.lld: error: undefined hidden symbol: std::type_info::operator==(std::type_info const&) const
    echo 'ac_add_options --with-system-icu' >> ../mozconfig


    # upstream #

    # archarm has these differences in ## general configuration ## above
    sed -i '
      /--enable-hardening/d
      /--enable-optimize/d
      /--enable-rust-simd/d
      s| --with-wasi-sysroot=.*| --without-wasm-sandboxed-libraries|
      /--disable-eme/d
    ' ../mozconfig

    if [[ $CARCH == "armv7h" ]]; then
      echo "ac_add_options --disable-elf-hack" >> .mozconfig
      # https://bugzilla.redhat.com/show_bug.cgi?id=1641623
      echo "ac_add_options --disable-av1" >> .mozconfig
      # reduce jobs due to RAM constraints
      MAKEFLAGS="-j4"
      # disable hard-coded LTO
      sed -i '/cargo_rustc_flags += -Clto/d' config/makefiles/rust.mk
      sed -i '/RUSTFLAGS += -Cembed-bitcode=yes/d' config/makefiles/rust.mk
      # increase codegen-units due to RAM constraints
      sed -i 's/codegen-units=1/codegen-units=16/' config/makefiles/rust.mk
      # webrtc on ARMv7 implies android, so disable it
      echo "ac_add_options --disable-webrtc" >> .mozconfig
    elif [[ $CARCH == "aarch64" ]]; then
      echo 'ac_add_options --enable-rust-simd' >> .mozconfig
    fi
    echo 'ac_add_options --enable-optimize="-g0 -O2"' >> .mozconfig
    echo "mk_add_options MOZ_MAKE_FLAGS=\"${MAKEFLAGS}\"" >> .mozconfig

    # archarm `export` commands are under the '[ARCH-SPECIFIC BUILD ENV]' section

    patch -p1 -i ../build-arm-libopus.patch

    # At this point in the script, the arch, arch32, and parabola PKGBUILDs
    # have prepared a temporary ${srcdir}/mozconfig; but the archarm PKGBUILD
    # writes directly to the final firefox-$pkgver/.mozconfig.
    # We allowed .mozconfig to be written above, only to minimize the diff against archarm.
    # For consistency across arches, we move it to ${srcdir}/mozconfig now.
    # ${srcdir}/mozconfig will clobber firefox-$pkgver/.mozconfig later, in build().
    cat .mozconfig >> ../mozconfig
    ;;
  i686)
    echo "FIXME: i686 iceweasel v>104 has known build failures"

    export MOZ_SOURCE_CHANGESET="DEVEDITION_${pkgver//./_}_RELEASE"
#     export MOZ_MAKE_FLAGS=-j2

    # disable LTO as it has little benefit and uses too many resources
    # don't compile with clang, use gcc toolchain (clang has issues on IA32)
    # disable SIMD (SSE2 for i686)
    # set correct compiler and toochain tools
    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
#ac_add_options --enable-strip
ac_add_options --disable-debug
ac_add_options --disable-debug-symbols
#export CC=gcc
#export CXX=g++
#export AR=gcc-ar
#export NM=gcc-nm
#export RANLIB=gcc-ranlib
#export STRIP=strip
END

    # FIXME GCC: /usr/lib/gcc/i686-pc-linux-gnu/12.1.0/include/xmmintrin.h:208:1: error: inlining failed in call to ‘always_inline’ ‘__m128 _mm_sqrt_ps(__m128)’: target specific option mismatch
    # FIXME LLVM: /build/iceweasel/src/firefox-106.0.1/third_party/libwebrtc/modules/audio_processing/aec3/adaptive_fir_filter.cc:110:27: error: always_inline function '_mm_loadu_ps' requires target feature 'sse', but would be inlined into function 'ComputeFrequencyResponse_Sse2' that is compiled without support for 'sse'
    echo "ac_add_options --disable-webrtc" >> ../mozconfig

    sed -i '/cargo_rustc_flags += -Clto/d' config/makefiles/rust.mk # FIXME: is this needed?

    # 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

    # FIXME: this patch is probably temporary - it comes from mozilla
    #          https://bugzilla.mozilla.org/show_bug.cgi?id=1729459
    #        /build/iceweasel/src/firefox-96.0.1/modules/fdlibm/src/math_private.h:34:21:
    #          error: conflicting declaration ‘typedef __double_t double_t’
    #        /usr/include/math.h:156:21: note: previous declaration as ‘typedef long double double_t’
    echo "applying firefox-106.0.1-fdlibm.patch"
    patch -p1 -i "$srcdir/firefox-106.0.1-fdlibm.patch"

    # disable AVX2 the brutal way
    # mozglue/misc/SIMD_avx2.cpp:66:10: error: ‘_mm_cvtsi64_si128’ was not declared in this scope; did you mean ‘_mm_cvtsi64_si32’?
    echo "applying simd_avx2.patch"
    patch -p1 -i "$srcdir/simd_avx2.patch"

    # js/src/jit/shared/AtomicOperations-shared-jit.cpp:88:9: error: ‘AtomicCopyByteUnsynchronized’ was not declared in this scope; did you mean ‘AtomicMemcpyUpUnsynchronized’?
    echo "applying fix-i686-build-moz-1792159.patch"
    patch -p1 -i "$srcdir/fix-i686-build-moz-1792159.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="${srcdir}"/firefox-${pkgver}/browser/branding/${pkgname}
  local tippytopdir="${srcdir}"/firefox-${pkgver}/browser/components/newtab/data/content/tippytop
  local blank_svg='<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"></svg>'
  rm -rf -- ${brandingdestdir}
  cp -aT -- ${brandingsrcdir}/branding ${brandingdestdir}

  pushd "${brandingdestdir}" > /dev/null

  # generate icons, logos, banners
  for size in 16 22 24 32 48 64 128 256
  do  rsvg-convert -w ${size} -h ${size}  iceweasel_icon.svg -o default${size}.png
  done
  cp                                      iceweasel_logo.svg        content/aboutlogins.svg
  cp                                      iceweasel_logo.svg        content/about-logo.svg
#  cp                                      iceweasel_logo.svg        content/about-logo.svg # RuntimeError: File "about-logo.svg" not found in browser/branding/iceweasel/content
  rsvg-convert -w 192 --keep-aspect-ratio iceweasel_logo.svg     -o content/about-logo.png
  rsvg-convert -w 384 --keep-aspect-ratio iceweasel_logo.svg     -o content/about-logo@2x.png
  cp                                      content/about-logo.png    content/about-logo-private.png
  cp                                      content/about-logo@2x.png content/about-logo-private@2x.png
  echo ${blank_svg}                                           > content/blank.svg

  popd > /dev/null

  # 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
  #        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"

  # process default Top Sites and their icons
  find ${tippytopdir} -type f      \
       -not -name 'wikipedia-org*' \
       -not -name 'top_sites.json' \
       -exec rm -v {} \;
  for image in "${brandingsrcdir}"/tippytop/*.svg; do
    local outname=$(basename -s .svg "${image}")
    local size=$(identify -format '%wx%h' ${tippytopdir}/images/wikipedia-org@2x.png)
    local background=$( [[ "${outname}" == 'gnu' ]] && echo 'white' || echo 'none' )
    magick -density 300 ${image}                           \
           -gravity center -resize ${size} -extent ${size} \
           "${tippytopdir}/images/${outname}@2x.png"

    size=256x256
    magick -density 300 -background ${background} ${image} \
           -gravity center -resize ${size} -extent ${size} \
           -define icon:auto-resize=64,48,32,16            \
           "${tippytopdir}/favicons/${outname}.ico"
  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'
  export QUILT_PC="${srcdir}"/.pc
  quilt push -av

  # misc branding
  sed -i "s|({ \$bits }-bit)|($CARCH)|" browser/locales/en-US/browser/aboutDialog.ftl


  ## searchengines ##

  pushd browser/components/search/extensions > /dev/null

  # Patch search-engines configs
  sed -i 's|https://duckduckgo.com/|https://html.duckduckgo.com/html/|' ddg/manifest.json

  # Removing URL parameters that let DuckDuckGo know the place in UI
  # the search was ran from (like address bar, context menu, etc.)
  local jq_cmd='del(.chrome_settings_overrides.search_provider.params)'
  jq "${jq_cmd}"           ddg/manifest.json > manifest.json.tmp
  ! diff manifest.json.tmp ddg/manifest.json > /dev/null
  mv manifest.json.tmp     ddg/manifest.json

  # Delete unused search engine configs
  find -mindepth 1 -maxdepth 1 \
       -not -name ddg          \
       -not -name wikipedia    \
       -exec rm -frv {} \;

  popd > /dev/null


  ## libre patching ##

  # Upstream tarball can contain some ignored cruft,
  # including binaries (for example, python3).
  echo 'Removing files specified in .gitignore...'
  git init && git clean -dfX                                                \
    --exclude='!ipc/chromium/src/third_party/libevent/evconfig-private.h'   \
    --exclude='!toolkit/crashreporter/google-breakpad/src/third_party/lss/' \
    --exclude='!third_party/python/**/*.egg-info/'
  rm -rf .git

  # Remove test-related networking dumps, because they contain code from
  # some Amazon webpage with no clear licensing, thus nonfree.
  # Also they interfere with checking of Remote Settings patching done later,
  # because communication with RS server has been captured in them too.
  rm python/mozperftest/mozperftest/system/example.zip
  rm testing/mozbase/mozproxy/tests/files/mitm5-linux-firefox-amazon.zip

  # Disable/neutralize Remote Settings (as best we can)
  echo "applying 9001-FSDG-sync-remote-settings-with-local-dump.patch"
  git apply ../9001-FSDG-sync-remote-settings-with-local-dump.patch

  # Disable various components at the source level
  sed -i 's/;1/;0/' toolkit/components/telemetry/components.conf
  sed -Ei 's/((MOZ_SERVICES_HEALTHREPORT|MOZ_NORMANDY).+)True/\1False/' browser/moz.configure
  #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

  python ../process-json-files.py "${srcdir}"/firefox-${pkgver} "${brandingsrcdir}"

  # disable various phone-home/goelocation anti-featires
  echo "applying 9002-FSDG-preference-defaults.patch"
  patch -Np1 --no-backup-if-mismatch -i "${srcdir}"/9002-FSDG-preference-defaults.patch

  # over-ride/install default URI protocol handlers
  echo "applying 9003-FSDG-urihandlers.patch"
  patch -Np1 --no-backup-if-mismatch -i "${srcdir}"/9003-FSDG-urihandlers.patch

  # Remove remaining non-free bits
  echo "applying 9004-FSDG-misc.patch"
  patch -Np1 --no-backup-if-mismatch -i "${srcdir}"/9004-FSDG-misc.patch

  echo "removing remaining non-free bits"
  rm -v toolkit/crashreporter/tools/upload_symbols.py
  rm -frv third_party/rust/winapi-{i686,x86_64}-pc-windows-gnu/**/*.a


  ## patching sanity checks ##

  _check_patching
}

build() {
  cd firefox-$pkgver

  ## build env ##

  export MOZ_NOSPAM=1
  export MOZBUILD_STATE_PATH="$srcdir/mozbuild"
  # export MOZ_ENABLE_FULL_SYMBOLS=1                    # anti-feature
  export MACH_BUILD_PYTHON_NATIVE_PACKAGE_SOURCE=system # parabola policy

  # LTO needs more open files
  ulimit -n 4096


  ## [ARCH-SPECIFIC BUILD ENV] ##

  case ${CARCH} in
  aarch64|armv7h)
    export MOZ_DEBUG_FLAGS=" "
    export CFLAGS+=" -g0"
    export CXXFLAGS+=" -g0"
    export LDFLAGS+=" -Wl,--no-keep-memory"
    export RUSTFLAGS="-Cdebuginfo=0"
    ;;
  i686)
    # -fno-plt with cross-LTO -> LLVM ERROR: Function Import: link error
    CFLAGS="${CFLAGS/-fno-plt/}"
    CXXFLAGS="${CXXFLAGS/-fno-plt/}"

    # try hard to tell ld and rust not to use too much memory (no lto, no debug info, etc.)
    export RUSTFLAGS+=" -Cdebuginfo=0 -Clto=off"
#    export LDFLAGS+=" -Wl,--no-keep-memory -Wl,--reduce-memory-overheads" # with GCC
    export LDFLAGS+=" -Wl,--no-keep-memory "                               # without GCC

    # libvpx has some hard-coded compiler flags for MMX, SSE, SSE2, use the correct one
    # per CARCH (75.0 uses an intrisic _mm_empty now, which required the corresponding
    # architecture flag to be preset - before it was merely embedding some assembly
    # code with EMMS
    export CFLAGS+=" -mmmx"
    export CXXFLAGS+=" -mmmx"
    ;;
  x86_64)
    ;;
  *) echo "no [ARCH-SPECIFIC BUILD ENV] for arch: ${CARCH}" ; return 1 ;
    ;;
  esac
  export CFLAGS
  export CXXFLAGS


  ## [ARCH-SPECIFIC BUILD CONFIG] ##

  case ${CARCH} in
  aarch64|armv7h)
    ;;
  i686)
    # /usr/bin/ld.bfd: error: libxul.so(.debug_info) is too large (0x54c5369a bytes)
#     options=( ${options[*]/\!strip/} )

    # 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"; so the final .mozconfig is ready 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

    echo "Building optimized browser..."
    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 ##

  _check_build_config


  ## main build ##

  (( ! $_should_skip_pgo )) || echo "Building optimized browser..."
  ./mach build

  # echo "Building symbol archive..." # anti-feature
  # ./mach buildsymbols               # anti-feature
}

package() {
  export MOZBUILD_STATE_PATH="$srcdir/mozbuild"         # needed for `libremakepkg -R`
  export MACH_BUILD_PYTHON_NATIVE_PACKAGE_SOURCE=system # needed for `libremakepkg -R`

  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
  cat "${srcdir}"/vendor.js.in >> "${vendorjs}"

  local distini="$pkgdir/usr/lib/$pkgname/distribution/distribution.ini"
  install -Dvm644 /dev/stdin "$distini" <<END
[Global]
id=parabola
version=(${_brandingver} branding)
about=${pkgname^} for Parabola GNU/Linux-libre
about.en-US=${pkgname^} for Parabola GNU/Linux-libre
about.eo=${pkgname^} por Parabola GNU/Linux-libre
about.es-ES=${pkgname^} para Parabola GNU/Linux-libre
about.gl=${pkgname^} para Parabola GNU/Linux-libre
about.pt-BR=${pkgname^} para Parabola GNU/Linux-libre

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

  # NOTE: browser/branding/$theme is $brandingdestdir in prepare()
  local i theme=$pkgname
  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 browser/branding/$theme/content/blank.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


  ## [ARCH-SPECIFIC INSTALL] ##

  case ${CARCH} in
  aarch64|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

    # disable stripping in mozconfig.<arch> (insists to use llvm-strip which runs
    # out of memory on libxul.so). Now 2.5 GB can be stripped to 166 MB, so we do
    # that with the normal 'strip' from binutils after 'mach install'
#    strip "$pkgdir/usr/lib/$pkgname/libxul.so"
    ;;
  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

  # export SOCORRO_SYMBOL_UPLOAD_TOKEN_FILE="$startdir/.crash-stats-api.token" # anti-feature
  # if [[ -f $SOCORRO_SYMBOL_UPLOAD_TOKEN_FILE ]]; then                        # anti-feature
  #   make -C obj uploadsymbols                                                # anti-feature
  # else                                                                       # anti-feature
  #   cp -fvt "$startdir" obj/dist/*crashreporter-symbols-full.tar.zst         # anti-feature
  # fi

  # BEGIN RENAME_PROFILE - temporary
  # replace binary with a temporary wrapper, to rename the user profile directory
  # NOTE: prior to v99, if another 'firefox' is installed in addition to iceweasel,
  #       both applications would share a profile, which is not very sane behavior.
  # TODO: this 'rename-profile.sh' source file, and the following two LOC,
  #       could be removed after a reasonable deprecation period (eg: in 2023)
  mv                                  "${pkgdir}"/usr/lib/iceweasel/ice{,-}weasel
  install -Dm755 ../rename-profile.sh "${pkgdir}"/usr/lib/iceweasel/iceweasel
  # END RENAME_PROFILE
}


# BEGIN RENAME_PROFILE - temporary - see note in package()
depends+=(gxmessage) ; source+=(rename-profile.sh) ;
sha256sums+=('da332a538662b6f8ebe67c0aee85a12af57a6f20309b1eec9f30add3ac1cbc4f')
# END RENAME_PROFILE