forked from UHH2/UHH2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.common
148 lines (110 loc) · 4.98 KB
/
Makefile.common
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# this is tthe 'common' Makefile for the UHH2 package(s). It is usually included by
# the sub-directories (such as core and example) after setting certain variables. The following
# variables can be set ,only the first is mandantory:
#
# * LIBRARY: should be set to a unique name, which will be used for the shared library and PROOF .par name
# typically, use SUHH2<subdirname>
# * USERLDFLAGS: additional flags for the linker. Specify all dependencies here, e.g. "-lSUHH2common" to link against
# the library built from 'common'. Note that some libraries are always linked against, in particular ROOT.
# * USERCXXFLAGS: additional flags for the compiler
# * DICT: set to a list of headers in 'include/' which should be used to build ROOT dictionaries. The include/XXX_LinkDef.h file
# must come last; see core and NtupleWriter for examples
# * PAR: if non-empty, build a minimal .par file for PROOF; this file can then be used in the SFrame configuration.
# Note that the created par file is minimal and does not do anything but to load the right shared object file.
# * TEST: if non-empty, build one test executable from each .cxx file in the 'test' subdirectory, and use all .cpp files to create
# a shared object. The executables are linked against the shared object and against the boost unit test framework.
ifeq ($(LIBRARY),)
$(error Define the variable 'LIBRARY' before including Makefile.common!)
endif
# create obj and obj/$LIBRARY/PROOF-INF (and intermediate) directories:
dummy := $(shell [ -d obj/$(LIBRARY)/PROOF-INF ] || mkdir -p obj/$(LIBRARY)/PROOF-INF )
# find sources to use for the build:
src_cc := $(wildcard src/*.cc)
src_cxx := $(wildcard src/*.cxx)
obj := $(patsubst src/%.cxx,obj/%.o,$(src_cxx)) $(patsubst src/%.cc,obj/%.o,$(src_cc))
deps := $(patsubst obj/%.o,obj/%.d,$(obj))
ifeq ($(SFRAME_DIR),)
$(error SFrame not set up. Set up SFrame first by sourcing setup.sh in the directory you installed SFrame in)
endif
ifeq ($(CMSSW_BASE),)
$(error CMSSW not set up. Set up CMSSW first via cmsenv)
endif
scramtag = $(shell cd $$CMSSW_BASE; scram tool tag $(1) $(2))
BOOST_CFLAGS := -I$(call scramtag,boost,INCLUDE)
BOOST_LDFLAGS := -L$(call scramtag,boost,LIBDIR)
INCLUDES := -I$(SFRAME_DIR) -I. -I$(CMSSW_BASE)/src
LIBTARGET := $(SFRAME_LIB_PATH)/lib$(LIBRARY).so
PARTARGET := $(SFRAME_LIB_PATH)/$(LIBRARY).par
PCMTARGET := $(SFRAME_LIB_PATH)/$(LIBRARY)_dict_rdict.pcm
# as default, build library only:
ifneq ($(DICT),)
all: $(LIBTARGET) $(PCMTARGET)
else
all: $(LIBTARGET)
endif
# build dictionary only if requested via $(DICT).
ifneq ($(DICT),)
DICTCXXFILE := obj/$(LIBRARY)_dict.cxx
DICTOBJ := obj/$(LIBRARY)_dict.o
$(DICTCXXFILE): $(DICT)
@echo "Generating dictionary $@"
@$(shell root-config --exec-prefix)/bin/rootcint -f $@ -c -p $(INCLUDES) $+ || rm -f $(DICTCXXFILE)
$(DICTOBJ): $(DICTCXXFILE)
@$(CXX_CMD)
obj += $(DICTOBJ)
# Rule to install the PCM file when using ROOT 6:
$(PCMTARGET): $(DICTCXXFILE)
@echo "Installing $@"
@cp obj/$(LIBRARY)_dict_rdict.pcm $@
endif
$(LIBTARGET): $(obj)
@$(SHARED_CMD)
ifneq ($(MAKECMDGOALS),clean)
-include $(deps)
endif
ifneq ($(TEST),)
dummy := $(shell [ -d obj/test ] || mkdir obj/test)
dummy := $(shell [ -d bin ] || mkdir bin)
testsources := $(wildcard test/*.cxx)
testobj := $(patsubst test/%.cxx,obj/test/%.o,$(testsources))
testprogs := $(patsubst test/%.cxx,bin/%,$(testsources))
testlibsources := $(wildcard test/*.cpp)
testlibobj := $(patsubst test/%.cpp,obj/test/%.o,$(testlibsources))
testlib := $(SFRAME_LIB_PATH)/libTest$(LIBRARY).so
.SECONDARY: $(testobj) $(testlibobj)
all: $(testprogs)
obj/test/%.o: test/%.cxx
@$(CXX_CMD)
bin/%: obj/test/%.o $(testlib)
@$(EXE_CMD) -lProof -lPyROOT -lTreePlayer -lTest$(LIBRARY) -l$(LIBRARY)
obj/test/%.o: test/%.cpp
@$(CXX_CMD)
$(testlib): $(testlibobj) $(LIBTARGET)
@$(SHARED_CMD) -l$(LIBRARY) $(BOOST_LDFLAGS) -lboost_unit_test_framework
endif
LIBS := $(shell root-config --libs) -lSFrameCore -lXMLParser
CXXFLAGS := $(shell root-config --cflags) -std=c++0x -O3 -Wall -Wextra -Werror=overflow -Werror=maybe-uninitialized -Wno-unused-local-typedefs -Wdeprecated-declarations -g -fPIC -pipe $(BOOST_CFLAGS) $(INCLUDES) $(USERCXXFLAGS)
LDFLAGS := $(LIBS) -fPIC -rdynamic -lrt -Wl,-z,defs -L$(SFRAME_LIB_PATH) $(USERLDFLAGS)
SHARED_CMD = echo creating $@; $(CXX) $^ -shared $(LDFLAGS) -o $@
EXE_CMD = echo creating $@; $(CXX) -o $@ $^ $(LDFLAGS)
CXX_CMD = echo creating $@; $(CXX) -c -o $@ $< $(CXXFLAGS)
obj/%.o : src/%.cxx
@$(CXX_CMD)
obj/%.o : src/%.cc
@$(CXX_CMD)
obj/%.d: src/%.cxx
@echo creating dep file $@; $(CXX) $(CXXFLAGS) -MM -MT '$(patsubst src/%.cxx,obj/%.o,$<)' $< > $@
ifneq ($(PAR),)
all: $(PARTARGET)
$(PARTARGET):
@../scripts/create-minimal-par $(LIBRARY) $(PARTARGET)
endif
ifneq ($(TESTPAR),)
TESTPARTARGET := $(SFRAME_LIB_PATH)/Test$(LIBRARY).par
all: $(TESTPARTARGET)
$(TESTPARTARGET):
@../scripts/create-minimal-par Test$(LIBRARY) $(TESTPARTARGET)
endif
clean:
@rm -rf obj/ bin/
.PHONY: clean obj/$(LIBRARY)/PROOF-INF/SETUP.C obj/$(LIBRARY)/PROOF-INF/BUILD.sh