CC=gcc

#Default libusb compile and install will be in a different directory
#than a Ubuntu package manager installation.
#CPPFLAGS+=-I/usr/local/include/libusb-1.0
CPPFLAGS+=-I/usr/include/libusb-1.0

CFLAGS+=-Wall -g -std=c99

LDFLAGS+= \
	-lusb-1.0 \
	-lpthread \
	-lrt \
	-ludev

TARGETS=libuphil.a chat load receive rs232 send

all: $(TARGETS)

gen:
	mkdir -p $@

gen/bsfuqf.h: data/r2336/bsfuqf.ufa | gen
	xxd -i $< $@

gen/fpgabootloader.h: data/r2316/fpgabootloader.bin | gen
	xxd -i $< $@

gen/usbzxla.h: data/r2300/usbzxla.bix | gen
	xxd -i $< $@

gen/VirtualCom.h: data/r2329/VirtualCom.bix | gen
	xxd -i $< $@

libuphil.a: uphil.o ezusb.o
	$(AR) rcs $@ $^

chat: chat.o
	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)

load: load.o libuphil.a
	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)

receive: receive.o
	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)

rs232: rs232.o
	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)

send: send.o
	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)

uphil.o: gen/bsfuqf.h
uphil.o: gen/fpgabootloader.h
uphil.o: gen/usbzxla.h
uphil.o: gen/VirtualCom.h

.PHONY: clean
clean:
	$(RM) $(TARGETS) *.o
	$(RM) -rf gen/
