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