File: rules

package info (click to toggle)
openjdk-11 11.0.4+11-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 757,028 kB
  • sloc: java: 5,016,041; xml: 1,191,974; cpp: 934,731; ansic: 555,697; sh: 24,299; objc: 12,703; python: 3,602; asm: 3,415; makefile: 2,772; awk: 351; sed: 172; perl: 114; jsp: 24; csh: 3
file content (1777 lines) | stat: -rwxr-xr-x 60,466 bytes parent folder | download | duplicates (2)
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
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

unexport LANG LC_ALL

dh_version := $(shell dpkg-query -f '$${Version}\n' -W debhelper | sed -n 's/^\(.\).*/\1/p')

# using brace expansion and substring replacements (${var:0:2}).
SHELL = /bin/bash

# use gnu time in verbose mode if available, otherwise default to the shell builtin
ifneq (,$(wildcard /usr/bin/time))
  TIME = /usr/bin/time -v
else
  TIME = time
endif

vafilt = $(subst $(2)=,,$(filter $(2)=%,$(1)))

DPKG_VARS		:= $(shell dpkg-architecture)
DEB_HOST_GNU_TYPE	?= $(call vafilt,$(DPKG_VARS),DEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE	?= $(call vafilt,$(DPKG_VARS),DEB_BUILD_GNU_TYPE)
DEB_HOST_ARCH		?= $(call vafilt,$(DPKG_VARS),DEB_HOST_ARCH)
DEB_BUILD_ARCH		?= $(call vafilt,$(DPKG_VARS),DEB_BUILD_ARCH)
DEB_HOST_ARCH_CPU	?= $(call vafilt,$(DPKG_VARS),DEB_HOST_ARCH_CPU)
DEB_HOST_MULTIARCH	?= $(call vafilt,$(DPKG_VARS),DEB_HOST_MULTIARCH)

PATH := $(CURDIR)/bin:$(PATH)
export PATH

CHANGELOG_VARS := $(shell dpkg-parsechangelog | sed -n 's/ /_/g;/^[^_]/s/^\([^:]*\):_\(.*\)/\1=\2/p')
PKGSOURCE := $(call vafilt,$(CHANGELOG_VARS),Source)
PKGVERSION := $(call vafilt,$(CHANGELOG_VARS),Version)

distribution := $(shell lsb_release --id --short)
distrel := $(shell lsb_release --codename --short)
derivative := $(shell if dpkg-vendor --derives-from Ubuntu; then echo Ubuntu; \
               elif dpkg-vendor --derives-from Debian; then echo Debian; \
               else echo Unknown; fi)
ifeq ($(distrel),n/a)
  distrel := sid
endif

multiarch_dir = /$(DEB_HOST_MULTIARCH)

hotspot_archs	= amd64 i386 arm64 armhf ppc64 ppc64el sparc64 s390x kfreebsd-amd64 kfreebsd-i386
jtreg_archs	= $(hotspot_archs) alpha ia64 powerpc powerpcspe ppc64 sh4 x32
#jtreg_archs	+= armel
#jtreg_archs	+= mips mipsel mips64 mips64el

# FIXME: use bootcycle builds for zero archs?
bootcycle_build = $(if $(filter $(DEB_HOST_ARCH), $(hotspot_archs)),yes)
bootcycle_build = $(if $(filter $(DEB_HOST_ARCH), amd64 i386),yes)
zbootcycle_build =
ifneq ($(DEB_HOST_ARCH),$(DEB_BUILD_ARCH))
  bootcycle_build =
  zbootcycle_build =
endif
ifneq (,$(filter nobootcycle, $(DEB_BUILD_OPTIONS)))
  bootcycle_build =
  zbootcycle_build =
endif

ifneq (,$(filter $(distrel),lucid precise quantal raring saucy trusty utopic vivid wily lenny etch squeeze wheezy jessie))
  is_default = no
else
  is_default = yes
endif

# FIXME: change that after the buster freeze for ea builds
is_upstream_release = yes

srcdir		= .
builddir	= build
zbuilddir	= build-zero

VENDOR		= openjdk
Vendor		= OpenJDK
TOP		= usr/lib/jvm
origin		= openjdk
basename	= openjdk-$(shortver)
ifneq (,$(filter $(DEB_HOST_ARCH), $(hotspot_archs)))
  priority	= $(if $(filter yes, $(is_default)),1111,1109)
  vm_name	= Hotspot JIT
else
  priority	= $(if $(filter yes, $(is_default)),1104,1103)
  vm_name	= Hotspot Zero
endif
jvmver		= 1.11.0
shortver	= 11
v_upstream	:= $(shell echo $(PKGVERSION) | sed 's/-[^-][^-]*$$//')
v_pkgrel	:= $(shell echo $(PKGVERSION) | sed 's/^.*-//')
# FIXME. currently v_upstream like 11~4
v_upbase	:= $(word 1, $(subst +, , $(v_upstream)))
v_upbuild	:= $(word 2, $(subst +, , $(v_upstream)))
#v_upbase	:= $(word 1, $(subst ~, , $(v_upstream)))
#v_upbuild	:= $(word 2, $(subst ~, , $(v_upstream)))
# that should be the package version ...

ifneq ($(PKGVERSION),$(v_upbase)+$(v_upbuild)-$(v_pkgrel))
  $(error wrong version: $(v_upbase)+$(v_upbuild)-$(v_pkgrel) should be: $(PKGVERSION))
endif
#ifneq ($(PKGVERSION),$(v_upbase)~$(v_upbuild)-$(v_pkgrel))
#  $(error wrong version: $(v_upbase)~$(v_upbuild)-$(v_pkgrel) should be: $(PKGVERSION))
#endif

ifneq (,$(DEB_HOST_MULTIARCH))
  jdirname	= java-$(shortver)-$(origin)-$(DEB_HOST_ARCH)
  jdiralias	= java-$(jvmver)-$(origin)-$(DEB_HOST_ARCH)
  basedir	= $(TOP)/$(jdirname)
  commonbasedir	= $(TOP)/java-$(shortver)-$(origin)-common
  commonbasedir	= $(basedir)
  etcdir	= etc/java-$(shortver)-$(origin)
else
  jdirname	= java-$(shortver)-$(origin)
  jdiralias	= java-$(jvmver)-$(origin)
  basedir	= $(TOP)/$(jdirname)
  commonbasedir	= $(TOP)/java-$(shortver)-$(origin)
  etcdir	= etc/$(jdirname)
endif
security	= $(etcdir)/security
ifeq ($(bootcycle_build),yes)
  sdkimg	= bootcycle-build/images/jdk
  build_target	= bootcycle-images test-image
else
  sdkimg	= images/jdk
  build_target	= images test-image
endif
ifeq ($(zbootcycle_build),yes)
  zsdkimg	= bootcycle-build/images/jdk
  zbuild_target	= bootcycle-images test-image
else
  zsdkimg	= images/jdk
  zbuild_target	= images test-image
endif

# Support parallel=<n> in DEB_BUILD_OPTIONS (see #209008)
COMMA=,
SPACE = $(EMPTY) $(EMPTY)
ifneq (,$(filter parallel=%,$(subst $(COMMA), ,$(DEB_BUILD_OPTIONS))))
  NJOBS = $(subst parallel=,,$(filter parallel=%,$(subst $(COMMA), ,$(DEB_BUILD_OPTIONS))))
endif

with_check = $(if $(findstring nocheck, $(DEB_BUILD_OPTIONS)),,yes)
# see Debian #920161
ifneq (,$(filter $(DEB_HOST_ARCH), alpha))
  with_check = disabled running check on $(DEB_HOST_ARCH)
endif
ifneq (,$(filter $(distrel), precise trusty))
  with_check = disabled for $(distrel)
endif

with_docs = $(if $(findstring nodoc, $(DEB_BUILD_OPTIONS)),,yes)
ifneq (,$(filter $(distrel), precise trusty))
  with_docs =
endif

with_wqy_zenhai = $(if $(filter $(distrel),lenny),,yes)

arch_map	:= alpha=alpha arm=arm armel=arm armhf=arm arm64=aarch64 amd64=amd64 hppa=parisc i386=i586 m68k=m68k mips=mips mipsel=mipsel mips64=mips64 mips64el=mips64el powerpc=ppc powerpcspe=ppc ppc64=ppc64 ppc64el=ppc64le riscv64=riscv64 sparc=sparc sparc64=sparcv9 sh4=sh s390x=s390x ia64=ia64 x32=x32

jvmarch		:= $(strip $(patsubst $(DEB_HOST_ARCH_CPU)=%, %, \
			$(filter $(DEB_HOST_ARCH_CPU)=%, $(arch_map))))
ifeq ($(DEB_HOST_ARCH),x32)
  jvmarch := x32
endif

default_vm = $(if $(filter $(DEB_HOST_ARCH), $(hotspot_archs)),hotspot,zero)

any_archs = alpha amd64 armel armhf arm64 i386 ia64 mips mipsel mips64 mips64el powerpc powerpcspe ppc64 ppc64el m68k riscv64 sh4 sparc sparc64 s390x x32 kfreebsd-i386 kfreebsd-amd64

altzero_archs = $(hotspot_archs)
ifneq (,$(filter $(distrel),trusty))
  altzero_archs := $(filter-out arm64, $(hotspot_archs))
endif

ifneq (,$(filter noaltzero, $(DEB_BUILD_OPTIONS)))
  altzero_archs =
else ifneq (,$(filter $(DEB_HOST_ARCH), $(altzero_archs)))
  alternate_vms += zero
  zero_dir = zero
endif

# needed for the jexec build
export DEBIAN_JDK_BASE_DIR := /$(basedir)

BOOTJDK_HOME := $(strip $(subst /bin/javac,, $(firstword $(wildcard \
			/usr/lib/jvm/java-10-openjdk-$(DEB_BUILD_ARCH)/bin/javac \
			/usr/lib/jvm/java-11-openjdk-$(DEB_BUILD_ARCH)/bin/javac \
		))))

ifeq ($(DEB_BUILD_ARCH),$(DEB_HOST_ARCH))
  BUILDJDK_HOME = $(CURDIR)/$(builddir)/$(sdkimg)
else
  BUILDJDK_HOME = $(BOOTJDK_HOME)
endif

# for Hotspot: hotspot/make/linux/makefiles/vm.make
# Don't overwrite Hotspot opt level :
# -O3 is already default option for hotspot

# FIXME: ftbfs with -Werror=format-security
dpkg_buildflags_hs = \
	DEB_CFLAGS_MAINT_STRIP="-O2 -Werror=format-security" \
	DEB_CXXFLAGS_MAINT_STRIP="-O2 -Werror=format-security" \
	DEB_CFLAGS_MAINT_APPEND="-fno-stack-protector -Wno-deprecated-declarations" \
	DEB_CXXFLAGS_MAINT_APPEND="-fno-stack-protector -Wno-deprecated-declarations$(if $(filter $(DEB_HOST_ARCH), armel armhf), -fpermissive)"
# jdk/make/CompileDemos.gmk (SetupJVMTIDemo) doesn't like commas in flags
dpkg_buildflags_hs += \
	DEB_LDFLAGS_MAINT_STRIP="-Wl,-z,relro -Wl,-Bsymbolic-functions" \
	DEB_LDFLAGS_MAINT_APPEND="-Xlinker -z -Xlinker relro -Xlinker -Bsymbolic-functions"
dpkg_buildflags_hs += dpkg-buildflags
export EXTRA_CPPFLAGS_HS := $(shell $(dpkg_buildflags_hs) --get CPPFLAGS)
export EXTRA_CFLAGS_HS   := $(shell $(dpkg_buildflags_hs) --get CFLAGS; $(dpkg_buildflags_hs) --get CPPFLAGS)
export EXTRA_CXXFLAGS_HS := $(shell $(dpkg_buildflags_hs) --get CXXFLAGS) -Wno-deprecated-declarations
export EXTRA_LDFLAGS_HS  := $(shell $(dpkg_buildflags_hs) --get LDFLAGS)

dpkg_buildflags_zero = \
	DEB_CFLAGS_MAINT_STRIP="-O2 -Werror=format-security -fstack-protector -fstack-protector-strong" \
	DEB_CXXFLAGS_MAINT_STRIP="-O2 -Werror=format-security -fstack-protector -fstack-protector-strong" \
	DEB_CFLAGS_MAINT_APPEND="-fno-stack-protector -Wno-deprecated-declarations" \
	DEB_CXXFLAGS_MAINT_APPEND="-fno-stack-protector -Wno-deprecated-declarations"
# jdk/make/CompileDemos.gmk (SetupJVMTIDemo) doesn't like commas in flags
dpkg_buildflags_zero += \
	DEB_LDFLAGS_MAINT_STRIP="-Wl,-z,relro -Wl,-Bsymbolic-functions" \
	DEB_LDFLAGS_MAINT_APPEND="-Xlinker -z -Xlinker relro -Xlinker -Bsymbolic-functions"
dpkg_buildflags_zero += dpkg-buildflags
export EXTRA_CPPFLAGS_ZERO := $(shell $(dpkg_buildflags_zero) --get CPPFLAGS)
export EXTRA_CFLAGS_ZERO   := $(shell $(dpkg_buildflags_zero) --get CFLAGS; $(dpkg_buildflags_zero) --get CPPFLAGS)
export EXTRA_CXXFLAGS_ZERO := $(shell $(dpkg_buildflags_zero) --get CXXFLAGS)
export EXTRA_LDFLAGS_ZERO  := $(shell $(dpkg_buildflags_zero) --get LDFLAGS)

ifeq ($(DEB_HOST_ARCH),alpha)
  export EXTRA_LDFLAGS_ZERO += -Wl,--no-relax
endif

# for JDK: jdk/make/common/Defs.gmk
# Don't overwrite JDK opt level :
# 1) with forced -03, it cause wrong Math.* computations, see #679292 and #678228
# 2) JDK already use it's own OPTIMIZATION_LEVEL variable for each module
dpkg_buildflags_jdk = DEB_CFLAGS_MAINT_STRIP="-O2" DEB_CXXFLAGS_MAINT_STRIP="-O2"
dpkg_buildflags_jdk += dpkg-buildflags
export EXTRA_CPPFLAGS_JDK := $(shell $(dpkg_buildflags_jdk) --get CPPFLAGS)
export EXTRA_CFLAGS_JDK   := $(shell $(dpkg_buildflags_jdk) --get CFLAGS) $(shell $(dpkg_buildflags_jdk) --get CPPFLAGS)
export EXTRA_CXXFLAGS_JDK := $(shell $(dpkg_buildflags_jdk) --get CXXFLAGS)
export EXTRA_LDFLAGS_JDK  := $(shell $(dpkg_buildflags_jdk) --get LDFLAGS)

#for IcedTea
ifeq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
dpkg_buildflags_it += DEB_CFLAGS_MAINT_STRIP="-O2" DEB_CXXFLAGS_MAINT_STRIP="-O2"
dpkg_buildflags_it += DEB_CFLAGS_MAINT_APPEND="-O3" DEB_CXXFLAGS_MAINT_APPEND="-O3"
endif
dpkg_buildflags_it += dpkg-buildflags
export EXTRA_CPPFLAGS_IT := $(shell $(dpkg_buildflags_it) --get CPPFLAGS)
export EXTRA_CFLAGS_IT   := $(shell $(dpkg_buildflags_it) --get CFLAGS)
export EXTRA_CXXFLAGS_IT := $(shell $(dpkg_buildflags_it) --get CXXFLAGS)
export EXTRA_LDFLAGS_IT  := $(shell $(dpkg_buildflags_it) --get LDFLAGS)

# This section should be in sync with "bd_gcc" definition
ifneq (,$(filter $(distrel),saucy trusty))
  export CC = gcc-4.8
  export CXX = g++-4.8
else ifneq (,$(filter $(distrel),utopic vivid jessie))
  export CC = gcc-4.9
  export CXX = g++-4.9
else ifneq (,$(filter $(distrel),wily xenial))
  ifneq (,$(filter $(DEB_HOST_ARCH), $(hotspot_archs)))
    export CC = $(DEB_HOST_GNU_TYPE)-gcc-5
    export CXX = $(DEB_HOST_GNU_TYPE)-g++-5
    # FIXME: altzero seems to build with GCC 5 on i386, amd64, ppc64el ...
    ifneq (,$(filter $(DEB_HOST_ARCH), arm64))
      ZERO_CC = $(DEB_HOST_GNU_TYPE)-gcc-4.9
      ZERO_CXX = $(DEB_HOST_GNU_TYPE)-g++-4.9
    endif
  else
    export CC = $(DEB_HOST_GNU_TYPE)-gcc-4.9
    export CXX = $(DEB_HOST_GNU_TYPE)-g++-4.9
  endif
else ifneq (,$(filter $(distrel),stretch))
  # FIXME: still hotspot core dumps with GCC 6
  export CC = $(DEB_HOST_GNU_TYPE)-gcc-6
  export CXX = $(DEB_HOST_GNU_TYPE)-g++-6
else ifneq (,$(filter $(distrel),artful bionic))
  export CC = $(DEB_HOST_GNU_TYPE)-gcc-7
  export CXX = $(DEB_HOST_GNU_TYPE)-g++-7
else ifneq (,$(filter $(distrel),precise))
  export CC = $(DEB_HOST_GNU_TYPE)-gcc-8
  export CXX = $(DEB_HOST_GNU_TYPE)-g++-8
else
  export CC = $(DEB_HOST_GNU_TYPE)-gcc-8
  export CXX = $(DEB_HOST_GNU_TYPE)-g++-8
endif

# until we are able to b-d on gcc-for-host ...
ifneq ($(DEB_BUILD_GNU_TYPE),$(DEB_HOST_GNU_TYPE))
  export CC = $(DEB_HOST_GNU_TYPE)-gcc
  export CXX = $(DEB_HOST_GNU_TYPE)-g++
endif

ifneq (,$(filter $(distrel),squeeze lucid))
  with_bridge = bridge
  with_jni_bridge = yes
else
  with_bridge = atk
endif

with_nss = yes

on_buildd := $(shell [ -f /CurrentlyBuilding -o "$$LOGNAME" = buildd ] && echo yes)

CONFIGURE_ARGS =

# GNU/kFreeBSD don't support epoll syscall so don't try to check of it.
# FIXME need to check the flag, configure complains about it
#ifneq (,$(filter $(DEB_HOST_ARCH), kfreebsd-amd64 kfreebsd-i386))
#  CONFIGURE_ARGS += --disable-compile-against-syscalls
#endif

# there are problems --with-alt-jar=/usr/bin/fastjar,
# see http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=217
# only use it for zero ports except powerpc (which we assume as
# fast enough to build.
ifeq (,$(filter $(DEB_HOST_ARCH), $(hotspot_archs) ia64 powerpc powerpcspe))
  CONFIGURE_ARGS += --with-alt-jar=/usr/bin/fastjar
endif

ifeq (,$(filter $(DEB_HOST_ARCH), $(hotspot_archs)))
  CONFIGURE_ARGS += --enable-zero
endif

ifeq (,$(filter $(DEB_BUILD_OPTIONS), terse))
  EXTRA_BUILD_ENV += MAKE_VERBOSE=y QUIETLY= LOG=debug
endif

# timestamp skew on kFreeBSD
EXTRA_BUILD_ENV += IGNORE_OLD_CONFIG=true

EXTRA_BUILD_ENV += LIBFFI_LIBS=-lffi_pic

CONFIGURE_ARGS += --enable-system-kerberos

ifeq ($(with_nss),yes)
  CONFIGURE_ARGS += --enable-nss
else ifeq ($(with_nss),no)
  CONFIGURE_ARGS += --disable-nss
endif

ifeq ($(with_systemtap),yes)
  CONFIGURE_ARGS += --enable-systemtap --with-abs-install-dir=/$(basedir)
endif

COMMON_CONFIGURE_ARGS =
DEFAULT_CONFIGURE_ARGS =
ZERO_CONFIGURE_ARGS =

# FIXME: --with-jvm-variants=server,zero not supported upstream
ifneq (,$(filter $(DEB_HOST_ARCH),$(hotspot_archs)))
  ifneq (,$(filter $(DEB_HOST_ARCH),i386))
    DEFAULT_CONFIGURE_ARGS += --with-jvm-variants=client,server
  else
    DEFAULT_CONFIGURE_ARGS += --with-jvm-variants=server
  endif
else
  DEFAULT_CONFIGURE_ARGS += --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE)
  DEFAULT_CONFIGURE_ARGS += --with-jvm-variants=zero
endif
ZERO_CONFIGURE_ARGS += --with-jvm-variants=zero

DEFAULT_CONFIGURE_ARGS += --with-boot-jdk=$(BOOTJDK_HOME)
ZERO_CONFIGURE_ARGS += --with-boot-jdk=$(BUILDJDK_HOME)

COMMON_CONFIGURE_ARGS += --disable-ccache

# FIXME: zero not ready for --disable-precompiled-headers
#COMMON_CONFIGURE_ARGS += --disable-precompiled-headers
ifneq (,$(filter $(DEB_HOST_ARCH),$(hotspot_archs)))
  DEFAULT_CONFIGURE_ARGS += --disable-precompiled-headers
endif

ifneq (,$(filter $(DEB_HOST_ARCH), powerpc))
  DEFAULT_CONFIGURE_ARGS += --with-boot-jdk-jvmargs="-XX:ThreadStackSize=2240"
endif

ifneq (,$(filter $(DEB_HOST_ARCH), ppc64 ppc64el))
  ZERO_CONFIGURE_ARGS += --with-boot-jdk-jvmargs="-XX:ThreadStackSize=2240"
endif

ifeq ($(with_check),yes)
  COMMON_CONFIGURE_ARGS += --with-jtreg=/usr
endif

ifneq (,$(filter $(DEB_HOST_ARCH), amd64))
  DEFAULT_CONFIGURE_ARGS += --with-jvm-features=zgc
endif

ifeq ($(distribution),Debian)
  COMMON_CONFIGURE_ARGS += \
	--with-vendor-name='$(distribution)' \
	--with-vendor-url='https://tracker.debian.org/$(basename)' \
	--with-vendor-bug-url='https://bugs.debian.org/$(basename)' \
	--with-vendor-vm-bug-url='https://bugs.debian.org/$(basename)'
else ifeq ($(distribution),Ubuntu)
  ppa_build := $(shell if echo '$(v_pkgrel)' | egrep '^[0-9]+(ubuntu[0-9]+)?(~[0-9.]+)?$$'; then echo no; else echo yes; fi)
  ifeq ($(ppa_build),yes)
    COMMON_CONFIGURE_ARGS += \
	--with-vendor-name='Private Build' \
	--with-vendor-url='Unknown' \
	--with-vendor-bug-url='Unknown' \
	--with-vendor-vm-bug-url='Unknown'
  else
    COMMON_CONFIGURE_ARGS += \
	--with-vendor-name='$(distribution)' \
	--with-vendor-url='https://ubuntu.com/' \
	--with-vendor-bug-url='https://bugs.launchpad.net/ubuntu/+source/openjdk-lts' \
	--with-vendor-vm-bug-url='https://bugs.launchpad.net/ubuntu/+source/openjdk-lts'
  endif
else
  COMMON_CONFIGURE_ARGS += \
	--with-vendor-name='$(distribution)' \
	--with-vendor-url='Unknown' \
	--with-vendor-bug-url='Unknown' \
	--with-vendor-vm-bug-url='Unknown'
endif

COMMON_CONFIGURE_ARGS += \
	--with-version-pre='$(if $(filter yes, $(is_upstream_release)),,ea)' \
	--with-version-build='$(v_upbuild)' \
	--with-version-opt='post-$(distribution)-$(v_pkgrel)' \

COMMON_CONFIGURE_ARGS += \
	--with-debug-level=release \
	--with-native-debug-symbols=internal \
	--enable-unlimited-crypto \
	--with-zlib=system \
	--with-giflib=system \
	--with-libpng=system \
	--with-libjpeg=system \
	--with-lcms=system \
	--with-pcsclite=system \
	--disable-warnings-as-errors \
	--disable-javac-server \

ifneq (,$(filter $(distrel),precise))
  # building with a GCC from a PPA ...
  COMMON_CONFIGURE_ARGS += \
	--with-stdc++lib=static
else
  COMMON_CONFIGURE_ARGS += \
	--with-stdc++lib=dynamic
endif

ifneq (,$(NJOBS))
  COMMON_CONFIGURE_ARGS += --with-num-cores=$(NJOBS)
endif

# FIXME: upstream says the extra flags are not designed for general purpose ...
# http://mail.openjdk.java.net/pipermail/jdk8u-dev/2014-July/001389.html

# FIXME: demos fail to build with these ...
# FIXME: zero ftbfs without -fpermissive
#src/cpu/zero/vm/cppInterpreter_zero.cpp:732:30: error: invalid conversion from 'intptr_t {aka long int}' to 'const void*' [-fpermissive]
#       object = (oop) locals[0];
#                              ^

#COMMON_CONFIGURE_ARGS += \
	--with-extra-cflags='$(EXTRA_CPPFLAGS_HS) $(EXTRA_CFLAGS_HS)' \
	--with-extra-cxxflags='$(EXTRA_CPPFLAGS_HS) $(EXTRA_CXXFLAGS_HS)' \
	--with-extra-ldflags='$(EXTRA_LDFLAGS_HS)'

ifneq (,$(filter $(DEB_HOST_ARCH), $(hotspot_archs)))
  DEFAULT_CONFIGURE_ARGS += \
	--with-extra-cflags='$(EXTRA_CPPFLAGS_HS) $(EXTRA_CFLAGS_HS)' \
	--with-extra-cxxflags='$(EXTRA_CPPFLAGS_HS) $(EXTRA_CXXFLAGS_HS)' \
	--with-extra-ldflags='$(EXTRA_LDFLAGS_HS)'
else
  DEFAULT_CONFIGURE_ARGS += \
	--with-extra-cflags='$(EXTRA_CPPFLAGS_ZERO) $(EXTRA_CFLAGS_ZERO)' \
	--with-extra-cxxflags='$(EXTRA_CPPFLAGS_ZERO) $(EXTRA_CXXFLAGS_ZERO)' \
	--with-extra-ldflags='$(EXTRA_LDFLAGS_ZERO)'
endif

ZERO_CONFIGURE_ARGS += \
	--with-extra-cflags='$(EXTRA_CPPFLAGS_ZERO) $(EXTRA_CFLAGS_ZERO)' \
	--with-extra-cxxflags='$(EXTRA_CPPFLAGS_ZERO) $(EXTRA_CXXFLAGS_ZERO)' \
	--with-extra-ldflags='$(EXTRA_LDFLAGS_ZERO)'

ifneq ($(DEB_HOST_ARCH),$(DEB_BUILD_ARCH))
  COMMON_CONFIGURE_ARGS += \
	--build=$(DEB_BUILD_GNU_TYPE) \
	--host=$(DEB_HOST_GNU_TYPE) \
	--target=$(DEB_HOST_GNU_TYPE) \
	BUILD_CC=$(subst $(DEB_HOST_GNU_TYPE),$(DEB_BUILD_GNU_TYPE),$(CC)) \
	BUILD_LD=$(subst $(DEB_HOST_GNU_TYPE),$(DEB_BUILD_GNU_TYPE),$(CC)) \
	BUILD_CXX=$(subst $(DEB_HOST_GNU_TYPE),$(DEB_BUILD_GNU_TYPE),$(CXX)) \

endif

# (most) jre and jdk tools handled by the alternatives system.
# dups in heimdal-clients, krb5-user: kinit, klist, ktab, no alternatives
# have jrunscript in the jdk packages

all_tools	= $(notdir $(wildcard $(builddir)/$(sdkimg)/bin/*))

jdk_hl_tools	= jar jarsigner javac javadoc javap jcmd jdb \
	jdeprscan jdeps jimage jinfo jlink jmap jmod jps \
	jrunscript jshell jstack jstat jstatd rmic serialver
ifneq (,$(filter $(DEB_HOST_ARCH), amd64 arm64))
  jdk_hl_tools	+= jaotc
endif
ifeq (,$(filter $(DEB_HOST_ARCH), alpha armel ia64 m68k mips mipsel mips64el powerpc riscv64 s390x x32))
  jdk_hl_tools	+= jhsdb
endif
jdk_tools	= jconsole

all_jre_tools	= $(filter-out $(jdk_hl_tools) $(jdk_tools), $(all_tools))
# no tools in $(p_jre)
jre_tools	=
jre_hl_tools	:= $(filter-out $(jre_tools), $(all_jre_tools))

# build dependencies
ifneq (,$(filter $(distrel),precise))
  bd_autotools = autoconf2.69, automake, autotools-dev,
else
  bd_autotools = autoconf, automake, autotools-dev,
endif

ifneq (,$(filter $(distrel),precise))
    bd_bootstrap = openjdk-10-jdk-headless | openjdk-11-jdk-headless,
else ifneq (,$(filter $(distrel),squeeze wheezy jessie trusty xenial))
    bd_bootstrap = openjdk-10-jdk-headless:native | openjdk-11-jdk-headless:native,
else
    bd_bootstrap = openjdk-11-jdk-headless:native | openjdk-10-jdk-headless:native,
endif
ifeq (,$(filter $(distrel),squeeze wheezy jessie precise trusty xenial))
  bd_cross += \
	$(basename)-jdk-headless <cross>,
else
  bd_cross += \
	file,
endif

ifneq (,$(filter $(distrel),squeeze wheezy jessie precise trusty))
  old_debhelper = veryold
  bd_debhelper = debhelper (>= 9),
else ifneq (,$(filter $(distrel), stretch xenial))
  old_debhelper = old
  bd_debhelper = debhelper (>= 9.20141010), dpkg-dev (>= 1.17.14),
else
  bd_debhelper = debhelper (>= 11),
endif

# This section should be in sync with "CC/CXX" definition
ifneq (,$(filter $(distrel), saucy trusty))
  bd_gcc = g++-4.8,
else ifneq (,$(filter $(distrel),utopic vivid jessie))
  bd_gcc = g++-4.9,
else ifneq (,$(filter $(distrel),wily xenial))
  bd_gcc = g++-5 [$(hotspot_archs)], g++-4.9 [$(strip $(foreach a,$(hotspot_archs), !$(a)))], g++-4.9 [arm64],
else ifneq (,$(filter $(distrel),stretch))
  bd_gcc = g++-6 <!cross>,
else ifneq (,$(filter $(distrel),artful bionic))
  bd_gcc = g++-7 <!cross>,
else ifneq (,$(filter $(distrel),precise))
  # FIXME: ftbfs on armhf with the default GCC
  bd_gcc = g++-8,
else
  bd_gcc = g++-8 <!cross>,
endif
bd_syslibs = zlib1g-dev, libattr1-dev,
ifneq (,$(filter $(distrel),squeeze lucid))
  bd_syslibs += libpng12-dev, libjpeg62-dev,
else ifneq (,$(filter $(distrel),wheezy precise quantal raring saucy))
  bd_syslibs += libpng-dev, libjpeg8-dev,
else
  bd_syslibs += libpng-dev, libjpeg-dev,
endif
bd_syslibs += \
	libgif-dev,
bd_openjdk = \
	libxtst-dev, libxi-dev, libxt-dev, libxaw7-dev, libxrender-dev, libcups2-dev, \
	libasound2-dev, liblcms2-dev, libfreetype6-dev (>= 2.2.1), \
	libxinerama-dev, libkrb5-dev, xsltproc, libpcsclite-dev, libgtk-3-dev, \
	libelf-dev, libfontconfig1-dev,

pkg_ffidev = libffi-dev

bd_zero = \
	$(pkg_ffidev) [$(foreach a,$(hotspot_archs),!$(a))],
bd_zero = \
	$(pkg_ffidev),

bd_ant = ant, ant-optional,

bd_fastjar = fastjar (>= 2:0.96-0ubuntu2),
ifeq ($(with_nss),yes)
  ifneq (,$(filter $(distrel),squeeze lucid precise quantal))
    bd_nss = libnss3-dev (>= 3.12.3),
  else ifneq (,$(filter $(distrel),wheezy raring saucy trusty))
    bd_nss = libnss3-dev (>= 2:3.12.3),
  else
    bd_nss = libnss3-dev (>= 2:3.17.1),
  endif
endif
ifeq ($(with_systemtap),yes)
  bd_systemtap = systemtap-sdt-dev [!sh4],
endif

ifeq (,$(filter $(distrel),precise))
  nocheck_profile = $(EMPTY) <!nocheck>
endif

bd_check = \
  jtreg$(nocheck_profile), testng$(nocheck_profile), \
  xvfb$(nocheck_profile), xauth$(nocheck_profile), \
  xfonts-base$(nocheck_profile), libgl1-mesa-dri [!x32]$(nocheck_profile), \
  xfwm4$(nocheck_profile), x11-xkb-utils$(nocheck_profile), \
  dbus-x11$(nocheck_profile),

ifneq (,$(filter $(distrel),precise trusty xenial))
  # no jtreg backport yet
  bd_check = file,
endif

dlopen_hl_depends = \
	libcups2, liblcms2-2,
ifeq ($(derivative),Ubuntu)
  ifneq (,$(filter $(distrel),lucid))
    dlopen_hl_depends += libjpeg62,
  else
    dlopen_hl_depends += libjpeg8,
  endif
else
  ifneq (,$(filter $(distrel),squeeze))
    dlopen_hl_depends += libjpeg62,
  else
    dlopen_hl_depends += libjpeg62-turbo,
  endif
endif
dlopen_hl_depends += libfontconfig1,
ifneq ($(with_nss),no)
  ifneq (,$(filter $(distrel),squeeze lucid precise))
    dlopen_hl_depends += , libnss3-1d (>= 3.12.3)
  else ifneq (,$(filter $(distrel),wheezy quantal raring saucy trusty))
    dlopen_hl_depends += , libnss3 (>= 2:3.12.3)
  else
    dlopen_hl_depends += , libnss3 (>= 2:3.17.1)
  endif
endif
dlopen_hl_recommends =
dlopen_jre_depends = \
	libglib2.0-0 (>= 2.24), libgtk2.0-0 | libgtk-3-0, libxrandr2, libxinerama1,
ifneq (,$(filter $(distrel),squeeze wheezy jessie stretch lucid precise xenial))
  dlopen_jre_depends = libgl1-mesa-glx | libgl1,
else
  dlopen_jre_depends = libgl1,
endif
dlopen_jre_recommends =

# .desktop files need to be multiarch installable
java_launcher = /$(basedir)/bin/java
java_launcher = /usr/bin/java
ifeq ($(derivative),Ubuntu)
  java_launcher = cautious-launcher %f /$(basedir)/bin/java
  java_launcher = cautious-launcher %f /usr/bin/java
endif

ifneq (,$(filter $(distrel),squeeze wheezy lucid precise quantal raring))
  core_fonts = ttf-dejavu-extra
else
  core_fonts = fonts-dejavu-extra
endif
ifneq (,$(filter $(distrel),squeeze lucid))
  cjk_fonts = ttf-baekmuk | ttf-unfonts | ttf-unfonts-core,
  cjk_fonts += ttf-sazanami-gothic | ttf-kochi-gothic,
  cjk_fonts += ttf-sazanami-mincho | ttf-kochi-mincho,
else
  cfk_fonts = fonts-nanum,
  cjk_fonts += fonts-ipafont-gothic, fonts-ipafont-mincho,
endif
cjk_fonts += $(if $(with_wqy_zenhai),fonts-wqy-microhei | fonts-wqy-zenhei,fonts-arphic-uming),
ifneq (,$(filter $(distrel),squeeze wheezy))
  cjk_fonts += ttf-indic-fonts,
else ifneq (,$(filter $(distrel), lucid maverick natty oneiric precise quantal raring saucy trusty))
  cjk_fonts += ttf-indic-fonts-core, ttf-telugu-fonts, ttf-oriya-fonts,
  cjk_fonts += ttf-kannada-fonts, ttf-bengali-fonts,
else
  cjk_fonts += fonts-indic,
endif

jrehl_breaks = clojure1.8 (<= 1.8.0-7ubuntu1~),
ifneq (,$(filter $(distrel),buster bionc cosmic disco eoan))
  jrehl_breaks += \
	jetty9 (<< 9.4.15-1~), netbeans (<< 10.0-3~), visualvm (<< 1.4.2-2~), \
	eclipse-platform (<< 3.8.1-11), libequinox-osgi-java (<< 3.9.1),
endif
ifneq (,$(filter $(distrel),bionc cosmic disco eoan))
  jrehl_breaks += \
	tomcat8 (<< 8.5.39-1ubuntu1~),
endif
ifneq (,$(filter $(distrel),buster sid))
  jrehl_breaks += libreoffice-core (<< 1:6.1.5-2~),
else ifneq (,$(filter $(distrel),xenial))
  jrehl_breaks += libreoffice-core (<< 1:5.1.6~rc2-0ubuntu1~xenial7),
else ifneq (,$(filter $(distrel),bionic))
  jrehl_breaks += libreoffice-core (<< 1:6.0.7-0ubuntu0.18.04.6),
else ifneq (,$(filter $(distrel),disco))
  jrehl_breaks += libreoffice-core (<< 1:6.2.2-0ubuntu2),
endif

p_jre	= $(basename)-jre
p_jrehl	= $(basename)-jre-headless
p_jrez	= $(basename)-jre-zero
p_jdkhl	= $(basename)-jdk-headless
p_jdk	= $(basename)-jdk
p_demo	= $(basename)-demo
p_src	= $(basename)-source
p_doc	= $(basename)-doc
p_dbg	= $(basename)-dbg

d	= debian/tmp
d_jre	= debian/$(p_jre)
d_jrehl	= debian/$(p_jrehl)
d_jrez	= debian/$(p_jrez)
d_jdkhl	= debian/$(p_jdkhl)
d_jdk	= debian/$(p_jdk)
d_demo	= debian/$(p_demo)
d_src	= debian/$(p_src)
d_doc	= debian/$(p_doc)
d_dbg	= debian/$(p_dbg)

control_vars = \
	'-Vvm:Name=$(vm_name)' \
	'-Vdlopenhl:Depends=$(dlopen_hl_depends)' \
	'-Vdlopenhl:Recommends=$(dlopen_hl_recommends)' \
	'-Vdlopenjre:Depends=$(dlopen_jre_depends)' \
	'-Vdlopenjre:Recommends=$(dlopen_jre_recommends)' \

ifeq ($(with_bridge),atk)
  control_vars += '-Vbridge:Recommends=libatk-wrapper-java-jni (>= 0.30.4-0ubuntu2)'
else ifeq ($(with_bridge),yes)
  ifneq (,$(DEB_HOST_MULTIARCH))
    control_vars += '-Vbridge:Recommends=libaccess-bridge-java-jni (>= 1.26.2-6)'
  else ifeq ($(with_jni_bridge),yes)
    control_vars += '-Vbridge:Recommends=libaccess-bridge-java-jni'
  else
    control_vars += '-Vbridge:Recommends=libaccess-bridge-java'
  endif
endif

ifeq (,$(filter $(DEB_HOST_ARCH), $(hotspot_archs)))
  control_vars += '-Vdefaultvm:Provides=$(p_jre)-zero'
endif

pkg_certs = ca-certificates-java
ifneq (,$(filter $(distrel), squeeze wheezy jessie stretch precise trusty xenial bionic cosmic disco))
  control_vars += '-Vcacert:Depends=$(pkg_certs)'
else
  control_vars += '-Vcacert:Depends=$(pkg_certs) (>= 20190405~)'
endif

ifneq (,$(filter $(distrel), squeeze wheezy jessie lucid precise quantal raring saucy trusty utopic vivid))
  control_vars += '-Vmountpoint:Depends=initscripts'
else
  control_vars += '-Vmountpoint:Depends=util-linux (>= 2.26.2-4)'
endif

pkg_jcommon = java-common (>= 0.28)
control_vars += '-Vjcommon:Depends=$(pkg_jcommon)'

control_vars += '-Vjrehl:Breaks=$(jrehl_breaks)'

debian/control: debian/control.in debian/rules
	@cp -p debian/control debian/control.old
	sed \
	      -e 's/@basename@/$(basename)/g' \
	      -e 's/@bd_autotools@/$(bd_autotools)/g' \
	      -e 's/@bd_bootstrap@/$(strip $(bd_bootstrap))/g' \
	      -e 's/@bd_cross@/$(strip $(bd_cross))/g' \
	      -e 's/@bd_debhelper@/$(strip $(bd_debhelper))/g' \
	      -e 's/@bd_openjdk@/$(bd_openjdk)/g' \
	      -e 's/@bd_zero@/$(bd_zero)/g' \
	      -e 's/@bd_gcc@/$(bd_gcc)/g' \
	      -e 's/@bd_syslibs@/$(bd_syslibs)/g' \
	      -e 's/@bd_fastjar@/$(bd_fastjar)/g' \
	      -e 's/@bd_nss@/$(bd_nss)/g' \
	      -e 's/@bd_systemtap@/$(bd_systemtap)/g' \
	      -e 's/@bd_ant@/$(bd_ant)/g' \
	      -e 's/@bd_check@/$(bd_check)/g' \
	      -e 's/@core_fonts@/$(core_fonts)/g' \
	      -e 's/@cjk_fonts@/$(cjk_fonts)/g' \
	      -e 's/@any_archs@/$(any_archs)/g' \
	      -e 's/@hotspot_archs@/$(hotspot_archs)/g' \
	      -e 's/@altzero_archs@/$(altzero_archs)/g' \
	    debian/control.in \
	    $(if $(altzero_archs), debian/control.zero-jre) \
	    $(if $(DEB_HOST_MULTIARCH),,| grep -v '^Multi-Arch') \
		> debian/control
	@if cmp -s debian/control debian/control.old; then \
	  rm -f debian/control.old; \
	else \
	  diff -u debian/control.old debian/control | wdiff -d -; \
	  echo "debian/control did change, please restart the build"; \
	  rm -f debian/control.old; \
	  exit 1; \
	fi

debian/tests/%.sh: debian/tests/%.in debian/rules
	sed \
		-e 's,@JDK_TO_TEST@,/$(basedir),g' \
		-e 's/@jtreg_archs@/$(jtreg_archs)/g' \
		$< > $@;
	chmod +x $@

gen-autopkgtests: debian/tests/jtreg-autopkgtest.sh

packaging-files:
	for f in debian/*.in; do \
	  case "$$f" in debian/control.in) continue; esac; \
	  f2=$$(echo $$f | sed 's/JB/$(basename)/;s/\.in$$//'); \
	  sed -e 's/@JRE@/$(p_jre)/g' \
	      -e 's/@JDK@/$(p_jdk)/g' \
	      -e 's/@vendor@/$(Vendor)/g' \
	      -e 's/@RELEASE@/$(shortver)/g' \
	      -e 's/@basename@/$(basename)/g' \
	      -e 's,@TOP@,$(TOP),g' \
	      -e 's,@basedir@,$(basedir),g' \
	      -e 's,@etcdir@,$(etcdir),g' \
	      -e 's,@jdiralias@,$(jdiralias),g' \
	      -e 's,@jdirname@,$(jdirname),g' \
	      -e 's/@srcname@/$(srcname)/g' \
	      -e 's/@jvmarch@/$(jvmarch)/g' \
	      -e 's/@tag@/$(tag)/g' \
	      -e 's/@priority@/$(priority)/g' \
	      -e 's/@mantag@/$(mantag)/g' \
	      -e 's/@multiarch@/$(DEB_HOST_MULTIARCH)/g' \
	      -e 's/@jre_hl_tools@/$(jre_hl_tools)/g' \
	      -e 's/@jre_tools@/$(jre_tools)/g' \
	      -e 's/@jdk_hl_tools@/$(jdk_hl_tools)/g' \
	      -e 's/@jdk_tools@/$(jdk_tools)/g' \
	      -e 's/@corba_tools@/$(corba_tools)/g' \
	      -e 's,@j2se_lib@,$(j2se_lib),g' \
	      -e 's,@j2se_share@,$(j2se_share),g' \
	      -e 's,@java_launcher@,$(java_launcher),g' \
	      -e 's/@cjk_fonts@/$(cjk_fonts)/g' \
	    $$f > $$f2; \
	done

configure: stamps/configure
stamps/configure: stamps/unpack
	@echo '========== $@ =========='
	@echo "Build options: $(DEB_BUILD_OPTIONS), Processors: $$(nproc)"
	@echo '========== $@ =========='
	-cat /proc/meminfo |egrep '^(Mem|Swap)'
	@echo '========== $@ =========='
	-cat /etc/hosts
	@echo '========== $@ =========='
	-cat /etc/fstab
	@echo '========== $@ =========='
	-cat /etc/mtab
	@echo '========== $@ =========='
	-cat /proc/mounts
	@echo '========== $@ =========='

	mkdir -p bin
ifeq (0,1)
ifeq (,$(filter $(DEB_HOST_ARCH), alpha amd64 arm64 hppa mips64 mips64el ppc64 ppc64el s390x sparc64 x32))
	( \
	  echo '#! /bin/sh'; \
	  echo 'if [ -x /usr/bin/linux32 ]; then'; \
	  echo '    exec /usr/bin/linux32 /bin/uname "$$@"'; \
	  echo 'else'; \
	  echo '    exec /bin/uname "$$@"'; \
	  echo 'fi'; \
	) > bin/uname
	chmod +x bin/uname
	echo "UNAME checks"
	uname -a
endif
endif
ifneq (,$(filter $(distrel),precise))
	for i in autoreconf autoheader autoupdate autoscan autom4te ifnames autoconf; do \
	  ln -sf /usr/bin/$${i}2.69 bin/$${i}; \
	done
endif
	which autoconf
	/bin/uname -a
	lsb_release -a

	-cat /proc/sys/kernel/random/entropy_avail

	mkdir -p stamps
	rm -rf $(builddir)
	mkdir -p $(builddir)
#	bash make/autoconf/autogen.sh
	cd $(builddir) && $(EXTRA_BUILD_ENV) bash ../configure \
		$(DEFAULT_CONFIGURE_ARGS) \
		$(COMMON_CONFIGURE_ARGS)

	touch $@

stamps/zero-configure: stamps/build stamps/unpack
	@echo '========== $@ =========='
	mkdir -p stamps
	rm -rf  $(zbuilddir)
	mkdir -p $(zbuilddir)
	$(if $(ZERO_CC), export CC=$(ZERO_CC); export CXX=$(ZERO_CXX);) \
	cd $(zbuilddir) && $(EXTRA_BUILD_ENV) bash ../configure \
		$(ZERO_CONFIGURE_ARGS) \
		$(COMMON_CONFIGURE_ARGS)

	touch $@

stamps/unpack:
	: # apply some architecture specific patches ...
ifeq ($(DEB_HOST_ARCH),alpha)
	patch -p1 < debian/patches/alpha-float-const.diff
endif
ifeq ($(DEB_HOST_ARCH),powerpcspe)
	patch -p1 < debian/patches/powerpcspe-float-const.diff
endif

	$(MAKE) -f debian/rules packaging-files

	mkdir -p stamps
	touch $@

ifeq ($(with_check),yes)
    ifneq (,$(filter $(DEB_HOST_ARCH), $(jtreg_archs)))
      with_jtreg_check = $(default_vm)
    endif

    ifneq (,$(filter zero, $(alternate_vms)))
      ifneq (,$(filter $(DEB_HOST_ARCH), arm64 amd64 i386))
	# only activate after testing; hangs several tests.
	with_jtreg_check += zero
      endif
    endif
endif

build_stamps = \
	stamps/build \
	$(if $(filter $(DEB_HOST_ARCH),$(altzero_archs)),stamps/zero-build)

build_stamps +=  stamps/jtreg-check-default

pre-build:
ifneq (,$(filter $(DEB_HOST_ARCH),s390))
	@echo explicitely fail the build for $(DEB_HOST_ARCH), patches not updated
#else ifneq (,$(filter $(DEB_HOST_ARCH),armel))
#	@echo explicitely fail the build for $(DEB_HOST_ARCH), ARM assembler interpreter not yet ported
	false
endif

build-arch: build
build-indep: build stamps/build-docs
build: pre-build $(build_stamps)
	if [ -f buildwatch.pid ]; then \
	  pid=$$(cat buildwatch.pid); \
	  kill -1 $$pid || :; sleep 1; kill -9 $$pid || :; \
	fi
	rm -f buildwatch.pid

stamps/build: stamps/configure
	@echo '========== $@ =========='
ifneq (,$(filter $(DEB_HOST_ARCH), alpha armel armhf ia64 m68k mips mipsel mips64 mips64el powerpc powerpcspe riscv64 s390x sparc sparc64))
	sh -c 'sh debian/buildwatch.sh $(CURDIR)/$(builddir) &'
endif
	if $(EXTRA_BUILD_ENV) $(MAKE) -C $(builddir) $(build_target); then \
	  : ; \
	else \
	  if [ -f buildwatch.pid ]; then \
	    pid=$$(cat buildwatch.pid); \
	    kill -1 $$pid || :; sleep 1; kill -9 $$pid || :; \
	  fi; \
	  false; \
	fi

	touch $@

stamps/zero-build: stamps/zero-configure
	@echo '========== $@ =========='
	: # FIXME: build using the just built jdk, and build the vm only
	$(EXTRA_BUILD_ENV) $(MAKE) -C $(zbuilddir) $(zbuild_target)
	rm -rf $(builddir)/$(sdkimg)/lib/zero
	cp -a $(zbuilddir)/$(zsdkimg)/lib/server \
		$(builddir)/$(sdkimg)/lib/zero
	touch $@

stamps/build-docs: stamps/build
	@echo '========== $@ =========='
	mkdir -p $(builddir)/images/docs
	echo '<!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="refresh" content="0;url=api/index.html"> </head> </html>' > $(builddir)/images/docs/index.html
ifeq ($(with_docs),yes)
	$(MAKE) -C $(builddir) docs
endif
	touch $@

stamps/jtreg-check-default: stamps/build
	$(MAKE) -f debian/rules jtreg-run-check VMNAME=$(default_vm) VMARGS= \
		$(if $(filter $(default_vm),hotspot),TEST_SUITES='hotspot langtools jaxp jdk',TEST_SUITES='hotspot langtools jaxp')
#		TEST_SUITES='hotspot langtools jaxp'
	touch $@

stamps/jtreg-check-zero: stamps/build
	$(MAKE) -f debian/rules jtreg-run-check VMNAME=zero VMARGS='-vmoption:-zero' \
		TEST_SUITES='hotspot langtools jaxp'
	touch $@

jtreg-run-check:
	mkdir -p jtreg-test-output
ifneq (,$(filter $(VMNAME), $(with_jtreg_check)))
	if [ ! -f $(builddir)/$(sdkimg)/conf/security/java.security.install ]; then \
	  fgrep -v 'sun.security.pkcs11' $(builddir)/$(sdkimg)/conf/security/java.security \
	    > $(builddir)/$(sdkimg)/conf/security/java.security.test; \
	  mv $(builddir)/$(sdkimg)/conf/security/java.security \
	    $(builddir)/$(sdkimg)/conf/security/java.security.install; \
	  mv $(builddir)/$(sdkimg)/conf/security/java.security.test \
	    $(builddir)/$(sdkimg)/conf/security/java.security; \
	fi

	@echo "BEGIN jtreg"
	$(TIME) $(MAKE) -f debian/rules -k jtregcheck \
		$(if $(TEST_SUITES),TEST_SUITES="$(TEST_SUITES)") \
		JTREG_OPTIONS='$(VMARGS)' \
		2>&1 | tee jtreg-test-output/jtreg_output-$(VMNAME)
	@echo "END jtreg"

	if [ -f $(builddir)/$(sdkimg)/conf/security/java.security.install ]; then \
	  mv $(builddir)/$(sdkimg)/conf/security/java.security.install \
	    $(builddir)/$(sdkimg)/conf/security/java.security; \
	fi

	for i in check-hotspot.log check-jaxp.log check-jdk.log check-langtools.log jtreg-summary.log; do \
	  if [ -f jtreg-test-output/$$i ]; then \
	    mv jtreg-test-output/$$i jtreg-test-output/$${i%*.log}-$(VMNAME).log; \
	  else \
	    mkdir -p jtreg-test-output; \
	  fi; \
	done

	@echo "BEGIN jtreg-summary-$(VMNAME)"
	-cat jtreg-test-output/jtreg-summary-$(VMNAME).log
	@echo "END jtreg-summary-$(VMNAME)"

	-for i in hotspot langtools jaxp jdk; do \
	  test -f jtreg-test-output/check-$$i-$(VMNAME).log || continue; \
	  for t in $$(egrep '^(FAILED|Error)' jtreg-test-output/check-$$i-$(VMNAME).log | grep -v '^Error: Some tests failed or other problems occurred.$$' | sed -e 's/.* \(.*\)\.[^.#]\+\(#id[0-9]*\)\?$$/\1\2/' -e 's/#id/_id/'); do \
	    echo jtreg-test-output/$$i/JTwork/$$t.jtr; \
	  done; \
	done | sort -u > jtreg-test-output/failed_tests-$(VMNAME).list; \
	GZIP=-9vn tar --ignore-failed-read -C . -c -z -f jtreg-test-output/failed_tests-$(VMNAME).tar.gz -T jtreg-test-output/failed_tests-$(VMNAME).list
	GZIP=-9vn tar -C . -c -z -f jtreg-test-output/jtreport-$(VMNAME).tar.gz jtreg-test-output/*/JTreport/
else
	echo "jtreg harness not run for this build" > jtreg-test-output/jtreg_output-$(VMNAME)
endif

# ----------------------------------------------------------------------------
# jtreg targets taken from IcedTea

TESTS_TO_RUN = $(addprefix check-,$(TEST_SUITES))

check-hotspot: stamps/build
	mkdir -p jtreg-test-output/hotspot
	JTREG_OPTIONS=$(JTREG_OPTIONS) VMNAME=$(VMNAME) JDK_TO_TEST=$(builddir)/$(sdkimg) \
	AUTOPKGTEST_TMP=/tmp/ AUTOPKGTEST_ARTIFACTS=jtreg-test-output/hotspot/ \
	  $(TIME) debian/tests/hotspot | tee jtreg-test-output/$@.log


check-langtools: stamps/build
	mkdir -p jtreg-test-output/langtools
	JTREG_OPTIONS=$(JTREG_OPTIONS) VMNAME=$(VMNAME) JDK_TO_TEST=$(builddir)/$(sdkimg) \
	AUTOPKGTEST_TMP=/tmp/ AUTOPKGTEST_ARTIFACTS=jtreg-test-output/langtools/ \
	  $(TIME) debian/tests/langtools | tee jtreg-test-output/$@.log

check-jaxp: stamps/build
	mkdir -p jtreg-test-output/jaxp
	JTREG_OPTIONS=$(JTREG_OPTIONS) VMNAME=$(VMNAME) JDK_TO_TEST=$(builddir)/$(sdkimg) \
	AUTOPKGTEST_TMP=/tmp/ AUTOPKGTEST_ARTIFACTS=jtreg-test-output/langtools/ \
	  $(TIME) debian/tests/jaxp | tee jtreg-test-output/$@.log

check-jdk: stamps/build
	mkdir -p jtreg-test-output/jdk
	JTREG_OPTIONS=$(JTREG_OPTIONS) VMNAME=$(VMNAME) JDK_TO_TEST=$(builddir)/$(sdkimg) \
	AUTOPKGTEST_TMP=/tmp/ AUTOPKGTEST_ARTIFACTS=jtreg-test-output/jdk/ \
	  $(TIME) debian/tests/jdk | tee jtreg-test-output/$@.log

jtregcheck: $(TESTS_TO_RUN)
	for i in $(TEST_SUITES); do \
	  echo "--------------- jtreg console summary for $$i ---------------"; \
	  egrep -v '^(Passed:|Directory|Re[a-z]+\ written\ to)' jtreg-test-output/check-$$i.log; \
	done | tee jtreg-test-output/jtreg-summary.log

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

clean: debian-clean
	dh_testdir
	dh_testroot
	rm -rf stamps build build-* jtreg-test-output
	rm -rf autom4te.cache
	rm -f bin/{jtreg.tmwrc,my-jtreg-run,my-xvfb-run,auto*,ifnames}
	rm -f buildwatch.pid
	rm -f config.log configure.log
	dh_clean

debian-clean:
	dh_testdir
	dh_testroot
	dh_prep
	for f in debian/*.in; do \
	  f2=$$(echo $$f | sed 's/JB/$(basename)/;s/\.in$$//'); \
	  case "$$f2" in debian/control) continue; esac; \
	  rm -f $$f2; \
	done
	rm -f debian/*.install debian/*.links debian/*.debhelper.log

lib_ext_dirs = common $(sort $(foreach arch,$(arch_map),$(firstword $(subst =,$(SPACE),$(arch)))))
ifeq ($(derivative),Ubuntu)
  lib_ext_dirs := $(filter-out arm hppa m68k mips% powerpcspe s390% sh%, $(lib_ext_dirs))
else
  lib_ext_dirs := $(filter-out arm hppa, $(lib_ext_dirs))
endif

install: packaging-files
	dh_testdir
	dh_testroot
	dh_prep || dh_clean -k
	rm -f debian/*.install debian/*.links
	dh_installdirs

	@echo "all_jre_tools: $(all_jre_tools)"
	@echo "jre_tools:     $(jre_tools)"
	@echo "jre_hl_tools:  $(jre_hl_tools)"
	@echo "all_jdk_tools: $(all_jdk_tools)"
	@echo "jdk_tools: $(jdk_tools)"

	: # install into temporary location
	mkdir -p $(d)/$(basedir)
	cp -a $(builddir)/$(sdkimg)/* $(d)/$(basedir)/

	chmod -R u+w $(d)

	: # use javaws from icedtea-netx 
	find $(d) -name 'javaws*' | xargs -r rm -f

	: # install default jvm config file
	ls -l $(d)/$(basedir)/lib
	cp debian/jvm.cfg-default $(d)/$(basedir)/lib/.

	: # compress manpages
	find $(d)/$(basedir)/man -type f ! -type l | xargs gzip -9v -n

	mkdir -p $(d)/$(etcdir)/security
	mkdir -p $(d)/$(etcdir)/security/policy/limited
	mkdir -p $(d)/$(etcdir)/security/policy/unlimited
	mkdir -p $(d)/$(etcdir)/management
	mkdir -p $(d)/$(etcdir)/jfr

ifeq (0,1)
	: # rename templates (comments only) to config files,
	: # and move to /$(etcdir)
	for i in \
	  conf/management/jmxremote.password \
	  conf/management/snmp.acl; \
	do \
	  mv $(d)/$(basedir)/$$i.template $(d)/$(etcdir)/$$i; \
	done
else
	: # FIXME: what to do about these?
	for i in \
	  conf/management/jmxremote.password \
	  conf/management/snmp.acl; \
	do \
	  rm -f $(d)/$(basedir)/$$i.template; \
	done
endif

ifeq ($(with_bridge),atk)
#  only add releases that are known to work with atk
#  by default leave atk disabled
#  ifneq (,$(filter $(distrel),))
#	cp -p debian/accessibility-atk.properties.enabled \
		$(d)/$(basedir)/conf/accessibility.properties
#  else
	cp -p debian/accessibility-atk.properties.disabled \
		$(d)/$(basedir)/conf/accessibility.properties
#  endif
else
	cp -p debian/accessibility.properties $(d)/$(basedir)/conf/
endif
	cp -p debian/swing.properties $(d)/$(basedir)/conf/

ifneq (,$(pkg_certs))
	rm -f $(d)/$(basedir)/lib/security/cacerts
endif

	: # FIXME: merge nss changes from IcedTea
	cp debian/nss.cfg $(d)/$(basedir)/conf/security/nss.cfg

	: # move config files to $(etcdir) and symlink them.
	rm -f $(d_jrehl).links
	for i in \
	  conf/accessibility.properties \
	  conf/logging.properties \
	  conf/sound.properties \
	  conf/net.properties \
	  lib/psfontj2d.properties \
	  lib/psfont.properties.ja \
	  lib/jfr/default.jfc \
	  lib/jfr/profile.jfc \
	  conf/swing.properties \
	  conf/management/jmxremote.access \
	  conf/management/management.properties \
	  conf/security/java.policy \
	  conf/security/java.security \
	  conf/security/policy/limited/default_local.policy \
	  conf/security/policy/limited/exempt_local.policy \
	  conf/security/policy/limited/default_US_export.policy \
	  conf/security/policy/unlimited/default_local.policy \
	  conf/security/policy/unlimited/default_US_export.policy \
	  conf/security/policy/README.txt \
	  $$([ -f $(d)/$(basedir)/conf/security/nss.cfg ] && echo conf/security/nss.cfg) \
	  $(if $(findstring ca-cert,$(pkg_certs)),,lib/security/cacerts) \
	  lib/security/default.policy \
	  lib/security/blacklisted.certs \
	  lib/security/public_suffix_list.dat; \
	do \
	  dest=$$(echo $$i | sed 's,^[^/]*/,,'); \
	  mv $(d)/$(basedir)/$$i $(d)/$(etcdir)/$$dest; \
	  echo "$(etcdir)/$$dest $(basedir)/$$i" >> $(d_jrehl).links; \
	done
	mv $(d)/$(basedir)/lib/jvm.cfg \
		$(d)/$(etcdir)/
ifneq (,$(filter $(DEB_HOST_ARCH), $(hotspot_archs)))
	printf -- '-zero KNOWN\n' >> $(d)/$(etcdir)/jvm.cfg
else
	printf -- '-zero ALIASED_TO -server\n' >> $(d)/$(etcdir)/jvm.cfg
endif
ifneq (,$(filter $(DEB_HOST_ARCH), amd64 i386))
	printf -- '-dcevm KNOWN\n' >> $(d)/$(etcdir)/jvm.cfg
endif

	: # remove files which we do not want to distribute

	: # remove empty directories

	: # FIXME: fix, move and install tapset files
	rm -rf $(d)/$(basedir)/tapset

	: # TODO: why do we provide a custom font.properties.ja?
	: # cp -p debian/font.properties.ja $(d_jbin)/$(etcdir)/.
#	cp debian/font.properties.wqy_zenhai \
#		$(d)/$(etcdir)/font.properties.ja


	: # now move things to the packages. it is so ****** to create
	: # .install files first. dh_movefiles did do the job perfectly

	: # $(p_jrehl).install / $(p_jre).install
	( \
	  echo 'etc'; \
	  echo '$(basedir)/lib/server'; \
	  echo '$(basedir)/lib/jvm.cfg-default'; \
	  echo '$(basedir)/lib/jli/libjli.so'; \
	  echo '$(basedir)/lib/ct.sym'; \
	  echo '$(basedir)/lib/jexec'; \
	  echo '$(basedir)/lib/jspawnhelper'; \
	  echo '$(basedir)/lib/jrt-fs.jar'; \
	  echo '$(basedir)/release'; \
	  echo '$(basedir)/lib/tzdb.dat'; \
	  if [ "$(default_vm)" = hotspot ]; then \
	    echo '$(basedir)/lib/classlist'; \
	  fi; \
	  echo '$(basedir)/lib/modules'; \
	) > debian/$(p_jrehl).install
ifneq (,$(filter $(DEB_HOST_ARCH),i386))
  ifneq (,$(findstring --with-jvm-variants=client,$(DEFAULT_CONFIGURE_ARGS)))
	echo '$(basedir)/lib/client' >> debian/$(p_jrehl).install
  endif
endif
ifeq ($(derivative),Ubuntu)
	( \
	  echo 'usr/share/apport/package-hooks'; \
	) >> debian/$(p_jrehl).install
endif

	$(RM) debian/$(p_jre).install

	: # jre binaries and man pages
	for i in $(jre_hl_tools); do \
	  case "$$i" in \
	    *policytool*) p=debian/$(p_jre).install;; \
	    *)            p=debian/$(p_jrehl).install; \
	  esac; \
	  echo $(basedir)/bin/$$i >> $$p; \
	  if [ -f $(d)/$(basedir)/man/man1/$$i.1.gz ]; then \
	    echo $(basedir)/man/man1/$$i.1.gz >> $$p; \
	  fi; \
	  if [ -f $(d)/$(basedir)/man/ja_JP.UTF-8/man1/$$i.1.gz ]; then \
	    echo $(basedir)/man/ja_JP.UTF-8/man1/$$i.1.gz >> $$p; \
	  fi; \
	done

	cd $(CURDIR)/$(d); \
	for i in $(basedir)/lib/*.so; do \
	  case "$$i" in \
	    */libjavagtk.so|*/libsplashscreen.so|*/libjsoundalsa.so|*/xawt) echo $$i >> ../$(p_jre).install;; \
	    */zero) echo $$i >> ../$(p_jrez).install;; \
	    *) echo $$i >> ../$(p_jrehl).install; \
	  esac; \
	done

	@echo XXXXX $(alternate_vms)
ifneq (,$(filter zero, $(alternate_vms)))
	echo '$(basedir)/lib/zero' >> debian/$(p_jrez).install
endif

	: # $(p_jrehl).install
	( \
	  echo '$(basedir)/legal'; \
	  echo '$(basedir)/man/ja'; \
	) >> debian/$(p_jrehl).install

	: # $(p_jdkhl).install
	( \
	  for i in $(jdk_hl_tools); do \
	    echo $(basedir)/bin/$$i; \
	    if [ -f $(d)/$(basedir)/man/man1/$$i.1.gz ]; then \
	      echo $(basedir)/man/man1/$$i.1.gz; \
	    fi; \
	    if [ -f $(d)/$(basedir)/man/ja_JP.UTF-8/man1/$$i.1.gz ]; then \
	      echo $(basedir)/man/ja_JP.UTF-8/man1/$$i.1.gz; \
	    fi; \
	  done; \
	  cd $(d); \
	  for i in $(basedir)/include/*.h; do \
	    case $$i in */jawt.h|*/jawt_md.h) continue; esac; \
	    [ -h $$i ] && continue; \
	    echo $$i; \
	  done; \
	  echo '$(basedir)/include/*/jni_md.h'; \
	  echo '$(basedir)/jmods'; \
	) > debian/$(p_jdkhl).install

	: # $(p_jdk).install
	( \
	  echo '$(basedir)/include/jawt.h'; \
	  echo '$(basedir)/include/*/jawt_md.h'; \
	  for i in $(jdk_tools); do \
	    echo $(basedir)/bin/$$i; \
	    if [ -f $(d)/$(basedir)/man/man1/$$i.1.gz ]; then \
	      echo $(basedir)/man/man1/$$i.1.gz; \
	    fi; \
	    if [ -f $(d)/$(basedir)/man/ja_JP.UTF-8/man1/$$i.1.gz ]; then \
	      echo $(basedir)/man/ja_JP.UTF-8/man1/$$i.1.gz; \
	    fi; \
	  done; \
	) > debian/$(p_jdk).install

	: # $(p_src).install
	( \
	  echo '$(basedir)/lib/src.zip $(TOP)/$(basename)/lib'; \
	) > debian/$(p_src).install

	: # copy apport hook
ifeq ($(derivative),Ubuntu)
	mkdir -p $(d)/usr/share/apport/package-hooks/
	cp debian/apport-hook.py $(d)/usr/share/apport/package-hooks/source_$(basename).py
endif

	: # move demos and samples, create symlinks for $(p_demo)
	mkdir -p $(d)/usr/share/doc/$(p_jrehl)/demo
	for i in $(d)/$(basedir)/demo/*; do \
	  b=$$(basename $$i); \
	  case "$$i" in \
	    */jvmti) \
	      echo $(basedir)/demo/$$b usr/share/doc/$(p_jrehl)/demo/$$b >> $(d_demo).links;; \
	    *) \
	      mv $$i $(d)/usr/share/doc/$(p_jrehl)/demo/$$b; \
	      echo usr/share/doc/$(p_jrehl)/demo/$$b $(basedir)/demo/$$b >> $(d_demo).links;; \
	  esac; \
	done
	echo usr/share/doc/$(p_jre) usr/share/doc/$(p_demo) >> $(d_demo).links

	: # $(p_demo).install
	( \
	  echo '$(basedir)/demo'; \
	  echo 'usr/share/doc/$(p_jrehl)/demo'; \
	) > debian/$(p_demo).install

	: # $(p_dbg).install
ifneq (,$(wildcard $(builddir)/$(sdkimg)/lib/*.diz))
	( \
	  echo '$(basedir)/lib/*.diz'; \
	  echo '$(basedir)/lib/*/*.diz'; \
	) > debian/$(p_dbg).install
endif
ifneq (,$(wildcard $(builddir)/$(sdkimg)/lib/*.debuginfo))
	( \
	  echo '$(basedir)/lib/*.debuginfo'; \
	  echo '$(basedir)/lib/*/*.debuginfo'; \
	) > debian/$(p_dbg).install
endif

	: # FIXME: the targets are not installed ...
	rm -rfv $(d)/$(basedir)/lib/jfr

	dh_install --sourcedir=debian/tmp -XLICENSE
ifeq (,$(findstring old, $(old_debhelper)))
	dh_missing --sourcedir=debian/tmp --fail-missing -XLICENSE
endif

	find $(d_jrehl) $(d_jre) $(d_jrez) \
	  \( -name '*.debuginfo' -o -name '*.diz' \) -print | xargs -r rm -f

ifeq (0,1)
# FIXME: ext no longer supported
	: # give all permissions to cross-VM extension directory
	sed -i \
	    -e '/permission java\.security\.AllPermission;/,/};/c\' \
	    -e '        permission java.security.AllPermission;\' \
	    -e '};\' \
	    -e '\' \
	    $(if $(DEB_HOST_MULTIARCH),$(foreach i, $(lib_ext_dirs), \
	    -e 'grant codeBase "file:/$(TOP)/java-$(shortver)-$(origin)-$(i)/lib/ext/*" {\' \
	    -e '        permission java.security.AllPermission;\' \
	    -e '};\')) \
	    -e '\' \
	    -e '// Comment this out if you want to give all permissions to the\' \
	    -e '// Debian Java repository too:\' \
	    -e '//grant codeBase "file:/usr/share/java/repository/-" {\' \
	    -e '//        permission java.security.AllPermission;\' \
	    -e '//};\' \
	    -e '' \
	    $(d_jrehl)/$(security)/java.policy
# 'make Emacs Makefile mode happy
endif

	dh_installdirs -p$(p_jrehl) \
		usr/share/doc/$(p_jrehl) \
		usr/share/binfmts

	dh_installdirs -p$(p_jre) \
		usr/share/applications \
		usr/share/application-registry \
		usr/share/mime-info \
		usr/share/pixmaps

	: # add GNOME stuff
ifneq (,$(findstring cautious-launcher, $(java_launcher)))
	cp -p debian/$(basename)-java.desktop \
	      $(d_jre)/usr/share/applications/
endif

	for i in archive; do \
	  cp debian/$(basename)-$$i.applications \
	    $(d_jre)/usr/share/application-registry/; \
	  cp debian/$(basename)-$$i.keys $(d_jre)/usr/share/mime-info/; \
	  cp debian/$(basename)-$$i.mime $(d_jre)/usr/share/mime-info/; \
	done

	cp -p debian/sun_java.xpm \
		$(d_jre)/usr/share/pixmaps/$(basename).xpm

	mkdir -p $(d_demo)/usr/share/pixmaps
	cp -p debian/sun_java_app.xpm \
		$(d_demo)/usr/share/pixmaps/$(basename)-app.xpm

	: # install icons
	for i in 16 24 32 48; do \
	  install -D -m 644 -p src/java.desktop/unix/classes/sun/awt/X11/java-icon$${i}.png \
	    $(d_jre)/usr/share/icons/hicolor/$${i}x$${i}/apps/$(basename).png; \
	done

	: # create docdir symlinks for $(p_jrehl)
	( \
	  echo usr/share/doc/$(p_jrehl) $(basedir)/docs; \
	) >> $(d_jrehl).links

	: # create docdir symlinks for $(p_jre)
	( \
	  echo usr/share/doc/$(p_jrehl) usr/share/doc/$(p_jre); \
	) > $(d_jre).links

ifneq (,$(filter zero, $(alternate_vms)))
	: # create docdir symlinks for $(p_jrez)
	( \
	  echo usr/share/doc/$(p_jrehl) usr/share/doc/$(p_jrez); \
	) > $(d_jrez).links
endif

	: # create docdir symlinks for $(p_src)
	( \
	  echo usr/share/doc/$(p_jdk) usr/share/doc/$(p_src); \
	) > $(d_src).links

	: # create docdir symlinks for $(p_jdkhl)
	( \
	  echo usr/share/doc/$(p_jrehl) usr/share/doc/$(p_jdkhl); \
	) > $(d_jdkhl).links

	: # create docdir symlinks for $(p_jdk)
	( \
	  echo usr/share/doc/$(p_jre) usr/share/doc/$(p_jdk); \
	  echo $(TOP)/$(basename)/lib/src.zip $(TOP)/$(basename)/src.zip; \
	) > $(d_jdk).links
# doesn't work, no package dependency
ifneq (,$(DEB_HOST_MULTIARCH))
	  echo '$(TOP)/$(basename)/src.zip $(basedir)/lib/src.zip' >> $(d_jdkhl).links
	  echo '$(TOP)/$(basename)/lib/src.zip $(basedir)/lib/src.zip' >> $(d_jdkhl).links
endif

	: # create docdir symlinks for $(p_dbg)
	( \
	  echo usr/share/doc/$(p_jrehl) usr/share/doc/$(p_dbg); \
	) > $(d_dbg).links

	: # OpenJDK Stack Unwinder and Frame Decorator
ifneq (,$(filter $(DEB_HOST_ARCH),amd64 kfreebsd-amd64))
	mkdir -p $(d_jrehl)/usr/share/gdb/auto-load/$(basedir)/jre/lib/server
	cp debian/dbg.py \
	  $(d_jrehl)/usr/share/gdb/auto-load/$(basedir)/jre/lib/server/libjvm.so-gdb.py
  ifneq (,$(filter zero, $(alternate_vms)))
	mkdir -p $(d_jrez)/usr/share/gdb/auto-load/$(basedir)/jre/lib/zero
	ln -sf ../server/libjvm.so-gdb.py \
	  $(d_jrez)/usr/share/gdb/auto-load/$(basedir)/jre/lib/zero/libjvm.so
  endif
endif

ifeq ($(with_bridge),atk)
	: # create links for the atk wrapper
  ifeq (0,1)
  # FIXME: ext no longer supported
	echo "usr/share/java/java-atk-wrapper.jar $(basedir)/lib/ext/java-atk-wrapper.jar" \
	    >> $(d_jre).links
  endif
	echo "usr/lib$(multiarch_dir)/jni/libatk-wrapper.so $(basedir)/lib/libatk-wrapper.so" \
	    >> $(d_jre).links
else ifeq ($(with_bridge),yes)
 ifeq (0,1)
# FIXME: ext no longer supported
	: # create links for the gnome accessibility bridge
	echo "usr/share/java/gnome-java-bridge.jar $(basedir)/lib/ext/gnome-java-bridge.jar" \
	    >> $(d_jre).links
  ifeq ($(with_jni_bridge),yes)
	  echo "usr/lib$(multiarch_dir)/jni/libjava-access-bridge-jni.so $(basedir)/lib/libjava-access-bridge-jni.so" \
	    >> $(d_jre).links
  endif
 endif
endif

	: # create links for the config/lib files
# note: $(d_jrehl).links already created when moving files to the etcdir
ifneq (,$(DEB_HOST_MULTIARCH))
	mv $(d_jrehl)/$(etcdir)/jvm.cfg \
	  $(d_jrehl)/$(etcdir)/jvm-$(DEB_HOST_ARCH).cfg
	( \
	  echo "$(etcdir)/jvm-$(DEB_HOST_ARCH).cfg $(basedir)/lib/jvm.cfg"; \
	) >> $(d_jrehl).links
else
	( \
	  echo "$(etcdir)/jvm.cfg $(basedir)/lib/jvm.cfg"; \
	) >> $(d_jrehl).links
endif
ifneq (,$(pkg_certs))
	echo "etc/ssl/certs/java/cacerts $(basedir)/lib/security/cacerts" \
	    >> $(d_jrehl).links
endif

	@echo JRE_HL_TOOLS: $(jre_hl_tools) jexec
	@echo JRE_TOOLS: $(jre_tools)
	@echo JDK_HL_TOOLS: $(jdk_hl_tools)
	@echo JDK_TOOLS: $(jdk_tools)
	( \
	  echo 'name=$(jdirname)'; \
	  echo 'alias=$(jdiralias)'; \
	  echo 'priority=$(priority)'; \
	  echo 'section=main'; \
	  echo ''; \
	  for i in $(jre_hl_tools); do \
	    echo "hl $$i /$(basedir)/bin/$$i"; \
	  done; \
	  echo "hl jexec /$(basedir)/lib/jexec"; \
	  for i in $(jre_tools); do \
	    echo "jre $$i /$(basedir)/bin/$$i"; \
	  done; \
	  for i in $(jdk_hl_tools); do \
	    echo "jdkhl $$i /$(basedir)/bin/$$i"; \
	  done; \
	  for i in $(jdk_tools); do \
	    echo "jdk $$i /$(basedir)/bin/$$i"; \
	  done; \
	) > $(d_jrehl)/$(TOP)/.$(jdiralias).jinfo

	( \
	  echo 'package $(basename)'; \
	  echo 'interpreter /usr/bin/jexec'; \
	  echo 'magic PK\x03\x04'; \
	) > $(d_jrehl)/$(basedir)/lib/jar.binfmt

	: # another jvm symlink
	ln -sf $(jdirname) $(d_jrehl)/usr/lib/jvm/$(jdiralias)
	mkdir -p $(d_jrehl)/usr/lib/debug/usr/lib/jvm
	ln -sf $(jdirname) $(d_jrehl)/usr/lib/debug/usr/lib/jvm/$(jdiralias)

ifeq ($(with_systemtap),yes FIXME)
	: # systemtap support
	mkdir -p $(d_jrehl)/usr/share/systemtap/tapset
	cp -p build/tapset/hotspot.stp $(d_jrehl)/usr/share/systemtap/tapset/
endif

	: # install lintian overrides
	for FILE in debian/*.overrides; do \
	  PKG=`basename $$FILE .overrides`; \
	  install -D -m644 $$FILE debian/$$PKG/usr/share/lintian/overrides/$$PKG; \
	done

nodocs = $(if $(findstring nodoc, $(DEB_BUILD_OPTIONS)),-N$(p_doc))
nojrez = $(if $(filter zero, $(alternate_vms)),,-N$(p_jrez))

# Build architecture independant packages
binary-indep: build-indep install
	dh_testdir
	dh_testroot
ifeq ($(with_docs),yes)
	dh_installchangelogs -p$(p_doc)
	dh_installdocs -p$(p_doc)
	mkdir -p $(d_doc)/usr/share/doc/$(p_jrehl)
	for i in $(builddir)/images/docs/*; do \
	  [ -e $$i ] || continue; \
	  b=$$(basename $$i); \
	  cp -a $$i $(d_doc)/usr/share/doc/$(p_jrehl)/; \
	  ln -sf ../$(p_jrehl)/$$b $(d_doc)/usr/share/doc/$(p_doc)/$$b; \
	done
endif
# FIXME: desktop and menu files not ready for multiarch. #658321
ifeq (,$(DEB_HOST_MULTIARCH))
	dh_installmenu -i $(nodocs)
endif
	-dh_icons -i $(nodocs) || dh_iconcache -i $(nodocs)
#	dh_installdebconf -i $(nodocs)
	dh_link -i $(nodocs)
	dh_compress -i $(nodocs) -Xexamples -Xdemo -Xpackage-list -Xelement-list
	dh_fixperms -i $(nodocs)
	dh_installdeb -i $(nodocs)
	dh_gencontrol -i $(nodocs) -- $(control_vars)
	dh_md5sums -i $(nodocs)
	dh_builddeb -i $(nodocs) $(bd_options)

absarchdir = $(CURDIR)/$(d_jrehl)/$(basedir)/lib
shlibdeps_ld_path =$(absarchdir):$(absarchdir)/client:$(absarchdir)/server:$(absarchdir)/native_threads

# pass vm name as first argument
define install_test_results
	mkdir -p $(d_jdk)/usr/share/doc/$(p_jrehl)/test-$(DEB_HOST_ARCH)
	-cp jtreg-test-output/jtreg_output-$(1) \
	  $(d_jdk)/usr/share/doc/$(p_jrehl)/test-$(DEB_HOST_ARCH)/jtreg_output-$(1).log
	-cp jtreg-test-output/jtreg-summary-$(1).log jtreg-test-output/check-*-$(1).log \
	  $(d_jdk)/usr/share/doc/$(p_jrehl)/test-$(DEB_HOST_ARCH)/
	-cp jtreg-test-output/failed_tests-$(1).tar.gz \
	  $(d_jdk)/usr/share/doc/$(p_jrehl)/test-$(DEB_HOST_ARCH)/failed_tests-$(1).tar.gz
	-cp jtreg-test-output/jtreport-$(1).tar.gz \
	  $(d_jdk)/usr/share/doc/$(p_jrehl)/test-$(DEB_HOST_ARCH)/jtreport-$(1).tar.gz
endef

# Build architecture dependant packages
binary-arch: build install
	dh_testdir
	dh_testroot

	dh_installchangelogs -p$(p_jrehl)
	dh_installdocs -p$(p_jrehl) \
		debian/JAVA_HOME \
		debian/README.alternatives \
		debian/README.Debian
ifeq (0,1)
# FIXME: IcedTea specific bits
	for i in AUTHORS NEWS README; do \
	  cp -p $$i $(d_jrehl)/usr/share/doc/$(p_jrehl)/$$i.IcedTea; \
	done
endif
	$(call install_test_results,$(default_vm))

ifneq (,$(filter zero, $(alternate_vms)))
	$(call install_test_results,zero)
endif
# FIXME: desktop and menu files not ready for multiarch. #658321
ifeq (,$(DEB_HOST_MULTIARCH))
	dh_installmenu -a $(nodemo) $(nojrez)
endif
	-dh_icons -a $(nodemo) $(nojrez) \
		|| dh_iconcache -a $(nodemo) $(nojrez)
#	dh_installdebconf -a $(nodemo) $(nojrez)
	dh_link -a $(nodemo) $(nojrez)
	dh_strip -a $(nodemo) $(nojrez) \
		-Xlibjvm.so -X.debuginfo --dbg-package=$(p_dbg)

ifeq (,$(findstring nostrip, $(DEB_BUILD_OPTIONS)))
	set -ex; \
	for i in {$(d_jrehl),$(d_jre),$(d_jrez)}/$(basedir)/lib/*/libjvm.so; do \
	  [ -f $$i ] || continue; \
	  b_id=$$(LC_ALL=C readelf -n $$i | sed -n 's/ *Build ID: *\([0-9a-f][0-9a-f]*\)/\1/p'); \
	  if [ -z "$$b_id" ]; then \
	    id=$$(echo $$i | sed -r 's,debian/[^/]+,$(d_dbg)/usr/lib/debug,'); \
	    echo strip $$i; \
	    mkdir -p $$(dirname $$id); \
	    objcopy --only-keep-debug $$i $$id; \
	    chmod 644 $$id; \
	    strip --remove-section=.comment --remove-section=.note \
	      --strip-debug $$i; \
	    objcopy --add-gnu-debuglink $$id $$i; \
	  else \
	    d=usr/lib/debug/.build-id/$${b_id:0:2}; \
	    f=$${b_id:2}.debug; \
	    mkdir -p $(d_dbg)/$$d; \
	    objcopy --only-keep-debug --compress-debug-sections $$i $(d_dbg)/$$d/$$f; \
	    chmod 644 $(d_dbg)/$$d/$$f; \
	    strip --remove-section=.comment --remove-section=.note $$i; \
	  fi; \
	done
endif
	dh_compress -a $(nodemo) $(nojrez) -Xexamples -Xdemo -Xpackage-list
	dh_fixperms -a $(nodemo) $(nojrez)
	dh_makeshlibs -p$(p_jrehl) -p$(p_jre)
	dh_shlibdeps -a $(nodemo) $(nojrez) -L $(p_jrehl) \
		-l$(shlibdeps_ld_path) \
		--
	find $(d_jrehl) $(d_jre) $(d_jrez) -type f -name '*.debuginfo'
	dh_installdeb -a $(nodemo) $(nojrez)
	dh_gencontrol -a $(nodemo) $(nojrez) \
		-- $(control_vars)
	dh_md5sums -a $(nodemo) $(nojrez)
	: # FIXME: something seems to hang here ...
	-ps afx
	NO_PKG_MANGLE=1 \
	dh_builddeb -a $(nodemo) $(nojrez) #$(bd_options)

is_release		= yes
hg_project		= jdk11u
hg_tag			= jdk-11.0.4+11
package_version		= $(subst jdk-,,$(hg_tag))
ifneq ($(is_release),yes)
  package_version	:= $(subst +,~,$(package_version))
endif
hg_url			= http://hg.openjdk.java.net/jdk-updates/$(hg_project)
origdir = ../$(basename)-$(package_version).orig
topdir = $(basename)-$(package_version)
get-orig:
	mkdir $(origdir)
	wget -O $(origdir)/jdk.tar.bz2 $(hg_url)/archive/$(hg_tag).tar.bz2

	set -ex; \
	repo=jdk; \
	d=$$(tar tf $(origdir)/$$repo.tar.bz2 | head -1 | sed 's,/.*,,'); \
	tar xf $(origdir)/$$repo.tar.bz2; \
	chmod 755 $$d/configure; \
	case $$repo in jdk) \
	  rm -v -rf $$d/src/java.base/share/native/libzip/zlib; \
	  find $$d/src/java.desktop/share/native/libjavajpeg \
	    ! -name imageioJPEG.c ! -name jpegdecoder.c ! -name jinclude.h \
	    -type f -print -delete; \
	  rm -v -rf $$d/src/java.desktop/share/native/libsplashscreen/giflib; \
	  rm -v -rf $$d/src/java.desktop/share/native/libsplashscreen/libpng; \
	  rm -v -f $$d/src/java.desktop/share/native/liblcms/cms*.c; \
	  rm -v -f $$d/src/java.desktop/share/native/liblcms/lcms2*.h; \
	  rm -v -rf $$d/src/java.smartcardio/unix/native/libj2pcsc/MUSCLE; \
	esac; \
	mv $$d $(topdir); \
	tar cfJ ../$(basename)_$(package_version).orig.tar.xz $(topdir); \
	rm -rf $(topdir)

	rm -f ../$(origdir)

binary: binary-arch binary-indep
.PHONY: build build-arch build-indep clean binary-indep binary-arch binary install packaging-files