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