# set this on the command line to get a WIN32 or a FINAL build BUILD := DEBUG ifeq (${BUILD},WIN32) LIBGL := -lopengl32 -lglu32 LIBSDL := `/usr/mingw32/bin/sdl-config --libs` else LIBGL := -lGL -lGLU LIBSDL := `sdl-config --libs` endif LIBMY := -lbear LIBS := ${LIBSDL} ${LIBGL} ${LIBMY} OPTFLAGS := -O2 DBGFLAGS := -ggdb PRFFLAGS := ${DBGFLAGS} -pg MYFLAGS := -Wall -pedantic -ansi RPATH := libs/ VALFLAGS := --leak-check=full LNKFLAGS := -Wl,-rpath,${RPATH} ifeq (${BUILD},WIN32) CXXFLAGS := ${MYFLAGS} ${OPTFLAGS} else ifeq (${BUILD},FINAL) CXXFLAGS := ${MYFLAGS} ${OPTFLAGS} else CXXFLAGS := ${MYFLAGS} ${DBGFLAGS} endif endif ifeq (${BUILD},WIN32) CXX := mingw32-g++ else CXX := g++ endif DIRS := # := start SRCSDIR := src/ SRCS := # := start ifeq (${BUILD},WIN32) OBJSDIR := objs-mingw32/ else ifeq (${BUILD},FINAL) OBJSDIR := objs/ else OBJSDIR := objsd/ endif endif OBJS := # := start DEPSDIR := deps/ DEPS := # := start # include all of the dir.mk DIRMK := dir.mk include ${SRCSDIR}${DIRMK} ifeq (${BUILD},WIN32) WORKINGDIR := bin-mingw32/ else ifeq (${BUILD},FINAL) WORKINGDIR := bin/ else WORKINGDIR := bind/ endif endif CFGDIRNAME := configs/ SRCCFGDIR := ${CFGDIRNAME} DSTCFGDIR := ${WORKINGDIR}${CFGDIRNAME} CFGS := # := start CFGS += keys.cfg CFGS := $(addprefix ${DSTCFGDIR},${CFGS}) LIBSDIRNAME := libs/ SRCLIBSDIR := ${LIBSDIRNAME} ifeq (${BUILD},WIN32) DSTLIBSDIR := ${WORKINGDIR} else DSTLIBSDIR := ${WORKINGDIR}${LIBSDIRNAME} endif LIBSTXT := # := start LIBSTXT += COPYING-SDL LIBSTXT += README-SDL LIBSTXT += VERSION-SDL LIBSTXT := $(addprefix ${DSTLIBSDIR},${LIBSTXT}) LIBSCPY := # := start ifeq (${BUILD},WIN32) LIBSCPY += SDL.dll LIBSCPY += bear.dll else LIBSCPY += libSDL-1.2.so.0 LIBSCPY += libbear.so.0 endif LIBSCPY := $(addprefix ${DSTLIBSDIR},${LIBSCPY}) SRCTXTDIR := DSTTXTDIR := ${WORKINGDIR} TXT := # := start TXT += COPYING TXT := $(addprefix ${DSTTXTDIR},${TXT}) ifeq (${BUILD},WIN32) TARGETNAME := run_physics.exe else TARGETNAME := run_physics endif TARGETTMP := ${OBJSDIR}${TARGETNAME} TARGET := ${WORKINGDIR}${TARGETNAME} DEPSBLDDIRS := ${DEPSDIR} $(addprefix ${DEPSDIR},${DIRS}) OBJSBLDDIRS := ${OBJSDIR} $(addprefix ${OBJSDIR},${DIRS}) BLDDIRS := # := start BLDDIRS += ${OBJSBLDDIRS} BLDDIRS += ${DEPSBLDDIRS} BLDDIRS += ${WORKINGDIR} BLDDIRS += ${DSTCFGDIR} BLDDIRS += ${DSTLIBSDIR} BLDDIRS := $(sort ${BLDDIRS}) # remove possible duplicates INCDIRS := ${SRCSDIR} INCFLAGS := $(addprefix -I, ${INCDIRS}) ifeq (${BUILD},WIN32) PRNTFMT := printf "%-12s: %s\n" else PRNTFMT := printf "%-8s: %s\n" endif VERBOSE := 0 ifeq (${VERBOSE},0) # quiet the printf command Q1 := @ # quiet the command that is `replaced' by an echo Q2 := @ else # EAT the printf command as if it was not there Q1 := @true # NOTE: the space between @true and the # is VERY important!! # do not quiet the command output Q2 := endif .PHONY: all all: ${TARGET} ${CFGS} ${LIBSTXT} ${LIBSCPY} ${TXT} # cause the fancy $$ directory rules to work out .SECONDEXPANSION: # how to link the main target ${TARGETTMP}: ${OBJS} ${Q1}${PRNTFMT} "${CXX}" "$@" ${Q2}${CXX} ${CXXFLAGS} ${LNKFLAGS} -o $@ $^ ${LIBS} # rule to copy tmp target to working directory ${TARGET}: ${TARGETTMP} | ${WORKINGDIR} ${Q1}${PRNTFMT} "cp" "$@" ${Q2}cp $< $@ # rule to copy the config files into the working directory ${DSTCFGDIR}%: ${SRCCFGDIR}% | $$(dir $$@) ${Q1}${PRNTFMT} "cp" "$@" ${Q2}cp $< $@ # rule to copy the library files into the working directory ${DSTLIBSDIR}%: ${SRCLIBSDIR}% | $$(dir $$@) ${Q1}${PRNTFMT} "cp" "$@" ${Q2}cp $< $@ # rule to copy the library files into the working directory ${DSTTXTDIR}%: ${SRCTXTDIR}% | $$(dir $$@) ${Q1}${PRNTFMT} "cp" "$@" ${Q2}cp $< $@ # how to make a directory ${BLDDIRS}: ${Q1}${PRNTFMT} "mkdir" "$@" ${Q2}mkdir -p $@ # rule to make an object file from a .cpp ${OBJSDIR}%.o: ${SRCSDIR}%.cpp | $$(dir $$@) ${Q1}${PRNTFMT} "${CXX}" "$@" ${Q2}${CXX} ${CXXFLAGS} -c -o $@ $< ${INCFLAGS} # rule to make a depend file from a .cpp # be clever and escape the / chars in file paths # DON'T simply use another sed delimiter or it can't appear in the file paths ${DEPSDIR}%.d: ${SRCSDIR}%.cpp | $$(dir $$@) ${Q1}${PRNTFMT} "DEP" "$@" ${Q2}${CXX} -MM ${CXXFLAGS} $< ${INCFLAGS} | \ sed 's/\(^.*\):/$(subst /,\/,${OBJSDIR}\1 $@):/' > $@ CLEANCMDS := cleanbin cleanobjs cleandeps clean cleanall .PHONY: cleanbin cleanbin: ${Q1}${PRNTFMT} "rm" "${WORKINGDIR}" ${Q2}rm -rf ${WORKINGDIR} .PHONY: cleanobjs cleanobjs: ${Q1}${PRNTFMT} "rm" "${OBJSDIR}" ${Q2}rm -rf ${OBJSDIR} .PHONY: cleandeps cleandeps: ${Q1}${PRNTFMT} "rm" "${DEPSDIR}" ${Q2}rm -rf ${DEPSDIR} .PHONY: clean clean: cleanobjs ${Q1}${PRNTFMT} "rm" "${TARGET}" ${Q2}rm -rf ${TARGET} .PHONY: cleanall cleanall: clean cleanbin cleandeps .PHONY: gitclean gitclean: ${Q1}${PRNTFMT} "git clean" "showing; use gitcleanf to force removal" ${Q2}git clean -nxd .PHONY: gitcleanf gitcleanf: ${Q1}${PRNTFMT} "git clean" "forcing" ${Q2}git clean -fxd .PHONY: tar tar: physics.tar.bz2 .PHONY: physics.tar.bz2 physics.tar.bz2: @${PRNTFMT} "git archive" "Warning, archives HEAD not current" ${Q1}${PRNTFMT} "git archive" "physics.tar.bz2" ${Q2}git archive --prefix=physics/ HEAD | bzip2 > physics.tar.bz2 .PHONY: run run: all ifeq (${WIN32},1) cd ${WORKINGDIR}; wine ${TARGETNAME} else cd ${WORKINGDIR}; ./${TARGETNAME} endif .PHONY: gdb gdb: all cd ${WORKINGDIR}; gdb ${TARGETNAME} .PHONY: cgdb cgdb: all cd ${WORKINGDIR}; cgdb ${TARGETNAME} .PHONY: val val: all cd ${WORKINGDIR}; valgrind ${VALFLAGS} ./${TARGETNAME} .PHONY: prof prof: run cd ${WORKINGDIR}; gprof -b ${TARGETNAME} > prof cd ${WORKINGDIR}; kprof -f prof # Do not include deps files when doing a _single_ clean operation ifeq ($(findstring ${MAKECMDGOALS},${CLEANCMDS}),) -include ${DEPS} endif