simple test system setup
authorPatrik Gornicz <Gornicz.P@gmail.com>
Sun, 31 May 2009 00:41:59 +0000 (20:41 -0400)
committerPatrik Gornicz <Gornicz.P@gmail.com>
Sun, 31 May 2009 00:41:59 +0000 (20:41 -0400)
Makefile
test/1/Makefile [new file with mode: 0644]
test/1/src/dir.mk [new file with mode: 0644]
test/1/src/main.cpp [new file with mode: 0644]

index 744aa81..2e5e5cf 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -112,6 +112,7 @@ endif
 # cause the fancy $${@D} directory rules to work out
 .SECONDEXPANSION:
 
+# The first and therefor default rule
 .PHONY: all
 all: ${TARGET}
 
diff --git a/test/1/Makefile b/test/1/Makefile
new file mode 100644 (file)
index 0000000..1d02c1a
--- /dev/null
@@ -0,0 +1,146 @@
+
+LIBDIR  := ../../
+SRCSDIR := src/
+DEPSDIR := deps/
+INCDIRS := ${SRCSDIR} ${LIBDIR}inc/
+
+OBJSDIR := objsd/
+
+WORKINGDIR  := bind/
+
+
+LIBGL   := -lGL -lGLU
+LIBSDL  := `sdl-config --libs`
+LIBBEAR := -lbear
+LIBS    := ${LIBSDL} ${LIBGL} ${LIBBEAR}
+
+
+LINKERNAME  := libpg.so
+SONAME      := libpg.so.0
+REALNAME    := libpg.so.0.0
+
+TARGETNAME  := test-1
+TARGETTMP   := ${OBJSDIR}${TARGETNAME}
+TARGET      := ${WORKINGDIR}${TARGETNAME}
+
+RPATH    := ${LIBDIR}/bind/
+
+OPTFLAGS := -O2
+DBGFLAGS := -ggdb
+PRFFLAGS := ${DBGFLAGS} -pg
+MYFLAGS  := -Wall -pedantic -ansi
+INCFLAGS := $(addprefix -I, ${INCDIRS})
+LNKFLAGS := -Wl,-rpath,${RPATH}
+CXXFLAGS := ${MYFLAGS} ${DBGFLAGS}
+
+CXX      := g++
+
+
+PRNTFMT := printf "%-8s: %s\n"
+
+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
+.PHONY: all
+all: ${TARGET}
+
+
+# lists populated by dir.mk files in subdirectories
+SRCS    := # := start
+DIRS    := # := start
+OBJS    := # := start
+DEPS    := # := start
+
+DIRMK   := dir.mk
+
+# 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}
+
+
+# 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
+
+.PHONY: run
+run: all
+       cd ${WORKINGDIR}; ./${TARGETNAME}
+
+# Do not include deps files when doing a _single_ clean operation
+ifeq ($(findstring ${MAKECMDGOALS},${CLEANCMDS}),)
+    -include ${DEPS}
+endif
+
diff --git a/test/1/src/dir.mk b/test/1/src/dir.mk
new file mode 100644 (file)
index 0000000..9a72bae
--- /dev/null
@@ -0,0 +1,24 @@
+
+NEWSRCS := # := start; empty
+NEWSRCS += main.cpp
+
+NEWDIRS := # := start; empty
+
+# Post dir setup
+
+CURDIR  :=
+
+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 $(addprefix ${SRCSDIR},$(addsuffix ${DIRMK},${NEWDIRS}))
diff --git a/test/1/src/main.cpp b/test/1/src/main.cpp
new file mode 100644 (file)
index 0000000..55575e6
--- /dev/null
@@ -0,0 +1,13 @@
+
+#include "debug.h"
+
+int main()
+{
+    bear::debug::init();
+
+    bear::DPF(0, "Test 1: DPF");
+
+    bear::debug::fini();
+
+    return 0;
+}