summaryrefslogtreecommitdiffstats
path: root/src/VBox/Installer/win/Makefile.kmk
blob: 4b91b4607dface88ba67136a56b23d173a38d341 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
# $Id: Makefile.kmk $
## @file
# Makefile for the Windows installer.
#

#
# Copyright (C) 2006-2023 Oracle and/or its affiliates.
#
# This file is part of VirtualBox base platform packages, as
# available from https://www.virtualbox.org.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation, in version 3 of the
# License.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <https://www.gnu.org/licenses>.
#
# SPDX-License-Identifier: GPL-3.0-only
#

SUB_DEPTH = ../../../..
include $(KBUILD_PATH)/subheader.kmk

ifneq ($(KBUILD_HOST),win)
 $(error "The Windows installer can only be built on Windows!")
endif


#
# Include Sub-Makefiles.
#
include $(PATH_SUB_CURRENT)/InstallHelper/Makefile.kmk

include $(PATH_SUB_CURRENT)/Stub/Makefile.kmk
include $(PATH_SUB_CURRENT)/StubBld/Makefile.kmk
include $(PATH_SUB_CURRENT)/Resources/Makefile.kmk
ifdef VBOX_WITH_MSI_HACK
 include $(PATH_SUB_CURRENT)/MsiHack/Makefile.kmk
endif

#
# Profile for quickly testing the actual mechanisms of our installer.
# This leaves out most of the optional stuff to make compilation / linking much
# faster for development cycles. Tweak to your likings if needed.
#
# Note! Rather hacky approach -- this *only* works when 'packing' is executed
#       directly in the VBox\Installer directory; otherwise with WILL break the
#       build mostly likely, as we mess with dependencies between components.
#
#       A better appraoch would be to define separate packing defines for dependencies
#       to decouple the building process from the packing more in such a scenario.
#
#       Use with care!
#
ifdef VBOX_INSTALLER_QUICK
 VBOX_INSTALLER_LANGUAGES       := en_US
 VBOX_WITH_LICENSE_DISPLAY      :=
 VBOX_WITH_SERIALNUMBER_INSTALL :=
 VBOX_WITH_ADDITIONS_PACKING    :=
 VBOX_WITH_DEBUGGER_GUI         :=
 VBOX_WITH_EFIFW_PACKING        :=
 VBOX_WITH_EXTPACK              :=
 VBOX_WITH_NETADP               :=
 VBOX_WITH_NETFLT               :=
 VBOX_WITH_PYTHON               :=
 VBOX_WITH_SDS                  :=
 VBOX_WITH_WEBSERVICES          :=
 VBOX_WITH_UNATTENDED           :=
 VBOX_WITH_DOCS_PACKING         :=
 VBOX_WITH_QTGUI                :=
 VBOX_WITH_USB                  :=
 VBOX_WITH_VBOX_IMG             :=
 VBOX_WITH_VBOXSDL              :=
 VBOX_CAB_COMPRESSION_LEVEL     := none
endif

#
# Globals.
#
# Tip: Use VBOX_CAB_COMPRESSION_LEVEL=none on the kmk command line when working
#      on the installer.
#
VBOX_WIN_INST_MAKEFILE_DEP := $(MAKEFILE_CURRENT)
ifndef VBOX_CAB_COMPRESSION_LEVEL
 VBOX_CAB_COMPRESSION_LEVEL := high
endif

VBOX_PATH_WIN_INST_SRC     := $(PATH_SUB_CURRENT)
VBOX_WIN_INST_OUT_DIR      := $(PATH_TARGET)/Installer/win
VBOX_WIN_INST_REPACK_DIR   := $(PATH_OUT)/repack

# Note: en_US *must* come first for the dependency file generation.
ifndef VBOX_INSTALLER_LANGUAGES
 VBOX_INSTALLER_LANGUAGES   = en_US de_DE el_GR fr_FR it_IT tr_TR zh_TW zh_CN
 VBOX_INSTALLER_LANGUAGES  += $(VBOX_INSTALLER_ADD_LANGUAGES)
endif

# Aliases for VBOX_SIGN_FILE_FN that allows better control of the MSI and MSM signing.
VBOX_SIGN_MSI_FN ?= $(VBOX_SIGN_FILE_FN)
VBOX_SIGN_MSM_FN ?= $(VBOX_SIGN_FILE_FN)
VBOX_SIGN_CAB_FN ?= $(VBOX_SIGN_FILE_FN)

#
# List of merge modules to use.
#
ifndef VBOX_INSTALLER_MERGE_MODULES
 VBOX_INSTALLER_MERGE_MODULES = App
 ifdef VBOX_WITH_NETADP
  VBOX_INSTALLER_MERGE_MODULES += NetAdp NetAdp6
 endif
 ifdef VBOX_WITH_NETFLT
  VBOX_INSTALLER_MERGE_MODULES += NetLwf NetFlt
 endif
 ifdef VBOX_WITH_USB
  VBOX_INSTALLER_MERGE_MODULES += USB
 endif
 ifdef VBOX_WITH_PYTHON
  VBOX_INSTALLER_MERGE_MODULES += Python
 endif
endif
ifeq ($(KBUILD_TARGET_ARCH),amd64)
 VBOX_INSTALLER_MERGE_MODULES += COM32On64
endif

# We only ship the merge modules in locale en_US for the moment.
ifdef VBOX_WITH_MSM_INSTALL
 VBOX_INSTALLER_LANGUAGES := en_US
 VBOX_INSTALLER_MERGE_LANGUAGES = $(VBOX_INSTALLER_LANGUAGES)
endif

#
# Language IDs (LCID, decimal)
#
VBOX_BRAND_en_US_LANG_ID ?= 1033
VBOX_BRAND_de_DE_LANG_ID ?= 1031
VBOX_BRAND_el_GR_LANG_ID ?= 1032
VBOX_BRAND_fa_IR_LANG_ID ?= 1065
VBOX_BRAND_fr_FR_LANG_ID ?= 1036
VBOX_BRAND_it_IT_LANG_ID ?= 1040
VBOX_BRAND_tr_TR_LANG_ID ?= 1055
VBOX_BRAND_zh_TW_LANG_ID ?= 1028
VBOX_BRAND_zh_CN_LANG_ID ?= 2052

# Standard language names (in the native language), to be extended as we go.
# VBOX_BRAND_$(lang)_LANG_NAME must be defined for each language which occurs
# in either VBOX_LICENSE_ADD_LANGUAGES or VBOX_MANUAL_ADD_LANGUAGES.
VBOX_BRAND_en_US_LANG_NAME := English
VBOX_BRAND_de_DE_LANG_NAME := Deutsch
VBOX_BRAND_el_GR_LANG_NAME := Ελληνικά
VBOX_BRAND_fr_FR_LANG_NAME := Français
VBOX_BRAND_it_IT_LANG_NAME := Italiano
VBOX_BRAND_tr_TR_LANG_NAME := Türkçe
VBOX_BRAND_zh_TW_LANG_NAME := 正體中文
VBOX_BRAND_zh_CN_LANG_NAME := 简体中文


#
# We don't have the license text in another language than English yet,
# so just define the branding targets to use the English one for now.
# The installer generation assumes that there is a translation for each
# of VBOX_INSTALLER_LANGUAGES.
#
$(foreach lang,$(VBOX_INSTALLER_LANGUAGES), \
	$(eval VBOX_BRAND_$(lang)_LICENSE_RTF := $(VBOX_BRAND_LICENSE_RTF)))

#
# Set the codepage for all languages to 1252, covers most cases.
#
$(foreach lang,$(sort $(VBOX_INSTALLER_LANGUAGES) $(VBOX_LICENSE_ADD_LANGUAGES) $(VBOX_MANUAL_ADD_LANGUAGES)), \
	$(eval VBOX_BRAND_$(lang)_LANGUAGE_CODEPAGE := 1252))
# Exceptions:
VBOX_BRAND_zh_TW_LANGUAGE_CODEPAGE := 950
VBOX_BRAND_zh_CN_LANGUAGE_CODEPAGE := 936
VBOX_BRAND_fa_IR_LANGUAGE_CODEPAGE := 1256
VBOX_BRAND_tr_TR_LANGUAGE_CODEPAGE := 1254

#
# If we want to build a combined package, we separate all common stuff
# (that is all 100% identical content between 32-/64-bit builds)
# into an own .cab file to save space. This .cab file then gets included
# and used by the 32-/64-bit installers.
#
ifdef VBOX_WITH_COMBINED_PACKAGE
 VBOX_INSTALLER_COMMON_DISKID  := 2
else
 VBOX_INSTALLER_COMMON_DISKID  := 1
endif

## @todo VBOX_ prefixes!
PACKAGE_BASE                := VirtualBox-$(VBOX_VERSION_STRING)
PACKAGE_NAME_LANG           := $(PACKAGE_BASE)-r$(VBOX_SVN_REV)
PACKAGE_NAME_FINAL          := $(PATH_STAGE_BIN)/$(PACKAGE_NAME_LANG).msi

ifdef VBOX_WITH_COMBINED_PACKAGE
 PATH_MULTIARCH_TEMP                := $(PATH_OUT_BASE)/win.x86/$(KBUILD_TYPE)/obj/Installer
 PATH_MULTIARCH_GUEST_ADDITIONS_ISO := $(PATH_OUT_BASE)/win.amd64/$(KBUILD_TYPE)/bin/additions
 PACKAGE_NAME_MULTIARCH             := $(PACKAGE_NAME_LANG)-MultiArch
 PACKAGE_NAME_MULTIARCH.x86         := $(PACKAGE_NAME_MULTIARCH)_x86.msi
 PACKAGE_NAME_MULTIARCH.amd64       := $(PACKAGE_NAME_MULTIARCH)_amd64.msi
 PACKAGE_NAME_FINAL                 := $(PATH_MULTIARCH_TEMP)/$(PACKAGE_NAME_MULTIARCH.$(KBUILD_TARGET_ARCH))
 PACKAGE_NAME_MULTIARCH_FINAL       := $(PACKAGE_NAME_MULTIARCH).exe
 # Always take the common.cab from the amd64 build, as it
 # might contain certain files for x86 compatibility such
 # as our 32-on-64-bit COM stuff.
 PACKAGE_NAME_MULTIARCH_COMMONCAB   := $(PATH_OUT_BASE)/win.amd64/$(KBUILD_TYPE)/obj/Installer/win/common.cab

 BLDDIRS += $(PATH_MULTIARCH_TEMP)
 PACKING += $(PACKAGE_NAME_FINAL)
 ifeq ($(KBUILD_TARGET_ARCH),x86)
  PACKING += $(PATH_STAGE_BIN)/$(PACKAGE_NAME_MULTIARCH_FINAL)
 endif
else
 PACKAGE_NAME_MULTIARCH             := $(PACKAGE_NAME_LANG)-MultiArch
 PACKAGE_NAME_MULTIARCH_FINAL       := $(PACKAGE_NAME_MULTIARCH).exe
 PACKING += $(PACKAGE_NAME_FINAL) $(PATH_STAGE_BIN)/$(PACKAGE_NAME_MULTIARCH_FINAL)
endif
BLDDIRS += \
	$(VBOX_WIN_INST_OUT_DIR) \
	$(VBOX_WIN_INST_REPACK_DIR)/ \
	$(foreach lang,$(VBOX_INSTALLER_LANGUAGES), \
	$(VBOX_WIN_INST_OUT_DIR)/$(lang)/ \
	$(VBOX_WIN_INST_REPACK_DIR)/files-VirtualBox_$(lang)/ ) \
	$(VBOX_WIN_INST_OUT_DIR)/NLS/

OTHER_CLEAN += \
	$(VBOX_WIN_INST_OUT_DIR)/VirtualBox.wixobj \
	$(VBOX_WIN_INST_OUT_DIR)/VirtualBox.wix \
	$(VBOX_WIN_INST_REPACK_DIR)/VirtualBox.wix \
	$(VBOX_WIN_INST_OUT_DIR)/VirtualBox.wixobj.dep \
	$(VBOX_WIN_INST_OUT_DIR)/VirtualBox_TypeLib.wxi \
	$(VBOX_WIN_INST_OUT_DIR)/VirtualBox_TypeLib_x86.wxi \
	$(VBOX_WIN_INST_OUT_DIR)/VirtualBox_ProxyStub.wxi \
	$(if $(VBOX_WITH_QTGUI),$(VBOX_WIN_INST_OUT_DIR)/VBoxGuiNLS.wxi) \
	$(VBOX_WIN_INST_OUT_DIR)/VBoxKey.wxi \
	$(VBOX_WIN_INST_OUT_DIR)/VBoxUnattendedTemplateComponent.wxi \
	$(foreach lang,$(VBOX_INSTALLER_LANGUAGES), \
	$(VBOX_WIN_INST_OUT_DIR)/NLS/Language_$(lang).wxl \
	$(VBOX_WIN_INST_OUT_DIR)/NLS/License_$(lang).wxl \
	$(VBOX_WIN_INST_OUT_DIR)/$(lang)/$(lang).mst \
	$(VBOX_WIN_INST_OUT_DIR)/$(lang)/$(PACKAGE_NAME_LANG)_$(lang).wixpdb \
	$(VBOX_WIN_INST_OUT_DIR)/$(lang)/$(PACKAGE_NAME_LANG)_$(lang).msi \
	$(VBOX_WIN_INST_OUT_DIR)/$(lang)/VirtualBox_$(lang).wix \
	$(VBOX_WIN_INST_OUT_DIR)/$(lang)/VirtualBox_$(lang).wixobj \
	$(VBOX_WIN_INST_OUT_DIR)/$(lang)/VirtualBox_$(lang).wixobj.dep \
	$(VBOX_WIN_INST_REPACK_DIR)/VirtualBox_$(lang).wix \
	$(VBOX_WIN_INST_REPACK_DIR)/VirtualBox_$(lang).files \
	$(VBOX_WIN_INST_REPACK_DIR)/2-link-$(PACKAGE_NAME_LANG).cmd \
	$(VBOX_WIN_INST_REPACK_DIR)/files-VirtualBox_$(lang)/Language_$(lang).wxl \
	$(VBOX_WIN_INST_REPACK_DIR)/files-VirtualBox_$(lang)/License_$(lang).wxl ) \
	$(VBOX_WIN_INST_OUT_DIR)/DirComponentsAndFiles_DTrace.wxi \
	$(VBOX_WIN_INST_OUT_DIR)/Files_Main.wxi \
	$(VBOX_WIN_INST_OUT_DIR)/Files_Doc.wxi \
	$(VBOX_WIN_INST_OUT_DIR)/Files_License.wxi \
	$(VBOX_WIN_INST_OUT_DIR)/Shortcuts_StartMenu.wxi \
	$(VBOX_WIN_INST_OUT_DIR)/$(PACKAGE_NAME_LANG).msi \
	$(VBOX_WIN_INST_REPACK_DIR)/3-multilingual-$(PACKAGE_NAME_LANG).cmd \
	$(PATH_STAGE_BIN)/$(PACKAGE_NAME_MULTIARCH_FINAL)

ifdef VBOX_WITH_COMBINED_PACKAGE
 ifeq ($(KBUILD_TARGET_ARCH),x86)
  OTHER_CLEAN += \
  	$(VBOX_WIN_INST_REPACK_DIR)/4-multiarch-$(PACKAGE_NAME_MULTIARCH_FINAL).cmd \
  	$(PATH_MULTIARCH_TEMP)/$(PACKAGE_NAME_MULTIARCH.x86)
 endif
 ifndef VBOX_WITH_MSM_INSTALL
  OTHER_CLEAN += \
  	$(VBOX_WIN_INST_OUT_DIR)/common.cab
 endif
else
 OTHER_CLEAN += \
 	$(VBOX_WIN_INST_REPACK_DIR)/4-multiarch-$(PACKAGE_NAME_MULTIARCH_FINAL).cmd \
 	$(PACKAGE_NAME_FINAL)
endif

ifdef VBOX_WITH_MSM_INSTALL
 OTHER_CLEAN += \
 	$(foreach module,$(VBOX_INSTALLER_MERGE_MODULES), \
 	$(foreach lang,$(VBOX_INSTALLER_MERGE_LANGUAGES), \
 	$(VBOX_WIN_INST_OUT_DIR)/VBoxMerge$(module)_$(lang)_$(KBUILD_TARGET_ARCH).msm \
 	$(VBOX_WIN_INST_OUT_DIR)/VBoxMerge$(module)_$(lang).wixobj \
 	$(VBOX_WIN_INST_OUT_DIR)/VBoxMerge$(module)_$(lang).wixobj.dep \
 	$(VBOX_WIN_INST_OUT_DIR)/VBoxMerge$(module)_$(lang).wixpdb \
 	$(VBOX_WIN_INST_REPACK_DIR)/VBoxMerge$(module)_$(lang).wix \
 	$(VBOX_WIN_INST_REPACK_DIR)/VBoxMerge$(module)_$(lang).files)
 BLDDIRS        += $foreach lang,$(VBOX_INSTALLER_MERGE_LANGUAGES), \
 	$(VBOX_WIN_INST_REPACK_DIR)/files-VBoxMerge$(module)_$(lang)/)
endif

#
# Suppress/skip the following ICE (Internal Consistency Evaluators):
# - ICE64: Checks that new directories in the user profile are removed correctly in roaming scenarios.
#          -> We don't want to remove system folders (like "Microsoft/Internet Explorer/Quick Launch").
# - ICE69: Checks if file references are within the same component.
#          -> We reference to files within different components, but these components are installed using
#             the same feature, so that's fine.
#
VBOX_MSI_ICE_IGNORE := \
	-ice:64 \
	-ice:69

#
# Create intermediate XML file for languages (needed for .MSI linking).
#
# Note: The double escaping of $(dir $@) in the prereq/dep list is because we first have
#       to escape the expansion of the $(eval ) argument and then the definition of the
#       rule. The statement is finally expanded during second dependency expansion, which
#       takes place after all makefiles has been loaded and with the @ variable defined.
#
define def_vbox_lang_xml
 $(VBOX_WIN_INST_OUT_DIR)/NLS/Language_$(lang).wxl: $(VBOX_PATH_WIN_INST_SRC)/NLS/$(lang).wxl | $$$$(dir $$$$@)
	$$(call MSG_GENERATE,,$$@,$$<)
	$(QUIET)$(INSTALL) -m 0644 $$< $$@
endef

$(foreach lang,$(VBOX_INSTALLER_LANGUAGES), \
	$(eval $(def_vbox_lang_xml)))

#
# Create intermediate XML file for licenses (needed for .MSI linking).
# These files are created from the original .RTF files in the /docs directory.
#
# Note: The redirect command below will open $$@ as stdout in append+text mode
#       and then exec cat, thus appending the license file to the result file.
#
# Note: The license_file variable has to be created before def_vbox_license_xml
#       is expanded by the 2nd eval because we rely on the that expansion
#       replacing all $(license_file) (and $(lang)) references before evaluation.
#
# Note: The REDIRECT + ECHO_EXT is because WiX gets upset if there a newline
#       between the tag and the RTF license text.
#
define def_vbox_license_xml
 $(VBOX_WIN_INST_OUT_DIR)/NLS/License_$(lang).wxl: $(license_file) $(VBOX_WIN_INST_MAKEFILE_DEP) | $$$$(dir $$$$@)
	$$(call MSG_GENERATE,,$$@,$$<)
	$(APPEND) -t $$@ '<?xml version="1.0" encoding="utf-8"?>'
	$(APPEND) $$@ '<WixLocalization xmlns="http://schemas.microsoft.com/wix/2006/localization" Codepage="$(VBOX_BRAND_$(lang)_LANGUAGE_CODEPAGE)" Culture="$(lang)">'

	$(REDIRECT) -a+to $$@ -- $(ECHO_EXT) -n '<String Id="LicenseText">'
	$(REDIRECT) -a+to $$@ -- $(SED) -e "s|<|\&lt;|g" -e "s|>|\&gt;|g" $(license_file)
	$(APPEND) $$@ '</String>'

	$(APPEND) $$@ '<String Id="LicenseFile">$(license_file)</String>'
	$(APPEND) $$@ '<String Id="LicenseInstallFileLong">License_$(lang).rtf</String>'
	$(APPEND) $$@ '<String Id="LicenseInstallFileShort">L_$(lang).rtf</String>'

	$(APPEND) $$@ '</WixLocalization>'
endef

$(foreach lang,$(VBOX_INSTALLER_LANGUAGES), \
	$(eval local license_file := $(VBOX_BRAND_$(subst en_US_,,$(lang)_)LICENSE_RTF)) \
	$(eval $(def_vbox_license_xml)))

#
# Create one intermediate WXI (Windows Installer Include) file for all installers (needed for .MSI compiling).
# This file includes all language-specific files (PDFs, CHMs, ...) to install.
#
# Note: When using the -n switch, append will append a new line after each
#       argument. The -t switch makes it truncate the file.
#
$(VBOX_WIN_INST_OUT_DIR)/Files_Main.wxi: $(VBOX_WIN_INST_MAKEFILE_DEP) | $$(dir $$@)
	$(call MSG_GENERATE,,$@,$<)
	$(APPEND) -t $@ '<?xml version="1.0" ?>'
	$(APPEND) $@ '<Include xmlns="http://schemas.microsoft.com/wix/2006/wi">'
ifdef VBOX_WITH_DOCS_PACKING
 ifdef VBOX_WITH_DOCS_CHM_PACKING
	$(APPEND) $@ '	<File Id="file_VirtualBox.chm" Name="VirtualBox.chm" DiskId="$(VBOX_INSTALLER_COMMON_DISKID)" Vital="yes" Source="$(subst /,\,$(PATH_STAGE_BIN)/VirtualBox.chm)"></File>'
	$(APPEND) -n $@ $(foreach lang,$(VBOX_MANUAL_ADD_LANGUAGES), \
		     '	<File Id="file_VirtualBox_$(lang).chm" Name="VirtualBox_$(lang).chm" DiskId="$(VBOX_INSTALLER_COMMON_DISKID)" Vital="yes" Source="$(subst /,\,$(PATH_STAGE_BIN)/VirtualBox_$(lang).chm)"></File>')
 endif
 ifdef VBOX_WITH_DOCS_QHELP_PACKING
	$(APPEND) $@ '	<File Id="file_UserManual.qch" Name="UserManual.qch" DiskId="$(VBOX_INSTALLER_COMMON_DISKID)" Vital="yes" Source="$(subst /,\,$(PATH_STAGE_BIN)/UserManual.qch)"></File>'
	$(APPEND) $@ '	<File Id="file_UserManual.qhc" Name="UserManual.qhc" DiskId="$(VBOX_INSTALLER_COMMON_DISKID)" Vital="yes" Source="$(subst /,\,$(PATH_STAGE_BIN)/UserManual.qhc)"></File>'
	$(APPEND) -n $@ $(foreach lang,$(VBOX_MANUAL_ADD_LANGUAGES), \
		     '	<File Id="file_UserManual_$(lang).qch" Name="UserManual_$(lang).qch" DiskId="$(VBOX_INSTALLER_COMMON_DISKID)" Vital="yes" Source="$(subst /,\,$(PATH_STAGE_BIN)/UserManual_$(lang).qch)"></File>' \
		     '	<File Id="file_UserManual_$(lang).qhc" Name="UserManual_$(lang).qhc" DiskId="$(VBOX_INSTALLER_COMMON_DISKID)" Vital="yes" Source="$(subst /,\,$(PATH_STAGE_BIN)/UserManual_$(lang).qhc)"></File>')
 endif
endif
	$(APPEND) $@ '</Include>'

$(VBOX_WIN_INST_OUT_DIR)/Files_Doc.wxi: $(VBOX_WIN_INST_MAKEFILE_DEP) | $$(dir $$@)
	$(call MSG_GENERATE,,$@,$<)
	$(APPEND) -t $@ '<?xml version="1.0" ?>'
	$(APPEND) $@ '<Include xmlns="http://schemas.microsoft.com/wix/2006/wi">'
ifdef VBOX_WITH_DOCS_PACKING
	$(APPEND) $@ '	<File Id="file_UserManual.pdf" Name="UserManual.pdf" DiskId="$(VBOX_INSTALLER_COMMON_DISKID)" Vital="yes" Source="$(subst /,\,$(PATH_STAGE_BIN)/UserManual.pdf)">'
	$(APPEND) $@ '	</File>'
	$(APPEND) -n $@ $(foreach lang,$(VBOX_MANUAL_ADD_LANGUAGES), \
	             '	<File Id="file_UserManual_$(lang).pdf" Name="UserManual_$(lang).pdf" DiskId="$(VBOX_INSTALLER_COMMON_DISKID)" Vital="yes" Source="$(subst /,\,$(PATH_STAGE_BIN)/UserManual_$(lang).pdf)">' \
	             '	</File>')
endif
	$(APPEND) $@ '</Include>'

$(VBOX_WIN_INST_OUT_DIR)/Files_License.wxi: $(VBOX_WIN_INST_MAKEFILE_DEP) | $$(dir $$@)
	$(call MSG_GENERATE,,$@,$<)
	$(APPEND) -t $@ '<?xml version="1.0" ?>'
	$(APPEND) $@ '<Include xmlns="http://schemas.microsoft.com/wix/2006/wi">'
	$(APPEND) $@ '	<File Id="file_License_en_US.rtf" Name="License_en_US.rtf" DiskId="$(VBOX_INSTALLER_COMMON_DISKID)" Vital="yes" Source="$(subst /,\,$(VBOX_BRAND_LICENSE_RTF))">' \
	             '	</File>'
	$(APPEND) -n $@ $(foreach lang,$(VBOX_LICENSE_ADD_LANGUAGES), \
	             '	<File Id="file_License_$(lang).rtf" Name="License_$(lang).rtf" DiskId="$(VBOX_INSTALLER_COMMON_DISKID)" Vital="yes" Source="$(subst /,\,$(VBOX_BRAND_$(lang)_LICENSE_RTF))">' \
	             '	</File>')
	$(APPEND) $@ '</Include>'

$(VBOX_WIN_INST_OUT_DIR)/DirComponentsAndFiles_DTrace.wxi: $(VBOX_WIN_INST_MAKEFILE_DEP) $(PATH_SUB_CURRENT)/../Config.kmk | $$(dir $$@)
	$(call MSG_GENERATE,,$@,$<)
	$(QUIET)$(APPEND) -nt "$@" \
		'<?xml version="1.0" ?>' \
		'<Include xmlns="http://schemas.microsoft.com/wix/2006/wi">'
ifdef VBOX_WITH_DTRACE
	$(QUIET)$(APPEND) -n "$@" \
		'<Directory Id="dir_DTrace" Name="dtrace">' \
		'  <Directory Id="dir_DTrace_lib" Name="lib">' \
		'    <Directory Id="dir_DTrace_lib_arch" Name="$(KBUILD_TARGET_ARCH)">' \
		'      <Component Id="cp_dir_DTrace_lib_arch" Guid="7476CDF6-4157-2E17-5CCC-FF92528D2854" Win64="$$(var.Property_Win64)">' \
		$(foreach file, $(VBOXINST_DTRACE_LIB_ARCH_FILES) \
                	, '        <File Id="file_dtrace_lib_arch_$(subst -,_,$(file))" Name="$(file)" Vital="yes" ' \
			  '              Source="$(subst /,\,$(PATH_STAGE_BIN)/dtrace/lib/$(KBUILD_TARGET_ARCH)/$(file))" />' ) \
		'      </Component>' \
		'    </Directory>' \
		'  </Directory>' \
        $(if $(VBOXINST_DTRACE_TESTCASE_ARCH_FILES), \
		'  <Directory Id="dir_DTrace_testcase" Name="testcase">' \
		'    <Directory Id="dir_DTrace_testcase_arch" Name="$(KBUILD_TARGET_ARCH)">' \
		'      <Component Id="cp_dir_DTrace_testcase_arch" Guid="45DF7014-4431-6C40-6DB0-35AF7C690EE1" Win64="$$(var.Property_Win64)">' \
		$(foreach file, $(VBOXINST_DTRACE_TESTCASE_ARCH_FILES) \
                	, '        <File Id="file_dtrace_testcase_arch_$(subst -,_,$(file))" Name="$(file)" Vital="yes" ' \
			  '              Source="$(subst /,\,$(PATH_STAGE_BIN)/dtrace/testcase/$(KBUILD_TARGET_ARCH)/$(file))" />' ) \
		'      </Component>' \
		'    </Directory>' \
		'  </Directory>') \
        $(if $(VBOXINST_DTRACE_SCRIPTS_FILES), \
		'  <Directory Id="dir_DTrace_scripts" Name="scripts">' \
		'    <Component Id="cp_dir_DTrace_scripts" Guid="AE07F9D5-4FD9-ACC7-C760-E9923CE01E16" Win64="$$(var.Property_Win64)">' \
		$(foreach file, $(VBOXINST_DTRACE_SCRIPTS_FILES) \
                	, '      <File Id="file_dtrace_scripts_$(subst -,_,$(file))" Name="$(file)" Vital="yes" ' \
			  '            Source="$(subst /,\,$(PATH_STAGE_BIN)/dtrace/scripts/$(file))" />' ) \
		'    </Component>' \
		'  </Directory>') \
		'</Directory>'
endif
	$(QUIET)$(APPEND) "$@" '</Include>'


$(VBOX_WIN_INST_OUT_DIR)/Shortcuts_StartMenu.wxi: $(VBOX_WIN_INST_MAKEFILE_DEP) | $$(dir $$@)
	$(call MSG_GENERATE,,$@,$<)
	$(APPEND) -t $@ '<?xml version="1.0" ?>'
	$(APPEND) $@ '<Include xmlns="http://schemas.microsoft.com/wix/2006/wi">'
	#
	# Documentation (PDF/CHM)
	#
ifdef VBOX_WITH_DOCS_PACKING
 ifdef VBOX_WITH_DOCS_CHM_PACKING
	$(APPEND) $@ '	<Shortcut Id="sc_StartMenu_ManualCHM_en_US" Directory="dir_StartMenuVBox" Name="!(loc.StartMenu_UserManual) (CHM, English)" Description="!(loc.StartMenu_UserManual)"' \
	             '            Target="[INSTALLDIR]\VirtualBox.chm" WorkingDirectory="dir_Documents" Advertise="no"/>'
	$(APPEND) -n $@ $(foreach lang,$(VBOX_MANUAL_ADD_LANGUAGES), \
	             '	<Shortcut Id="sc_StartMenu_ManualCHM_$(lang)" Directory="dir_StartMenuVBox" Name="!(loc.StartMenu_UserManual) (CHM, $(VBOX_BRAND_$(lang)_LANG_NAME))"' \
		     '            Description="!(loc.StartMenu_UserManual) ($(VBOX_BRAND_$(lang)_LANG_NAME))" Target="[INSTALLDIR]\VirtualBox_$(lang).chm" WorkingDirectory="dir_Documents"/>')
 endif
	$(APPEND) $@ '	<Shortcut Id="sc_StartMenu_ManualPDF_en_US" Directory="dir_StartMenuVBox" Name="!(loc.StartMenu_UserManual) (PDF, English)" Description="!(loc.StartMenu_UserManual)"' \
	             '            Target="[INSTALLDIR]\doc\UserManual.pdf" WorkingDirectory="dir_Documents" Advertise="no"/>'
	$(APPEND) -n $@ $(foreach lang,$(VBOX_MANUAL_ADD_LANGUAGES), \
	             '	<Shortcut Id="sc_StartMenu_ManualPDF_$(lang)" Directory="dir_StartMenuVBox" Name="!(loc.StartMenu_UserManual) (PDF, $(VBOX_BRAND_$(lang)_LANG_NAME))"' \
		     '            Description="!(loc.StartMenu_UserManual) ($(VBOX_BRAND_$(lang)_LANG_NAME))" Target="[INSTALLDIR]\doc\UserManual_$(lang).pdf" WorkingDirectory="dir_Documents"/>')
endif
	#
	# License(s) (RTF)
	#
	$(APPEND) $@ '	<Shortcut Id="sc_StartMenu_License_en_US" Directory="dir_StartMenuVBox" Name="!(loc.StartMenu_License) (English)" Description="!(loc.StartMenu_License)"' \
	             '            Target="[INSTALLDIR]License_en_US.rtf" WorkingDirectory="INSTALLDIR" Advertise="no"/>'
	$(APPEND) -n $@ $(foreach lang,$(VBOX_LICENSE_ADD_LANGUAGES), \
	             '	<Shortcut Id="sc_StartMenu_License_$(lang)" Directory="dir_StartMenuVBox" Name="!(loc.StartMenu_License) ($(VBOX_BRAND_$(lang)_LANG_NAME))"' \
		     '            Description="!(loc.StartMenu_License) ($(VBOX_BRAND_$(lang)_LANG_NAME))" Target="License_$(lang).rtf" WorkingDirectory="INSTALLDIR"/>')
	$(APPEND) $@ '</Include>'

#
# .MSI linking of the main installer (en_US).
#
# Note: This will clean up any previous .msi and .wixpdb files to prevent dep
#       build boxes from filling up with old files.
#
define def_vbox_link_msi
 $(VBOX_WIN_INST_OUT_DIR)/$(lang)/$(PACKAGE_NAME_LANG)_$(lang).msi \
 $(if-expr defined(VBOX_WITH_COMBINED_PACKAGE) && !defined(VBOX_WITH_MSM_INSTALL), + $(VBOX_WIN_INST_OUT_DIR)/common.cab,): \
 		$(VBOX_WIN_INST_OUT_DIR)/$(lang)/VirtualBox_$(lang).wixobj \
 		$(VBOX_WIN_INST_OUT_DIR)/NLS/Language_$(lang).wxl \
 		$(VBOX_WIN_INST_OUT_DIR)/NLS/License_$(lang).wxl \
 		$(PATH_STAGE_BIN)/VBoxInstallHelper.dll \
 		$(VBOX_SVN_REV_KMK) \
 		$(VBOX_WIN_INST_MAKEFILE_DEP) \
 		$(if-expr defined(VBOX_WITH_MSI_HACK),$(MsiHack_0_OUTDIR)/MsiHack.dll,) \
 		$(if-expr defined(VBOX_WITH_MSI_HACK),$(MsiHack_0_OUTDIR)/MsiHackExtension.dll,) \
 		| $$$$(dir $$$$@)
	$$(call MSG_L1,Linking installer $$@)
	$(QUIET)$(RM) -f $$(wildcard $$(subst r$$(VBOX_SVN_REV),r*,\
		$$@ \
		$$(basename $$@).wixpdb \
		$$(VBOX_WIN_INST_REPACK_DIR)/2-link-$$(PACKAGE_NAME_LANG).cmd ))
	kmk_time $$(REDIRECT_EXT) -E WIX_TEMP='$$(subst /,\,$$(@D))' -- $(VBOX_PATH_WIX)/light.exe -v -nologo \
		-loc $(VBOX_WIN_INST_OUT_DIR)/NLS/Language_$(lang).wxl \
		-loc $(VBOX_WIN_INST_OUT_DIR)/NLS/License_$(lang).wxl \
		-ext $(VBOX_PATH_WIX)/WixUIExtension.dll \
		-ext $(VBOX_PATH_WIX)/WixDifxAppExtension.dll \
		-ext $(VBOX_PATH_WIX)/WixUtilExtension.dll \
               $(if-expr defined(VBOX_WITH_MSI_HACK),-ext $(MsiHack_0_OUTDIR)/MsiHackExtension.dll,) \
		$(VBOX_MSI_ICE_IGNORE) \
		-out $$@ \
		$$< \
		$(VBOX_PATH_WIX)/difxapp_$(if-expr "$(KBUILD_TARGET_ARCH)" == "x86",x86,x64).wixlib
 if defined(VBOX_WITH_COMBINED_PACKAGE) && !defined(VBOX_WITH_MSM_INSTALL)
	$(MV) -f -- $$(@D)/common.cab $$(@D)/../common.cab
 endif
 ifeq ($(lang),en_US)
	$(CP) -f -- "$(VBOX_WIN_INST_OUT_DIR)/NLS/Language_$(lang).wxl" "$(VBOX_WIN_INST_OUT_DIR)/NLS/License_$(lang).wxl" \
       	"$(VBOX_WIN_INST_REPACK_DIR)/files-VirtualBox_$(lang)/"
  # Create repack script for this step.
	$(APPEND) -tn "$$(VBOX_WIN_INST_REPACK_DIR)/2-link-$$(PACKAGE_NAME_LANG).cmd" \
       	'if ".%KBUILD_DEVTOOLS%" == "." (echo KBUILD_DEVTOOLS is not set & exit /b1)' \
		$(subst $(KBUILD_DEVTOOLS),%KBUILD_DEVTOOLS%,\
		'$(VBOX_PATH_WIX)/light.exe -v -nologo ^' \
		'  -loc files-VirtualBox_$(lang)/Language_$(lang).wxl ^' \
		'  -loc files-VirtualBox_$(lang)/License_$(lang).wxl ^' \
		'  -ext $(VBOX_PATH_WIX)/WixUIExtension.dll ^' \
		'  -ext $(VBOX_PATH_WIX)/WixDifxAppExtension.dll ^' \
		'  -ext $(VBOX_PATH_WIX)/WixUtilExtension.dll ^' \
               $(if-expr defined(VBOX_WITH_MSI_HACK),'-ext $(MsiHack_0_OUTDIR)/MsiHackExtension.dll ^',) \
		'  $(VBOX_MSI_ICE_IGNORE) ^' \
		'  -out $$(@F) ^' \
		'  $$(<F) ^' \
		'  $(VBOX_PATH_WIX)/difxapp_$(if-expr "$(KBUILD_TARGET_ARCH)" == "x86",x86,x64).wixlib ^' \
               '  || exit /b1' \
               ) \
               '@echo Created MSI installer: $$(@F)' \
		$(if-expr defined(VBOX_WITH_COMBINED_PACKAGE) && !defined(VBOX_WITH_MSM_INSTALL),'@echo Created: common.cab',)

 endif
endef

$(foreach lang, en_US, $(eval $(def_vbox_link_msi)))


#
# Merge module linking (all languages).
#
# Note: This will clean up any previous .msm to prevent dep build boxes from
#       filling up with old files.
#
define def_vbox_link_msm
 $(VBOX_WIN_INST_OUT_DIR)/VBoxMerge$(module)_$(lang)_$(KBUILD_TARGET_ARCH).msm: \
 		$(VBOX_WIN_INST_OUT_DIR)/VBoxMerge$(module)_$(lang).wixobj \
 		$(VBOX_WIN_INST_OUT_DIR)/NLS/Language_$(lang).wxl \
 		$(VBOX_WIN_INST_OUT_DIR)/NLS/License_$(lang).wxl \
 		$(PATH_STAGE_BIN)/VBoxInstallHelper.dll \
 		$(VBOX_SVN_REV_KMK) \
 		$(VBOX_WIN_INST_MAKEFILE_DEP) \
 		| $$$$(dir $$$$@)
	$$(call MSG_L1,Linking installer $$@)
	$(QUIET)$(RM) -f $$(wildcard $(VBOX_WIN_INST_OUT_DIR)/$(PACKAGE_BASE)-r*_$(lang).msi)
	kmk_time $$(REDIRECT_EXT) -E WIX_TEMP='$$(subst /,\,$$(@D))' -- $(VBOX_PATH_WIX)/light.exe -v -nologo \
		-loc $(VBOX_WIN_INST_OUT_DIR)/NLS/Language_$(lang).wxl \
		-loc $(VBOX_WIN_INST_OUT_DIR)/NLS/License_$(lang).wxl \
		-ext $(VBOX_PATH_WIX)/WixDifxAppExtension.dll \
		-ext $(VBOX_PATH_WIX)/WixUtilExtension.dll \
		$(VBOX_MSI_ICE_IGNORE) \
		-out $$@ \
		$$< \
		$(VBOX_PATH_WIX)/difxapp_$(if-expr "$(KBUILD_TARGET_ARCH)" == "x86",x86,x64).wixlib
	$(RM) -f $(VBOX_WIN_INST_OUT_DIR)/NLS/$(lang).mst
	$(call VBOX_SIGN_MSM_FN,$$@,$(VBOX_PRODUCT) $(VBOX_VERSION_STRING)r$(VBOX_SVN_REV) ($(KBUILD_TARGET_ARCH)),,,disable-dual-signing)
 # Create repack script for this step.
	$(APPEND) -tn "$$(VBOX_WIN_INST_REPACK_DIR)/2-link-VBoxMerge$(module)_$(lang).cmd" \
       	'if ".%KBUILD_DEVTOOLS%" == "." (echo KBUILD_DEVTOOLS is not set & exit /b1)' \
		$(subst $(KBUILD_DEVTOOLS),%KBUILD_DEVTOOLS%,\
		'$(VBOX_PATH_WIX)/light.exe -v -nologo ^' \
		'  -loc files-VirtualBox_$(lang)/Language_$(lang).wxl ^' \
		'  -loc files-VirtualBox_$(lang)/License_$(lang).wxl ^' \
		'  -ext $(VBOX_PATH_WIX)/WixDifxAppExtension.dll ^' \
		'  -ext $(VBOX_PATH_WIX)/WixUtilExtension.dll ^' \
		'  $(VBOX_MSI_ICE_IGNORE) ^' \
		'  -out $$(@F) ^' \
		'  $$(<F) ^' \
		'  $(VBOX_PATH_WIX)/difxapp_$(if-expr "$(KBUILD_TARGET_ARCH)" == "x86",x86,x64).wixlib ^' \
               '  || exit /b1' \
		'call sign-sha1.cmd $$(@F) || exit /b1' \
               ) \
               '@echo Created MSM module: $$(@F)'
endef

ifdef VBOX_WITH_MSM_INSTALL
 $(foreach module,$(VBOX_INSTALLER_MERGE_MODULES), \
 	$(foreach lang,$(VBOX_INSTALLER_MERGE_LANGUAGES), \
		$(eval $(def_vbox_link_msm)))),)
endif


#
# Add dependencies that makes sure necessary bits gets built.
# For combined packages we always use the .ISO from the amd64 build.
#
ifdef VBOX_WITH_COMBINED_PACKAGE
 VBOX_MSI_DEPENDENCIES := \
 	$(if $(VBOX_WITH_ADDITIONS_PACKING),$(PATH_MULTIARCH_GUEST_ADDITIONS_ISO)/VBoxGuestAdditions.iso)
else
 VBOX_MSI_DEPENDENCIES := \
 	$(if $(VBOX_WITH_ADDITIONS_PACKING),$(VBOX_PATH_ADDITIONS_ISO)/VBoxGuestAdditions.iso)
endif

#
# A few manual dependencies to make sure everything is rebuilt when they should.
#
$(PATH_SUB_CURRENT)/VirtualBox.wxs: \
		$(PATH_SUB_CURRENT)/CommonProperties.wxi \
		$(PATH_SUB_CURRENT)/Defines.wxi \
		$(PATH_SUB_CURRENT)/VBoxMergeApp.wxi

$(PATH_SUB_CURRENT)/VBoxMergeApp.wxi $(PATH_SUB_CURRENT)/VirtualBox.wxs: \
		$(VBOX_WIN_INST_OUT_DIR)/Files_Doc.wxi \
		$(VBOX_WIN_INST_OUT_DIR)/DirComponentsAndFiles_DTrace.wxi \
		$(VBOX_WIN_INST_OUT_DIR)/Files_License.wxi \
		$(VBOX_WIN_INST_OUT_DIR)/Files_Main.wxi \
		$(VBOX_WIN_INST_OUT_DIR)/VBoxKey.wxi \
		$(VBOX_WIN_INST_OUT_DIR)/VBoxGuiNLS.wxi \
		$(VBOX_WIN_INST_OUT_DIR)/VirtualBox_TypeLib.wxi \
		$(VBOX_WIN_INST_OUT_DIR)/VBoxUnattendedTemplateComponent.wxi

#
# MSI compile.
# We've separated the processing from the compilation for repacking reasons.
#
define def_vbox_compile_wixobj
 includedep $(VBOX_WIN_INST_OUT_DIR)/$(lang)/VirtualBox_$(lang).wixobj.dep
 $(VBOX_WIN_INST_OUT_DIR)/$(lang)/VirtualBox_$(lang).wixobj \
 + $(VBOX_WIN_INST_OUT_DIR)/$(lang)/VirtualBox_$(lang).wix \
 $(if-expr "$(lang)" != "en_US",, \
 	+ $(VBOX_WIN_INST_REPACK_DIR)/VirtualBox_$(lang).wix $(VBOX_WIN_INST_REPACK_DIR)/VirtualBox_$(lang).files ): \
 		$(PATH_SUB_CURRENT)/VirtualBox.wxs \
 		$(PATH_SUB_CURRENT)/UserInterface.wxi \
 		$(if-expr defined(VBOX_WITH_MSM_INSTALL), \
 			$(foreach module,$(VBOX_INSTALLER_MERGE_MODULES), \
 				$(VBOX_WIN_INST_OUT_DIR)/VBoxMerge$(module)_$(lang)_$(KBUILD_TARGET_ARCH).msm), \
 			$(VBOX_WIN_INST_OUT_DIR)/Shortcuts_StartMenu.wxi \
 			$(VBOX_WIN_INST_OUT_DIR)/VirtualBox_TypeLib.wxi \
 			$(if $(VBOX_WITH_32_ON_64_MAIN_API),$(VBOX_WIN_INST_OUT_DIR)/VirtualBox_TypeLib_x86.wxi,) \
 			$(VBOX_WIN_INST_OUT_DIR)/VBoxKey.wxi \
 			$(if $(VBOX_WITH_CRT_PACKING),$(VBOX_WIN_INST_OUT_DIR)/VBoxCrtDlls.wxi,) \
 			$(if $(VBOX_WITH_CRT_PACKING),$(VBOX_WIN_INST_OUT_DIR)/VBoxCrtDlls32.wxi,) \
 			$(VBOX_WIN_INST_OUT_DIR)/VBoxUnattendedTemplateComponent.wxi \
 			$(if $(VBOX_WITH_QTGUI),$(VBOX_WIN_INST_OUT_DIR)/VBoxGuiNLS.wxi) \
 			$(VBOX_MSI_DEPENDENCIES)) \
 		$(VBOX_VERSION_STAMP) \
 		| $$$$(dir $$$$@) $(if-expr "$(lang)" != "en_US",, \
 			$(VBOX_WIN_INST_REPACK_DIR)/ $(VBOX_WIN_INST_REPACK_DIR)/files-VirtualBox_$(lang)/ )
	$(QUIET)$(RM) -f -- "$$@"  "$(VBOX_WIN_INST_OUT_DIR)/$(lang)/VirtualBox_$(lang).wix" "$(VBOX_WIN_INST_REPACK_DIR)/VirtualBox_$(lang).wix"
	$(REDIRECT) \
		-E 'PATH_OUT=$(subst /,\,$(PATH_OUT))' \
		-E 'PATH_TARGET=$(subst /,\,$(VBOX_WIN_INST_OUT_DIR))' \
		-E 'PATH_ROOT=$(subst /,\,$(PATH_ROOT))' \
		-E 'PATH_MULTIARCH_GUEST_ADDITIONS_ISO=$(subst /,\,$(PATH_MULTIARCH_GUEST_ADDITIONS_ISO))' \
		-E 'VBOX_PATH_WIN_INST_SRC=$(subst /,\,$(VBOX_PATH_WIN_INST_SRC))' \
		-E 'VBOX_BRAND_WIN_INST_DLGJPG=$(subst /,\,$(VBOX_BRAND_WIN_INST_DLGJPG))' \
		-E 'VBOX_ADD_LANGUAGES=$(VBOX_INSTALLER_ADD_LANGUAGES)' \
		-E 'VBOX_BRAND_LICENSE_RTF=$(subst /,\,$(VBOX_BRAND_LICENSE_RTF))' \
		$(foreach lang,$(VBOX_INSTALLER_LANGUAGES), \
			-E 'VBOX_BRAND_$(lang)_LICENSE_RTF=$(subst /,\,$(VBOX_BRAND_$(subst en_US_,,$(lang)_)LICENSE_RTF))') \
		-E 'VBOX_BUILD_NR_FOR_INST=$(VBOX_VERSION_BUILD)' \
		-E 'VBOX_VENDOR=$(VBOX_VENDOR)' \
		-E 'VBOX_VENDOR_SHORT=$(VBOX_VENDOR_SHORT)' \
		-E 'VBOX_PRODUCT=$(VBOX_PRODUCT)' \
		-E 'VBOX_C_YEAR=$(VBOX_C_YEAR)' \
		-E 'VBOX_VERSION_STRING=$(VBOX_VERSION_STRING)' \
		-E 'VBOX_VERSION_STRING_RAW=$(VBOX_VERSION_STRING_RAW)' \
		-E 'VBOX_VERSION_MAJOR_INST=$(VBOX_VERSION_MAJOR)' \
		-E 'VBOX_VERSION_MINOR_INST=$(VBOX_VERSION_MINOR)' \
		-E 'VBOX_SIGNING_MODE=$(strip $(if $(VBOX_SIGNING_MODE),$(VBOX_SIGNING_MODE),none))' \
		-E 'VBOX_CAB_COMPRESSION_LEVEL=$(if-expr $(lang) == "en_US",$(VBOX_CAB_COMPRESSION_LEVEL),none)' \
		-E 'VBOX_CAB_COMPRESSION_LEVEL_COMMON=$(if-expr $(lang) == "en_US" && $(KBUILD_TARGET_ARCH) == "amd64",$(VBOX_CAB_COMPRESSION_LEVEL),none)' \
		-E 'VBOX_GUI_USE_QGL=$(if $(VBOX_GUI_USE_QGL),yes,no)' \
		-E 'VBOX_MIDL_PROXY_CLSID=$(VBOX_MIDL_PROXY_CLSID)' \
		$(if-expr defined(VBOX_WITH_MSM_INSTALL), \
			$(foreach module,$(VBOX_INSTALLER_MERGE_MODULES), \
				-E 'VBOX_WIN_INST_MERGE_$(toupper $(module))=$(subst /,\,$(VBOX_WIN_INST_OUT_DIR)/VBoxMerge$(module)_$(lang)_$(KBUILD_TARGET_ARCH).msm')),) \
		-E 'VBOX_WINDOWS_ICON_FILE=$(subst /,\,$(VBOX_WINDOWS_ICON_FILE))' \
		-E 'VBOX_QT_INFIX=$(VBOX_QT_INFIX)' \
		-E 'VBOX_WITH_32_ON_64_MAIN_API=$(if $(VBOX_WITH_32_ON_64_MAIN_API),yes,no)' \
		-E 'VBOX_WITH_ADDITIONS_PACKING=$(if $(VBOX_WITH_ADDITIONS_PACKING),yes,no)' \
		-E 'VBOX_WITH_COMBINED_PACKAGE=$(if-expr defined(VBOX_WITH_COMBINED_PACKAGE),yes,no)' \
		-E 'VBOX_WITH_CRT_PACKING=$(if-expr defined(VBOX_WITH_CRT_PACKING),yes,no)' \
		-E 'VBOX_WITH_DEBUGGER_GUI=$(if-expr defined(VBOX_WITH_DEBUGGER_GUI) && defined(VBOX_WITH_QTGUI),yes,no)' \
		-E 'VBOX_WITH_DOCS_PACKING=$(if $(VBOX_WITH_DOCS_PACKING),yes,no)' \
		-E 'VBOX_WITH_DRAG_AND_DROP=$(if $(VBOX_WITH_DRAG_AND_DROP),yes,no)' \
		-E 'VBOX_WITH_DTRACE=$(if $(VBOX_WITH_DTRACE),yes,no)' \
		-E 'VBOX_WITH_HOST_SHIPPING_AUDIO_TEST=$(if $(VBOX_WITH_HOST_SHIPPING_AUDIO_TEST),yes,no)' \
		-E 'VBOX_WITH_EFIFW_PACKING=$(if $(VBOX_WITH_EFIFW_PACKING),yes,no)' \
		-E 'VBOX_WITH_EXTPACK=$(if $(VBOX_WITH_EXTPACK),yes,no)' \
		-E 'VBOX_WITH_GUEST_CONTROL=$(if $(VBOX_WITH_GUEST_CONTROL),yes,no)' \
		-E 'VBOX_WITH_GUEST_PROPS=$(if $(VBOX_WITH_GUEST_PROPS),yes,no)' \
		-E 'VBOX_WITH_HARDENING=$(if $(VBOX_WITH_HARDENING),yes,no)' \
		-E 'VBOX_WITH_HEADLESS=$(if $(VBOX_WITH_HEADLESS),yes,no)' \
		-E 'VBOX_WITH_FE_BALLOONCTRL=$(if $(VBOX_WITH_FE_BALLOONCTRL),yes,no)' \
		-E 'VBOX_WITH_FE_AUTOSTART=$(if $(VBOX_WITH_FE_AUTOSTART),yes,no)' \
		-E 'VBOX_WITH_FE_BUGREPORT=$(if $(VBOX_WITH_FE_BUGREPORT),yes,no)' \
		-E 'VBOX_WITH_LIBSSH=$(if $(VBOX_WITH_LIBSSH),yes,no)' \
		-E 'VBOX_WITH_LICENSE_DISPLAY=$(if $(VBOX_WITH_LICENSE_DISPLAY),yes,no)' \
		-E 'VBOX_WITH_MIDL_PROXY_STUB=$(if $(VBOX_WITH_MIDL_PROXY_STUB),yes,no)' \
		-E 'VBOX_WITH_MSM_INSTALL=$(if-expr defined(VBOX_WITH_MSM_INSTALL),yes,no)' \
		-E 'VBOX_WITH_NETADP=$(if $(VBOX_WITH_NETADP),yes,no)' \
		-E 'VBOX_WITH_NETFLT=$(if $(VBOX_WITH_NETFLT),yes,no)' \
		-E 'VBOX_WITH_PYTHON=$(if $(VBOX_WITH_PYTHON),yes,no)' \
		-E 'VBOX_WITH_QTGUI=$(if $(VBOX_WITH_QTGUI),yes,no)' \
		-E 'VBOX_WITH_RAW_MODE=$(if $(VBOX_WITH_RAW_MODE),yes,no)' \
		-E 'VBOX_WITH_SERIALNUMBER_INSTALL=$(if $(VBOX_WITH_SERIALNUMBER_INSTALL),yes,no)' \
		-E 'VBOX_WITH_VIDEOHWACCEL=$(if $(VBOX_WITH_VIDEOHWACCEL),yes,no)' \
		-E 'VBOX_WITH_VRDP=$(if-expr defined(VBOX_WITH_VRDP) && !defined(VBOX_WITH_EXTPACK_PUEL),yes,no)' \
		-E 'VBOX_WITH_WEBSERVICES=$(if $(VBOX_WITH_WEBSERVICES),yes,no)' \
		-E 'VBOX_WITH_SDS=$(if $(VBOX_WITH_SDS),yes,no)' \
		-E 'VBOX_WITH_UNATTENDED=$(if $(VBOX_WITH_UNATTENDED),yes,no)' \
		-E 'VBOX_WITH_USB=$(if $(VBOX_WITH_USB),yes,no)' \
		-E 'VBOX_WITH_VBOX_IMG=$(if $(VBOX_WITH_VBOX_IMG)$(VBOX_WITH_TESTCASES),yes,no)' \
		-E 'VBOX_WITH_VBOXSDL=$(if $(VBOX_WITH_VBOXSDL),yes,no)' \
		-E 'VBOX_WITH_VMSVGA3D=$(if $(VBOX_WITH_VMSVGA3D),yes,no)' \
		-E 'VBOX_WITH_VIDEOHWACCEL=$(if $(VBOX_WITH_VIDEOHWACCEL),yes,no)' \
		-E 'KBUILD_TYPE=$(KBUILD_TYPE)' \
		-E 'KBUILD_TARGET_ARCH=$(KBUILD_TARGET_ARCH)' \
		-E 'VBOX_INSTALLER_QUICK=$(VBOX_INSTALLER_QUICK)' \
		-E 'VBOX_VCC_TOOL_STEM=$(VBOX_VCC_TOOL_STEM)' \
		-- \
		$(VBOX_PATH_WIX)/candle.exe $(filter-out $(VBOX_VERSION_STAMP),$$<) \
			-ext $(VBOX_PATH_WIX)/WixUIExtension.dll \
			-ext $(VBOX_PATH_WIX)/WixDifxAppExtension.dll \
			-ext $(VBOX_PATH_WIX)/WixUtilExtension.dll \
			-p$(VBOX_WIN_INST_OUT_DIR)/$(lang)/VirtualBox_$(lang).wix
	$(VBOX_PATH_WIX)/candle.exe $(VBOX_WIN_INST_OUT_DIR)/$(lang)/VirtualBox_$(lang).wix \
		-ext $(VBOX_PATH_WIX)/WixUIExtension.dll \
		-ext $(VBOX_PATH_WIX)/WixDifxAppExtension.dll \
		-ext $(VBOX_PATH_WIX)/WixUtilExtension.dll \
		-out $$@
 ifeq ($(lang),en_US)
  # Copy preprocessed wix and change source paths to be relative.  Stuff not in ../bin needs copying.
	$(SED)	-e 's,$(subst /,\\,$(PATH_OUT))\\bin,..\\bin,g' \
		-e 's,$(subst /,\\,$(PATH_OUT_BASE))\\win.amd64\\$(KBUILD_TYPE)\\bin,..\\..\\..\\win.amd64\\$(KBUILD_TYPE)\\bin,g' \
		-e 's,$(subst /,\\,$(PATH_OUT_BASE))\\win.x86\\$(KBUILD_TYPE)\\bin,..\\..\\..\\win.x86\\$(KBUILD_TYPE)\\bin,g' \
               \
		-e 's,$(subst /,\\,$(PATH_ROOT))\\doc\\,files-VirtualBox_$(lang)\\,g' \
		-e 's,$(subst /,\\,$(VBOX_PATH_WIN_INST_SRC))\\Binary\\,files-VirtualBox_$(lang)\\,g' \
		-e 's,$(subst /,\\,$(VBOX_WIN_INST_OUT_DIR))\\,,g' \
		-e 's,$(subst /,\\,$(dir $(VBOX_WINDOWS_ICON_FILE))),files-VirtualBox_$(lang)\\,g' \
		--output "$(VBOX_WIN_INST_REPACK_DIR)/VirtualBox_$(lang).wix" \
		"$(VBOX_WIN_INST_OUT_DIR)/$(lang)/VirtualBox_$(lang).wix"
	$(SED)	-n \
		-e '/<\?ln /d' \
		-e '/$(subst /,\\,$(PATH_ROOT))/p' \
		-e '/$(subst /,\\,$(PATH_ROOT))/q2' \
		"$(VBOX_WIN_INST_REPACK_DIR)/VirtualBox_$(lang).wix"
	$(SED)	-n \
		-e '/<\?ln /d' \
		-e 's/\\/\//g' \
		-e 's,^.*"\($(PATH_ROOT)/doc/[^"]*\)".*$$(DOLLAR),\1,p' \
		-e 's,^.*"\($(VBOX_PATH_WIN_INST_SRC)/Binary/[^"]*\)".*$$(DOLLAR),\1,p' \
		-e 's,^.*"\($(dir $(VBOX_WINDOWS_ICON_FILE))[^"]*\)".*$$(DOLLAR),\1,p' \
		--output "$(VBOX_WIN_INST_REPACK_DIR)/VirtualBox_$(lang).files" \
		"$(VBOX_WIN_INST_OUT_DIR)/$(lang)/VirtualBox_$(lang).wix"
	set -xe && for file in  `$(CAT_EXT) "$(VBOX_WIN_INST_REPACK_DIR)/VirtualBox_$(lang).files"`; \
		do $(CP_EXT) -f -- "$$(DOLLAR){file}" "$(VBOX_WIN_INST_REPACK_DIR)/files-VirtualBox_$(lang)/"; done
  # Create repack script for this step.
	$(APPEND) -tn "$(VBOX_WIN_INST_REPACK_DIR)/1-compile-VirtualBox_$(lang).cmd" \
       	'if ".%KBUILD_DEVTOOLS%" == "." (echo KBUILD_DEVTOOLS is not set & exit /b1)' \
		$(subst $(KBUILD_DEVTOOLS),%KBUILD_DEVTOOLS%,\
		'$(VBOX_PATH_WIX)/candle.exe VirtualBox_$(lang).wix ^' \
		'  -ext $(VBOX_PATH_WIX)/WixUIExtension.dll ^' \
		'  -ext $(VBOX_PATH_WIX)/WixDifxAppExtension.dll ^' \
		'  -ext $(VBOX_PATH_WIX)/WixUtilExtension.dll ^' \
		'  -out $$(@F) || exit /b1' \
               ) \
               '@echo Created: $$(@F)'
 endif
 # Generate wxi dependencies based on the sourceLineNumber references in the output.  Add repack file list for cleanup.
	$(QUIET)$(APPEND) -t '$$@.dep' '$$@: \'
	$(QUIET)$(VBOX_XSLTPROC) $(VBOX_PATH_WIN_INST_SRC)/dep.xsl "$$@" >> "$$@.dep"
	$(QUIET)$(VBOX_XSLTPROC) $(VBOX_PATH_WIN_INST_SRC)/dep2.xsl "$$@" | sort  | $(SED) '$!N; /^\(.*\)\n\1$$$$/!P; D' >> "$$@.dep"
	$(QUIET)$(APPEND) -n '$$@.dep' '' ''
 ifeq ($(lang),en_US)
	$(QUIET)$(APPEND) -n '$$@.dep' 'define VBOX_REPACK_FILES_VirtualBox_$(lang)'
	$(QUIET)$(CAT_EXT) "$(VBOX_WIN_INST_REPACK_DIR)/VirtualBox_$(lang).files" >> '$$@.dep'
	$(QUIET)$(APPEND) -n '$$@.dep' '' 'endef'
 endif

 $(eval OTHER_CLEAN += $(VBOX_REPACK_FILES_VirtualBox_$(lang)))
endef

$(foreach lang,$(VBOX_INSTALLER_LANGUAGES), \
	$(eval $(def_vbox_compile_wixobj)))

#
# MSM (merge module) compile.
#
define def_vbox_compile_msm
 includedep $(VBOX_WIN_INST_OUT_DIR)/VBoxMerge$(module)_$(lang).wixobj.dep
 $(VBOX_WIN_INST_OUT_DIR)/VBoxMerge$(module)_$(lang).wixobj \
 + $(VBOX_WIN_INST_OUT_DIR)/VBoxMerge$(module)_$(lang).wix \
 $(if-expr "$(lang)" != "en_US",, \
 	+ $(VBOX_WIN_INST_REPACK_DIR)/VBoxMerge$(module)_$(lang).wix): \
 		$(PATH_SUB_CURRENT)/VBoxMerge$(module).wxs \
 		$(PATH_SUB_CURRENT)/VBoxMerge$(module).wxi \
 		$(PATH_SUB_CURRENT)/VBoxMerge$(module)CA.wxi \
 		$(PATH_SUB_CURRENT)/VBoxMerge$(module)Seq.wxi \
 		$(PATH_SUB_CURRENT)/UserInterface.wxi \
 		$(VBOX_WIN_INST_OUT_DIR)/Shortcuts_StartMenu.wxi \
 		$(VBOX_WIN_INST_OUT_DIR)/VirtualBox_TypeLib.wxi \
 		$(if $(VBOX_WITH_32_ON_64_MAIN_API),$(VBOX_WIN_INST_OUT_DIR)/VirtualBox_TypeLib_x86.wxi,) \
 		$(VBOX_WIN_INST_OUT_DIR)/VBoxKey.wxi \
 		$(if $(VBOX_WITH_CRT_PACKING),$(VBOX_WIN_INST_OUT_DIR)/VBoxCrtDlls.wxi,) \
 		$(if $(VBOX_WITH_CRT_PACKING),$(VBOX_WIN_INST_OUT_DIR)/VBoxCrtDlls32.wxi,) \
 		$(VBOX_WIN_INST_OUT_DIR)/VBoxUnattendedTemplateComponent.wxi \
 		$(if $(VBOX_WITH_QTGUI),$(VBOX_WIN_INST_OUT_DIR)/VBoxGuiNLS.wxi) \
 		$(VBOX_MSI_DEPENDENCIES) \
 		$(VBOX_VERSION_STAMP) \
 		| $$$$(dir $$$$@) $(VBOX_WIN_INST_REPACK_DIR)/
	$(QUIET)$(RM) -f -- "$$@" "$(VBOX_WIN_INST_OUT_DIR)/VBoxMerge$(module)_$(lang).wix" "$(VBOX_WIN_INST_REPACK_DIR)/VBoxMerge$(module)_$(lang).wix"
	$(REDIRECT) \
		-E 'PATH_OUT=$(subst /,\,$(PATH_OUT))' \
		-E 'PATH_TARGET=$(subst /,\,$(VBOX_WIN_INST_OUT_DIR))' \
		-E 'PATH_ROOT=$(subst /,\,$(PATH_ROOT))' \
		-E 'PATH_MULTIARCH_GUEST_ADDITIONS_ISO=$(subst /,\,$(PATH_MULTIARCH_GUEST_ADDITIONS_ISO))' \
		-E 'VBOX_PATH_WIN_INST_SRC=$(subst /,\,$(VBOX_PATH_WIN_INST_SRC))' \
		-E 'VBOX_BRAND_WIN_INST_DLGJPG=$(subst /,\,$(VBOX_BRAND_WIN_INST_DLGJPG))' \
		-E 'VBOX_ADD_LANGUAGES=$(VBOX_INSTALLER_ADD_LANGUAGES)' \
		-E 'VBOX_BRAND_LICENSE_RTF=$(subst /,\,$(VBOX_BRAND_LICENSE_RTF))' \
		$(foreach lang,$(VBOX_INSTALLER_LANGUAGES), \
			-E 'VBOX_BRAND_$(lang)_LICENSE_RTF=$(subst /,\,$(VBOX_BRAND_$(subst en_US_,,$(lang)_)LICENSE_RTF))') \
		-E 'VBOX_BUILD_NR_FOR_INST=$(VBOX_VERSION_BUILD)' \
		-E 'VBOX_VENDOR=$(VBOX_VENDOR)' \
		-E 'VBOX_VENDOR_SHORT=$(VBOX_VENDOR_SHORT)' \
		-E 'VBOX_PRODUCT=$(VBOX_PRODUCT)' \
		-E 'VBOX_C_YEAR=$(VBOX_C_YEAR)' \
		-E 'VBOX_VERSION_STRING=$(VBOX_VERSION_STRING)' \
		-E 'VBOX_VERSION_STRING_RAW=$(VBOX_VERSION_STRING_RAW)' \
		-E 'VBOX_VERSION_MAJOR_INST=$(VBOX_VERSION_MAJOR)' \
		-E 'VBOX_VERSION_MINOR_INST=$(VBOX_VERSION_MINOR)' \
		-E 'VBOX_SIGNING_MODE=$(strip $(if $(VBOX_SIGNING_MODE),$(VBOX_SIGNING_MODE),none))' \
		-E 'VBOX_CAB_COMPRESSION_LEVEL=$(VBOX_CAB_COMPRESSION_LEVEL)' \
		-E 'VBOX_CAB_COMPRESSION_LEVEL_COMMON=$(VBOX_CAB_COMPRESSION_LEVEL)' \
		-E 'VBOX_GUI_USE_QGL=$(if $(VBOX_GUI_USE_QGL),yes,no)' \
		-E 'VBOX_MIDL_PROXY_CLSID=$(VBOX_MIDL_PROXY_CLSID)' \
		-E 'VBOX_WINDOWS_ICON_FILE=$(subst /,\,$(VBOX_WINDOWS_ICON_FILE))' \
		-E 'VBOX_QT_INFIX=$(VBOX_QT_INFIX)' \
		-E 'VBOX_WITH_32_ON_64_MAIN_API=$(if $(VBOX_WITH_32_ON_64_MAIN_API),yes,no)' \
		-E 'VBOX_WITH_ADDITIONS_PACKING=$(if $(VBOX_WITH_ADDITIONS_PACKING),yes,no)' \
		-E 'VBOX_WITH_COMBINED_PACKAGE=$(if-expr defined(VBOX_WITH_COMBINED_PACKAGE),yes,no)' \
		-E 'VBOX_WITH_CRT_PACKING=$(if-expr defined(VBOX_WITH_CRT_PACKING),yes,no)' \
		-E 'VBOX_WITH_DEBUGGER_GUI=$(if-expr defined(VBOX_WITH_DEBUGGER_GUI) && defined(VBOX_WITH_QTGUI),yes,no)' \
		-E 'VBOX_WITH_DOCS_PACKING=$(if $(VBOX_WITH_DOCS_PACKING),yes,no)' \
		-E 'VBOX_WITH_DRAG_AND_DROP=$(if $(VBOX_WITH_DRAG_AND_DROP),yes,no)' \
		-E 'VBOX_WITH_DTRACE=$(if $(VBOX_WITH_DTRACE),yes,no)' \
		-E 'VBOX_WITH_HOST_SHIPPING_AUDIO_TEST=$(if $(VBOX_WITH_HOST_SHIPPING_AUDIO_TEST),yes,no)' \
		-E 'VBOX_WITH_EFIFW_PACKING=$(if $(VBOX_WITH_EFIFW_PACKING),yes,no)' \
		-E 'VBOX_WITH_EXTPACK=$(if $(VBOX_WITH_EXTPACK),yes,no)' \
		-E 'VBOX_WITH_GUEST_CONTROL=$(if $(VBOX_WITH_GUEST_CONTROL),yes,no)' \
		-E 'VBOX_WITH_GUEST_PROPS=$(if $(VBOX_WITH_GUEST_PROPS),yes,no)' \
		-E 'VBOX_WITH_HARDENING=$(if $(VBOX_WITH_HARDENING),yes,no)' \
		-E 'VBOX_WITH_HEADLESS=$(if $(VBOX_WITH_HEADLESS),yes,no)' \
		-E 'VBOX_WITH_FE_BALLOONCTRL=$(if $(VBOX_WITH_FE_BALLOONCTRL),yes,no)' \
		-E 'VBOX_WITH_FE_AUTOSTART=$(if $(VBOX_WITH_FE_AUTOSTART),yes,no)' \
		-E 'VBOX_WITH_FE_BUGREPORT=$(if $(VBOX_WITH_FE_BUGREPORT),yes,no)' \
		-E 'VBOX_WITH_LIBSSH=$(if $(VBOX_WITH_LIBSSH),yes,no)' \
		-E 'VBOX_WITH_LICENSE_DISPLAY=$(if $(VBOX_WITH_LICENSE_DISPLAY),yes,no)' \
		-E 'VBOX_WITH_MIDL_PROXY_STUB=$(if $(VBOX_WITH_MIDL_PROXY_STUB),yes,no)' \
		-E 'VBOX_WITH_MSM_INSTALL=$(if-expr defined(VBOX_WITH_MSM_INSTALL),yes,no)' \
		-E 'VBOX_WITH_NETADP=$(if $(VBOX_WITH_NETADP),yes,no)' \
		-E 'VBOX_WITH_NETFLT=$(if $(VBOX_WITH_NETFLT),yes,no)' \
		-E 'VBOX_WITH_PYTHON=$(if $(VBOX_WITH_PYTHON),yes,no)' \
		-E 'VBOX_WITH_QTGUI=$(if $(VBOX_WITH_QTGUI),yes,no)' \
		-E 'VBOX_WITH_RAW_MODE=$(if $(VBOX_WITH_RAW_MODE),yes,no)' \
		-E 'VBOX_WITH_SERIALNUMBER_INSTALL=$(if $(VBOX_WITH_SERIALNUMBER_INSTALL),yes,no)' \
		-E 'VBOX_WITH_VIDEOHWACCEL=$(if $(VBOX_WITH_VIDEOHWACCEL),yes,no)' \
		-E 'VBOX_WITH_VRDP=$(if-expr defined(VBOX_WITH_VRDP) && !defined(VBOX_WITH_EXTPACK_PUEL),yes,no)' \
		-E 'VBOX_WITH_WEBSERVICES=$(if $(VBOX_WITH_WEBSERVICES),yes,no)' \
		-E 'VBOX_WITH_SDS=$(if $(VBOX_WITH_SDS),yes,no)' \
		-E 'VBOX_WITH_UNATTENDED=$(if $(VBOX_WITH_UNATTENDED),yes,no)' \
		-E 'VBOX_WITH_VBOX_IMG=$(if $(VBOX_WITH_VBOX_IMG),yes,no)' \
		-E 'VBOX_WITH_VBOXSDL=$(if $(VBOX_WITH_VBOXSDL),yes,no)' \
		-E 'VBOX_WITH_VMSVGA3D=$(if $(VBOX_WITH_VMSVGA3D),yes,no)' \
		-E 'VBOX_WITH_VIDEOHWACCEL=$(if $(VBOX_WITH_VIDEOHWACCEL),yes,no)' \
		-E 'KBUILD_TYPE=$(KBUILD_TYPE)' \
		-E 'KBUILD_TARGET_ARCH=$(KBUILD_TARGET_ARCH)' \
		-E 'VBOX_INSTALLER_QUICK=$(VBOX_INSTALLER_QUICK)' \
		-E 'VBOX_VCC_TOOL_STEM=$(VBOX_VCC_TOOL_STEM)' \
		-- \
		$(VBOX_PATH_WIX)/candle.exe $(filter-out $(VBOX_VERSION_STAMP),$$<) \
			-ext $(VBOX_PATH_WIX)/WixUIExtension.dll \
			-ext $(VBOX_PATH_WIX)/WixDifxAppExtension.dll \
			-ext $(VBOX_PATH_WIX)/WixUtilExtension.dll \
			-p$(VBOX_WIN_INST_OUT_DIR)/VBoxMerge$(module)_$(lang).wix
	$(VBOX_PATH_WIX)/candle.exe $(VBOX_WIN_INST_OUT_DIR)/VBoxMerge$(module)_$(lang).wix \
		-ext $(VBOX_PATH_WIX)/WixUIExtension.dll \
		-ext $(VBOX_PATH_WIX)/WixDifxAppExtension.dll \
		-ext $(VBOX_PATH_WIX)/WixUtilExtension.dll \
		-out $$@
 ifeq ($(lang),en_US)
  # Copy preprocessed wix and change source paths to be relative.  Stuff not in ../bin needs copying.
	$(SED)	-e 's,$(subst /,\\,$(PATH_OUT))\\bin,..\\bin,g' \
		-e 's,$(subst /,\\,$(PATH_OUT_BASE))\\win.amd64\\$(KBUILD_TYPE)\\bin,..\\..\\..\\win.amd64\\$(KBUILD_TYPE)\\bin,g' \
		-e 's,$(subst /,\\,$(PATH_OUT_BASE))\\win.x86\\$(KBUILD_TYPE)\\bin,..\\..\\..\\win.x86\\$(KBUILD_TYPE)\\bin,g' \
		-e 's,$(subst /,\\,$(PATH_ROOT))\\doc\\,files-VBoxMerge$(module)_$(lang)\\,g' \
		-e 's,$(subst /,\\,$(VBOX_PATH_WIN_INST_SRC))\\Binary\\,files-VBoxMerge$(module)_$(lang)\\,g' \
		-e 's,$(subst /,\\,$(dir $(VBOX_WINDOWS_ICON_FILE))),files-VBoxMerge$(module)_$(lang)\\,g' \
		-e 's,$(subst /,\\,$(VBOX_PATH_WIN_INST_SRC))\\,,g' \
		--output "$(VBOX_WIN_INST_REPACK_DIR)/VBoxMerge$(module)_$(lang).wix" \
		"$(VBOX_WIN_INST_OUT_DIR)/VBoxMerge$(module)_$(lang).wix"
	$(SED)	-n \
		-e '/<\?ln /d' \
		-e '/$(subst /,\\,$(PATH_ROOT))/p' \
		-e '/$(subst /,\\,$(PATH_ROOT))/q2' \
		"$(VBOX_WIN_INST_REPACK_DIR)/VBoxMerge$(module)_$(lang).wix"
	$(SED)	-n \
		-e '/<\?ln /d' \
		-e 's/\\/\//g' \
		-e 's,^.*"\($(PATH_ROOT)/doc/[^"]*\)".*$$(DOLLAR),\1,p' \
		-e 's,^.*"\($(VBOX_PATH_WIN_INST_SRC)/Binary/[^"]*\)".*$$(DOLLAR),\1,p' \
		-e 's,^.*"\($(dir $(VBOX_WINDOWS_ICON_FILE))[^"]*\)".*$$(DOLLAR),\1,p' \
		--output "$(VBOX_WIN_INST_REPACK_DIR)/VBoxMerge$(module)_$(lang).files" \
		"$(VBOX_WIN_INST_OUT_DIR)/VBoxMerge$(module)_$(lang).wix"
	$(MKDIR) -p -- "$(VBOX_WIN_INST_REPACK_DIR)/files-VBoxMerge$(module)_$(lang)/"
	set -xe && for file in  `$(CAT_EXT) "$(VBOX_WIN_INST_REPACK_DIR)/VBoxMerge$(module)_$(lang).files"`; \
		do $(CP_EXT) -f -- "$$(DOLLAR){file}" "$(VBOX_WIN_INST_REPACK_DIR)/files-VBoxMerge$(module)_$(lang)/"; done
  # Create repack script for this step.
	$(APPEND) -tn "$(VBOX_WIN_INST_REPACK_DIR)/1-compile-VBoxMerge$(module)_$(lang).cmd" \
       	'if ".%KBUILD_DEVTOOLS%" == "." (echo KBUILD_DEVTOOLS is not set & exit /b1)' \
		$(subst $(KBUILD_DEVTOOLS),%KBUILD_DEVTOOLS%,\
		'$(VBOX_PATH_WIX)/candle.exe VBoxMerge$(module)_$(lang).wix ^' \
		'  -ext $(VBOX_PATH_WIX)/WixUIExtension.dll ^'\
		'  -ext $(VBOX_PATH_WIX)/WixDifxAppExtension.dll ^' \
		'  -ext $(VBOX_PATH_WIX)/WixUtilExtension.dll ^' \
		'  -out $$(@F) || exit /b1' \
               ) \
               '@echo Created: $$(@F)'
 endif
 # Generate wxi dependencies based on the sourceLineNumber references in the output.  Add repack file list for cleanup.
	$(QUIET)$(APPEND) -t '$$@.dep' '$$@: \'
	$(QUIET)$(VBOX_XSLTPROC) $(VBOX_PATH_WIN_INST_SRC)/dep.xsl "$$@" >> "$$@.dep"
	$(QUIET)$(VBOX_XSLTPROC) $(VBOX_PATH_WIN_INST_SRC)/dep2.xsl "$$@" | sort  | $(SED) '$!N; /^\(.*\)\n\1$$$$/!P; D' >> "$$@.dep"
	$(QUIET)$(APPEND) -n '$$@.dep' '' ''
 ifeq ($(lang),en_US)
	$(QUIET)$(APPEND) -n '$$@.dep' 'define VBOX_REPACK_FILES_VBoxMerge$(module)_$(lang)'
	$(QUIET)$(CAT_EXT) "$(VBOX_WIN_INST_REPACK_DIR)/VBoxMerge$(module)_$(lang).files" >> '$$@.dep'
	$(QUIET)$(APPEND) -n '$$@.dep' '' 'endef'
 endif

 $(eval OTHER_CLEAN += $(VBOX_REPACK_FILES_VBoxMerge$(module)_$(lang)))
endef

$(foreach module,$(VBOX_INSTALLER_MERGE_MODULES), \
	$(foreach lang,$(VBOX_INSTALLER_MERGE_LANGUAGES), \
		$(eval $(def_vbox_compile_msm))))

#
# VirtualBox Type Library definition.
#
$(VBOX_WIN_INST_OUT_DIR)/VirtualBox_TypeLib.wxi: \
		$(PATH_SUB_CURRENT)/$(if-expr defined(VBOX_WITH_MIDL_PROXY_STUB),VirtualBox_TypeLibWithInterfaces.xsl,VirtualBox_TypeLib.xsl) \
		$(VBOX_XIDL_FILE) \
		$(MAKEFILE) \
		| $$(dir $$@)
	$(VBOX_XSLTPROC) \
		$(if-expr defined(VBOX_WITH_MIDL_PROXY_STUB),--stringparam "a_sProxyStubClsid" "$(VBOX_MIDL_PROXY_CLSID)",) \
		$(if-expr defined(VBOX_WITH_SDS),--stringparam "a_sWithSDS" "yes",) \
		-o $@ $< $(VBOX_XIDL_FILE)

$(VBOX_WIN_INST_OUT_DIR)/VirtualBox_TypeLib_x86.wxi: \
		$(PATH_SUB_CURRENT)/$(if-expr defined(VBOX_WITH_MIDL_PROXY_STUB),VirtualBox_TypeLibWithInterfaces.xsl,VirtualBox_TypeLib.xsl) \
		$(VBOX_XIDL_FILE) \
		| $$(dir $$@)
	$(VBOX_XSLTPROC) --stringparam "a_sTarget" "VBoxClient-x86" \
		$(if-expr defined(VBOX_WITH_MIDL_PROXY_STUB),--stringparam "a_sProxyStubClsid" "$(VBOX_MIDL_PROXY_CLSID)",) \
		$(if-expr defined(VBOX_WITH_SDS),--stringparam "a_sWithSDS" "yes",) \
 		-o $@ $< $(VBOX_XIDL_FILE)

#
# Construct the list of GUI translations.
# ('-t' -- truncate file; '-n' -- new line between arguments)
#
include $(PATH_ROOT)/src/VBox/Frontends/VirtualBox/nls/ApprovedLanguages.kmk
$(call KB_FN_AUTO_CMD_DEPS,$(VBOX_WIN_INST_OUT_DIR)/VBoxGuiNLS.wxi)
$(VBOX_WIN_INST_OUT_DIR)/VBoxGuiNLS.wxi: $(PATH_ROOT)/src/VBox/Frontends/VirtualBox/nls/ApprovedLanguages.kmk | $$(dir $$@)
	$(APPEND) -t $@ '<?xml version="1.0" ?>'
	$(APPEND) $@ '<Include>'
	$(APPEND) -n $@ $(foreach lang,$(VBOX_APPROVED_GUI_LANGUAGES), \
	             '  <File Id="nlsqt${lang}"  Name="qt_${lang}.qm"         DiskId="$(VBOX_INSTALLER_COMMON_DISKID)" Vital="yes" Source="$$(env.PATH_OUT)\bin\nls\qt_${lang}.qm"         />' \
	             '  <File Id="nlsgui${lang}" Name="VirtualBox_${lang}.qm" DiskId="$(VBOX_INSTALLER_COMMON_DISKID)" Vital="yes" Source="$$(env.PATH_OUT)\bin\nls\VirtualBox_${lang}.qm" />')
	$(APPEND) $@ '</Include>'

#
# Edit the version stored in the registry.
#
$(call KB_FN_AUTO_CMD_DEPS,$(VBOX_WIN_INST_OUT_DIR)/VBoxKey.wxi)
$(VBOX_WIN_INST_OUT_DIR)/VBoxKey.wxi: $(PATH_SUB_CURRENT)/VBoxKey.wxi $(VBOX_VERSION_STAMP) | $$(dir $$@)
	$(SED)	-e 's/%VER%/$(VBOX_VERSION_STRING_RAW)/' \
		-e 's/%VER_EXT%/$(VBOX_VERSION_STRING)/' \
		--output $@ $<

#
# Generate the list of CRT DLLs.
#
ifndef TOOL_$(VBOX_VCC_TOOL)
 include $(KBUILD_PATH)/tools/$(VBOX_VCC_TOOL).kmk
endif
$(call KB_FN_AUTO_CMD_DEPS,$(VBOX_WIN_INST_OUT_DIR)/VBoxCrtDlls.wxi)
$(VBOX_WIN_INST_OUT_DIR)/VBoxCrtDlls.wxi: | $$(dir $$@)
	$(APPEND) -t -n $@ \
		'<?xml version="1.0" ?>' \
		'<Include>' \
		$(foreach dll \
		,$(if-expr "$(VBOX_VCC_TOOL_STEM)"=="VCC100",msvcr100.dll msvcp100.dll \
		  ,$(if-expr "$(VBOX_VCC_TOOL_STEM)"=="VCC110",msvcr110.dll msvcp110.dll \
                   ,$(TOOL_$(VBOX_VCC_TOOL)_REDIST_CRT_DLLS) $(TOOL_$(VBOX_VCC_TOOL)_REDIST_CPP_DLLS))) \
        	 $(if-expr "$(KBUILD_TYPE)"=="asan",clang_rt.asan_dynamic-x86_64.dll,) \
               ,'  <File Id="file_$(translate $(dll),-,_)" Name="$(dll)" Source="$$(env.PATH_OUT)\bin\$(dll)" />') \
		'</Include>'

#
# Generate the list of 32-bit CRT DLLs.
#
ifndef TOOL_$(VBOX_VCC_TOOL_STEM)X86
 include $(KBUILD_PATH)/tools/$(VBOX_VCC_TOOL_STEM)X86.kmk
endif
$(call KB_FN_AUTO_CMD_DEPS,$(VBOX_WIN_INST_OUT_DIR)/VBoxCrtDlls32.wxi)
$(VBOX_WIN_INST_OUT_DIR)/VBoxCrtDlls32.wxi: | $$(dir $$@)
	$(APPEND) -t -n $@ \
		'<?xml version="1.0" ?>' \
		'<Include>' \
		$(foreach dll \
		,$(if-expr "$(VBOX_VCC_TOOL_STEM)"=="VCC100",msvcr100.dll msvcp100.dll \
		  ,$(if-expr "$(VBOX_VCC_TOOL_STEM)"=="VCC110",msvcr110.dll msvcp110.dll \
                   ,$(TOOL_$(VBOX_VCC_TOOL_STEM)X86_REDIST_CRT_DLLS) $(TOOL_$(VBOX_VCC_TOOL_STEM)X86_REDIST_CPP_DLLS))) \
        	 $(if-expr "$(KBUILD_TYPE)"=="asan",clang_rt.asan_dynamic-i386.dll,) \
               ,'  <File Id="file_$(translate $(dll),-,_)_x86" Name="$(dll)" Source="$$(env.PATH_OUT)\bin\x86\$(dll)" DiskId="$$(var.Property_DiskIdCommon)" />') \
		'</Include>'
#
# Generate the list of unattended template script files.
#
$(call KB_FN_AUTO_CMD_DEPS,$(VBOX_WIN_INST_OUT_DIR)/VBoxUnattendedTemplateComponent.wxi)
$(VBOX_WIN_INST_OUT_DIR)/VBoxUnattendedTemplateComponent.wxi: | $$(dir $$@)
	$(APPEND) -t -n $@ \
		'<?xml version="1.0" ?>' \
		'<Include>'
ifdef VBOX_UNATTENDED_TEMPLATES
	$(APPEND) -n $@ \
		'  <Directory Id="dir_VBoxUnattendedTemplates" Name="UnattendedTemplates">' \
		'    <Component Id="cp_UnattendedTemplates" Guid="0571550d-aaa5-4723-c17b-5ddcc29f5686" Win64="$$(var.Property_Win64)">' \
		$(foreach file,$(VBOX_UNATTENDED_TEMPLATES), \
		'      <File Id="$(file)" Name="$(file)" Source="$$(env.PATH_OUT)\bin\UnattendedTemplates\$(file)" />') \
		'    </Component>' \
		'  </Directory>'
endif
	$(APPEND) $@ '</Include>'


#
# Build the multi-language version of the .MSI installer (final installer).
#
# This is done by creating binary .MST diffs of all the language-specific installers
# against the en_US one, and then merging the diffs into the en_US one using tools
# from the MS Installer SDK.
#
define def_vbox_create_mst
 $(VBOX_WIN_INST_OUT_DIR)/$(lang)/$(lang).mst \
 + $(VBOX_WIN_INST_REPACK_DIR)/$(lang).mst: \
 		$(VBOX_WIN_INST_OUT_DIR)/en_US/$(PACKAGE_NAME_LANG)_en_US.msi \
 		$(VBOX_WIN_INST_OUT_DIR)/$(lang)/VirtualBox_$(lang).wixobj \
 		$(VBOX_WIN_INST_OUT_DIR)/NLS/Language_$(lang).wxl \
 		$(VBOX_WIN_INST_OUT_DIR)/NLS/License_$(lang).wxl \
 		$(PATH_STAGE_BIN)/VBoxInstallHelper.dll \
 		$(VBOX_SVN_REV_KMK) \
 		$(VBOX_WIN_INST_MAKEFILE_DEP) \
 		$(if-expr defined(VBOX_WITH_MSI_HACK),$(MsiHack_0_OUTDIR)/MsiHack.dll,) \
 		$(if-expr defined(VBOX_WITH_MSI_HACK),$(MsiHack_0_OUTDIR)/MsiHackExtension.dll,) \
 		| $$$$(dir $$$$@) $(VBOX_WIN_INST_REPACK_DIR)/
	$(call MSG_L1,Creating language diff for $(lang))
	kmk_time $$(REDIRECT_EXT) -E WIX_TEMP='$$(subst /,\,$$(@D))' -- $(VBOX_PATH_WIX)/light.exe -v -nologo \
		-loc $(VBOX_WIN_INST_OUT_DIR)/NLS/Language_$(lang).wxl \
		-loc $(VBOX_WIN_INST_OUT_DIR)/NLS/License_$(lang).wxl \
		-ext $(VBOX_PATH_WIX)/WixUIExtension.dll \
		-ext $(VBOX_PATH_WIX)/WixDifxAppExtension.dll \
		-ext $(VBOX_PATH_WIX)/WixUtilExtension.dll \
               $(if-expr defined(VBOX_WITH_MSI_HACK),-ext $(MsiHack_0_OUTDIR)/MsiHackExtension.dll,) \
		$(VBOX_MSI_ICE_IGNORE) \
		-out $$(@D)/$(PACKAGE_NAME_LANG)_$(lang).msi \
		$$(@D)/VirtualBox_$(lang).wixobj \
		$(VBOX_PATH_WIX)/difxapp_$(if-expr "$(KBUILD_TARGET_ARCH)" == "x86",x86,x64).wixlib
	$(REDIRECT) -C $$(@D) -- $$(VBOX_PATH_MSITRAN) -g $$< $(PACKAGE_NAME_LANG)_$(lang).msi $(lang).mst
	$(CP) -f -- "$(VBOX_WIN_INST_OUT_DIR)/$(lang)/$(lang).mst" "$(VBOX_WIN_INST_REPACK_DIR)/$(lang).mst"
	$(RM) -f -- $$(@D)/$(PACKAGE_NAME_LANG)_$(lang).msi \
		$$(@D)/$(PACKAGE_NAME_LANG)_$(lang).wixpdb \
		$$(@D)/common.cab

endef

$(foreach lang,$(filter-out en_US, $(VBOX_INSTALLER_LANGUAGES)), \
	$(eval local lang_id := $(VBOX_BRAND_$(lang)_LANG_ID)) \
	$(eval $(def_vbox_create_mst)))


# Create WISUMINFO argument.
VBOX_INS_PROD_ARCH.amd64 = x64
VBOX_INS_PROD_ARCH.x86   = Intel
VBOX_INS_PROD_ARCH := $(VBOX_INS_PROD_ARCH.$(KBUILD_TARGET_ARCH))
ifeq ($(VBOX_INS_PROD_ARCH),)
 $(error VBOX_INS_PROD_ARCH is empty!)
endif
VBOX_INS_PROD_LANG := 7="$(VBOX_INS_PROD_ARCH);1033
$(foreach lang, $(filter-out en_US,$(VBOX_INSTALLER_LANGUAGES))\
	, $(eval VBOX_INS_PROD_LANG := $(VBOX_INS_PROD_LANG)$(COMMA)$(VBOX_BRAND_$(lang)_LANG_ID)))
VBOX_INS_PROD_LANG := $(VBOX_INS_PROD_LANG)"

# The multilingual installer rule.
$(VBOX_WIN_INST_OUT_DIR)/$(PACKAGE_NAME_LANG).msi \
+ $(VBOX_WIN_INST_REPACK_DIR)/3-multilingual-$(PACKAGE_NAME_LANG).cmd: \
		$(VBOX_WIN_INST_OUT_DIR)/en_US/$(PACKAGE_NAME_LANG)_en_US.msi \
		$(foreach lang,$(filter-out en_US,$(VBOX_INSTALLER_LANGUAGES)),$(VBOX_WIN_INST_OUT_DIR)/$(lang)/$(lang).mst)
	$(call MSG_L1,Creating final multilingual MSI)
	$(QUIET)$(RM) -f -- \
		$(wildcard $(@D)/$(PACKAGE_BASE)-r*.msi $(VBOX_WIN_INST_REPACK_DIR)/3-multilingual-$(PACKAGE_BASE)-r*.cmd )
	$(CP) -f -- "$<" "$@"

	$(foreach lang,$(filter-out en_US,$(VBOX_INSTALLER_LANGUAGES)), \
		$(NLTAB)$(REDIRECT) -C $(@D)/$(lang) -- $(VBOX_PATH_MSIDB) -d $@ -r $(lang).mst \
		$(NLTAB)$(REDIRECT) -C $(@D)/$(lang) -- cscript.exe /nologo $(VBOX_PATH_WISUBSTG) $@ $(lang).mst $(VBOX_BRAND_$(lang)_LANG_ID) )

	$(REDIRECT) -C $(@D) -- cscript.exe /nologo $(VBOX_PATH_WISUBSTG) $(@F)
	$(REDIRECT) -C $(@D) -- cscript.exe /nologo $(VBOX_PATH_WISUMINFO) $@ $(VBOX_INS_PROD_LANG)
	$(call VBOX_SIGN_MSI_FN,$@,$(VBOX_PRODUCT) $(VBOX_VERSION_STRING)r$(VBOX_SVN_REV) ($(KBUILD_TARGET_ARCH)),,,disable-dual-signing)

# Create repack script for this step.
	$(APPEND) -nt "$(VBOX_WIN_INST_REPACK_DIR)/3-multilingual-$(PACKAGE_NAME_LANG).cmd" \
		'if ".%KBUILD_DEVTOOLS%" == "." (echo KBUILD_DEVTOOLS is not set & exit /b1)' \
		'if ".%KBUILD_BIN_PATH%" == "." (echo KBUILD_BIN_PATH is not set & exit /b1)' \
		'copy /y  "$(<F)" "$(@F)" || exit /b1' \
		$(subst $(KBUILD_BIN_PATH),%KBUILD_BIN_PATH%,$(subst $(KBUILD_DEVTOOLS),%KBUILD_DEVTOOLS%,\
		$(foreach lang,$(filter-out en_US,$(VBOX_INSTALLER_LANGUAGES)), \
			'$(VBOX_PATH_MSIDB) -d $(@F) -r $(lang).mst || exit /b1' \
			'cscript.exe /nologo $(VBOX_PATH_WISUBSTG) $(@F) $(lang).mst $(VBOX_BRAND_$(lang)_LANG_ID) || exit /b1') \
		'cscript.exe /nologo $(VBOX_PATH_WISUBSTG) $(@F) || exit /b1' \
		'cscript.exe /nologo $(VBOX_PATH_WISUMINFO) $(@F) $(VBOX_INS_PROD_LANG) || exit /b1' \
		'call sign-sha1.cmd $(@F) || exit /b1' \
		) ) \
        $(if-expr defined(VBOX_WITH_COMBINED_PACKAGE),'copy /y "$(@F)" "$(notdir $(PACKAGE_NAME_FINAL))" || exit /b1',) \
		'@echo Created multilanguage MSI: $(notdir $(PACKAGE_NAME_FINAL))'

# Copy multilingual installer to bin.
$(PACKAGE_NAME_FINAL): $(VBOX_WIN_INST_OUT_DIR)/$(PACKAGE_NAME_LANG).msi | $$(dir $$@)
	$(QUIET)$(RM) -f $(wildcard $(@D)/$(PACKAGE_BASE)-r*$(if-expr defined(VBOX_WITH_COMBINED_PACKAGE),_$(KBUILD_TARGET_ARCH),).msi)
	$(INSTALL_STAGING) -- $< $@


if defined(VBOX_WITH_COMBINED_PACKAGE) && "$(KBUILD_TARGET_ARCH)" == "x86"
 #
 # Make the multi-architecture installer by calling our stub builder
 # with both platform installers (x86 and amd64) + common cab. The common
 # cab only is needed when we don't use merge modules. We only
 # need to do this once; so do it on x86 only.
 #
 $(PATH_STAGE_BIN)/$(PACKAGE_NAME_MULTIARCH_FINAL) \
 + $(VBOX_WIN_INST_REPACK_DIR)/4-multiarch-$(PACKAGE_NAME_MULTIARCH_FINAL).cmd: \
 		$(PATH_MULTIARCH_TEMP)/$(PACKAGE_NAME_MULTIARCH.x86) \
 		$(PATH_MULTIARCH_TEMP)/$(PACKAGE_NAME_MULTIARCH.amd64) \
 		$(PATH_STAGE_BIN)/VBoxStub.exe \
 		$$(VBoxStubBld_1_TARGET)
	$(call MSG_L1,Building Windows combined package)
	$(QUIET)$(RM) -f -- $(wildcard $(subst r$(VBOX_SVN_REV),r*, \
		$@ \
		$(VBOX_WIN_INST_REPACK_DIR)/4-multiarch-$(PACKAGE_NAME_MULTIARCH_FINAL).cmd ) )
	$(if-expr defined(VBOX_WITH_MSM_INSTALL),,$(call VBOX_SIGN_CAB_FN,$(PACKAGE_NAME_MULTIARCH_COMMONCAB)))
	$(REDIRECT) -C $(@D) -- \
		$(VBoxStubBld_1_TARGET) -out $@ \
			-target-x86 $(PATH_MULTIARCH_TEMP)/$(PACKAGE_NAME_MULTIARCH.x86) \
			-target-amd64 $(PATH_MULTIARCH_TEMP)/$(PACKAGE_NAME_MULTIARCH.amd64) \
			$(if-expr defined(VBOX_WITH_MSM_INSTALL),,-target-all $(PACKAGE_NAME_MULTIARCH_COMMONCAB)) \
			-stub $(PATH_STAGE_BIN)/VBoxStub.exe
	$(VBOX_VCC_EDITBIN) /IntegrityCheck:NO $@
	$(call VBOX_SIGN_FILE_FN,$@)
 # Create repack script for this step.
	$(APPEND) -nt "$(VBOX_WIN_INST_REPACK_DIR)/4-multiarch-$(@F).cmd" \
		'if ".%KBUILD_DEVTOOLS%" == "." (echo KBUILD_DEVTOOLS is not set & exit /b1)' \
		'if ".%KBUILD_BIN_PATH%" == "." (echo KBUILD_BIN_PATH is not set & exit /b1)' \
		$(subst $(KBUILD_BIN_PATH),%KBUILD_BIN_PATH%,$(subst $(KBUILD_DEVTOOLS),%KBUILD_DEVTOOLS%, \
		$(if-expr defined(VBOX_WITH_MSM_INSTALL), \
		,'call sign-dual.cmd ../../../win.amd64/$(KBUILD_TYPE)/repack/$(notdir $(PACKAGE_NAME_MULTIARCH_COMMONCAB)) || exit /b1') \
		'..\bin\VBoxStubBld.exe ^' \
		'  -out $(@F) ^' \
		'  -target-x86 $(PACKAGE_NAME_MULTIARCH.x86) ^' \
		'  -target-amd64 ../../../win.amd64/$(KBUILD_TYPE)/repack/$(PACKAGE_NAME_MULTIARCH.amd64) ^' \
		$(if-expr defined(VBOX_WITH_MSM_INSTALL),\
		,'  -target-all ../../../win.amd64/$(KBUILD_TYPE)/repack/$(notdir $(PACKAGE_NAME_MULTIARCH_COMMONCAB)) ^' ) \
		'  -stub ../bin/VBoxStub.exe || exit /b1' \
		'$(VBOX_VCC_EDITBIN) /IntegrityCheck:NO $(@F) || exit /b1' \
		'call sign-dual.cmd $(@F) || exit /b1' \
		) ) \
		'@echo Created multiarch EXE: $(@F)'
else
 #
 # We still do the installer stub thing even if we only ship 64-bit, because we've
 # gotten used to having it around to install the certificate and such.
 #
 $(PATH_STAGE_BIN)/$(PACKAGE_NAME_MULTIARCH_FINAL) \
 + $(VBOX_WIN_INST_REPACK_DIR)/4-multiarch-$(PACKAGE_NAME_MULTIARCH_FINAL).cmd: \
 		$(PACKAGE_NAME_FINAL) \
 		$(PATH_STAGE_BIN)/VBoxStub.exe \
 		$$(VBoxStubBld_1_TARGET)
	$(call MSG_L1,Building Windows package w/ installer stub)
	$(QUIET)$(RM) -f -- $(wildcard $(subst r$(VBOX_SVN_REV),r*, \
		$@ \
		$(VBOX_WIN_INST_REPACK_DIR)/4-multiarch-$(PACKAGE_NAME_MULTIARCH_FINAL).cmd ) )
	$(REDIRECT) -C $(@D) -- \
		$(VBoxStubBld_1_TARGET) -out $@ \
			-target-$(KBUILD_TARGET_ARCH) $(PACKAGE_NAME_FINAL) \
			-stub $(PATH_STAGE_BIN)/VBoxStub.exe
	$(VBOX_VCC_EDITBIN) /IntegrityCheck:NO $@
	$(call VBOX_SIGN_FILE_FN,$@)
 # Create repack script for this step.
	$(APPEND) -nt "$(VBOX_WIN_INST_REPACK_DIR)/4-multiarch-$(@F).cmd" \
		'if ".%KBUILD_DEVTOOLS%" == "." (echo KBUILD_DEVTOOLS is not set & exit /b1)' \
		'if ".%KBUILD_BIN_PATH%" == "." (echo KBUILD_BIN_PATH is not set & exit /b1)' \
		$(subst $(KBUILD_BIN_PATH),%KBUILD_BIN_PATH%,$(subst $(KBUILD_DEVTOOLS),%KBUILD_DEVTOOLS%, \
		'..\bin\VBoxStubBld.exe ^' \
		'  -out $(@F) ^' \
		'  -target-$(KBUILD_TARGET_ARCH) $(notdir $(PACKAGE_NAME_FINAL)) ^' \
		'  -stub ../bin/VBoxStub.exe || exit /b1' \
		'$(VBOX_VCC_EDITBIN) /IntegrityCheck:NO $(@F) || exit /b1' \
		'call sign-dual.cmd $(@F) || exit /b1' \
		) ) \
		'@echo Created multiarch EXE: $(@F)'
 ifdef VBOX_WIN_ATTESTATION_SIGNING
	echo "Repacking HERE"
	$(RM) -f $(VBOX_WIN_INST_REPACK_DIR)/*.ddf
	cd $(PATH_OUT)/repack && $(RM) -f *.ddf
	$(RM) -f $(VBOX_WIN_INST_REPACK_DIR)/$(PACKAGE_NAME_LANG)-$(KBUILD_TARGET_ARCH).cab
	$(RM) -f $(VBOX_WIN_INST_REPACK_DIR)/PackDriversForSubmission_internal.cmd
	$(APPEND) -nt "$(VBOX_WIN_INST_REPACK_DIR)/PackDriversForSubmission_internal.cmd" \
	"SET KBUILD_BIN_PATH=$(KBUILD_BIN_PATH)" \
	"call PackDriversForSubmission.cmd -b $(PATH_STAGE_BIN) -a $(KBUILD_TARGET_ARCH) \
		-x -n --no-extpack -o $(VBOX_WIN_INST_REPACK_DIR)/$(PACKAGE_NAME_LANG)-$(KBUILD_TARGET_ARCH).cab"

	cd $(VBOX_WIN_INST_REPACK_DIR) && $(EXEC_X86_WIN32) cmd.exe /c PackDriversForSubmission_internal.cmd
	cd $(VBOX_WIN_INST_REPACK_DIR) && $(VBOX_RETRY) $(VBOX_WIN_ATTESTATION_SIGNING_EXE) "Oracle VM VirtualBox Base drivers $(KBUILD_TARGET_ARCH) $(VBOX_VERSION_MAJOR).$(VBOX_VERSION_MINOR).$(VBOX_VERSION_BUILD)r$(VBOX_SVN_REV)" "$(KBUILD_TARGET_ARCH)" "r$(VBOX_SVN_REV)" "$(PACKAGE_NAME_LANG)-$(KBUILD_TARGET_ARCH).cab"

	$(RM) -f $(VBOX_WIN_INST_REPACK_DIR)/Single-3-Repack_internal.cmd
	$(APPEND) -nt "$(VBOX_WIN_INST_REPACK_DIR)/Single-3-Repack_internal.cmd" \
	"SET KBUILD_BIN_PATH=$(KBUILD_BIN_PATH)" \
	"SET KBUILD_DEVTOOLS=$(KBUILD_DEVTOOLS)" \
	"call Single-3-Repack.cmd --no-extpack --signed "$(PACKAGE_NAME_LANG)-$(KBUILD_TARGET_ARCH).cab.Signed.zip"
	cd $(VBOX_WIN_INST_REPACK_DIR) && $(EXEC_X86_WIN32) cmd.exe /c Single-3-Repack_internal.cmd

	$(RM) -f $(PATH_STAGE_BIN)/$(PACKAGE_NAME_MULTIARCH_FINAL)
	$(RM) -f $(PATH_STAGE_BIN)/$(PACKAGE_NAME_LANG).msi
	$(CP) $(VBOX_WIN_INST_REPACK_DIR)/$(PACKAGE_NAME_MULTIARCH_FINAL) $(PATH_STAGE_BIN)/
	$(CP) $(VBOX_WIN_INST_REPACK_DIR)/$(PACKAGE_NAME_LANG).msi        $(PATH_STAGE_BIN)/
 endif
endif

#
# Repackaging scripts and files.
#
INSTALLS += RePackScripts
RePackScripts_TEMPLATE = DUMMY
RePackScripts_INST = repack/
RePackScripts_INSTTYPE = stage
RePackScripts_SOURCES = \
	Scripts/UnpackBlessedDrivers.cmd \
	$(RePackScripts_0_OUTDIR)/PackDriversForSubmission.cmd \
	$(RePackScripts_0_OUTDIR)/sign-dual.cmd \
	$(RePackScripts_0_OUTDIR)/sign-sha1.cmd \
	$(if-expr defined(VBOX_SIGN_EV_FILE_FN),$(RePackScripts_0_OUTDIR)/sign-ev.cmd,) \
	$(RePackScripts_0_OUTDIR)/VMMR0.inf \
	$(RePackScripts_0_OUTDIR)/VBoxExtPackPuel.inf
if !defined(VBOX_WITH_COMBINED_PACKAGE) || "$(KBUILD_TARGET_ARCH)" == "x86"
 RePackScripts_SOURCES += \
 	$(RePackScripts_0_OUTDIR)/RepackExtPack.cmd
endif
ifdef VBOX_WITH_COMBINED_PACKAGE
 if "$(KBUILD_TARGET_ARCH)" == "x86"
  RePackScripts_SOURCES += \
  	$(RePackScripts_0_OUTDIR)/Combined-1-Prepare.cmd \
  	$(RePackScripts_0_OUTDIR)/Combined-3-Repack.cmd \
  	$(RePackScripts_0_OUTDIR)/Combined-3-RepackAdditions.cmd
 endif
else
 RePackScripts_SOURCES += \
 	$(RePackScripts_0_OUTDIR)/Single-1-Prepare.cmd \
 	$(RePackScripts_0_OUTDIR)/Single-3-Repack.cmd

 ifndef VBOX_OSE
  RePackScripts_SOURCES += \
  	$(RePackScripts_0_OUTDIR)/Single-0-All.cmd
 endif

endif
RePackScripts_CLEAN = \
	$(RePackScripts_0_OUTDIR)/PackDriversForSubmission.cmd \
	$(RePackScripts_0_OUTDIR)/sign-dual.cmd \
	$(RePackScripts_0_OUTDIR)/sign-sha1.cmd \
	$(RePackScripts_0_OUTDIR)/sign-ev.cmd \
	$(RePackScripts_0_OUTDIR)/VMMR0.inf \
	$(RePackScripts_0_OUTDIR)/VBoxExtPackPuel.inf

$(call VBOX_EDIT_VERSION_AND_BUILD_RULE_FN,RePackScripts,Scripts/PackDriversForSubmission.cmd,PackDriversForSubmission.cmd)
$(call VBOX_EDIT_VERSION_AND_BUILD_RULE_FN,RePackScripts,Scripts/RepackExtPack.cmd,RepackExtPack.cmd)
ifdef VBOX_WITH_COMBINED_PACKAGE
 $(call VBOX_EDIT_VERSION_AND_BUILD_RULE_FN,RePackScripts,Scripts/Combined-1-Prepare.cmd,Combined-1-Prepare.cmd)
 $(call VBOX_EDIT_VERSION_AND_BUILD_RULE_FN,RePackScripts,Scripts/Combined-3-Repack.cmd,Combined-3-Repack.cmd)
 $(call VBOX_EDIT_VERSION_AND_BUILD_RULE_FN,RePackScripts,Scripts/Combined-3-RepackAdditions.cmd,Combined-3-RepackAdditions.cmd)
else
 ifndef VBOX_OSE
  $(call VBOX_EDIT_VERSION_AND_BUILD_RULE_FN,RePackScripts,Scripts/Single-0-All.cmd,Single-0-All.cmd)
 endif
 $(call VBOX_EDIT_VERSION_AND_BUILD_RULE_FN,RePackScripts,Scripts/Single-1-Prepare.cmd,Single-1-Prepare.cmd)
 $(call VBOX_EDIT_VERSION_AND_BUILD_RULE_FN,RePackScripts,Scripts/Single-3-Repack.cmd,Single-3-Repack.cmd)
endif

$$(RePackScripts_0_OUTDIR)/sign-dual.cmd: | $$(dir $$@)
	$(APPEND) -nt "$@" \
		'if ".%KBUILD_DEVTOOLS%" == "." (echo KBUILD_DEVTOOLS is not set & exit /b 1)' \
		'if ".%KBUILD_BIN_PATH%" == "." (echo KBUILD_BIN_PATH is not set & exit /b 1)' \
		'if ".%1" == "." (echo No .cat file specified & exit /b 1)' \
		$(subst /win-6.1/,/win-rel/,$(subst $(KBUILD_BIN_PATH),%KBUILD_BIN_PATH%,$(subst $(KBUILD_DEVTOOLS),%KBUILD_DEVTOOLS%, \
		'( $(call VBOX_SIGN_FILE_FN,%1,$(VBOX_PRODUCT) $(VBOX_VERSION_STRING)r$(VBOX_SVN_REV) ($(KBUILD_TARGET_ARCH)),,,,&&) ) || exit /b1' \
		) ) )

$$(RePackScripts_0_OUTDIR)/sign-sha1.cmd: | $$(dir $$@)
	$(APPEND) -nt "$@" \
		'if ".%KBUILD_DEVTOOLS%" == "." (echo KBUILD_DEVTOOLS is not set & exit /b 1)' \
		'if ".%KBUILD_BIN_PATH%" == "." (echo KBUILD_BIN_PATH is not set & exit /b 1)' \
		'if ".%1" == "." (echo No .cat file specified & exit /b 1)' \
		$(subst $(KBUILD_BIN_PATH),%KBUILD_BIN_PATH%,$(subst $(KBUILD_DEVTOOLS),%KBUILD_DEVTOOLS%, \
		'( $(call VBOX_SIGN_FILE_FN,%1,$(VBOX_PRODUCT) $(VBOX_VERSION_STRING)r$(VBOX_SVN_REV) ($(KBUILD_TARGET_ARCH)),,,disable-dual-signing,&&) ) || exit /b1' \
		) )

# The %~dp1\ oddity is working around otherwise ending with \" during
# expansion of the CCS command line which for a reason I cannot immediately
# understand appends a " to the path.
$$(RePackScripts_0_OUTDIR)/sign-ev.cmd: | $$(dir $$@)
	$(APPEND) -nt "$@" \
		'if ".%KBUILD_DEVTOOLS%" == "." (echo KBUILD_DEVTOOLS is not set & exit /b 1)' \
		'if ".%KBUILD_BIN_PATH%" == "." (echo KBUILD_BIN_PATH is not set & exit /b 1)' \
		'if ".%1" == "." (echo No .cab file specified & exit /b 1)' \
		$(subst $(KBUILD_BIN_PATH),%KBUILD_BIN_PATH%,$(subst $(KBUILD_DEVTOOLS),%KBUILD_DEVTOOLS%, \
		'( $(call VBOX_SIGN_EV_FILE_FN,%1,%~dp1\) ) || exit /b1' \
		) )

$$(RePackScripts_0_OUTDIR)/VMMR0.inf: $(PATH_SUB_CURRENT)/Scripts/VMMR0.inf $(MAKEFILE_CURRENT) | $$(dir $$@)
	$(call MSG_GENERATE,RePackScripts,$@,$<)
	$(call VBOX_EDIT_INF_FN,$<,$@)

$$(RePackScripts_0_OUTDIR)/VBoxExtPackPuel.inf: $(PATH_SUB_CURRENT)/Scripts/VBoxExtPackPuel.inf $(MAKEFILE_CURRENT) | $$(dir $$@)
	$(call MSG_GENERATE,RePackScripts,$@,$<)
	$(call VBOX_EDIT_INF_FN,$<,$@)


include $(FILE_KBUILD_SUB_FOOTER)