Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:14:12

0001 #!/bin/bash
0002 #
0003 #  file:        install_BlackHat.sh
0004 #  description: BASH script for the installation of the BlackHat package,
0005 #               can be used standalone or called from other scripts
0006 #
0007 #  author:      Markus Merschmeyer, Sebastian Thüer, RWTH Aachen University
0008 #  date:        2014/02/22
0009 #  version:     1.1
0010 #
0011 
0012 print_help() {
0013     echo "" && \
0014     echo "install_blackhat version 1.0" && echo && \
0015     echo "options: -v  version    define BlackHat version ( "${BHVER}" )" && \
0016     echo "         -d  path       define BlackHat installation directory" && \
0017     echo "                         -> ( "${IDIR}" )" && \
0018     echo "         -p  path       apply official BLACKHAT patches ( "${PATCHES}" )" && \
0019     echo "                         from this path ( "${PDIR}" )" && \
0020     echo "         -Q  path       qd installation directory ( "${QDDIR}" )" && \
0021     echo "         -W  location   (web)location of BlackHat tarball ( "${BHWEBLOCATION}" )" && \
0022     echo "         -S  filename   file name of BlackHat tarball ( "${BHFILE}" )" && \
0023     echo "         -C  level      cleaning level of SHERPA installation ( "${LVLCLEAN}" )" && \
0024     echo "                         -> 0: nothing, 1: +objects (make clean)" && \
0025     echo "         -D             debug flag, compile with '-g' option ( "${FLGDEBUG}" )" && \
0026     echo "         -X             create XML file for tool override in CMSSW ( "${FLGXMLFL}" )" && \
0027     echo "         -Z             use multiple CPU cores if available ( "${FLGMCORE}" )" && \
0028     echo "         -K             keep BlackHat source code tree after installation ( "${FGLKEEPT}" )" && \
0029     echo "         -h             display this help and exit" && echo
0030 }
0031 
0032 
0033 # save current path
0034 HDIR=`pwd`
0035 
0036 
0037 # get absolute path of this script
0038 SCRIPT=$(readlink -f $0)
0039 #echo "XXX: "$SCRIPT
0040 SCRIPTPATH=`dirname $SCRIPT`
0041 #echo "YYY: "$SCRIPTPATH
0042 
0043 
0044 # dummy setup (if all options are missing)
0045 IDIR="/tmp"                # installation directory
0046 BHVER="0.9.9"              # BlackHat version to be installed
0047 BHWEBLOCATION=""           # (web)location of BlackHat tarball
0048 BHFILE=""                  # file name of BlackHat tarball
0049 QDDIR=""                   # qd installation directory
0050 LVLCLEAN=0                 # cleaning level (0-2)
0051 FLGDEBUG="FALSE"           # debug flag for compilation
0052 FLGXMLFL="FALSE"           # create XML tool definition file for SCRAM?
0053 FLGKEEPT="FALSE"           # keep the source code tree?
0054 FLGMCORE="FALSE"           # use multiple cores for compilation
0055 PATCHES="FALSE"            # apply SHERPA patches
0056 PDIR="./"                  # path containing patches
0057 
0058 
0059 
0060 # get & evaluate options
0061 while getopts :v:d:p:W:S:C:Q:DXZKh OPT
0062 do
0063   case $OPT in
0064   v) BHVER=$OPTARG ;;
0065   d) IDIR=$OPTARG ;;
0066   Q) QDDIR=$OPTARG ;;
0067   W) BHWEBLOCATION=$OPTARG ;;
0068   S) BHFILE=$OPTARG ;;
0069   C) LVLCLEAN=$OPTARG ;;
0070   D) FLGDEBUG=TRUE ;;
0071   X) FLGXMLFL=TRUE ;;
0072   Z) FLGMCORE=TRUE ;;
0073   K) FLGKEEPT=TRUE ;;
0074   p) PATCHES=TRUE && PDIR=$OPTARG ;;  
0075   h) print_help && exit 0 ;;
0076   \?)
0077     shift `expr $OPTIND - 1`
0078     if [ "$1" = "--help" ]; then print_help && exit 0;
0079     else 
0080       echo -n "install_blackhat: error: unrecognized option "
0081       if [ $OPTARG != "-" ]; then echo "'-$OPTARG'. try '-h'"
0082       else echo "'$1'. try '-h'"
0083       fi
0084       print_help && exit 1
0085     fi
0086 #    shift 1
0087 #    OPTIND=1
0088   esac
0089 done
0090 
0091 
0092 # set up file names
0093 MSI=$HDIR                            # main installation directory
0094 MSI=$SCRIPTPATH
0095 bhpatchfile="blackhat_patches_"${BHVER}".tgz" # official patches for current BLACKHAT version
0096 
0097 # set BlackHat download location
0098 if [ "$BHWEBLOCATION" = "" ]; then
0099   BHWEBLOCATION="http://www.hepforge.org/archive/blackhat"
0100   FLOC=" "
0101 else
0102   if [ -e ${BHWEBLOCATION} ]; then   # is the location a local subdirectory?
0103     if [ -d ${BHWEBLOCATION} ]; then
0104       cd ${BHWEBLOCATION}; BHWEBLOCATION=`pwd`; cd ${HDIR}
0105     fi
0106   fi
0107   FLOC=" -W "${BHWEBLOCATION}
0108 fi
0109 if [ "$BHFILE" = "" ]; then
0110   BHFILE="blackhat-"${BHVER}".tar.gz"
0111 fi
0112 
0113 
0114 # make BlackHat version a global variable
0115 export BHVER=${BHVER}
0116 export QDVER=${QDVER}
0117 # always use absolute path name...
0118 cd ${PDIR}; PDIR=`pwd`; cd ${HDIR}
0119 cd ${IDIR}; IDIR=`pwd`
0120 
0121 echo " BlackHat installation: "
0122 echo "  -> BlackHat version: '"${BHVER}"'"
0123 echo "  -> installation directory: '"${IDIR}"'"
0124 echo "  -> BlackHat location: '"${BHWEBLOCATION}"'"
0125 echo "  -> BlackHat file name: '"${BHFILE}"'"
0126 echo "  -> QD inst. dir.: '"${QDDIR}"'"
0127 echo "  -> cleaning level: '"${LVLCLEAN}"'"
0128 echo "  -> debugging mode: '"${FLGDEBUG}"'"
0129 echo "  -> CMSSW override: '"${FLGXMLFL}"'"
0130 echo "  -> keep sources:   '"${FLGKEEPT}"'"
0131 echo "  -> use multiple CPU cores: '"${FLGMCORE}"'"
0132 echo "  -> BlackHat patches: '"${PATCHES}"' in '"${PDIR}"'"
0133 
0134 
0135 # set path to local BlackHat installation
0136 export BHDIR=${IDIR}"/blackhat-"${BHVER}
0137 export BHIDIR=${IDIR}"/BH_"${BHVER}
0138 
0139 
0140 
0141 # add compiler & linker flags
0142 echo "CXX      (old):  "$CXX
0143 echo "CXXFLAGS (old):  "$CXXFLAGS
0144 echo "LDFLAGS  (old):  "$LDFLAGS
0145 ##MM FIXME
0146 #  export CXX=""
0147 #  export CXXFLAGS=""
0148 #  export LDFLAGS=""
0149 ##MM FIXME
0150 if [ "$FLGDEBUG" = "TRUE" ]; then
0151   CFDEBUG="-g"
0152   export CXXFLAGS=${CXXFLAGS}" "${CFDEBUG}
0153 fi
0154 echo "CXX      (new):  "$CXX
0155 echo "CXXFLAGS (new):  "$CXXFLAGS
0156 echo "LDFLAGS  (new):  "$LDFLAGS
0157 
0158 # add compiler & linker flags
0159 COPTS="CXXFLAGS=-Wno-deprecated"
0160 #intel compiler#COPTS=${COPTS}" CXXFLAGS=-wd803"
0161 ##COPTS="CXXFLAGS=-Wno-deprecated"
0162 MOPTS=""
0163 POPTS=""
0164 BHCFLAGS="--with-QDpath="${QDDIR}
0165 if [ "$FLGMCORE" = "TRUE" ]; then
0166     nprc=`cat /proc/cpuinfo | grep  -c processor`
0167     let nprc=$nprc
0168     if [ $nprc -gt 1 ]; then
0169       echo " <I> multiple CPU cores detected: "$nprc
0170       POPTS=" -j"$nprc" "
0171     fi
0172 fi
0173 
0174 
0175 
0176 # download, extract compile/install BlackHat
0177 cd ${IDIR}
0178 if [ ! -d ${BHIDIR} ]; then
0179   if [ `echo ${BHWEBLOCATION} | grep -c "http:"` -gt 0 ]; then
0180     echo " -> downloading BlackHat "${BHVER}" from "${BHWEBLOCATION}/${BHFILE}
0181     wget ${BHWEBLOCATION}/${BHFILE}
0182   elif [ `echo ${BHWEBLOCATION} | grep -c "srm:"` -gt 0 ]; then
0183     echo " -> srm-copying BlackHat "${BHVER}" from "${BHWEBLOCATION}/${BHFILE}
0184     srmcp ${BHWEBLOCATION}/${BHFILE} file:////${BHFILE}
0185   else
0186     echo " -> copying BlackHat "${BHVER}" from "${BHWEBLOCATION}/${BHFILE}
0187     cp ${BHWEBLOCATION}/${BHFILE} ./
0188   fi
0189   tar -xzf ${BHFILE}
0190   if [ ! "$FLGKEEPT" = "TRUE" ]; then
0191     rm ${BHFILE}
0192   fi
0193   cd ${BHDIR}
0194 #  if [ ! -e configure ]; then
0195 #    ./bootstrap
0196 #  fi
0197 
0198 ### CHANGES 
0199 # apply the necessary patches
0200   
0201   if [ "$PATCHES" = "TRUE" ]; then
0202         echo " <I> applying patches to BLACKHAT..."
0203         if [ -e ${PDIR}/${bhpatchfile} ]; then
0204                 pfilelist=`tar -xzvf ${PDIR}/${bhpatchfile}`
0205                 for pfile in `echo ${pfilelist}`; do
0206                         echo "  -> applying patch: "${pfile}
0207                         patch -p1 < ${pfile}
0208                         echo " <I> (patches) removing file "${pfile}
0209                         rm ${pfile}
0210                 done
0211         else
0212                 echo " <W> file "${PDIR}/${bhpatchfile}" does not exist,"
0213                 echo " <W>  cannot apply Sherpa patches"
0214         fi
0215   fi
0216 #### CHANGES
0217 
0218 
0219 
0220   echo " -> configuring BlackHat with options "${COPTS} && \
0221   ./configure --prefix=${BHIDIR} ${BHCFLAGS} ${COPTS} && \
0222   echo " -> making BlackHat with options "${POPTS} ${MOPTS} && \
0223   make ${POPTS} ${MOPTS} && \
0224   echo " -> installing BlackHat with options "${MOPTS} && \
0225   make install ${MOPTS}
0226   if [ ${LVLCLEAN} -gt 0 ]; then 
0227     echo " -> cleaning up BlackHat installation, level: "${LVLCLEAN}" ..."
0228     if [ ${LVLCLEAN} -ge 1 ]; then  # normal cleanup (objects)
0229       make clean
0230     fi
0231   fi
0232   cd ${HDIR}
0233   if [ "$FLGKEEPT" = "TRUE" ]; then
0234     echo "-> keeping source code..."
0235   else
0236     rm -rf ${BHDIR}
0237   fi
0238 else
0239   echo " <W> path exists => using already installed BlackHat"
0240 fi
0241 export BHDIR=${BHIDIR}
0242 cd ${HDIR}
0243 
0244 
0245 # create XML file fro SCRAM
0246 if [ "${FLGXMLFL}" = "TRUE" ]; then
0247   xmlfile="blackhat_"${BHVER}".xml"
0248   echo " <I>"
0249   echo " <I> creating BlackHat tool definition XML file"
0250   if [ -e ${xmlfile} ]; then rm ${xmlfile}; fi; touch ${xmlfile}
0251   echo "  <tool name=\"BlackHat\" version=\""${BHVER}"\">" >> ${xmlfile}
0252   tmppath=`find ${BHDIR} -type f -name libBH.so\*`
0253   tmpcnt=`echo ${tmppath} | grep -o "/" | grep -c "/"`
0254   tmppath=`echo ${tmppath} | cut -f 1-${tmpcnt} -d "/"`
0255   for LIB in `cd ${tmppath}; ls *.so | cut -f 1 -d "." | sed -e 's/lib//'; cd ${HDIR}`; do
0256     echo "    <lib name=\""${LIB}"\"/>" >> ${xmlfile}
0257   done
0258   echo "    <client>" >> ${xmlfile}
0259   echo "      <Environment name=\"BLACKHAT_BASE\" value=\""${BHDIR}"\"/>" >> ${xmlfile}
0260   echo "      <Environment name=\"LIBDIR\" default=\"\$BLACKHAT_BASE/lib/blackhat\"/>" >> ${xmlfile}
0261   echo "      <Environment name=\"INCLUDE\" default=\"\$BLACKHAT_BASE/include/blackhat\"/>" >> ${xmlfile}
0262   echo "    </client>" >> ${xmlfile}
0263 #  echo "    <runtime name=\"CMSSW_FWLITE_INCLUDE_PATH\" value=\"\$BLACKHAT_BASE/include\" type=\"path\"/>" >> ${xmlfile}
0264 #  echo "    <use name=\"CLHEP\"/>" >> ${xmlfile}
0265   echo "  </tool>" >> ${xmlfile}
0266   if [ ! "$PWD" = "${HDIR}" ]; then
0267     mv ${xmlfile} ${HDIR}/
0268   fi
0269 
0270   if [ ! "$CMSSW_BASE" = "" ]; then
0271     cd $CMSSW_BASE
0272     tmpbh=`scramv1 tool info blackhat | grep "BLACKHAT_BASE" | cut -f2 -d"="`
0273     tmpxml=`find $CMSSW_BASE/config -type f -name blackhat.xml -printf %h`
0274     echo " <I>"
0275     echo " <I> BlackHat version currently being used: "${tmpbh}
0276     echo " <I> ...defined in "${tmpxml}
0277     cd ${tmpxml}; tmpxml=$PWD; cd ${HDIR}
0278     echo " <I>"
0279     echo " <I> If you want to override this version with the freshly produced "${xmlfile}","
0280     echo " <I> ...please type the following commands:"
0281     echo " <I>"
0282     echo "       cd $CMSSW_BASE"
0283     echo "       scramv1 tool remove blackhat"
0284     echo "       cp ${HDIR}/${xmlfile} ${tmpxml}/"
0285     echo "       scramv1 setup blackhat"
0286     echo "       cd -"
0287     echo " <I>"
0288   fi
0289 
0290 fi
0291 
0292 
0293 echo " -> BlackHat installation directory is: "
0294 echo "  "${BHIDIR}