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