1 |
# YodaProfiler |
2 |
# SOFTWARE VERSION |
3 |
VER= v2r00 |
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 |
29 |
CFLAGS=-Wall -O -fPIC -pthread |
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 |
37 |
F77FLAGS= -Wall -Wno-globals -fvxt -fno-automatic -fbounds-check -extend_source -static -fno-backslash |
38 |
# C++ |
39 |
CXX=g++ |
40 |
#CXXFLAGS=-Wall -O -fPIC -pthread -g |
41 |
CXXFLAGS=-Wall -O -fPIC -pthread |
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=doc |
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}/YodaProfilerVerl2.cpp \ |
65 |
${DIRSRC}/PamelaDBOperations.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=${DIRSRC}/GLTables.cpp |
74 |
# ${DIRSRC}/PacketTypeList.cpp |
75 |
LIBROOTLIBS=$(LIBROOTSRCS:${DIRSRC}/%.cpp=${DIRLIB}/lib%_${VER}.so) |
76 |
LIBROOTCLIBS=libGLTables #libPacketTypeList |
77 |
FULLROOTCLIBS=$(LIBROOTCLIBS:%=${DIRLIB}/%_${VER}.so) |
78 |
|
79 |
# -- CPP - NON-ROOT libraries -- |
80 |
LIBCPPSRCS=${DIRSRC}/sgp4.cpp |
81 |
LIBCPPLIBS=$(LIBCPPSRCS:${DIRSRC}/%.cpp=${DIRLIB}/lib%_${VER}.so) |
82 |
LIBCPPCLIBS=libsgp4 |
83 |
FULLLIBCPPLIBS=$(LIBCPPCLIBS:%=${DIRLIB}/%_${VER}.so) |
84 |
|
85 |
# -- CPP - Executables -- |
86 |
CXXEXESRCS=${DIRSRC}/YodaProfiler.cpp |
87 |
CXXEXEOBJS=$(CXXEXESRCS:${DIRSRC}%.cpp=${DIRLIB}%.o) |
88 |
CXXEXELIBS:=YodaProfiler |
89 |
|
90 |
# List of all libraries we want to install |
91 |
FULLLIBS = ${FULLROOTCLIBS} ${FULLLIBCPPLIBS} ${DARTHVLIB} |
92 |
|
93 |
# Other objects to install |
94 |
EXESRCS=${DIRBIN}/YodaProfiler |
95 |
|
96 |
INCSRCS=${DIRINC}/GLTables.h ${DIRINC}/GLTablesStruct.h ${DIRINC}/sgp4.h |
97 |
|
98 |
MACROSSRCS= |
99 |
|
100 |
CALIBFILES= |
101 |
|
102 |
DOCFILES= |
103 |
|
104 |
# Here the Variables used for info target |
105 |
PACKAGE=PAMELA analysis flight software |
106 |
EXECUTABLES= ${EXESRCS} |
107 |
LIBS= ${FULLLIBS} |
108 |
DOCS= |
109 |
SRCS= |
110 |
#SRCS= ${FSRCS} ${CRSCS} ${CXXEXESRCS} ${LIBROOTSRCS} ${LIBCPPSRCS} |
111 |
MACROS= ${MACROSSRCS} |
112 |
INCLUDE= ${INCSRCS} |
113 |
# |
114 |
TOBEDEL = junk |
115 |
ROOTINC=$$${shell root-config --incdir} |
116 |
NROOTINC=${shell root-config --incdir} |
117 |
|
118 |
# Let's start |
119 |
all: test mkbindir mklibdir mkverpath ${FOBJS} ${CPPOBJS} ${LIBROOTLIBS} ${LIBCPPLIBS} ${CXXEXELIBS} |
120 |
@echo -e ${GREEN} "" |
121 |
@(${EGREEN} " Finished, now you can install the package \n (use: make install or make upgrade or make forceinstall) "; ${RESET}) |
122 |
@echo -e ${GREEN} "" |
123 |
@${RESET} |
124 |
|
125 |
# Here some general rules to produce objects in our local dir |
126 |
${DIRLIB}/%.o: ${DIRSRC}/%.cpp |
127 |
@(${EGREEN} "Creating CPP object file: "${WHITE} "`basename $@`"; ${RESET}) |
128 |
@${CXX} ${CXXFLAGS} -c -o $@ ${DIRSRC}/`basename ${@} .o`.cpp -I${DIRINC} ${SUBINC} -I${PAM_YODA}/include/yoda/ `root-config --cflags` |
129 |
|
130 |
${DIRLIB}/%.o: ${DIRSRC}/%.c |
131 |
@(${EGREEN} "Creating C object file: "${WHITE} "`basename $@`"; ${RESET}) |
132 |
@${CXX} ${CXXFLAGS} -c -o $@ ${DIRSRC}/`basename ${@} .o`.c -I${DIRINC} -I${PAM_YODA}/include/yoda/ `root-config --cflags` |
133 |
|
134 |
${DIRLIB}/%.o: ${DIRSRC}/%.for |
135 |
@(${EGREEN} "Creating F77 object file: "${WHITE} "`basename $@`"; ${RESET}) |
136 |
@${F77} ${F77FLAGS} -c -o $@ ${DIRSRC}/`basename ${@} .o`.for -I${DIRINC} |
137 |
|
138 |
${LIBROOTLIBS}: ${LIBROOTSRCS} |
139 |
@(${EGREEN} "ROOTCINT - creating file: "${WHITE} "`basename $(@F) _${VER}.so | sed s/lib//`Dict.cpp"; ${RESET}) |
140 |
# |
141 |
# Create *Dict.cpp and *Dict.h |
142 |
# |
143 |
@${ROOTCINT} -f ${DIRSRC}/`basename $(@F) _${VER}.so | sed s/lib//`Dict.cpp -c -I${ROOTINC} -I${PAM_YODA}/include/yoda/ ${DIRINC}/`basename $(@F) _${VER}.so | sed s/lib//`.h ${DIRINC}/`basename $(@F) _${VER}.so | sed s/lib//`LinkDef.h |
144 |
# |
145 |
# create .o |
146 |
# |
147 |
@(${EGREEN} "Compiling CPP file: "${WHITE} "`basename $(@F) _${VER}.so | sed s/lib//`.cpp"; ${RESET}) |
148 |
@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}; |
149 |
@(${EGREEN} "Compiling CPP file: "${WHITE} "`basename $(@F) _${VER}.so | sed s/lib//`Dict.cpp"; ${RESET}) |
150 |
@cd ${DIRSRC} &>/dev/null && ${CXX} ${CXXFLAGS} -c `basename $(@F) _${VER}.so | sed s/lib//`Dict.cpp -I${DIRTOP}/${DIRINC} -I${DIRTOP} -I${PAM_YODA}/include/yoda/ -I${NROOTINC}; |
151 |
# |
152 |
# create .so |
153 |
# |
154 |
@(${EGREEN} "Creating shared library: "${WHITE} "`basename $@`"; ${RESET}) |
155 |
@${CXX} ${CXXFLAGS} -Xlinker -soname=$(@F) -shared -o $@ -lg2c -I${DIRTOP}/${DIRINC} -I${DIRTOP} -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 |
156 |
@ln -sf ${DIRTOP}/${DIRLIB}/$(@F) ${DIRTOP}/${DIRLIB}/$(patsubst %_${VER}.so,%.so,$(@F)) |
157 |
|
158 |
${LIBCPPLIBS}: ${LIBSRCS} ${COBJS} ${FOBJS} |
159 |
# |
160 |
# create .o |
161 |
# |
162 |
@(${EGREEN} "Compiling CPP file: "${WHITE} "`basename $(@F) _${VER}.so | sed s/lib//`.cpp"; ${RESET}) |
163 |
@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} ${SUBINC}; |
164 |
# |
165 |
# create .so |
166 |
# |
167 |
@(${EGREEN} "Creating shared library: "${WHITE} "`basename $@`"; ${RESET}) |
168 |
@${CXX} ${CXXFLAGS} -Xlinker -soname=$(@F) -shared -o $@ -lg2c -I${DIRTOP}/${DIRINC} -I${DIRTOP} -I${SUBINC} -I${PAM_YODA}/include/yoda/ ${DIRTOP}/${DIRSRC}/`basename $(@F) _${VER}.so | sed s/lib//`.o ${FOBJS} ${COBJS} 1>/dev/null |
169 |
@ln -sf ${DIRTOP}/${DIRLIB}/$(@F) ${DIRTOP}/${DIRLIB}/$(patsubst %_${VER}.so,%.so,$(@F)) |
170 |
|
171 |
${CXXEXELIBS}: ${CPPOBJS} ${COBJS} ${CXXEXEOBJS} |
172 |
@(${EGREEN} "Creating exec file: "${WHITE} "$@"; ${RESET}) |
173 |
@${CXX} ${CXXFLAGS} -o ${DIRBIN}/$@ ${DIRTOP}/${DIRLIB}/$@.o ${DIRTOP}/${DIRLIB}/libGLTables.so ${DIRTOP}/${DIRLIB}/libsgp4.so ${CPPOBJS} ${PAM_YODA}/lib/libyoda.so -lThread `root-config --cflags --glibs` |
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} ${CPPOBJS} ${CXXEXEOBJS} ${FULLLINKCLIBS} ${FULLMACROCLIBS} ${FULLLINKMACROCLIBS} ${DIRSRC}/YodaProfilerVerl2.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 |
@${cp_dir} |
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}/YodaProfilerVerl2.cpp; echo ' char *YodaProfilerInfo(bool print){ if ( print ) printf("\nPAMELA YodaProfiler version: ${VER}\n\nCompiled on '${TODAY}' with: '${GCCVER}'\n\nOn: '${UNAMEA}'\n\n"); return("${VER}"); }' >> ${DIRTOP}/${DIRSRC}/YodaProfilerVerl2.cpp |
247 |
@sleep 0.8 |
248 |
|
249 |
|
250 |
info: |
251 |
@echo " " |
252 |
@${EGREEN} "Infos for package :" ${WHITE} ${PACKAGE} |
253 |
@${EGREEN} " VERSION :" ${WHITE} ${VER} |
254 |
@${EGREEN} " EXECUTABLES :" ${WHITE} ${EXECUTABLES} |
255 |
@${EGREEN} " LIBS :" ${WHITE} ${LIBS} |
256 |
@${EGREEN} " DOCS :" ${WHITE} ${DOCS} |
257 |
@${EGREEN} " SRCS :" ${WHITE} ${SRCS} |
258 |
@${EGREEN} " MACROS :" ${WHITE} ${MACROS} |
259 |
@${EGREEN} " INCLUDE :" ${WHITE} ${INCLUDE} |
260 |
@echo " " |
261 |
@${RESET} |
262 |
|
263 |
test: testpamenv |
264 |
|
265 |
testpamenv: ${PAM_ENV} |
266 |
|
267 |
root-config: OPT=--cflags |
268 |
root-config: |
269 |
@${test_cmd} |
270 |
|
271 |
# Here follows some usefull macros |
272 |
define test_and_cp |
273 |
wd=`pwd`;\ |
274 |
for i in ${TOBEMOVED} ; do \ |
275 |
wv=$${i##/*/}; \ |
276 |
dest=$${i/$${wv}/}; \ |
277 |
${EGREEN} "Testing for :" ${WHITE} "$${i}" ; ${RESET}; \ |
278 |
if [ ! "${FORCE}" ] ; then \ |
279 |
if [ ! -f $${i} ]; then \ |
280 |
${EGREEN} "Copying : "${WHITE} ${ORIGIN}/$${i##/*/} ;\ |
281 |
${EGREEN} " to: "${WHITE} $${i} ; ${RESET}; \ |
282 |
cp ${ORIGIN}/$${i##/*/} $${i}; \ |
283 |
else \ |
284 |
${ERED} "File already exist !!!! Please delete it " ${WHITE}; ${RESET}; \ |
285 |
fi;\ |
286 |
else \ |
287 |
if [ "${FORCE}" == "-u" ] ; then \ |
288 |
if [ "`basename $${i}`" != "`basename $${i} _${VER}.so`" ]; then \ |
289 |
${EYELLOW} "Removing: "${WHITE} ${PAM_LIB}/`basename $${i} _${VER}.so`_v*r*.so; ${RESET}; \ |
290 |
rm -f ${PAM_LIB}/`basename $${i} _${VER}.so`_v*r*.so ; \ |
291 |
${EGREEN} "Copying : "${WHITE} ${ORIGIN}/$${i##/*/} ;\ |
292 |
${EGREEN} " to: "${WHITE} $${i} ; ${RESET}; \ |
293 |
cp ${ORIGIN}/$${i##/*/} $${i}; \ |
294 |
else \ |
295 |
${EYELLOW} " Forcing copy: "${WHITE} ${ORIGIN}/$${i##/*/} ;\ |
296 |
${EYELLOW} " to: "${WHITE} $${i} ; ${RESET}; \ |
297 |
cp -f ${ORIGIN}/$${i##/*/} $${i}; \ |
298 |
fi; \ |
299 |
else \ |
300 |
${EYELLOW} " Forcing copy: "${WHITE} ${ORIGIN}/$${i##/*/} ;\ |
301 |
${EYELLOW} " to: "${WHITE} $${i} ; ${RESET}; \ |
302 |
cp ${FORCE} ${ORIGIN}/$${i##/*/} $${i}; \ |
303 |
fi;\ |
304 |
fi ;\ |
305 |
if [ ! -z ${LINK} ] ; then \ |
306 |
${EGREEN} "Creating symlink from : "${WHITE} $${wv/_${VER}/} ;\ |
307 |
${EGREEN} " to : "${WHITE} $${i##/*/} ; ${RESET}; \ |
308 |
cd $${dest}; \ |
309 |
ln -sf $${wv} $${wv/_${VER}/}; \ |
310 |
cd $${wd}; \ |
311 |
fi \ |
312 |
done |
313 |
endef |
314 |
|
315 |
define cp_dir |
316 |
wd=`pwd`;\ |
317 |
for i in ${TOBEMOVED} ; do \ |
318 |
wv=$${i##/*/}; \ |
319 |
dest=$${i/$${wv}/}; \ |
320 |
${EYELLOW} " Copying directory: "${WHITE} ${ORIGIN}/$${i##/*/} ;\ |
321 |
${EYELLOW} " to: "${WHITE} ${PAM_CALIB} ; ${RESET}; \ |
322 |
cp -rf ${ORIGIN}/$${i##/*/} ${PAM_CALIB}; \ |
323 |
done |
324 |
endef |
325 |
|
326 |
define test_and_mk |
327 |
${EGREEN} "Testing for :" ${WHITE} "$@"; ${RESET} |
328 |
test -d "$@" || \ |
329 |
(${EGREEN} "Creating : "${WHITE} "$@"; ${RESET}; mkdir -p $@) |
330 |
endef |
331 |
|
332 |
define test_env |
333 |
${EGREEN} "Testing for env:" ${WHITE} $(patsubst %_env,%,$@); ${RESET} |
334 |
printenv $(patsubst %_env,%,$@) 1>/dev/null || \ |
335 |
(${ERED} "ERROR, variable : "${WHITE} $(patsubst %_env,%,$@) \ |
336 |
${RED} "not defined !!! Check your env. settings"; \ |
337 |
${RESET}; exit 1) |
338 |
${EGREEN} " Defined:" ${WHITE} $${$(patsubst %_env,%,$@)}; ${RESET} |
339 |
endef |
340 |
|
341 |
define test_cmd |
342 |
${EGREEN} "Testing for cmd:" ${WHITE} $@ ${OPT}; ${RESET} |
343 |
$@ ${OPT} 1>/dev/null 2>&1 || \ |
344 |
(${ERED} "ERROR, command : "${WHITE} $@ ${OPT}\ |
345 |
${RED} "not found !!! Check your installation"; \ |
346 |
${RESET}; exit 1) |
347 |
${EGREEN} " Present:" ${WHITE} $@ ${OPT}; ${RESET} |
348 |
endef |
349 |
|
350 |
define test_and_rm |
351 |
for i in ${TOBEDEL}; do \ |
352 |
test -d $${i} || (${ERED} "Removing file :"${WHITE} $${i}; ${RESET}; \ |
353 |
rm -f $${i} ); \ |
354 |
test ! -d $${i} || (${ERED} "Removing dir :"${WHITE} $${i}; ${RESET}; \ |
355 |
rm -rf $${i} ); \ |
356 |
done |
357 |
endef |