Created
May 2, 2014 15:30
-
-
Save tcoffin/8df26e9df8d3f93d962e to your computer and use it in GitHub Desktop.
Example makefile with proper dependency handling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SRCS := foo.c bar.c | |
OBJS := $($(SRC):.c=.o) | |
foo: $(OBJS) | |
$(CPP) -o $@ $^ $(LINKFLAGS) | |
-include $(OBJS:.o=.d) | |
%.o: %.cc | |
$(CPP) -c $(CFLAGS) $*.cc -o $*.o | |
$(CPP) -MM $(CFLAGS) $*.cc > $*.d # generates .d files which will detect header file changes as well | |
@sed -i -e 's|.*:|$*.o:|' $*.d # corrects a problem in the generated .d files | |
%.o: %.c | |
$(CC) -c $(CFLAGS) $*.c -o $*.o | |
$(CC) -MM $(CFLAGS) $*.c > $*.d | |
@sed -i -e 's|.*:|$*.o:|' $*.d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment