slicPandora
diff -u -r1.3 -r1.4
--- Makefile 13 Jan 2010 01:47:22 -0000 1.3
+++ Makefile 13 Jan 2010 04:19:55 -0000 1.4
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.3 2010/01/13 01:47:22 jeremy Exp $
+# $Id: Makefile,v 1.4 2010/01/13 04:19:55 jeremy Exp $
ifndef PANDORAPFA
$(error Set PANDORAPFA env var to location of Pandora PFA New.)
@@ -11,46 +11,84 @@
CXX=g++
AR=ar
-SRCDIR=$(PWD)/src
-INCDIR=$(PWD)/include
BINNAME=slicPandora
+SRCDIR=$(PWD)/src
SRCS=$(wildcard $(SRCDIR)/*.cpp)
+TESTSRCS=$(wildcard $(PWD)/tests/*.cpp)
+
OBJS=$(addsuffix .o, $(basename $(SRCS)))
+
+INCDIR=$(PWD)/include
INCLUDES=-I$(INCDIR) -I$(PANDORAPFA)/include -I$(LCIO)/src/cpp/include/
-LIBS=-L$(PANDORAPFA)/lib -lPandoraPFANew -L$(LCIO)/lib -llcio
+LIBS=-L$(PANDORAPFA)/lib -lPandoraPFANew -L$(LCIO)/lib -llcio -lsio
+
+TESTLIBS=$(LIBS) -L$(PWD)/lib -l$(BINNAME)
+TESTBINS=$(subst tests,bin,$(basename $(TESTSRCS)))
+TESTOBJ=$(addsuffix .o, $(basename $(TESTSRCS)))
+TESTSCRIPT=$(PWD)/scripts/run_test.sh
+TESTRUN=$(addsuffix _run,$(TESTBINS))
CXXFLAGS=-Wall -g $(INCLUDES)
# Create bin, static lib, and shared lib.
-all: bin lib shlib
+all: libdir bindir bin lib shlib tests
-# The default target creates the binary and both libs.
+# Default target.
.DEFAULT: all
# Create a standalone binary.
-bin:
- @mkdir -p $(PWD)/bin; $(CXX) $(SRCS) $(CXXFLAGS) $(LIBS) -o $(PWD)/bin/$(BINNAME)
+bin: bindir
+ @$(CXX) $(SRCS) $(CXXFLAGS) $(LIBS) -o $(PWD)/bin/$(BINNAME)
# Create .o files from .cpp files.
%.o: %.cpp
@$(CXX) -c $(CXXFLAGS) -o $@ $<
-# Create all the .o files using rule above.
+# Create all the .o files.
obj:
@$(MAKE) $(OBJS)
# Create a static library.
-lib: obj
- mkdir -p $(PWD)/lib; \
- $(AR) rcs $(PWD)/lib/$(BINNAME).a $(OBJS)
+lib: libdir obj
+ @$(AR) rcs $(PWD)/lib/lib$(BINNAME).a $(OBJS)
# Create a shared library.
-shlib: obj
- mkdir -p $(PWD)/lib; \
- $(CXX) -shared -W1,-soname,$(BINNAME).so -o $(PWD)/lib/$(BINNAME).so $(OBJS) $(LIBS)
+shlib: libdir obj
+ @$(CXX) -shared -W1,-soname,lib$(BINNAME).so -o $(PWD)/lib/lib$(BINNAME).so $(OBJS) $(LIBS)
+
+# Compile a test case.
+$(TESTBINS) : $(TESTSRCS)
+ @$(CXX) $< $(CXXFLAGS) $(TESTLIBS) -o $@
+
+# Compile all the tests.
+tests: bindir lib shlib
+ @echo $(TESTBINS); \
+ $(MAKE) $(TESTBINS)
+
+# Run a single test.
+# These are named like ${BINNAME}_run to avoid conflicts with other targets.
+$(TESTRUN) :
+ @res=$(shell $(TESTSCRIPT) $(subst _run,,$@));
+
+# Run all the tests.
+runtests: tests FORCE
+ @rm -f $(PWD)/test.log; \
+ for testrun in $(TESTRUN); do \
+ echo "Running test case: $$testrun"; \
+ $(MAKE) $$testrun; \
+ done;
+
+FORCE:
# Clean up the object files and directories.
clean:
- rm -rf $(OBJS) $(PWD)/lib $(PWD)/bin
+ @rm -rf $(OBJS) $(PWD)/lib $(PWD)/bin
+# Create the lib directory.
+libdir:
+ @mkdir -p $(PWD)/lib;
+
+# Create the bin directory.
+bindir:
+ @mkdir -p $(PWD)/bin;
\ No newline at end of file