ROM 		= ../rom.bin

BUILD_DIR 	= .build

SRC_DIRS 	= programs system

# VASM 		= ~/6502/vasm6502
ASM		 	= ca65
ASMFLAGS 	= -g --cpu 65C02 $(foreach srcdir, $(SRC_DIRS), -I $(srcdir))
ASMDEPFLAGS	= --create-dep .dependencies

LD 			= ld65
LDFLAGS 	= -C linker.conf

# DEPENDS		= $(shell $(VASM) -depend=make $(MAIN))

-include .dependencies

$(BUILD_DIR):
	mkdir $@

.PHONY: default test clean
default: $(ROM)
test: ../test.bin


$(ROM): $(BUILD_DIR)/main.o
	$(LD) $(LDFLAGS) $< -o $@

../test.bin: $(BUILD_DIR)/test.o
	# $(VASM) -dotdir -opt-branch -wdc02 -chklabels test.asm6502 
	$(LD) $(LDFLAGS) $(BUILD_DIR)/test.o -o ../test.bin

$(BUILD_DIR)/%.o: %.s65 | $(BUILD_DIR)
	$(ASM) $(ASMFLAGS) $(ASMDEPFLAGS) $< -o $@


clean:
	rm -r $(BUILD_DIR)
	rm $(ROM)