1 |
# Calorimeter flight analysis software
|
2 |
# SOFTWARE VERSION
|
3 |
VER= v0r01
|
4 |
# An almost general purpouse Makefile for PAMELA repository
|
5 |
# Let's start with some usefull definition for colorize the echo
|
6 |
RED='\E[1;31;40m'
|
7 |
GREEN='\E[1;32;40m'
|
8 |
YELLOW='\E[1;33;40m'
|
9 |
BLUE='\E[1;34;40m'
|
10 |
WHITE='\E[1;37;40m'
|
11 |
VIOLET='\E[1;35;40m'
|
12 |
CYAN='\E[1;36;40m'
|
13 |
# Here the echo definition to use them
|
14 |
EVIOLET=echo -e ${VIOLET}
|
15 |
ECYAN=echo -e ${CYAN}
|
16 |
ERED=echo -e ${RED}
|
17 |
EGREEN=echo -e ${GREEN}
|
18 |
EYELLOW=echo -e ${YELLOW}
|
19 |
EBLUE=echo -e ${BLUE}
|
20 |
EWHITE=echo -e ${WHITE}
|
21 |
# Reset the terminal
|
22 |
RESET=tput sgr0
|
23 |
# Here the variables used to override the standard make flags
|
24 |
# C
|
25 |
CC=gcc
|
26 |
CFLAGS=-Wall -O -fPIC -pthread -g
|
27 |
#CFLAGS=-Wall -O -fPIC -pthread
|
28 |
# Enviroment:
|
29 |
GCCVER=`gcc --version | head -1`
|
30 |
UNAMEA=`uname -a`
|
31 |
TODAY=`date`
|
32 |
# F77
|
33 |
F77=g77
|
34 |
F77FLAGS= -Wall -Wno-globals -fvxt -fno-automatic -fbounds-check -g -extend_source -static -fno-backslash
|
35 |
#F77FLAGS= -Wall -Wno-globals -fvxt -fno-automatic -fbounds-check -extend_source -static -fno-backslash
|
36 |
# C++
|
37 |
CXX=g++
|
38 |
CXXFLAGS=-Wall -O -fPIC -pthread -g
|
39 |
#CXXFLAGS=-Wall -O -fPIC -pthread
|
40 |
# ROOTCINT
|
41 |
ROOTCINT=rootcint
|
42 |
# Here the variables definig the local directories
|
43 |
DIRTOP=${shell pwd}
|
44 |
DIRLIB=lib/${ARCH}/
|
45 |
DIRBIN=bin/${ARCH}/
|
46 |
DIRSRC=src
|
47 |
DIRINC=inc
|
48 |
DIRDOC=doc
|
49 |
DIRMACROS=macros
|
50 |
DIRCALIB=calib
|
51 |
# Here the PAMELA environmental variables to be checked
|
52 |
PAM_ENV= PAM_BIN_env PAM_LIB_env PAM_INC_env PAM_DOC_env PAM_CALIB_env PAM_YODA_env
|
53 |
# Here the local variables used to build the targets
|
54 |
#-------------------------------------------------
|
55 |
FSRCS=
|
56 |
FOBJS=$(FSRCS:${DIRSRC}/F77/%.f=${DIRLIB}/%.o)
|
57 |
#-------------------------------------------------
|
58 |
CSRCS=
|
59 |
COBJS=$(CSRCS:${DIRSRC}%.cpp=${DIRLIB}/%.o)
|
60 |
#-------------------------------------------------
|
61 |
# librerie utilizzabili da root (ci deve essere anche il ***LinkDef.h )
|
62 |
LIBROOTSRCS=${DIRSRC}/PamLevel2.cpp
|
63 |
LIBROOTLIBS=$(LIBROOTSRCS:${DIRSRC}/%.cpp=${DIRLIB}/lib%_${VER}.so)
|
64 |
LIBROOTOBJS=
|
65 |
LIBROOTCLIBS=libPamLevel2
|
66 |
FULLROOTCLIBS=$(LIBROOTCLIBS:%=${DIRLIB}/%_${VER}.so)
|
67 |
#-------------------------------------------------
|
68 |
# librerie C++ NON utilizzabili da root
|
69 |
LIBCPPSRCS=#${DIRSRC}/PamLevel2.cpp
|
70 |
LIBCPPLIBS=$(LIBCPPSRCS:${DIRSRC}/%.cpp=${DIRLIB}/lib%_${VER}.so)
|
71 |
LIBCPPCLIBS=#libPamLevel2
|
72 |
FULLCPPCLIBS=$(LIBCPPCLIBS:%=${DIRLIB}/%_${VER}.so)
|
73 |
#-------------------------------------------------
|
74 |
# librerie F77 NON utilizzabili da root
|
75 |
LIBF77SRCS=
|
76 |
LIBF77OBJS= $(LIBF77SRCS:${DIRSRC}/F77/%.f=${DIRLIB}/%.o)
|
77 |
LIBF77LIBS= $(LIBF77SRCS:${DIRSRC}/F77/%.f=${DIRLIB}/lib%_${VER}.so)
|
78 |
LIBF77CLIBS=
|
79 |
FULLF77CLIBS=$(LIBF77CLIBS:%=${DIRLIB}/%_${VER}.so)
|
80 |
#-------------------------------------------------
|
81 |
FULLLIBS=${FULLROOTCLIBS} ${FULLCPPCLIBS} ${FULLF77CLIBS}
|
82 |
|
83 |
#-------------------------------------------------
|
84 |
# eseguibile
|
85 |
CXXEXESRCS=
|
86 |
CXXEXEOBJS=$(CXXEXESRCS:${DIRSRC}%.cpp=${DIRLIB}%.o)
|
87 |
CXXEXELIBS:=
|
88 |
|
89 |
OTHERLIBS=
|
90 |
#-------------------------------------------------
|
91 |
# variabili per l'installazione
|
92 |
EXESRCS=
|
93 |
INCSRCS=${DIRINC}/PamLevel2.h
|
94 |
MACROSSRCS=
|
95 |
CALIBFILES=
|
96 |
DOCFILES=
|
97 |
# Here the Variables used for info target
|
98 |
PACKAGE=Tracker flight software
|
99 |
EXECUTABLES=${EXESRCS}
|
100 |
LIBS= ${FULLLIBS} ${OTHERLIBS}
|
101 |
DOCS=
|
102 |
SRCS=
|
103 |
MACROS= ${MACROSSRCS}
|
104 |
INCLUDE= ${INCSRCS}
|
105 |
#
|
106 |
TOBEDEL = junk
|
107 |
ROOTINC=$$${shell root-config --incdir}
|
108 |
NROOTINC=${shell root-config --incdir}
|
109 |
# Let's start
|
110 |
all : test mkbindir mklibdir mkverpath ${LIBF77LIBS} ${LIBROOTLIBS} ${LIBCPPLIBS} ${CXXEXELIBS}
|
111 |
all:
|
112 |
@echo -e ${GREEN} ""
|
113 |
@(${EGREEN} " Finished, now you can install the package \n (use: make install or make upgrade or make forceinstall) "; ${RESET})
|
114 |
@echo -e ${GREEN} ""
|
115 |
@${RESET}
|
116 |
|
117 |
# Here some general rules to produce objects in our local dir
|
118 |
${DIRLIB}/%.o: ${DIRSRC}/%.cpp
|
119 |
@(${EYELLOW} " C++ object ------------------------")
|
120 |
@(${EGREEN} "Creating object file: "${WHITE} "$@"; ${RESET})
|
121 |
@${CXX} ${CXXFLAGS} -c -o $@ ${DIRSRC}/`basename ${@} .o`.cpp -I${DIRINC} -I${PAM_INC} -I${PAM_YODA}/include/yoda/ `root-config --cflags`
|
122 |
|
123 |
${DIRLIB}/%.o : ${DIRSRC}/F77/%.f
|
124 |
@(${EYELLOW} " F77 object ------------------------")
|
125 |
@(${EGREEN} "Creating object file: "${WHITE} "$@"; ${RESET})
|
126 |
@${F77} ${F77FLAGS} -c -o $@ ${DIRSRC}/F77/`basename ${@} .o`.f -I${DIRINC}/F77 -I${NROOTINC} -I${PAM_YODA}/include/yoda
|
127 |
|
128 |
|
129 |
# .so from .o fortran
|
130 |
${LIBF77LIBS}: ${LIBF77OBJS}
|
131 |
@(${EYELLOW} " F77 shared library --------------------------")
|
132 |
@(${EGREEN} "Creating library: "${WHITE} "$@"; ${RESET})
|
133 |
@${CXX} ${CXXFLAGS} -Xlinker -soname=$(@F) -shared -o $@ $^ -lg2c `cernlib mathlib`
|
134 |
|
135 |
|
136 |
${LIBROOTLIBS}: ${LIBROOTSRCS} ${FOBJS}
|
137 |
@(${EYELLOW} " ROOT library ------------------------")
|
138 |
@(${EGREEN} "Creating file: "${WHITE} "`basename $(@F) _${VER}.so | sed s/lib//`Dict.cpp"; ${RESET})
|
139 |
#
|
140 |
# Create *Dict.cpp and *Dict.h
|
141 |
#
|
142 |
@${ROOTCINT} -f ${DIRSRC}/`basename $(@F) _${VER}.so | sed s/lib//`Dict.cpp -c -I${ROOTINC} -I${PAM_YODA}/include/yoda/ -I${PAM_INC} ${DIRINC}/`basename $(@F) _${VER}.so | sed s/lib//`.h ${DIRINC}/`basename $(@F) _${VER}.so | sed s/lib//`LinkDef.h
|
143 |
#
|
144 |
# create .o
|
145 |
#
|
146 |
@(${EGREEN} "Compiling file: "${WHITE} "`basename $(@F) _${VER}.so | sed s/lib//`.cpp"; ${RESET})
|
147 |
@cd ${DIRSRC} &>/dev/null && ${CXX} ${CXXFLAGS} -c `basename $(@F) _${VER}.so | sed s/lib//`.cpp -I${DIRTOP}/${DIRINC} -I${DIRTOP} -I${PAM_INC} -I${PAM_YODA}/include/yoda/ -I${NROOTINC};
|
148 |
@(${EGREEN} "Compiling file: "${WHITE} "`basename $(@F) _${VER}.so | sed s/lib//`Dict.cpp"; ${RESET})
|
149 |
@cd ${DIRSRC} &>/dev/null && ${CXX} ${CXXFLAGS} -c `basename $(@F) _${VER}.so | sed s/lib//`Dict.cpp -I${DIRTOP}/${DIRINC} -I${DIRTOP} -I${PAM_INC} -I${PAM_YODA}/include/yoda/ -I${NROOTINC};
|
150 |
#
|
151 |
# create .so
|
152 |
#
|
153 |
@(${EGREEN} "Compiling shared library: "${WHITE} "$@"; ${RESET})
|
154 |
@${CXX} ${CXXFLAGS} -Xlinker -soname=$(@F) -shared -o $@ -lg2c -I${DIRTOP}/${DIRINC} -I${DIRTOP} -I${PAM_YODA}/include/yoda -I${PAM_INC} ${DIRTOP}/${DIRSRC}/`basename $(@F) _${VER}.so | sed s/lib//`.o ${DIRTOP}/${DIRSRC}/`basename $(@F) _${VER}.so | sed s/lib//`Dict.o ${LIBROOTOBJS} `cernlib mathlib` 1>/dev/null
|
155 |
# @ln -sf ${DIRTOP}/${DIRLIB}/$(@F) ${DIRTOP}/${DIRLIB}/$(patsubst %_${VER}.so,%.so,$(@F))
|
156 |
|
157 |
${LIBCPPLIBS}: ${LIBCPPSRCS}
|
158 |
#
|
159 |
# create .o
|
160 |
#
|
161 |
@(${EGREEN} "Compiling file: "${WHITE} "`basename $(@F) _${VER}.so | sed s/lib//`.cpp"; ${RESET})
|
162 |
@cd ${DIRSRC} &>/dev/null && ${CXX} ${CXXFLAGS} -c `basename $(@F) _${VER}.so | sed s/lib//`.cpp -I${DIRTOP}/${DIRINC} -I${DIRTOP} -I${PAM_YODA}/include/yoda/ -I${NROOTINC} -I${PAM_INC} ;
|
163 |
#
|
164 |
# create .so
|
165 |
#
|
166 |
@(${EGREEN} "Compiling shared library: "${WHITE} "$@"; ${RESET})
|
167 |
@${CXX} ${CXXFLAGS} -Xlinker -soname=$(@F) -shared -o $@ -lg2c -I${DIRTOP}/${DIRINC} -I${DIRTOP} -I${PAM_YODA}/include/yoda/ -I${PAM_INC} ${DIRTOP}/${DIRSRC}/`basename $(@F) _${VER}.so | sed s/lib//`.o 1>/dev/null
|
168 |
|
169 |
|
170 |
${CXXEXELIBS}: ${COBJS} ${FOBJS} ${CXXEXEOBJS}
|
171 |
@(${EVIOLET} "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *")
|
172 |
@(${EGREEN} "Creating exec file: "${WHITE} "$@"; ${RESET})
|
173 |
@${CXX} ${CXXFLAGS} -o ${DIRBIN}/$@ ${DIRLIB}/$@.o -I${DIRTOP}/${DIRINC} -I${PAM_INC} -I${PAM_YODA}/include/yoda/ ${PAM_YODA}/lib/libyoda.so ${FOBJS} ${COBJS} ${FULLLIBS} ${OTHERLIBS} -lThread `root-config --cflags --glibs` `cernlib mathlib` ;
|
174 |
|
175 |
# A small target to check environmental variables
|
176 |
%_env:
|
177 |
@${test_env}
|
178 |
|
179 |
.PHONY: install installdoc installlib installmacros installinc installexe installcmacro
|
180 |
.PHONY: clean depclean info mkbindir mklibdir testcern testpamenv test
|
181 |
|
182 |
mkbindir: ${DIRBIN}
|
183 |
${DIRBIN}:
|
184 |
@${test_and_mk}
|
185 |
|
186 |
mklibdir: ${DIRLIB}
|
187 |
${DIRLIB}:
|
188 |
@${test_and_mk}
|
189 |
|
190 |
# Here what has to be deleted in clean target
|
191 |
clean: TOBEDEL= ${DIRSRC}/*.o ${DIRSRC}/*Dict.cpp ${DIRSRC}/*Dict.h ${FOBJS} ${FULLLIBS} ${DIRBIN}/${CXXEXELIBS} ${COBJS} ${CXXEXEOBJS} ${DIRSRC}/TrkVerl2.cpp
|
192 |
clean:
|
193 |
@${test_and_rm}
|
194 |
|
195 |
distclean: clean
|
196 |
distclean: TOBEDEL= ${DIRBIN} ${DIRLIB}
|
197 |
distclean:
|
198 |
@${test_and_rm}
|
199 |
|
200 |
forceinstall: FORCE=-f
|
201 |
forceinstall: install
|
202 |
|
203 |
upgrade: FORCE=-u
|
204 |
upgrade: install
|
205 |
|
206 |
install: installlib installinc installmacros installcalib installdoc installexe installcmacro
|
207 |
|
208 |
installlib: LINK=y
|
209 |
installlib: TOBEMOVED= $(FULLLIBS:${DIRLIB}%=${PAM_LIB}%)
|
210 |
installlib: ORIGIN=${DIRLIB}
|
211 |
installlib:
|
212 |
@${test_and_cp}
|
213 |
|
214 |
installcmacro: LINK=y
|
215 |
installcmacro: TOBEMOVED= $(FULLMACROCLIBS:${DIRLIB}%=${PAM_LIB}%)
|
216 |
installcmacro: ORIGIN=${DIRLIB}
|
217 |
installcmacro:
|
218 |
@${test_and_cp}
|
219 |
|
220 |
installinc: TOBEMOVED= $(INCSRCS:${DIRINC}/%=${PAM_INC}/%)
|
221 |
installinc: ORIGIN=${DIRINC}
|
222 |
installinc:
|
223 |
@${test_and_cp}
|
224 |
|
225 |
installexe: TOBEMOVED= $(EXESRCS:${DIRBIN}/%=${PAM_BIN}/%)
|
226 |
installexe: ORIGIN=${DIRBIN}
|
227 |
installexe:
|
228 |
@${test_and_cp}
|
229 |
|
230 |
installmacros: TOBEMOVED= $(MACROSSRCS:${DIRMACROS}/%=${PAM_MACROS}/%)
|
231 |
installmacros: ORIGIN=${DIRMACROS}
|
232 |
installmacros:
|
233 |
@${test_and_cp}
|
234 |
|
235 |
installcalib: TOBEMOVED= $(CALIBFILES:${DIRCALIB}/%=${PAM_CALIB}/%)
|
236 |
installcalib: ORIGIN=${DIRCALIB}
|
237 |
installcalib:
|
238 |
@${test_and_cp}
|
239 |
|
240 |
installdoc: TOBEMOVED= $(DOCFILES:${DIRDOC}/%=${PAM_DOC}/%)
|
241 |
installdoc: ORIGIN=${DIRDOC}
|
242 |
installdoc:
|
243 |
@${test_and_cp}
|
244 |
|
245 |
mkverpath:
|
246 |
@echo '#include <TSystem.h>' > ${DIRTOP}/${DIRSRC}/TrkVerl2.cpp; echo ' void info(){ printf("\nTracker Level2 flight package version: ${VER}\n\nCompiled on '${TODAY}' with: '${GCCVER}'\n\nOn: '${UNAMEA}'\n\n"); }' >> ${DIRTOP}/${DIRSRC}/TrkVerl2.cpp
|
247 |
@sleep 0.8
|
248 |
|
249 |
|
250 |
|
251 |
info:
|
252 |
@echo " "
|
253 |
@${EGREEN} "Infos for package :" ${WHITE} ${PACKAGE}
|
254 |
@${EGREEN} " VERSION :" ${WHITE} ${VER}
|
255 |
@${EGREEN} " EXECUTABLES :" ${WHITE} ${EXECUTABLES}
|
256 |
@${EGREEN} " INCLUDES :" ${WHITE} ${INCLUDE}
|
257 |
@${EGREEN} " LIBS :" ${WHITE} ${LIBS}
|
258 |
@${EGREEN} " DOCS :" ${WHITE} ${DOCS}
|
259 |
@${EGREEN} " SRCS :" ${WHITE} ${SRCS}
|
260 |
@${EGREEN} " MACROS :" ${WHITE} ${MACROS}
|
261 |
@echo " "
|
262 |
@${RESET}
|
263 |
|
264 |
test: testpamenv
|
265 |
|
266 |
testpamenv: ${PAM_ENV}
|
267 |
|
268 |
root-config: OPT=--cflags
|
269 |
root-config:
|
270 |
@${test_cmd}
|
271 |
|
272 |
# Here follows some usefull macros
|
273 |
define test_and_cp
|
274 |
wd=`pwd`;\
|
275 |
for i in ${TOBEMOVED} ; do \
|
276 |
wv=$${i##/*/}; \
|
277 |
dest=$${i/$${wv}/}; \
|
278 |
${EGREEN} "Testing for :" ${WHITE} "$${i}" ; ${RESET}; \
|
279 |
if [ ! "${FORCE}" ] ; then \
|
280 |
if [ ! -f $${i} ]; then \
|
281 |
${EGREEN} "Copying : "${WHITE} ${ORIGIN}/$${i##/*/} ;\
|
282 |
${EGREEN} " to: "${WHITE} $${i} ; ${RESET}; \
|
283 |
cp ${ORIGIN}/$${i##/*/} $${i}; \
|
284 |
else \
|
285 |
${ERED} "File already exist !!!! Please delete it " ${WHITE}; ${RESET}; \
|
286 |
fi;\
|
287 |
else \
|
288 |
if [ "${FORCE}" == "-u" ] ; then \
|
289 |
if [ "`basename $${i}`" != "`basename $${i} _${VER}.so`" ]; then \
|
290 |
${EYELLOW} "Removing: "${WHITE} ${PAM_LIB}/`basename $${i} _${VER}.so`_v*r*.so; ${RESET}; \
|
291 |
rm -f ${PAM_LIB}/`basename $${i} _${VER}.so`_v*r*.so ; \
|
292 |
${EGREEN} "Copying : "${WHITE} ${ORIGIN}/$${i##/*/} ;\
|
293 |
${EGREEN} " to: "${WHITE} $${i} ; ${RESET}; \
|
294 |
cp ${ORIGIN}/$${i##/*/} $${i}; \
|
295 |
else \
|
296 |
${EYELLOW} " Forcing copy: "${WHITE} ${ORIGIN}/$${i##/*/} ;\
|
297 |
${EYELLOW} " to: "${WHITE} $${i} ; ${RESET}; \
|
298 |
cp -f ${ORIGIN}/$${i##/*/} $${i}; \
|
299 |
fi; \
|
300 |
else \
|
301 |
${EYELLOW} " Forcing copy: "${WHITE} ${ORIGIN}/$${i##/*/} ;\
|
302 |
${EYELLOW} " to: "${WHITE} $${i} ; ${RESET}; \
|
303 |
cp ${FORCE} ${ORIGIN}/$${i##/*/} $${i}; \
|
304 |
fi;\
|
305 |
fi ;\
|
306 |
if [ ! -z ${LINK} ] ; then \
|
307 |
${EGREEN} "Creating symlink from : "${WHITE} $${wv/_${VER}/} ;\
|
308 |
${EGREEN} " to : "${WHITE} $${i##/*/} ; ${RESET}; \
|
309 |
cd $${dest}; \
|
310 |
ln -sf $${wv} $${wv/_${VER}/}; \
|
311 |
cd $${wd}; \
|
312 |
fi \
|
313 |
done
|
314 |
endef
|
315 |
|
316 |
define test_and_mk
|
317 |
${EGREEN} "Testing for :" ${WHITE} "$@"; ${RESET}
|
318 |
test -d "$@" || \
|
319 |
(${EGREEN} "Creating : "${WHITE} "$@"; ${RESET}; mkdir -p $@)
|
320 |
endef
|
321 |
|
322 |
define test_env
|
323 |
${EGREEN} "Testing for env:" ${WHITE} $(patsubst %_env,%,$@); ${RESET}
|
324 |
printenv $(patsubst %_env,%,$@) 1>/dev/null || \
|
325 |
(${ERED} "ERROR, variable : "${WHITE} $(patsubst %_env,%,$@) \
|
326 |
${RED} "not defined !!! Check your env. settings"; \
|
327 |
${RESET}; exit 1)
|
328 |
${EGREEN} " Defined:" ${WHITE} $${$(patsubst %_env,%,$@)}; ${RESET}
|
329 |
endef
|
330 |
|
331 |
define test_cmd
|
332 |
${EGREEN} "Testing for cmd:" ${WHITE} $@ ${OPT}; ${RESET}
|
333 |
$@ ${OPT} 1>/dev/null 2>&1 || \
|
334 |
(${ERED} "ERROR, command : "${WHITE} $@ ${OPT}\
|
335 |
${RED} "not found !!! Check your installation"; \
|
336 |
${RESET}; exit 1)
|
337 |
${EGREEN} " Present:" ${WHITE} $@ ${OPT}; ${RESET}
|
338 |
endef
|
339 |
|
340 |
define test_and_rm
|
341 |
for i in ${TOBEDEL}; do \
|
342 |
test -d $${i} || (${ERED} "Removing file :"${WHITE} $${i}; ${RESET}; \
|
343 |
rm -f $${i} ); \
|
344 |
test ! -d $${i} || (${ERED} "Removing dir :"${WHITE} $${i}; ${RESET}; \
|
345 |
rm -rf $${i} ); \
|
346 |
done
|
347 |
endef
|