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
This commit is contained in:
parent
5f29edd6cc
commit
b0541348aa
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user