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