
GCC_FLAGS	= -Wall -Werror
LIBS_X11	= -L/usr/X11R6/lib -lX11

all: bin/sim bin/ass

-include src/machine/*.dep
-include src/ass/*.dep
-include src/sim/*.dep

# slurp it
util_c		= $(shell find src/util -name "*.c" -follow)
util_dep 	= $(patsubst %.c,%.dep,$(util_c))
util_o		= $(patsubst %.c,%.o,$(util_c))

machine_c	= $(shell find src/machine -name "*.c" -follow)
machine_dep	= $(patsubst %.c,%.dep,$(machine_c))
machine_o	= $(patsubst %.c,%.o,$(machine_c))

ass_c		= $(shell find src/ass -name "*.c" -follow)
ass_dep 	= $(patsubst %.c,%.dep,$(ass_c))
ass_o		= $(patsubst %.c,%.o,$(ass_c))

sim_c		= $(shell find src/sim -name "*.c" -follow)
sim_dep 	= $(patsubst %.c,%.dep,$(sim_c))
sim_o		= $(patsubst %.c,%.o,$(sim_c))


.PHONY : deps
deps: $(machine_dep) $(ass_dep) $(util_dep) $(sim_deps)

bin/sim : $(sim_o) $(machine_o) $(util_o)
	gcc -o bin/sim $^ $(LIBS_X11)

bin/ass : $(ass_o) $(machine_o) $(util_o)
	gcc -o bin/ass $^ 

%.dep : %.c
	@echo "* Building Deps $<"
	@gcc $(GCC_FLAGS) -MM $< -MT $(patsubst %.dep,%.o,$@) -Isrc -o $@

%.o : %.c
	@echo "* Compiling $<"
	@gcc $(GCC_FLAGS) -c $< -o $@ -Isrc


# ---- clean 
clean:
	rm -f Makefile.deps
	rm -f bin/*
	find .  	-name "*.o" \
		-o 	-name "*.dep" \
		-follow | xargs -n 1 rm -f

	



