.PHONY: all clean

CPPFLAGS = -I. -DCMOS
CFLAGS = -Wall -O2 -g

all: disasm sintab adfs init_hd

sintab: sintab.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $< -lm

sinetab.h: sintab
	./sintab
	cmp -s sinetab.h ../sinetab.h || cp sinetab.h ..

disasm: disasm-6502.o disasm.o disasm-opt.tab.o disasm-opt.l.o

disasm-opt.tab.c disasm-opt.tab.h: disasm-opt.y
	bison -p opt -d $<

disasm-opt.l.c: disasm-opt.l
	flex -CF -Popt -o$@ $<

disasm-opt.l.o: disasm-opt.l.c disasm-opt.gperf.h disasm-opt.tab.h

disasm-opt.gperf.h: disasm-opt.gperf
	gperf -t -L ANSI-C -H disasm_opt_hash -N disasm_opt_lookup -C \
		-E -I -o $< > $@

adfs: adfs-extract.o
	$(CC) -o $@ $<

init_hd: init_hd.o
	$(CC) -o $@ $<

clean:
	rm -f disasm sintab adfs init_hd
	rm -f *.o
	rm -f disasm-opt.tab.c disasm-opt.tab.h disasm-opt.l.c disasm-opt.gperf.h
