c202f11fd1c74ee0cc0f2b66e46679391caa04a0
[u/mrichter/AliRoot.git] / build / MakefileDA
1 #-*- Mode: Makefile -*-
2
3 ONLINEDETECTORNAME:=$(firstword $(subst -, ,$(subst -clean,,$(subst -rpm,,$(subst daqDA-,,$(filter daqDA-% daqDA-%-rpm daqDA-%-clean,$(MAKECMDGOALS)))))))
4 DAMODULE:=$(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)))))))))))))
5
6 ifeq ($(ONLINEDETECTORNAME),SPD)
7 SUBDAMODULE:=SPD
8 else
9 ifeq ($(ONLINEDETECTORNAME),SDD)
10 SUBDAMODULE:=SDD
11 else
12 ifeq ($(ONLINEDETECTORNAME),SSD)
13 SUBDAMODULE:=SSD
14 else
15 ifeq ($(ONLINEDETECTORNAME),CPV)
16 SUBDAMODULE:=CPV
17 else
18 ifeq ($(ONLINEDETECTORNAME),MCH)
19 SUBDAMODULE:=TRK
20 else
21 ifeq ($(ONLINEDETECTORNAME),MTR)
22 SUBDAMODULE:=TRG
23 endif
24 endif
25 endif
26 endif
27 endif
28 endif
29
30 DANAME=$(word 2,$(subst -, ,$(subst -clean,,$(subst -rpm,,$(subst daqDA-,,$(filter daqDA-% daqDA-%-rpm daqDA-%-clean,$(MAKECMDGOALS)))))))
31
32 ifneq ($(DANAME),)
33
34 DATARGETNAME:=daqDA-$(ONLINEDETECTORNAME)-$(DANAME)
35
36 ifeq ($(DANAME),NONAME)
37 DANAME:=
38 endif
39
40 ifneq ($(findstring $(DAMODULE),$(MODULES)),)
41
42 CXXFLAGS+=-I${ALICE_ROOT}/RAW
43 CXXFLAGS+=-I${ALICE_ROOT}/$(DAMODULE)
44 CXXFLAGS+=$(addprefix -I,$(filter-out %tgt_${ALICE_TARGET},$(filter-out %CVS,$(patsubst %/,%,$(shell ls -d ${ALICE_ROOT}/$(DAMODULE)/*/)))))
45
46 DATARGETDIR=${DAMODULE}/tgt_${ALICE_TARGET}
47 DASRC=${DAMODULE}/${DAMODULE}$(SUBDAMODULE)${DANAME}da.cxx
48 DAOBJ=${DATARGETDIR}/${DAMODULE}$(SUBDAMODULE)${DANAME}da.o
49 DADEP=${DATARGETDIR}/${DAMODULE}$(SUBDAMODULE)${DANAME}da.d
50 DALIB=${ALICE_ROOT}/lib/tgt_${ALICE_TARGET}/lib${DAMODULE}$(SUBDAMODULE)${DANAME}DA.a
51 DAEXE=${ALICE_ROOT}/bin/tgt_${ALICE_TARGET}/${DAMODULE}$(SUBDAMODULE)${DANAME}da.exe
52
53 DAVERSION=$(firstword $(shell cvs status $(DASRC) | grep "Working revision:" | cut -d: -f2 ))
54
55 DAROOTRELEASE=$(subst /,.,$(shell root-config --version))
56
57 DAALIROOTRELEASE=$(subst -,.,$(firstword $(shell cvs status $(DASRC) | grep "Sticky Tag:" | cut -d: -f2 )))
58 ifeq ($(DAALIROOTRELEASE),(none))
59 DAALIROOTRELEASE:="HEAD_"$(subst -,.,$(shell date --iso-8601))
60 endif
61
62 DAARCNAME=$(patsubst %-,%,daqDA-${ONLINEDETECTORNAME}-${DANAME})
63 DAARC=$(DAARCNAME)-$(DAVERSION)
64 DATAR=${DATARGETDIR}/$(DAARC).src.tar.gz
65 DASPECFILE=${DATARGETDIR}/$(DAMODULE)$(SUBDAMODULE)$(DANAME)da.spec
66 DAMAKEFILE=${DATARGETDIR}/${DAMODULE}$(SUBDAMODULE)${DANAME}da.make
67
68 ifeq ($(DAQDALIB_PATH),)
69 DAQDADIR=${ALICE}/daqDAlib
70 else
71 DAQDADIR=${DAQDALIB_PATH}
72 endif
73 DAQDALIB=$(DAQDADIR)/libdaqDA.a
74
75 ROOTLIBDIR=$(shell root-config --libdir)
76
77 SYSLIBS=-ldl
78
79 MONITORLIBS=$(shell date-config --monitorlibs=noshift)
80
81 ALIROOTALIBS=$(RAWDatabaseALIB) $(RAWDatarecALIB) $(RAWDatasimALIB) $(STEERBaseALIB) $(STEERALIB) $(CDBALIB) $(ESDALIB) $(AODALIB)
82
83 ALIROOTALIBS+=$($(DAMODULE)ALIBS)
84
85 EXTRAROOTLIB=${ALICE_ROOT}/lib/tgt_${ALICE_TARGET}/libRootExtra.a
86
87 EXTRADAMODULE:=$(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)))))))))))
88
89 ifneq ($(EXTRADAMODULE),)
90 CXXFLAGS+=-I${ALICE_ROOT}/$(EXTRADAMODULE)
91 CXXFLAGS+=$(addprefix -I,$(filter-out %tgt_${ALICE_TARGET},$(filter-out %CVS,$(patsubst %/,%,$(shell ls -d ${ALICE_ROOT}/$(EXTRADAMODULE)/*/)))))
92 ALIROOTALIBS+=$($(EXTRADAMODULE)ALIBS)
93 endif
94
95 DAOUTPUTFILES=$(sort $(shell grep TFile $(DASRC) | grep '(' | grep ')' | grep -i recreate | cut -d'(' -f2 | cut -d',' -f1 | cut -d')' -f1 ))
96 DAINPUTFILES=$(sort $(shell grep TFile $(DASRC) | grep '(' | grep ')' | grep -vi recreate | cut -d'(' -f2 | cut -d',' -f1 | cut -d')' -f1 ))
97 $(DATARGETNAME): $(DAEXE)
98
99 $(DAEXE): $(DAOBJ) $(LIBPATH) $(DALIB) $(DAQDALIB) $(EXTRAROOTLIB)
100         @echo "***** Making executable $(DAEXE) *****"
101         $(MUTE)$(LD) $(LDFLAGS) -o $@ $< \
102         $(DALIB) \
103         $(EXTRAROOTLIB) \
104         $(ROOTLIBDIR)/libRoot.a \
105         $(ROOTLIBDIR)/libfreetype.a $(ROOTLIBDIR)/libpcre.a \
106         $(DAQDALIB) $(MONITORLIBS) \
107         $(SYSLIBS)
108
109 $(DAOBJ): $(DASRC) $(DAQDADIR) $(DADEP) $(DATARGETDIR)
110         @echo "***** Compiling $(DASRC) *****"
111         $(MUTE)$(CXX) -c $(CXXFLAGS) -I$(DAQDADIR) $< -o $@
112
113 $(DADEP): $(DASRC) $(DAQDADIR) $(DATARGETDIR)
114         @echo "***** Making detector-algorithm dependencies $(DADEP) *****"
115         $(MUTE)$(CPP) -MM $(CXXFLAGS) $(addprefix -I$(ALICE_ROOT)/,$(MODULES)) -I$(DAQDADIR) $< > $@
116
117 -include $(DADEP)
118
119 $(DATARGETDIR):
120         $(MUTE)if [ ! -d '$@' ]; then echo "***** Making directory $@ *****"; mkdir -p $@; fi
121
122 $(DALIB): $(ALIROOTALIBS)
123         @echo "***** Linking static library $(DALIB) *****"
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
127
128 $(EXTRAROOTLIB): $(LIBPATH) 
129         $(MUTE)$(AR) r $@ `ls ${ROOTSYS}/vmc/src/*.o ${ROOTSYS}/treeplayer/src/*.o`
130
131 $(DATARGETNAME)-clean:
132         @echo "***** Cleaning $(DAMODULE)$(SUBDAMODULE)$(DANAME) detector-algorithm *****"
133         $(MUTE)rm -f $(DASPECFILE)
134         $(MUTE)rm -f $(DATAR)
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)
141         $(MUTE)rm -f $(EXTRAROOTLIB)
142
143 $(DAMAKEFILE): $(DATARGETDIR)
144         $(MUTE)rm -f $(DAMAKEFILE)
145         @echo "***** Making makefile $(DAMAKEFILE) *****"
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 "" >> $@
167         @echo "DAQDALIB=""$$""(DAQDADIR)/libdaqDA.a" >> $@
168         @echo "MONITORLIBS=""$$""(shell date-config --monitorlibs=noshift)" >> $@
169         @echo "" >> $@
170         @echo "${DAMODULE}${SUBDAMODULE}${DANAME}da.exe: ${DAMODULE}${SUBDAMODULE}${DANAME}da.o" >> $@
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 "" >> $@
179         @echo "${DAMODULE}${SUBDAMODULE}${DANAME}da.o: ${DAMODULE}${SUBDAMODULE}${DANAME}da.cxx" >> $@
180         @echo "         ""$$""(CXX) -c ""$$""(CXXFLAGS) -I""$$""(DAQDADIR) ""$$""< -o ""$$""@" >> $@
181         @echo "" >> $@
182         @echo "clean:" >> $@
183         @echo "         @rm -f ${DAMODULE}${SUBDAMODULE}${DANAME}da.exe ${DAMODULE}${SUBDAMODULE}${DANAME}da.o" >> $@
184         @echo "" >> $@
185         @echo "install: ${DAMODULE}${SUBDAMODULE}${DANAME}da.exe" >> $@
186         @echo "         @if [ '""$$""(INSTALL_PATH)' == '' ]; then \\" >> $@
187         @echo "         echo Environment variable INSTALL_PATH undefined, cannot continue; \\" >> $@
188         @echo "         exit 1; \\" >> $@
189         @echo "         fi" >> $@
190         @echo "         @cp -p ${DAMODULE}${SUBDAMODULE}${DANAME}da.exe ""$$""(INSTALL_PATH)" >> $@
191
192 $(DATAR): $(DASRC) $(DAMAKEFILE) $(DASPECFILE)
193         @echo "***** Making archive $(DATAR) *****"
194         $(MUTE)rm -rf $(DATAR)
195         $(MUTE)rm -rf junk
196         $(MUTE)mkdir junk && mkdir junk/$(DAARC) && \
197         cp -a $(DASRC) junk/$(DAARC) && \
198         cp -a $(DAMAKEFILE) junk/$(DAARC)/Makefile && \
199         cp -a $(DASPECFILE) junk/$(DAARC)/$(DAMODULE)${SUBDAMODULE}$(DANAME)da.spec && \
200         cd junk && \
201         tar czf ../$(DATAR) * && \
202         cd .. && rm -rf junk
203
204 $(DASPECFILE): $(DATARGETDIR)
205         $(MUTE)rm -f $(DASPECFILE)
206         @echo "***** Making RPM spec-file $(DASPECFILE) *****"
207         @echo "# RPM specfile for $(DAMODULE)${SUBDAMODULE}$(DANAME) Detector Algorithm" >> $@
208         @echo "Summary: $(ONLINEDETECTORNAME) Detector Algorithm" >> $@
209         @echo "Name: $(DAARCNAME)" >> $@
210         @echo "Version: $(DAVERSION)" >> $@
211         @echo "Release: $(DAALIROOTRELEASE)" >> $@
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" >> $@
231         @echo "This is the $(ONLINEDETECTORNAME) $(DANAME) DA for online calibration." >> $@
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)" >> $@
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
288 $(DATARGETNAME)-rpm: $(DATAR) $(DASPECFILE) $(DALIB) $(DADEP) $(EXTRAROOTLIB)
289         @echo "***** Making RPMS for $(DAMODULE)$(SUBDAMODULE)$(DANAME) detector-algorithm *****"
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
293         $(MUTE)rpmbuild --quiet --define "_topdir $(ALICE_ROOT)/junk" --nodeps -bb $(DASPECFILE)
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
298 else
299
300 $(DATARGETNAME):        $(DATARGETNAME)-clean
301 $(DATARGETNAME)-clean:  $(DATARGETNAME)-rpm
302 $(DATARGETNAME)-rpm:
303         @echo
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)                                               *"
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:                                                                                        *"
312         @echo "*              make TOF-da-rpm  (compiles, links TOF/TOFda.cxx and builds the TOF DA binary RPM)      *"
313         @echo "*              make ITS-SPD-da-rpm (compiles, link ITS/ITSSPDda.cxx and builds ITS SPD DA binary RPM) *"
314         @echo "*******************************************************************************************************"
315         @echo
316
317 endif
318
319 else
320
321 DAMODULEALLTARGETS:=$(notdir $(wildcard $(DAMODULE)/$(DAMODULE)$(SUBDAMODULE)*da.cxx))
322
323 daqDA-$(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
329 daqDA-$(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
335 daqDA-$(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
341 endif