~openjdk/openjdk/openjdk8

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
#!/usr/bin/make -f
# -*- makefile -*-

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

unexport LANG LC_ALL

SHELL = /bin/bash

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)

# don't use it on 64bit archs
ifeq (,$(filter $(DEB_HOST_ARCH), alpha amd64 hppa ppc64 s390x))
  PATH := $(CURDIR)/bin:$(PATH)
  export PATH
endif

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)

hotspot_archs	= amd64 i386 lpia sparc
shark_archs	= amd64 i386 lpia
shark_archs	=
no_bootstrap_archs = alpha armel

VENDOR		= openjdk
Vendor		= OpenJDK
TOP		= usr/lib/jvm
jdirname	= java-$(shortver)-$(origin)
origin		= openjdk
basename	= openjdk-$(shortver)
ifneq (,$(filter $(DEB_HOST_ARCH), $(hotspot_archs)))
  priority	= 1061
  vm_name	= Hotspot JIT
else ifneq (,$(filter $(DEB_HOST_ARCH), $(shark_archs)))
  priority	= 1055
  vm_name	= Hotspot Shark
else
  priority	= 1053
  vm_name	= Hotspot Zero
endif
p_lib_arch	= all
jvmver		= 1.7.0
shortver	= 7
jdiralias	= java-$(shortver)-$(origin)
basedir		= usr/lib/jvm/$(jdiralias)
jreimg		= openjdk/build/linux-$(jvmarch)/j2re-image
sdkimg		= openjdk/build/linux-$(jvmarch)/j2sdk-image
security	= etc/$(jdiralias)/security

# 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))))
  HOTSPOT_BUILD_JOBS = $(NJOBS)
  ALT_PARALLEL_COMPILE_JOBS = $(NJOBS)
  export HOTSPOT_BUILD_JOBS
  export ALT_PARALLEL_COMPILE_JOBS
endif

# make the build log comparable
#export HOTSPOT_BUILD_JOBS = 1
#export ALT_PARALLEL_COMPILE_JOBS = 1

with_check = $(if $(findstring nocheck, $(DEB_BUILD_OPTIONS)),,yes)
with_docs = $(if $(findstring nodocs, $(DEB_BUILD_OPTIONS)),,yes)
ifneq (,$(findstring cacao shark, $(PKGSOURCE)))
  with_docs = disabled for cacao and shark
endif

with_plugin_pkg = yes
plugin_name = IcedTeaPlugin.so

distribution := $(shell lsb_release --id --short)
distrel := $(shell lsb_release --codename --short)

with_wgy_zenhai = $(if $(filter $(distrel),hardy intrepid jaunty karmic squeeze sid),yes)

arch_map	:= alpha=alpha arm=arm armel=arm amd64=amd64 hppa=parisc i386=i586 lpia=i586 m68k=m68k mips=mips mipsel=mipsel powerpc=ppc sparc=sparc s390=s390 ia64=ia64
archdir_map	:= alpha=alpha arm=arm armel=arm amd64=amd64 hppa=parisc i386=i386 lpia=i386 m68k=m68k mips=mips mipsel=mipsel powerpc=ppc sparc=sparc s390=s390 ia64=ia64

jvmarch		:= $(strip $(patsubst $(DEB_HOST_ARCH)=%, %, \
			$(filter $(DEB_HOST_ARCH)=%, $(arch_map))))
archdir		:= $(strip $(patsubst $(DEB_HOST_ARCH)=%, %, \
			$(filter $(DEB_HOST_ARCH)=%, $(archdir_map))))

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

#stage1_openjdk_archs = alpha amd64 armel i386 ia64 lpia powerpc m68k mips mipsel sparc s390
#stage1_gcj_archs = amd64 hppa i386 ia64 lpia powerpc m68k mips mipsel sparc s390
stage1_gcj_archs = hppa ia64 powerpc m68k mips mipsel sparc s390
stage1_openjdk_archs = alpha amd64 armel i386 lpia
stage1_cacao_archs =

cacao_archs = alpha amd64 armel i386 lpia powerpc m68k mips mipsel s390
altzero_archs = $(filter-out sparc, $(hotspot_archs))
altzero_archs =

ifneq (,$(filter $(DEB_HOST_ARCH), $(cacao_archs)))
  alternate_vms += cacao
endif
ifneq (,$(filter $(DEB_HOST_ARCH), $(altzero_archs)))
  ifneq (,$(filter $(DEB_HOST_ARCH), $(shark_archs)))
    alternate_vms += shark
  else
    alternate_vms += zero
  endif
endif

ifneq (,$(filter $(DEB_HOST_ARCH), $(stage1_gcj_archs)))
  STAGE1_JAVA = gcj
  STAGE1_HOME = /usr/lib/jvm/java-gcj
else ifneq (,$(filter $(DEB_HOST_ARCH), $(stage1_openjdk_archs)))
  STAGE1_JAVA = openjdk
  STAGE1_HOME = /usr/lib/jvm/java-6-openjdk
else ifneq (,$(filter $(DEB_HOST_ARCH), $(stage1_cacao_archs)))
  STAGE1_JAVA = cacao
  STAGE1_HOME = /usr/lib/jvm/java-6-cacao
else
  $(error unknown bootstrap method for architecture $(DEB_HOST_ARCH))
endif

OPENJDK_VERSION = b59
OPENJDK_SRC_ZIP = openjdk-7-ea-src-$(OPENJDK_VERSION)-20_nov_2008-dfsg.tar.gz
# the version of the build dependency for non-bootstrap builds; only adjust if
# the package is installable on all these architectures.
req_openjdk_bd_ver = 6b14
req_openjdk_ver = 7b59

unexport CFLAGS CXXFLAGS CPPFLAGS FFLAGS LDFLAGS

ifneq (,$(filter $(distrel),hardy gutsy feisty edgy dapper))
  ifneq (,$(filter $(DEB_HOST_ARCH), i386 lpia))
    export GCC_SUFFIX = -4.1
    GCJ_SUFFIX = -4.2
  endif
  ifneq (,$(filter $(DEB_HOST_ARCH), amd64 powerpc sparc))
    export GCC_SUFFIX = -4.2
  endif
else ifneq (,$(filter $(distrel),lenny intrepid jaunty squeeze sid))
  export GCC_SUFFIX = -4.3
  export GCJ_SUFFIX = -4.3
else
  export GCC_SUFFIX = -4.4
  export GCJ_SUFFIX = -4.4
  ifneq (,$(filter $(DEB_HOST_ARCH), sparc))
    export GCC_SUFFIX = -4.3
    export GCJ_SUFFIX = -4.3
  endif
endif

ifneq (,$(filter $(distrel),jaunty karmic unstable experimental sid))
  with_pulse = yes
endif

ifneq (,$(filter $(distrel),karmic sid squeeze))
  with_jni_bridge = yes
endif

#ifneq (,$(filter $(distrel),karmic unstable experimental sid))
#  with_systemtap = yes
#endif

with_hotspot = new
ifneq (,$(filter $(distrel),gutsy feisty edgy dapper hardy intrepid))
  with_hotspot = original
endif

ifeq ($(with_hotspot),original)
#	$(if $(filter $(distribution),Ubuntu),debian/patches/gcc-no-stack-protector-original.diff) \

  DISTRIBUTION_PATCHES = \
	debian/patches/ld-symbolic-functions-original.diff \
	debian/patches/set-exec-name-original.diff
else
# FIXME: doesn't seem to be enough, the gcc-*-no-stack-protector patches below are needed.
#	$(if $(filter $(distribution),Ubuntu),debian/patches/gcc-no-stack-protector.diff) \

  DISTRIBUTION_PATCHES = \
	debian/patches/ld-symbolic-functions.diff \
	debian/patches/set-exec-name.diff \
	debian/patches/hotspot-warn-no-errformat.diff
endif

DISTRIBUTION_PATCHES += \
	debian/patches/shebang.diff \
	debian/patches/jexec.diff \
	$(if $(with_wgy_zenhai),,debian/patches/fontconfig-arphic-uming.diff) \
	debian/patches/no-compiler-path.diff \
	debian/patches/jdk-freetypeScaler-crash.diff \
	debian/patches/icedtea-pretend-memory.diff \
	debian/patches/default-jvm-cfg.diff \
	debian/patches/nonreparenting-wm.diff \
	debian/patches/java-access-bridge-security.patch \
	debian/patches/accessible-toolkit.patch \
	debian/patches/default-libpath.diff \

#	debian/patches/gcc-mtune-generic.diff \

ifneq (,$(filter $(distrel),hardy gutsy feisty edgy dapper))
  DISTRIBUTION_PATCHES += \
	$(if $(filter $(DEB_HOST_ARCH), amd64), debian/patches/gcc-jdk-opt-O2.diff) \
	$(if $(filter $(DEB_HOST_ARCH), powerpc), debian/patches/gcc-opt-O2.diff)
endif

ifeq ($(distribution),Ubuntu)
  DISTRIBUTION_PATCHES += \
	debian/patches/openjdk-ubuntu-branding.patch \
	debian/patches/gcc-jdk-no-stack-protector.diff
  ifeq ($(with_hotspot),original)
    DISTRIBUTION_PATCHES += \
	debian/patches/gcc-hotspot-no-stack-protector-original.diff
  else
    DISTRIBUTION_PATCHES += \
	debian/patches/gcc-hotspot-no-stack-protector.diff
  endif
endif

# FIXME: temporarily disabled
#ifneq (,$(filter $(DEB_HOST_ARCH),armel))
#  DISTRIBUTION_PATCHES += \
#	debian/patches/zero-hotspot-opt.diff
#endif

export DISTRIBUTION_PATCHES

ifeq ($(STAGE1_JAVA),gcj)
  CONFIGURE_ARGS = \
	--with-gcj-home=$(STAGE1_HOME) \
	--with-ecj=/usr/bin/ecj \
	--with-java=$(STAGE1_HOME)/bin/java \
	--with-javah=/usr/bin/gjavah$(GCJ_SUFFIX) \
	--with-rmic=/usr/bin/grmic$(GCJ_SUFFIX)
  ifeq (,$(filter ia64, $(DEB_HOST_ARCH)))
    CONFIGURE_ARGS += \
	--with-jar=/usr/bin/fastjar
  endif
  build_target = icedtea-against-icedtea
else ifeq ($(STAGE1_JAVA),openjdk)
  CONFIGURE_ARGS = \
	--with-icedtea \
	--with-icedtea-home=$(STAGE1_HOME)
  build_target = #icedtea-against-icedtea
else ifeq ($(STAGE1_JAVA),cacao)
  CONFIGURE_ARGS = \
	--with-icedtea \
	--with-icedtea-home=$(STAGE1_HOME)
  build_target = #icedtea-against-icedtea
endif

CONFIGURE_ARGS += --with-pkgversion="$(PKGVERSION)"

# 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))
  CONFIGURE_ARGS += --with-alt-jar=/usr/bin/fastjar
endif

CONFIGURE_ARGS += \
	--with-xalan2-jar=/usr/share/java/xalan2.jar \
	--with-xalan2-serializer-jar=/usr/share/java/serializer.jar \
	--with-rhino=/usr/share/java/js.jar \
	--with-openjdk-src-zip=$(CURDIR)/openjdk.tar.gz \
	--with-hotspot-src-zip=$(CURDIR)/hotspot.tar.gz \
	--with-corba-src-zip=$(CURDIR)/corba.tar.gz \
	--with-jaxp-src-zip=$(CURDIR)/jaxp.tar.gz \
	--with-jaxws-src-zip=$(CURDIR)/jaxws.tar.gz \
	--with-jdk-src-zip=$(CURDIR)/jdk-dfsg.tar.gz \
	--with-langtools-src-zip=$(CURDIR)/langtools.tar.gz

#CONFIGURE_ARGS += --disable-nimbus --disable-nimbus-generation

ifneq (,$(filter $(DEB_HOST_ARCH), $(cacao_archs)))
  CONFIGURE_ARGS += \
	--with-cacao-src-zip=$(firstword $(wildcard $(CURDIR)/cacao-*.tar.* /usr/src/cacao-*.tar.*))
  ifneq (,$(filter $(DEB_HOST_ARCH), armel))
    EXTRA_BUILD_ENV = CACAO_CONFIGURE_ARGS='--enable-softfloat --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE)'
  else
    EXTRA_BUILD_ENV = CACAO_CONFIGURE_ARGS='--host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE)'
  endif
endif

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

ifeq ($(with_hotspot),original)
  CONFIGURE_ARGS += --without-hotspot-build
else
  CONFIGURE_ARGS += --with-hotspot-build
endif

EXTRA_BUILD_ENV += LIBFFI_LIBS=-lffi_pic

# assume we don't build binary indep packages on these architectures
ifeq ($(with_docs),yes)
  ifeq (,$(filter $(DEB_HOST_ARCH), amd64 i386 lpia))
    CONFIGURE_ARGS += --disable-docs
  endif
else
  CONFIGURE_ARGS += --disable-docs
endif

ifneq (,$(NJOBS))
  CONFIGURE_ARGS += --with-parallel-jobs=$(NJOBS)
endif

ifeq ($(with_plugin_pkg),yes)
  CONFIGURE_ARGS += --enable-liveconnect
else
  CONFIGURE_ARGS += --disable-liveconnect
endif

ifeq ($(with_pulse),yes)
  CONFIGURE_ARGS += --enable-pulse-java
endif

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

ifneq (,$(alternate_vms))
  CONFIGURE_ARGS += --with-additional-vms=$(subst $(SPACE),$(COMMA),$(alternate_vms))
endif

CONFIGURE_ARGS += --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE)

# (most) jre and jdk tools handled by the alternatives system.
# dups in heimdal-clients, krb5-user: kinit, klist, ktab, no alternatives
all_jre_tools	= $(notdir $(wildcard build/$(jreimg)/bin/*))
jre_tools	= $(filter javaws pluginappletviewer policytool, $(all_jre_tools))
jre_hl_tools	:= $(filter-out $(jre_tools), $(all_jre_tools))

corba_tools	= orbd servertool tnameserv
jre_hl_tools_alt= $(filter-out $(corba_tools), $(jre_hl_tools)) $(corba_tools)
jre_tools_alt	= $(filter-out kinit klist ktab, $(jre_tools))

all_jdk_tools	= $(notdir $(wildcard build/$(sdkimg)/bin/*))
jdk_tools	= $(filter-out $(all_jre_tools), $(all_jdk_tools))
jdk_tools_alt	= $(filter-out java-rmi.cgi, $(jdk_tools))

ifeq ($(distribution),Ubuntu)
  pkg_compress	= lzma
else
  pkg_compress  = bzip2
endif

# build dependencies
bd_bootstrap =
ifneq (,$(stage1_gcj_archs))
  bd_bootstrap += \
	ecj-gcj [$(strip $(foreach a,$(stage1_gcj_archs), $(a)))],
  ifneq (,$(filter $(distrel),karmic unstable experimental))
    bd_bootstrap += \
	gcj-jdk [$(strip $(foreach a,$(stage1_gcj_archs), $(a)))],
  else
    bd_bootstrap += \
	gcj (>= 4:4.2.1) [$(strip $(foreach a,$(stage1_gcj_archs), $(a)))], \
	java-gcj-compat-dev (>= 1.0.76-2ubuntu3) [$(strip $(foreach a,$(stage1_gcj_archs), $(a)))],
  endif
endif
ifneq (,$(stage1_openjdk_archs))
  bd_bootstrap += \
	openjdk-6-jdk (>= $(req_openjdk_bd_ver)) [$(strip $(foreach a,$(stage1_openjdk_archs), $(a)))],
endif
ifneq (,$(stage1_cacao_archs))
  bd_bootstrap += \
	cacao-oj6-jdk [$(strip $(foreach a,$(stage1_cacao_archs), $(a)))],
endif

ifneq (,$(filter $(distrel),hardy gutsy feisty edgy dapper))
  bd_gcc = g++-4.2 [amd64 powerpc sparc], g++-4.1 [i386 lpia],
else ifneq (,$(filter $(distrel),lenny intrepid jaunty squeeze sid))
  bd_gcc = g++-4.3,
else
  bd_gcc = g++-4.4 [!sparc], g++-4.3 [sparc],
endif
bd_syslibs = \
	libjpeg62-dev, libpng12-dev, libgif-dev$(if $(filter $(distrel),etch dapper edgy feisty gutsy), | libungif4-dev), zlib1g-dev,
bd_openjdk = \
	libxtst-dev, libxi-dev, libxt-dev, libxp-dev, libxaw7-dev, libxrender-dev, \
	$(if $(filter $(distrel), etch dapper edgy gutsy hardy),libcupsys2-dev,libcups2-dev), \
	libasound2-dev, libfreetype6-dev, \
	libxalan2-java, rhino, liblcms1-dev, libxinerama-dev,
bd_openjdk += \
	libxpp3-java, libjibx-java,

pkg_ffidev = $(if $(filter $(distribution),Ubuntu),$(if $(filter $(distrel),hardy),libffi4-dev,libffi-dev),libffi-dev)

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

ifneq (,$(shark_archs))
  bd_zero = $(pkg_ffidev),
  bd_shark = llvm-dev (>= 2.5) [$(foreach a,$(shark_archs),$(a))],
endif

bd_cacao = libtool,
ifneq ($(distribution),Ubuntu)
  bd_cacao += cacao-source (>= 0.99.4-1),
endif

bd_plugin = \
  libgtk2.0-dev, $(if $(filter $(distribution),Debian),xulrunner-dev (>= 1.9.0),$(if $(filter $(distrel),hardy intrepid jaunty karmic),xulrunner-1.9-dev,firefox-dev)),
bd_netx = fastjar (>= 2:0.96-0ubuntu2),
ifneq (,$(filter $(distrel),lenny sid experimental))
  bd_netx = fastjar (>= 2:0.95-4),
endif
ifneq (,$(filter $(distrel),hardy))
  bd_netx = fastjar (>= 2:0.95-1ubuntu2),
endif
bd_mauve = mauve, xvfb, autoconf, automake, xauth, xfonts-base
bd_compress = $(pkg_compress),
pkg_pulseaudio = pulseaudio (>= 0.9.12)
ifeq ($(with_pulse),yes)
  bd_pulsejava = libpulse-dev (>= 0.9.12), $(pkg_pulseaudio),
endif
ifeq ($(with_systemtap),yes)
  bd_systemtap = systemtap-sdt-dev,
endif

dlopen_hl_depends = \
	$(if $(filter $(distrel), etch dapper edgy gutsy hardy),libcupsys2,libcups2), \
	liblcms1, libjpeg62
dlopen_hl_recommends = \
dlopen_jre_depends = \
	libgtk2.0-0, libgnome2-0, libgnomevfs2-0, libgconf2-4, \
	libxrandr2, libxinerama1, libgl1-mesa-glx
dlopen_jre_recommends =

ifeq ($(distribution),Ubuntu)
  browser_plugin_dirs = xulrunner-addons firefox iceape iceweasel mozilla midbrowser xulrunner
  browser_plugin_dirs = xulrunner-addons
else
  browser_plugin_dirs = mozilla
endif

ifneq (,$(filter $(distrel),etch dapper feisty))
  core_fonts = ttf-dejavu
else
  core_fonts = ttf-dejavu-core
endif
cjk_fonts = ttf-baekmuk | ttf-unfonts | ttf-unfonts-core,
cjk_fonts += ttf-kochi-gothic | ttf-sazanami-gothic,
cjk_fonts += ttf-kochi-mincho | ttf-sazanami-mincho,
cjk_fonts += $(if $(with_wgy_zenhai),ttf-wqy-zenhei,ttf-arphic-uming),
ifneq (,$(filter $(distrel),lenny sid))
  cjk_fonts += ttf-indic-fonts,
else
  cjk_fonts += ttf-indic-fonts-core, ttf-telugu-fonts, ttf-oriya-fonts,
  cjk_fonts += ttf-kannada-fonts, ttf-bengali-fonts,
endif

p_jre	= $(basename)-jre
p_jrehl	= $(basename)-jre-headless
p_jrec	= icedtea-$(shortver)-jre-cacao
p_jrez	= $(basename)-jre-zero
p_lib	= $(basename)-jre-lib
p_jdk	= $(basename)-jdk
p_demo	= $(basename)-demo
p_src	= $(basename)-source
p_doc	= $(basename)-doc
p_dbg	= $(basename)-dbg
p_plug = icedtea7-plugin

d	= debian/tmp
d_jre	= debian/$(p_jre)
d_jrehl	= debian/$(p_jrehl)
d_jrec	= debian/$(p_jrec)
d_jrez	= debian/$(p_jrez)
d_lib	= debian/$(p_lib)
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)
d_plug	= debian/$(p_plug)

control_vars = \
	'-Vvm:Name=$(vm_name)' \
	'-Vbase:Version=$(req_openjdk_ver)' \
	'-Vdlopenhl:Depends=$(dlopen_hl_depends)' \
	'-Vdlopenhl:Recommends=$(dlopen_hl_recommends)' \
	'-Vdlopenjre:Depends=$(dlopen_jre_depends)' \
	'-Vdlopenjre:Recommends=$(dlopen_jre_recommends)' \
	'-Vpkg:pulseaudio=$(pkg_pulseaudio)' \

ifeq ($(pkg_compress),lzma)
  bd_options = -- -Zlzma
  control_vars += '-Vdpkg:Depends=dpkg (>= 1.14.12ubuntu3)'
else ifeq ($(pkg_compress),bzip2)
  bd_options = -- -Zbzip2
  control_vars += '-Vdpkg:Depends=dpkg (>= 1.10.24)'
endif

ifneq (,$(filter-out $(hotspot_archs), $(cacao_archs)))
  control_vars += '-Vcacao:Recommends=$(p_jrec) (= $${binary:Version})'
endif

# FIXME, temporarily disabled
#ifeq ($(with_jni_bridge),yes)
#  control_vars += '-Vdep:bridge=libaccess-bridge-java'
#else
#  control_vars += '-Vdep:bridge=libaccess-bridge-java-jni'
#endif

debian/control: debian/control.in debian/rules
	@cp -p debian/control debian/control.old
	sed \
	      -e 's/@basename@/$(basename)/g' \
	      -e 's/@bd_bootstrap@/$(bd_bootstrap)/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_plugin@/$(bd_plugin)/g' \
	      -e 's/@bd_netx@/$(bd_netx)/g' \
	      -e 's/@bd_mauve@/$(bd_mauve)/g' \
	      -e 's/@bd_compress@/$(pkg_compress)/g' \
	      -e 's/@bd_cacao@/$(bd_cacao)/g' \
	      -e 's/@bd_pulsejava@/$(bd_pulsejava)/g' \
	      -e 's/@bd_systemtap@/$(bd_systemtap)/g' \
	      -e 's/@bd_shark@/$(bd_shark)/g' \
	      -e 's/@core_fonts@/$(core_fonts)/g' \
	      -e 's/@cjk_fonts@/$(cjk_fonts)/g' \
	      -e 's/@pkg_plugin@/$(p_plug)/g' \
	      -e 's/@cacao_archs@/$(cacao_archs)/g' \
	      -e 's/@hotspot_archs@/$(hotspot_archs)/g' \
	      -e 's/@altzero_archs@/$(altzero_archs)/g' \
	      -e 's,@pkg_version@,$(if $(filter $(distrel),etch dapper edgy feisty gutsy),$${Source-Version},$${binary:Version}),g' \
	      -e 's/@lib_arch@/$(p_lib_arch)/g' \
	    debian/control.in \
	    debian/control.plugin \
	    $(if $(cacao_archs), debian/control.cacao-jre) \
	    $(if $(altzero_archs), debian/control.zero-jre) \
		> debian/control
	@if cmp -s debian/control debian/control.old; then \
	  rm -f debian/control.old; \
	else \
	  diff -u debian/control.old debian/control; \
	  echo "debian/control did change, please restart the build"; \
	  rm -f debian/control.old; \
          exit 1; \
	fi

packaging-files:
	for f in debian/*.in; do \
	  case "$$f" in debian/control.in) continue; esac; \
	  case "$$f" in \
	    debian/PLUGIN.*.in) f2=$$(echo $$f | sed 's/PLUGIN/$(p_plug)/;s/\.in$$//');; \
	    *) f2=$$(echo $$f | sed 's/JB/$(basename)/;s/\.in$$//'); \
	  esac; \
	  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,@basediralias@,$(TOP)/$(jdiralias),g' \
	      -e 's,@jdiralias@,$(jdiralias),g' \
	      -e 's,@jdirname@,$(jdirname),g' \
	      -e 's/@srcname@/$(srcname)/g' \
	      -e 's/@jvmarch@/$(jvmarch)/g' \
	      -e 's/@archdir@/$(archdir)/g' \
	      -e 's/@tag@/$(tag)/g' \
	      -e 's/@priority@/$(priority)/g' \
	      -e 's/@mantag@/$(mantag)/g' \
	      -e 's/@jre_hl_tools@/$(jre_hl_tools_alt)/g' \
	      -e 's/@jre_tools@/$(jre_tools_alt)/g' \
	      -e 's/@jdk_tools@/$(jdk_tools_alt)/g' \
	      -e 's/@corba_tools@/$(corba_tools)/g' \
	      -e 's,@j2se_lib@,$(j2se_lib),g' \
	      -e 's,@j2se_share@,$(j2se_share),g' \
	      -e 's,@plugin_name@,$(plugin_name),g' \
	      -e 's/@pkg_plugin@/$(p_plug)/g' \
	      -e 's,@browser_dirs@,$(browser_plugin_dirs),g' \
	      -e 's/@cjk_fonts@/$(cjk_fonts)/g' \
	    $$f > $$f2; \
	done
ifneq (,$(filter $(DEB_HOST_ARCH), i386 lpia))
# not yet in OpenJDK
#	cat debian/$(p_jre)-i586.menu >> $(d_jre).menu
	rm -f debian/$(p_jre)-i586.menu
endif

icedtea-configure: stamps/icedtea-configure
stamps/icedtea-configure:
	rm -f rt/net/sourceforge/jnlp/runtime/InstallDialog.java

	mkdir -p bin
	( \
	  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
	/bin/uname -a
	test -x /usr/bin/linux32 && linux32 uname -a || true
	test -x /usr/bin/linux32 &&linux32 /bin/uname -a || true

# FIXME: temporarily disabled
#	patch --verbose -p0 < debian/patches/zero-port-opt.diff

	mkdir -p stamps
	mkdir -p build
	chmod +x configure
	cd build && $(EXTRA_BUILD_ENV) ../configure $(CONFIGURE_ARGS)
	touch $@

unpack: stamps/unpack
stamps/unpack: stamps/icedtea-configure
	$(MAKE) -C build stamps/extract.stamp
ifeq ($(STAGE1_JAVA),gcj)
#	$(MAKE) -C build stamps/extract-ecj.stamp
endif
	touch $@

dist-openjdk: $(OPENJDK_SRC_ZIP)
	@echo "downloading openjdk source from hg to create zipfile: $(OPENJDK_SRC_ZIP)"
	$(MAKE) -C build $@

patch: stamps/patch
stamps/patch: stamps/unpack
ifeq ($(STAGE1_JAVA),gcj)
	$(MAKE) -C build stamps/patch-ecj.stamp
endif
	$(MAKE) -C build stamps/patch.stamp
	touch $@

ifeq ($(with_check),yes)
    ifneq (,$(filter $(DEB_HOST_ARCH), $(hotspot_archs) alpha armel ia64 mips mipsel powerpc s390))
      with_mauve_check = $(default_vm)
    endif
    ifneq (,$(filter $(DEB_HOST_ARCH), $(hotspot_archs) alpha armel ia64 mips mipsel powerpc s390))
      with_jtreg_check = $(default_vm)
    endif

    ifneq (,$(filter cacao, $(alternate_vms)))
      ifneq (,$(filter $(DEB_HOST_ARCH), amd64 i386 lpia powerpc sparc))
        # only activate after testing; problems on s390
        with_mauve_check += cacao
      endif
      ifneq (,$(filter $(DEB_HOST_ARCH), alpha amd64 armel i386 lpia mips mipsel powerpc s390))
        # only activate after testing; hangs several tests.
        with_jtreg_check += cacao
      endif
    endif

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

build_stamps = stamps/build
build_stamps +=  stamps/mauve-check-default stamps/jtreg-check-default
#build_stamps += $(if $(filter cacao, $(alternate_vms)),stamps/mauve-check-cacao stamps/jtreg-check-cacao)
build_stamps += $(if $(filter zero, $(alternate_vms)),stamps/mauve-check-zero stamps/jtreg-check-zero)

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/patch
ifneq (,$(filter $(DEB_HOST_ARCH), alpha arm armel hppa ia64 m68k mips mipsel powerpc s390 sparc))
	sh -c 'sh debian/buildwatch.sh $(CURDIR)/build &'
endif
	if $(EXTRA_BUILD_ENV) $(MAKE) -C build $(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/xvfb-check:
	mkdir -p bin
	echo 'xvfb-run -a -e xvfb-run.log -s "-extension GLX" "$$@"' > bin/my-xvfb-run
	if ! /bin/sh bin/my-xvfb-run true ; then \
	  echo "error running $$(cat bin/my-xvfb-run)"; \
	  cat xvfb-run.log; \
	  echo 'xvfb-run -a -e xvfb-run.log -s "$$@"' > bin/my-xvfb-run; \
	  if ! /bin/sh bin/my-xvfb-run true ; then \
	    echo "error running $$(cat bin/my-xvfb-run)"; \
	    cat xvfb-run.log; \
	    rm -f bin/my-xvfb-run; \
	  fi; \
	fi
	if [ -f bin/my-xvfb-run ]; then \
	  echo "using $$(cat bin/my-xvfb-run)"; \
	fi
	touch $@

stamps/mauve-check-default: stamps/build stamps/xvfb-check
	$(MAKE) -f debian/rules mauve-run-check VMNAME=$(default_vm) VMARGS=
	touch $@

stamps/mauve-check-cacao: stamps/xvfb-check
	$(MAKE) -f debian/rules mauve-run-check VMNAME=cacao VMARGS='-vmarg -cacao'
	touch $@

stamps/mauve-check-zero: stamps/xvfb-check
	$(MAKE) -f debian/rules mauve-run-check VMNAME=zero VMARGS='-vmarg -zero'
	touch $@

stamps/mauve-build: stamps/build
	rm -rf build/mauve
	mkdir -p build/mauve
ifeq ($(with_mauve_check),yes)
	tar -x -C build -f /usr/src/mauve.tar.gz
	cd build/mauve \
	    && aclocal \
	    && automake \
	    && autoconf \
	    && PATH=$(CURDIR)/build/$(sdkimg)/bin:$$PATH \
		./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE)
	PATH=$(CURDIR)/build/$(sdkimg)/bin:$$PATH $(MAKE) -C build/mauve
endif
	touch $@

stamps/mauve-check: stamps/build stamps/mauve-build stamps/xvfb-check

mauve-run-check:
	rm -rf build/mauve build/mauve-$(VMNAME)
ifneq (,$(filter $(VMNAME), $(with_mauve_check)))
	tar -x -C build -f /usr/src/mauve.tar.gz
	mv build/mauve build/mauve-$(VMNAME)
	cd build/mauve-$(VMNAME) \
	    && aclocal \
	    && automake \
	    && autoconf \
	    && PATH=$(CURDIR)/build/$(sdkimg)/bin:$$PATH ./configure \
		--host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE)
	PATH=$(CURDIR)/build/$(sdkimg)/bin:$$PATH $(MAKE) -C build/mauve-$(VMNAME)

	if [ -f bin/my-xvfb-run ]; then \
	  cd build/mauve-$(VMNAME) && \
	    JAVA_HOME=$(CURDIR)/build/$(sdkimg) \
	    PATH=$(CURDIR)/build/$(sdkimg)/bin:$$PATH \
		/bin/sh $(CURDIR)/bin/my-xvfb-run java Harness \
		    -vm $(CURDIR)/build/$(sdkimg)/bin/java \
		    $(VMARGS) \
		    -file $(CURDIR)/debian/mauve_tests \
		    -timeout 30000 2>&1 \
		| tee mauve_output-$(VMNAME); \
	else \
	  echo "mauve testsuite not run for this build (xvfb failures)" \
	    > build/mauve-$(VMNAME)/mauve_output-$(VMNAME); \
	  cat xvfb-run.log >> build/mauve-$(VMNAME)/mauve_output-$(VMNAME); \
	fi
	@sleep 5
else
	mkdir -p build/mauve-$(VMNAME)
	echo "mauve testsuite not run for this build" \
	  > build/mauve-$(VMNAME)/mauve_output-$(VMNAME)
endif

jtreg_processes = ps x -ww -o pid,ppid,args \
	| awk '$$2 == 1 && $$3 ~ /^$(subst /,\/,/scratch)/' \
	| sed 's,$(CURDIR)/build/$(sdkimg),<sdkimg>,g;s,$(CURDIR),<pwd>,g'
jtreg_pids = ps x --no-headers -ww -o pid,ppid,args \
	| awk '$$2 == 1 && $$3 ~ /^$(subst /,\/,$(CURDIR)/build/$(sdkimg))/ {print $$1}'

stamps/jtreg-check-default: stamps/build stamps/xvfb-check
	$(MAKE) -f debian/rules jtreg-run-check VMNAME=$(default_vm) VMARGS=
	touch $@

stamps/jtreg-check-cacao: stamps/build stamps/xvfb-check
	$(MAKE) -f debian/rules jtreg-run-check VMNAME=cacao VMARGS='-vmoption:-cacao'
	touch $@

stamps/jtreg-check-zero: stamps/build stamps/xvfb-check
	$(MAKE) -f debian/rules jtreg-run-check VMNAME=zero VMARGS='-vmoption:-zero'
	touch $@

jtreg-run-check:
ifneq (,$(filter $(VMNAME), $(with_jtreg_check)))
	@echo "BEGIN jtreg"
	if [ -f bin/my-xvfb-run ]; then \
	  /bin/sh bin/my-xvfb-run $(MAKE) -C build -k jtregcheck ICEDTEA_JTREG_OPTIONS='$(VMARGS)' \
		2>&1 | tee jtreg_output-$(VMNAME); \
	else \
	  echo "jtreg harness not run for this build" > jtreg_output-$(VMNAME); \
	  cat xvfb-run.log >> jtreg_output-$(VMNAME); \
	fi
	@echo "END jtreg"

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

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

	: # kill testsuite processes still hanging
	@pids=$$($(jtreg_pids)); \
	if [ -n "$$pids" ]; then \
	  echo "killing processes..."; \
	  $(jtreg_processes); \
	  kill -1 $$pids; \
	  sleep 2; \
	  pids=$$($(jtreg_pids)); \
	  if [ -n "$$pids" ]; then \
	    echo "trying harder..."; \
	    $(jtreg_processes); \
	    kill -9 $$pids; \
	    sleep 2; \
	  fi; \
	else \
	  echo "nothing to cleanup"; \
	fi; \
	pids=$$($(jtreg_pids)); \
	if [ -n "$$pids" ]; then \
	  echo "leftover processes..."; \
	  $(jtreg_processes); \
	fi

	-for i in hotspot langtools jdk; do \
	  for t in $$(egrep '^(FAILED|Error)' build/test/check-$$i-$(VMNAME).log | sed 's/.* \(.*\)\.[^.][^.]*$$/\1/'); do \
	    echo test/$$i/JTwork/$$t.jtr; \
	  done; \
	done > build/test/failed_tests-$(VMNAME).list; \
	tar -C build -c -z -f build/test/failed_tests-$(VMNAME).tar.gz -T build/test/failed_tests-$(VMNAME).list
else
	echo "jtreg harness not run for this build" > jtreg_output-$(VMNAME)
endif

clean: debian-clean
	dh_testdir
	dh_testroot
	rm -rf stamps build build-*
	rm -rf autom4te.cache
	rm -rf bin
	rm -f jtreg_output* xvfb-run.log
	rm -f buildwatch.pid

	if [ -f ports/hotspot/src/cpu/zero/vm/bytecodeInterpreter_arm.S ]; then \
	  patch --verbose -p0 -R < debian/patches/zero-port-opt.diff; \
	  rm -f ports/hotspot/src/cpu/zero/vm/bytecodeInterpreter_arm.S; \
	fi

	dh_clean

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

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

	: # install into temporary location
	mkdir -p $(d)/$(basedir)
	cp -a build/$(sdkimg)/* $(d)/$(basedir)/
	cp -a build/$(jreimg)/man $(d)/$(basedir)/jre/
	chmod -R u+w $(d)

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

	: # add extra symlinks for header files
	ln -sf linux/jni_md.h $(d)/$(basedir)/include/jni_md.h
	ln -sf linux/jawt_md.h $(d)/$(basedir)/include/jawt_md.h

ifneq (,$(filter --with-alt-jar=/usr/bin/fastjar, $(CONFIGURE_ARGS)))
	: # add javascript files to the archive
	if ! fastjar tf $(d)/$(basedir)/jre/lib/rt.jar | fgrep -q JSObject.class; then \
	  echo "FIXME: Adding class files for IcedTeaPlugin to rt.jar..."; \
	  fastjar -u -v -0 -f $(d)/$(basedir)/jre/lib/rt.jar \
		-C lib/rt netscape/javascript; \
	fi
endif
	: # compress manpages
	find $(d)/$(basedir)/man $(d)/$(basedir)/jre/man -type f ! -type l \
	  | xargs gzip -9v

	: # replace common files in jdk and jre by symlinks
	@cd $(d)/$(basedir); \
	  for i in `find jre -type f`; do \
	    i2=$${i#jre/*}; \
	    [ -f $$i2 ] && cmp -s $$i $$i2 || continue; \
	    d=$$(echo ./$$i2 | sed -r 's,[^/]+/,../,g;s,/[^/]+$$,,;s,\.\.$$,,'); \
	    echo "    symlink $$i2 -> $$d$$i"; \
	    ln -sf $$d$$i $$i2; \
	  done

	mkdir -p $(d)/etc/$(jdiralias)/security
	mkdir -p $(d)/etc/$(jdiralias)/management
	mkdir -p $(d)/etc/$(jdiralias)/images/cursors

	: # rename templates (comments only) to config files,
	: # and move to /etc/$(jdiralias)
	for i in \
	  management/jmxremote.password \
	  management/snmp.acl; \
	do \
	  mv $(d)/$(basedir)/jre/lib/$$i.template $(d)/etc/$(jdiralias)/$$i; \
	done

	cp -p debian/accessibility.properties $(d)/$(basedir)/jre/lib/
	cp -p debian/swing.properties $(d)/$(basedir)/jre/lib/

	rm -f $(d)/$(basedir)/jre/lib/security/cacerts

	: # move config files to etc/$(jdiralias) and symlink them.
	for i in \
	  accessibility.properties \
	  calendars.properties \
	  content-types.properties \
	  images/cursors/cursors.properties \
	  logging.properties \
	  sound.properties \
	  flavormap.properties \
	  net.properties \
	  psfontj2d.properties \
	  psfont.properties.ja \
	  swing.properties \
	  management/jmxremote.access \
	  management/management.properties \
	  security/java.policy \
	  security/java.security; \
	do \
	  mv $(d)/$(basedir)/jre/lib/$$i $(d)/etc/$(jdiralias)/$$i; \
	done
	mv $(d)/$(basedir)/jre/lib/$(archdir)/jvm.cfg \
		$(d)/etc/$(jdiralias)/

	mv $(d)/$(basedir)/jre/lib/fontconfig.Ubuntu.properties.src \
		$(d)/etc/$(jdiralias)/fontconfig.properties
	mv $(d)/$(basedir)/jre/lib/fontconfig.Ubuntu.bfc \
		$(d)/etc/$(jdiralias)/fontconfig.bfc

	: # remove files which we do not want to distribute
	rm -f $(d)/$(basedir)/jre/lib/fontconfig*.properties.src
	rm -f $(d)/$(basedir)/jre/lib/fontconfig*.bfc

	: # remove empty directories
	rmdir $(d)/$(basedir)/jre/lib/management
	rmdir $(d)/$(basedir)/jre/lib/applet
	rmdir $(d)/$(basedir)/jre/lib/security

	: # TODO: why do we provide a custom font.properties.ja?
	: # cp -p debian/font.properties.ja $(d_jbin)/etc/$(jdiralias)/.
#	cp debian/font.properties.wgy_zenhai \
#		$(d)/etc/$(jdiralias)/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)/jre/lib/jexec'; \
	  echo '$(basedir)/jre/lib/rt.jar'; \
	  echo '$(basedir)/jre/man/ja'; \
	  echo '$(basedir)/man/ja'; \
	  echo '$(basedir)/bin/java-rmi.cgi'; \
	) > debian/$(p_jrehl).install
	$(RM) debian/$(p_jre).install

	cd $(CURDIR)/$(d); \
	for i in $(basedir)/jre/{bin,man/man1,man/ja_JP.eucJP/man1}/*; do \
	  case "$$i" in \
	    */javaws*|*/pluginappletviewer*|*/policytool*) echo $$i >> ../$(p_jre).install;; \
	    *) echo $$i >> ../$(p_jrehl).install; \
	  esac; \
	done

	cd $(CURDIR)/$(d); \
	for i in $(basedir)/{bin,man/man1,man/ja_JP.eucJP/man1}/*; do \
	  [ -h $$i ] || continue; \
	  case "$$i" in \
	    */javaws*|*/pluginappletviewer*|*/policytool*) echo $$i >> ../$(p_jre).install;; \
	    *) echo $$i >> ../$(p_jrehl).install; \
	  esac; \
	done; \

	cd $(CURDIR)/$(d); \
	for i in $(basedir)/jre/lib/$(archdir)/*; do \
	  case "$$i" in \
	    */$(plugin_name)) continue;; \
	    */libsplashscreen.so|*/libjsoundalsa.so|$(if $(with_pulse),*/libpulse-java.so|)*/xawt) echo $$i >> ../$(p_jre).install;; \
	    */cacao) echo $$i >> ../$(p_jrec).install;; \
	    */zero) echo $$i >> ../$(p_jrez).install;; \
	    *) echo $$i >> ../$(p_jrehl).install; \
	  esac; \
	done

	: # $(p_lib).install
	( \
	  echo '$(basedir)/jre/ASSEMBLY_EXCEPTION'; \
	  echo '$(basedir)/jre/THIRD_PARTY_README'; \
	  cd $(d); \
	  for i in $(basedir)/jre/lib/*; do \
	    case "$$i" in */$(archdir)|*/jexec|*/rt.jar) continue; esac; \
	    echo $$i; \
	  done; \
	) > debian/$(p_lib).install

	: # $(p_jdk).install
	( \
	  echo '$(basedir)/include'; \
	  echo '$(basedir)/lib'; \
	  echo '$(basedir)/LICENSE'; \
	  echo '$(basedir)/ASSEMBLY_EXCEPTION'; \
	  echo '$(basedir)/THIRD_PARTY_README'; \
	  cd $(d); \
	  for i in $(basedir)/{bin,man/man1,man/ja_JP.eucJP/man1}/*; do \
	    [ -h $$i -o "$$i" = $(basedir)/bin/java-rmi.cgi ] && continue; \
	    echo $$i; \
	  done; \
	) > debian/$(p_jdk).install

ifeq ($(with_plugin_pkg),yes)
	dh_installdirs -p$(p_plug) \
		$(foreach d, $(browser_plugin_dirs), usr/lib/$(d)/plugins)

	: # $(p_plug).install
	( \
	  echo '$(basedir)/jre/lib/$(archdir)/$(plugin_name)'; \
	) > debian/$(p_plug).install
else
	: # include the plugin in the $(p_jre) package
	echo '$(basedir)/jre/lib/$(archdir)/$(plugin_name)' \
		>> debian/$(p_jre).install
endif

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

	: # move demos and samples, create symlinks for $(p_demo)
	mkdir -p $(d)/usr/share/doc/$(p_jre)/demo
	for i in $(d)/$(basedir)/demo/*; do \
	  b=$$(basename $$i); \
	  case "$$i" in \
	    */jvmti) \
	      echo $(basedir)/demo/$$b usr/share/doc/$(p_jre)/demo/$$b >> $(d_demo).links;; \
	    *) \
	      mv $$i $(d)/usr/share/doc/$(p_jre)/demo/$$b; \
	      echo usr/share/doc/$(p_jre)/demo/$$b $(basedir)/demo/$$b >> $(d_demo).links;; \
	  esac; \
	done
	mv $(d)/$(basedir)/sample $(d)/usr/share/doc/$(p_jre)/examples
	echo usr/share/doc/$(p_jre)/examples $(basedir)/sample >> $(d_demo).links
	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_jre)/examples'; \
	  echo 'usr/share/doc/$(p_jre)/demo'; \
	) > debian/$(p_demo).install

	dh_install --sourcedir=debian/tmp --fail-missing -XLICENSE

	: # give all permissions to cross-VM extension directory
	sed -i \
	    -e '/permission java\.security\.AllPermission;/,/};/c\' \
	    -e '        permission java.security.AllPermission;\' \
	    -e '};\' \
	    -e '\' \
	    -e 'grant codeBase "file:/$(basedir)/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

	dh_installdirs -p$(p_jrehl) \
		usr/share/doc/$(p_jre) \
		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
	cp -p debian/$(basename)-{javaws,policytool}.desktop \
	      $(d_jre)/usr/share/applications/
	cp -p debian/$(basename)-java.desktop \
	      $(d_jre)/usr/share/applications/
# not yet in OpenJDK
#	cp -p debian/$(basename)-controlpanel.desktop \
#	      $(d_jre)/usr/share/applications/

	for i in archive web-start; 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 build/openjdk/jdk/src/solaris/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_jre) usr/share/doc/$(p_jrehl); \
	  echo usr/share/doc/$(p_jre) $(basedir)/docs; \
	) > $(d_jrehl).links

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

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

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

ifeq ($(with_plugin_pkg),yes)
	: # create docdir symlinks for $(p_plug)
	( \
	  echo usr/share/doc/$(p_jre) usr/share/doc/$(p_plug); \
	) > $(d_plug).links
endif

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

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

# FIXME: temporarily disabled
#	: # create links for the gnome accessibility bridge
#	echo "usr/share/java/gnome-java-bridge.jar $(basedir)/jre/lib/ext/gnome-java-bridge.jar" \
#	    >> $(d_jre).links
#ifeq ($(with_jni_bridge),yes)
#	  echo "usr/lib/jni/libjava-access-bridge-jni.so $(basedir)/jre/lib/ext/libjava-access-bridge-jni.so" \
#	    >> $(d_jre).links
#endif

	: # create links for the config files
	find $(d_jrehl)/etc/$(jdiralias) -type f ! -name jvm.cfg \
	    -printf "etc/$(jdiralias)/%P $(basedir)/jre/lib/%P\n" >> $(d_jrehl).links
	echo "etc/$(jdiralias)/jvm.cfg $(basedir)/jre/lib/$(archdir)/jvm.cfg" \
	    >> $(d_jrehl).links
	echo "etc/ssl/certs/java/cacerts $(basedir)/jre/lib/security/cacerts" \
	    >> $(d_jrehl).links

	@echo JRE_HL_TOOLS: $(jre_hl_tools_alt) jexec
	@echo JRE_TOOLS: $(jre_tools_alt)
	@echo JDK_TOOLS: $(jdk_tools_alt)
	( \
	  echo 'name=$(jdirname)'; \
	  echo 'alias=$(jdiralias)'; \
	  echo 'priority=$(priority)'; \
	  echo 'section=main'; \
	  echo ''; \
	  for i in $(jre_hl_tools_alt); do \
	    echo "hl $$i /$(TOP)/$(jdiralias)/jre/bin/$$i"; \
	  done; \
	  echo "hl jexec /$(TOP)/$(jdiralias)/jre/lib/jexec"; \
	  for i in $(jre_tools_alt); do \
	    echo "jre $$i /$(TOP)/$(jdiralias)/jre/bin/$$i"; \
	  done; \
	  for i in $(jdk_tools_alt); do \
	    echo "jdk $$i /$(TOP)/$(jdiralias)/bin/$$i"; \
	  done; \
	  for d in $(browser_plugin_dirs); do \
	    case "$$d" in \
	      xulrunner-addons) b=xulrunner-1.9;; \
	      *) b=$$d;; \
	    esac; \
	    echo "plugin $$b-javaplugin.so /$(TOP)/$(jdiralias)/jre/lib/$(archdir)/$(plugin_name)"; \
	  done; \
	) > $(d_jrehl)/$(TOP)/.$(jdiralias).jinfo

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

	: # install a wrapper for javaws
	mv $(d_jre)/$(basedir)/jre/bin/javaws $(d_jre)/$(basedir)/jre/bin/javaws.real
	install -m 755 debian/javaws-wrapper.sh $(d_jre)/$(basedir)/jre/bin/javaws

	: # another jvm symlink
	ln -sf $(jdiralias) $(d_jrehl)/usr/lib/jvm/java-$(jvmver)-$(origin)

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

	: # Install stuff to generate font config and timezone files.
	mkdir -p $(d_lib)/$(basedir)/jre/lib
	cp -p build/openjdk/build/linux-$(jvmarch)/btjars/compilefontconfig.jar \
		$(d_lib)/$(basedir)/jre/lib/
	cp -p build/openjdk/build/linux-$(jvmarch)/btjars/javazic.jar \
		$(d_lib)/$(basedir)/jre/lib/

	: # 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 nodocs, $(DEB_BUILD_OPTIONS)),-N$(p_doc))
nodemo = $(if $(findstring cacao, $(PKGSOURCE)),-N$(p_demo))
nojrec = $(if $(filter cacao, $(alternate_vms)),,-N$(p_jrec))
nojrez = $(if $(filter zero, $(alternate_vms)),,-N$(p_jrez))

# Build architecture independant packages
binary-indep: build 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_jre)
	for i in build/openjdk/build/linux-$(jvmarch)/docs/*; do \
	  [ -e $$i ] || continue; \
	  b=$$(basename $$i); \
	  cp -a $$i $(d_doc)/usr/share/doc/$(p_jre)/; \
	  ln -sf ../$(p_jre)/$$b $(d_doc)/usr/share/doc/$(p_doc)/$$b; \
	done
endif
	dh_installmenu -i $(nodocs)
	-dh_icons -i $(nodocs) || dh_iconcache -i $(nodocs)
#	dh_installdebconf -i $(nodocs)
	dh_link -i $(nodocs)
	dh_compress -i $(nodocs) -Xexamples -Xdemos
	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)/jre/lib/$(archdir)
shlibdeps_ld_path =$(absarchdir):$(absarchdir)/client:$(absarchdir)/server:$(absarchdir)/native_threads

# 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
	mv $(d_jrehl)/usr/share/doc/$(p_jrehl)/* $(d_jrehl)/usr/share/doc/$(p_jre)
	rm -rf $(d_jrehl)/usr/share/doc/$(p_jrehl)
	for i in AUTHORS NEWS README; do \
	  cp -p $$i $(d_jrehl)/usr/share/doc/$(p_jre)/$$i.IcedTea; \
	done
	mkdir -p $(d_jdk)/usr/share/doc/$(p_jre)
	cp build/mauve-$(default_vm)/mauve_output-$(default_vm) \
		$(d_jdk)/usr/share/doc/$(p_jre)/mauve_output-$(default_vm).log
	cp jtreg_output-$(default_vm) \
		$(d_jdk)/usr/share/doc/$(p_jre)/jtreg_output-$(default_vm).log
	-cp build/test/jtreg-summary-$(default_vm).log build/test/check-*-$(default_vm).log \
		$(d_jdk)/usr/share/doc/$(p_jre)/
	-cp build/test/failed_tests-$(default_vm).tar.gz $(d_jdk)/usr/share/doc/$(p_jre)/

ifneq (,$(filter cacao, $(alternate_vms)))
	dh_installchangelogs -p$(p_jrec)
	dh_installdocs -p$(p_jrec)
	mkdir -p $(d_jrec)/usr/share/doc/$(p_jre)
	-cp build/mauve-cacao/mauve_output-cacao \
		$(d_jrec)/usr/share/doc/$(p_jre)/mauve_output-cacao.log
	-cp jtreg_output-cacao \
		$(d_jrec)/usr/share/doc/$(p_jre)/jtreg_output-cacao.log
	-cp build/test/jtreg-summary-cacao.log build/test/check-*-cacao.log \
		$(d_jrec)/usr/share/doc/$(p_jre)/
	-cp build/test/failed_tests-cacao.tar.gz $(d_jrec)/usr/share/doc/$(p_jre)/
endif
ifneq (,$(filter zero, $(alternate_vms)))
	mkdir -p $(d_jrez)/usr/share/doc/$(p_jre)
	-cp build/mauve-zero/mauve_output-zero \
		$(d_jrez)/usr/share/doc/$(p_jre)/mauve_output-zero.log
	-cp jtreg_output-zero \
		$(d_jrez)/usr/share/doc/$(p_jre)/jtreg_output-zero.log
	-cp build/test/jtreg-summary-zero.log build/test/check-*-zero.log \
		$(d_jrez)/usr/share/doc/$(p_jre)/
	-cp build/test/failed_tests-zero.tar.gz $(d_jrez)/usr/share/doc/$(p_jre)/
endif
	dh_desktop -s $(nodemo) $(nojrec) $(nojrez)
	dh_installmenu -s $(nodemo) $(nojrec) $(nojrez)
	-dh_icons -s $(nodemo) $(nojrec) $(nojrez) || dh_iconcache -s $(nodemo) $(nojrec) $(nojrez)
#	dh_installdebconf -s $(nodemo) $(nojrec) $(nojrez)
	dh_link -s $(nodemo) $(nojrec) $(nojrez)
	dh_strip -s $(nodemo) $(nojrec) $(nojrez) --dbg-package=$(p_dbg)
	dh_compress -s $(nodemo) $(nojrec) $(nojrez)
	dh_fixperms -s $(nodemo) $(nojrec) $(nojrez)
	dh_makeshlibs -p$(p_jrehl) -p$(p_jre)
	dh_shlibdeps -s $(nodemo) $(nojrec) $(nojrez) -L $(p_jrehl) \
		-l$(shlibdeps_ld_path) \
		--
	dh_installdeb -s $(nodemo) $(nojrec) $(nojrez)
	dh_gencontrol -s $(nodemo) $(nojrec) $(nojrez) -- $(control_vars)
	dh_md5sums -s $(nodemo) $(nojrec) $(nojrez)
	dh_builddeb -s $(nodemo) $(nojrec) $(nojrez) #$(bd_options)

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