.PHONY: all clean distclean install

PREFIX := $(PJ_PREFIX)

BOOTLDR_IMAGE := norboot.bin
PL1029_IMAGE_STUB := prostub.bin
BOOTLDR_INSTALLER := norinstall.bin
PL1029_BOOTLDR_DIR := proboot-1
PL1029_BOOTLDR_STUB_DIR := prostub-1.0

all: $(BOOTLDR_IMAGE) $(BOOTLDR_INSTALLER) $(PL1029_IMAGE_STUB)

$(DEFAULT_SH):
	cp $(PL1029_BOOTLDR_DIR)/$(DEFAULT_SH) $(PL1029_BOOTLDR_DIR)/default.sh

$(BOOTLDR_IMAGE): $(DEFAULT_SH)
	make -C $(PL1029_BOOTLDR_DIR)
	make -C $(PL1029_BOOTLDR_DIR) norboot.bin

$(BOOTLDR_INSTALLER): $(DEFAULT_SH)
	make -C $(PL1029_BOOTLDR_DIR) norinstall.bin

$(PL1029_IMAGE_STUB):
	make -C $(PL1029_BOOTLDR_STUB_DIR)

clean:
distclean:
	make -C $(PL1029_BOOTLDR_DIR)/ clean
	make -C $(PL1029_BOOTLDR_STUB_DIR)/ clean
	
install: all
	[ "$$PJ_NAME" != "" ]
	[ "$$PJ_PREFIX" != "" ]
	mkdir -p $$PJ_PREFIX/boot
	cp $(PL1029_BOOTLDR_DIR)/$(BOOTLDR_IMAGE) $(PREFIX)/boot
	cp $(PL1029_BOOTLDR_DIR)/$(BOOTLDR_INSTALLER) $(PREFIX)/boot
	cp $(PL1029_BOOTLDR_STUB_DIR)/$(PL1029_IMAGE_STUB) $(PREFIX)/boot
