started smart includes
[physics.git] / src / Makefile
1
2 LIBGL := -lGL -lGLU
3 LIBSDL := `sdl-config --libs`
4 LIBS := ${LIBSDL} ${LIBGL}
5
6 OPTFLAGS := -O2
7 DBGFLAGS := -ggdb
8 PRFFLAGS := ${DBGFLAGS} -pg
9 CXXFLAGS := -Wall -pedantic -ansi ${DBGFLAGS}
10
11 VALFLAGS := --leak-check=full
12
13 TARGET := ../run_physics
14
15 SRCS := # simply to keep every line below the same
16
17 DIRS := # := start
18 DIRS += .
19 DIRS += Entities
20 DIRS += GameStates
21 DIRS += Effects
22 DIRS += config
23 DIRS += input
24 DIRS += graphics
25
26 include $(addsuffix /files.mk,${DIRS})
27
28 OBJSDIR := ../objs/
29 OBJS := ${SRCS:.cpp=.o}
30 OBJS := $(addprefix ${OBJSDIR},${OBJS})
31
32 DEPSDIR := ../deps/
33 DEPS := ${SRCS:.cpp=.d}
34 DEPS := $(addprefix ${DEPSDIR},${DEPS})
35
36 HRDS := ${SRCS:.cpp=.h}
37 HRDS := $(filter-out main.h,$HRDS) # remove main.h
38 HRDS += debug.h
39
40 HRDS += graphics/colors.h
41
42 TARS := ${SRCS} ${HRDS} Makefile
43
44
45 VERBOSE := 0
46
47 ifeq (${VERBOSE},0)
48     # quiet the echo command
49     Q1 := @
50     # quiet the command that is `replaced' by an echo
51     Q2 := @
52 else
53     # EAT the echo command as if it was not there
54     Q1 := @true # NOTE: the space between @true and the # is VERY important!!
55     # do not quiet the command output
56     Q2 :=
57 endif
58
59 .PHONY: all
60 all: ${TARGET}
61         echo "${SRCS}"
62         echo "${FILES}"
63
64 ${TARGET}: ${OBJS}
65         ${Q1}echo "${CXX}: $@"
66         ${Q2}${CXX} ${CXXFLAGS} -o $@ $^ ${LIBS}
67
68 # rule to make a depend file from a .cpp
69 ${DEPSDIR}%.d: %.cpp
70         ${Q1}echo "DEP: $@"
71         ${Q2}${CXX} -MM ${CXXFLAGS} $< | sed 's,: , $@: ,' > $@
72
73 # rule to make an object file from a .cpp
74 ${OBJSDIR}%.o: %.cpp
75         ${Q1}echo "${CXX}: $@"
76         ${Q2}${CXX} ${CXXFLAGS} -c -o $@ $<
77
78
79 .PHONY: clean
80 clean:
81         ${Q1}echo "CLEAN: OBJS"
82         ${Q2}rm -f ${OBJS}
83         ${Q1}echo "CLEAN: TARGET"
84         ${Q2}rm -f ${TARGET}
85
86 .PHONY: distclean
87 distclean: clean
88         ${Q1}echo "CLEAN: DEPS"
89         ${Q2}rm -f ${DEPS}
90         ${Q1}echo "CLEAN: tags prof gmon.out"
91         ${Q2}rm -f tags prof gmon.out
92
93 .PHONY: gitclean
94 gitclean:
95         ${Q1}echo "git-clean: show, use gitcleanf to force"
96         ${Q2}cd ..; git clean -nxd
97
98 .PHONY: gitcleanf
99 gitcleanf:
100         ${Q1}echo "git-clean: forced"
101         ${Q2}cd ..; git clean -fxd
102
103 tags: ${SRCS}
104         ctags $^
105
106 .PHONY: tar
107 tar: ../physics.tar.bz2
108
109 .PHONY: ../physics.tar.bz2
110 ../physics.tar.bz2:
111         @echo "git-archive: Warning, archives HEAD not current"
112         ${Q1}echo "git-archive: ../physics.tar.bz2"
113         ${Q2}cd ..; git-archive --prefix=physics/ HEAD | bzip2 > physics.tar.bz2
114
115 .PHONY: run
116 run: all
117         cd ..; ./run_physics
118
119 .PHONY: gdb
120 gdb: all
121         gdb ${TARGET}
122
123 .PHONY: val
124 val: all
125         valgrind ${VALFLAGS} ${TARGET}
126
127 .PHONY: prof
128 prof: all
129         ${TARGET}
130         gprof -b ${TARGET} > prof
131         kprof -f prof
132
133 -include ${DEPS}