From b0541348aa6495ce44aba34ebfcf481585f7a394 Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Mon, 12 Jun 2017 14:29:01 +0200 Subject: [PATCH] Makefile: simplification and improvment Default target is the main program. Use implicit rule for main program. Generate .d file at compilation time instead of using specific rules Fix CFLAGS CPPFLAGS usage --- Makefile/Makefile | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Makefile/Makefile b/Makefile/Makefile index da06de7..a51fc33 100644 --- a/Makefile/Makefile +++ b/Makefile/Makefile @@ -1,19 +1,23 @@ -CPPFLAGS ?= -Werror -Wall +# Preproc options +# -MMD is used to generate .d files for header dependencies +CPPFLAGS = -MMD +# main compilation +CFLAGS ?= -Werror -Wall +#Linker flags +LDFLAGS = +#Linker path +LDLIBS = program = test sources = $(wildcard *.c) objects = $(sources:%.c=%.o) depends = $(sources:%.c=%.d) -%.d: %.c - @$(CPP) $(CPPFLAGS) -c -MP -MM -MT "$@ $*.o" $< >$@ - $(program): $(objects) - $(CXX) -o $@ $^ $(LDFLAGS) $(LDLIBS) .PHONY: clean clean: - rm -f $(program) $(objects) $(depends) + $(RM) $(program) $(objects) $(depends) ifneq ($(MAKECMDGOALS),clean) -include $(depends)