126b5ececSMatt Madia# Set anyboot file name and directory defaults.
226b5ececSMatt MadiaHAIKU_ANYBOOT_NAME ?= $(HAIKU_DEFAULT_ANYBOOT_NAME) ;
326b5ececSMatt MadiaHAIKU_ANYBOOT_DIR ?= $(HAIKU_DEFAULT_ANYBOOT_DIR) ;
426b5ececSMatt MadiaHAIKU_ANYBOOT = $(HAIKU_ANYBOOT_NAME) ;
526b5ececSMatt MadiaHAIKU_ANYBOOT_LABEL ?= $(HAIKU_DEFAULT_ANYBOOT_LABEL) ;
626b5ececSMatt Madia
7100e9192SMichael Lotzrule BuildAnybootImage anybootImage : mbrPart : isoPart : imageFile {
8100e9192SMichael Lotz	local anyboot = <build>anyboot ;
9100e9192SMichael Lotz
10100e9192SMichael Lotz	Depends $(anybootImage) : $(anyboot) ;
11100e9192SMichael Lotz	Depends $(anybootImage) : $(isoPart) ;
12100e9192SMichael Lotz	Depends $(anybootImage) : $(mbrPart) ;
13100e9192SMichael Lotz	Depends $(anybootImage) : $(imageFile) ;
14100e9192SMichael Lotz
152f0ca697SAlexander von Gluck IV	BuildAnybootImage1 $(anybootImage) : $(anyboot) $(mbrPart) $(isoPart) $(imageFile) ;
16100e9192SMichael Lotz}
17100e9192SMichael Lotz
18100e9192SMichael Lotzactions BuildAnybootImage1 {
192f0ca697SAlexander von Gluck IV	$(2[1]) -b $(2[2]) $(2[3]) $(2[4]) $(1)
20100e9192SMichael Lotz}
21100e9192SMichael Lotz
221f96a3cbSJessica Hamiltonrule BuildAnybootImageEfi anybootImage : mbrPart : efiPart : isoPart : imageFile {
231f96a3cbSJessica Hamilton	local anyboot = <build>anyboot ;
241f96a3cbSJessica Hamilton
251f96a3cbSJessica Hamilton	Depends $(anybootImage) : $(anyboot) ;
261f96a3cbSJessica Hamilton	Depends $(anybootImage) : $(isoPart) ;
271f96a3cbSJessica Hamilton	Depends $(anybootImage) : $(mbrPart) ;
281f96a3cbSJessica Hamilton	Depends $(anybootImage) : $(efiPart) ;
291f96a3cbSJessica Hamilton	Depends $(anybootImage) : $(imageFile) ;
301f96a3cbSJessica Hamilton
311f96a3cbSJessica Hamilton	BuildAnybootImageEfi1 $(anybootImage) : $(anyboot) $(mbrPart) $(efiPart) $(isoPart) $(imageFile) ;
321f96a3cbSJessica Hamilton}
331f96a3cbSJessica Hamilton
341f96a3cbSJessica Hamiltonactions BuildAnybootImageEfi1 {
351f96a3cbSJessica Hamilton	$(2[1]) -b $(2[2]) -e $(2[3]) $(2[4]) $(2[5]) $(1)
361f96a3cbSJessica Hamilton}
371f96a3cbSJessica Hamilton
3826b5ececSMatt Madialocal baseMBR = base_mbr.bin ;
3911e8ecddSJessica Hamiltonlocal mbrSource = [ FDirName $(HAIKU_TOP) src bin writembr mbr.S ] ;
4011e8ecddSJessica HamiltonBuildMBR $(baseMBR) : $(mbrSource) ;
4126b5ececSMatt MadiaMakeLocate $(baseMBR) : $(HAIKU_OUTPUT_DIR) ;
4226b5ececSMatt MadiaMakeLocate $(HAIKU_ANYBOOT) : $(HAIKU_ANYBOOT_DIR) ;
431f96a3cbSJessica Hamilton
4459bba8b9SAlexander von Gluck IVif $(HAIKU_ANYBOOT_LEGACY) = 1 {
4559bba8b9SAlexander von Gluck IV	BuildAnybootImage $(HAIKU_ANYBOOT) : $(baseMBR) : $(HAIKU_CD_BOOT_IMAGE)
4659bba8b9SAlexander von Gluck IV		: $(HAIKU_IMAGE_NAME) ;
4759bba8b9SAlexander von Gluck IV} else {
481f96a3cbSJessica Hamilton	local efiLoader = haiku_loader.efi ;
491f96a3cbSJessica Hamilton	local efiPartition = esp.image ;
501f96a3cbSJessica Hamilton	MakeLocate $(efiPartition) ;
511f96a3cbSJessica Hamilton	BuildEfiSystemPartition $(efiPartition) : $(efiLoader) ;
521f96a3cbSJessica Hamilton	BuildAnybootImageEfi $(HAIKU_ANYBOOT) : $(baseMBR) : $(efiPartition) : $(HAIKU_CD_BOOT_IMAGE)
531f96a3cbSJessica Hamilton		: $(HAIKU_IMAGE_NAME) ;
541f96a3cbSJessica Hamilton}
55100e9192SMichael Lotz
56100e9192SMichael Lotz# TODO: this one seems to cause the build to fail each other run (caching?)
5726b5ececSMatt Madia#RmTemps $(HAIKU_ANYBOOT) : $(baseMBR) ;
5826b5ececSMatt MadiaRmTemps $(HAIKU_ANYBOOT) : $(HAIKU_CD_BOOT_IMAGE) ;
5926b5ececSMatt MadiaRmTemps $(HAIKU_ANYBOOT) : $(HAIKU_IMAGE_NAME) ;
6026b5ececSMatt MadiaRmTemps $(HAIKU_ANYBOOT) : $(HAIKU_BOOT_FLOPPY) ;
61100e9192SMichael Lotz
62100e9192SMichael LotzNotFile haiku-anyboot-image ;
6326b5ececSMatt MadiaDepends haiku-anyboot-image : $(HAIKU_ANYBOOT) ;
64