From 3fc83b9f70fca788c6e5811c80b2eb22c8f6f74b Mon Sep 17 00:00:00 2001 From: Patrik Gornicz Date: Thu, 4 Jun 2009 00:00:56 -0400 Subject: [PATCH] make system divided into *.mk files --- Makefile | 206 +++-------------------------------------------------- src/dir.mk | 34 ++++----- src/files.mk | 28 ++++++++ src/locks/dir.mk | 22 +----- src/locks/files.mk | 24 +++++++ src/rules.mk | 71 ++++++++++++++++++ src/vars.mk | 76 ++++++++++++++++++++ vars.mk | 34 +++++++++ 8 files changed, 257 insertions(+), 238 deletions(-) create mode 100644 src/files.mk create mode 100644 src/locks/files.mk create mode 100644 src/rules.mk create mode 100644 src/vars.mk create mode 100644 vars.mk diff --git a/Makefile b/Makefile index 5361ec7..b70bff2 100644 --- a/Makefile +++ b/Makefile @@ -2,120 +2,21 @@ # set this on the command line to get a WIN32 or a FINAL build BUILD := DEBUG - -SRCSDIR := src/ -DEPSDIR := deps/ -INCDIRS := ${SRCSDIR} inc/ - -ifeq (${BUILD},WIN32) - OBJSDIR := objs-mingw32/ -else -ifeq (${BUILD},FINAL) - OBJSDIR := objs/ -else - OBJSDIR := objsd/ -endif -endif - -ifeq (${BUILD},WIN32) - WORKINGDIR := bin-mingw32/ -else -ifeq (${BUILD},FINAL) - WORKINGDIR := bin/ -else - WORKINGDIR := bind/ -endif -endif - - -ifeq (${BUILD},WIN32) - LIBGL := -lopengl32 -lglu32 - LIBSDL := `/usr/mingw32/bin/sdl-config --libs` -else - LIBGL := -lGL -lGLU - LIBSDL := `sdl-config --libs` -endif -LIBS := ${LIBSDL} ${LIBGL} - - -ifeq (${BUILD},WIN32) - LINKERNAME := bear.dll - SONAME := bear.dll - REALNAME := bear.dll -else - LINKERNAME := libbear.so - SONAME := libbear.so.0 - REALNAME := libbear.so.0.0 -endif - -TARGETTMP := ${OBJSDIR}${REALNAME} -TARGET := ${WORKINGDIR}${REALNAME} - - -OPTFLAGS := -O2 -DBGFLAGS := -ggdb -PRFFLAGS := ${DBGFLAGS} -pg -LIBFLAGS := -fPIC -MYFLAGS := -Wall -Wextra -pedantic -ansi -INCFLAGS := $(addprefix -I, ${INCDIRS}) -LNKFLAGS := -shared -Wl,-soname,${SONAME} - -CXXFLAGS := ${MYFLAGS} ${LIBFLAGS} -ifeq (${BUILD},WIN32) - CXXFLAGS += ${OPTFLAGS} -else -ifeq (${BUILD},FINAL) - CXXFLAGS += ${OPTFLAGS} -else - CXXFLAGS += ${DBGFLAGS} -endif -endif - -ifeq (${BUILD},WIN32) - CXX := mingw32-g++ -else - CXX := g++ -endif - - - -ifeq (${BUILD},WIN32) - prefix := /usr/mingw32 -else - prefix := /usr -endif -exec_prefix := ${prefix} -includedir := ${prefix}/include -libdir := ${exec_prefix}/lib - -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 - - # cause the fancy $${@D} directory rules to work out .SECONDEXPANSION: # The first and therefor default rule +# targets append themselves to this to be built by all .PHONY: all -all: ${TARGET} +all: +#all: ${TARGET} + +DIRMK := dir.mk +VARSMK := vars.mk +FILESMK := files.mk +RULESMK := rules.mk +include ${VARSMK} # lists populated by dir.mk files in subdirectories SRCS := # := start @@ -123,93 +24,8 @@ DIRS := # := start OBJS := # := start DEPS := # := start -DIRMK := dir.mk +BLDDIRS := # := start # include all of the dir.mk files in src -include ${SRCSDIR}${DIRMK} - - -DEPSBLDDIRS := ${DEPSDIR} $(addprefix ${DEPSDIR},${DIRS}) -OBJSBLDDIRS := ${OBJSDIR} $(addprefix ${OBJSDIR},${DIRS}) - -BLDDIRS := # := start -BLDDIRS += ${OBJSBLDDIRS} -BLDDIRS += ${DEPSBLDDIRS} -BLDDIRS += ${WORKINGDIR} - - -INSTALL := install - -# HACK install -install: - ${INSTALL} -d ${includedir}/bear - ${INSTALL} -t ${includedir}/bear inc/* - ln -sfn ${REALNAME} ${libdir}/${LINKERNAME} - ln -sfn ${REALNAME} ${libdir}/${SONAME} - ${INSTALL} -t ${libdir} ${WORKINGDIR}${REALNAME} - -# HACK uninstall -uninstall: - rm -rf /usr/include/bear - rm /usr/lib/${REALNAME} - rm /usr/lib/${LINKERNAME} - rm /usr/lib/${SONAME} - -# how to link the main target -${TARGETTMP}: ${OBJS} | $${@D} - ${Q1}${PRNTFMT} "${CXX}" "$@" - ${Q2}${CXX} ${CXXFLAGS} ${LNKFLAGS} -o $@ $^ ${LIBS} - -# rule to copy tmp target to working directory -${TARGET}: ${TARGETTMP} | $${@D} - ${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 | $${@D} - ${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 | $${@D} - ${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 -f ${TARGET} - -.PHONY: cleanall -cleanall: cleanbin cleanobjs cleandeps - -# Do not include deps files when doing a _single_ clean operation -ifeq ($(findstring ${MAKECMDGOALS},${CLEANCMDS}),) - -include ${DEPS} -endif +include src/${DIRMK} diff --git a/src/dir.mk b/src/dir.mk index 6f0b4e0..2f1a642 100644 --- a/src/dir.mk +++ b/src/dir.mk @@ -1,29 +1,19 @@ -NEWSRCS := # := start; empty -NEWSRCS += Vector2.cpp -NEWSRCS += mathw.cpp -NEWSRCS += debug.cpp -NEWSRCS += Timer.cpp -NEWSRCS += Ticks.cpp - -NEWDIRS := # := start; empty -NEWDIRS += locks/ - -# Post dir setup - CURDIR := -NEWSRCS := $(addprefix ${CURDIR},${NEWSRCS}) -NEWDIRS := $(addprefix ${CURDIR},${NEWDIRS}) -NEWOBJS := ${NEWSRCS:.cpp=.o} -NEWDEPS := ${NEWSRCS:.cpp=.d} +include src/${VARSMK} +include src/${FILESMK} +include $(addprefix ${SRCSDIR},$(addsuffix ${DIRMK},${NEWDIRS})) -# Append to lists -SRCS += ${NEWSRCS} -DIRS += ${CURDIR} -OBJS += $(addprefix ${OBJSDIR},${NEWOBJS}) -DEPS += $(addprefix ${DEPSDIR},${NEWDEPS}) +BLDDIRS += ${OBJSDIR} +BLDDIRS += ${DEPSDIR} +BLDDIRS += ${WORKINGDIR} -include $(addprefix ${SRCSDIR},$(addsuffix ${DIRMK},${NEWDIRS})) +include src/${RULESMK} + +# Do not include deps files when doing a clean operation +ifeq ($(filter ${CLEANCMDS},${MAKECMDGOALS}),) + -include ${DEPS} +endif diff --git a/src/files.mk b/src/files.mk new file mode 100644 index 0000000..c9eb874 --- /dev/null +++ b/src/files.mk @@ -0,0 +1,28 @@ + +NEWSRCS := # := start; empty +NEWSRCS += Vector2.cpp +NEWSRCS += mathw.cpp +NEWSRCS += debug.cpp +NEWSRCS += Timer.cpp +NEWSRCS += Ticks.cpp + +NEWDIRS := # := start; empty +NEWDIRS += locks/ + +################################################################################ + +NEWSRCS := $(addprefix ${CURDIR},${NEWSRCS}) +NEWDIRS := $(addprefix ${CURDIR},${NEWDIRS}) +NEWOBJS := ${NEWSRCS:.cpp=.o} +NEWDEPS := ${NEWSRCS:.cpp=.d} + +# Append to lists + +SRCS += ${NEWSRCS} +DIRS += ${CURDIR} +OBJS += $(addprefix ${OBJSDIR},${NEWOBJS}) +DEPS += $(addprefix ${DEPSDIR},${NEWDEPS}) + +BLDDIRS += $(addprefix ${OBJSDIR},${NEWDIRS}) +BLDDIRS += $(addprefix ${DEPSDIR},${NEWDIRS}) + diff --git a/src/locks/dir.mk b/src/locks/dir.mk index 0c0b1e6..875cfae 100644 --- a/src/locks/dir.mk +++ b/src/locks/dir.mk @@ -1,25 +1,5 @@ -NEWSRCS := # := start; empty -NEWSRCS += Autolock.cpp -NEWSRCS += Lock.cpp - -NEWDIRS := # := start; empty - -# Post dir setup - CURDIR := locks/ -NEWSRCS := $(addprefix ${CURDIR},${NEWSRCS}) -NEWDIRS := $(addprefix ${CURDIR},${NEWDIRS}) -NEWOBJS := ${NEWSRCS:.cpp=.o} -NEWDEPS := ${NEWSRCS:.cpp=.d} - -# Append to lists - -SRCS += ${NEWSRCS} -DIRS += ${CURDIR} -OBJS += $(addprefix ${OBJSDIR},${NEWOBJS}) -DEPS += $(addprefix ${DEPSDIR},${NEWDEPS}) - - +include src/locks/${FILESMK} include $(addprefix ${SRCSDIR},$(addsuffix ${DIRMK},${NEWDIRS})) diff --git a/src/locks/files.mk b/src/locks/files.mk new file mode 100644 index 0000000..845d68b --- /dev/null +++ b/src/locks/files.mk @@ -0,0 +1,24 @@ + +NEWSRCS := # := start; empty +NEWSRCS += Autolock.cpp +NEWSRCS += Lock.cpp + +NEWDIRS := # := start; empty + +################################################################################ + +NEWSRCS := $(addprefix ${CURDIR},${NEWSRCS}) +NEWDIRS := $(addprefix ${CURDIR},${NEWDIRS}) +NEWOBJS := ${NEWSRCS:.cpp=.o} +NEWDEPS := ${NEWSRCS:.cpp=.d} + +# Append to lists + +SRCS += ${NEWSRCS} +DIRS += ${CURDIR} +OBJS += $(addprefix ${OBJSDIR},${NEWOBJS}) +DEPS += $(addprefix ${DEPSDIR},${NEWDEPS}) + +BLDDIRS += $(addprefix ${OBJSDIR},${NEWDIRS}) +BLDDIRS += $(addprefix ${DEPSDIR},${NEWDIRS}) + diff --git a/src/rules.mk b/src/rules.mk new file mode 100644 index 0000000..efd74f5 --- /dev/null +++ b/src/rules.mk @@ -0,0 +1,71 @@ + +# HACK install +install: + ${INSTALL} -d ${includedir}/bear + ${INSTALL} -t ${includedir}/bear inc/* + ln -sfn ${REALNAME} ${libdir}/${LINKERNAME} + ln -sfn ${REALNAME} ${libdir}/${SONAME} + ${INSTALL} -t ${libdir} ${WORKINGDIR}${REALNAME} + +# HACK uninstall +uninstall: + rm -rf /usr/include/bear + rm /usr/lib/${REALNAME} + rm /usr/lib/${LINKERNAME} + rm /usr/lib/${SONAME} + +# how to link the main target +${TARGETTMP}: ${OBJS} | $${@D} + ${Q1}${PRNTFMT} "${CXX}" "$@" + ${Q2}${CXX} ${CXXFLAGS} ${LNKFLAGS} -o $@ $^ ${LIBS} + +# TARGET will be built by default +all: ${TARGET} + +# rule to copy tmp target to working directory +${TARGET}: ${TARGETTMP} | $${@D} + ${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 | $${@D} + ${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 | $${@D} + ${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 -f ${TARGET} + +.PHONY: cleanall +cleanall: cleanbin cleanobjs cleandeps diff --git a/src/vars.mk b/src/vars.mk new file mode 100644 index 0000000..61aa670 --- /dev/null +++ b/src/vars.mk @@ -0,0 +1,76 @@ + +SRCSDIR := src/ +DEPSDIR := deps/ +INCDIRS := ${SRCSDIR} inc/ + +ifeq (${BUILD},WIN32) + OBJSDIR := objs-mingw32/ +else +ifeq (${BUILD},FINAL) + OBJSDIR := objs/ +else + OBJSDIR := objsd/ +endif +endif + +ifeq (${BUILD},WIN32) + WORKINGDIR := bin-mingw32/ +else +ifeq (${BUILD},FINAL) + WORKINGDIR := bin/ +else + WORKINGDIR := bind/ +endif +endif + + +ifeq (${BUILD},WIN32) + LIBGL := -lopengl32 -lglu32 + LIBSDL := `/usr/mingw32/bin/sdl-config --libs` +else + LIBGL := -lGL -lGLU + LIBSDL := `sdl-config --libs` +endif +LIBS := ${LIBSDL} ${LIBGL} + + +ifeq (${BUILD},WIN32) + LINKERNAME := bear.dll + SONAME := bear.dll + REALNAME := bear.dll +else + LINKERNAME := libbear.so + SONAME := libbear.so.0 + REALNAME := libbear.so.0.0 +endif + +TARGETTMP := ${OBJSDIR}${REALNAME} +TARGET := ${WORKINGDIR}${REALNAME} + + +ifeq (${BUILD},WIN32) + prefix := /usr/mingw32 +else + prefix := /usr +endif +exec_prefix := ${prefix} +includedir := ${prefix}/include +libdir := ${exec_prefix}/lib +INSTALL := install + + +LIBFLAGS := -fPIC +INCFLAGS := $(addprefix -I, ${INCDIRS}) +LNKFLAGS := -shared -Wl,-soname,${SONAME} + +CXXFLAGS += ${LIBFLAGS} +ifeq (${BUILD},WIN32) + CXXFLAGS += ${OPTFLAGS} +else +ifeq (${BUILD},FINAL) + CXXFLAGS += ${OPTFLAGS} +else + CXXFLAGS += ${DBGFLAGS} +endif +endif + diff --git a/vars.mk b/vars.mk new file mode 100644 index 0000000..de72284 --- /dev/null +++ b/vars.mk @@ -0,0 +1,34 @@ + +OPTFLAGS := -O2 +DBGFLAGS := -ggdb +PRFFLAGS := ${DBGFLAGS} -pg +WARFLAGS := -Wall -Wextra -pedantic -ansi + +CXXFLAGS := ${WARFLAGS} + +ifeq (${BUILD},WIN32) + CXX := mingw32-g++ +else + CXX := g++ +endif + +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 + -- 2.10.2