ifdef $(GENDEV)
ROOTDIR = $(GENDEV)
else
ROOTDIR = /opt/toolchains/sega
endif

BOOTBLOCKDIR = $(ROOTDIR)/bootblocks

MDPREFIX = $(ROOTDIR)/m68k-elf/bin/m68k-elf-
AS = $(MDPREFIX)as
LD = $(MDPREFIX)ld
RM = rm -f

all: us_ipl eu_ipl jp_ipl

us_ipl:
	$(RM) crt0.o US_BOOT.BIN
	$(AS) -m68000 --register-prefix-optional --defsym REGION_US=1 crt0.s -o crt0.o
	$(LD) --oformat=binary --section-start=.text=0 crt0.o -o US_BOOT.BIN

eu_ipl:
	$(RM) crt0.o EU_BOOT.BIN
	$(AS) -m68000 --register-prefix-optional --defsym REGION_EU=1 crt0.s -o crt0.o
	$(LD) --oformat=binary --section-start=.text=0 crt0.o -o EU_BOOT.BIN

jp_ipl:
	$(RM) crt0.o JP_BOOT.BIN
	$(AS) -m68000 --register-prefix-optional --defsym REGION_JP=1 crt0.s -o crt0.o
	$(LD) --oformat=binary --section-start=.text=0 crt0.o -o JP_BOOT.BIN

install:
	cp US_BOOT.BIN $(BOOTBLOCKDIR)/
	cp EU_BOOT.BIN $(BOOTBLOCKDIR)/
	cp JP_BOOT.BIN $(BOOTBLOCKDIR)/

clean:
	$(RM) crt0.o US_BOOT.BIN EU_BOOT.BIN JP_BOOT.BIN
