summaryrefslogtreecommitdiffstats
path: root/chromium/build/chromium.SlackBuild_15.0
blob: 959a0b3204616fdd8d0de95af0e715ba2b17a60a (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
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
#!/bin/bash
# $Id$
# Copyright 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023  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:     - ninja;
#                  - nodejs >= 15.6.0;
#                  - gcc >= 8 , llvm >= 16 for bootstrapping gn;
#                  - nasm >= 2.14;
#                  - cmake >= 3.13.4;
#                  - python3 >= 3.7, python3-setuptools;
#                  - java runtime;
#                  - Internet access (for downloading 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 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>
#                  * New release.
# 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.
# 81.0.4044.113-1: 16/apr/2020 by Eric Hameleers <alien@slackware.com>
#                  * Updated.
# 81.0.4044.122-1: 25/apr/2020 by Eric Hameleers <alien@slackware.com>
#                  * Updated.
# 81.0.4044.129-1: 29/apr/2020 by Eric Hameleers <alien@slackware.com>
#                  * Updated.
# 81.0.4044.138-1: 06/may/2020 by Eric Hameleers <alien@slackware.com>
#                  * Updated.
# 83.0.4103.61-1:  20/may/2020 by Eric Hameleers <alien@slackware.com>
#                  * Update to M83.
# 83.0.4103.97-1:  07/jun/2020 by Eric Hameleers <alien@slackware.com>
#                  * Updated.
# 83.0.4103.106-1: 16/jun/2020 by Eric Hameleers <alien@slackware.com>
#                  * Updated.
# 83.0.4103.116-1: 23/jun/2020 by Eric Hameleers <alien@slackware.com>
#                  * Updated.
#                    Add support for VAAPI. This is off by default but
#                    can be enabled by adding '--ignore-gpu-blacklist' and
#                    then one of '--use-gl=desktop' or '--use-gl=egl'.
#                    See https://chromium.googlesource.com/chromium/src/+/master/docs/gpu/vaapi.md#VaAPI-on-Linux
#                    for the intended usage (Intel VAAPI and MESA VAAPI).
#                    To support Nvidia and other GPUs, patches would be needed.
# 84.0.4147.89-1:  20/jul/2020 by Eric Hameleers <alien@slackware.com>
#                  * Update to M84.
# 84.0.4147.94-1:  23/jul/2020 by Eric Hameleers <alien@slackware.com>
#                  * Updated. Use a newer nodejs to make the sources compile
#                    on 32bit Slackware 14, plus this also fixes the
#                    broken development tools.
# 84.0.4147.105-1: 01/aug/2020 by Eric Hameleers <alien@slackware.com>
#                  * Updated.
# 85.0.4183.83-1:  28/aug/2020 by Eric Hameleers <alien@slackware.com>
#                  * Update to M85.
# 85.0.4183.102-1: 09/sep/2020 by Eric Hameleers <alien@slackware.com>
#                  * Updated.
# 85.0.4183.121-1: 22/sep/2020 by Eric Hameleers <alien@slackware.com>
#                  * Updated.
# 86.0.4240.75-1:  07/oct/2020 by Eric Hameleers <alien@slackware.com>
#                  * Update to M86.
# 86.0.4240.111-1: 22/oct/2020 by Eric Hameleers <alien@slackware.com>
#                  * Updated.
# 86.0.4240.183-1: 03/nov/2020 by Eric Hameleers <alien@slackware.com>
#                  * Updated.
# 86.0.4240.198-1: 13/nov/2020 by Eric Hameleers <alien@slackware.com>
#                  * Updated.
# 87.0.4280.66-1:  23/nov/2020 by Eric Hameleers <alien@slackware.com>
#                  * Update to M87.
# 87.0.4280.88-1:  03/dec/2020 by Eric Hameleers <alien@slackware.com>
#                  * Updated.
# 87.0.4280.141-1: 07/jan/2021 by Eric Hameleers <alien@slackware.com>
#                  * Updated.
# 88.0.4324.96-1:  21/jan/2021 by Eric Hameleers <alien@slackware.com>
#                  * Update to M88.
# 88.0.4324.146-1: 04/feb/2021 by Eric Hameleers <alien@slackware.com>
#                  * Updated.
# 88.0.4324.150-1: 06/feb/2021 by Eric Hameleers <alien@slackware.com>
#                  * Updated.
# 88.0.4324.182-1: 17/feb/2021 by Eric Hameleers <alien@slackware.com>
#                  * Updated.
# 88.0.4324.190-1: 23/feb/2021 by Eric Hameleers <alien@slackware.com>
#                  * Updated.
# 89.0.4389.72-1:  03/mar/2021 by Eric Hameleers <alien@slackware.com>
#                  * Update to M89.
# 89.0.4389.82-1:  07/mar/2021 by Eric Hameleers <alien@slackware.com>
#                  * Updated.
# 89.0.4389.90-1:  13/mar/2021 by Eric Hameleers <alien@slackware.com>
#                  * Updated.
# 89.0.4389.114-1: 31/mar/2021 by Eric Hameleers <alien@slackware.com>
#                  * Updated.
# 89.0.4389.128-1: 14/apr/2021 by Eric Hameleers <alien@slackware.com>
#                  * Updated.
# 90.0.4430.72-1:  15/apr/2021 by Eric Hameleers <alien@slackware.com>
#                  * Update to M90.
# 90.0.4430.93-1:  28/apr/2021 by Eric Hameleers <alien@slackware.com>
#                  * Updated.
# 90.0.4430.212-1: 11/may/2021 by Eric Hameleers <alien@slackware.com>
#                  * Updated.
# 91.0.4472.101-1: 11/jun/2021 by Eric Hameleers <alien@slackware.com>
#                  * Update.
# 91.0.4472.114-1: 19/jun/2021 by Eric Hameleers <alien@slackware.com>
#                  * Update.
# 92.0.4515.107-1: 22/jul/2021 by Eric Hameleers <alien@slackware.com>
#                  * Update to M92.
# 92.0.4515.131-1: 05/aug/2021 by Eric Hameleers <alien@slackware.com>
#                  * Update.
# 92.0.4515.159-1: 17/aug/2021 by Eric Hameleers <alien@slackware.com>
#                  * Update.
# 93.0.4577.63-1:  01/sep/2021 by Eric Hameleers <alien@slackware.com>
#                  * Update to M93. Add some mods that hopefully make building
#                    on ARM platforms easier.
# 93.0.4577.82-1:  13/sep/2021 by Eric Hameleers <alien@slackware.com>
#                  * Update.
# 94.0.4606.71-1:  02/oct/2021 by Eric Hameleers <alien@slackware.com>
#                  * Update to M94.
# 95.0.4638.69-1:  28/oct/2021 by Eric Hameleers <alien@slackware.com>
#                  * Update to M95.
# 96.0.4664.45-1:  15/nov/2021 by Eric Hameleers <alien@slackware.com>
#                  * Update to M96.
# 96.0.4664.93-1:  09/dec/2021 by Eric Hameleers <alien@slackware.com>
#                  * Update.
# 96.0.4664.110-1: 14/dec/2021 by Eric Hameleers <alien@slackware.com>
#                  * Update.
# 97.0.4692.71-1:  05/jan/2022 by Eric Hameleers <alien@slackware.com>
#                  * Update to M97.
# 97.0.4692.99-1:  20/jan/2022 by Eric Hameleers <alien@slackware.com>
#                  * Update.
# 98.0.4758.80-1:  02/feb/2022 by Eric Hameleers <alien@slackware.com>
#                  * Update to M98.
# 98.0.4758.102-1:  16/feb/2022 by Eric Hameleers <alien@slackware.com>
#                  * Update.
# 99.0.4844.51-1:  02/mar/2022 by Eric Hameleers <alien@slackware.com>
#                  * Update to M99.
# 99.0.4844.74-1:  16/mar/2022 by Eric Hameleers <alien@slackware.com>
#                  * Update.
# 99.0.4844.82-1:  24/mar/2022 by Eric Hameleers <alien@slackware.com>
#                  * Update.
# 99.0.4844.84-1:  27/mar/2022 by Eric Hameleers <alien@slackware.com>
#                  * Emergency update.
# 100.0.4896.60-1: 30/mar/2022 by Eric Hameleers <alien@slackware.com>
#                  * Update to M100.
# 100.0.4896.75-1: 05/apr/2022 by Eric Hameleers <alien@slackware.com>
#                  * Update.
# 100.0.4896.88-1: 12/apr/2022 by Eric Hameleers <alien@slackware.com>
#                  * Update.
# 100.0.4896.127-1:15/apr/2022 by Eric Hameleers <alien@slackware.com>
#                  * Emergency update.
# 101.0.4951.41-1: 28/apr/2022 by Eric Hameleers <alien@slackware.com>
#                  * Update to M101.
# 101.0.4951.54-1: 02/may/2022 by Eric Hameleers <alien@slackware.com>
#                  * Update.
# 101.0.4951.64-1: 11/may/2022 by Eric Hameleers <alien@slackware.com>
#                  * Update.
# 102.0.5005.61-1: 25/may/2022 by Eric Hameleers <alien@slackware.com>
#                  * Update to M102.
# 102.0.5005.115-1:10/jun/2022 by Eric Hameleers <alien@slackware.com>
#                  * Update.
# 103.0.5060.53-1: 25/jun/2022 by Eric Hameleers <alien@slackware.com>
#                  * Update to M103.
# 103.0.5060.134-1:20/jul/2022 by Eric Hameleers <alien@slackware.com>
#                  * Update.
# 104.0.5112.79-1: 02/aug/2022 by Eric Hameleers <alien@slackware.com>
#                  * Update to M104.
# 104.0.5112.101-1:17/aug/2022 by Eric Hameleers <alien@slackware.com>
#                  * Update.
# 105.0.5195.52-1: 02/aug/2022 by Eric Hameleers <alien@slackware.com>
#                  * Update to M105.
# 105.0.5195.102-1:04/aug/2022 by Eric Hameleers <alien@slackware.com>
#                  * Update.
# 105.0.5195.125-1:21/sep/2022 by Eric Hameleers <alien@slackware.com>
#                  * Update.
# 106.0.5249.61-1: 28/sep/2022 by Eric Hameleers <alien@slackware.com>
#                  * Update to M106.
# 106.0.5249.91-1: 02/oct/2022 by Eric Hameleers <alien@slackware.com>
#                  * Update.
# 106.0.5249.103-1:09/oct/2022 by Eric Hameleers <alien@slackware.com>
#                  * Update.
# 106.0.5249.119-1:18/oct/2022 by Eric Hameleers <alien@slackware.com>
#                  * Update.
# 107.0.5304.68-1: 26/oct/2022 by Eric Hameleers <alien@slackware.com>
#                  * Update to M107.
# 107.0.5304.87-1: 28/oct/2022 by Eric Hameleers <alien@slackware.com>
#                  * Update.
# 107.0.5304.110-1: 09/nov/2022 by Eric Hameleers <alien@slackware.com>
#                  * Update.
# 107.0.5304.121-1: 25/nov/2022 by Eric Hameleers <alien@slackware.com>
#                  * Update.
# 108.0.5359.71-1: 02/dec/2022 by Eric Hameleers <alien@slackware.com>
#                  * Update to M108.
# 108.0.5359.94-1: 02/dec/2022 by Eric Hameleers <alien@slackware.com>
#                  * Update.
# 108.0.5359.94-2: 06/dec/2022 by Eric Hameleers <alien@slackware.com>
#                  * Fix undefined symbol "gbm_bo_get_modifier" on 14.2.
# 108.0.5359.98-1: 08/dec/2022 by Eric Hameleers <alien@slackware.com>
#                  * Update.
# 108.0.5359.124-1: 17/dec/2022 by Eric Hameleers <alien@slackware.com>
#                  * Update.
# 109.0.5414.74-1: 15/jan/2023 by Eric Hameleers <alien@slackware.com>
#                  * Update to M109.
# 109.0.5414.74-2: 17/jan/2023 by Eric Hameleers <alien@slackware.com>
#                  * System libdrm on Slackware 14.2 is too old.
# 109.0.5414.119-1: 25/jan/2023 by Eric Hameleers <alien@slackware.com>
#                  * Update.
# 110.0.5481.77-1: 09/feb/2023 by Eric Hameleers <alien@slackware.com>
#                  * Update to M110.
# 110.0.5481.100-1:15/feb/2023 by Eric Hameleers <alien@slackware.com>
#                  * Update.
# 110.0.5481.177-1:26/feb/2023 by Eric Hameleers <alien@slackware.com>
#                  * Update.
# 
# -----------------------------------------------------------------------------
# 
# 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'. 
#
# -----------------------------------------------------------------------------

# Build an ungoogled chromium package (default no):
USE_UNGOOGLED=${USE_UNGOOGLED:-0}

# Build a development version of chromium (default no):
USE_DEV=${USE_DEV:-0}

[ ${USE_DEV} -ne 0 ] && SRCEXT="-dev" || SRCEXT=""
[ ${USE_UNGOOGLED} -ne 0 ] && SRCEXT="${SRCEXT}-ungoogled"

# -----------------------------------------------------------------------------

SRCNAM=chromium
PRGNAM=${SRCNAM}${SRCEXT}     # chromium, chromium-dev, chromium-ungoogled, etc
VERSION=${VERSION:-110.0.5481.177}
UNGOOGLED=${UNGOOGLED:-110.0.5481.177-1}
BUILD=${BUILD:-1}
TAG=${TAG:-alien}

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

# Debug build (disabled by default):
USE_DEBUG=${USE_DEBUG:-0}

# Differentiate between stable and development releases:
if [ $USE_DEV -ne 0 ]; then
  CRFLAGS="CHROMIUM_DEV_FLAGS"
  CRUSERFLAGS="CHROMIUM_DEV_USER_FLAGS"
elif [ $USE_UNGOOGLED -ne 0 ]; then
  CRFLAGS="CHROMIUM_UNGOOGLED_FLAGS"
  CRUSERFLAGS="CHROMIUM_UNGOOGLED_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;
# FYI, this will actually also just work for Slackware > 14.2:
if [ $(cat /etc/slackware-version |cut -d' ' -f2- |cut -d. -f1) -lt 15 ]; then
  USE_SYSROOT=${USE_SYSROOT:-1}
else
  USE_SYSROOT=${USE_SYSROOT:-0}
fi
# When using a sysroot, we also use its internal libffi:
USE_INTFFI=${USE_SYSROOT}

# Enable Wayland on Slackware 15.0 & newer where we don't use a debian sysroot.
if /usr/bin/pkg-config --exists wayland-client 2>/dev/null ; then
  if [ ${USE_SYSROOT} -eq 0 ]; then
    USE_WAYLAND=${USE_WAYLAND:-1}
  else
    USE_WAYLAND=${USE_WAYLAND:-0}
  fi
else
  USE_WAYLAND=${USE_WAYLAND:-0}
fi

# Enable Qt UI on Slackware 15.0 & newer where we do not need a debian sysroot.
# Until Chromium 110, enable Qt5 UI using param '--enable-features=AllowQt':
if pkg-config --exists "Qt5Core >= 5.15.3" ; then
  if [ ${USE_SYSROOT} -eq 0 ]; then
    USE_QT=${USE_QT:-1}
  else
    USE_QT=${USE_QT:-0}
  fi
else
  USE_QT=${USE_QT:-0}
fi

# 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:-ChromeOS} # or "Chrome", or "Chromium"

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

# 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.
# You will have to download and apply lots of patches when using gcc anyway.
# This script can compile google's modified clang from source, so that 32bit
# can be supported on older Slackware (Google offers only 64bit pre-built
# clang for download0:
USE_CLANG=${USE_CLANG:-1}

# Build a custom clang or use the system clang?
# CLANG_MIN is the minimal clang version needed to compile chromium,
# see 'CLANG_REVISION' and 'RELEASE_VERSION' in tools/clang/scripts/update.py :
CLANG_MIN=16
if [ $(clang -dumpversion |cut -d. -f1) -ge ${CLANG_MIN} ]; then
  BUILD_CLANG=${BUILD_CLANG:-0}
else
  BUILD_CLANG=${BUILD_CLANG:-1}
fi

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

# Chromium supports VAAPI (we disable it when the platform is not capable):
USE_VAAPI=${USE_VAAPI:-1}

# Building Chromium against the system libstdc++ requires additional patches.
# Luckily, https://github.com/stha09/chromium-patches maintains a patch set.
USE_SYSCXX=${USE_SYSCXX:-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 used to be built with Alien's Google API keys for Chromium.
# The keys must be present in the file "chromium_apikeys".
# If you rebuild this package, you can use your own API keys. See:
#   http://www.chromium.org/developers/how-tos/api-keys
# This browser is now compiled without API keys. This will disable stuff like
# browser sync and other functionality which accesses Google APIs. 
# The following variables must be set to access Google's public APIs:
#   _google_api_key
#   _google_default_client_id
#   _google_default_client_secret
_google_api_key=""
_google_default_client_id=""
_google_default_client_secret=""
if [ ${USE_UNGOOGLED} -eq 0 ]; then
  if [ -f ${HOME}/.chromium_apikeys ]; then
    . ${HOME}/.chromium_apikeys
  elif [ -f ${SRCDIR}/chromium_apikeys ]; then
    . ${SRCDIR}/chromium_apikeys
  fi
  if [ -z "$_google_api_key" ]; then
    cat <<EOT
No values were supplied for the following variables:
   _google_api_key
   _google_default_client_id
   _google_default_client_secret
You can supply your own Google API keys and compile them into Chromium now.
Else you can always provide Google API keys at runtime through the environment.
To achieve that, create '/etc/${PRGNAM}/01-apikeys.conf' as root:
  # echo "export GOOGLE_API_KEY='yourkey'" >> /etc/${PRGNAM}/01-apikeys.conf
  # echo "export GOOGLE_DEFAULT_CLIENT_ID='yourclientid'" >> /etc/${PRGNAM}/01-apikeys.conf
  # echo "export GOOGLE_DEFAULT_CLIENT_SECRET='yourclientsecret'" >> /etc/${PRGNAM}/01-apikeys.conf

Press Ctrl-C to abort this script and add your own Google API keys,
or wait 10 seconds to continue compilation without adding keys.

EOT
    sleep 10
  fi
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 ;;
    armv7*)  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-linux-gnu"
             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-linux-gnu"
               PKGARCH="i586"
             else
               SLKCFLAGS="-O2 -fPIC"
               SLKLDFLAGS="-L/usr/lib64"; LIBDIRSUFFIX="64"
               FFMPEG_ARCH="x64"
               SYSROOT_ARCH="amd64"
               SYSROOT_TARGET="x86_64-linux-gnu"
               PKGARCH="$ARCH"
             fi
             #DSSE="0"
             DSSE="1"
             ;;
  armv7*)    SLKCFLAGS="-O2 -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=hard"
             SLKLDFLAGS="-Wl,-z,notext"; LIBDIRSUFFIX=""
             DSSE="1"
             # Widevine not supported (no binary library available):
             USE_CDM=0
             # VAAPI not supported:
             USE_VAAPI=0
             FFMPEG_ARCH="arm"
             SYSROOT_ARCH="arm"
             SYSROOT_TARGET="arm-linux-gnueabihf"
             PKGARCH="$ARCH"
             ;;
  *)         SLKCFLAGS=${SLKCFLAGS:-"O2"}
             SLKLDFLAGS=${SLKLDFLAGS:-""}; LIBDIRSUFFIX=${LIBDIRSUFFIX:-""}
             DSSE="1"
             # Widevine not supported by default:
             USE_CDM=0
             # VAAPI not supported by default:
             USE_VAAPI=0
             FFMPEG_ARCH="$ARCH"
             SYSROOT_ARCH="$ARCH"
             SYSROOT_TARGET="$ARCH-linux-gnu"
             PKGARCH="$ARCH"
             ;;
esac

case "$ARCH" in
    armv7*)  TARGET=$ARCH-slackware-linux-gnueabi ;;
    arm*)    TARGET=${SYSROOT_ARCH}-slackware-linux-gnueabihf ;;
    *)       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"

if [ ${USE_UNGOOGLED} -ne 0 ]; then
  SOURCE[2]="$SRCDIR/ungoogled-chromium-${UNGOOGLED}.tar.gz"
  SRCURL[2]="https://github.com/Eloston/ungoogled-chromium/archive/${UNGOOGLED}.tar.gz"
  #SRCURL[2]="https://github.com/tangalbert919/ungoogled-chromium/archive/${UNGOOGLED}.tar.gz"
fi

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

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

if [ ${USE_UNGOOGLED} -ne 0 ]; then
  # Give chromium-ungoogled our own Slackware grey logo:
  for size in 16 32 ; do
    convert ${SRCDIR}/${PRGNAM}.png -resize ${size}x${size} \
      chrome/app/theme/default_200_percent/chromium/product_logo_$size.png
    convert ${SRCDIR}/${PRGNAM}.png -resize ${size}x${size} \
      chrome/app/theme/default_100_percent/chromium/product_logo_$size.png
    convert ${SRCDIR}/${PRGNAM}.png -resize ${size}x${size} \
      chrome/app/theme/default_100_percent/chromium/linux/product_logo_$size.png
  done
  for size in 24 48 64 128 256; do
    convert ${SRCDIR}/${PRGNAM}.png -resize ${size}x${size} \
      chrome/app/theme/chromium/product_logo_$size.png
    convert ${SRCDIR}/${PRGNAM}.png -resize ${size}x${size} \
      chrome/app/theme/chromium/linux/product_logo_$size.png
  done
  for size in 32 ; do
    convert ${SRCDIR}/${PRGNAM}.png -resize ${size}x${size} \
      chrome/app/theme/chromium/linux/product_logo_$size.xpm
  done
fi

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

# For chromium >= 102, download a specific build.py which allows us to
# compile our 32bit package successfully:
if [ ${VERSION%%.*} -ge 102 ]; then
  wget --no-check-certificate -O - https://raw.githubusercontent.com/chromium/chromium/ad35291af36d609042e1d320adb1568daafef9a8/tools/clang/scripts/build.py > tools/clang/scripts/build.py
fi

# 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
# https://github.com/protocolbuffers/protobuf/issues/9792
cat $SRCDIR/patches/chromium_protobuf_32bit.patch \
  | patch -p0 --verbose \
  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}.log

# Be compatible with gcc 10:
cat $SRCDIR/patches/chromium_gcc10.patch | patch -p1 --verbose \
  2>&1 | tee -a $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
if [ "$ARCH" == "i586" ] ; then
  # Don't complain about unsupported flags when we add
  # "--disable-seccomp-sandbox" on 32bit OS:
  cat $SRCDIR/patches/chromium_slax_nobadflagsmessage.patch \
    | patch -p1 --verbose \
    2>&1 | tee -a $OUTPUT/patch-${PRGNAM}.log
fi

if [ ${USE_SYSCXX} -eq 1 ]; then
  echo "-- Compiling against system libstdc++"
  # Apply patches from https://github.com/stha09/chromium-patches
  # to be able to compile Chromium against our GCC's libstdc++:
  cat $SRCDIR/patches/chromium-103-VirtualCursor-std-layout.patch \
    | patch -p1 --verbose \
    2>&1 | tee -a $OUTPUT/patch-${PRGNAM}.log
  cat $SRCDIR/patches/chromium-110-NativeThemeBase-fabs.patch \
    | patch -p1 --verbose \
    2>&1 | tee -a $OUTPUT/patch-${PRGNAM}.log
  cat $SRCDIR/patches/chromium-110-CredentialUIEntry-const.patch \
    | patch -p1 --verbose \
    2>&1 | tee -a $OUTPUT/patch-${PRGNAM}.log
  cat $SRCDIR/patches/chromium-110-InProgressDownloadManager-include.patch \
    | patch -p1 --verbose \
    2>&1 | tee -a $OUTPUT/patch-${PRGNAM}.log
  cat $SRCDIR/patches/chromium-110-DarkModeLABColorSpace-pow.patch  \
    | patch -p1 --verbose \
    2>&1 | tee -a $OUTPUT/patch-${PRGNAM}.log
fi

# Prevent an error 'Looking for xmlReadMemory - not found ' building clang:
sed \
  -i tools/clang/scripts/build.py \
  -e "s%'lib', 'libxml2.a'%'lib$LIBDIRSUFFIX', 'libxml2.a'%"
sed \
  -i third_party/libxml/src/libxml2-config.cmake.in \
  -e 's%set(LIBXML2_LIBRARY_DIR *${_libxml2_rootdir}/lib%&'${LIBDIRSUFFIX}'%'

## Fix a compilation error because we enable HEVC but are not ChromeOS:
#cat $SRCDIR/patches/chromium_hevc_non_chromeos.patch | patch -p1 --verbose \
#  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}.log
# Slackware specific:
# When compiling google's clang on 32bit Slackware or on ARM, add our triplets.
# I am a python noob so this is clumsy, better implementation is welcome :-)
cp $SRCDIR/patches/clang.toolchains.slackware.triple.diff .
cat $SRCDIR/patches/chromium_slackware_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
fi

if [ ${USE_UNGOOGLED} -ne 0 ]; then
  # Apply ungoogled-chromium patch kit:
  UGDIR=$TMP/tmp-$PRGNAM/ungoogled-chromium-${UNGOOGLED}
  echo "-- Un-googling internal binaries:"
  python3 ${UGDIR}/utils/prune_binaries.py ./ ${UGDIR}/pruning.list
  echo "-- Un-googling sources; apply patches:"
  python3 ${UGDIR}/utils/patches.py apply ./ ${UGDIR}/patches
  # We will have to un-google internally used domain list later.
fi

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

# And fix the 32bit compilation while we are at it:
sed -i tools/clang/scripts/build.py -e "s/ldflags = \[\]/ldflags = \['-latomic'\]/"

## Avoid failure because the built clang version is not what update.py expects:
#sed -i tools/clang/scripts/update.py -e "s/RELEASE_VERSION = '16'/RELEASE_VERSION = '16.0.0'/"
cat $SRCDIR/patches/chromium_clang_versiondetect.patch | patch -p0 --verbose \
  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}.log

# Fix "unable to find library -l:libffi_pic.a":
cat $SRCDIR/patches/chromium_libffi_pic.patch | patch -p0 --verbose \
  2>&1 | tee -a $OUTPUT/patch-${PRGNAM}.log

# ARM platform specifics:
if [[ "$ARCH" =~ arm.* ]]; then
  # Fix the hard-coded bootstrap target 'X86':
  sed -i tools/clang/scripts/build.py \
    -e "s/bootstrap_targets = 'X86'/bootstrap_targets = 'ARM'/"

  # Compile only the relevant back-ends (ARM, AArch64 and X86):
  sed -i tools/clang/scripts/build.py \
    -e "s/\(^ *targets = \).*$/&1'ARM;X86;AArch64'/"
fi

# 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/#&/'

# We require a 32bit gn binary, devs!
sed -i BUILD.gn \
  -e 's/target_os != "linux" || /target_os == "linux" || /'

# 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/
ln -s /usr/lib${LIBDIRSUFFIX}/java/bin/java third_party/jdk/current/bin/

if [ "$PRGNAM" != "$SRCNAM" ]; then
  # Save configuration in ~/.config/$PRGNAM:
  sed -e 's|filename = "chromium-browser|&'$SRCEXT'|' \
      -e 's|confdir = "chromium|&'$SRCEXT'|' \
      -i chrome/BUILD.gn
  sed -e 's|data_dir_basename = "chromium|&'$SRCEXT'|' \
      -e 's|config_dir.Append("chromium|&'$SRCEXT'|' \
      -i chrome/common/chrome_paths_linux.cc
  if [ -f chrome/browser/web_applications/external_web_app_manager.cc ]; then
    sed -e 's|/etc/chromium|&'$SRCEXT'|' \
        -e 's|/usr/share/chromium|&'$SRCEXT'|' \
        -i chrome/browser/web_applications/external_web_app_manager.cc
  else
    sed -e 's|/etc/chromium|&'$SRCEXT'|' \
        -e 's|/usr/share/chromium|&'$SRCEXT'|' \
        -i chrome/browser/web_applications/preinstalled_web_app_manager.cc
  fi
  sed -e 's|/etc/chromium|&'$SRCEXT'|' \
      -e 's|/usr/share/chromium|&'$SRCEXT'|' \
      -i chrome/common/chrome_paths.cc
  sed -e 's|/etc/chromium|&'$SRCEXT'|' \
      -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
[ ${BUILD_CLANG} -eq 1 ] && do_custclang=true || do_custclang=false
[ ${USE_CDM} -eq 1 ] && do_cdm=true || do_cdm=false
[ ${USE_HOTWORD} -eq 1 ] && do_hotword=true || do_hotword=false
[ ${USE_INTFFI} -eq 1 ] && do_syslibffi=false || do_syslibffi=true
[ ${USE_PA} -eq 1 ] && do_pa=true || do_pa=false
[ ${USE_QT} -eq 1 ] && do_qt=true || do_qt=false
[ ${USE_SYSCXX} -eq 1 ] && do_custcxx=false || do_custcxx=true
[ ${USE_SYSROOT} -eq 1 ] && do_sysroot=true || do_sysroot=false
[ ${USE_VAAPI} -eq 1 ] && do_vaapi=true || do_vaapi=false
[ ${USE_WAYLAND} -eq 1 ] && do_wayland=true || do_wayland=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=(
    'blink_enable_generated_code_formatting=false'
    'blink_symbol_level=0'
    "enable_hevc_parser_and_hw_decoder=${do_hevc}"
    "enable_platform_hevc=${do_hevc}"
    "enable_platform_hevc_decoding=${do_hevc}"
    "enable_platform_encrypted_hevc=${do_hevc}"
    'enable_platform_ac3_eac3_audio=true'
    'enable_platform_mpeg_h_audio=true'
    'enable_platform_dolby_vision=true'
    'enable_mse_mpeg2ts_stream_parser=true'
    'enable_precompiled_headers=false'
    'enable_pseudolocales=false'
    'enable_webrtc=true'
    'fatal_linker_warnings=false'
    "ffmpeg_branding=\"${FFMPEG_BRANDING}\""
    "is_clang=${do_clang}"
    #"llvm_force_head_revision=${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'
    "ozone_platform_wayland=${do_wayland}"
    "rtc_use_pipewire=${do_wayland}"
    "rtc_link_pipewire=${do_wayland}"
    '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=${do_custcxx}"
    'use_gconf=false'
    'use_kerberos=false'
    'use_lld=true'
    'use_ozone=true'
    "use_pulseaudio=${do_pa}"
    "use_system_libffi=${do_syslibffi}"
    'use_system_minigbm=false'
    "use_qt=${do_qt}"
    "use_sysroot=${do_sysroot}"
    "use_vaapi=${do_vaapi}"
    "use_xkbcommon=${do_wayland}"
    "enable_wayland_server=${do_wayland}"
    "extra_cxxflags=\"${CXXFLAGS}\""
    "extra_ldflags=\"${LDFLAGS}\""
)
# Needed for Ungoogled Chromium 94 to prevent compile error related to
# missing pref 'kGoogleServicesConsentedToSync' because 'is_debug=false' seems
# to no longer suffice. Also, need to reduce crash proneness according to
# https://groups.google.com/a/chromium.org/g/chromium-packagers/c/2E5AayFuFt4 :
_chromium_conf+=(
  'is_official_build=true'
  'dcheck_always_on=false'
)
# Prevent segfaults with llvm-12.0.1 (Chromium 94), thanks Void Linux:
_chromium_conf+=(
  'is_cfi=false'
  'use_thin_lto=false'
  'use_cfi_icall=false'
  'chrome_pgo_phase=0'
)
if [ ${USE_CLANG} -eq 1 ] && [  ${BUILD_CLANG} -eq 0 ]; then
  # Use system toolchain:
  _chromium_conf+=(
    'custom_toolchain="//build/toolchain/linux/unbundle:default"'
    'host_toolchain="//build/toolchain/linux/unbundle:default"'
  )
fi
if [ ${USE_UNGOOGLED} -ne 0 ]; then
  # Add ungoogled flags if requested:
  readarray -t -O ${#_chromium_conf[@]} _chromium_conf < ${UGDIR}/flags.gn
else
  # Add remainder of standard chromium flags:
  # https://chromium.googlesource.com/chromium/src/+/refs/heads/main/testing/variations/README.md
  _chromium_conf+=(
    "clang_use_chrome_plugins=${do_custclang}"
    'enable_hangout_services_extension=true'
    "enable_hotwording=${do_hotword}"
    'enable_js_type_check=true'
    'enable_nacl=false'
    'enable_nacl_nonsfi=false'
    'enable_pepper_cdms=true'
    "enable_widevine=${do_cdm}"
    'exclude_unwind_tables=true'
    'disable_fieldtrial_testing_config=true'
    'logging_like_official_build=true'
  )
fi
# Add Google API key if defined:
if [ -n "$_google_api_key" ]; then
  _chromium_conf+=(
    "google_api_key=\"$_google_api_key\""
  )
  # Also add client id/secret if it was provided:
  if [ -n "$_google_default_client_id" ]; then
    _chromium_conf+=(
      "google_default_client_id=\"$_google_default_client_id\""
      "google_default_client_secret=\"$_google_default_client_secret\""
    )
  fi
fi

if [ $(cat /etc/slackware-version |cut -d' ' -f2- |cut -d. -f1) -lt 15 ]; then
  # For older Slackware:
  _chromium_conf+=( 'use_system_libdrm=false' )
fi

#if [ "$ARCH" == "i586" ] || [ "${CROSS32}" = "YES" ]; then
#  _chromium_conf+=( 'target_cpu="x86"' )
#fi
if [[ "$ARCH" =~ arm.* ]]; then
  _chromium_conf+=( 'target_cpu="arm"' 'target_os="linux"' )
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

## The array of possible replacements of embedded with system libraries is
## found in 'build/linux/unbundle/replace_gn_files.py':
#gn_system_libraries=(
#  # 'bzip2'
#  # 'ffmpeg'
#  # 'flac'
#  # 'freetype2'
#  # 'harfbuzz'
#  # 'icu'
#  # 'libdrm'
#  # 'libevent'
#  # 'libjpeg'
#  # 'libpng'
#  # 'libvpx'
#  # 'libwebp'
#  # 'libxml'
#  # 'libxslt'
#  # 'opus'
#  # 're2'
#  # 'snappy'
#  # '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/harfbuzz-ng/utils/hb_scoped.h" \
#    \! -regex '.*\.\(gn\|gni\|isolate\)' \
#    -delete
#done
#
## Change bundled libraries to system ones:
#echo "-- Change bundled to system libraries in $PRGNAM sources."
#python3 build/linux/unbundle/replace_gn_files.py --system-libraries ${gn_system_libraries[@]}
#

# Do not make the build fail, see Chromium issue #386097:
python3 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

if [ ${USE_SYSROOT} -eq 1 ]; then
  # Take care of Debian/Ubuntu related missing header issues:
  SYSROOTDIR=$(basename $(ls build/linux/ |grep ${SYSROOT_ARCH}-sysroot))

  ln -s ../../lib/${SYSROOT_TARGET}/glib-2.0/include/glibconfig.h \
    build/linux/${SYSROOTDIR}/usr/include/glib-2.0/glibconfig.h
  ln -s ../../../lib/${SYSROOT_TARGET}/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}/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}/nss" >> \
  #  build/linux/${SYSROOTDIR}/etc/ld.so.conf.d/${SYSROOT_TARGET}.conf
  for SOFILE in build/linux/${SYSROOTDIR}/usr/lib/${SYSROOT_TARGET}/nss/*.so ;
  do
    ln -sf nss/$(basename $SOFILE) \
      build/linux/${SYSROOTDIR}/usr/lib/${SYSROOT_TARGET}/
  done
  ln -s libsqlite3.so.0 \
    build/linux/${SYSROOTDIR}/usr/lib/${SYSROOT_TARGET}/libsqlite3.so

  # The platform-specific alias for the ARM readelf binary is missing
  # from the debian sysroot image:
  if [ ! -f build/linux/${SYSROOTDIR}/usr/bin/${SYSROOT_TARGET}-readelf ]; then
    ln -s /usr/bin/readelf \
      build/linux/${SYSROOTDIR}/usr/bin/${SYSROOT_TARGET}-readelf
  fi
fi

# Do not make the build fail on stripping chromedriver,
# because Chromium installs a 64bit version of eu-strip on the 32bit & ARM OS:
if [ "$ARCH" != "x86_64" ]; then
  if file $TMP/tmp-$PRGNAM/${SRCNAM}-${VERSION}/buildtools/third_party/eu-strip/bin/eu-strip 2>/dev/null | grep -q "ELF 64-bit" ; then
    install -D -m0755 -t $TMP/tmp-$PRGNAM/${SRCNAM}-${VERSION}/buildtools/third_party/eu-strip/bin /usr/bin/eu-strip
  fi
fi

# --- Compile --- #

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

# Compile google's internal clang sources if needed
if [ ${USE_CLANG} -eq 1 ] && [  ${BUILD_CLANG} -eq 1 ]; then
  # Build clang from source instead of downloading:
  echo "-- Building google's clang toolchain."
  HDR2REM=""
  if [ "$ARCH" == "i586" ]; then
    # Actually 32bit compilation fails by not finding 'bits/c++config.h'.
    # I could only work around this using a kludge:
    # cp -ia /usr/include/c++/$(gcc -dumpversion)/${TARGET}/bits/* /usr/include/c++/$(gcc -dumpversion)/bits/
    # Keep a list of the symlinks we'll be creating:
    for HDR in /usr/include/c++/$(gcc -dumpversion)/${TARGET}/bits/*.h ; do
      if [ ! -f /usr/include/c++/$(gcc -dumpversion)/bits/$(basename $HDR) ];
    then
      ln -s $HDR /usr/include/c++/$(gcc -dumpversion)/bits/
      HDR2REM="$(basename $HDR) $HDR2REM"
      fi
    done
  fi
  LDFLAGS="$LDFLAGS" \
  python3 tools/clang/scripts/build.py \
    --bootstrap \
    --disable-asserts \
    --gcc-toolchain /usr \
    --host-cc /usr/bin/gcc \
    --host-cxx /usr/bin/g++ \
    --skip-checkout \
    --use-system-cmake \
    --without-android \
    --without-fuchsia \
    2>&1 | tee $OUTPUT/clang_build-${PRGNAM}.log
    #--llvm-force-head-revision \

  # Building gn for Chromium 110 fails when this file is not present:
  if [ ! -f third_party/llvm-build/Release+Asserts/cr_build_revision ]; then
    CLANG_REVISION=$(grep ^CLANG_REVISION tools/clang/scripts/update.py |cut -d= -f2 |tr -d " '")
    CLANG_SUB_REVISION=$(grep ^CLANG_SUB_REVISION tools/clang/scripts/update.py |cut -d= -f2 |tr -d " '")
    echo "${CLANG_REVISION}-${CLANG_SUB_REVISION}" > third_party/llvm-build/Release+Asserts/cr_build_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"

  # Package up this custom clang compiler so that next time, we can speed up
  # the Chromium build:
  if [ -f $TMP/tmp-$PRGNAM/${SRCNAM}-${VERSION}/third_party/llvm-build/Release+Asserts/bin/clang ]; then
    if [ -f $SRCDIR/google-clang.build ]; then
      source $SRCDIR/google-clang.build \
        2>&1 | tee $OUTPUT/clang_package-${PRGNAM}.log
    fi
  fi


fi

# For Chromium 92, disable ffmpeg re-configuration on 32bit OS,
# to avoid linking errors like:
# "FAILED: v8_context_snapshot_generator - ld.lld: error: undefined symbol: ff_psdsp_init_x86"
if [ ${FFMPEG_HEVC} -eq 1 ] && [ "${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
    # Re-configure bundled ffmpeg to make it compile on 32bit Slackware:
    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:
    python3 chromium/scripts/build_ffmpeg.py linux ${FFMPEG_ARCH} \
      --branding ${FFMPEG_BRANDING} -- ${FFMPEG_CUSTOM_ARGS} \
      2>&1 | tee $OUTPUT/ffmpeg_configure-${PRGNAM}.log
    python3 chromium/scripts/copy_config.sh \
      2>&1 | tee -a $OUTPUT/ffmpeg_configure-${PRGNAM}.log
    # Runs into 'SyntaxError: invalid syntax' with Python2:
    python3 chromium/scripts/generate_gn.py \
      2>&1 | tee -a $OUTPUT/ffmpeg_configure-${PRGNAM}.log
  cd - 2>/dev/null
fi

if [ ${USE_UNGOOGLED} -ne 0 ]; then
  echo "-- Un-googling internally used domain list:"
  python3 ${UGDIR}/utils/domain_substitution.py apply \
    -r ${UGDIR}/domain_regex.list \
    -f ${UGDIR}/domain_substitution.list \
    -c domainsubcache.tar.gz ./
fi

# If gn is not installed we need to compile it ourselves:
if ! which gn 1>/dev/null 2>/dev/null ; then
  echo "-- Bootstrapping 'gn'."

  if [ ${USE_CLANG} -eq 1 ] && [  ${BUILD_CLANG} -eq 1 ]; then
    # Symlink ld to lld to make gn linking stage succeed:
    cd $MYCLANG_PATH ; ln -s lld ld ; cd - 1>/dev/null
  fi

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

  #if [ ${USE_CLANG} -eq 1 ] && [  ${BUILD_CLANG} -eq 1 ]; then
  #  # Remove symlink again:
  #  rm $MYCLANG_PATH/ld
  #fi
fi

if [ ${USE_CLANG} -eq 1 ] && [  ${BUILD_CLANG} -eq 1 ]; then
  if [ -n "$HDR2REM" ]; then
    # Remove the temporary header symlinks we created earlier:
    ( cd /usr/include/c++/$(gcc -dumpversion)/bits/ && rm $HDR2REM)
  fi
fi

echo "-- Generating ninja build files."
if ! which gn 1>/dev/null 2>/dev/null ; then
  out/Release/gn gen out/Release -v --args="${_chromium_conf[*]}" \
    2>&1 | tee -a $OUTPUT/gngen-${PRGNAM}.log
else
  gn gen out/Release -v --args="${_chromium_conf[*]}" \
    2>&1 | tee -a $OUTPUT/gngen-${PRGNAM}.log
fi

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

if [ ${USE_CLANG} -eq 1 ] && [ ${BUILD_CLANG} -eq 1 ]; then
  # Use the clang that we build in-tree instead of using the system version:
  echo "-- Using our custom clang."
  export CC="$MYCLANG_PATH/clang"
  export CXX="$MYCLANG_PATH/clang++"
  export LD="$MYCLANG_PATH/lld"
  export AR="$MYCLANG_PATH/llvm-ar"
  export NM="$MYCLANG_PATH/llvm-nm"
elif [ "$USE_CLANG" = "0" ]; then
  # Be careful not to override CC and CXX (may have been set by gcc5):
  echo "-- Using gcc/g++ compilers."
  export CC=${CC:-"gcc"}
  export CXX=${CXX:-"g++"}
else
  # Use the system clang:
  echo "-- Using the system clang."
  export CC="/usr/bin/clang"
  export CXX="/usr/bin/clang++"
  export LD="/usr/bin/lld"
  export AR="/usr/bin/llvm-ar"
  export NM="/usr/bin/llvm-nm"
fi
export AS=as

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

if [ $USE_UNGOOGLED -eq 0 ] &&  [ ! -f out/Release/chrome_crashpad_handler ]
then
  # ungoogled-chromium has crash-reporting disabled:
  LDFLAGS="$LDFLAGS" \
  LC_ALL=C \
  ninja -C out/Release \
    chrome_crashpad_handler \
    2>&1 | tee -a $OUTPUT/ninja-${PRGNAM}.log
fi

# 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

if [ $USE_UNGOOGLED -eq 0 ]; then
  # Crashpad, the Chromium crash-reporting client:
  install -D out/Release/chrome_crashpad_handler $PKG/usr/lib${LIBDIRSUFFIX}/${PRGNAM}/chrome_crashpad_handler
fi

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

# Copy over the remaining binaries:
cp -a \
  out/Release/angledata \
  $PKG/usr/lib${LIBDIRSUFFIX}/${PRGNAM}/
# Un-googled chromium disables MEI Preload:
if [ -d out/Release/MEIPreload ]; then
  cp -a \
    out/Release/MEIPreload \
    $PKG/usr/lib${LIBDIRSUFFIX}/${PRGNAM}/
fi
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
if [ ${USE_QT} -eq 1 ]; then
  cp -a \
    out/Release/libqt5_shim.so \
  $PKG/usr/lib${LIBDIRSUFFIX}/${PRGNAM}/
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

# Install appdata:
mkdir -p $PKG/usr/share/metainfo
if [ $USE_UNGOOGLED -eq 0 ]; then
  # Remove text with relevance to Google only (thanks Arch):
  sed -n \
   -e "s/chromium-browser\.desktop/chromium-browser${SRCEXT}.desktop/" \
   -e '/<update_contact>/d' \
   -e '/<p>/N;/<p>\n.*\(We invite\|Chromium supports Vorbis\)/,/<\/p>/d' \
   -e '/^<?xml/,$p' \
   chrome/installer/linux/common/chromium-browser/chromium-browser.appdata.xml \
   > $PKG/usr/share/metainfo/${PRGNAM}.appdata.xml
elif [ -f $SRCDIR/${PRGNAM}.appdata.xml ]; then
  # A customized un-googled version for this package:
  cat $SRCDIR/${PRGNAM}.appdata.xml \
    > $PKG/usr/share/metainfo/${PRGNAM}.appdata.xml
fi
chmod 644 $PKG/usr/share/metainfo/${PRGNAM}.appdata.xml

if [ $USE_DEBUG -eq 0 ]; then
  # Manually strip binaries:
  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 [ $USE_UNGOOGLED -eq 0 ]; then
    strip  --strip-unneeded \
      $PKG/usr/lib${LIBDIRSUFFIX}/${PRGNAM}/chrome_crashpad_handler
  fi
  if [ -f $PKG/usr/lib${LIBDIRSUFFIX}/${PRGNAM}/lib/libffmpeg*.so ]; then
    strip  --strip-unneeded \
      $PKG/usr/lib${LIBDIRSUFFIX}/${PRGNAM}/lib/lib*.so
  fi
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 we need to do it manually.
# First, fix an incompatibility with the 'date' command in Slackware before 15.0:
sed -e 's/--rfc-email/-R/g' \
  -i $TMP/tmp-$PRGNAM/${SRCNAM}-${VERSION}/chrome/installer/linux/common/installer.include
# We source this script since its '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/${SRCNAM}.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/${SRCNAM}.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

if [ $USE_UNGOOGLED -eq 0 ]; then
  if [ -z "$_google_api_key" ]; then
    # If the package was built without an API key, install the sample file:
    cat $SRCDIR/${SRCNAM}.apikeys.sample \
      > $PKG/etc/${PRGNAM}/01-apikeys.conf.new
  else
    # Else add it to the docs:
    mkdir -p $PKG/usr/doc/${PRGNAM}-${VERSION}
    cat $SRCDIR/${SRCNAM}.apikeys.sample \
      > $PKG/usr/doc/${PRGNAM}-${VERSION}/01-apikeys.conf
  fi
fi

# 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

if [ -z "$_google_api_key" ] && [ $USE_UNGOOGLED -eq 0 ]; then
  echo "config etc/${PRGNAM}/01-apikeys.conf.new" >> $PKG/install/doinst.sh
fi

# 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:
[ $USE_DEV -eq 0 ] && DEV_SPECIFICS="" \
  || DEV_SPECIFICS=" This package contains the development version."
[ $USE_UNGOOGLED -eq 0 ] && UG_SPECIFICS="" \
  || UG_SPECIFICS=" This package contains the un-googled version."
mkdir -p $PKG/install
cat <<EOT >$PKG/install/slack-desc
$PRGNAM: chromium (Open Source version of Chrome Web Browser)
$PRGNAM:
$PRGNAM: Chromium is the open-source project behind Google Chrome,
$PRGNAM: an attempt at creating a safer, faster, and more stable browser.
$PRGNAM:$DEV_SPECIFICS
$PRGNAM:$UG_SPECIFICS
$PRGNAM:
$PRGNAM:
$PRGNAM:
$PRGNAM: chromium home: http://www.chromium.org/
$PRGNAM:
EOT

# 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_}