New DA targets in order to facilitate the building and installing the DAs on the...
[u/mrichter/AliRoot.git] / build / MakefileDA
CommitLineData
17cb72ed 1#-*- Mode: Makefile -*-
2
0c662ab2 3ONLINEDETECTORNAME:=$(firstword $(subst -, ,$(subst -clean,,$(subst -rpm,,$(subst daqDA-,,$(filter daqDA-% daqDA-%-rpm daqDA-%-clean,$(MAKECMDGOALS)))))))
4DAMODULE:=$(subst SPD,ITS,$(subst SDD,ITS,$(subst SSD,ITS,$(subst HMP,HMPID,$(subst PHS,PHOS,$(subst CPV,PHOS,$(subst MCH,MUON,$(subst MTR,MUON,$(subst T00,T0,$(subst V00,VZERO,$(subst ACO,ACORDE,$(subst EMC,EMCAL,$(ONLINEDETECTORNAME)))))))))))))
35f91121 5
0c662ab2 6ifeq ($(ONLINEDETECTORNAME),SPD)
7SUBDAMODULE:=SPD
35f91121 8else
0c662ab2 9ifeq ($(ONLINEDETECTORNAME),SDD)
10SUBDAMODULE:=SDD
11else
12ifeq ($(ONLINEDETECTORNAME),SSD)
13SUBDAMODULE:=SSD
14else
15ifeq ($(ONLINEDETECTORNAME),CPV)
16SUBDAMODULE:=CPV
17else
18ifeq ($(ONLINEDETECTORNAME),MCH)
19SUBDAMODULE:=TRK
20else
21ifeq ($(ONLINEDETECTORNAME),MTR)
22SUBDAMODULE:=TRG
23endif
24endif
25endif
26endif
27endif
28endif
29
30DANAME=$(word 2,$(subst -, ,$(subst -clean,,$(subst -rpm,,$(subst daqDA-,,$(filter daqDA-% daqDA-%-rpm daqDA-%-clean,$(MAKECMDGOALS)))))))
31
32ifneq ($(DANAME),)
33
34DATARGETNAME:=daqDA-$(ONLINEDETECTORNAME)-$(DANAME)
35
36ifeq ($(DANAME),NONAME)
37DANAME:=
35f91121 38endif
39
40ifneq ($(findstring $(DAMODULE),$(MODULES)),)
4179078a 41
17cb72ed 42CXXFLAGS+=-I${ALICE_ROOT}/RAW
4caead95 43CXXFLAGS+=-I${ALICE_ROOT}/$(DAMODULE)
44CXXFLAGS+=$(addprefix -I,$(filter-out %tgt_${ALICE_TARGET},$(filter-out %CVS,$(patsubst %/,%,$(shell ls -d ${ALICE_ROOT}/$(DAMODULE)/*/)))))
17cb72ed 45
f2d76654 46DATARGETDIR=${DAMODULE}/tgt_${ALICE_TARGET}
0c662ab2 47DASRC=${DAMODULE}/${DAMODULE}$(SUBDAMODULE)${DANAME}da.cxx
48DAOBJ=${DATARGETDIR}/${DAMODULE}$(SUBDAMODULE)${DANAME}da.o
49DADEP=${DATARGETDIR}/${DAMODULE}$(SUBDAMODULE)${DANAME}da.d
50DALIB=${ALICE_ROOT}/lib/tgt_${ALICE_TARGET}/lib${DAMODULE}$(SUBDAMODULE)${DANAME}DA.a
51DAEXE=${ALICE_ROOT}/bin/tgt_${ALICE_TARGET}/${DAMODULE}$(SUBDAMODULE)${DANAME}da.exe
17cb72ed 52
35f91121 53DAVERSION=$(firstword $(shell cvs status $(DASRC) | grep "Working revision:" | cut -d: -f2 ))
54
55DAROOTRELEASE=$(subst /,.,$(shell root-config --version))
f2d76654 56
35f91121 57DAALIROOTRELEASE=$(subst -,.,$(firstword $(shell cvs status $(DASRC) | grep "Sticky Tag:" | cut -d: -f2 )))
58ifeq ($(DAALIROOTRELEASE),(none))
59DAALIROOTRELEASE:="HEAD_"$(subst -,.,$(shell date --iso-8601))
f2d76654 60endif
61
0c662ab2 62DAARCNAME=$(patsubst %-,%,daqDA-${ONLINEDETECTORNAME}-${DANAME})
63DAARC=$(DAARCNAME)-$(DAVERSION)
f2d76654 64DATAR=${DATARGETDIR}/$(DAARC).src.tar.gz
0c662ab2 65DASPECFILE=${DATARGETDIR}/$(DAMODULE)$(SUBDAMODULE)$(DANAME)da.spec
66DAMAKEFILE=${DATARGETDIR}/${DAMODULE}$(SUBDAMODULE)${DANAME}da.make
e06bd7b4 67
35f91121 68ifeq ($(DAQDALIB_PATH),)
17cb72ed 69DAQDADIR=${ALICE}/daqDAlib
35f91121 70else
71DAQDADIR=${DAQDALIB_PATH}
72endif
17cb72ed 73DAQDALIB=$(DAQDADIR)/libdaqDA.a
74
75ROOTLIBDIR=$(shell root-config --libdir)
76
4179078a 77SYSLIBS=-ldl
e06bd7b4 78
17cb72ed 79MONITORLIBS=$(shell date-config --monitorlibs=noshift)
80
9c678667 81ALIROOTALIBS=$(RAWDatabaseALIB) $(RAWDatarecALIB) $(RAWDatasimALIB) $(STEERBaseALIB) $(STEERALIB) $(CDBALIB) $(ESDALIB) $(AODALIB)
17cb72ed 82
4caead95 83ALIROOTALIBS+=$($(DAMODULE)ALIBS)
17cb72ed 84
35f91121 85EXTRAROOTLIB=${ALICE_ROOT}/lib/tgt_${ALICE_TARGET}/libRootExtra.a
17cb72ed 86
35f91121 87EXTRADAMODULE:=$(firstword $(subst /,,$(subst $(ALICE_ROOT),,$(filter-out $(ALICE_ROOT)/STEER/ $(ALICE_ROOT)/RAW/ $(ALICE_ROOT)/$(DAMODULE)% $(ALICE_ROOT)/include/,$(sort $(dir $(filter $(ALICE_ROOT)%,$(filter-out %.o:,$(filter-out %.cxx,$(filter-out \,$(shell if [ -f "${DADEP}" ]; then cat $(DADEP); fi)))))))))))
17cb72ed 88
35f91121 89ifneq ($(EXTRADAMODULE),)
90CXXFLAGS+=-I${ALICE_ROOT}/$(EXTRADAMODULE)
91CXXFLAGS+=$(addprefix -I,$(filter-out %tgt_${ALICE_TARGET},$(filter-out %CVS,$(patsubst %/,%,$(shell ls -d ${ALICE_ROOT}/$(EXTRADAMODULE)/*/)))))
92ALIROOTALIBS+=$($(EXTRADAMODULE)ALIBS)
17cb72ed 93endif
94
35f91121 95DAOUTPUTFILES=$(sort $(shell grep TFile $(DASRC) | grep '(' | grep ')' | grep -i recreate | cut -d'(' -f2 | cut -d',' -f1 | cut -d')' -f1 ))
96DAINPUTFILES=$(sort $(shell grep TFile $(DASRC) | grep '(' | grep ')' | grep -vi recreate | cut -d'(' -f2 | cut -d',' -f1 | cut -d')' -f1 ))
35f91121 97$(DATARGETNAME): $(DAEXE)
98
99$(DAEXE): $(DAOBJ) $(LIBPATH) $(DALIB) $(DAQDALIB) $(EXTRAROOTLIB)
f2d76654 100 @echo "***** Making executable $(DAEXE) *****"
35f91121 101 $(MUTE)$(LD) $(LDFLAGS) -o $@ $< \
102 $(DALIB) \
103 $(EXTRAROOTLIB) \
4179078a 104 $(ROOTLIBDIR)/libRoot.a \
105 $(ROOTLIBDIR)/libfreetype.a $(ROOTLIBDIR)/libpcre.a \
35f91121 106 $(DAQDALIB) $(MONITORLIBS) \
107 $(SYSLIBS)
17cb72ed 108
f2d76654 109$(DAOBJ): $(DASRC) $(DAQDADIR) $(DADEP) $(DATARGETDIR)
110 @echo "***** Compiling $(DASRC) *****"
4caead95 111 $(MUTE)$(CXX) -c $(CXXFLAGS) -I$(DAQDADIR) $< -o $@
4179078a 112
f2d76654 113$(DADEP): $(DASRC) $(DAQDADIR) $(DATARGETDIR)
114 @echo "***** Making detector-algorithm dependencies $(DADEP) *****"
35f91121 115 $(MUTE)$(CPP) -MM $(CXXFLAGS) $(addprefix -I$(ALICE_ROOT)/,$(MODULES)) -I$(DAQDADIR) $< > $@
17cb72ed 116
117-include $(DADEP)
118
f2d76654 119$(DATARGETDIR):
120 $(MUTE)if [ ! -d '$@' ]; then echo "***** Making directory $@ *****"; mkdir -p $@; fi
121
17cb72ed 122$(DALIB): $(ALIROOTALIBS)
f2d76654 123 @echo "***** Linking static library $(DALIB) *****"
4caead95 124 $(MUTE)rm -rf $@
125 $(MUTE)rm -rf junk
126 $(MUTE)mkdir junk && cd junk && $(addprefix $(AR) x ../,$(addsuffix &&,$^)) $(AR) r $@ *.o && cd .. && rm -rf junk
17cb72ed 127
35f91121 128$(EXTRAROOTLIB): $(LIBPATH)
129 $(MUTE)$(AR) r $@ `ls ${ROOTSYS}/vmc/src/*.o ${ROOTSYS}/treeplayer/src/*.o`
130
131$(DATARGETNAME)-clean:
0c662ab2 132 @echo "***** Cleaning $(DAMODULE)$(SUBDAMODULE)$(DANAME) detector-algorithm *****"
f2d76654 133 $(MUTE)rm -f $(DASPECFILE)
134 $(MUTE)rm -f $(DATAR)
4caead95 135 $(MUTE)rm -f $(DAEXE)
136 $(MUTE)rm -f $(DAOBJ)
137 $(MUTE)rm -f $(DADEP)
138 $(MUTE)rm -f $(DAMAKEFILE)
139 $(MUTE)rm -f $(DALIB)
140 $(MUTE)rm -f $(ALIROOTALIBS)
35f91121 141 $(MUTE)rm -f $(EXTRAROOTLIB)
17cb72ed 142
f2d76654 143$(DAMAKEFILE): $(DATARGETDIR)
35f91121 144 $(MUTE)rm -f $(DAMAKEFILE)
f2d76654 145 @echo "***** Making makefile $(DAMAKEFILE) *****"
35f91121 146 @echo "####################################################" >> $@
147 @echo "# Makefile for Detector Algorithm" >> $@
148 @echo "#" >> $@
149 @echo "# It is necessary to setup build environment before" >> $@
150 @echo "# using make:" >> $@
151 @echo "# - define path to daqDAlib (env. DAQDALIB_PATH)" >> $@
152 @echo "#" >> $@
153 @echo "####################################################" >> $@
154 @echo "" >> $@
155 @echo "CXX=$(CXX)" >> $@
156 @echo "LD=$(LD)" >> $@
157 @echo "" >> $@
158 @echo "CXXFLAGS=$(CXXFLAGS)" >> $@
159 @echo "LDFLAGS=$(LDFLAGS)" >> $@
160 @echo "" >> $@
161 @echo "ifeq (""$$""(DAQDALIB_PATH),)" >> $@
162 @echo "DAQDADIR=${ALICE}/daqDAlib" >> $@
163 @echo "else" >> $@
164 @echo "DAQDADIR=""$$""(DAQDALIB_PATH)" >> $@
165 @echo "endif" >> $@
166 @echo "" >> $@
e06bd7b4 167 @echo "DAQDALIB=""$$""(DAQDADIR)/libdaqDA.a" >> $@
168 @echo "MONITORLIBS=""$$""(shell date-config --monitorlibs=noshift)" >> $@
35f91121 169 @echo "" >> $@
0c662ab2 170 @echo "${DAMODULE}${SUBDAMODULE}${DANAME}da.exe: ${DAMODULE}${SUBDAMODULE}${DANAME}da.o" >> $@
35f91121 171 @echo " ""$$""(LD) ""$$""(LDFLAGS) -o ""$$""@ ""$$""< \\" >> $@
172 @echo " $(DALIB) \\" >> $@
173 @echo " $(EXTRAROOTLIB) \\" >> $@
174 @echo " ""$$""(ROOTSYS)/lib/libRoot.a \\" >> $@
175 @echo " ""$$""(ROOTSYS)/lib/libfreetype.a ""$$""(ROOTSYS)/lib/libpcre.a \\" >> $@
176 @echo " ""$$""(DAQDALIB) ""$$""(MONITORLIBS) \\" >> $@
177 @echo " $(SYSLIBS)" >> $@
178 @echo "" >> $@
0c662ab2 179 @echo "${DAMODULE}${SUBDAMODULE}${DANAME}da.o: ${DAMODULE}${SUBDAMODULE}${DANAME}da.cxx" >> $@
e06bd7b4 180 @echo " ""$$""(CXX) -c ""$$""(CXXFLAGS) -I""$$""(DAQDADIR) ""$$""< -o ""$$""@" >> $@
35f91121 181 @echo "" >> $@
e06bd7b4 182 @echo "clean:" >> $@
0c662ab2 183 @echo " @rm -f ${DAMODULE}${SUBDAMODULE}${DANAME}da.exe ${DAMODULE}${SUBDAMODULE}${DANAME}da.o" >> $@
35f91121 184 @echo "" >> $@
0c662ab2 185 @echo "install: ${DAMODULE}${SUBDAMODULE}${DANAME}da.exe" >> $@
f2d76654 186 @echo " @if [ '""$$""(INSTALL_PATH)' == '' ]; then \\" >> $@
187 @echo " echo Environment variable INSTALL_PATH undefined, cannot continue; \\" >> $@
188 @echo " exit 1; \\" >> $@
189 @echo " fi" >> $@
0c662ab2 190 @echo " @cp -p ${DAMODULE}${SUBDAMODULE}${DANAME}da.exe ""$$""(INSTALL_PATH)" >> $@
f2d76654 191
35f91121 192$(DATAR): $(DASRC) $(DAMAKEFILE) $(DASPECFILE)
f2d76654 193 @echo "***** Making archive $(DATAR) *****"
194 $(MUTE)rm -rf $(DATAR)
4caead95 195 $(MUTE)rm -rf junk
35f91121 196 $(MUTE)mkdir junk && mkdir junk/$(DAARC) && \
197 cp -a $(DASRC) junk/$(DAARC) && \
f2d76654 198 cp -a $(DAMAKEFILE) junk/$(DAARC)/Makefile && \
0c662ab2 199 cp -a $(DASPECFILE) junk/$(DAARC)/$(DAMODULE)${SUBDAMODULE}$(DANAME)da.spec && \
17cb72ed 200 cd junk && \
f2d76654 201 tar czf ../$(DATAR) * && \
17cb72ed 202 cd .. && rm -rf junk
4179078a 203
f2d76654 204$(DASPECFILE): $(DATARGETDIR)
35f91121 205 $(MUTE)rm -f $(DASPECFILE)
f2d76654 206 @echo "***** Making RPM spec-file $(DASPECFILE) *****"
0c662ab2 207 @echo "# RPM specfile for $(DAMODULE)${SUBDAMODULE}$(DANAME) Detector Algorithm" >> $@
208 @echo "Summary: $(ONLINEDETECTORNAME) Detector Algorithm" >> $@
209 @echo "Name: $(DAARCNAME)" >> $@
f2d76654 210 @echo "Version: $(DAVERSION)" >> $@
0c662ab2 211 @echo "Release: $(DAALIROOTRELEASE)" >> $@
f2d76654 212 @echo "Copyright: CERN Alice DAQ/Offine" >> $@
213 @echo "Source: %{name}-%{version}.src.tar.gz" >> $@
214 @echo "Group: Applications/Alice" >> $@
215 @echo "Prefix: /opt/%{name}" >> $@
216 @echo "BuildRoot: %{_tmppath}/%{name}-root" >> $@
217 @echo "" >> $@
218 @echo "# automatic dependencies" >> $@
219 @echo "AutoReqProv: yes" >> $@
220 @echo "" >> $@
221 @echo "# list here required RPM packages for compilation" >> $@
222 @echo "BuildRequires: date" >> $@
223 @echo "" >> $@
224 @echo "# list here required RPM packages for runtime" >> $@
225 @echo "Requires: date" >> $@
226 @echo "" >> $@
227 @echo "# You can specify other dependencies in the description tag below." >> $@
228 @echo "" >> $@
229 @echo "# description of the package" >> $@
230 @echo "%description" >> $@
0c662ab2 231 @echo "This is the $(ONLINEDETECTORNAME) $(DANAME) DA for online calibration." >> $@
35f91121 232 @echo "It uses data from $(DAMODULE) and $(EXTRADAMODULE) detectors at run time." >> $@
233 @echo "Build requires: daqDAlib, date, AliRoot $(DAALIROOTRELEASE), ROOT $(DAROOTRELEASE)." >> $@
234 @echo "Runtime requires: date." >> $@
235 @echo "Files produced: $(DAOUTPUTFILES)" >> $@
236 @echo "Files used: $(DAINPUTFILES)" >> $@
f2d76654 237 @echo "" >> $@
238 @echo "#################################################################" >> $@
239 @echo "# Do not modify following scripts" >> $@
240 @echo "#################################################################" >> $@
241 @echo "" >> $@
242 @echo "# here is defined the installation root directory" >> $@
243 @echo "%define pkgname %{name}-%{version}" >> $@
244 @echo "%define destdir %{prefix}" >> $@
245 @echo "" >> $@
246 @echo "# pre-compilation script: extract from tarball" >> $@
247 @echo "%prep" >> $@
248 @echo "# extract archive" >> $@
249 @echo "%setup -n %{pkgname}" >> $@
250 @echo "" >> $@
251 @echo "# compile" >> $@
252 @echo "%build" >> $@
253 @echo "export DATE_SITE=" >> $@
254 @echo ". /date/setup.sh" >> $@
255 @echo "gmake" >> $@
256 @echo "" >> $@
257 @echo "# install runtime files" >> $@
258 @echo "%install" >> $@
259 @echo "#remove install dir if existing" >> $@
260 @echo "[ -d ""$$""RPM_BUILD_ROOT ] && rm -rf ""$$""RPM_BUILD_ROOT" >> $@
261 @echo "#make install in install root directory" >> $@
262 @echo "mkdir -p ""$$""RPM_BUILD_ROOT/%{prefix}" >> $@
263 @echo "make install INSTALL_PATH=""$$""RPM_BUILD_ROOT/%{prefix}" >> $@
264 @echo "" >> $@
265 @echo "# clean RPM build files" >> $@
266 @echo "%clean" >> $@
267 @echo "# remove source files" >> $@
268 @echo "rm -rf ""$$""RPM_BUILD_DIR/%{pkgname}" >> $@
269 @echo "# remove installed files" >> $@
270 @echo "rm -rf ""$$""RPM_BUILD_ROOT" >> $@
271 @echo "" >> $@
272 @echo "# pre-install script" >> $@
273 @echo "%pre" >> $@
274 @echo "" >> $@
275 @echo "# list of files to be installed" >> $@
276 @echo "%files" >> $@
277 @echo "%defattr (-,root,root)" >> $@
278 @echo "%{destdir}" >> $@
279 @echo "" >> $@
280 @echo "# post-install script" >> $@
281 @echo "# launched after rpm installed" >> $@
282 @echo "%post" >> $@
283 @echo "" >> $@
284 @echo "# post-uninstall script" >> $@
285 @echo "# launched after rpm removed" >> $@
286 @echo "%postun" >> $@
287
35f91121 288$(DATARGETNAME)-rpm: $(DATAR) $(DASPECFILE) $(DALIB) $(DADEP) $(EXTRAROOTLIB)
0c662ab2 289 @echo "***** Making RPMS for $(DAMODULE)$(SUBDAMODULE)$(DANAME) detector-algorithm *****"
f2d76654 290 $(MUTE)rm -rf junk
291 $(MUTE)mkdir -p junk/SOURCES junk/SPECS junk/BUILD junk/RPMS junk/SRPMS
292 $(MUTE)cp $(DATAR) junk/SOURCES
35f91121 293 $(MUTE)rpmbuild --quiet --define "_topdir $(ALICE_ROOT)/junk" --nodeps -bb $(DASPECFILE)
f2d76654 294 $(MUTE)find junk/ -name "$(DAARC)-*.rpm" -exec cp -p {} . \;
295 $(MUTE)rm -rf junk
296 @echo "***** RPMS created and put $(ALICE_ROOT) folder *****"
297
4179078a 298else
299
35f91121 300$(DATARGETNAME): $(DATARGETNAME)-clean
feddbf46 301$(DATARGETNAME)-clean: $(DATARGETNAME)-rpm
35f91121 302$(DATARGETNAME)-rpm:
4179078a 303 @echo
35f91121 304 @echo "*******************************************************************************************************"
305 @echo "* In order to build a detector-algorithm package you have run AliRoot make with the following syntax: *"
306 @echo "* For example: make TPC-da (compiles and link TPC/TPCda.cxx DA source file and produces TPCda.exe) *"
307 @echo "* make MUON-TRK-da (MUON is the AliRoot module, TRK is the name of the DA algorithm, *"
308 @echo "* this target will compile and link MUON/MUONTRKda.cxx and will *"
309 @echo "* produce MUONTRKda.exe) *"
feddbf46 310 @echo "* In case you want to build the corresponding DA binary RPM, you have to add -rpm to your target name,*"
311 @echo "* for example: *"
35f91121 312 @echo "* make TOF-da-rpm (compiles, links TOF/TOFda.cxx and builds the TOF DA binary RPM) *"
feddbf46 313 @echo "* make ITS-SPD-da-rpm (compiles, link ITS/ITSSPDda.cxx and builds ITS SPD DA binary RPM) *"
35f91121 314 @echo "*******************************************************************************************************"
4179078a 315 @echo
316
4179078a 317endif
0c662ab2 318
319else
320
321DAMODULEALLTARGETS:=$(notdir $(wildcard $(DAMODULE)/$(DAMODULE)$(SUBDAMODULE)*da.cxx))
322
323daqDA-$(ONLINEDETECTORNAME): $(DAMODULEALLTARGETS)
324 @echo "***** All available detector-algorithms for $(ONLINEDETECTORNAME) have been built *****"
325
326%da.cxx:
327 $(MUTE)make $(patsubst %-,%-NONAME,$(addprefix daqDA-,$(subst $(DAMODULE)$(SUBDAMODULE),$(ONLINEDETECTORNAME)-,$(subst da.cxx,,$@))))
328
329daqDA-$(ONLINEDETECTORNAME)-rpm: $(addsuffix -rpm,$(DAMODULEALLTARGETS))
330 @echo "***** All available detector-algorithm RPMs for $(ONLINEDETECTORNAME) have been built *****"
331
332%da.cxx-rpm:
333 $(MUTE)make $(subst --,-NONAME-,$(addsuffix -rpm,$(addprefix daqDA-,$(subst $(DAMODULE)$(SUBDAMODULE),$(ONLINEDETECTORNAME)-,$(subst da.cxx-rpm,,$@)))))
334
335daqDA-$(ONLINEDETECTORNAME)-clean: $(addsuffix -clean,$(DAMODULEALLTARGETS))
336 @echo "***** All available detector-algorithms for $(ONLINEDETECTORNAME) have been cleaned *****"
337
338%da.cxx-clean:
339 $(MUTE)make $(subst --,-NONAME-,$(addsuffix -clean,$(addprefix daqDA-,$(subst $(DAMODULE)$(SUBDAMODULE),$(ONLINEDETECTORNAME)-,$(subst da.cxx-clean,,$@)))))
340
341endif