# Put the name of the generated executable. There should be a corresponding C # source file, with the same base name, in the same directory as this makefile. main = # # This VPATH directive assumes that the directory layout is: # # ../.. # | # +-- LIBRARY # | # +-- # | # +-- # VPATH = ../lang/c:../../LIBRARY/lang/c CC = gcc CFLAGS = $(patsubst %,-I%,$(subst :, ,$(VPATH))) sources = $(notdir $(wildcard $(patsubst %,%/*.c,$(subst :, ,$(VPATH))))) sources += $(main).c $(main): $(sources:%.c=%.o) $(CC) -o $@ $^ clean: rm -f $(main) $(sources:%.c=%.d) $(sources:%.c=%.o) %.o: %.c $(CC) -c $(CFLAGS) $< # Taken from GNU make's manual (4.14 Generating Prerequisites Automatically). %.d: %.c @set -e; rm -f $@; \ $(CC) -M $(CFLAGS) $< > $@.$$$$; \ sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \ rm -f $@.$$$$ -include $(sources:%.c=%.d)