-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
227 lines (184 loc) · 5.7 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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
PREFIX=$(HOME)
UNIC=$(HOME)
MAD=$(HOME)
LIBNAME=PLASMA
# Define CXX, CXXFLAGS, SOFLAGS & LIBS
# ====================================
OPT2 = -O2
ROOTCONFIG = root-config
ARCH := $(shell $(ROOTCONFIG) --arch)
ALTCXX := $(shell $(ROOTCONFIG) --cxx)
ROOTCFLAGS:= $(shell $(ROOTCONFIG) --cflags)
ROOTLIBS := $(shell $(ROOTCONFIG) --libs)
ARCHOK = no
ifeq ($(ARCH),linux)
CXX = g++
CXXFLAGS = $(OPT2) -Wall -fPIC
SOFLAGS = -shared
ARCHOK = yes
endif
ifeq ($(ARCH),linuxx8664gcc)
CXX = g++
CXXFLAGS = $(OPT2) -Wall -fPIC
SOFLAGS = -shared
ARCHOK = yes
endif
ifeq ($(ARCH),win32gcc)
CXX = g++
CXXFLAGS = $(OPT2) -Wall
SOFLAGS = -shared
ARCHOK = yes
endif
# If arch != the above options, a error message is given
ifeq ($(ARCHOK),no)
$(error $(ARCH) invalid architecture)
endif
# In case that ALTCXX = 0, g++ will be used as CXX
ifneq ($(ALTCXX),)
CXX = $(ALTCXX)
endif
# dependence
CXXFLAGS+= -I$(UNIC)/include
CXXFLAGS+= -I$(MAD)/include
# Finally, define CXXFLAGS & LIBS
CXXFLAGS+= $(ROOTCFLAGS)
CXXFLAGS+= -g
LIBS += $(ROOTLIBS)
# Define things related to rootcint
# =================================
ROOTCINT = rootcint
ROOTIFIED_SOURCE := $(LIBNAME)Dict.cc
ROOTIFIED_HEADER := $(ROOTIFIED_SOURCE:.cc=.h)
ROOTIFIED_OBJECT := $(ROOTIFIED_SOURCE:.cc=.o)
# Define SOURCES, HEADERS & OBJECTS
# ==========================================
SOURCES = $(filter-out $(ROOTIFIED_SOURCE), $(wildcard *.cc))
HEADERS = $(SOURCES:.cc=.h)
OBJECTS = $(SOURCES:.cc=.o)
DEPFILE = $(SOURCES:.cc=.d)
EXESRCS = $(wildcard *.C)
EXES = $(EXESRCS:.C=.exe)
LINKDEF = LinkDef.h
# Define LIBRARY, ROOTMAP & variables to create them
# ==================================================
LIBRARY = lib$(LIBNAME).so
ROOTMAP = $(LIBRARY:.so=.rootmap)
SYMBOLS = `nm -CPu $(LIBRARY) |\
awk -F: '/^T/{printf("(%s)\n",$$1)}' |\
sort -u | tr '\n' '|'`
ALLLIBS = $(wildcard $(shell $(ROOTCONFIG) --libdir)/*.so)
DEPENDS = $(shell symbols=$(SYMBOLS); \
for so in $(ALLLIBS); \
do nm -CD --defined-only $$so |\
grep -E 'T ('$$symbols')::' > /dev/null &&\
echo $$so;\
done | sort -u | tr '\n' ' ')
RLIBMAP = rlibmap
# Action starts
# =============
# the first target is the default target, it depends on $(ROOTMAP)
# before "make all", make will include all other makefiles specified
# by the include command
all: $(EXES)
@echo
@echo "* Done!"
@echo
# include *.d files, which are makefiles defining dependencies between files
ifeq ($(filter info clean tags,$(MAKECMDGOALS)),)
-include $(DEPFILE) # - tells make to continue if dependence files do not exist
endif
# rules to create *.d files
%.d:%.cc
@echo creating $@
@set -e; rm -f $@; \
$(CXX) -MM $(CPPFLAGS) $< > $@.$$$$; \
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
# lib$(LIBNAME).rootmap can only be created after the creation of lib$(LIBNAME).so. It
# tells ROOT the dependence among libraries. Putting it along with the
# corresponding library allows one to use in CINT the functions defined in the
# library without calling gSystem->Load("lib.so")
$(ROOTMAP): $(LIBRARY)
@echo
@echo "* Creating rootmap file:"
$(RLIBMAP) -o $(ROOTMAP) -l $(LIBRARY) -d $(DEPENDS) -c $(LINKDEF)
# lib$(LIBNAME).so depends on all *.o files.
# The flag "-shared" is used to create shared libs
# $@ represents the target, that is, lib$(LIBNAME).so
# $^ represents all the prerequisites, i.e., all *.o files
$(LIBRARY): $(ROOTIFIED_OBJECT) $(OBJECTS)
@echo
@echo "* Creating shared library:"
$(CXX) $(CXXFLAGS) $(LIBS) $(SOFLAGS) -o $@ $^
# An xxx.o file depends on xxx.cc. It is created with the command:
# g++ -c xxx.cc -o xxx.o
# Since this is obvious, "make" automatically does it.
# There is no need to explicitly write down the rules to do it.
# To use classes & functions directly in ROOT. One has to do the following
$(ROOTIFIED_SOURCE): $(HEADERS) $(LINKDEF)
@echo
@echo "* Rootifying files:"
@rm -f $(ROOTIFIED_SOURCE) $(ROOTIFIED_HEADER)
$(ROOTCINT) $(ROOTIFIED_SOURCE) -c -p $(CXXFLAGS) $(HEADERS) $(LINKDEF)
@echo
@echo "* Creating object files:"
info:
@echo
@echo "target: $(LIBRARY) $(ROOTMAP)"
@echo "sources: $(SOURCES)"
@echo "headers: $(HEADERS)"
@echo "objects: $(OBJECTS)"
@echo
@echo "compiler: $(CXX)"
@echo "flags: $(CXXFLAGS)"
@echo "libs: $(LIBS)"
@echo
@echo "executables:$(EXES)"
@echo
clean:
$(RM) *.o *.exe *.d *.d.* *~ *Dict* $(ROOTMAP) $(LIBRARY)
tags:
ctags --c-kinds=+p $(HEADERS) $(SOURCES)
$(EXES): %.exe:%.C install
$(CXX) $< $(CXXFLAGS) $(LIBS) -L$(MAD)/lib -lMAD -L. -l$(LIBNAME) -o $@
install: $(ROOTMAP)
@echo
@echo "* Installing to PREFIX=$(PREFIX)"
@echo -n "checking if $(PREFIX) exists..."
@if [ -d $(PREFIX) ]; then \
echo "yes."; \
else \
echo "no."; \
echo "mkdir $(PREFIX)..."; \
mkdir $(PREFIX); \
fi
@echo -n "copying lib$(LIBNAME).so to $(PREFIX)/lib..."
@if [ -d $(PREFIX)/lib ]; then \
cp lib$(LIBNAME).so $(PREFIX)/lib; \
cp lib$(LIBNAME).rootmap $(PREFIX)/lib; \
else \
mkdir $(PREFIX)/lib; \
cp lib$(LIBNAME).so $(PREFIX)/lib; \
cp lib$(LIBNAME).rootmap $(PREFIX)/lib; \
fi;
@echo "done.";
@echo -n "copying *.h to $(PREFIX)/include/$(LIBNAME)..."
@if [ -d $(PREFIX)/include ]; then \
if [ -d $(PREFIX)/include/$(LIBNAME) ]; then \
cp $(HEADERS) $(PREFIX)/include/$(LIBNAME); \
else \
mkdir $(PREFIX)/include/$(LIBNAME); \
cp $(HEADERS) $(PREFIX)/include/$(LIBNAME); \
fi; \
else \
mkdir $(PREFIX)/include; \
mkdir -p $(PREFIX)/include/$(LIBNAME); \
cp *.h $(PREFIX)/include/$(LIBNAME); \
fi
@echo "done."
@echo
@echo "* Create executables:"
uninstall:
$(RM) -r $(PREFIX)/include/$(LIBNAME)
$(RM) -r $(PREFIX)/lib/lib$(LIBNAME).so
.PHONY: all info tags clean install uninstall