1 |
# |
2 |
# RawReader makefile |
3 |
# |
4 |
# SOFTWARE VERSION |
5 |
VER= v1r13 |
6 |
# An almost general purpouse Makefile for PAMELA repository |
7 |
# Let's start with some usefull definition for colorize the echo |
8 |
RED='\E[1;31;40m' |
9 |
GREEN='\E[1;32;40m' |
10 |
YELLOW='\E[1;33;40m' |
11 |
BLUE='\E[1;34;40m' |
12 |
WHITE='\E[1;37;40m' |
13 |
VIOLET='\E[1;35;40m' |
14 |
CYAN='\E[1;36;40m' |
15 |
# Here the echo definition to use them |
16 |
EVIOLET=echo -e ${VIOLET} |
17 |
ECYAN=echo -e ${CYAN} |
18 |
ERED=echo -e ${RED} |
19 |
EGREEN=echo -e ${GREEN} |
20 |
EYELLOW=echo -e ${YELLOW} |
21 |
EBLUE=echo -e ${BLUE} |
22 |
EWHITE=echo -e ${WHITE} |
23 |
# Reset the terminal |
24 |
RESET=tput sgr0 |
25 |
# Here the variables used to override the standard make flags |
26 |
# C |
27 |
CC=gcc |
28 |
CFLAGS+= -Wall -O3 -fPIC |
29 |
# F77 |
30 |
F77=g77 |
31 |
F77FLAGS= -Wall -Wno-globals -fno-bounds-check -g -extend_source -static -fno-backslash -O -fPIC |
32 |
# C++ |
33 |
CXX=g++ |
34 |
CXXFLAGS+= -Wall -O3 |
35 |
# Linker |
36 |
LD=g++ |
37 |
LDFLAGS+= |
38 |
# Here the variables definig the local directories |
39 |
DIRTOP=${shell pwd} |
40 |
DIRLIB=lib/${ARCH} |
41 |
DIRBIN=bin/${ARCH} |
42 |
DIRSRC=src |
43 |
DIRINC=inc |
44 |
DIRDOC=doc |
45 |
DIRDAT=dat |
46 |
# Here the PAMELA environmental variables to be checked |
47 |
PAM_ENV= PAM_BIN_env PAM_LIB_env PAM_INC_env PAM_DOC_env PAM_MACROS_env PAM_CALIB_env PAM_YODA_env |
48 |
# Here the local variables used to build the targets |
49 |
|
50 |
# Fortran sources if any |
51 |
FSRCS= |
52 |
FOBJS=$(FSRCS:${DIRSRC}%.for=${DIRBIN}%.o) |
53 |
FLIBS= |
54 |
FULLFLIBS=$(FLIBS:%=${DIRLIB}/lib%_${VER}.so) |
55 |
FULLLINKFLIBS=$(FLIBS:%=${DIRLIB}/lib%.so) |
56 |
|
57 |
# C sources if any |
58 |
CSRCS= |
59 |
COBJS=$(CSRCS:${DIRSRC}%.c=${DIRBIN}%.o) |
60 |
CLIBS= |
61 |
FULLCLIBS=$(CLIBS:%=${DIRLIB}/lib%_${VER}.so) |
62 |
FULLLINKCLIBS=$(CLIBS:%=${DIRLIB}/lib%.so) |
63 |
|
64 |
# C++ sources if any |
65 |
CXXSRCS=$(patsubst %,${DIRSRC}/%, \ |
66 |
CRC16.cpp \ |
67 |
Crc.cpp \ |
68 |
CrcHeader.cpp \ |
69 |
FindRoute.cpp \ |
70 |
Main.cpp \ |
71 |
Read.cpp \ |
72 |
RunHeaderReader.cpp \ |
73 |
Trunc.cpp \ |
74 |
Verify.cpp \ |
75 |
filename.cpp \ |
76 |
sort.cpp ) |
77 |
CXXOBJS=$(CXXSRCS:${DIRSRC}/%.cpp=${DIRBIN}/%.o) |
78 |
CXXLIBS=`root-config --libs` -lMySQL |
79 |
CXXFLAGS+= `root-config --cflags` -I${DIRINC} |
80 |
# |
81 |
CALIBFILES= |
82 |
DOCFILES= |
83 |
DATFILES=parameter.dat |
84 |
# Here the Variables used for info target |
85 |
PACKAGE=RawReader |
86 |
EXECUTABLES=RawReader.exe |
87 |
OBJS=${FOBJS} ${COBJS} ${CXXOBJS} |
88 |
LIBS=${FLIBS} ${CLIBS} ${CXXLIBS} |
89 |
DOCS= |
90 |
SRCS=${FSRCS} ${CRSCS} ${CXXSRCS} |
91 |
# |
92 |
TOBEDEL = ${OBJS} ${EXECUTABLES} |
93 |
# Let's start |
94 |
# all: test mkbindir mklibdir ${EXECUTABLES} |
95 |
all: mkbindir mklibdir ${EXECUTABLES} |
96 |
@echo -e ${GREEN} "" |
97 |
@(${EGREEN} " Finished, now you can install the package \n (use: make install or make upgrade or make forceinstall) \n or you can copy by hand the files: "; ${RESET}) |
98 |
@(${EBLUE} " - ${EXECUTABLES}" ) |
99 |
@(${EBLUE} " - ${DIRDAT}/${DATFILES}"; ${RESET}) |
100 |
@echo -e ${GREEN} "" |
101 |
@${RESET} |
102 |
|
103 |
${EXECUTABLES}: ${OBJS} |
104 |
@(${EGREEN} "Creating executables: "${WHITE} "$@"; ${RESET}) |
105 |
@${LD} ${LDFLAGS} -o $@ $^ ${LIBS} |
106 |
|
107 |
# Here some general rules to produce objects in our local dir |
108 |
# .o from fortran |
109 |
${DIRBIN}/%.o : ${DIRSRC}/%.for |
110 |
@(${EGREEN} "Creating object file: "${WHITE} "$@"; ${RESET}) |
111 |
@${F77} ${F77FLAGS} -c -o $@ $< -I${DIRINC} |
112 |
|
113 |
${DIRBIN}/%.o: ${DIRSRC}/%.cpp |
114 |
@(${EGREEN} "Creating object file: "${WHITE} "$@"; ${RESET}) |
115 |
@${CXX} ${CXXFLAGS} -c -o $@ $< -I${DIRINC} |
116 |
|
117 |
# .o from C |
118 |
${DIRBIN}/%.o : ${DIRSRC}/%.c |
119 |
@(${EGREEN} "Creating object file: "${WHITE} "$@"; ${RESET}) |
120 |
@${CC} ${CFLAGS} -c -o $@ $< -I${DIRINC} |
121 |
|
122 |
|
123 |
# .so from .o fortran |
124 |
${FULLFLIBS}: ${FOBJS} |
125 |
@(${EGREEN} "Creating library: "${WHITE} "$@"; ${RESET}) |
126 |
@${CXX} ${CXXFLAGS} -Xlinker -soname=$(@F) -shared -o $@ $^ -lg2c `cernlib mathlib` |
127 |
@(${EGREEN} "Creating symlink from : "${WHITE} "$@"; ${RESET}) |
128 |
@(${EGREEN} " to : "${WHITE} "${DIRLIB}/`basename $@ _${VER}.so`.so"; ${RESET}) |
129 |
@ln -sf `basename $@` ${DIRLIB}/`basename $@ _${VER}.so`.so |
130 |
|
131 |
# .so from .o c |
132 |
${FULLCLIBS}: ${COBJS} |
133 |
@(${EGREEN} "Creating library: "${WHITE} "$@"; ${RESET}) |
134 |
@${CXX} ${CXXFLAGS} -Xlinker -soname=$(@F) -shared -o $@ $^ -lg2c |
135 |
@(${EGREEN} "Creating symlink from : "${WHITE} "$@"; ${RESET}) |
136 |
@(${EGREEN} " to : "${WHITE} "${DIRLIB}/`basename $@ _${VER}.so`.so"; ${RESET}) |
137 |
@ln -sf `basename $@` ${DIRLIB}/`basename $@ _${VER}.so`.so |
138 |
|
139 |
# A small target to check environmental variables |
140 |
%_env: |
141 |
@${test_env} |
142 |
|
143 |
.PHONY: install installdoc installlib installmacros installinc installexe installcmacro |
144 |
.PHONY: clean depclean info mkbindir mklibdir testcern testpamenv test |
145 |
|
146 |
mkbindir: ${DIRBIN} |
147 |
${DIRBIN}: |
148 |
@${test_and_mk} |
149 |
|
150 |
mklibdir: ${DIRLIB} |
151 |
${DIRLIB}: |
152 |
@${test_and_mk} |
153 |
|
154 |
# Here what has to be deleted in clean target |
155 |
clean: |
156 |
@${test_and_rm} |
157 |
|
158 |
distclean: clean |
159 |
distclean: TOBEDEL= ${DIRBIN} ${DIRLIB} |
160 |
distclean: |
161 |
@${test_and_rm} |
162 |
|
163 |
forceinstall: FORCE=-f |
164 |
forceinstall: install |
165 |
|
166 |
upgrade: FORCE=-u |
167 |
upgrade: install |
168 |
|
169 |
#install: installlib installinc installmacros installcalib installdoc installexe installcmacro |
170 |
install: test installexe installdoc installdat |
171 |
|
172 |
installlib: LINK=y |
173 |
installlib: TOBEMOVED= $(FULLLIBS:${DIRLIB}%=${PAM_LIB}%) |
174 |
installlib: ORIGIN=${DIRLIB} |
175 |
installlib: |
176 |
@${test_and_cp} |
177 |
|
178 |
installinc: TOBEMOVED= $(INCSRCS:${DIRINC}/%=${PAM_INC}/%) |
179 |
installinc: ORIGIN=${DIRINC} |
180 |
installinc: |
181 |
@${test_and_cp} |
182 |
|
183 |
installexe: TOBEMOVED= $(EXESRCS:${DIRBIN}/%=${PAM_BIN}/%) |
184 |
installexe: ORIGIN=${DIRBIN} |
185 |
installexe: |
186 |
@${test_and_cp} |
187 |
|
188 |
installmacros: TOBEMOVED= $(MACROSSRCS:${DIRMACROS}/%=${PAM_MACROS}/%) |
189 |
installmacros: ORIGIN=${DIRMACROS} |
190 |
installmacros: |
191 |
@${test_and_cp} |
192 |
|
193 |
installcmacro: LINK=y |
194 |
installcmacro: TOBEMOVED= $(FULLMACROCLIBS:${DIRLIB}%=${PAM_LIB}%) |
195 |
installcmacro: ORIGIN=${DIRLIB} |
196 |
installcmacro: |
197 |
@${test_and_cp} |
198 |
|
199 |
installcalib: TOBEMOVED= $(CALIBFILES:${DIRCALIB}/%=${PAM_CALIB}/%) |
200 |
installcalib: ORIGIN=${DIRCALIB} |
201 |
installcalib: |
202 |
@${test_and_cp} |
203 |
|
204 |
installdoc: TOBEMOVED= $(DOCFILES:${DIRDOC}/%=${PAM_DOC}/%) |
205 |
installdoc: ORIGIN=${DIRDOC} |
206 |
installdoc: |
207 |
@${test_and_cp} |
208 |
|
209 |
installdat: TOBEMOVED= $(DATFILES:${DIRDAT}/%=${PAM_BIN}/%) |
210 |
installdat: ORIGIN=${DIRDAT} |
211 |
installdat: |
212 |
@${test_and_cp} |
213 |
|
214 |
info: |
215 |
@echo " " |
216 |
@${EGREEN} "Infos for package :" ${WHITE} ${PACKAGE} |
217 |
@${EGREEN} " VERSION :" ${WHITE} ${VER} |
218 |
@${EGREEN} " EXECUTABLES :" ${WHITE} ${EXECUTABLES} |
219 |
@${EGREEN} " LIBS :" ${WHITE} ${LIBS} |
220 |
@${EGREEN} " SRCS :" ${WHITE} ${SRCS} |
221 |
@${EGREEN} " OBJS :" ${WHITE} ${OBJS} |
222 |
@${EGREEN} " DOCS :" ${WHITE} ${DOCS} |
223 |
@${EGREEN} " PARAMETERS :" ${WHITE} ${DATFILES} |
224 |
@echo " " |
225 |
@${RESET} |
226 |
|
227 |
test: testpamenv testcernlib testcalocommon testlibtrack testlibreadb2maps testroot2paw |
228 |
|
229 |
testpamenv: ${PAM_ENV} |
230 |
|
231 |
testcernlib: cernlib root-config |
232 |
|
233 |
cernlib: |
234 |
@${test_cmd} |
235 |
|
236 |
root-config: OPT=--cflags |
237 |
root-config: |
238 |
@${test_cmd} |
239 |
|
240 |
# Here follows some usefull macros |
241 |
define test_and_cp |
242 |
wd=`pwd`;\ |
243 |
for i in ${TOBEMOVED} ; do \ |
244 |
wv=$${i##/*/}; \ |
245 |
dest=$${i/$${wv}/}; \ |
246 |
${EGREEN} "Testing for :" ${WHITE} "$${i}" ; ${RESET}; \ |
247 |
if [ ! "${FORCE}" ] ; then \ |
248 |
if [ ! -f $${i} ]; then \ |
249 |
${EGREEN} "Copying : "${WHITE} ${ORIGIN}/$${i##/*/} ;\ |
250 |
${EGREEN} " to: "${WHITE} $${i} ; ${RESET}; \ |
251 |
cp ${ORIGIN}/$${i##/*/} $${i}; \ |
252 |
else \ |
253 |
${ERED} "File already exist !!!! Please delete it " ${WHITE}; ${RESET}; \ |
254 |
fi;\ |
255 |
else \ |
256 |
if [ "${FORCE}" == "-u" ] ; then \ |
257 |
if [ "`basename $${i}`" != "`basename $${i} _${VER}.so`" ]; then \ |
258 |
${EYELLOW} "Removing: "${WHITE} ${PAM_LIB}/`basename $${i} _${VER}.so`_v*r*.so; ${RESET}; \ |
259 |
rm -f ${PAM_LIB}/`basename $${i} _${VER}.so`_v*r*.so ; \ |
260 |
${EGREEN} "Copying : "${WHITE} ${ORIGIN}/$${i##/*/} ;\ |
261 |
${EGREEN} " to: "${WHITE} $${i} ; ${RESET}; \ |
262 |
cp ${ORIGIN}/$${i##/*/} $${i}; \ |
263 |
else \ |
264 |
${EYELLOW} " Forcing copy: "${WHITE} ${ORIGIN}/$${i##/*/} ;\ |
265 |
${EYELLOW} " to: "${WHITE} $${i} ; ${RESET}; \ |
266 |
cp -f ${ORIGIN}/$${i##/*/} $${i}; \ |
267 |
fi; \ |
268 |
else \ |
269 |
${EYELLOW} " Forcing copy: "${WHITE} ${ORIGIN}/$${i##/*/} ;\ |
270 |
${EYELLOW} " to: "${WHITE} $${i} ; ${RESET}; \ |
271 |
cp ${FORCE} ${ORIGIN}/$${i##/*/} $${i}; \ |
272 |
fi;\ |
273 |
fi ;\ |
274 |
if [ ! -z ${LINK} ] ; then \ |
275 |
${EGREEN} "Creating symlink from : "${WHITE} $${wv/_${VER}/} ;\ |
276 |
${EGREEN} " to : "${WHITE} $${i##/*/} ; ${RESET}; \ |
277 |
cd $${dest}; \ |
278 |
ln -sf $${wv} $${wv/_${VER}/}; \ |
279 |
cd $${wd}; \ |
280 |
fi \ |
281 |
done |
282 |
endef |
283 |
|
284 |
define test_and_mk |
285 |
${EGREEN} "Testing for :" ${WHITE} "$@"; ${RESET} |
286 |
test -d "$@" || \ |
287 |
(${EGREEN} "Creating : "${WHITE} "$@"; ${RESET}; mkdir -p $@) |
288 |
endef |
289 |
|
290 |
define test_env |
291 |
${EGREEN} "Testing for env:" ${WHITE} $(patsubst %_env,%,$@); ${RESET} |
292 |
printenv $(patsubst %_env,%,$@) 1>/dev/null || \ |
293 |
(${ERED} "ERROR, variable : "${WHITE} $(patsubst %_env,%,$@) \ |
294 |
${RED} "not defined !!! Check your env. settings"; \ |
295 |
${RESET}; exit 1) |
296 |
${EGREEN} " Defined:" ${WHITE} $${$(patsubst %_env,%,$@)}; ${RESET} |
297 |
endef |
298 |
|
299 |
define test_cmd |
300 |
${EGREEN} "Testing for cmd:" ${WHITE} $@ ${OPT}; ${RESET} |
301 |
$@ ${OPT} 1>/dev/null 2>&1 || \ |
302 |
(${ERED} "ERROR, command : "${WHITE} $@ ${OPT}\ |
303 |
${RED} "not found !!! Check your installation"; \ |
304 |
${RESET}; exit 1) |
305 |
${EGREEN} " Present:" ${WHITE} $@ ${OPT}; ${RESET} |
306 |
endef |
307 |
|
308 |
define test_exist |
309 |
${EGREEN} "Testing for library:" ${WHITE} $@ ${OPT}; ${RESET} |
310 |
ls $@ 1>/dev/null 2>&1 || \ |
311 |
(${ERED} "ERROR, library : "${WHITE} $@ ${OPT}\ |
312 |
${RED} " Not found !!! Check your installation"; \ |
313 |
${RESET}; exit 1) |
314 |
${EGREEN} " Present:" ${WHITE} $@ ${OPT}; ${RESET} |
315 |
endef |
316 |
|
317 |
define test_and_rm |
318 |
for i in ${TOBEDEL}; do \ |
319 |
test -d $${i} || (${ERED} "Removing file :"${WHITE} $${i}; ${RESET}; \ |
320 |
rm -f $${i} ); \ |
321 |
test ! -d $${i} || (${ERED} "Removing dir :"${WHITE} $${i}; ${RESET}; \ |
322 |
rm -rf $${i} ); \ |
323 |
done |
324 |
endef |