BUILD_DIR_PURE := build.raspbian

BUILD_DIR := $(BUILD_DIR_PURE)/

PITREX_DIR := ../pitrex/pitrex/
VECTREX_DIR := ../pitrex/vectrex/
CFLAGS := -Ofast -I../pitrex/ -DPIZERO -DRPI0
CC := gcc

.PHONY: pitrexLib
.PHONY: dirCheck

all:	asteroids_sbt

dirCheck:
	if [ ! -d $(BUILD_DIR_PURE) ]; then mkdir $(BUILD_DIR_PURE); fi

pitrexLib:
	$(MAKE) -C $(PITREX_DIR) -f Makefile.raspbian all
	$(MAKE) -C $(VECTREX_DIR) -f Makefile.raspbian all

$(BUILD_DIR)gmain.o: gmain.c rom.h game.c
	$(CC) $(CFLAGS) -c -o $(BUILD_DIR)gmain.o gmain.c

rom.h: game.c
	@echo rom.h is rebuilt when game.c is rebuilt.

roms:
	@cp `md5sum \`locate 035127.02\` 2>/dev/null | fgrep e6c34b639fe16deff0f951be63076812 | head -1 | tr ' ' '\n' | tail -1` . 2> /dev/null || ( echo You need to follow the instructions in README-ROMS.txt in the main directory && exit 1 )
	@cp `md5sum \`locate 035145.02\` 2>/dev/null | fgrep ca4f0146fb806f58a12e3e69d8fd7277 | head -1 | tr ' ' '\n' | tail -1` . 2> /dev/null || ( echo You need to follow the instructions in README-ROMS.txt in the main directory && exit 1 )
	@cp `md5sum \`locate 035143.02\` 2>/dev/null | fgrep dd35aef4a17c271151413cbb0893b550 | head -1 | tr ' ' '\n' | tail -1` . 2> /dev/null || ( echo You need to follow the instructions in README-ROMS.txt in the main directory && exit 1 )
	@cp `md5sum \`locate 035144.02\` 2>/dev/null | fgrep 8010044e056c7a2ba3538a8c68b773d2 | head -1 | tr ' ' '\n' | tail -1` . 2> /dev/null || ( echo You need to follow the instructions in README-ROMS.txt in the main directory && exit 1 )

035127.02:
	@echo "if you have 035127.02 somewhere else on this system (and have locate installed),"
	@echo "you may be able to copy it here more easily by cd-ing to the asteroids_sbt" 
	@echo "directory, and typing:  make -f Makefile.raspbian roms"
	@echo "Otherwise follow the instructions in README-ROMS.txt in the main directory."
	@exit 1

035145.02:
	@echo "if you have 035145.02 somewhere else on this system (and have locate installed),"
	@echo "you may be able to copy it here more easily by cd-ing to the asteroids_sbt" 
	@echo "directory, and typing:  make -f Makefile.raspbian roms"
	@echo "Otherwise follow the instructions in README-ROMS.txt in the main directory."
	@exit 1

035143.02:
	@echo "if you have 035143.02 somewhere else on this system (and have locate installed),"
	@echo "you may be able to copy it here more easily by cd-ing to the asteroids_sbt" 
	@echo "directory, and typing:  make -f Makefile.raspbian roms"
	@echo "Otherwise follow the instructions in README-ROMS.txt in the main directory."
	@exit 1

035144.02:
	@echo "if you have 035144.02 somewhere else on this system (and have locate installed),"
	@echo "you may be able to copy it here more easily by cd-ing to the asteroids_sbt" 
	@echo "directory, and typing:  make -f Makefile.raspbian roms"
	@echo "Otherwise follow the instructions in README-ROMS.txt in the main directory."
	@exit 1

game.c: trans 035127.02 035145.02 035143.02 035144.02
	./trans > game.c

trans: trans.c
	$(CC) -o trans trans.c

$(BUILD_DIR)dvg.o: dvg.c rom.h dvg.h
	$(CC) $(CFLAGS) -c -o $(BUILD_DIR)dvg.o dvg.c

asteroids_sbt: dirCheck pitrexLib $(BUILD_DIR)gmain.o $(BUILD_DIR)dvg.o
	$(RM) asteroids_sbt
	$(CC) $(CFLAGS) -o asteroids_sbt \
	$(PITREX_DIR)$(BUILD_DIR)bcm2835.o \
	$(PITREX_DIR)$(BUILD_DIR)pitrexio-gpio.o \
	$(VECTREX_DIR)$(BUILD_DIR)vectrexInterface.o \
	$(VECTREX_DIR)$(BUILD_DIR)osWrapper.o \
	$(VECTREX_DIR)$(BUILD_DIR)baremetalUtil.o \
	$(BUILD_DIR)gmain.o \
	$(BUILD_DIR)dvg.o

clean:
	$(RM) $(BUILD_DIR)*.*
	rm -f asteroids_sbt

install:
	install -o root -g games -m 6555 asteroids_sbt /opt/pitrex/bin
