BUILD_DIR_PURE := build.raspbian
BUILD_DIR := $(BUILD_DIR_PURE)/

PITREX_DIR := ../pitrex/pitrex/
VECTREX_DIR := ../pitrex/vectrex/
CFLAGS := -g -I ../pitrex/ -I libmsvg/src -DPIZERO -DRPI0
# CFLAGS := -Ofast -I../pitrex/ -DPIZERO -DRPI0
CC := gcc -DPITREX

.PHONY: pitrexLib
.PHONY: dirCheck


all:	dirCheck pitrexLib testnew
	# echo sudo LD_LIBRARY_PATH=/usr/local/lib/arm-linux-gnueabihf ./testnew
	sudo ./testnew
	echo All up to date

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)usvg.o: usvg.c svg.h
	$(CC) $(CFLAGS) -o $(BUILD_DIR)usvg.o -c usvg.c

$(BUILD_DIR)testnew.o: testnew.c
	$(CC) $(CFLAGS) `geos-config --cflags` -o $(BUILD_DIR)testnew.o -c testnew.c

$(BUILD_DIR)polygon.o: polygon.c
	$(CC) $(CFLAGS) `geos-config --cflags` -o $(BUILD_DIR)polygon.o -c polygon.c

$(BUILD_DIR)window.o: window.c
	$(CC) $(CFLAGS) `geos-config --cflags` -o $(BUILD_DIR)window.o -c window.c

$(BUILD_DIR)polygon.o: polygon.c polygon-geos.h polygon-dev.h polygon.h
	$(CC) -c ${CFLAGS} `geos-config --cflags` -o $(BUILD_DIR)polygon.o polygon.c

$(BUILD_DIR)polygon-geos.o: polygon-geos.c polygon-geos.h polygon.h
	$(CC) -c ${CFLAGS} `geos-config --cflags` -o $(BUILD_DIR)polygon-geos.o polygon-geos.c

$(BUILD_DIR)polygon-dev.o: polygon-dev.c polygon-dev.h polygon.h
	$(CC) -c ${CFLAGS} `geos-config --cflags` -o $(BUILD_DIR)polygon-dev.o polygon-dev.c

$(BUILD_DIR)geostree.o: geostree.c polygon.h polygon-dev.h polygon-geos.h
	$(CC) -c ${CFLAGS} `geos-config --cflags` -o $(BUILD_DIR)geostree.o geostree.c

testnew: $(BUILD_DIR)testnew.o $(BUILD_DIR)polygon.o $(BUILD_DIR)polygon-dev.o $(BUILD_DIR)polygon-geos.o $(BUILD_DIR)geostree.o $(BUILD_DIR)usvg.o $(BUILD_DIR)window.o pitrexLib
	$(RM) testnew
	$(CC) $(CFLAGS) -o testnew \
	$(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)testnew.o \
	$(BUILD_DIR)polygon.o \
	$(BUILD_DIR)window.o \
	$(BUILD_DIR)polygon-dev.o \
	$(BUILD_DIR)polygon-geos.o \
	$(BUILD_DIR)geostree.o \
	$(BUILD_DIR)usvg.o \
	`geos-config --static-clibs` -L libmsvg/src -l msvg -lm

# `geos-config --static-clibs` -L libmsvg/src -l msvg

# -L/home/gtoal/src/geos-3.11.1/build/lib -lgeos_c -lm

clean:
	$(RM) *~ $(BUILD_DIR)testnew.o $(BUILD_DIR)polygon.o testnew
