diff --git a/Makefile b/Makefile index d493b13..1c86195 100644 --- a/Makefile +++ b/Makefile @@ -24,4 +24,4 @@ clean: make -C main clean make -C shapes clean make -C util clean - -rm -f $(TARGET) tests + -rm -f $(TARGET) diff --git a/parser/Makefile b/parser/Makefile index 2288a47..bd897a5 100644 --- a/parser/Makefile +++ b/parser/Makefile @@ -6,14 +6,15 @@ PARSER := parser COBJS := lex.yy.o CXXOBJS := $(PARSER).tab.o +OBJS := $(COBJS) $(CXXOBJS) -all: $(COBJS) $(CXXOBJS) +all: $(OBJS) %.o: %.c - $(CC) -c -o $@ $(CPPFLAGS) $< + $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $< %.o: %.cc - $(CXX) -c -o $@ $(CPPFLAGS) $< + $(CXX) -c -o $@ $(CPPFLAGS) $(CXXFLAGS) $< $(PARSER).tab.cc $(PARSER).tab.hh: $(PARSER).yy $(BISON) -d $< @@ -24,5 +25,21 @@ lex.yy.c: $(PARSER).tab.hh lex.yy.c: $(PARSER).lex $(FLEX) $< +# Make dependency files +%.dep: %.c + @set -e; rm -f $@; \ + $(CC) -MM $(CPPFLAGS) $< > $@.$$$$; \ + sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \ + rm -f $@.$$$$ + +%.dep: %.cc + @set -e; rm -f $@; \ + $(CXX) -MM $(CPPFLAGS) $< > $@.$$$$; \ + sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \ + rm -f $@.$$$$ + clean: - -rm -f lex.yy.c $(PARSER).tab.cc $(PARSER).tab.hh *~ *.o + -rm -f lex.yy.c $(PARSER).tab.cc $(PARSER).tab.hh *~ *.o *.dep + +# Include dependency files +include $(OBJS:.o=.dep)