-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
32 lines (25 loc) · 807 Bytes
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
DIRS := src
SOURCES := $(foreach dir, $(DIRS), $(wildcard $(dir)/*.cc))
OBJS := $(patsubst %.cc, %.o, $(SOURCES))
OBJS := $(foreach o,$(OBJS),./obj/$(o))
DEPFILES:= $(patsubst %.o, %.P, $(OBJS))
CFLAGS = -Wall -MMD -c
COMPILER = g++
#link the executable
main: $(OBJS)
$(COMPILER) $(OBJS) -o main
#generate dependency information and compile
obj/%.o : %.cc
@mkdir -p $(@D)
$(COMPILER) $(CFLAGS) -o $@ -MF obj/$*.P $<
@sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
-e '/^$$/ d' -e 's/$$/ :/' < obj/$*.P >> obj/$*.P;
#remove all generated files
clean:
rm -f main
rm -rf obj
#include the dependency information
-include $(DEPFILES)
#http://www.gnu.org/s/hello/manual/make/Automatic-Variables.html
#http://mad-scientist.net/make/autodep.html
#http://linux.die.net/man/1/g++