CC := gcc YACC := bison LEX := flex SRCD := src TSTD := tests BLDD := build BIND := bin INCD := include MAIN := $(BLDD)/main.o ALL_SRCF := $(shell find $(SRCD) -type f -name *.c) ALL_OBJF := $(patsubst $(SRCD)/%,$(BLDD)/%,$(ALL_SRCF:.c=.o)) ALL_FUNCF := $(filter-out $(MAIN) $(AUX), $(ALL_OBJF)) TEST_SRC := $(shell find $(TSTD) -type f -name *.c) INC := -I $(INCD) CFLAGS := -Wall -Werror -Wno-unused-function -MMD COLORF := -DCOLOR DFLAGS := -g -DDEBUG -DCOLOR PRINT_STAMENTS := -DERROR -DSUCCESS -DWARN -DINFO TEST_LIB := -lcriterion LIBS := EXEC := mush TEST_EXEC := $(EXEC)_tests .PHONY: clean all setup debug all: setup $(BIND)/$(EXEC) $(BIND)/$(TEST_EXEC) debug: CFLAGS += $(DFLAGS) $(PRINT_STAMENTS) $(COLORF) debug: all setup: $(BIND) $(BLDD) $(BIND): mkdir -p $(BIND) $(BLDD): mkdir -p $(BLDD) $(BIND)/$(EXEC): $(BLDD)/mush.tab.o $(BLDD)/mush.lex.o $(ALL_OBJF) $(CC) $^ -o $@ $(LIBS) $(BIND)/$(TEST_EXEC): $(ALL_FUNCF) $(BLDD)/mush.tab.o $(BLDD)/mush.lex.o $(TEST_SRC) $(CC) $(CFLAGS) $(INC) $(ALL_FUNCF) $(TEST_SRC) $(TEST_LIB) $(LIBS) -o $@ $(BLDD)/%.o: $(SRCD)/%.c $(INCD)/$(EXEC).tab.h $(CC) $(CFLAGS) $(INC) -c -o $@ $< clean: rm -rf $(BLDD) $(BIND) # Cancel the implicit rule that is doing the wrong thing. %.c: %.y %.c: %.l .PRECIOUS: $(BLDD)/*.d -include $(BLDD)/*.d