summaryrefslogtreecommitdiffstats
path: root/src/VBox/Installer/darwin/Makefile.kmk
blob: bc728aa25452fa9a3f867f58901d0a14ef4c77ee (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
# $Id: Makefile.kmk $
## @file
# Install misc stuff and create dist packages for Mac OS X.
#

#
# Copyright (C) 2006-2019 Oracle Corporation
#
# This file is part of VirtualBox Open Source Edition (OSE), as
# available from http://www.virtualbox.org. This file is free software;
# you can redistribute it and/or modify it under the terms of the GNU
# General Public License (GPL) as published by the Free Software
# Foundation, in version 2 as it comes in the "COPYING" file of the
# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
#

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


#
# Globals
#
VBOX_PATH_DI_SRC := $(PATH_SUB_CURRENT)
VBOX_DI_OUT_DIR  := $(PATH_TARGET)/Installer/darwin
BLDDIRS += $(VBOX_DI_OUT_DIR)

VBOX_DI_FN_DEP_BOTH = $(VBOX_PATH_DIST)/$1
ifeq ($(KBUILD_TARGET_ARCH),x86)
 VBOX_DI_FN_DEP_32  = $(VBOX_PATH_DIST)/$1
 VBOX_DI_FN_DEP_64  =
else
 VBOX_DI_FN_DEP_64  = $(VBOX_PATH_DIST)/$1
 VBOX_DI_FN_DEP_32  =
endif
VBOX_PATH_DIST_OTHER = $(error VBOX_PATH_DIST_OTHER used in a non-combined package deal)

VBOX_QT_VERSION_MAJOR = 5
PATH_SDK_QT = $(PATH_SDK_QT5)

# Unset this to speed up things during makefile hacking.
VBOX_DARWIN_INST_DEP_ON_MAKEFILE := $(MAKEFILE_CURRENT)

# The location of the pkgbuild program.
ifndef VBOX_PKGBUILD
 VBOX_PKGBUILD := pkgbuild
endif

# The location of the productbuild program.
ifndef VBOX_PRODUCTBUILD
 VBOX_PRODUCTBUILD := productbuild
endif

# Where we do the packing (override this in LocalConfig.kmk if building on smbfs).
ifndef VBOX_PATH_PACK_TMP
 VBOX_PATH_PACK_TMP := $(VBOX_DI_OUT_DIR)
endif

# Shorthand for $(VBOX_PATH_PACK_TMP)/VirtualBox.pkg.root/Applications/VirtualBox.app
VBOX_PATH_VBOX_APP_TMP := $(VBOX_PATH_PACK_TMP)/VirtualBox.pkg.root/Applications/VirtualBox.app


#
# Install the darwin docs/license.
#
INSTALLS += darwin-docs
darwin-docs_INST = $(INST_DIST)
darwin-docs_MODE = a+r,u+w
darwin-docs_SOURCES = \
	$(VBOX_BRAND_LICENSE_TXT)=>LICENSE


#
# The packing.
#
PACKING += $(VBOX_PATH_DIST)/VirtualBox-$(VBOX_VERSION_STRING)-r$(VBOX_SVN_REV).dmg
#OTHER_CLEAN = TODO


include $(FILE_KBUILD_SUB_FOOTER)


#
# We're running commands as root here, take some care and assertion
# a sane environment.
#
ifeq ($(strip $(VBOX_PATH_DIST)),)
 $(error VBOX_PATH_DIST=$(VBOX_PATH_DIST))
endif
ifeq ($(strip $(VBOX_PATH_DIST)),/)
 $(error VBOX_PATH_DIST=$(VBOX_PATH_DIST))
endif
ifeq ($(strip $(VBOX_PATH_PACK_TMP)),)
 $(error VBOX_PATH_PACK_TMP=$(VBOX_PATH_PACK_TMP))
endif
ifeq ($(strip $(VBOX_PATH_PACK_TMP)),/)
 $(error VBOX_PATH_PACK_TMP=$(VBOX_PATH_PACK_TMP))
endif


# Check for additional manuals
VBOX_ADD_MANUALS := $(foreach f,$(VBOX_MANUAL_ADD_LANGUAGES),$(VBOX_PATH_DIST)/VirtualBox.app/Contents/MacOS/UserManual_$(f).pdf)

VBOX_ADD_MANUAL_de_DE := $(filter $(VBOX_PATH_DIST)/VirtualBox.app/Contents/MacOS/UserManual_de_DE.pdf,$(VBOX_ADD_MANUALS))
VBOX_ADD_MANUAL_fr_FR := $(filter $(VBOX_PATH_DIST)/VirtualBox.app/Contents/MacOS/UserManual_fr_FR.pdf,$(VBOX_ADD_MANUALS))

#
# The disk image.
#
$(VBOX_PATH_DIST)/VirtualBox-$(VBOX_VERSION_STRING)-r$(VBOX_SVN_REV).dmg: \
		$(VBOX_PATH_PACK_TMP)/DiskImage/VirtualBox.pkg \
		$(VBOX_BRAND_DARWIN_DISKIMAGE_BG) \
		$(VBOX_BRAND_DARWIN_DISKIMAGE_DS_STORE) \
		$$(wildcard $(VBOX_PATH_DI_SRC)/DiskImage/*) \
		$(if $(VBOX_WITH_DOCS_PACKING), \
			$(VBOX_PATH_DIST)/VirtualBox.app/Contents/MacOS/UserManual.pdf \
			$(VBOX_ADD_MANUALS)) \
		$(VBOX_DARWIN_INST_DEP_ON_MAKEFILE)
	$(call MSG_TOOL,hdiutil,,,$@)
	@# Cleanup any previously failed attempts and various trash.
	sudo rm -Rf $(VBOX_PATH_PACK_TMP)/DiskImage.tmp
	$(MKDIR) -p $(VBOX_PATH_PACK_TMP)/DiskImage.tmp/
	sudo mv $(VBOX_PATH_PACK_TMP)/DiskImage/VirtualBox.pkg $(VBOX_PATH_PACK_TMP)/DiskImage.tmp/
	sudo rm -Rf \
		$@ \
		$(VBOX_PATH_PACK_TMP)/DiskImage/
	sudo mv $(VBOX_PATH_PACK_TMP)/DiskImage.tmp $(VBOX_PATH_PACK_TMP)/DiskImage
	@# Remove .dmg packages from old depend builds
	$(QUIET)$(RM) -f $(wildcard $(VBOX_PATH_DIST)/VirtualBox-*-r*.dmg)
	@# Populate the image with uninstaller, readme, picture, and .VolumeIcon.icns. (TODO)
	$(INSTALL) $(VBOX_PATH_DI_SRC)/DiskImage/VirtualBox_Uninstall.tool  $(VBOX_PATH_PACK_TMP)/DiskImage/
ifdef VBOX_SIGNING_MODE
	$(call VBOX_SIGN_FILE_FN,$(VBOX_PATH_PACK_TMP)/DiskImage/VirtualBox_Uninstall.tool,org.virtualbox.dmg.uninstaller)
endif
ifeq (1,1)
	@# Pedantic mode...
	$(INSTALL) -m 644 $(VBOX_BRAND_DARWIN_DISKIMAGE_DS_STORE)           $(VBOX_PATH_PACK_TMP)/DiskImage/.DS_Store
	$(MKDIR) $(VBOX_PATH_PACK_TMP)/DiskImage/.background
	$(INSTALL) -m 644 $(VBOX_BRAND_DARWIN_DISKIMAGE_BG)                 $(VBOX_PATH_PACK_TMP)/DiskImage/.background/vbox_folder.tiff
 ifdef VBOX_WITH_BUNDLED_INSTALLER
	$(if $(VBOX_WITH_DOCS_PACKING), \
		$(INSTALL) -m 644 $(VBOX_PATH_DIST)/VirtualBox.app/Contents/MacOS/UserManual.pdf $(VBOX_PATH_PACK_TMP)/DiskImage/User\ Manual.pdf$(NLTAB) \
		$(if $(VBOX_ADD_MANUAL_de_DE),$(INSTALL) -m 644 $(VBOX_ADD_MANUAL_de_DE) "$(VBOX_PATH_PACK_TMP)/DiskImage/$(VBOX_BRAND_de_DE_MANUAL_NAME).pdf"$(NLTAB)) \
		$(if $(VBOX_ADD_MANUAL_fr_FR),$(INSTALL) -m 644 $(VBOX_ADD_MANUAL_fr_FR) "$(VBOX_PATH_PACK_TMP)/DiskImage/$(VBOX_BRAND_fr_FR_MANUAL_NAME).pdf"$(NLTAB)))
    # Rename the main package
 else
	$(if $(VBOX_WITH_DOCS_PACKING), $(INSTALL) $(VBOX_PATH_DIST)/VirtualBox.app/Contents/MacOS/UserManual.pdf $(VBOX_PATH_PACK_TMP)/DiskImage/)
	$(LN) -s /Applications/                                             $(VBOX_PATH_PACK_TMP)/DiskImage/Applications
 endif
endif
	@# hdiutil of OS X 10.10 adds a .Trashes directory and some suggest this may upset the image size calculations (-5341).
	$(MKDIR) -m 1333  $(VBOX_PATH_PACK_TMP)/DiskImage/.Trashes
	@# Change the owners.
	sudo chown -R root:admin $(VBOX_PATH_PACK_TMP)/DiskImage
	@# Create the image. We calculate the size our selves, adding 16MB for fudging (min 13MB fudge needed on high sierra).
	sudo hdiutil create -format UDBZ -volname "VirtualBox" -srcfolder "$(VBOX_PATH_PACK_TMP)/DiskImage" \
		-size $(DOLLAR)((`sudo /usr/bin/du -sk "$(VBOX_PATH_PACK_TMP)/DiskImage/" | /usr/bin/cut -f1` + 16384))k \
		"$@"
	@# Change (back) the owner so it can be deleted by the user.
	sudo chown "$(shell whoami)" "$@"
	sudo chown -R "$(shell whoami)" $(VBOX_PATH_PACK_TMP)/DiskImage
ifdef VBOX_SIGNING_MODE
 ifndef VBOX_WITHOUT_SIGNED_DMG
	@# Sign the created dmg.
	$(call VBOX_SIGN_DMG_FN,$@,org.virtualbox.dmg)
 endif
endif

#
# The meta-package.
#
$(VBOX_PATH_PACK_TMP)/DiskImage/VirtualBox.pkg: \
		$(VBOX_PATH_PACK_TMP)/Packages/VBoxKEXTs.pkg \
		$(VBOX_PATH_PACK_TMP)/Packages/VirtualBoxCLI.pkg \
		$(VBOX_PATH_PACK_TMP)/Packages/VirtualBox.pkg \
		$$(wildcard $(VBOX_PATH_DI_SRC)/VirtualBox_mpkg/* \
		            $(VBOX_PATH_DI_SRC)/VirtualBox_mpkg/*.lproj/*) \
		$(foreach f,$(VBOX_INSTALLER_ADD_LANGUAGES), $(VBOX_BRAND_$(f)_VIRTUALBOX_WELCOME_RTF)) \
		$(if $(VBOX_WITH_FUSE_PACKING), $(VBOX_PATH_PACK_TMP)/Packages/OSXFuseCore.pkg) \
		$(VBOX_DARWIN_INST_DEP_ON_MAKEFILE)
	$(call MSG_TOOL,productbuild,,,$@)
	@# Cleanup any previously failed attempts.
	sudo rm -Rf \
		$@ \
		$(VBOX_PATH_PACK_TMP)/VirtualBox.dist.root \
		$(VBOX_PATH_PACK_TMP)/VirtualBox.dist.desc \
		$(VBOX_PATH_PACK_TMP)/VirtualBox.dist.res
	@# Correct directory permissions are important.
	$(MKDIR) -p \
		$(@D) \
		$(VBOX_PATH_PACK_TMP)/VirtualBox.dist.desc \
		$(VBOX_PATH_PACK_TMP)/VirtualBox.dist.res \
		$(VBOX_PATH_PACK_TMP)/VirtualBox.dist.res/English.lproj
	@# Do keyword replacement in the package info and description files.
	$(SED) \
		-e 's/@VBOX_VERSION_STRING@/$(VBOX_VERSION_STRING)/g' \
		-e 's/@VBOX_VERSION_MAJOR@/$(VBOX_VERSION_MAJOR)/g' \
		-e 's/@VBOX_VERSION_MINOR@/$(VBOX_VERSION_MINOR)/g' \
		-e 's/@VBOX_VERSION_BUILD@/$(VBOX_VERSION_BUILD)/g' \
		-e 's/@VBOX_VENDOR@/$(VBOX_VENDOR)/g' \
		-e 's/@VBOX_PRODUCT@/$(VBOX_PRODUCT)/g' \
		-e 's/@VBOX_C_YEAR@/$(VBOX_C_YEAR)/g' \
		--output $(VBOX_PATH_PACK_TMP)/VirtualBox.dist.res/English.lproj/Welcome.rtf \
		$(VBOX_PATH_DI_SRC)/VirtualBox_mpkg/Welcome.rtf
	@# Copy the resources.
	$(INSTALL) -m 0644 $(VBOX_PATH_DI_SRC)/VirtualBox_mpkg/Conclusion.rtf                   $(VBOX_PATH_PACK_TMP)/VirtualBox.dist.res/English.lproj/Conclusion.rtf
	$(SED) \
		-e 's/@VBOX_VENDOR@/$(VBOX_VENDOR)/g' \
		-e 's/@VBOX_PRODUCT@/$(VBOX_PRODUCT)/g' \
		-e 's/@VBOX_C_YEAR@/$(VBOX_C_YEAR)/g' \
		--output $(VBOX_PATH_PACK_TMP)/VirtualBox.dist.res/English.lproj/Localizable.strings \
		$(VBOX_PATH_DI_SRC)/VirtualBox_mpkg/Localizable.strings
	$(INSTALL) -m 0644 $(VBOX_BRAND_DARWIN_INSTALLER_BG)                                    $(VBOX_PATH_PACK_TMP)/VirtualBox.dist.res/background.tif
	$(foreach f,$(VBOX_INSTALLER_ADD_LANGUAGES), \
		$(MKDIR) -p \
			$(VBOX_PATH_PACK_TMP)/VirtualBox.dist.res/$(VBOX_INSTALLER_$(f)_DARWIN_TARGET).lproj$(NLTAB) \
		$(SED) \
			-e 's/@VBOX_VERSION_STRING@/$(VBOX_VERSION_STRING)/g' \
			-e 's/@VBOX_VERSION_MAJOR@/$(VBOX_VERSION_MAJOR)/g' \
			-e 's/@VBOX_VERSION_MINOR@/$(VBOX_VERSION_MINOR)/g' \
			-e 's/@VBOX_VERSION_BUILD@/$(VBOX_VERSION_BUILD)/g' \
			--output $(VBOX_PATH_PACK_TMP)/VirtualBox.dist.res/$(VBOX_INSTALLER_$(f)_DARWIN_TARGET).lproj/Welcome.rtf \
			$(VBOX_BRAND_$(f)_VIRTUALBOX_WELCOME_RTF)$(NLTAB) \
		$(INSTALL) -m 0644 $(VBOX_BRAND_$(f)_VIRTUALBOX_CONCLUSION_RTF)                $(VBOX_PATH_PACK_TMP)/VirtualBox.dist.res/$(VBOX_INSTALLER_$(f)_DARWIN_TARGET).lproj/Conclusion.rtf$(NLTAB) \
		$(SED) \
			-e 's/@VBOX_VENDOR@/$(VBOX_VENDOR)/g' \
			-e 's/@VBOX_PRODUCT@/$(VBOX_PRODUCT)/g' \
			-e 's/@VBOX_C_YEAR@/$(VBOX_C_YEAR)/g' \
			--output $(VBOX_PATH_PACK_TMP)/VirtualBox.dist.res/$(VBOX_INSTALLER_$(f)_DARWIN_TARGET).lproj/Localizable.strings \
			$(VBOX_BRAND_$(f)_VIRTUALBOX_LOCALIZABLE_STRINGS)$(NLTAB) \
	)
	@# Build the package.
	$(VBOX_PRODUCTBUILD) \
		--distribution $(VBOX_PATH_DI_SRC)/VirtualBox_mpkg/distribution.dist \
		--package-path $(VBOX_PATH_PACK_TMP)/Packages \
		--resources $(VBOX_PATH_PACK_TMP)/VirtualBox.dist.res \
		--identifier org.VirtualBox.mpkg.virtualbox \
		--version $(VBOX_VERSION_MAJOR).$(VBOX_VERSION_MINOR).$(VBOX_VERSION_BUILD) \
		$(if $(VBOX_MACOSX_INSTALLER_SIGN),--sign "$(VBOX_MACOSX_INSTALLER_SIGN)",) \
		$@
ifdef VBOX_SIGNING_MODE
 ifdef VBOX_WITH_CORP_CODE_SIGNING
	@# Sign the created pkg.
	$(call VBOX_SIGN_PKG_FN,$@,org.VirtualBox.mpkg.virtualbox)
 endif
endif
	@# Cleanup.
	sudo rm -Rf \
		$(VBOX_PATH_PACK_TMP)/VirtualBox.dist.root \
		$(VBOX_PATH_PACK_TMP)/VirtualBox.dist.desc \
		$(VBOX_PATH_PACK_TMP)/VirtualBox.dist.res


#
# The VirtualBox Kernel extensions.
#
VBOX_DI_KEXTS_UNIVERSAL = VBoxDrv VBoxNetFlt VBoxNetAdp VBoxUSB
VBOX_DI_KEXTS = $(VBOX_DI_KEXTS_UNIVERSAL)

$(VBOX_PATH_PACK_TMP)/Packages/VBoxKEXTs.pkg: \
		$(foreach kext,$(VBOX_DI_KEXTS_UNIVERSAL), $(call VBOX_DI_FN_DEP_BOTH,$(kext).kext/Contents/MacOS/$(kext))) \
		$(foreach kext,$(VBOX_DI_KEXTS), $(VBOX_PATH_DIST)/$(kext).kext/Contents/Info.plist) \
		$$(wildcard $(VBOX_PATH_DI_SRC)/VBoxKEXTs/* \
		            $(VBOX_PATH_DI_SRC)/VBoxKEXTs/*.lproj/*) \
		$(foreach f,$(VBOX_INSTALLER_ADD_LANGUAGES), \
			$(VBOX_BRAND_$(f)_VBOXKEXTS_DESCRIPTION_PLIST) \
			$(VBOX_BRAND_$(f)_VBOXKEXTS_README_HTML) \
			$(VBOX_BRAND_$(f)_VBOXKEXTS_INSTALLATIONCHECK_STRINGS)) \
		$(VBOX_DARWIN_INST_DEP_ON_MAKEFILE)
	$(call MSG_TOOL,pkgbuild,,,$@)
	@# Cleanup any previously failed attempts.
	sudo rm -Rf \
		$@ \
		$(VBOX_PATH_PACK_TMP)/VBoxKEXTs.pkg.root \
		$(VBOX_PATH_PACK_TMP)/VBoxKEXTs.pkg.desc \
		$(VBOX_PATH_PACK_TMP)/VBoxKEXTs.pkg.res
	@# Correct directory permissions are important.
	$(MKDIR) -p \
		$(@D) \
		$(VBOX_PATH_PACK_TMP)/VBoxKEXTs.pkg.desc \
		$(VBOX_PATH_PACK_TMP)/VBoxKEXTs.pkg.res \
		$(VBOX_PATH_PACK_TMP)/VBoxKEXTs.pkg.res/English.lproj
	$(MKDIR) -p -m 0755 \
		$(VBOX_PATH_PACK_TMP)/VBoxKEXTs.pkg.root \
		$(VBOX_PATH_PACK_TMP)/VBoxKEXTs.pkg.root/LaunchDaemons \
		$(foreach kext,$(VBOX_DI_KEXTS), \
			$(VBOX_PATH_PACK_TMP)/VBoxKEXTs.pkg.root/$(kext).kext \
			$(VBOX_PATH_PACK_TMP)/VBoxKEXTs.pkg.root/$(kext).kext/Contents \
			$(VBOX_PATH_PACK_TMP)/VBoxKEXTs.pkg.root/$(kext).kext/Contents/MacOS )
	@# Copy the launch daemon bits.
	$(INSTALL) -m 0755  $(VBOX_PATH_DI_SRC)/VBoxKEXTs/VirtualBoxStartup.sh          $(VBOX_PATH_PACK_TMP)/VBoxKEXTs.pkg.root/LaunchDaemons/
	$(INSTALL) -m 0644  $(VBOX_PATH_DI_SRC)/VBoxKEXTs/org.virtualbox.startup.plist 	$(VBOX_PATH_PACK_TMP)/VBoxKEXTs.pkg.root/LaunchDaemons/
	@# Copy the common files (Info.plist).
	$(foreach kext,$(VBOX_DI_KEXTS), \
		$(NLTAB)$(INSTALL) -m 0644 $(VBOX_PATH_DIST)/$(kext).kext/Contents/Info.plist $(VBOX_PATH_PACK_TMP)/VBoxKEXTs.pkg.root/$(kext).kext/Contents/)
	@# Copy the binaries and invoking lipo.
	$(foreach kext,$(VBOX_DI_KEXTS), \
		$(NLTAB)$(INSTALL) -m 0755 $(VBOX_PATH_DIST)/$(kext).kext/Contents/MacOS/$(kext) $(VBOX_PATH_PACK_TMP)/VBoxKEXTs.pkg.root/$(kext).kext/Contents/MacOS/)
	@# Signed the kext bundles.
ifdef VBOX_SIGNING_MODE
	$(foreach kext,$(VBOX_DI_KEXTS) \
		,$(NLTAB)$(call VBOX_SIGN_MACHO_FN,$(VBOX_PATH_PACK_TMP)/VBoxKEXTs.pkg.root/$(kext).kext/Contents/MacOS/$(kext),org.virtualbox.app.kext.$(kext)) )
	$(foreach kext,$(VBOX_DI_KEXTS), \
		$(NLTAB)$(call VBOX_SIGN_BUNDLE_FN,$(VBOX_PATH_PACK_TMP)/VBoxKEXTs.pkg.root/$(kext).kext,org.virtualbox.app.kext.$(kext)) )
## @TODO check why this fails on the build box:	$(foreach kext,$(VBOX_DI_KEXTS), $(NLTAB)codesign --verify --verbose=1 $(VBOX_PATH_PACK_TMP)/VBoxKEXTs.pkg.root/$(kext).kext )
endif
	@# Set the correct owners.
	sudo chown -R root:wheel $(VBOX_PATH_PACK_TMP)/VBoxKEXTs.pkg.root/
	@# Do keyword replacement in the package info and description files.
	$(SED) \
		-e 's/@VBOX_VERSION_STRING@/$(VBOX_VERSION_STRING)/g' \
		-e 's/@VBOX_VERSION_MAJOR@/$(VBOX_VERSION_MAJOR)/g' \
		-e 's/@VBOX_VERSION_MINOR@/$(VBOX_VERSION_MINOR)/g' \
		-e 's/@VBOX_VERSION_BUILD@/$(VBOX_VERSION_BUILD)/g' \
		-e 's/@VBOX_VENDOR@/$(VBOX_VENDOR)/g' \
		-e 's/@VBOX_PRODUCT@/$(VBOX_PRODUCT)/g' \
		-e 's/@VBOX_C_YEAR@/$(VBOX_C_YEAR)/g' \
		--output $(VBOX_PATH_PACK_TMP)/VBoxKEXTs.pkg.desc/PkgBuildComponent.plist \
		$(VBOX_PATH_DI_SRC)/VBoxKEXTs/PkgBuildComponent.plist
	@# Copy the resources.
	$(INSTALL) -m 0755 $(VBOX_PATH_DI_SRC)/VBoxKEXTs/postflight                            $(VBOX_PATH_PACK_TMP)/VBoxKEXTs.pkg.res/
	@# Build the package.
	$(VBOX_PKGBUILD) \
		--root   $(VBOX_PATH_PACK_TMP)/VBoxKEXTs.pkg.root/ \
		--component-plist $(VBOX_PATH_PACK_TMP)/VBoxKEXTs.pkg.desc/PkgBuildComponent.plist \
		--script $(VBOX_PATH_PACK_TMP)/VBoxKEXTs.pkg.res \
		--identifier org.virtualbox.pkg.vboxkexts \
		--version $(VBOX_VERSION_MAJOR).$(VBOX_VERSION_MINOR).$(VBOX_VERSION_BUILD) \
		--install-location "/Library/Application Support/VirtualBox" \
		--ownership preserve \
		$(if $(VBOX_MACOSX_INSTALLER_SIGN),--sign "$(VBOX_MACOSX_INSTALLER_SIGN)",) \
		$@
ifdef VBOX_SIGNING_MODE
 ifdef VBOX_WITH_CORP_CODE_SIGNING
	@# Sign the created pkg.
	$(call VBOX_SIGN_PKG_FN,$@,org.virtualbox.pkg.vboxkexts)
 endif
endif
	@# Cleanup
	sudo chown -R "$(shell whoami)" \
		$(VBOX_PATH_PACK_TMP)/VBoxKEXTs.pkg.root
	sudo rm -Rf \
		$(VBOX_PATH_PACK_TMP)/VBoxKEXTs.pkg.root \
		$(VBOX_PATH_PACK_TMP)/VBoxKEXTs.pkg.desc \
		$(VBOX_PATH_PACK_TMP)/VBoxKEXTs.pkg.res


#
# Figure out which languages that we support and construct
# .qm and .lproj lists for these.
#
include $(PATH_ROOT)/src/VBox/Frontends/VirtualBox/nls/ApprovedLanguages.kmk
VBOX_INSTALL_LANG_FILES := $(foreach f,$(VBOX_APPROVED_GUI_LANGUAGES), VirtualBox_$(f).qm qt_$(f).qm)
VBOX_INSTALL_LANG_LPROJ := $(addsuffix .lproj,$(VBOX_APPROVED_GUI_LANGUAGES))


#
# The VirtualBox Application.
#

VBOX_DI_VBAPP_DYLIBS = \
	$(foreach qtmod, $(VBOX_QT_MOD_NAMES), Frameworks/$(qtmod).framework/Versions/$(VBOX_QT_VERSION_MAJOR)/$(qtmod)) \
	MacOS/VBoxDD.dylib \
	MacOS/VBoxDD2.dylib \
	MacOS/VBoxDDU.dylib \
	$(if $(VBOX_WITH_REM),MacOS/VBoxREM.dylib,) \
	MacOS/VBoxRT.dylib \
	$(if $(VBOX_WITH_SHARED_FOLDERS),MacOS/VBoxSharedFolders.dylib,) \
	$(if $(VBOX_WITH_SHARED_CLIPBOARD),MacOS/VBoxSharedClipboard.dylib,) \
	$(if $(VBOX_WITH_DRAG_AND_DROP),MacOS/VBoxDragAndDropSvc.dylib,) \
	$(if $(VBOX_WITH_GUEST_PROPS),MacOS/VBoxGuestPropSvc.dylib,) \
	MacOS/VBoxHostChannel.dylib \
	MacOS/VBoxVMM.dylib \
	MacOS/VBoxXPCOM.dylib \
	MacOS/VBoxXPCOMC.dylib \
	MacOS/components/VBoxC.dylib \
	MacOS/components/VBoxSVCM.dylib \
	MacOS/components/VBoxXPCOMIPCC.dylib \
	MacOS/VBoxAuth.dylib \
	MacOS/VBoxAuthSimple.dylib \
	$(if $(VBOX_WITH_GUEST_CONTROL),MacOS/VBoxGuestControlSvc.dylib,)
ifneq ($(wildcard $(VBOX_PATH_DIST)/VirtualBox.app/Contents/MacOS/accessible/libqtaccessiblewidgets.dylib),)
 VBOX_DI_VBAPP_DYLIBS += \
	MacOS/accessible/libqtaccessiblewidgets.dylib
endif
if defined(VBOX_WITH_VRDP) && !defined(VBOX_WITH_EXTPACK_PUEL)
 VBOX_DI_VBAPP_DYLIBS += \
	MacOS/VBoxVRDP.dylib
endif
ifdef VBOX_WITH_CROGL
 VBOX_DI_VBAPP_DYLIBS += \
 	MacOS/VBoxOGLhostcrutil.dylib \
 	MacOS/VBoxOGLhosterrorspu.dylib \
 	MacOS/VBoxOGLrenderspu.dylib \
 	MacOS/VBoxSharedCrOpenGL.dylib

 ifdef VBOX_WITH_CR_DISPLAY_LISTS
  VBOX_DI_VBAPP_DYLIBS += \
 	MacOS/VBoxOGLexpandospu.dylib
 endif
endif
ifdef VBOX_WITH_DEBUGGER_GUI
 VBOX_DI_VBAPP_DYLIBS += \
 	MacOS/VBoxDbg.dylib \
 	MacOS/DbgPlugInDiggers.dylib
endif
ifdef VBOX_WITH_HARDENING
 VBOX_DI_VBAPP_DYLIBS += \
 	MacOS/VBoxGlobal.dylib \
 	MacOS/VirtualBoxVM.dylib \
 	MacOS/VBoxNetDHCP.dylib \
 	MacOS/VBoxNetNAT.dylib \
 	MacOS/VBoxHeadless.dylib
endif
ifdef VBOX_WITH_HDDPARALLELS_INSTALL
 VBOX_DI_VBAPP_DYLIBS += \
 	MacOS/VBoxHDDParallels.dylib
endif
if defined(VBOX_WITH_PYTHON) && !defined(VBOX_WITHOUT_VBOXPYTHON_FOR_OSX_10_6)
 VBOX_DI_VBAPP_DYLIBS += \
 	MacOS/VBoxPython2_6.so
endif
if defined(VBOX_WITH_PYTHON) && !defined(VBOX_WITHOUT_VBOXPYTHON_FOR_OSX_10_7)
 VBOX_DI_VBAPP_DYLIBS += \
 	MacOS/VBoxPython2_7.so
endif
ifdef VBOX_WITH_VMSVGA3D
 VBOX_DI_VBAPP_DYLIBS += \
 	MacOS/VBoxSVGA3D.dylib \
 	MacOS/VBoxSVGA3DObjC.dylib
endif

ifdef VBOX_WITH_REM
 VBOX_DI_VBAPP_DYLIBS.x86 := \
 	MacOS/VBoxREM32.dylib \
 	MacOS/VBoxREM64.dylib
endif
ifdef VBOX_WITH_PYTHON
 VBOX_DI_VBAPP_DYLIBS.x86 += \
 	MacOS/VBoxPython2_5.so \
	$(if-expr defined(VBOX_WITH_MAC_OS_X_10_4_SUPPORT),MacOS/VBoxPython2_3.so,)
endif

VBOX_DI_VBAPP_DYLIBS.amd64 :=
if defined(VBOX_WITH_PYTHON) && defined(VBOX_WITHOUT_VBOXPYTHON_FOR_OSX_10_6)
 VBOX_DI_VBAPP_DYLIBS.amd64 += \
 	MacOS/VBoxPython2_6.so
endif

if defined(VBOX_WITH_JXPCOM)
 VBOX_DI_VBAPP_DYLIBS += \
        MacOS/libvboxjxpcom.jnilib
endif

if1of ($(VBOX_DI_VBAPP_DYLIBS.amd64), $(VBOX_DI_VBAPP_DYLIBS.x86))
 $(error Conflict.$(NLTAB)VBOX_DI_VBAPP_DYLIBS.amd64=$(VBOX_DI_VBAPP_DYLIBS.amd64)$(NLTAB)VBOX_DI_VBAPP_DYLIBS.x86  =$(VBOX_DI_VBAPP_DYLIBS.x86))
endif
if1of ($(VBOX_DI_VBAPP_DYLIBS.amd64) $(VBOX_DI_VBAPP_DYLIBS.x86),$(VBOX_DI_VBAPP_DYLIBS))
 $(error Conflict.$(NLTAB)VBOX_DI_VBAPP_DYLIBS.amd64=$(VBOX_DI_VBAPP_DYLIBS.amd64)$(NLTAB)VBOX_DI_VBAPP_DYLIBS.x86  =$(VBOX_DI_VBAPP_DYLIBS.x86)$(NLTAB)VBOX_DI_VBAPP_DYLIBS=$(VBOX_DI_VBAPP_DYLIBS))
endif

VBOX_DI_VBAPP_PROGS = \
	MacOS/VBoxManage \
	MacOS/VBoxSVC \
	MacOS/VBoxHeadless \
	MacOS/VBoxXPCOMIPCD \
	MacOS/VBoxNetAdpCtl \
	MacOS/VBoxNetDHCP \
	MacOS/VBoxNetNAT \
	MacOS/VBoxExtPackHelperApp \
	MacOS/VBoxBugReport \
	MacOS/VBoxBalloonCtrl \
	MacOS/VBoxAutostart \
	MacOS/VirtualBoxVM \
	$(if $(VBOX_WITH_WEBSERVICES),MacOS/vboxwebsrv) \
	MacOS/VirtualBox \
	$(if $(VBOX_WITH_DTRACE),MacOS/VBoxDTrace,)

VBOX_DI_VBAPP_UNIVERSAL_PROGS = \
	MacOS/vmstarter \
	$(if $(VBOX_WITH_VBOX_IMG)$(VBOX_WITH_TESTCASES),MacOS/vbox-img,) \
	$(if $(VBOX_WITH_VBOXIMGMOUNT),MacOS/vboximg-mount,)

VBOX_DI_VBAPP_OTHER_UNIVERSAL_BINS = \
	MacOS/VMMR0.r0 \
	MacOS/VBoxDDR0.r0

ifdef VBOX_WITH_RAW_MODE
 VBOX_DI_VBAPP_OTHER_BINS = \
	MacOS/VMMRC.rc \
	MacOS/VBoxDDRC.rc
else
 VBOX_DI_VBAPP_OTHER_BINS =
endif

VBOX_DI_VBAPP_DUPLICATED_RESOURCE_FILES = \
	Resources/virtualbox.icns \
	Resources/virtualbox.png \
	Resources/virtualbox-vbox.icns \
	Resources/virtualbox-vbox-extpack.icns \
	Resources/virtualbox-ovf.icns \
	Resources/virtualbox-ova.icns \
	Resources/virtualbox-vdi.icns \
	Resources/virtualbox-vmdk.icns \
	Resources/virtualbox-vhd.icns \
	Resources/virtualbox-hdd.icns

VBOX_DI_VBAPP_MISC_FILES = \
	Info.plist \
	PkgInfo \
       $(VBOX_DI_VBAPP_DUPLICATED_RESOURCE_FILES) \
	MacOS/components/VBoxXPCOMBase.xpt \
	MacOS/components/VirtualBox_XPCOM.xpt \
	Resources/VirtualBoxVM.app/Contents/Info.plist \
	Resources/VirtualBoxVM.app/Contents/PkgInfo \
       $(addprefix Resources/VirtualBoxVM.app/Contents/,$(VBOX_DI_VBAPP_DUPLICATED_RESOURCE_FILES)) \
	Resources/vmstarter.app/Contents/Info.plist \
	Resources/vmstarter.app/Contents/PkgInfo \
       $(addprefix Resources/vmstarter.app/Contents/,$(VBOX_DI_VBAPP_DUPLICATED_RESOURCE_FILES))
ifdef VBOX_WITH_DOCS_PACKING
VBOX_DI_VBAPP_MISC_FILES += \
	MacOS/UserManual.pdf
endif
ifdef VBOX_WITH_ADDITIONS_PACKING
 ifneq ($(wildcard $(VBOX_PATH_DIST)/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso),)
 VBOX_DI_VBAPP_MISC_FILES += \
	MacOS/VBoxGuestAdditions.iso
 endif
endif
ifdef VBOX_WITH_EFIFW_PACKING
VBOX_DI_VBAPP_MISC_FILES += \
	MacOS/VBoxEFI32.fd \
	MacOS/VBoxEFI64.fd
endif
 VBOX_DI_VBAPP_DYLIBS += \
	plugins/platforms/libqcocoa$(SUFF_DLL) \
	plugins/platforms/libqminimal$(SUFF_DLL) \
	plugins/platforms/libqoffscreen$(SUFF_DLL)
VBOX_DI_VBAPP_MISC_FILES += \
	$(foreach qtmod, $(VBOX_QT_MOD_NAMES), Frameworks/$(qtmod).framework/Versions/$(VBOX_QT_VERSION_MAJOR)/Resources/Info.plist)

VBOX_DI_VBAPP_SYMLINKS = \
	Resources/VirtualBoxVM.app/Contents/MacOS=>../../../MacOS/ \
	Resources/vmstarter.app/Contents/MacOS=>../../../MacOS/ \
	$(foreach qtmod, $(VBOX_QT_MOD_NAMES) \
	,Frameworks/$(qtmod).framework/Versions/Current=>$(VBOX_QT_VERSION_MAJOR) )

ifdef VBOX_WITH_PYTHON
 # Python XPCOM glue
 VBOX_DI_VBAPP_PYTHON_FILES = \
 	$(VBOXINST_SDK_BINDINGS_XPCOM_PYTHON_FILES) \
 	$(VBOXINST_SDK_INSTALLER_PYTHON_FILES)
endif


# (The dependencies are including way too much here because I'm lazy.)
$(VBOX_PATH_PACK_TMP)/Packages/VirtualBox.pkg: \
		$(foreach f,$(VBOX_INSTALLER_ADD_LANGUAGES), \
			$(VBOX_BRAND_$(f)_VIRTUALBOX_DESCRIPTION_PLIST)) \
		$(foreach f, $(VBOX_DI_VBAPP_DYLIBS) $(VBOX_DI_VBAPP_OTHER_UNIVERSAL_BINS) $(VBOX_DI_VBAPP_UNIVERSAL_PROGS) $(VBOX_DI_VBAPP_OTHER_BINS) $(VBOX_DI_VBAPP_PROGS) $(VBOX_DI_VBAPP_MISC_FILES)\
			,$(call VBOX_DI_FN_DEP_BOTH,VirtualBox.app/Contents/$(f)) ) \
		$(foreach f, $(VBOX_DI_VBAPP_DYLIBS.x86) $(VBOX_DI_VBAPP_MISC_FILES.x86)\
			,$(call VBOX_DI_FN_DEP_32,VirtualBox.app/Contents/$(f)) ) \
		$(foreach f, $(VBOX_DI_VBAPP_DYLIBS.amd64) $(VBOX_DI_VBAPP_MISC_FILES.amd64)\
			,$(call VBOX_DI_FN_DEP_64,VirtualBox.app/Contents/$(f)) ) \
		\
		$(if $(VBOX_WITH_DOCS_PACKING),$(VBOX_ADD_MANUALS),) \
		$(VBOX_BRAND_LICENSE_TXT) \
		$(wildcard $(VBOX_PATH_DI_SRC)/VirtualBox/*) \
		$(wildcard $(VBOX_PATH_DI_SRC)/VirtualBox/*.lproj/*) \
		$$(addprefix $(VBOX_PATH_DIST)/VirtualBox.app/Contents/MacOS/nls/,$(VBOX_INSTALL_LANG_FILES)) \
		\
		$$(wildcard $(VBOX_PATH_DIST)/VirtualBox.app/*) \
		$(filter-out Disabled, $(wildcard $(VBOX_PATH_DIST)/VirtualBox.app/Contents/*)) \
		$$(wildcard $(VBOX_PATH_DIST)/VirtualBox.app/Contents/Resources/*) \
		$$(wildcard $(VBOX_PATH_DIST)/VirtualBox.app/Contents/Resources/VirtualBoxVM.app/Contents/*) \
		$$(wildcard $(VBOX_PATH_DIST)/VirtualBox.app/Contents/Resources/VirtualBoxVM.app/Contents/Resources/*) \
		$$(wildcard $(VBOX_PATH_DIST)/VirtualBox.app/Contents/Resources/VirtualBoxVM.app/Contents/Resources/*.lproj/*) \
		$$(wildcard $(VBOX_PATH_DIST)/VirtualBox.app/Contents/Resources/vmstarter.app/Contents/*) \
		$$(wildcard $(VBOX_PATH_DIST)/VirtualBox.app/Contents/Resources/vmstarter.app/Contents/Resources/*) \
		$$(wildcard $(VBOX_PATH_DIST)/VirtualBox.app/Contents/Resources/vmstarter.app/Contents/Resources/*.lproj/*) \
		$$(wildcard $(VBOX_PATH_DIST)/VirtualBox.app/Contents/Resources/*.lproj/*) \
		$$(wildcard $(VBOX_PATH_DIST)/VirtualBox.app/Contents/MacOS/*) \
		$$(wildcard $(VBOX_PATH_DIST)/VirtualBox.app/Contents/MacOS/additions/*) \
		$$(wildcard $(VBOX_PATH_DIST)/VirtualBox.app/Contents/MacOS/components/*) \
		$$(wildcard $(VBOX_PATH_DIST)/VirtualBox.app/Contents/MacOS/accessible/*) \
		$(addprefix $(VBOX_PATH_DIST)/VirtualBox.app/Contents/MacOS/UnattendedTemplates/, $(VBOX_UNATTENDED_TEMPLATES)) \
		$(if-expr defined(VBOX_WITH_PYTHON), $(addprefix $(VBOX_PATH_DIST)/, $(VBOX_DI_VBAPP_PYTHON_FILES)),) \
                $(if-expr defined(VBOX_WITH_JXPCOM), $(addprefix $(VBOX_PATH_DIST)/, sdk/bindings/xpcom/java/vboxjxpcom.jar),) \
		$(if $(VBOX_WITH_WEBSERVICES),$(VBOX_PATH_DI_SRC)/VirtualBox/org.virtualbox.vboxwebsrv.plist,) \
		$(VBOX_PATH_DI_SRC)/VirtualBox/org.virtualbox.vboxballoonctrl.plist \
		$(VBOX_PATH_DI_SRC)/VirtualBox/org.virtualbox.vboxautostart.plist \
		$(VBOX_PATH_DI_SRC)/VirtualBox/VBoxAutostartDarwin.sh \
               $(if-expr defined(VBOX_WITH_DTRACE), \
                $(foreach f, $(VBOXINST_DTRACE_LIB_ARCH_FILES), \
		 	$(call VBOX_DI_FN_DEP_32,VirtualBox.app/Contents/MacOS/dtrace/lib/x86/$f) \
		 	$(call VBOX_DI_FN_DEP_64,VirtualBox.app/Contents/MacOS/dtrace/lib/amd64/$f)) \
                $(foreach f, $(VBOXINST_DTRACE_TESTCASE_ARCH_FILES), \
		 	$(call VBOX_DI_FN_DEP_32,VirtualBox.app/Contents/MacOS/dtrace/testcase/x86/$f) \
		 	$(call VBOX_DI_FN_DEP_64,VirtualBox.app/Contents/MacOS/dtrace/testcase/amd64/$f)) \
                $(addprefix $(VBOX_PATH_DIST)/VirtualBox.app/Contents/MacOS/dtrace/scripts/,$(VBOXINST_DTRACE_SCRIPTS_FILES)) \
		 ,) \
		$(VBOX_DARWIN_INST_DEP_ON_MAKEFILE)
	$(call MSG_TOOL,pkgbuild,,,$@)
	@# Cleanup any previously failed attempts.
	sudo rm -Rf \
		$@ \
		$(VBOX_PATH_PACK_TMP)/VirtualBox.pkg.root \
		$(VBOX_PATH_PACK_TMP)/VirtualBox.pkg.desc \
		$(VBOX_PATH_PACK_TMP)/VirtualBox.pkg.res
	@# Correct directory permissions are important.
	$(MKDIR) -p \
		$(@D) \
		$(VBOX_PATH_PACK_TMP)/VirtualBox.pkg.desc \
		$(VBOX_PATH_PACK_TMP)/VirtualBox.pkg.res \
		$(VBOX_PATH_PACK_TMP)/VirtualBox.pkg.res/English.lproj
	$(MKDIR) -p -m 0775 \
		$(VBOX_PATH_PACK_TMP)/VirtualBox.pkg.root/Applications
	$(MKDIR) -p -m 0755 $(sort \
		$(VBOX_PATH_VBOX_APP_TMP)/Contents \
		$(VBOX_PATH_VBOX_APP_TMP)/Contents/MacOS \
		$(VBOX_PATH_VBOX_APP_TMP)/Contents/MacOS/components \
		$(VBOX_PATH_VBOX_APP_TMP)/Contents/MacOS/nls \
		$(VBOX_PATH_VBOX_APP_TMP)/Contents/MacOS/accessible \
		$(VBOX_PATH_VBOX_APP_TMP)/Contents/Resources \
		$(VBOX_PATH_VBOX_APP_TMP)/Contents/Resources/VirtualBoxVM.app \
		$(VBOX_PATH_VBOX_APP_TMP)/Contents/Resources/VirtualBoxVM.app/Contents \
		$(VBOX_PATH_VBOX_APP_TMP)/Contents/Resources/vmstarter.app \
		$(VBOX_PATH_VBOX_APP_TMP)/Contents/Resources/vmstarter.app/Contents \
		$(if-expr defined(VBOX_WITH_PYTHON), \
			$(VBOX_PATH_VBOX_APP_TMP)/Contents/MacOS/sdk \
			$(VBOX_PATH_VBOX_APP_TMP)/Contents/MacOS/sdk/installer \
			$(VBOX_PATH_VBOX_APP_TMP)/Contents/MacOS/sdk/installer/vboxapi \
			$(VBOX_PATH_VBOX_APP_TMP)/Contents/MacOS/sdk/bindings/ \
			$(VBOX_PATH_VBOX_APP_TMP)/Contents/MacOS/sdk/bindings/xpcom \
			$(VBOX_PATH_VBOX_APP_TMP)/Contents/MacOS/sdk/bindings/xpcom/python \
			$(VBOX_PATH_VBOX_APP_TMP)/Contents/MacOS/sdk/bindings/xpcom/python/xpcom \
			$(VBOX_PATH_VBOX_APP_TMP)/Contents/MacOS/sdk/bindings/xpcom/python/xpcom/client \
			$(VBOX_PATH_VBOX_APP_TMP)/Contents/MacOS/sdk/bindings/xpcom/python/xpcom/server,) \
                $(if-expr defined(VBOX_WITH_JXPCOM), \
                        $(VBOX_PATH_VBOX_APP_TMP)/Contents/MacOS/sdk/bindings/xpcom/java,) \
		$(addprefix $(VBOX_PATH_VBOX_APP_TMP)/Contents/,$(dir \
			$(VBOX_DI_VBAPP_DYLIBS) \
			$(VBOX_DI_VBAPP_OTHER_UNIVERSAL_BINS) \
			$(VBOX_DI_VBAPP_UNIVERSAL_PROGS) \
			$(VBOX_DI_VBAPP_OTHER_BINS) \
			$(VBOX_DI_VBAPP_PROGS) \
			$(VBOX_DI_VBAPP_MISC_FILES) \
			$(VBOX_DI_VBAPP_DYLIBS.$(KBUILD_TARGET_ARCH)) \
			$(VBOX_DI_VBAPP_MISC_FILES.$(KBUILD_TARGET_ARCH)) \
			))\
		)
# Create the .lproj language directories
	$(MKDIR) -p -m 0755 \
		$(addprefix $(VBOX_PATH_VBOX_APP_TMP)/Contents/Resources/,$(VBOX_INSTALL_LANG_LPROJ))
# Install all supported language files
	$(foreach f, $(VBOX_INSTALL_LANG_FILES) \
		,$(INSTALL) -m 0644 $(VBOX_PATH_DIST)/VirtualBox.app/Contents/MacOS/nls/$(f)    $(VBOX_PATH_VBOX_APP_TMP)/Contents/MacOS/nls/$(f)$(NLTAB))
ifdef VBOX_WITH_WEBSERVICES
	$(INSTALL) -m 0644 $(VBOX_PATH_DI_SRC)/VirtualBox/org.virtualbox.vboxwebsrv.plist       $(VBOX_PATH_VBOX_APP_TMP)/Contents/MacOS/
endif
	$(INSTALL) -m 0644 $(VBOX_PATH_DI_SRC)/VirtualBox/org.virtualbox.vboxballoonctrl.plist  $(VBOX_PATH_VBOX_APP_TMP)/Contents/MacOS/
	$(INSTALL) -m 0644 $(VBOX_PATH_DI_SRC)/VirtualBox/org.virtualbox.vboxautostart.plist    $(VBOX_PATH_VBOX_APP_TMP)/Contents/MacOS/
	$(INSTALL) -m 0755 $(VBOX_PATH_DI_SRC)/VirtualBox/VBoxAutostartDarwin.sh                $(VBOX_PATH_VBOX_APP_TMP)/Contents/MacOS/
# Install the python bridge stuff
ifdef VBOX_WITH_PYTHON
	$(foreach f,$(VBOX_DI_VBAPP_PYTHON_FILES) \
		,$(INSTALL) -m 0644 $(VBOX_PATH_DIST)/$(f)                                      $(VBOX_PATH_VBOX_APP_TMP)/Contents/MacOS/$(f)$(NLTAB) )
	$(INSTALL) -m 0755 $(PATH_ROOT)/src/VBox/Frontends/VBoxShell/vboxshell.py               $(VBOX_PATH_VBOX_APP_TMP)/Contents/MacOS
endif
# Install the java bridge stuff
ifdef VBOX_WITH_JXPCOM
	$(INSTALL) -m 0755 $(VBOX_PATH_DIST)/sdk/bindings/xpcom/java/vboxjxpcom.jar             $(VBOX_PATH_VBOX_APP_TMP)/Contents/MacOS/sdk/bindings/xpcom/java/vboxjxpcom.jar
endif
# Copy misc files.
	$(foreach f,$(VBOX_DI_VBAPP_MISC_FILES) \
		,$(INSTALL) -m 0644 $(VBOX_PATH_DIST)/VirtualBox.app/Contents/$(f)              $(VBOX_PATH_VBOX_APP_TMP)/Contents/$(f)$(NLTAB) )
	$(INSTALL) -m 644 $(VBOX_BRAND_LICENSE_TXT)                                             $(VBOX_PATH_VBOX_APP_TMP)/Contents/Resources/LICENSE
ifdef VBOX_WITH_DOCS_PACKING
	$(foreach f,$(VBOX_ADD_MANUALS) \
		,$(INSTALL) -m 0644 $(f) $(VBOX_PATH_VBOX_APP_TMP)/Contents/MacOS/$(NLTAB))
endif
	@# Create symlinks.
	$(foreach symlink,$(VBOX_DI_VBAPP_SYMLINKS) $(VBOX_DI_VBAPP_SYMLINKS.$(KBUILD_TARGET_ARCH)) \
		,$(LN) -s $(word 2,$(subst =>, ,$(symlink)))                                    $(VBOX_PATH_VBOX_APP_TMP)/Contents/$(word 1,$(subst =>, ,$(symlink)))$(NLTAB))
	@# Copy the dylibs.
	$(foreach dylib, $(VBOX_DI_VBAPP_DYLIBS) $(VBOX_DI_VBAPP_DYLIBS.$(KBUILD_TARGET_ARCH)) \
		,$(INSTALL) -m 0644 $(VBOX_PATH_DIST)/VirtualBox.app/Contents/$(dylib)          $(VBOX_PATH_VBOX_APP_TMP)/Contents/$(dylib)$(NLTAB))
	@# Copy the other binaries.
	$(foreach otherbin, $(VBOX_DI_VBAPP_OTHER_UNIVERSAL_BINS) $(VBOX_DI_VBAPP_OTHER_BINS) \
		,$(INSTALL) -m 0644 $(VBOX_PATH_DIST)/VirtualBox.app/Contents/$(otherbin)       $(VBOX_PATH_VBOX_APP_TMP)/Contents/$(otherbin)$(NLTAB))
	@# Create/copy the universal executable binaries.
	$(foreach otherbin, $(VBOX_DI_VBAPP_UNIVERSAL_PROGS) \
		,$(INSTALL) -m 0755 $(VBOX_PATH_DIST)/VirtualBox.app/Contents/$(otherbin)       $(VBOX_PATH_VBOX_APP_TMP)/Contents/$(otherbin)$(NLTAB))
	@# Copy the binaries.
	$(foreach prog, $(VBOX_DI_VBAPP_PROGS) \
		,$(INSTALL) -m 0755 $(VBOX_PATH_DIST)/VirtualBox.app/Contents/$(prog)       	$(VBOX_PATH_VBOX_APP_TMP)/Contents/$(prog)$(NLTAB))
#ifdef VBOX_WITH_HARDENING - disabled temporarily
if 1
	@# We cannot use @executable_path together with setuid binaries, dyld gets upset about it. So, fix Qt libs and users.
	$(foreach qtmod, $(VBOX_QT_MOD_NAMES) \
		,install_name_tool -id /Applications/VirtualBox.app/Contents/Frameworks/$(qtmod).framework/Versions/$(VBOX_QT_VERSION_MAJOR)/$(qtmod) \
			$(VBOX_PATH_VBOX_APP_TMP)/Contents/Frameworks/$(qtmod).framework/Versions/$(VBOX_QT_VERSION_MAJOR)/$(qtmod)$(NLTAB) )
	$(foreach f, \
		$(VBOX_DI_VBAPP_DYLIBS) \
		$(VBOX_DI_VBAPP_DYLIBS.$(KBUILD_TARGET_ARCH)) \
		$(VBOX_DI_VBAPP_PROGS) \
		,install_name_tool \
			$(foreach qtmod, $(VBOX_QT_MOD_NAMES), \
				-change           @executable_path/../Frameworks/$(qtmod).framework/Versions/$(VBOX_QT_VERSION_MAJOR)/$(qtmod) \
				/Applications/VirtualBox.app/Contents/Frameworks/$(qtmod).framework/Versions/$(VBOX_QT_VERSION_MAJOR)/$(qtmod) \
				-change               $(VBOX_PATH_QT)/Frameworks/$(qtmod).framework/Versions/$(VBOX_QT_VERSION_MAJOR)/$(qtmod) \
				/Applications/VirtualBox.app/Contents/Frameworks/$(qtmod).framework/Versions/$(VBOX_QT_VERSION_MAJOR)/$(qtmod) \
				-change                           $(PATH_SDK_QT)/$(qtmod).framework/Versions/$(VBOX_QT_VERSION_MAJOR)/$(qtmod) \
				/Applications/VirtualBox.app/Contents/Frameworks/$(qtmod).framework/Versions/$(VBOX_QT_VERSION_MAJOR)/$(qtmod) \
				-change                                          $(qtmod).framework/Versions/$(VBOX_QT_VERSION_MAJOR)/$(qtmod) \
				/Applications/VirtualBox.app/Contents/Frameworks/$(qtmod).framework/Versions/$(VBOX_QT_VERSION_MAJOR)/$(qtmod) \
				) \
			$(VBOX_PATH_VBOX_APP_TMP)/Contents/$(f)$(NLTAB) )
endif
ifdef VBOX_UNATTENDED_TEMPLATES
# Unattended installation template scripts.
	$(MKDIR) -p -m 0755 -- $(VBOX_PATH_VBOX_APP_TMP)/Contents/MacOS/UnattendedTemplates
	$(foreach file, $(VBOX_UNATTENDED_TEMPLATES) \
		,$(INSTALL) -m 0655 $(VBOX_PATH_DIST)/VirtualBox.app/Contents/MacOS/UnattendedTemplates/$(file) \
			$(VBOX_PATH_VBOX_APP_TMP)/Contents/MacOS/UnattendedTemplates/$(file)$(NLTAB))
endif
ifdef VBOX_WITH_DTRACE
# DTrace library, testcases and scripts.
	$(MKDIR) -p -m 0755 -- \
		$(VBOX_PATH_VBOX_APP_TMP)/Contents/MacOS/dtrace/lib/$(KBUILD_TARGET_ARCH)/ \
		$(VBOX_PATH_VBOX_APP_TMP)/Contents/MacOS/dtrace/testcase/$(KBUILD_TARGET_ARCH)/ \
		$(VBOX_PATH_VBOX_APP_TMP)/Contents/MacOS/dtrace/scripts/
	$(foreach file, $(addprefix lib/$(KBUILD_TARGET_ARCH)/,$(VBOXINST_DTRACE_LIB_ARCH_FILES)) \
			$(addprefix testcase/$(KBUILD_TARGET_ARCH)/,$(VBOXINST_DTRACE_TESTCASE_ARCH_FILES)) \
       		$(addprefix scripts/,$(VBOXINST_DTRACE_SCRIPTS_FILES)) \
		,$(INSTALL) -m 0655 $(VBOX_PATH_DIST)/VirtualBox.app/Contents/MacOS/dtrace/$(file) \
			$(VBOX_PATH_VBOX_APP_TMP)/Contents/MacOS/dtrace/$(file)$(NLTAB))
endif
	@# Signed the binaries and the application bundle.
ifdef VBOX_SIGNING_MODE
	$(foreach qtmod, $(VBOX_QT_MOD_NAMES) \
		,$(NLTAB)$(call VBOX_SIGN_MACHO_FN,$(VBOX_PATH_VBOX_APP_TMP)/Contents/Frameworks/$(qtmod).framework/Versions/$(VBOX_QT_VERSION_MAJOR)/$(qtmod),org.virtualbox.app.frameworks.$(qtmod)) )
	$(foreach qtmod, $(VBOX_QT_MOD_NAMES) \
		,$(NLTAB)$(call VBOX_SIGN_BUNDLE_FN,$(VBOX_PATH_VBOX_APP_TMP)/Contents/Frameworks/$(qtmod).framework/Versions/$(VBOX_QT_VERSION_MAJOR),org.virtualbox.app.frameworks.$(qtmod)) )
	$(foreach dylib, \
		$(VBOX_DI_VBAPP_DYLIBS) \
		$(VBOX_DI_VBAPP_DYLIBS.$(KBUILD_TARGET_ARCH)) \
		, $(NLTAB)$(call VBOX_SIGN_MACHO_FN,$(VBOX_PATH_VBOX_APP_TMP)/Contents/$(dylib),org.virtualbox.app.macos.$(notdir $(dylib))) )
	$(foreach bin, $(VBOX_DI_VBAPP_UNIVERSAL_PROGS) \
		, $(NLTAB)$(call VBOX_SIGN_MACHO_FN,$(VBOX_PATH_VBOX_APP_TMP)/Contents/$(bin),org.virtualbox.app.macos.$(notdir $(bin))) )
	$(foreach other, $(VBOX_DI_VBAPP_OTHER_UNIVERSAL_BINS) $(VBOX_DI_VBAPP_OTHER_BINS)\
		, $(NLTAB)$(call VBOX_SIGN_MACHO_FN,$(VBOX_PATH_VBOX_APP_TMP)/Contents/$(other),org.virtualbox.app.macos.$(notdir $(other))) )
	$(foreach bin, $(filter-out MacOS/VirtualBox,$(VBOX_DI_VBAPP_PROGS)) \
		, $(NLTAB)$(call VBOX_SIGN_MACHO_FN,$(VBOX_PATH_VBOX_APP_TMP)/Contents/$(bin),org.virtualbox.app.macos.$(notdir $(bin))) )
	$(foreach file, $(if-expr defined(VBOX_WITH_WEBSERVICES),MacOS/org.virtualbox.vboxwebsrv.plist,) \
			MacOS/org.virtualbox.vboxballoonctrl.plist \
			MacOS/org.virtualbox.vboxautostart.plist \
			MacOS/VBoxAutostartDarwin.sh \
			$(if-expr defined(VBOX_WITH_PYTHON),$(addprefix MacOS/, $(VBOX_DI_VBAPP_PYTHON_FILES) vboxshell.py),) \
			$(if-expr defined(VBOX_WITH_JXPCOM),MacOS/sdk/bindings/xpcom/java/vboxjxpcom.jar,) \
			$(filter MacOS/%,$(VBOX_DI_VBAPP_MISC_FILES)) \
                       $(if-expr defined(VBOX_WITH_DOCS_PACKING),$(addprefix MacOS/,$(VBOX_ADD_MANUALS)),) \
                       $(if-expr defined(VBOX_WITH_DTRACE),\
				$(addprefix MacOS/dtrace/lib/$(KBUILD_TARGET_ARCH)/,$(VBOXINST_DTRACE_LIB_ARCH_FILES)) \
				$(addprefix MacOS/dtrace/testcase/$(KBUILD_TARGET_ARCH)/,$(VBOXINST_DTRACE_TESTCASE_ARCH_FILES)) \
       			$(addprefix MacOS/dtrace/scripts/,$(VBOXINST_DTRACE_SCRIPTS_FILES)) ,) \
			$(addprefix MacOS/nls/,$(VBOX_INSTALL_LANG_FILES)) \
		, $(NLTAB)$(call VBOX_SIGN_FILE_FN,$(VBOX_PATH_VBOX_APP_TMP)/Contents/$(file),org.virtualbox.app.$(tolower $(subst $(SP),,$(subst /,.,$(file))))) )

	$(call VBOX_SIGN_BUNDLE_FN,$(VBOX_PATH_VBOX_APP_TMP)/Contents/Resources/VirtualBoxVM.app,,)
	$(call VBOX_SIGN_BUNDLE_FN,$(VBOX_PATH_VBOX_APP_TMP)/Contents/Resources/vmstarter.app,,)
	$(call VBOX_SIGN_BUNDLE_FN,$(VBOX_PATH_VBOX_APP_TMP),,--deep)
endif
	@# Set the correct owner and set the set-user-ID-on-execution bit on the relevant executables.
	sudo chown -R root:admin $(VBOX_PATH_PACK_TMP)/VirtualBox.pkg.root
	sudo chmod u+s $(VBOX_PATH_VBOX_APP_TMP)/Contents/MacOS/VBoxNetAdpCtl
ifdef VBOX_WITH_HARDENING
	sudo chmod u+s \
		$(foreach bin,VBoxHeadless VirtualBoxVM VBoxNetDHCP VBoxNetNAT,\
			$(VBOX_PATH_VBOX_APP_TMP)/Contents/MacOS/$(bin))
endif
	@# Do keyword replacement in the package info and description files.
	$(SED) \
		-e 's/@VBOX_VERSION_STRING@/$(VBOX_VERSION_STRING)/g' \
		-e 's/@VBOX_VERSION_MAJOR@/$(VBOX_VERSION_MAJOR)/g' \
		-e 's/@VBOX_VERSION_MINOR@/$(VBOX_VERSION_MINOR)/g' \
		-e 's/@VBOX_VERSION_BUILD@/$(VBOX_VERSION_BUILD)/g' \
		-e 's/@VBOX_VENDOR@/$(VBOX_VENDOR)/g' \
		-e 's/@VBOX_PRODUCT@/$(VBOX_PRODUCT)/g' \
		-e 's/@VBOX_C_YEAR@/$(VBOX_C_YEAR)/g' \
		--output $(VBOX_PATH_PACK_TMP)/VirtualBox.pkg.desc/PkgBuildComponent.plist \
		$(VBOX_PATH_DI_SRC)/VirtualBox/PkgBuildComponent.plist
	@# Copy the resources.
	$(INSTALL) -m 0755 $(VBOX_PATH_DI_SRC)/VirtualBox/preflight                         $(VBOX_PATH_PACK_TMP)/VirtualBox.pkg.res/
ifdef VBOX_WITH_HARDENING
	$(INSTALL) -m 0755 $(VBOX_PATH_DI_SRC)/VirtualBox/postflight                        $(VBOX_PATH_PACK_TMP)/VirtualBox.pkg.res/
else
	$(SED) -s '/WITH_HARDENING/d' -o $(VBOX_PATH_PACK_TMP)/VirtualBox.pkg.res/postflight $(VBOX_PATH_DI_SRC)/VirtualBox/postflight
	$(CHMOD) 0755 $(VBOX_PATH_PACK_TMP)/VirtualBox.pkg.res/postflight
endif
	@# Build the package.
	$(VBOX_PKGBUILD) \
       	--root   $(VBOX_PATH_PACK_TMP)/VirtualBox.pkg.root/Applications/ \
		--component-plist $(VBOX_PATH_PACK_TMP)/VirtualBox.pkg.desc/PkgBuildComponent.plist \
		--script $(VBOX_PATH_PACK_TMP)/VirtualBox.pkg.res \
		--identifier org.virtualbox.pkg.virtualbox \
		--version $(VBOX_VERSION_MAJOR).$(VBOX_VERSION_MINOR).$(VBOX_VERSION_BUILD) \
		--install-location /Applications/ \
		--ownership preserve \
		--preserve-xattr \
		$(if $(VBOX_MACOSX_INSTALLER_SIGN),--sign "$(VBOX_MACOSX_INSTALLER_SIGN)",) \
		$@
ifdef VBOX_SIGNING_MODE
 ifdef VBOX_WITH_CORP_CODE_SIGNING
	@# Sign the created pkg.
	$(call VBOX_SIGN_PKG_FN,$@,org.virtualbox.pkg.virtualbox)
 endif
endif
	@# Cleanup
	sudo chown -R "$(shell whoami)" \
		$(VBOX_PATH_PACK_TMP)/VirtualBox.pkg.root
	sudo chmod -R a-s \
		$(VBOX_PATH_PACK_TMP)/VirtualBox.pkg.root
	sudo rm -Rf \
		$(VBOX_PATH_PACK_TMP)/VirtualBox.pkg.root \
		$(VBOX_PATH_PACK_TMP)/VirtualBox.pkg.desc \
		$(VBOX_PATH_PACK_TMP)/VirtualBox.pkg.res

#
# The VirtualBox CLI wrapper scripts.
#
$(VBOX_PATH_PACK_TMP)/Packages/VirtualBoxCLI.pkg: \
		$$(wildcard $(VBOX_PATH_DI_SRC)/VirtualBoxCLI/* \
		            $(VBOX_PATH_DI_SRC)/VirtualBoxCLI/*.lproj/*) \
		$(foreach f,$(VBOX_INSTALLER_ADD_LANGUAGES) \
			,$(VBOX_BRAND_$(f)_VIRTUALBOXCLI_DESCRIPTION_PLIST)) \
		$(VBOX_DARWIN_INST_DEP_ON_MAKEFILE)
	$(call MSG_TOOL,pkgbuild,,,$@)
	@# Cleanup any previously failed attempts.
	sudo rm -Rf \
		$@ \
		$(VBOX_PATH_PACK_TMP)/VirtualBoxCLI.pkg.root \
		$(VBOX_PATH_PACK_TMP)/VirtualBoxCLI.pkg.desc \
		$(VBOX_PATH_PACK_TMP)/VirtualBoxCLI.pkg.res
	@# Correct directory permissions are important.
	$(MKDIR) -p \
		$(@D) \
		$(VBOX_PATH_PACK_TMP)/VirtualBoxCLI.pkg.desc \
		$(VBOX_PATH_PACK_TMP)/VirtualBoxCLI.pkg.res \
		$(VBOX_PATH_PACK_TMP)/VirtualBoxCLI.pkg.res/English.lproj
	$(MKDIR) -p -m 0755 \
		$(VBOX_PATH_PACK_TMP)/VirtualBoxCLI.pkg.root/usr \
		$(VBOX_PATH_PACK_TMP)/VirtualBoxCLI.pkg.root/usr/local/bin
	@# Generate the wrapper scripts.
	$(APPEND) -tn  $(VBOX_PATH_PACK_TMP)/VirtualBoxCLI.pkg.root/usr/local/bin/VirtualBox \
		'#!/bin/bash' 'exec /Applications/VirtualBox.app/Contents/MacOS/VirtualBox "$$@"'
	$(APPEND) -tn  $(VBOX_PATH_PACK_TMP)/VirtualBoxCLI.pkg.root/usr/local/bin/VirtualBoxVM \
		'#!/bin/bash' 'exec /Applications/VirtualBox.app/Contents/MacOS/VirtualBoxVM "$$@"'
	$(APPEND) -tn  $(VBOX_PATH_PACK_TMP)/VirtualBoxCLI.pkg.root/usr/local/bin/VBoxManage \
		'#!/bin/bash' 'exec /Applications/VirtualBox.app/Contents/MacOS/VBoxManage "$$@"'
	$(APPEND) -tn $(VBOX_PATH_PACK_TMP)/VirtualBoxCLI.pkg.root/usr/local/bin/VBoxVRDP \
		'#!/bin/bash' 'exec /Applications/VirtualBox.app/Contents/MacOS/VBoxHeadless "$$@"'
	$(APPEND) -tn $(VBOX_PATH_PACK_TMP)/VirtualBoxCLI.pkg.root/usr/local/bin/VBoxHeadless \
		'#!/bin/bash' 'exec /Applications/VirtualBox.app/Contents/MacOS/VBoxHeadless "$$@"'
ifdef VBOX_WITH_WEBSERVICES
	$(APPEND) -tn $(VBOX_PATH_PACK_TMP)/VirtualBoxCLI.pkg.root/usr/local/bin/vboxwebsrv \
		'#!/bin/bash' 'exec /Applications/VirtualBox.app/Contents/MacOS/vboxwebsrv "$$@"'
endif
if defined(VBOX_WITH_VBOX_IMG) || defined(VBOX_WITH_TESTCASES)
	$(APPEND) -tn $(VBOX_PATH_PACK_TMP)/VirtualBoxCLI.pkg.root/usr/local/bin/vbox-img \
		'#!/bin/bash' 'exec /Applications/VirtualBox.app/Contents/MacOS/vbox-img "$$@"'
endif
if defined(VBOX_WITH_VBOXIMGMOUNT)
	$(APPEND) -tn $(VBOX_PATH_PACK_TMP)/VirtualBoxCLI.pkg.root/usr/local/bin/vboximg-mount \
		'#!/bin/bash' 'exec /Applications/VirtualBox.app/Contents/MacOS/vboximg-mount "$$@"'
endif
	$(APPEND) -tn $(VBOX_PATH_PACK_TMP)/VirtualBoxCLI.pkg.root/usr/local/bin/VBoxBugReport \
		'#!/bin/bash' 'exec /Applications/VirtualBox.app/Contents/MacOS/VBoxBugReport "$$@"'
	$(APPEND) -tn $(VBOX_PATH_PACK_TMP)/VirtualBoxCLI.pkg.root/usr/local/bin/VBoxBalloonCtrl \
		'#!/bin/bash' 'exec /Applications/VirtualBox.app/Contents/MacOS/VBoxBalloonCtrl "$$@"'
	$(APPEND) -tn $(VBOX_PATH_PACK_TMP)/VirtualBoxCLI.pkg.root/usr/local/bin/VBoxAutostart \
		'#!/bin/bash' 'exec /Applications/VirtualBox.app/Contents/MacOS/VBoxAutostart "$$@"'
ifdef VBOX_WITH_DTRACE
	$(APPEND) -tn $(VBOX_PATH_PACK_TMP)/VirtualBoxCLI.pkg.root/usr/local/bin/VBoxDTrace \
		'#!/bin/bash' 'exec /Applications/VirtualBox.app/Contents/MacOS/VBoxDTrace "$$@"'
endif
	@# Set the correct owners and file permissions.
	sudo chmod 0755 $(VBOX_PATH_PACK_TMP)/VirtualBoxCLI.pkg.root/usr/local/bin/*
	sudo chown    root:admin $(VBOX_PATH_PACK_TMP)/VirtualBoxCLI.pkg.root
	sudo chown -R root:wheel $(VBOX_PATH_PACK_TMP)/VirtualBoxCLI.pkg.root/usr
	@# Build the package.
	$(VBOX_PKGBUILD) \
       	--root   $(VBOX_PATH_PACK_TMP)/VirtualBoxCLI.pkg.root/usr/local/bin \
		--identifier org.virtualbox.pkg.virtualboxcli \
		--version $(VBOX_VERSION_MAJOR).$(VBOX_VERSION_MINOR).$(VBOX_VERSION_BUILD) \
		--install-location /usr/local/bin \
		--ownership preserve \
		$(if $(VBOX_MACOSX_INSTALLER_SIGN),--sign "$(VBOX_MACOSX_INSTALLER_SIGN)",) \
		$@
ifdef VBOX_SIGNING_MODE
 ifdef VBOX_WITH_CORP_CODE_SIGNING
	@# Sign the created pkg.
	$(call VBOX_SIGN_PKG_FN,$@,org.virtualbox.pkg.virtualboxcli)
 endif
endif
	@# Cleanup
	sudo chown -R "$(shell whoami)" \
		$(VBOX_PATH_PACK_TMP)/VirtualBoxCLI.pkg.root
	sudo rm -Rf \
		$(VBOX_PATH_PACK_TMP)/VirtualBoxCLI.pkg.root \
		$(VBOX_PATH_PACK_TMP)/VirtualBoxCLI.pkg.desc \
		$(VBOX_PATH_PACK_TMP)/VirtualBoxCLI.pkg.res

ifdef VBOX_WITH_FUSE_PACKING
#
# The FUSE for macOS core package.
#
VBOX_PATH_FUSE_CORE_PKG ?= $(lastword $(sort $(wildcard $(KBUILD_DEVTOOLS_TRG)/osxfuse/v*)))/Core.pkg
$(VBOX_PATH_PACK_TMP)/Packages/OSXFuseCore.pkg: \
		$(VBOX_PATH_FUSE_CORE_PKG)
	$(call MSG_TOOL,Preparing FUSE for macOS core package,,,$@)
	@# Cleanup any previously failed attempts.
	sudo rm -Rf $@
	pkgutil --flatten $(VBOX_PATH_FUSE_CORE_PKG) $@
endif


#
# Aliases.
#
VBoxKEXTs.pkg:        $(VBOX_PATH_PACK_TMP)/Packages/VBoxKEXTs.pkg
VirtualBoxCLI.pkg:    $(VBOX_PATH_PACK_TMP)/Packages/VirtualBoxCLI.pkg
VirtualBox.pkg:       $(VBOX_PATH_PACK_TMP)/Packages/VirtualBox.pkg
VirtualBox.mpkg:      $(VBOX_PATH_PACK_TMP)/DiskImage/VirtualBox.pkg
VirtualBox.dmg:       $(VBOX_PATH_DIST)/VirtualBox-$(VBOX_VERSION_STRING)-r$(VBOX_SVN_REV).dmg