| 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 | MYFLAGS := -Wall -pedantic -ansi |
| 10 | |
| 11 | VALFLAGS := --leak-check=full |
| 12 | CXXFLAGS := ${MYFLAGS} ${DBGFLAGS} |
| 13 | |
| 14 | CXX := g++ |
| 15 | |
| 16 | DIRS := # := start |
| 17 | DIRS += ./ |
| 18 | DIRS += Entities/ |
| 19 | DIRS += GameStates/ |
| 20 | DIRS += Effects/ |
| 21 | DIRS += config/ |
| 22 | DIRS += input/ |
| 23 | DIRS += graphics/ |
| 24 | |
| 25 | SRCS := # := start |
| 26 | include $(addsuffix /files.mk,${DIRS}) |
| 27 | |
| 28 | WORKINGDIR := ../bin/ |
| 29 | |
| 30 | OBJSDIR := ../objs/ |
| 31 | OBJS := ${SRCS:.cpp=.o} |
| 32 | OBJS := $(addprefix ${OBJSDIR},${OBJS}) |
| 33 | |
| 34 | DEPSDIR := ../deps/ |
| 35 | DEPS := ${SRCS:.cpp=.d} |
| 36 | DEPS := $(addprefix ${DEPSDIR},${DEPS}) |
| 37 | |
| 38 | CFGDIRNAME := configs/ |
| 39 | SRCCFGDIR := ../${CFGDIRNAME} |
| 40 | DSTCFGDIR := ${WORKINGDIR}${CFGDIRNAME} |
| 41 | |
| 42 | CFGS := # := start |
| 43 | CFGS += keys.cfg |
| 44 | CFGS := $(addprefix ${DSTCFGDIR},${CFGS}) |
| 45 | |
| 46 | TARGETNAME := run_physics |
| 47 | TARGETTMP := ${OBJSDIR}${TARGETNAME} |
| 48 | TARGET := ${WORKINGDIR}${TARGETNAME} |
| 49 | |
| 50 | DEPSBLDDIRS := $(addprefix ${DEPSDIR},${DIRS}) |
| 51 | OBJSBLDDIRS := $(addprefix ${OBJSDIR},${DIRS}) |
| 52 | BLDDIRS := ${OBJSBLDDIRS} ${DEPSBLDDIRS} ${WORKINGDIR} ${DSTCFGDIR} |
| 53 | |
| 54 | |
| 55 | VERBOSE := 0 |
| 56 | |
| 57 | ifeq (${VERBOSE},0) |
| 58 | # quiet the echo command |
| 59 | Q1 := @ |
| 60 | # quiet the command that is `replaced' by an echo |
| 61 | Q2 := @ |
| 62 | else |
| 63 | # EAT the echo command as if it was not there |
| 64 | Q1 := @true # NOTE: the space between @true and the # is VERY important!! |
| 65 | # do not quiet the command output |
| 66 | Q2 := |
| 67 | endif |
| 68 | |
| 69 | .PHONY: all |
| 70 | all: ${TARGET} ${CFGS} |
| 71 | |
| 72 | # how to link the main target |
| 73 | ${TARGETTMP}: ${OBJS} |
| 74 | ${Q1}echo "${CXX}: $@" |
| 75 | ${Q2}${CXX} ${CXXFLAGS} -o $@ $^ ${LIBS} |
| 76 | |
| 77 | # rule to copy tmp target to working directory |
| 78 | ${TARGET}: ${TARGETTMP} | ${WORKINGDIR} |
| 79 | ${Q1}echo "cp: $@" |
| 80 | ${Q2}cp $< $@ |
| 81 | |
| 82 | # how to make a directory |
| 83 | ${BLDDIRS}: |
| 84 | ${Q2}mkdir -p $@ |
| 85 | |
| 86 | # rule to make an object file from a .cpp |
| 87 | ${OBJSDIR}%.o: %.cpp | ${OBJSBLDDIRS} |
| 88 | ${Q1}echo "${CXX}: $@" |
| 89 | ${Q2}${CXX} ${CXXFLAGS} -c -o $@ $< |
| 90 | |
| 91 | # rule to make a depend file from a .cpp |
| 92 | ${DEPSDIR}%.d: %.cpp | ${DEPSBLDDIRS} |
| 93 | ${Q1}echo "DEP: $@" |
| 94 | ${Q2}${CXX} -MM ${CXXFLAGS} $< | sed 's,\(^.*\):,${OBJSDIR}\1 $@:,' > $@ |
| 95 | |
| 96 | # rule to copy the config files into the working directory |
| 97 | ${DSTCFGDIR}%.cfg: ${SRCCFGDIR}%.cfg | ${DSTCFGDIR} |
| 98 | ${Q1}echo "cp: $@" |
| 99 | ${Q2}cp $< $@ |
| 100 | |
| 101 | |
| 102 | tags: ${SRCS} |
| 103 | ${Q1}echo "ctags: $@" |
| 104 | ${Q2}ctags $^ |
| 105 | |
| 106 | |
| 107 | .PHONY: clean |
| 108 | clean: |
| 109 | ${Q1}echo "CLEAN: OBJS" |
| 110 | ${Q2}rm -f ${OBJS} |
| 111 | ${Q1}echo "CLEAN: TARGET" |
| 112 | ${Q2}rm -f ${TARGET} |
| 113 | |
| 114 | .PHONY: distclean |
| 115 | distclean: clean |
| 116 | ${Q1}echo "CLEAN: DEPS" |
| 117 | ${Q2}rm -f ${DEPS} |
| 118 | ${Q1}echo "CLEAN: tags prof gmon.out" |
| 119 | ${Q2}rm -f tags prof gmon.out |
| 120 | |
| 121 | .PHONY: gitclean |
| 122 | gitclean: |
| 123 | ${Q1}echo "git-clean: show, use gitcleanf to force" |
| 124 | ${Q2}cd ..; git clean -nxd |
| 125 | |
| 126 | .PHONY: gitcleanf |
| 127 | gitcleanf: |
| 128 | ${Q1}echo "git-clean: forced" |
| 129 | ${Q2}cd ..; git clean -fxd |
| 130 | |
| 131 | .PHONY: tar |
| 132 | tar: ../physics.tar.bz2 |
| 133 | |
| 134 | .PHONY: ../physics.tar.bz2 |
| 135 | ../physics.tar.bz2: |
| 136 | @echo "git-archive: Warning, archives HEAD not current" |
| 137 | ${Q1}echo "git-archive: ../physics.tar.bz2" |
| 138 | ${Q2}cd ..; git-archive --prefix=physics/ HEAD | bzip2 > physics.tar.bz2 |
| 139 | |
| 140 | .PHONY: run |
| 141 | run: all |
| 142 | cd ${WORKINGDIR}; ./${TARGETNAME} |
| 143 | |
| 144 | .PHONY: gdb |
| 145 | gdb: all |
| 146 | cd ${WORKINGDIR}; gdb ${TARGETNAME} |
| 147 | |
| 148 | .PHONY: cgdb |
| 149 | cgdb: all |
| 150 | cd ${WORKINGDIR}; cgdb ${TARGETNAME} |
| 151 | |
| 152 | .PHONY: val |
| 153 | val: all |
| 154 | cd ${WORKINGDIR}; valgrind ${VALFLAGS} ./${TARGETNAME} |
| 155 | |
| 156 | .PHONY: prof |
| 157 | prof: run |
| 158 | cd ${WORKINGDIR}; gprof -b ${TARGETNAME} > src/prof |
| 159 | kprof -f prof |
| 160 | |
| 161 | MINGMAKEARGS := "LIBGL := -lopengl32 -lglu32" \ |
| 162 | "LIBSDL := `/usr/mingw32/bin/sdl-config --libs`" \ |
| 163 | "CXXFLAGS := ${OPTFLAGS}" \ |
| 164 | "CXX := mingw32-g++" \ |
| 165 | "OBJSDIR := ../objs-mingw32/" \ |
| 166 | "WORKINGDIR := ../bin-mingw32/" \ |
| 167 | "TARGETNAME := run_physics.exe" |
| 168 | |
| 169 | .PHONY: mingw32 |
| 170 | mingw32: |
| 171 | ${Q1}echo "make: mingw32" |
| 172 | ${Q2}${MAKE} ${MINGMAKEARGS} clean all |
| 173 | |
| 174 | -include ${DEPS} |