forked from csullivan/GRUTinizer
-
Notifications
You must be signed in to change notification settings - Fork 11
/
makefile
202 lines (160 loc) · 7.76 KB
/
makefile
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
.PHONY: clean all extras pcm_files
.SECONDARY:
.SECONDEXPANSION:
RCNP=1
PLATFORM:=$(PLATFORM)
# EDIT THIS SECTION
INCLUDES = include
CFLAGS = -g -std=c++11 -O3 -Wall -Wextra -pedantic -Wno-unused-parameter
LINKFLAGS_PREFIX =
LINKFLAGS_SUFFIX = -L/opt/X11/lib -lX11 -lXpm -std=c++11
SRC_SUFFIX = cxx
# EVERYTHING PAST HERE SHOULD WORK AUTOMATICALLY
USING_ROOT_6 = $(shell expr $(shell root-config --version | cut -f1 -d.) \>= 6)
ifeq ($(PLATFORM),Darwin)
export __APPLE__:= 1
CFLAGS += -DOS_DARWIN -DHAVE_ZLIB
CFLAGS += -I/opt/X11/include -Qunused-arguments
CPP = clang++
SHAREDSWITCH = -install_name # ENDING SPACE
else
export __LINUX__:= 1
CPP = g++
LINKFLAGS_PREFIX += -Wl,--no-as-needed
SHAREDSWITCH = -shared -Wl,-soname,# NO ENDING SPACE
endif
# When compiling and linking against RCNP analyzer routines one must set RCNP=1
ifeq ($(RCNP),1)
RCNPANAPATH = ./GRAnalyzer/analyzer
RCNPANALYZER = $(realpath $(RCNPANAPATH)/../lib)
RCNPFLAGS = -D`uname -m` -D`uname -s` -DLinux86 -Df2cFortran -DUSE_PAW -DRCNP
RCNPLINKFLAGS = -L$(RCNPANALYZER) -Wl,-rpath,$(RCNPANALYZER) -lRCNPEvent -lGRAnalyzer -L$(realpath $(RCNPANAPATH)/lib) -lpacklib -lm -lgfortran -lnsl
RCNPINCLUDES = $(RCNPANAPATH)/include $(RCNPANAPATH)/libRCNPEvent/include $(RCNPANAPATH)/libGRAnalyzer/include
CINTFLAGS += $(RCNPFLAGS)
CFLAGS += $(RCNPFLAGS)
INCLUDES += $(RCNPINCLUDES)
endif
COM_COLOR=\033[0;34m
OBJ_COLOR=\033[0;36m
BLD_COLOR=\033[3;34m
LIB_COLOR=\033[3;36m
OK_COLOR=\033[0;32m
ERROR_COLOR=\033[0;31m
WARN_COLOR=\033[0;33m
NO_COLOR=\033[m
OK_STRING="[OK]"
ERROR_STRING="[ERROR]"
WARN_STRING="[WARNING]"
COM_STRING= "Compiling"
BLD_STRING= "Building\ "
COPY_STRING="Copying\ \ "
FIN_STRING="Finished Building"
LIBRARY_DIRS := $(shell find libraries -type d -links 2 2> /dev/null)
LIBRARY_NAMES := $(notdir $(LIBRARY_DIRS))
LIBRARY_OUTPUT := $(patsubst %,lib/lib%.so,$(LIBRARY_NAMES))
INCLUDES := $(addprefix -I$(PWD)/,$(INCLUDES))
CFLAGS += $(shell root-config --cflags)
CFLAGS += -MMD -MP $(INCLUDES)
LINKFLAGS += -Llib $(addprefix -l,$(LIBRARY_NAMES)) -Wl,-rpath,\$$ORIGIN/../lib
LINKFLAGS += $(shell root-config --glibs) -lSpectrum -lPyROOT -lMinuit
LINKFLAGS := $(LINKFLAGS_PREFIX) $(LINKFLAGS) $(LINKFLAGS_SUFFIX)
ROOT_LIBFLAGS := $(shell root-config --cflags)
UTIL_O_FILES := $(patsubst %.$(SRC_SUFFIX),.build/%.o,$(wildcard util/*.$(SRC_SUFFIX)))
MAIN_O_FILES := $(patsubst %.$(SRC_SUFFIX),.build/%.o,$(wildcard src/*.$(SRC_SUFFIX)))
EXE_O_FILES := $(UTIL_O_FILES)
EXECUTABLES := $(patsubst %.o,bin/%,$(notdir $(EXE_O_FILES))) bin/grutinizer
HISTOGRAM_SO := $(patsubst histos/%.$(SRC_SUFFIX),lib/lib%.so,$(wildcard histos/*.$(SRC_SUFFIX)))
FILTER_SO := $(patsubst filters/%.$(SRC_SUFFIX),lib/lib%.so,$(wildcard filters/*.$(SRC_SUFFIX)))
ifdef VERBOSE
run_and_test = @echo $(1) && $(1);
else
run_and_test =@printf "%b%b%b" " $(3)$(4)$(5)" $(notdir $(2)) "$(NO_COLOR)\r"; \
$(1) 2> $(2).log || touch $(2).error; \
if test -e $(2).error; then \
printf "%-60b%b%s%b" "$(3)$(4)$(5)$(2)" "$(ERROR_COLOR)" "$(ERROR_STRING)" "$(NO_COLOR)\n" ; \
cat $(2).log; \
rm -f $(2).log $(2).error; \
exit 1; \
elif test -s $(2).log; then \
printf "%-60b%b%s%b" "$(3)$(4)$(5)$(2)" "$(WARN_COLOR)" "$(WARN_STRING)" "$(NO_COLOR)\n" ; \
cat $(2).log; \
else \
printf "%b%-60s%b%s%b" "$(3)$(4)$(5)" $(notdir $(2)) "$(OK_COLOR)" "$(OK_STRING)" "$(NO_COLOR)\n" ; \
fi; \
rm -f $(2).log $(2).error
endif
all: include/GVersion.h $(EXECUTABLES) $(LIBRARY_OUTPUT) pcm_files \
bin/grutinizer-config bin/gadd_fast.py\
$(HISTOGRAM_SO) $(FILTER_SO) extras lib/libAllGrutinizer.so
@printf "$(OK_COLOR)Compilation successful, $(WARN_COLOR)woohoo!$(NO_COLOR)\n"
pcm_files:
docs:
doxygen doxygen.config
bin/%: util/% | bin
@ln -sf ../$< $@
bin/grutinizer: $(MAIN_O_FILES) | $(LIBRARY_OUTPUT) pcm_files bin
$(call run_and_test,$(CPP) $^ -o $@ $(LINKFLAGS) $(RCNPLINKFLAGS),$@,$(COM_COLOR),$(COM_STRING),$(OBJ_COLOR) )
bin/%: .build/util/%.o | $(LIBRARY_OUTPUT) pcm_files bin
$(call run_and_test,$(CPP) $< -o $@ $(LINKFLAGS) $(RCNPLINKFLAGS),$@,$(COM_COLOR),$(COM_STRING),$(OBJ_COLOR) )
bin lib:
@mkdir -p $@
include/GVersion.h: .git/HEAD .git/index util/gen_version.sh
$(call run_and_test,util/gen_version.sh,$@,$(COM_COLOR),$(COM_STRING),$(OBJ_COLOR) )
lib/libAllGrutinizer.so: $(LIBRARY_OUTPUT)
$(call run_and_test,echo | $(CPP) -x c++ - -fPIC -o $@ $(SHAREDSWITCH)$(notdir $@) $(LINKFLAGS) $(RCNPLINKFLAGS),$@,$(BLD_COLOR),$(BLD_STRING),$(OBJ_COLOR) )
lib/lib%.so: .build/histos/%.o | lib
$(call run_and_test,$(CPP) -fPIC $^ $(SHAREDSWITCH)lib$*.so $(ROOT_LIBFLAGS) -o $@,$@,$(BLD_COLOR),$(BLD_STRING),$(OBJ_COLOR) )
lib/lib%.so: .build/filters/%.o | lib
$(call run_and_test,$(CPP) -fPIC $^ $(SHAREDSWITCH)lib$*.so $(ROOT_LIBFLAGS) -o $@,$@,$(BLD_COLOR),$(BLD_STRING),$(OBJ_COLOR) )
libGRAnalyzer:
ifdef RCNP
$(MAKE) -C GRAnalyzer
endif
# Functions for determining the files included in a library.
# All src files in the library directory are included.
# If a LinkDef.h file is present in the library directory,
# a dictionary file will also be generated and added to the library.
libdir = $(shell find libraries -name $(1) -type d)
lib_src_files = $(shell find $(call libdir,$(1)) -name "*.$(SRC_SUFFIX)")
lib_o_files = $(patsubst %.$(SRC_SUFFIX),.build/%.o,$(call lib_src_files,$(1)))
lib_linkdef = $(wildcard $(call libdir,$(1))/LinkDef.h)
lib_dictionary = $(patsubst %/LinkDef.h,.build/%/LibDictionary.o,$(call lib_linkdef,$(1)))
# If using ROOT6, and if there is a linkdef, then we need to copy the pcm file
lib_pcm = $(if \
$(and $(filter 1,$(USING_ROOT_6)),$(call lib_linkdef,$(1))), \
lib/$(1)Dict_rdict.pcm)
lib/lib%.so: $$(call lib_o_files,%) $$(call lib_dictionary,%) | lib
$(call run_and_test,$(CPP) -fPIC $^ $(SHAREDSWITCH)lib$*.so $(ROOT_LIBFLAGS) -o $@,$@,$(BLD_COLOR),$(BLD_STRING),$(OBJ_COLOR) )
.build/%.o: %.$(SRC_SUFFIX) libGRAnalyzer
@mkdir -p $(dir $@)
$(call run_and_test,$(CPP) -fPIC -c $< -o $@ $(CFLAGS),$@,$(COM_COLOR),$(COM_STRING),$(OBJ_COLOR) )
dict_header_files = $(addprefix $(PWD)/include/,$(subst //,,$(shell head $(1) -n 1 2> /dev/null)))
find_linkdef = $(shell find $(1) -name "*LinkDef.h")
# In order for all function names to be unique, rootcint requires unique output names.
# Therefore, usual wildcard rules are insufficient.
# Eval is more powerful, but is less convenient to use.
define library_template
.build/$(1)/$(notdir $(1))Dict.cxx: $(1)/LinkDef.h $$(call dict_header_files,$(1)/LinkDef.h)
@mkdir -p $$(dir $$@)
$$(call run_and_test,rootcint -f $$@ -c $$(INCLUDES) $$(CINTFLAGS) -p $$(notdir $$(filter-out $$<,$$^)) $$<,$$@,$$(COM_COLOR),$$(BLD_STRING) ,$$(OBJ_COLOR))
.build/$(1)/LibDictionary.o: .build/$(1)/$(notdir $(1))Dict.cxx
$$(call run_and_test,$$(CPP) -fPIC -c $$< -o $$@ $$(CFLAGS),$$@,$$(COM_COLOR),$$(COM_STRING),$$(OBJ_COLOR) )
lib/$(notdir $(1))Dict_rdict.pcm: .build/$(1)/$(notdir $(1))Dict_rdict.pcm | lib
$$(call run_and_test,cp $$< $$@,$$@,$$(COM_COLOR),$$(COPY_STRING),$$(OBJ_COLOR) )
pcm_files: $$(call lib_pcm,$$(notdir $(1)))
endef
# rootcling makes the Dict_rdict.pcm at the same time as making Dict.cxx
# We need to tell make that it will exist once Dict.cxx exists.
%_rdict.pcm: %.cxx
@touch $@
$(foreach lib,$(LIBRARY_DIRS),$(eval $(call library_template,$(lib))))
-include $(shell find .build -name '*.d' 2> /dev/null)
clean:
@printf "\n$(WARN_COLOR)Cleaning up$(NO_COLOR)\n\n"
@-$(RM) -rf .build bin lib include/GVersion.h
ifdef RCNP
@-$(MAKE) clean -sC GRAnalyzer
endif
cleaner: clean
@printf "\nEven more clean up\n\n"
@-$(RM) -rf htmldoc