Updated version of the HMPID DA. To be checked on real data by the experts and then...
[u/mrichter/AliRoot.git] / build / MakefileDA
index e06d457..d72106e 100644 (file)
 #-*- Mode: Makefile -*-
 
-ifdef DAMODULE
+DAMODULE=$(firstword $(subst -, ,$(subst -da,,$(subst -da-rpm,,$(subst -da-clean,,$(filter %-da %-da-rpm %-da-clean,$(MAKECMDGOALS)))))))
+DANAME=$(word 2,$(subst -, ,$(subst -da,,$(subst -da-rpm,,$(subst -da-clean,,$(filter %-da %-da-rpm %-da-clean,$(MAKECMDGOALS)))))))
 
-ifdef ALIROOTMODULES
-
-CXXFLAGS+=-I${ALICE_ROOT}/RAW
-
-ifneq ($(EXTRADAMODULE),) 
-CXXFLAGS+=-I${ALICE_ROOT}/$(EXTRADAMODULE)
+ifeq ($(DANAME),)
+DATARGETNAME=$(DAMODULE)-da
+else
+DATARGETNAME=$(DAMODULE)-$(DANAME)-da
 endif
 
-DASRC=${DAMODULE}/${DAMODULE}da.cxx
-DADEP=${DAMODULE}/${DAMODULE}da.d
-DAOBJ=${DAMODULE}/tgt_${ALICE_TARGET}/${DAMODULE}da.o
-DALIB=${ALICE_ROOT}/lib/tgt_${ALICE_TARGET}/lib${DAMODULE}DA.a
-DAEXE=${ALICE_ROOT}/bin/tgt_${ALICE_TARGET}/${DAMODULE}da.exe
+ifneq ($(findstring $(DAMODULE),$(MODULES)),)
 
-DAQDADIR=${ALICE}/daqDAlib
-DAQDALIB=$(DAQDADIR)/libdaqDA.a
-
-ROOTLIBDIR=$(shell root-config --libdir)
+CXXFLAGS+=-I${ALICE_ROOT}/RAW
+CXXFLAGS+=-I${ALICE_ROOT}/$(DAMODULE)
+CXXFLAGS+=$(addprefix -I,$(filter-out %tgt_${ALICE_TARGET},$(filter-out %CVS,$(patsubst %/,%,$(shell ls -d ${ALICE_ROOT}/$(DAMODULE)/*/)))))
 
-else
+DATARGETDIR=${DAMODULE}/tgt_${ALICE_TARGET}
+DASRC=${DAMODULE}/${DAMODULE}${DANAME}da.cxx
+DAOBJ=${DATARGETDIR}/${DAMODULE}${DANAME}da.o
+DADEP=${DATARGETDIR}/${DAMODULE}${DANAME}da.d
+DALIB=${ALICE_ROOT}/lib/tgt_${ALICE_TARGET}/lib${DAMODULE}${DANAME}DA.a
+DAEXE=${ALICE_ROOT}/bin/tgt_${ALICE_TARGET}/${DAMODULE}${DANAME}da.exe
 
-CXXFLAGS+=$(shell date-config --cflags)
-CXXFLAGS+=-Iinclude
-LD=$(CXX)
+DAVERSION=$(firstword $(shell cvs status $(DASRC) | grep "Working revision:" | cut -d: -f2 ))
 
-DASRC=./${DAMODULE}da.cxx
-DADEP=./${DAMODULE}da.d
-DAOBJ=./${DAMODULE}da.o
-DALIB=./lib${DAMODULE}DA.a
-DAEXE=./${DAMODULE}da.exe
+DAROOTRELEASE=$(subst /,.,$(shell root-config --version))
+DARELEASE:="Root_"$(DAROOTRELEASE)"__AliRoot_"
 
-DAQDADIR=./daqDAlib
-DAQDALIB=$(DAQDADIR)/libdaqDA.a
+DAALIROOTRELEASE=$(subst -,.,$(firstword $(shell cvs status $(DASRC) | grep "Sticky Tag:" | cut -d: -f2 )))
+ifeq ($(DAALIROOTRELEASE),(none))
+DAALIROOTRELEASE:="HEAD_"$(subst -,.,$(shell date --iso-8601))
+endif
+DARELEASE:=$(DARELEASE)$(DAALIROOTRELEASE)
 
-ROOTLIBDIR=.
+DAARC=daqDA-${DAMODULE}${DANAME}-calib-$(DAVERSION)
+DATAR=${DATARGETDIR}/$(DAARC).src.tar.gz
+DASPECFILE=${DATARGETDIR}/$(DAMODULE)$(DANAME)da.spec
 
-LIBPATH=
+DAMAKEFILE=${DATARGETDIR}/${DAMODULE}${DANAME}da.make
 
+ifeq ($(DAQDALIB_PATH),)
+DAQDADIR=${ALICE}/daqDAlib
+else
+DAQDADIR=${DAQDALIB_PATH}
 endif
+DAQDALIB=$(DAQDADIR)/libdaqDA.a
+
+ROOTLIBDIR=$(shell root-config --libdir)
 
 SYSLIBS=-ldl
+
 MONITORLIBS=$(shell date-config --monitorlibs=noshift)
 
-ALIROOTALIBS=$(RAWDatabaseALIB) $(RAWDatarecALIB) $(RAWDatasimALIB) $(STEERALIB) $(CDBALIB) $(ESDALIB)
+ALIROOTALIBS=$(RAWDatabaseALIB) $(RAWDatarecALIB) $(RAWDatasimALIB) $(STEERALIB) $(CDBALIB) $(ESDALIB) $(AODALIB)
 
-ALIROOTALIBS+=$($(DAMODULE)baseALIB) $($(DAMODULE)recALIB) $($(DAMODULE)simALIB)
+ALIROOTALIBS+=$($(DAMODULE)ALIBS)
 
-ifneq ($(EXTRADAMODULE),) 
+EXTRAROOTLIB=${ALICE_ROOT}/lib/tgt_${ALICE_TARGET}/libRootExtra.a
 
-ALIROOTALIBS+=$($(EXTRADAMODULE)baseALIB) $($(EXTRADAMODULE)recALIB) $($(EXTRADAMODULE)simALIB)
+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)))))))))))
 
+ifneq ($(EXTRADAMODULE),)
+CXXFLAGS+=-I${ALICE_ROOT}/$(EXTRADAMODULE)
+CXXFLAGS+=$(addprefix -I,$(filter-out %tgt_${ALICE_TARGET},$(filter-out %CVS,$(patsubst %/,%,$(shell ls -d ${ALICE_ROOT}/$(EXTRADAMODULE)/*/)))))
+ALIROOTALIBS+=$($(EXTRADAMODULE)ALIBS)
 endif
 
-static-DA: $(DAEXE)
+DAOUTPUTFILES=$(sort $(shell grep TFile $(DASRC) | grep '(' | grep ')' | grep -i recreate | cut -d'(' -f2 | cut -d',' -f1 | cut -d')' -f1 ))
+DAINPUTFILES=$(sort $(shell grep TFile $(DASRC) | grep '(' | grep ')' | grep -vi recreate | cut -d'(' -f2 | cut -d',' -f1 | cut -d')' -f1 ))
 
-$(DAEXE): $(LIBPATH) $(DAOBJ) $(DALIB) $(DAQDALIB)
+$(DATARGETNAME): $(DAEXE)
 
-       $(LD) $(LDFLAGS) -o $@ $(DAOBJ) $(DALIB) \
-       $(SYSLIBS) \
+$(DAEXE): $(DAOBJ) $(LIBPATH) $(DALIB) $(DAQDALIB) $(EXTRAROOTLIB)
+       @echo "***** Making executable $(DAEXE) *****"
+       $(MUTE)$(LD) $(LDFLAGS) -o $@ $< \
+       $(DALIB) \
+       $(EXTRAROOTLIB) \
        $(ROOTLIBDIR)/libRoot.a \
        $(ROOTLIBDIR)/libfreetype.a $(ROOTLIBDIR)/libpcre.a \
-       $(MONITORLIBS) $(DAQDALIB)
+       $(DAQDALIB) $(MONITORLIBS) \
+       $(SYSLIBS)
 
-$(DAOBJ): $(DASRC) $(DAQDADIR) $(DADEP)
-       $(CXX) -c $(CXXFLAGS) -I$(DAQDADIR) $< -o $@
+$(DAOBJ): $(DASRC) $(DAQDADIR) $(DADEP) $(DATARGETDIR)
+       @echo "***** Compiling $(DASRC) *****"
+       $(MUTE)$(CXX) -c $(CXXFLAGS) -I$(DAQDADIR) $< -o $@
 
-$(DADEP): $(DASRC) $(DAQDADIR)
-       $(CPP) -MM $(CXXFLAGS) -I$(DAQDADIR) $< > $@
-
-DAINCLUDES=$(sort $(filter-out %.o:,$(filter-out %.cxx,$(filter-out \,$(shell cat $(DADEP))))))
+$(DADEP): $(DASRC) $(DAQDADIR) $(DATARGETDIR)
+       @echo "***** Making detector-algorithm dependencies $(DADEP) *****"
+       $(MUTE)$(CPP) -MM $(CXXFLAGS) $(addprefix -I$(ALICE_ROOT)/,$(MODULES)) -I$(DAQDADIR) $< > $@
 
 -include $(DADEP)
 
-$(DALIB): $(ALIROOTALIBS)
-       @rm -rf $@
-       @rm -rf junk
-       mkdir junk && cd junk && $(addprefix $(AR) x ../,$(addsuffix &&,$^)) $(AR) r $@ *.o && cd .. && rm -rf junk
-
-clean-DA:
-       @rm -f $(DAEXE)
-       @rm -f $(DAOBJ)
-       @rm -f $(DADEP)
-ifdef ALIROOTMODULES
-       @rm -f $(DALIB)
-       @rm -f $(ALIROOTALIBS)
-endif
+$(DATARGETDIR):
+       $(MUTE)if [ ! -d '$@' ]; then echo "***** Making directory $@ *****"; mkdir -p $@; fi
 
-tar-DA: $(DASRC) $(DALIB) $(DAQDADIR) $(DADEP)
-       @rm -rf $(DAMODULE)da.tar
-       @rm -rf junk
-       mkdir junk && mkdir junk/include && \
-       cp -a $(DASRC) $(DALIB) $(ROOTLIBDIR)/libRoot.a $(ROOTLIBDIR)/libfreetype.a $(ROOTLIBDIR)/libpcre.a $(DAQDADIR) junk && \
-       $(foreach daincfile,$(DAINCLUDES), cp -a $(daincfile) junk/include &&) \
-       cp -a build/MakefileDA junk/Makefile && \
+$(DALIB): $(ALIROOTALIBS)
+       @echo "***** Linking static library $(DALIB) *****"
+       $(MUTE)rm -rf $@
+       $(MUTE)rm -rf junk
+       $(MUTE)mkdir junk && cd junk && $(addprefix $(AR) x ../,$(addsuffix &&,$^)) $(AR) r $@ *.o && cd .. && rm -rf junk
+
+$(EXTRAROOTLIB): $(LIBPATH) 
+       $(MUTE)$(AR) r $@ `ls ${ROOTSYS}/vmc/src/*.o ${ROOTSYS}/treeplayer/src/*.o`
+
+$(DATARGETNAME)-clean:
+       @echo "***** Cleaning $(DAMODULE)$(DANAME) detector-algorithm *****"
+       $(MUTE)rm -f $(DASPECFILE)
+       $(MUTE)rm -f $(DATAR)
+       $(MUTE)rm -f $(DAEXE)
+       $(MUTE)rm -f $(DAOBJ)
+       $(MUTE)rm -f $(DADEP)
+       $(MUTE)rm -f $(DAMAKEFILE)
+       $(MUTE)rm -f $(DALIB)
+       $(MUTE)rm -f $(ALIROOTALIBS)
+       $(MUTE)rm -f $(EXTRAROOTLIB)
+
+$(DAMAKEFILE): $(DATARGETDIR)
+       $(MUTE)rm -f $(DAMAKEFILE)
+       @echo "***** Making makefile $(DAMAKEFILE) *****"
+       @echo "####################################################" >> $@
+       @echo "# Makefile for Detector Algorithm" >> $@
+       @echo "#" >> $@
+       @echo "# It is necessary to setup build environment before" >> $@
+       @echo "# using make:" >> $@
+       @echo "# - define path to daqDAlib (env. DAQDALIB_PATH)" >> $@
+       @echo "#" >> $@
+       @echo "####################################################" >> $@
+       @echo "" >> $@
+       @echo "CXX=$(CXX)" >> $@
+       @echo "LD=$(LD)" >> $@
+       @echo "" >> $@
+       @echo "CXXFLAGS=$(CXXFLAGS)" >> $@
+       @echo "LDFLAGS=$(LDFLAGS)" >> $@
+       @echo "" >> $@
+       @echo "ifeq (""$$""(DAQDALIB_PATH),)" >> $@
+       @echo "DAQDADIR=${ALICE}/daqDAlib" >> $@
+       @echo "else" >> $@
+       @echo "DAQDADIR=""$$""(DAQDALIB_PATH)" >> $@
+       @echo "endif" >> $@
+       @echo "" >> $@
+       @echo "DAQDALIB=""$$""(DAQDADIR)/libdaqDA.a" >> $@
+       @echo "MONITORLIBS=""$$""(shell date-config --monitorlibs=noshift)" >> $@
+       @echo "" >> $@
+       @echo "${DAMODULE}${DANAME}da.exe: ${DAMODULE}${DANAME}da.o" >> $@
+       @echo "         ""$$""(LD) ""$$""(LDFLAGS) -o ""$$""@ ""$$""< \\" >> $@
+       @echo "         $(DALIB) \\" >> $@
+       @echo "         $(EXTRAROOTLIB) \\" >> $@
+       @echo "         ""$$""(ROOTSYS)/lib/libRoot.a \\" >> $@
+       @echo "         ""$$""(ROOTSYS)/lib/libfreetype.a ""$$""(ROOTSYS)/lib/libpcre.a \\" >> $@
+       @echo "         ""$$""(DAQDALIB) ""$$""(MONITORLIBS) \\" >> $@
+       @echo "         $(SYSLIBS)" >> $@
+       @echo "" >> $@
+       @echo "${DAMODULE}${DANAME}da.o: ${DAMODULE}${DANAME}da.cxx" >> $@
+       @echo "         ""$$""(CXX) -c ""$$""(CXXFLAGS) -I""$$""(DAQDADIR) ""$$""< -o ""$$""@" >> $@
+       @echo "" >> $@
+       @echo "clean:" >> $@
+       @echo "         @rm -f ${DAMODULE}${DANAME}da.exe ${DAMODULE}${DANAME}da.o" >> $@
+       @echo "" >> $@
+       @echo "install: ${DAMODULE}${DANAME}da.exe" >> $@
+       @echo "         @if [ '""$$""(INSTALL_PATH)' == '' ]; then \\" >> $@
+       @echo "         echo Environment variable INSTALL_PATH undefined, cannot continue; \\" >> $@
+       @echo "         exit 1; \\" >> $@
+       @echo "         fi" >> $@
+       @echo "         @cp -p ${DAMODULE}${DANAME}da.exe ""$$""(INSTALL_PATH)" >> $@
+
+$(DATAR): $(DASRC) $(DAMAKEFILE) $(DASPECFILE)
+       @echo "***** Making archive $(DATAR) *****"
+       $(MUTE)rm -rf $(DATAR)
+       $(MUTE)rm -rf junk
+       $(MUTE)mkdir junk && mkdir junk/$(DAARC) && \
+       cp -a $(DASRC) junk/$(DAARC) && \
+       cp -a $(DAMAKEFILE) junk/$(DAARC)/Makefile && \
+       cp -a $(DASPECFILE) junk/$(DAARC)/$(DAMODULE)$(DANAME)da.spec && \
        cd junk && \
-       tar cvf ../$(DAMODULE)da.tar * && \
+       tar czf ../$(DATAR) * && \
        cd .. && rm -rf junk
 
+$(DASPECFILE): $(DATARGETDIR)
+       $(MUTE)rm -f $(DASPECFILE)
+       @echo "***** Making RPM spec-file $(DASPECFILE) *****"
+       @echo "# RPM specfile for $(DAMODULE)$(DANAME) Detector Algorithm" >> $@
+       @echo "Summary: $(DAMODULE) Detector Algorithm" >> $@
+       @echo "Name: daqDA-$(DAMODULE)$(DANAME)-calib" >> $@
+       @echo "Version: $(DAVERSION)" >> $@
+       @echo "Release: $(DARELEASE)" >> $@
+       @echo "Copyright: CERN Alice DAQ/Offine" >> $@
+       @echo "Source: %{name}-%{version}.src.tar.gz" >> $@
+       @echo "Group: Applications/Alice" >> $@
+       @echo "Prefix: /opt/%{name}" >> $@
+       @echo "BuildRoot: %{_tmppath}/%{name}-root" >> $@
+       @echo "" >> $@
+       @echo "# automatic dependencies" >> $@
+       @echo "AutoReqProv: yes" >> $@
+       @echo "" >> $@
+       @echo "# list here required RPM packages for compilation" >> $@
+       @echo "BuildRequires: date" >> $@
+       @echo "" >> $@
+       @echo "# list here required RPM packages for runtime" >> $@
+       @echo "Requires: date" >> $@
+       @echo "" >> $@
+       @echo "# You can specify other dependencies in the description tag below." >> $@
+       @echo "" >> $@
+       @echo "# description of the package" >> $@
+       @echo "%description" >> $@
+       @echo "This is the $(DAMODULE)$(DANAME) DA for online calibration." >> $@
+       @echo "It uses data from $(DAMODULE) and $(EXTRADAMODULE) detectors at run time." >> $@
+       @echo "Build requires: daqDAlib, date, AliRoot $(DAALIROOTRELEASE), ROOT $(DAROOTRELEASE)." >> $@
+       @echo "Runtime requires: date." >> $@
+       @echo "Files produced: $(DAOUTPUTFILES)" >> $@
+       @echo "Files used: $(DAINPUTFILES)" >> $@
+       @echo "" >> $@
+       @echo "#################################################################" >> $@
+       @echo "# Do not modify following scripts" >> $@
+       @echo "#################################################################" >> $@
+       @echo "" >> $@
+       @echo "# here is defined the installation root directory" >> $@
+       @echo "%define pkgname %{name}-%{version}" >> $@
+       @echo "%define destdir %{prefix}" >> $@
+       @echo "" >> $@
+       @echo "# pre-compilation script: extract from tarball" >> $@
+       @echo "%prep" >> $@
+       @echo "# extract archive" >> $@
+       @echo "%setup -n %{pkgname}" >> $@
+       @echo "" >> $@
+       @echo "# compile" >> $@
+       @echo "%build" >> $@
+       @echo "export DATE_SITE=" >> $@
+       @echo ". /date/setup.sh" >> $@
+       @echo "gmake" >> $@
+       @echo "" >> $@
+       @echo "# install runtime files" >> $@
+       @echo "%install" >> $@
+       @echo "#remove install dir if existing" >> $@
+       @echo "[ -d ""$$""RPM_BUILD_ROOT ] && rm -rf ""$$""RPM_BUILD_ROOT" >> $@
+       @echo "#make install in install root directory" >> $@
+       @echo "mkdir -p ""$$""RPM_BUILD_ROOT/%{prefix}" >> $@
+       @echo "make install INSTALL_PATH=""$$""RPM_BUILD_ROOT/%{prefix}" >> $@
+       @echo "" >> $@
+       @echo "# clean RPM build files" >> $@
+       @echo "%clean" >> $@
+       @echo "# remove source files" >> $@
+       @echo "rm -rf ""$$""RPM_BUILD_DIR/%{pkgname}" >> $@
+       @echo "# remove installed files" >> $@
+       @echo "rm -rf ""$$""RPM_BUILD_ROOT" >> $@
+       @echo "" >> $@
+       @echo "# pre-install script" >> $@
+       @echo "%pre" >> $@
+       @echo "" >> $@
+       @echo "# list of files to be installed" >> $@
+       @echo "%files" >> $@
+       @echo "%defattr (-,root,root)" >> $@
+       @echo "%{destdir}" >> $@
+       @echo "" >> $@
+       @echo "# post-install script" >> $@
+       @echo "# launched after rpm installed" >> $@
+       @echo "%post" >> $@
+       @echo "" >> $@
+       @echo "# post-uninstall script" >> $@
+       @echo "# launched after rpm removed" >> $@
+       @echo "%postun" >> $@
+
+$(DATARGETNAME)-rpm: $(DATAR) $(DASPECFILE) $(DALIB) $(DADEP) $(EXTRAROOTLIB)
+       @echo "***** Making RPMS for $(DAMODULE)$(DANAME) detector-algorithm *****"
+       $(MUTE)rm -rf junk
+       $(MUTE)mkdir -p junk/SOURCES junk/SPECS junk/BUILD junk/RPMS junk/SRPMS
+       $(MUTE)cp $(DATAR) junk/SOURCES
+       $(MUTE)rpmbuild --quiet --define "_topdir $(ALICE_ROOT)/junk" --nodeps -bb $(DASPECFILE)
+       $(MUTE)find junk/ -name "$(DAARC)-*.rpm" -exec cp -p {} . \;
+       $(MUTE)rm -rf junk
+       @echo "***** RPMS created and put $(ALICE_ROOT) folder *****"
+
 else
 
-static-DA: clean-DA
-clean-DA: tar-DA
-tar-DA:
+$(DATARGETNAME):        $(DATARGETNAME)-clean
+$(DATARGETNAME)-clean:  $(DATARGETNAME)-rpm
+$(DATARGETNAME)-rpm:
        @echo
-       @echo "****************************************************************************************************"
-       @echo "* In order to build a detector-algorithm package you have to set the environment variable DAMODULE *"
-       @echo "* For example: setenv DAMODULE TOF                                                                 *"
-       @echo "*          or  export DAMODULE=TOF                                                                 *"
-       @echo "* If the detector algorithm uses data from another sub-detector you can specify this by setting    *"
-       @echo "* the environment variable EXTRADAMODULE                                                           *"
-       @echo "****************************************************************************************************"
+       @echo "*******************************************************************************************************"
+       @echo "* In order to build a detector-algorithm package you have run AliRoot make with the following syntax: *"
+       @echo "* For example: make TPC-da (compiles and link TPC/TPCda.cxx DA source file and produces TPCda.exe)    *"
+       @echo "*              make MUON-TRK-da (MUON is the AliRoot module, TRK is the name of the DA algorithm,     *"
+       @echo "*                                this target will compile and link MUON/MUONTRKda.cxx and will        *"
+       @echo "*                                produce MUONTRKda.exe)                                               *"
+       @echo "* In case you want to build the corresponding DA binary RPM, you have to add -rpm to your target name,*"
+       @echo "* for example:                                                                                        *"
+       @echo "*              make TOF-da-rpm  (compiles, links TOF/TOFda.cxx and builds the TOF DA binary RPM)      *"
+       @echo "*              make ITS-SPD-da-rpm (compiles, link ITS/ITSSPDda.cxx and builds ITS SPD DA binary RPM) *"
+       @echo "*******************************************************************************************************"
        @echo
 
-
 endif