slicPandora
diff -u -r1.2 -r1.3
--- Makefile 9 Jan 2010 07:32:11 -0000 1.2
+++ Makefile 13 Jan 2010 01:47:22 -0000 1.3
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.2 2010/01/09 07:32:11 jeremy Exp $
+# $Id: Makefile,v 1.3 2010/01/13 01:47:22 jeremy Exp $
ifndef PANDORAPFA
$(error Set PANDORAPFA env var to location of Pandora PFA New.)
@@ -8,10 +8,49 @@
$(error Set LCIO env var to location of standalone LCIO project.)
endif
-CPP=g++
+CXX=g++
+AR=ar
+
SRCDIR=$(PWD)/src
INCDIR=$(PWD)/include
BINNAME=slicPandora
-compile:
- $(CPP) $(SRCDIR)/*.cc $(SRCDIR)/*.cpp -I$(INCDIR) -I$(PANDORAPFA)/include -I$(LCIO)/src/cpp/include/ -L$(PANDORAPFA)/lib -lPandoraPFANew -L$(LCIO)/lib -llcio -o $(BINNAME)
+SRCS=$(wildcard $(SRCDIR)/*.cpp)
+OBJS=$(addsuffix .o, $(basename $(SRCS)))
+INCLUDES=-I$(INCDIR) -I$(PANDORAPFA)/include -I$(LCIO)/src/cpp/include/
+LIBS=-L$(PANDORAPFA)/lib -lPandoraPFANew -L$(LCIO)/lib -llcio
+
+CXXFLAGS=-Wall -g $(INCLUDES)
+
+# Create bin, static lib, and shared lib.
+all: bin lib shlib
+
+# The default target creates the binary and both libs.
+.DEFAULT: all
+
+# Create a standalone binary.
+bin:
+ @mkdir -p $(PWD)/bin; $(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.
+obj:
+ @$(MAKE) $(OBJS)
+
+# Create a static library.
+lib: obj
+ mkdir -p $(PWD)/lib; \
+ $(AR) rcs $(PWD)/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)
+
+# Clean up the object files and directories.
+clean:
+ rm -rf $(OBJS) $(PWD)/lib $(PWD)/bin
+