summaryrefslogtreecommitdiffstats
path: root/chromium/build/chromium.SlackBuild
blob: e14f627628efc9df6d0e4d80632562155fae2969 (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
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
#!/bin/bash
# $Id$
# Copyright 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020  Eric Hameleers, Eindhoven, NL
# All rights reserved.
#
#   Permission to use, copy, modify, and distribute this software for
#   any purpose with or without fee is hereby granted, provided that
#   the above copyright notice and this permission notice appear in all
#   copies.
#
#   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
#   WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
#   MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
#   IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
#   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
#   USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
#   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
#   OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
#   OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
#   SUCH DAMAGE.
#
# -----------------------------------------------------------------------------
#
# Slackware SlackBuild script 
# ===========================
# By:          Eric Hameleers <alien@slackware.com>
# For:         chromium
# Descr:       Open Source version of Chrome Web Browser
# URL:         http://www.chromium.org/
# Build needs: - multilib gcc & glibc for compiling the Native Client (64-bit);
#              - libelf with '-D_FILE_OFFSET_BITS=64' added to CFLAGS (32-bit);
#              - ninja;
#              - nodejs;
#              - gcc >= 8 for bootstrapping gn;
#              - Internet access (for downloading the nacl/pnacl toolchain bins)
# Needs:       
# Changelog:   
# 31.0.1650.57-1:
#              18/nov/2013 by Eric Hameleers <alien@slackware.com>
#              * Initial build.
# 31.0.1650.63-1:
#              18/Nov/2013 by Eric Hameleers <alien@slackware.com>
# 31.0.1650.67-1:
#              19/dec/2013 by Eric Hameleers <alien@slackware.com>
#              * Update comes with several security fixes.
# 32.0.1700.77-1:
#              14/jan/2014 by Eric Hameleers <alien@slackware.com>
#              * Update comes with several security fixes.
# 32.0.1700.102-1:
#              29/jan/2014 by Eric Hameleers <alien@slackware.com>
#              * Update comes with several security fixes.
# 32.0.1700.107-1:
#              04/feb/2014 by Eric Hameleers <alien@slackware.com>
#              * Update.
# 33.0.1750.117-1:
#              21/feb/2014 by Eric Hameleers <alien@slackware.com>
#              * Update comes with several security fixes.
# 33.0.1750.146-1:
#              04/mar/2014 by Eric Hameleers <alien@slackware.com>
#              * Update comes with several security fixes.
# 33.0.1750.149-1:
#              11/mar/2014 by Eric Hameleers <alien@slackware.com>
#              * Update comes with several security fixes.
# 33.0.1750.152-1:
#              18/mar/2014 by Eric Hameleers <alien@slackware.com>
#              * Update comes with several security fixes.
# 34.0.1847.116-1:
#              09/apr/2014 by Eric Hameleers <alien@slackware.com>
#              * Update comes with several security fixes.
# 34.0.1847.132-1:
#              25/apr/2014 by Eric Hameleers <alien@slackware.com>
#              * Update.
# 34.0.1847.137-1:
#              14/may/2014 by Eric Hameleers <alien@slackware.com>
#              * Update.
# 35.0.1916.114-1:
#              20/may/2014 by Eric Hameleers <alien@slackware.com>
#              * Update comes with several security fixes.
# 35.0.1916.153-1:
#              10/jun/2014 by Eric Hameleers <alien@slackware.com>
#              * Update comes with several security fixes.
# 36.0.1985.125-1:
#              16/jun/2014 by Eric Hameleers <alien@slackware.com>
#              * Update comes with several security fixes.
#                We can no longer download the toolchain binaries in advance,
#                so the build will now require internet connectivity.
# 36.0.1985.143-1:
#              12/aug/2014 by Eric Hameleers <alien@slackware.com>
#              * Update comes with security fixes, Chrome also comes with an
#                updated Flash plugin: 14.0.0.177.
# 37.0.2062.94-1:
#              27/aug/2014 by Eric Hameleers <alien@slackware.com>
#              * Update comes with security fixes, New: an embedded PDF viewer.
# 37.0.2062.120-1:
#              09/sep/2014 by Eric Hameleers <alien@slackware.com>
#              * Update comes with security fixes, Chrome also comes with an
#                updated Flash plugin: 15.0.0.152.
# 38.0.2125.101-1:
#              08/oct/2014 by Eric Hameleers <alien@slackware.com>
#              * Update comes with security fixes.
# 38.0.2125.104-1:
#              18/oct/2014 by Eric Hameleers <alien@slackware.com>
#              * Update comes with security fixes. Chrome also updates its
#                Flash plugin to 15.0.0.189.
# 38.0.2125.111-1:
#              28/oct/2014 by Eric Hameleers <alien@slackware.com>
#              * Update.
# 38.0.2125.122-1:
#              11/nov/2014 by Eric Hameleers <alien@slackware.com>
#              * Update comes with security fixes. Chrome also updates its
#                Flash plugin to 15.0.0.223.
# 39.0.2171.65-1:
#              17/nov/2014 by Eric Hameleers <alien@slackware.com>
#              * Update comes with security fixes.  See
#                http://googlechromereleases.blogspot.nl/2014/11/stable-channel-update_18.html
# 39.0.2171.71-1:
#              26/nov/2014 by Eric Hameleers <alien@slackware.com>
#              * Update comes with security fixes. Chrome also updates its
#                Flash plugin to 15.0.0.239.
# 39.0.2171.95-1:
#              09/dec/2014 by Eric Hameleers <alien@slackware.com>
#              * Update comes with security fixes. Chrome also updates its
#                Flash plugin to 16.0.0.235.
# 39.0.2171.95-2:
#              01/jan/2015 by Eric Hameleers <alien@slackware.com>
#              * Add support for the WIdevine CDM plugin (i.e. Netflix playback)
# 39.0.2171.99-1:
#              14/jan/2015 by Eric Hameleers <alien@slackware.com>
#              * New release accompanied by pepperflash 16.0.0.257. 
# 40.0.2214.91-1:
#              21/jan/2015 by Eric Hameleers <alien@slackware.com>
#              * New release.
# 40.0.2214.111-1:
#              06/feb/2015 by Eric Hameleers <alien@slackware.com>
# 41.0.2272.76-1:
#              05/mar/2015 by Eric Hameleers <alien@slackware.com>
#              * First release of Chromium 41 stable.
# 41.0.2272.118-1:
#              02/apr/2015 by Eric Hameleers <alien@slackware.com>
#              * Security update.
# 42.0.2311.90-1:
#              15/apr/2015 by Eric Hameleers <alien@slackware.com>
#              * First release of Chromium 42 stable.
# 42.0.2311.135-1:
#              30/apr/2015 by Eric Hameleers <alien@slackware.com>
#              * Security update.
# 43.0.2357.65-1:
#              20/may/2015 by Eric Hameleers <alien@slackware.com>
#              * Security update, first 43 version.
# 43.0.2357.81-1:
#              29/may/2015 by Eric Hameleers <alien@slackware.com>
#              * Update.
# 43.0.2357.124-1:
#              09/jun/2015 by Eric Hameleers <alien@slackware.com>
#              * Update.
# 43.0.2357.125-1:
#              12/jun/2015 by Eric Hameleers <alien@slackware.com>
#              * Update.
# 43.0.2357.125-2:
#              19/jun/2015 by Eric Hameleers <alien@slackware.com>
#              * Disable "OK Google" hotwording completely.
# 43.0.2357.130-1:
#              22/jun/2015 by Eric Hameleers <alien@slackware.com>
#              * Update.
# 43.0.2357.130-2:
#              25/jun/2015 by Eric Hameleers <alien@slackware.com>
#              * Fix broken password manager in KDE.
# 43.0.2357.132-1:
#              08/jul/2015 by Eric Hameleers <alien@slackware.com>
#              * Update.
# 43.0.2357.134-1:
#              15/jul/2015 by Eric Hameleers <alien@slackware.com>
#              * Update.
# 44.0.2403.89-1:
#              22/jul/2015 by Eric Hameleers <alien@slackware.com>
#              * Update - first 44 release.
# 44.0.2403.107-1:
#              25/jul/2015 by Eric Hameleers <alien@slackware.com>
#              * Update - emergency bugfix release.
# 44.0.2403.155-1:
#              11/aug/2015 by Eric Hameleers <alien@slackware.com>
#              * Update.
# 44.0.2403.157-1:
#              21/aug/2015 by Eric Hameleers <alien@slackware.com>
#              * Update.
# 45.0.2454.85-1:
#              02/sep/2015 by Eric Hameleers <alien@slackware.com>
#              * Update - first 45 release.
# 45.0.2454.93-1:
#              16/sep/2015 by Eric Hameleers <alien@slackware.com>
#              * Update.
# 45.0.2454.101-1:
#              25/sep/2015 by Eric Hameleers <alien@slackware.com>
#              * Update.
# 46.0.2490.71-1:
#              14/oct/2015 by Eric Hameleers <alien@slackware.com>
#              * First 46 release.
# 46.0.2490.86-1:
#              22/nov/2015 by Eric Hameleers <alien@slackware.com>
#              * Security update.
# 47.0.2526.73-1:
#              03/dec/2015 by Eric Hameleers <alien@slackware.com>
#              * First 47 release.
# 48.0.2564.82-1:
#              24/jan/2016 by Eric Hameleers <alien@slackware.com>
#              * First 48 release.
# 48.0.2564.97-1:
#              31/jan/2016 by Eric Hameleers <alien@slackware.com>
#              * Update.
# 48.0.2564.109-1:
#              13/feb/2016 by Eric Hameleers <alien@slackware.com>
#              * Update.
# 49.0.2623.75-1:
#              05/mar/2016 by Eric Hameleers <alien@slackware.com>
#              * First 49 release.  Binary plugins such as widevine and
#                pepperflash are no longer available for 32-bit since
#                Google stopped providing binaries for 32-bit Chrome.
# 49.0.2623.108-1:
#              25/feb/2016 by Eric Hameleers <alien@slackware.com>
#              * Update.
# 49.0.2623.112-1:
#              08/apr/2016 by Eric Hameleers <alien@slackware.com>
#              * Update.
# 50.0.2661.75-1:
#              14/apr/2016 by Eric Hameleers <alien@slackware.com>
#              * First 50 release.
# 50.0.2661.94-1:
#              29/apr/2016 by Eric Hameleers <alien@slackware.com>
#              * Security update.
# 50.0.2661.102-1:
#              12/may/2016 by Eric Hameleers <alien@slackware.com>
#              * Security update.
# 51.0.2704.63-1:
#              26/may/2016 by Eric Hameleers <alien@slackware.com>
#              * First 51 release.
# 51.0.2704.84-1:
#              07/jun/2016 by Eric Hameleers <alien@slackware.com>
#              * Update.
# 51.0.2704.103-1:
#              17/jun/2016 by Eric Hameleers <alien@slackware.com>
#              * Update.
# 52.0.2743.82-1:
#              24/jul/2016 by Eric Hameleers <alien@slackware.com>
#              * Update.
# 52.0.2743.116-1:
#              04/aug/2016 by Eric Hameleers <alien@slackware.com>
#              * Update.
# 53.0.2785.92-1:
#              06/sep/2016 by Eric Hameleers <alien@slackware.com>
#              * First 53 release.
# 53.0.2785.92-2:
#              12/sep/2016 by Eric Hameleers <alien@slackware.com>
#              * Apply patch required for Slackware 14.1.
# 54.0.2840.90-1:
#              03/nov/2016 by Eric Hameleers <alien@slackware.com>
#              * First 54 release. Build system changed from gyp to gn.
# 54.0.2840.100-1:
#              17/nov/2016 by Eric Hameleers <alien@slackware.com>
#              * Updated. Security fix. Removed the VAAPI patch because
#                several people have issues with it.
# 55.0.2883.75-1:
#              12/dec/2016 by Eric Hameleers <alien@slackware.com>
#              * First 55 release.
# 56.0.2924.76-1:
#              30/jan/2017 by Eric Hameleers <alien@slackware.com>
#              * First 56 release.
# 56.0.2924.76-2:
#              25/feb/2017 by Eric Hameleers <alien@slackware.com>
#              * Built for Slackware 14.1 with some additional patches.
# 57.0.2987.98-1:
#              14/mar/2017 by Eric Hameleers <alien@slackware.com>
#              * First 57 release.
# 58.0.3029.96-1:
#              04/may/2017 by Eric Hameleers <alien@slackware.com>
#              * Update to 58.
# 59.0.3071.86-1:
#              06/jun/2017 by Eric Hameleers <alien@slackware.com>
#              * Update to 59.
# 60.0.3112.78-1:
#              25/jun/2017 by Eric Hameleers <alien@slackware.com>
#              * Update to 60.
# 61.0.3163.79-1:
#              11/sep/2017 by Eric Hameleers <alien@slackware.com>
#              * Update to 61.
# 61.0.3163.100-1:
#              25/sep/2017 by Eric Hameleers <alien@slackware.com>
#              * Security update.
# 62.0.3202.62-1:
#              18/oct/2017 by Eric Hameleers <alien@slackware.com>
#              * Update to 62.
# 62.0.3202.75-1:
#              27/oct/2017 by Eric Hameleers <alien@slackware.com>
#              * Update, switch compiler to clang instead of gcc.
# 62.0.3202.94-1:
#              25/nov/2017 by Eric Hameleers <alien@slackware.com>
#              * Update.
# 63.0.3239.108-1:
#              17/dec/2017 by Eric Hameleers <alien@slackware.com>
#              * Update to 63.
# 63.0.3239.132-1:
#              07/jan/2018 by Eric Hameleers <alien@slackware.com>
#              * Update.
# 64.0.3282.119-1:
#              26/jan/2018 by Eric Hameleers <alien@slackware.com>
#              * Update to 64.
# 64.0.3282.119-2:
#              29/jan/2018 by Eric Hameleers <alien@slackware.com>
#              * Enable HEVC support.
# 64.0.3282.140-1:
#              05/feb/2018 by Eric Hameleers <alien@slackware.com>
#              * Update.
# 64.0.3282.186-1:
#              06/mar/2018 by Eric Hameleers <alien@slackware.com>
#              * Update.
# 65.0.3325.146-1:
#              09/mar/2018 by Eric Hameleers <alien@slackware.com>
#              * Update to M65.
# 65.0.3325.162-1:
#              16/mar/2018 by Eric Hameleers <alien@slackware.com>
#              * Update.
# 65.0.3325.181-1:
#              31/mar/2018 by Eric Hameleers <alien@slackware.com>
#              * Update.
# 66.0.3359.117-1:
#              25/apr/2018 by Eric Hameleers <alien@slackware.com>
#              * Update to M66.
# 66.0.3359.139-1:
#              25/apr/2018 by Eric Hameleers <alien@slackware.com>
#              * Security update (CVE-2018-6118).
# 66.0.3359.181-1:
#              18/may/2018 by Eric Hameleers <alien@slackware.com>
#              * Update.
# 67.0.3396.62-1:
#              31/may/2018 by Eric Hameleers <alien@slackware.com>
#              * Update to M67.
# 67.0.3396.79-1:
#              08/jun/2018 by Eric Hameleers <alien@slackware.com>
#              * Update.
# 67.0.3396.99-1:
#              02/jul/2018 by Eric Hameleers <alien@slackware.com>
#              * Update.
# 68.0.3440.84-1:
#              01/aug/2018 by Eric Hameleers <alien@slackware.com>
#              * Update to 68.
# 69.0.3497.81-1:
#              05/sep/2018 by Eric Hameleers <alien@slackware.com>
#              * Update to 69.
# 69.0.3497.100-1:
#              28/sep/2018 by Eric Hameleers <alien@slackware.com>
#              * Update, trying to fix pulseaudio.
# 70.0.3538.67-1:
#              24/oct/2018 by Eric Hameleers <alien@slackware.com>
#              * Update to 70.
# 70.0.3538.102-1:
#              11/nov/2018 by Eric Hameleers <alien@slackware.com>
#              * Update.
# 71.0.3578.80-1:
#              05/dec/2018 by Eric Hameleers <alien@slackware.com>
#              * Update to M71.
# 72.0.3626.81-1:
#              31/jan/2019 by Eric Hameleers <alien@slackware.com>
#              * Update to M72.
# 72.0.3626.121-1:
#              03/mar/2019 by Eric Hameleers <alien@slackware.com>
#              * Update to 72.0.3626.121.
# 73.0.3683.75-1:
#              15/mar/2019 by Eric Hameleers <alien@slackware.com>
#              * Update to M73.
# 73.0.3683.75-2:
#              17/mar/2019 by Eric Hameleers <alien@slackware.com>
#              * Fix 32bit build.
# 73.0.3683.86-1:
#              31/mar/2019 by Eric Hameleers <alien@slackware.com>
#              * Update.
# 73.0.3683.103-1:
#              14/apr/2019 by Eric Hameleers <alien@slackware.com>
#              * Update.
# 74.0.3729.108-1:
#              24/apr/2019 by Eric Hameleers <alien@slackware.com>
#              * Update to M74.
# 74.0.3729.169-1:
#              22/may/2019 by Eric Hameleers <alien@slackware.com>
#              * Update.
# 75.0.3770.80-1:
#              08/jun/2019 by Eric Hameleers <alien@slackware.com>
#              * Update to M75.
# 75.0.3770.90-1:
#              13/jun/2019 by Eric Hameleers <alien@slackware.com>
#              * Update.
# 75.0.3770.100-1:
#              20/jun/2019 by Eric Hameleers <alien@slackware.com>
#              * Update.
# 75.0.3770.100-2:
#              20/jun/2019 by Eric Hameleers <alien@slackware.com>
#              * Fix HEVC support.
# 75.0.3770.142-1:
#              15/jul/2019 by Eric Hameleers <alien@slackware.com>
#              * Update.
# 76.0.3809.87-1:
#              31/jul/2019 by Eric Hameleers <alien@slackware.com>
#              * Update to M76.
# 76.0.3809.132-1:
#              30/aug/2019 by Eric Hameleers <alien@slackware.com>
#              * Update.
# 77.0.3865.75-1:
#              11/sep/2019 by Eric Hameleers <alien@slackware.com>
#              * Update to M77.
# 77.0.3865.90-1:
#              11/sep/2019 by Eric Hameleers <alien@slackware.com>
#              * Security update.
# 77.0.3865.120-1:
#              10/oct/2019 by Eric Hameleers <alien@slackware.com>
#              * Security update.
# 78.0.3904.70-1:
#              10/oct/2019 by Eric Hameleers <alien@slackware.com>
#              * Update to M78.
# 78.0.3904.87-1:
#              01/nov/2019 by Eric Hameleers <alien@slackware.com>
#              * Critical security update.
# 78.0.3904.97-1:
#              11/nov/2019 by Eric Hameleers <alien@slackware.com>
#              * Security update.
# 78.0.3904.108-1:
#              19/nov/2019 by Eric Hameleers <alien@slackware.com>
#              * Security update.
# 79.0.3945.79-1:
#              11/dec/2019 by Eric Hameleers <alien@slackware.com>
#              * Security update.
# 79.0.3945.88-1:
#              18/dec/2019 by Eric Hameleers <alien@slackware.com>
#              * Security update.
# 79.0.3945.117-1:
#              08/jan/2020 by Eric Hameleers <alien@slackware.com>
#              * Security update.
# 79.0.3945.130-1:
#              19/jan/2020 by Eric Hameleers <alien@slackware.com>
#              * Security update.
# 80.0.3987.87-1:
#              05/feb/2020 by Eric Hameleers <alien@slackware.com>
#              * Update to M80.
# 80.0.3987.106-1:
#              14/feb/2020 by Eric Hameleers <alien@slackware.com>
#              * Updated.
# 80.0.3987.122-1:
#              27/feb/2020 by Eric Hameleers <alien@slackware.com>
#              * Updated.
# 80.0.3987.132-1:
#              04/mar/2020 by Eric Hameleers <alien@slackware.com>
#              * Updated.
# 80.0.3987.149-1:
#              18/mar/2020 by Eric Hameleers <alien@slackware.com>
#              * Updated.
# 81.0.4044.92-1:
#              08/apr/2020 by Eric Hameleers <alien@slackware.com>
#              * Update to M81.
# 
# -----------------------------------------------------------------------------
# 
# Run 'sh chromium.SlackBuild' to build a Slackware package.
# The package (.txz) and .txt file as well as build logs are created in /tmp .
# Install it using 'installpkg'. 
#
# -----------------------------------------------------------------------------

SRCNAM=chromium
SRCEXT=${SRCEXT:-""}               # could be "-dev" for development build
PRGNAM=${SRCNAM}${SRCEXT}          # chromium or chromium-dev
VERSION=${VERSION:-81.0.4044.92}
BUILD=${BUILD:-1}
TAG=${TAG:-alien}

# Cross-compiling 32bit binaries on 64bit Slackware; set to "YES":
CROSS32=${CROSS32:-"NO"}

# Differentiate between stable and development releases:
if [ "x$SRCEXT" = "x-dev" ]; then
  CRFLAGS="CHROMIUM_DEV_FLAGS"
  CRUSERFLAGS="CHROMIUM_DEV_USER_FLAGS"
else
  CRFLAGS="CHROMIUM_FLAGS"
  CRUSERFLAGS="CHROMIUM_USER_FLAGS"
fi

# If pulseaudio is installed we support it unless you explicitly disable it:
if /usr/bin/pkg-config --exists libpulse 2>/dev/null ; then
  USE_PA=${USE_PA:-1}
else
  USE_PA=${USE_PA:-0}
fi

# Build Chromium using a debian sysroot for Slackware 14.2 or older:
USE_SYSROOT=${USE_SYSROOT:-0}

# By default the ffmpeg and other component libraries are built statically
# into the chromium binary.  This takes more time at the linking stage but
# will speed up the browser's startup.
# You can instead build shared libraries, among which will be libffmpeg.so
# (formerly libffmpegsumo.so) if you want to be able to swap the libffmpeg.so
# library for someone else's library with more features:
SHARED_FFMPEG=${SHARED_FFMPEG:-false} # other option is 'true'

# The branding determines what (proprietary) codec support will be added:
FFMPEG_BRANDING=${FFMPEG_BRANDING:-Chrome} # or "ChromeOS", or "Chromium"

# HEVC support. Set to '0' to disable, '1' to enable:
FFMPEG_HEVC=${FFMPEG_HEVC:-1}

# You can build with NaCl (native client) if you set USE_NACL to "1",
# and gain some Chrome functionality like using in-browser applications.
# Note that NaCl is only supported on 64bit, and will be obsoleted in 2018
# in favor of WebAssembly:
USE_NACL=${USE_NACL:-0}

# Use the clang compiler. Results in faster build and smaller binaries.
# This default to "1" (on) because gcc support is getting stale
# and the gcc of Slackware 14.2 is already too old.
# This script will compile google's modified clang from source, so that 32bit
# can be supported (Google offers only 64bit pre-built clang for download0:
USE_CLANG=${USE_CLANG:-1}

# If you don't want to enable support for Widevine CDM
# (content decryption module) say "0" here.
USE_CDM=${USE_CDM:-1}

# If you are OK with the "OK Google" hotwording feature which will
# automatically download a binary blob with proprietary code, set this to "1".
# Some people object to a download without consent so it is disabled by default:
USE_HOTWORD=${USE_HOTWORD:-0}

DOCS="AUTHORS BUILD.gn CODE_OF_CONDUCT.md DEPS LICENSE* OWNERS WATCHLISTS README*"

# Where do we look for sources?
SRCDIR=$(cd $(dirname $0); pwd)

# Place to build (TMP) package (PKG) and output (OUTPUT) the program:
TMP=${TMP:-/tmp/build}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

# Visible directory listing of anything Chrome related is:
#   http://gsdview.appspot.com/
# Official location (non-browsable) of the above is:
#   https://commondatastorage.googleapis.com/

# This package is built with Alien's Google API keys for Chromium.
# The keys are contained in the file "chromium_apikeys".
# If you want to rebuild this package, you can use my API keys, however:
# you are not allowed to re-distribute these keys!!
# You can also obtain your own, see:
#   http://www.chromium.org/developers/how-tos/api-keys
# Or else you can simply compile without API keys. This will disable stuff like
# browser sync and other functionality which accesses Google APIs. 
# The following variables must be set:
#   _google_api_key
#   _google_default_client_id
#   _google_default_client_secret
if [ -f ${HOME}/.chromium_apikeys ]; then
  . ${HOME}/.chromium_apikeys
elif [ -f ${SRCDIR}/chromium_apikeys ]; then
  . ${SRCDIR}/chromium_apikeys
else
  _google_api_key=" "
  _google_default_client_id=" "
  _google_default_client_secret=" "
  cat <<EOT
No values were defined for the following variables:
   _google_api_key
   _google_default_client_id
   _google_default_client_secret
Please supply your own Google API keys for Chromium!
Press Ctrl-C to abort this script or wait 10 seconds to continue anyway.
EOT
sleep 10
fi

##
## --- with a little luck, you won't have to edit below this point --- ##
##

# Automatically determine the architecture we're building on:
MARCH=$( uname -m )
if [ -z "$ARCH" ]; then
  case "$MARCH" in
    i?86)    export ARCH=i586 ;;
    armv7hl) export ARCH=$MARCH ;;
    armv6hl) export ARCH=$MARCH ;;
    arm*)    export ARCH=arm ;;
    # Unless $ARCH is already set, use uname -m for all other archs:
    *)       export ARCH=$MARCH ;;
  esac
fi

case "$ARCH" in
  i?86)      SLKCFLAGS="-O2 -march=${ARCH} -mtune=i686"
             # Fix for using lld while linking chromium in a 32bit chroot:
             SLKLDFLAGS="-Wl,-z,notext"; LIBDIRSUFFIX=""
             DSSE="1"
             FFMPEG_ARCH="ia32"
             SYSROOT_ARCH="i386"
             SYSROOT_TARGET="i386"
             PKGARCH="$ARCH"
             ;;
  x86_64)    # Ensure that 32bit libraries are found first if we cross-compile:
             if [ "${CROSS32}" = "YES" ]; then
               SLKCFLAGS="-O2"
               SLKLDFLAGS="-L/usr/lib"; LIBDIRSUFFIX=""
               FFMPEG_ARCH="ia32"
               SYSROOT_ARCH="i386"
               SYSROOT_TARGET="i386"
               PKGARCH="i586"
             else
               SLKCFLAGS="-O2 -fPIC"
               SLKLDFLAGS="-L/usr/lib64"; LIBDIRSUFFIX="64"
               FFMPEG_ARCH="x64"
               SYSROOT_ARCH="amd64"
               SYSROOT_TARGET="x86_64"
               PKGARCH="$ARCH"
             fi
             #DSSE="0"
             DSSE="1"
             ;;
  armv7hl)   SLKCFLAGS="-O2 -march=armv7-a -mfpu=vfpv3-d16"
             SLKLDFLAGS=""; LIBDIRSUFFIX=""
             DSSE="1"
             # Widevine not supported (no binary library available):
             USE_CDM=0
             FFMPEG_ARCH="arm"
             SYSROOT_ARCH="arm"
             SYSROOT_TARGET="arm"
             PKGARCH="$ARCH"
             ;;
  armv6hl)   SLKCFLAGS="-O2 -march=armv6 -mfpu=vfp -mfloat-abi=hard"
             SLKLDFLAGS=""; LIBDIRSUFFIX=""
             DSSE="1"
             # Widevine not supported (no binary library available):
             USE_CDM=0
             FFMPEG_ARCH="arm"
             SYSROOT_ARCH="arm"
             SYSROOT_TARGET="arm"
             PKGARCH="$ARCH"
             ;;
  *)         SLKCFLAGS=${SLKCFLAGS:-"O2"}
             SLKLDFLAGS=${SLKLDFLAGS:-""}; LIBDIRSUFFIX=${LIBDIRSUFFIX:-""}
             DSSE="1"
             # Widevine not supported by default:
             USE_CDM=0
             FFMPEG_ARCH="$ARCH"
             SYSROOT_ARCH="$ARCH"
             SYSROOT_TARGET="$ARCH"
             PKGARCH="$ARCH"
             ;;
esac

case "$ARCH" in
    arm*)    TARGET=$ARCH-slackware-linux-gnueabi ;;
    *)       TARGET=$ARCH-slackware-linux ;;
esac

# Exit the script on errors:
set -e
trap 'echo "$0 FAILED at line ${LINENO}" | tee $OUTPUT/error-${PRGNAM}.log' ERR
# Catch unitialized variables:
set -u
P1=${1:-1}

# Save old umask and set to 0022:
_UMASK_=$(umask)
umask 0022

# Source locations:
SOURCE[0]="$SRCDIR/${SRCNAM}-${VERSION}.tar.xz"
SRCURL[0]="https://commondatastorage.googleapis.com/${SRCNAM}-browser-official/${SRCNAM}-${VERSION}.tar.xz"

SOURCE[1]="$SRCDIR/widevine-versions.txt"
SRCURL[1]="https://dl.google.com/widevine-cdm/versions.txt"

# Create working directories:
mkdir -p $OUTPUT          # place for the package to be saved
mkdir -p $TMP/tmp-$PRGNAM # location to build the source
mkdir -p $PKG             # place for the package to be built
rm -rf $PKG/*             # always erase old package's contents
rm -rf $TMP/tmp-$PRGNAM/* # remove the remnants of previous build
rm -rf $OUTPUT/{configure,make,install,error,makepkg,patch}-$PRGNAM.log
                          # remove old log files

# Source file availability:
for (( i = 0; i < ${#SOURCE[*]}; i++ )) ; do
  if ! [ -f ${SOURCE[$i]} ]; then
    echo "Source '$(basename ${SOURCE[$i]})' not available yet..."
    # Check if the $SRCDIR is writable at all - if not, download to $OUTPUT
    [ -w "$SRCDIR" ] || SOURCE[$i]="$OUTPUT/$(basename ${SOURCE[$i]})"
    if [ -f ${SOURCE[$i]} ]; then echo "Ah, found it!"; continue; fi
    if ! [ "x${SRCURL[$i]}" == "x" ]; then
      echo "Will download file to $(dirname $SOURCE[$i])"
      wget --no-check-certificate -nv -T 20 -O "${SOURCE[$i]}" "${SRCURL[$i]}" || true
      if [ $? -ne 0 -o ! -s "${SOURCE[$i]}" ]; then
        echo "Fail to download '$(basename ${SOURCE[$i]})'. Aborting the build."
        mv -f "${SOURCE[$i]}" "${SOURCE[$i]}".FAIL
        exit 1
      fi
    else
      echo "File '$(basename ${SOURCE[$i]})' not available. Aborting the build."
      exit 1
    fi
  fi
done

if [ "$P1" == "--download" ]; then
  echo "Download complete."
  exit 0
fi

# --- PACKAGE BUILDING ---

echo "++"
echo "|| $PRGNAM-$VERSION"
echo "++"

# Find the version of Widevine:
WIDEVINE_VERSION="$(cat ${SOURCE[1]}|tail -1)"

cd $TMP/tmp-$PRGNAM
echo "Extracting the source archive(s) for $PRGNAM..."
tar -xf ${SOURCE[0]}
cd ${SRCNAM}-${VERSION}

# Allow building against system libraries in official builds:
sed -e 's/OFFICIAL_BUILD/GOOGLE_CHROME_BUILD/' \
  -i tools/generate_shim_headers/generate_shim_headers.py
# Patches and bug fixes:
touch $OUTPUT/patch-${PRGNAM}.log
# Fix the link on 32bit:
sed -e '/ldflags /s/-m32/&", "-Wl,-z,notext/' \
  -i build/config/compiler/BUILD.gn
  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}.log
# Slackware specific:
# When compiling google's clang on 32bit Slackware use 'i586' in the triplet.
# I am a python noob so this is clumsy, better implementation is welcome :-)
cp $SRCDIR/patches/clang.toolchains.i586.triple.diff .
cat $SRCDIR/patches/chromium_32bit_triplet.patch | patch -p1 --verbose \
  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}.log
# Don't crap out when gzip does not support '--rsyncable' (Slackware < 14.2):
if ! gzip --help |grep -q rsyncable ; then
  cat $SRCDIR/patches/chromium_no_rsyncable.patch | patch -p1 --verbose \
    2>&1 | tee -a $OUTPUT/patch-${PRGNAM}.log
fi
if [ $FFMPEG_HEVC -eq 1 ]; then
  # Add essential proprietary codecs to the "chrome" branding of ffmpeg:
  cat $SRCDIR/patches/chromium_ffmpeg_prop.patch | patch -p1 --verbose \
    2>&1 | tee -a $OUTPUT/patch-${PRGNAM}.log
  ## Advertize HEVC/X.265 support (won't work at the moment):
  #cat $SRCDIR/patches/chromium_hevc_supported.patch | patch -p1 --verbose \
  #  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}.log
fi
## Enable VAAPI hardware decoding on Linux platform:
#cat $SRCDIR/patches/chromium_vaapi.patch | patch -p1 --verbose \
#  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}.log

# Also needed for Slackware <= 14.2:
if [ $(LC_ALL=C gcc -dumpversion |cut -d. -f1) -eq 4 ]; then
  cat $SRCDIR/patches/chromium56_gcc4.patch | patch -p1 --verbose \
    2>&1 | tee -a $OUTPUT/patch-${PRGNAM}.log
fi

# When compiling google's clang, we want 32bit too - don't limit us, devs:
sed -i tools/clang/scripts/build.py -e "s/x86_64-unknown-linux-gnu/$TARGET/g"

# When compiling google's clang, use the system cmake
# (prebuilt binary from google is only available as 64bit):
sed -i tools/clang/scripts/build.py -e 's/^ *AddCMakeToPath/#&/'

## Explicitly use Python 2:
#find . -name '*.py' -exec sed -i -r 's|/usr/bin/python$|&2|g' {} +
## The above does not solve every invocation of python:
#mkdir -p $TMP/tmp-$PRGNAM/privatebin
#ln -sf /usr/bin/python2 $TMP/tmp-$PRGNAM/privatebin/python

# Force script incompatible with Python 3 to use /usr/bin/python2:
sed -i '1s|python$|&2|' third_party/dom_distiller_js/protoc_plugins/*.py

# Prevent a build failure (yes, 'x64' even on 32bit Slackware):
mkdir -p third_party/node/linux/node-linux-x64/bin
ln -s /usr/bin/node third_party/node/linux/node-linux-x64/bin/

if [ "$ARCH" != "x86_64" -a "$USE_NACL" != "0" ]; then
  # For now, disable NaCl except on x86_64 because the precompiled toolchain is
  # only available for that architecture at the moment.
  echo "** Not building NaCL - architecture '$ARCH' is currently unsupported."
  USE_NACL=0
fi

if [ $USE_CDM -eq 1 ]; then
  # Add support for widevine cdm to this build.
  # Note that the resulting Slackware package will *not* include the
  # proprietary Widevine CDM, only the adapter library which is built from OSS.
  # To compile, we just add one #define - see https://crbug.com/473866
  sed '14i#define WIDEVINE_CDM_VERSION_STRING "'$WIDEVINE_VERSION'"' \
    -i third_party/widevine/cdm/widevine_cdm_version.h
  # From M67 to M70 we also need to explicitly enable linux as supported OS:
  #sed -e 's/assert(!enable_widevine || is_win || is_mac || is_chromecast/& || is_linux/' \
  #  -i third_party/widevine/cdm/BUILD.gn
  # From M71 we need to change another #define:
  #sed 's/BUILDFLAG(BUNDLE_WIDEVINE_CDM)/BUILDFLAG(ENABLE_WIDEVINE)/' \
  #  -i chrome/common/chrome_content_client.cc
  # From M79 we need to change this again, Chromium is supposed to download
  # the CDM now but actually it does not work:
  sed 's/BUNDLE_WIDEVINE_CDM=$bundle_widevine_cdm/BUNDLE_WIDEVINE_CDM=true/' \
    -i third_party/widevine/cdm/BUILD.gn
fi

if [ "x$SRCEXT" = "x-dev" ]; then
  # Save configuration in ~/.config/chromium-dev":
  sed -e 's|filename = "chromium-browser"|filename = "chromium-dev"|' \
      -e 's|confdir = "chromium|&-dev|' \
      -i chrome/BUILD.gn
  sed -e 's|config_dir.Append("chromium|&-dev|' \
      -i chrome/common/chrome_paths_linux.cc
  sed -e 's|/etc/chromium|&-dev|' \
      -e 's|/usr/share/chromium|&-dev|' \
      -i chrome/common/chrome_paths.cc
  sed -e 's|/etc/chromium|&-dev|' \
      -i components/policy/tools/template_writers/writer_configuration.py
fi

chown -R root:root .
chmod -R u+w,go+r-w,a+X-s .

echo Building ...

[ ${USE_CLANG} -eq 1 ] && do_clang=true || do_clang=false
[ ${USE_CDM} -eq 1 ] && do_cdm=true || do_cdm=false
[ ${USE_HOTWORD} -eq 1 ] && do_hotword=true || do_hotword=false
[ ${USE_NACL} -eq 1 ] && do_nacl=true || do_nacl=false
[ ${USE_PA} -eq 1 ] && do_pa=true || do_pa=false
[ ${USE_SYSROOT} -eq 1 ] && do_sysroot=true || do_sysroot=false
[ ${FFMPEG_HEVC} -eq 1 ] && do_hevc=true || do_hevc=false 

export LDFLAGS="$SLKLDFLAGS"
export CXXFLAGS="$SLKCFLAGS -Wno-unknown-warning-option"
export CFLAGS="$SLKCFLAGS -Wno-unused-local-typedefs -Wno-unknown-warning-option"
export PATH="$TMP/tmp-$PRGNAM/privatebin:$PATH"

# After building gn, run:
# "./out/Release/gn args out/Release --list"
# for a list of all variables.
_chromium_conf=(
    "clang_use_chrome_plugins=${do_clang}"
    'enable_hangout_services_extension=true'
    'enable_hidpi=true'
    "enable_hotwording=${do_hotword}"
    "enable_nacl=${do_nacl}"
    "enable_nacl_nonsfi=${do_nacl}"
    'enable_pepper_cdms=true'
    "enable_platform_hevc=${do_hevc}"
    'enable_platform_ac3_eac3_audio=true'
    'enable_platform_mpeg_h_audio=true'
    'enable_platform_dolby_vision=true'
    'enable_precompiled_headers=false'
    'enable_swiftshader=true'
    'enable_webrtc=true'
    "enable_widevine=${do_cdm}"
    'exclude_unwind_tables=true'
    'fatal_linker_warnings=false'
    "ffmpeg_branding=\"${FFMPEG_BRANDING}\""
    'fieldtrial_testing_like_official_build=true'
    "google_api_key=\"$_google_api_key\""
    "google_default_client_id=\"$_google_default_client_id\""
    "google_default_client_secret=\"$_google_default_client_secret\""
    "is_clang=${do_clang}"
    'is_debug=false'
    "is_component_build=${SHARED_FFMPEG}"
    "is_component_ffmpeg=${SHARED_FFMPEG}"
    "link_pulseaudio=${do_pa}"
    "linux_sandbox_path=\"/usr/lib${LIBDIRSUFFIX}/${PRGNAM}/chrome_sandbox\""
    'linux_strip_binary=true'
    'linux_use_bundled_binutils=false'
    'logging_like_official_build=true'
    'proprietary_codecs=true'
    'remove_webcore_debug_symbols=true'
    'symbol_level=0'
    'treat_warnings_as_errors=false'
    "usb_ids_path=\"/usr/share/hwdata/usb.ids\""
    'use_allocator="none"'
    'use_bundled_fontconfig=false'
    'use_cfi_icall=false' # https://crbug.com/866290
    'use_cups=true'
    'use_custom_libcxx=true'
    'use_gconf=false'
    'use_kerberos=false'
    'use_lld=true'
    "use_pulseaudio=${do_pa}"
    "use_sysroot=${do_sysroot}"
    "extra_cxxflags=\"${CXXFLAGS}\""
    "extra_ldflags=\"${LDFLAGS}\""
)
    # For older Slackware:
    #'use_system_libdrm=false'
    #'use_system_minigbm=false'

if [ "${CROSS32}" = "YES" ]; then
  _chromium_conf=("${_chromium_conf[@]}" 'target_cpu="x86"')
fi

    # Change this back when CRBUG 592268 is fixed (error during final link:
    # undefined reference to `base::i18n::GetRawIcuMemory())
    # See https://bugs.chromium.org/p/chromium/issues/detail?id=592268
    # icu_use_data_file_flag=false

gn_system_libraries=(
  # 'bzip2'
  # 'ffmpeg'
  # 'flac'
  # 'freetype2'
  # 'harfbuzz'
  # 'icu'
  # 'libdrm'
  # 'libevent'
  # 'libjpeg'
  # 'libpng'
  # 'libvpx'
  # 'libwebp'
  # 'libxml'
  # 'libxslt'
  # 'opus'
  # 're2'
  # 'snappy'
  'yasm'
  # 'zlib'
  )

# Unbundle the libraries which we use from the system.
# (taken from Arch Linux:)
# This *should* do what the remove_bundled_libraries.py script does,
# with the added benefit of not having to list all the remaining libraries:
echo "-- Unbundling system libraries from $PRGNAM sources."
for ULIB in ${gn_system_libraries[@]}; do
  find -type f -path "*third_party/$ULIB/*" \
    \! -path "*third_party/$ULIB/chromium/*" \
    \! -path "*third_party/$ULIB/google/*" \
    \! -path '*third_party/yasm/run_yasm.py' \
    \! -regex '.*\.\(gn\|gni\|isolate\)' \
    -delete
done

# Change bundled libraries to system ones:
echo "-- Change bundled to system libraries in $PRGNAM sources."
python2 build/linux/unbundle/replace_gn_files.py --system-libraries ${gn_system_libraries[@]}

# Do not make the build fail, see Chromium issue #386097:
python2 third_party/libaddressinput/chromium/tools/update-strings.py \
  2>&1 | tee $OUTPUT/update_strings-${PRGNAM}.log

# Use usb.ids at run time instead of compiling it in:
sed -i services/device/public/cpp/usb/BUILD.gn \
  -e 's|//third_party/usb_ids/usb.ids|/usr/share/hwdata/usb.ids|g'

# Do not make the build fail, see https://groups.google.com/a/chromium.org/d/topic/chromium-packagers/9JX1N2nf4PU/discussion :
touch chrome/test/data/webui/i18n_process_css_test.html

# Do not make the build fail:
if [ ! -f chrome/test/data/webui_test_resources.grd ]; then
cat <<EOF >chrome/test/data/webui_test_resources.grd
<?xml version="1.0" encoding="UTF-8"?>
<grit latest_public_release="0" current_release="1">
  <outputs>
    <output filename="chrome/test/data/grit/webui_test_resources.h" type="rc_header">
      <emit emit_type='prepend'></emit>
    </output>
    <output filename="webui_test_resources.pak" type="data_package" />
  </outputs>
  <release seq="1">
  </release>
</grit>
EOF
fi

# Download the NaCL toolchains:
if [ ${USE_NACL} -eq 1 ]; then
  # We do not need arm_trusted on x86:
  echo "-- Downloading NaCL toolchains."
  python2 build/download_nacl_toolchains.py --packages nacl_x86_newlib,pnacl_newlib,pnacl_translator sync --extract \
    2>&1 | tee $OUTPUT/nacl_dl-${PRGNAM}.log
fi

if [ ${USE_SYSROOT} -eq 1 ]; then
  # Download a sysroot image:
  python2 build/linux/sysroot_scripts/install-sysroot.py --arch=${SYSROOT_ARCH}

  # Take care of Debian/Ubuntu related missing header issues:
  SYSROOTDIR=$(basename $(ls build/linux/ |grep ${SYSROOT_ARCH}-sysroot))

  ln -s ../../lib/${SYSROOT_TARGET}-linux-gnu/glib-2.0/include/glibconfig.h \
    build/linux/${SYSROOTDIR}/usr/include/glib-2.0/glibconfig.h
  ln -s ../../../lib/${SYSROOT_TARGET}-linux-gnu/dbus-1.0/include/dbus/dbus-arch-deps.h \
    build/linux/${SYSROOTDIR}/usr/include/dbus-1.0/dbus/dbus-arch-deps.h
  ln -s ../../lib/${SYSROOT_TARGET}-linux-gnu/graphene-1.0/include/graphene-config.h \
    build/linux/${SYSROOTDIR}/usr/include/graphene-1.0/graphene-config.h

  # Take care of Debian/Ubuntu related linker issues:
  echo "/usr/lib/${SYSROOT_TARGET}-linux-gnu/nss" >> \
    build/linux/${SYSROOTDIR}/etc/ld.so.conf.d/${SYSROOT_TARGET}-linux-gnu.conf
  ln -s libsqlite3.so.0 \
    build/linux/${SYSROOTDIR}/usr/lib/${SYSROOT_TARGET}-linux-gnu/libsqlite3.so
fi

# --- Compile --- #

# Final link uses lots of file descriptors.
ulimit -n 2048

# Compile google's internal clang sources if needed
# (clang is required for building NaCl):
if [ ${USE_CLANG} -eq 1 -o ${USE_NACL} -eq 1 ]; then
  # Build clang from source instead of downloading:
  echo "-- Building google's clang toolchain."
  python2 tools/clang/scripts/build.py \
    --bootstrap --lto-lld \
    --disable-asserts \
    --gcc-toolchain /usr \
    --skip-checkout \
    --use-system-cmake \
    --without-android \
    --without-fuchsia \
    2>&1 | tee $OUTPUT/clang_build-${PRGNAM}.log
    #--llvm-force-head-revision \
fi

# Ensure that only this new clang is used, ignoring the system version:
MYCLANG_PATH="$TMP/tmp-$PRGNAM/${SRCNAM}-${VERSION}/third_party/llvm-build/Release+Asserts/bin"
export PATH="$MYCLANG_PATH:$PATH"

# Re-configure bundled ffmpeg to make it compile on 32bit Slackware:
if [ ${FFMPEG_HEVC} -eq 1 -o "${FFMPEG_ARCH}" = "ia32" ]; then
  echo "-- Re-configuring bundled ffmpeg..."
  if [ ${FFMPEG_HEVC} -eq 1 ]; then
    echo "  +- Adding HEVC support..."
    FFMPEG_CUSTOM_ARGS="--enable-decoder=hevc --enable-demuxer=hevc --enable-parser=hevc"
  else
    FFMPEG_CUSTOM_ARGS=""
  fi
  if [ "${FFMPEG_ARCH}" = "ia32" ]; then
    echo "  +- Disabling assembler code..."
    FFMPEG_CUSTOM_ARGS="${FFMPEG_CUSTOM_ARGS} --disable-asm"
  fi
  cd third_party/ffmpeg
    ## To prevent error on x86_64:
    ## "clang-5.0: error: invalid linker name in argument '-fuse-ld=lld'" 
    ## in third_party/ffmpeg/build.x64.linux/ChromeOS/ffbuild/config.log
    #sed -e "s/--extra-ldflags=-fuse-ld=lld/--extra-ldflags=''/" \
    #    -i chromium/scripts/build_ffmpeg.py
    # Actual reconfigure steps:
    PATH="$MYCLANG_PATH:${PATH}" \
    python2 chromium/scripts/build_ffmpeg.py linux ${FFMPEG_ARCH} \
      --branding ${FFMPEG_BRANDING} -- ${FFMPEG_CUSTOM_ARGS} \
      2>&1 | tee $OUTPUT/ffmpeg_configure-${PRGNAM}.log
    ./chromium/scripts/copy_config.sh \
      2>&1 | tee -a $OUTPUT/ffmpeg_configure-${PRGNAM}.log
    ./chromium/scripts/generate_gn.py \
      2>&1 | tee -a $OUTPUT/ffmpeg_configure-${PRGNAM}.log
  cd - 2>/dev/null
fi

# Generate the ninja build files:
echo "-- Bootstrapping 'gn'."

# Symlink ld to lld to make gn linking stage succeed:
cd $MYCLANG_PATH ; ln -s lld ld ; cd - 1>/dev/null

LDFLAGS="$LDFLAGS" python2 tools/gn/bootstrap/bootstrap.py \
  2>&1 | tee $OUTPUT/gyp-${PRGNAM}.log
  #--use-custom-libcxx \

# Remove symlink again:
rm $MYCLANG_PATH/ld

echo "-- Generating ninja build files."
out/Release/gn gen out/Release -v --args="${_chromium_conf[*]}" \
  --script-executable=/usr/bin/python2 \
  2>&1 | tee -a $OUTPUT/gyp-${PRGNAM}.log

# Compile everything:
echo "-- Compiling the lot."

if [ "$USE_CLANG" = "1" ]; then
  # Use the clang that we build in-tree instead of using the system version:
  export CC="$MYCLANG_PATH/clang"
  export CXX="$MYCLANG_PATH/clang++"
  export LD="$MYCLANG_PATH/lld"
  #unset CC
  #unset CXX
else
  # Be careful not to override CC and CXX (may have been set by gcc5):
  export CC=${CC:-"gcc"}
  export CXX=${CXX:-"g++"}
fi
export AS=as
export AR=ar

LDFLAGS="$LDFLAGS" \
LC_ALL=C \
ninja -C out/Release \
  pdf chrome chrome_sandbox chromedriver \
  2>&1 | tee $OUTPUT/ninja-${PRGNAM}.log

# Manually install everything:
echo "-- Manually installing everything."

# The main binary:
install -D out/Release/chrome $PKG/usr/lib${LIBDIRSUFFIX}/${PRGNAM}/${PRGNAM}

# The sandbox:
install -D -m4755 -o root -g root out/Release/chrome_sandbox \
  $PKG/usr/lib${LIBDIRSUFFIX}/${PRGNAM}/chrome-sandbox

# The Chromium implementation of the WebDriver wire protocol
# (automated testing of web apps):
install -D out/Release/chromedriver $PKG/usr/lib${LIBDIRSUFFIX}/${PRGNAM}/chromedriver

# Copy libraries:
for CRLIB in {libEGL,libGLESv2,libVkICD_mock_icd,libvk_swiftshader}.so
 do
  install -D -m0755 -o root -g root out/Release/$CRLIB \
    $PKG/usr/lib${LIBDIRSUFFIX}/${PRGNAM}/$CRLIB
done

# Copy over the remaining binaries:
cp -a \
  out/Release/{swiftshader,MEIPreload,angledata} \
  $PKG/usr/lib${LIBDIRSUFFIX}/${PRGNAM}/
cp -a \
  out/Release/*.pak \
  $PKG/usr/lib${LIBDIRSUFFIX}/${PRGNAM}/
if [ -f out/Release/libffmpeg*.so ]; then
  cp -a \
    out/Release/libffmpeg*.so* \
    $PKG/usr/lib${LIBDIRSUFFIX}/${PRGNAM}/
elif [ -f out/Release/lib/libffmpeg.so ]; then
  mkdir -p $PKG/usr/lib${LIBDIRSUFFIX}/${PRGNAM}/lib/
  cp -a \
    out/Release/lib/libffmpeg.so* \
    $PKG/usr/lib${LIBDIRSUFFIX}/${PRGNAM}/lib/
fi
for BLOB in out/Release/{natives_blob.bin,snapshot_blob.bin,v8_context_snapshot.bin};
do
  if [ -f $BLOB ]; then
    cp -a $BLOB $PKG/usr/lib${LIBDIRSUFFIX}/${PRGNAM}/
  fi
done
if [ ${USE_NACL} -eq 1 ]; then
  # Native Client files:
  cp -a \
    out/Release/nacl_helper{,_bootstrap,_nonsfi} \
    out/Release/nacl_irt_*.nexe \
    $PKG/usr/lib${LIBDIRSUFFIX}/${PRGNAM}/
fi

# Manually strip binaries so that 'nacl_irt_*.nexe' is left intact
strip  --strip-unneeded \
  $PKG/usr/lib${LIBDIRSUFFIX}/${PRGNAM}/{${PRGNAM},chrome-sandbox} \
  $PKG/usr/lib${LIBDIRSUFFIX}/${PRGNAM}/chromedriver
strip  --strip-unneeded \
  $PKG/usr/lib${LIBDIRSUFFIX}/${PRGNAM}/*.so
if [ -f $PKG/usr/lib${LIBDIRSUFFIX}/${PRGNAM}/lib/libffmpeg*.so ]; then
  strip  --strip-unneeded \
    $PKG/usr/lib${LIBDIRSUFFIX}/${PRGNAM}/lib/lib*.so
fi
if [ ${USE_NACL} -eq 1 ]; then
  strip  --strip-unneeded \
    $PKG/usr/lib${LIBDIRSUFFIX}/${PRGNAM}/nacl_helper{,_bootstrap,_nonsfi}
fi

# Add locales:
cp -a out/Release/locales $PKG/usr/lib${LIBDIRSUFFIX}/${PRGNAM}/
ln -s locales $PKG/usr/lib${LIBDIRSUFFIX}/${PRGNAM}/remoting_locales

# Add resource files:
cp -a out/Release/resources $PKG/usr/lib${LIBDIRSUFFIX}/${PRGNAM}/

# This step used to be done for us, now do it manually too.
# This script's 'process_template' function is needed in order
# to generate man page and desktop file:
source $TMP/tmp-$PRGNAM/${SRCNAM}-${VERSION}/chrome/installer/linux/common/installer.include
PACKAGE=${PRGNAM}
PROGNAME=${PRGNAM}
MENUNAME="${PRGNAM^} Web Browser"
USR_BIN_SYMLINK_NAME=${PRGNAM}

# Install a man page:
process_template chrome/app/resources/manpage.1.in out/Release/${PRGNAM}.1
install -D -m0644 out/Release/${PRGNAM}.1 $PKG/usr/man/man1/${PRGNAM}.1

# Add a desktop file:
process_template chrome/installer/linux/common/desktop.template \
  out/Release/${PRGNAM}.desktop
install -D -m0644 out/Release/${PRGNAM}.desktop \
  $PKG/usr/share/applications/${PRGNAM}.desktop

# Install desktop icons:
for size in 16 32; do
  install -D -m0644 \
    chrome/app/theme/default_100_percent/chromium/product_logo_$size.png \
    $PKG/usr/share/icons/hicolor/${size}x${size}/apps/${PRGNAM}.png
    ln -s ${PRGNAM}.png \
      $PKG/usr/share/icons/hicolor/${size}x${size}/apps/chromium-browser${SRCEXT}.png
done
for size in 24 48 64 128 256; do
  install -D -m0644 \
    chrome/app/theme/chromium/product_logo_$size.png \
    $PKG/usr/share/icons/hicolor/${size}x${size}/apps/${PRGNAM}.png
    ln -s ${PRGNAM}.png \
      $PKG/usr/share/icons/hicolor/${size}x${size}/apps/chromium-browser${SRCEXT}.png
done

# Without this file, chromium refuses to start:
cp -a out/Release/icudtl.dat $PKG/usr/lib${LIBDIRSUFFIX}/${PRGNAM}/

# Install a wrapper script:
install -D -m0755 $SRCDIR/${PRGNAM}.sh $PKG/usr/bin/${PRGNAM}
sed \
    -e "s/@PRGNAM@/${PRGNAM}/g" \
    -e "s/@SRCEXT@/${SRCEXT}/g" \
    -e "s/@LIBDIRSUFFIX@/${LIBDIRSUFFIX}/g" \
    -e "s/@CRFLAGS@/${CRFLAGS}/g" \
    -e "s/@CRUSERFLAGS@/${CRUSERFLAGS}/g" \
    -i $PKG/usr/bin/${PRGNAM}

# Make the chromedriver available in the $PATH :
ln -s ../lib${LIBDIRSUFFIX}/${PRGNAM}/chromedriver $PKG/usr/bin/chromedriver${SRCEXT}

# xdg-utils looks for "chromium-browser" so symlink it to the wrapper:
ln -s ${PRGNAM} $PKG/usr/bin/chromium-browser${SRCEXT}

# Move the 'default' file into place.
# This allows users to override command-line options:
mkdir -p $PKG/etc/${PRGNAM}
cat $SRCDIR/${PRGNAM}.default | sed \
  -e "s/@PRGNAM@/${PRGNAM}/g" \
  -e "s/@SRCEXT@/${SRCEXT}/g" \
  -e "s/@CRFLAGS@/${CRFLAGS}/g" \
  -e "s/@CRUSERFLAGS@/${CRUSERFLAGS}/g" \
  -e "s/@LIBDIRSUFFIX@/${LIBDIRSUFFIX}/g" \
  > $PKG/etc/${PRGNAM}/00-default.conf.new

# Add this to the doinst.sh:
mkdir -p $PKG/install
cat <<EOINS >> $PKG/install/doinst.sh
# Handle the incoming configuration files:
config() {
  for infile in \$1; do
    NEW="\$infile"
    OLD="\`dirname \$NEW\`/\`basename \$NEW .new\`"
    # If there's no config file by that name, mv it over:
    if [ ! -r \$OLD ]; then
      mv \$NEW \$OLD
    elif [ "\`cat \$OLD | md5sum\`" = "\`cat \$NEW | md5sum\`" ]; then
      # toss the redundant copy
      rm \$NEW
    fi
    # Otherwise, we leave the .new copy for the admin to consider...
  done
}

config etc/${PRGNAM}/00-default.conf.new

# Update the desktop database:
if [ -x usr/bin/update-desktop-database ]; then
  chroot . /usr/bin/update-desktop-database usr/share/applications > /dev/null 2>&1
fi

# Update hicolor theme cache:
if [ -d usr/share/icons/hicolor ]; then
  if [ -x /usr/bin/gtk-update-icon-cache ]; then
    chroot . /usr/bin/gtk-update-icon-cache -f -t usr/share/icons/hicolor 1> /dev/null 2> /dev/null
  fi
fi

# Update the mime database:
if [ -x usr/bin/update-mime-database ]; then
  chroot . /usr/bin/update-mime-database usr/share/mime >/dev/null 2>&1
fi

EOINS

# Add documentation:
mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
cp -a $DOCS $PKG/usr/doc/$PRGNAM-$VERSION || true
mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION/patches
cp -a $SRCDIR/patches/*.{diff,patch} $PKG/usr/doc/$PRGNAM-$VERSION/patches/
cat $SRCDIR/$(basename $0) > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild
chown -R root:root $PKG/usr/doc/$PRGNAM-$VERSION
find $PKG/usr/doc -type f -exec chmod 644 {} \;

# Compress the man page(s):
if [ -d $PKG/usr/man ]; then
  find $PKG/usr/man -type f -name "*.?" -exec gzip -9f {} \;
  for i in $(find $PKG/usr/man -type l -name "*.?") ; do ln -s $( readlink $i ).gz $i.gz ; rm $i ; done
fi

# Add a package description:
mkdir -p $PKG/install
cat $SRCDIR/slack-desc${SRCEXT} > $PKG/install/slack-desc

# Build the package:
cd $PKG
makepkg --linkadd y --chown n $OUTPUT/${PRGNAM}-${VERSION}-${PKGARCH}-${BUILD}${TAG}.${PKGTYPE:-txz} 2>&1 | tee $OUTPUT/makepkg-${PRGNAM}.log
cd $OUTPUT
md5sum ${PRGNAM}-${VERSION}-${PKGARCH}-${BUILD}${TAG}.${PKGTYPE:-txz} > ${PRGNAM}-${VERSION}-${PKGARCH}-${BUILD}${TAG}.${PKGTYPE:-txz}.md5
cd -
cat $PKG/install/slack-desc | grep "^${PRGNAM}" > $OUTPUT/${PRGNAM}-${VERSION}-${PKGARCH}-${BUILD}${TAG}.txt

# Restore the original umask:
umask ${_UMASK_}