From 10f18091875418feb35105c8e51507806d9c702b Mon Sep 17 00:00:00 2001 From: Patrik Gornicz Date: Fri, 12 Jun 2009 00:15:28 -0400 Subject: [PATCH] added $P to tests, fixed some bugs with mixing --- Makefile | 2 +- lib/post-dir.mk | 15 +++++++++------ lib/rules.mk | 16 ++++++++-------- lib/vars.mk | 7 +++++++ tests/dir.mk | 20 ++++++++++++++++---- tests/rules.mk | 34 +++++++++++++++++++++++++++++++--- tests/src/1/dir.mk | 16 +++++++++++++++- tests/src/1/files.mk | 10 +++++----- tests/src/1/rules.mk | 6 +++--- tests/src/1/vars.mk | 25 ++++++++++--------------- tests/src/dir.mk | 2 +- tests/src/files.mk | 10 +++++----- tests/vars.mk | 46 ++++++++++++++++++++++++---------------------- 13 files changed, 135 insertions(+), 74 deletions(-) diff --git a/Makefile b/Makefile index d648676..67d1542 100644 --- a/Makefile +++ b/Makefile @@ -25,5 +25,5 @@ include ${VARSMK} # include all of the dir.mk include lib/${DIRMK} -#include tests/${DIRMK} +include tests/${DIRMK} diff --git a/lib/post-dir.mk b/lib/post-dir.mk index c888a88..c858276 100644 --- a/lib/post-dir.mk +++ b/lib/post-dir.mk @@ -1,10 +1,13 @@ -INCFLAGS_$P := $(addprefix -I, ${INCDIRS_$P}) - # add flags specific to the library target and all prerequisites -${OBJS_$P} ${DEPS_$P}: CXXFLAGS += -fPIC -${OBJS_$P} ${DEPS_$P}: INCFLAGS += ${INCFLAGS_$P} +${OBJS_$P} ${DEPS_$P}: CXXFLAGS := ${CXXFLAGS_$P} +${OBJS_$P} ${DEPS_$P}: INCFLAGS := ${INCFLAGS_$P} + ${DEPS_$P}: OBJSDIR := ${OBJSDIR_$P} -${TARGETTMP_$P}: LNKFLAGS += -shared -Wl,-soname,${SONAME_$P} -${TARGETTMP_$P}: LIBS += ${LIBS_$P} +${TARGETTMP_$P}: LNKFLAGS := ${LNKFLAGS_$P} +${TARGETTMP_$P}: LIBS := ${LIBS_$P} +$P-cleanbin: WORKINGDIR := ${WORKINGDIR_$P} +$P-cleanobjs: OBJSDIR := ${OBJSDIR_$P} +$P-cleandeps: DEPSDIR := ${DEPSDIR_$P} +$P-clean: TARGET := ${TARGET_$P} diff --git a/lib/rules.mk b/lib/rules.mk index 75573e6..95d17c6 100644 --- a/lib/rules.mk +++ b/lib/rules.mk @@ -53,29 +53,29 @@ CLEANCMDS += $P-cleanbin cleanbin: $P-cleanbin .PHONY: $P-cleanbin $P-cleanbin: - ${Q1}${PRNTFMT} "rm" "${WORKINGDIR_$P}" - ${Q2}rm -rf ${WORKINGDIR_$P} + ${Q1}${PRNTFMT} "rm" "${WORKINGDIR}" + ${Q2}rm -rf ${WORKINGDIR} CLEANCMDS += $P-cleanobjs cleanobjs: $P-cleanobjs .PHONY: $P-cleanobjs $P-cleanobjs: - ${Q1}${PRNTFMT} "rm" "${OBJSDIR_$P}" - ${Q2}rm -rf ${OBJSDIR_$P} + ${Q1}${PRNTFMT} "rm" "${OBJSDIR}" + ${Q2}rm -rf ${OBJSDIR} CLEANCMDS += $P-cleandeps cleandeps: $P-cleandeps .PHONY: $P-cleandeps $P-cleandeps: - ${Q1}${PRNTFMT} "rm" "${DEPSDIR_$P}" - ${Q2}rm -rf ${DEPSDIR_$P} + ${Q1}${PRNTFMT} "rm" "${DEPSDIR}" + ${Q2}rm -rf ${DEPSDIR} CLEANCMDS += $P-clean clean: $P-clean .PHONY: $P-clean $P-clean: $P-cleanobjs - ${Q1}${PRNTFMT} "rm" "${TARGET_$P}" - ${Q2}rm -f ${TARGET_$P} + ${Q1}${PRNTFMT} "rm" "${TARGET}" + ${Q2}rm -f ${TARGET} CLEANCMDS += $P-cleanall cleanall: $P-cleanall diff --git a/lib/vars.mk b/lib/vars.mk index db42bc1..a3b40b3 100644 --- a/lib/vars.mk +++ b/lib/vars.mk @@ -1,8 +1,13 @@ +CXXFLAGS_$P := ${CXXFLAGS} -fPIC + SRCSDIR_$P := ${CURDIR}src/ DEPSDIR_$P := ${CURDIR}deps/ INCDIRS_$P := ${SRCSDIR_$P} ${CURDIR}inc/ +INCFLAGS_$P := $(addprefix -I, ${INCDIRS_$P}) + + ifeq (${BUILD},WIN32) OBJSDIR_$P := ${CURDIR}objs-mingw32/ else @@ -44,6 +49,8 @@ else REALNAME_$P := libbear.so.0.0 endif +LNKFLAGS_$P := -shared -Wl,-soname,${SONAME_$P} + TARGETTMP_$P := ${OBJSDIR_$P}${REALNAME_$P} TARGET_$P := ${WORKINGDIR_$P}${REALNAME_$P} diff --git a/tests/dir.mk b/tests/dir.mk index 2175922..aa9097d 100644 --- a/tests/dir.mk +++ b/tests/dir.mk @@ -1,19 +1,31 @@ +# Package name +P := tests CURDIR := tests/ -#SRCPATH := # Not used at this level include ${CURDIR}${VARSMK} # steps on variables -include ${SRCSDIR}${DIRMK} +include ${SRCSDIR_$P}${DIRMK} # Restore variables CURDIR := tests/ -#SRCPATH := # Not used at this level + +INCFLAGS_$P := $(addprefix -I, ${INCDIRS_$P}) +${OBJS_$P} ${DEPS_$P}: CXXFLAGS := ${CXXFLAGS_$P} +${OBJS_$P} ${DEPS_$P}: INCFLAGS := ${INCFLAGS_$P} + ${DEPS_$P}: OBJSDIRS := ${OBJSDIRS_$P} + +$P-cleanbin: WORKINGDIR := ${WORKINGDIR_$P} +$P-cleanobjs: OBJSDIR := ${OBJSDIR_$P} +$P-cleandeps: DEPSDIR := ${DEPSDIR_$P} +$P-clean: TARGET := ${TARGET_$P} include ${CURDIR}${RULESMK} # Do not include deps files when doing a clean operation ifeq ($(filter ${CLEANCMDS},${MAKECMDGOALS}),) - -include ${DEPS} + -include ${DEPS_$P} endif + +P := diff --git a/tests/rules.mk b/tests/rules.mk index 4821208..0ac584f 100644 --- a/tests/rules.mk +++ b/tests/rules.mk @@ -1,19 +1,47 @@ # how to make a directory -${BLDDIRS}: +${BLDDIRS_$P}: ${Q1}${PRNTFMT} "mkdir" "$@" ${Q2}mkdir -p $@ # rule to make an object file from a .cpp -${OBJSDIR}%.o: ${SRCSDIR}%.cpp | $${@D} +${OBJSDIR_$P}%.o: ${SRCSDIR_$P}%.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} +${DEPSDIR_$P}%.d: ${SRCSDIR_$P}%.cpp | $${@D} ${Q1}${PRNTFMT} "DEP" "$@" ${Q2}${CXX} -MM ${CXXFLAGS} $< ${INCFLAGS} | \ sed 's/\(^.*\):/$(subst /,\/,${OBJSDIR}\1 $@):/' > $@ +CLEANCMDS += $P-cleanbin +.PHONY: $P-cleanbin +$P-cleanbin: + ${Q1}${PRNTFMT} "rm" "${WORKINGDIR}" + ${Q2}rm -rf ${WORKINGDIR} + +CLEANCMDS += $P-cleanobjs +.PHONY: $P-cleanobjs +$P-cleanobjs: + ${Q1}${PRNTFMT} "rm" "${OBJSDIR}" + ${Q2}rm -rf ${OBJSDIR} + +CLEANCMDS += $P-cleandeps +.PHONY: $P-cleandeps +$P-cleandeps: + ${Q1}${PRNTFMT} "rm" "${DEPSDIR}" + ${Q2}rm -rf ${DEPSDIR} + +CLEANCMDS += $P-clean +.PHONY: $P-clean +$P-clean: $P-cleanobjs + ${Q1}${PRNTFMT} "rm" "${TARGET}" + ${Q2}rm -f ${TARGET} + +CLEANCMDS += $P-cleanall +.PHONY: $P-cleanall +$P-cleanall: $P-cleanbin $P-cleanobjs $P-cleandeps + diff --git a/tests/src/1/dir.mk b/tests/src/1/dir.mk index 874ed88..3e8b58d 100644 --- a/tests/src/1/dir.mk +++ b/tests/src/1/dir.mk @@ -1,13 +1,27 @@ +D := tests_src_1 CURDIR := tests/src/1/ SRCPATH := 1/ include ${CURDIR}${VARSMK} + +SRCS_$D := +OBJS_$D := +DEPS_$D := + include ${CURDIR}${FILESMK} -include $(addprefix ${SRCSDIR},$(addsuffix ${DIRMK},${NEWDIRS})) + +SRCS_$P += ${SRCS_$D} +OBJS_$P += ${OBJS_$D} +DEPS_$P += ${DEPS_$D} + +include $(addprefix ${SRCSDIR_$P},$(addsuffix ${DIRMK},${NEWDIRS})) # restore CURDIR := tests/src/1/ SRCPATH := 1/ + include ${CURDIR}${RULESMK} + +D := diff --git a/tests/src/1/files.mk b/tests/src/1/files.mk index 9a3c438..fc724fe 100644 --- a/tests/src/1/files.mk +++ b/tests/src/1/files.mk @@ -13,10 +13,10 @@ NEWDEPS := ${NEWSRCS:.cpp=.d} # Append to lists -SRCS += ${NEWSRCS} -OBJS += $(addprefix ${OBJSDIR},${NEWOBJS}) -DEPS += $(addprefix ${DEPSDIR},${NEWDEPS}) +SRCS_$D += ${NEWSRCS} +OBJS_$D += $(addprefix ${OBJSDIR_$P},${NEWOBJS}) +DEPS_$D += $(addprefix ${DEPSDIR_$P},${NEWDEPS}) -BLDDIRS += $(addprefix ${OBJSDIR},${NEWDIRS}) -BLDDIRS += $(addprefix ${DEPSDIR},${NEWDIRS}) +BLDDIRS_$P += $(addprefix ${OBJSDIR_$P},${NEWDIRS}) +BLDDIRS_$P += $(addprefix ${DEPSDIR_$P},${NEWDIRS}) diff --git a/tests/src/1/rules.mk b/tests/src/1/rules.mk index d3988d4..4078f22 100644 --- a/tests/src/1/rules.mk +++ b/tests/src/1/rules.mk @@ -1,14 +1,14 @@ # how to link the main target -${TARGETTMP}: ${OBJS} | $${@D} +${TARGETTMP_$D}: ${OBJS_$D} | $${@D} ${Q1}${PRNTFMT} "${CXX}" "$@" ${Q2}${CXX} ${CXXFLAGS} ${LNKFLAGS} -o $@ $^ ${LIBS} # TARGET will be built by default -tests: ${TARGET} +tests: ${TARGET_$D} # rule to copy tmp target to working directory -${TARGET}: ${TARGETTMP} | $${@D} +${TARGET_$D}: ${TARGETTMP_$D} | $${@D} ${Q1}${PRNTFMT} "cp" "$@" ${Q2}cp $< $@ diff --git a/tests/src/1/vars.mk b/tests/src/1/vars.mk index 1b15c03..b1ffe30 100644 --- a/tests/src/1/vars.mk +++ b/tests/src/1/vars.mk @@ -1,22 +1,17 @@ ifeq (${BUILD},WIN32) - LIBGL := -lopengl32 -lglu32 - LIBSDL := `/usr/mingw32/bin/sdl-config --libs` + LIBGL_$D := -lopengl32 -lglu32 + LIBSDL_$D := `/usr/mingw32/bin/sdl-config --libs` else - LIBGL := -lGL -lGLU - LIBSDL := `sdl-config --libs` + LIBGL_$D := -lGL -lGLU + LIBSDL_$D := `sdl-config --libs` endif -LIBS := ${LIBSDL} ${LIBGL} +LIBS_$D := ${LIBSDL_$D} ${LIBGL_$D} -TARGETNAME := test-1 -TARGETTMP := ${OBJSDIR}${TARGETNAME} -TARGET := ${WORKINGDIR}${TARGETNAME} +TARGETNAME_$D := test-1 +TARGETTMP_$D := ${OBJSDIR_$P}${TARGETNAME_$D} +TARGET_$D := ${WORKINGDIR_$P}${TARGETNAME_$D} -# HACK needed for deps -INCFLAGS += $(addprefix -I, ${INCDIRS}) - -# add flags specific to the library target and all prerequisites -${TARGET}: CXXFLAGS += -fPIC -${TARGET}: INCFLAGS += $(addprefix -I, ${INCDIRS}) -${TARGET}: LNKFLAGS += -Wl,-rpath,${RPATH} -rdynamic +${TARGETTMP_$D}: LNKFLAGS := -Wl,-rpath,${RPATH_$P} -rdynamic +${TARGETTMP_$D}: LIBS := ${LIBS_$P} diff --git a/tests/src/dir.mk b/tests/src/dir.mk index a4243c3..e475657 100644 --- a/tests/src/dir.mk +++ b/tests/src/dir.mk @@ -3,4 +3,4 @@ CURDIR := tests/src/ SRCPATH := include ${CURDIR}${FILESMK} -include $(addprefix ${SRCSDIR},$(addsuffix ${DIRMK},${NEWDIRS})) +include $(addprefix ${SRCSDIR_$P},$(addsuffix ${DIRMK},${NEWDIRS})) diff --git a/tests/src/files.mk b/tests/src/files.mk index 0b5ce2d..7167774 100644 --- a/tests/src/files.mk +++ b/tests/src/files.mk @@ -15,10 +15,10 @@ NEWDEPS := ${NEWSRCS:.cpp=.d} # Append to lists -SRCS += ${NEWSRCS} -OBJS += $(addprefix ${OBJSDIR},${NEWOBJS}) -DEPS += $(addprefix ${DEPSDIR},${NEWDEPS}) +SRCS_$P += ${NEWSRCS} +OBJS_$P += $(addprefix ${OBJSDIR_$P},${NEWOBJS}) +DEPS_$P += $(addprefix ${DEPSDIR_$P},${NEWDEPS}) -BLDDIRS += $(addprefix ${OBJSDIR},${NEWDIRS}) -BLDDIRS += $(addprefix ${DEPSDIR},${NEWDIRS}) +BLDDIRS_$P += $(addprefix ${OBJSDIR_$P},${NEWDIRS}) +BLDDIRS_$P += $(addprefix ${DEPSDIR_$P},${NEWDIRS}) diff --git a/tests/vars.mk b/tests/vars.mk index 8eabd56..d0f837d 100644 --- a/tests/vars.mk +++ b/tests/vars.mk @@ -1,47 +1,49 @@ -SRCSDIR := ${CURDIR}src/ -DEPSDIR := ${CURDIR}deps/ -INCDIRS := ${SRCSDIR} lib/inc/ +CXXFLAGS_$P := ${CXXFLAGS} + +SRCSDIR_$P := ${CURDIR}src/ +DEPSDIR_$P := ${CURDIR}deps/ +INCDIRS_$P := lib/inc/ ifeq (${BUILD},WIN32) - OBJSDIR := ${CURDIR}objs-mingw32/ + OBJSDIR_$P := ${CURDIR}objs-mingw32/ else ifeq (${BUILD},FINAL) - OBJSDIR := ${CURDIR}objs/ + OBJSDIR_$P := ${CURDIR}objs/ else - OBJSDIR := ${CURDIR}objsd/ + OBJSDIR_$P := ${CURDIR}objsd/ endif endif ifeq (${BUILD},WIN32) - WORKINGDIR := ${CURDIR}bin-mingw32/ + WORKINGDIR_$P := ${CURDIR}bin-mingw32/ else ifeq (${BUILD},FINAL) - WORKINGDIR := ${CURDIR}bin/ + WORKINGDIR_$P := ${CURDIR}bin/ else - WORKINGDIR := ${CURDIR}bind/ + WORKINGDIR_$P := ${CURDIR}bind/ endif endif -SRCLIBSDIR := ${CURDIR}libs/ -DSTLIBSDIR := ${WORKINGDIR} +SRCLIBSDIR_$P := ${CURDIR}libs/ +DSTLIBSDIR_$P := ${WORKINGDIR_$P} -LIBSCPY := # := start -LIBSCPY += libbear.so.0 -LIBSCPY := $(addprefix ${DSTLIBSDIR},${LIBSCPY}) +LIBSCPY_$P := # := start +LIBSCPY_$P += libbear.so.0 +LIBSCPY_$P := $(addprefix ${DSTLIBSDIR_$P},${LIBSCPY_$P}) -RPATH := ./ +RPATH_$P := ./ # lists populated by dir.mk files in subdirectories -SRCS := # := start -OBJS := # := start -DEPS := # := start +SRCS_$P := # := start +OBJS_$P := # := start +DEPS_$P := # := start -BLDDIRS := # := start +BLDDIRS_$P := # := start -BLDDIRS += ${OBJSDIR} -BLDDIRS += ${DEPSDIR} -BLDDIRS += ${WORKINGDIR} +BLDDIRS_$P += ${OBJSDIR_$P} +BLDDIRS_$P += ${DEPSDIR_$P} +BLDDIRS_$P += ${WORKINGDIR_$P} -- 2.10.2