3 #------------------------------------------------------------------
     5 # Name: build_swtrigger.sh
     7 # Purpose: Build debug and prof flavors of swtrigger on Jenkins.
     9 # Created:  25-Jun-2015  H. Greenlee
    11 #------------------------------------------------------------------
    13 echo "swtrigger version: $VERSION"
    14 echo "qualifier: $QUAL"
    15 echo "build type: $BUILDTYPE"
    16 echo "workspace: $WORKSPACE"
    18 # Get number of cores to use.
    20 if [ `uname` = Darwin ]; then
    21   #ncores=`sysctl -n hw.ncpu`
    22   #ncores=$(( $ncores / 4 ))
    25   ncores=`cat /proc/cpuinfo 2>/dev/null | grep -c -e '^processor'`
    27 if [ $ncores -lt 1 ]; then
    30 echo "Building using $ncores cores."
    32 # Environment setup, uses /grid/fermiapp or cvmfs.
    34 if [ -f /grid/fermiapp/products/uboone/setup_uboone.sh ]; then
    35   source /grid/fermiapp/products/uboone/setup_uboone.sh || exit 1
    36 elif [ -f /cvmfs/uboone.opensciencegrid.org/products/setup_uboone.sh ]; then
    37   if [ -x /cvmfs/grid.cern.ch/util/cvmfs-uptodate ]; then
    38     /cvmfs/grid.cern.ch/util/cvmfs-uptodate /cvmfs/uboone.opensciencegrid.org/products
    40   source /cvmfs/uboone.opensciencegrid.org/products/setup_uboone.sh || exit 1
    42   echo "No setup file found."
    46 # Use system git on macos.
    48 if ! uname | grep -q Darwin; then
    52 # Other required setups.
    54 setup cetbuildtools v5_04_02
    56 # Set up working area.
    59 rm -rf $WORKSPACE/temp || exit 1
    60 mkdir -p $WORKSPACE/temp || exit 1
    61 mkdir -p $WORKSPACE/copyBack || exit 1
    62 rm -f $WORKSPACE/copyBack/* || exit 1
    63 cd $WORKSPACE/temp || exit 1
    64 export SWTRIGGER_HOME_DIR=`pwd`
    66 # Check for supported combination of base qualifier and OS.
    67 if [[ `uname -s` == Darwin ]] && [[ $QUAL == e* ]]; then
    68   echo "${QUAL} build not supported on `uname -s`"
    69   echo "${QUAL} build not supported on `uname -s`" > $WORKSPACE/copyBack/skipping_build
    75 # Make source area and check out sources.
    79 git clone https://github.com/twongjirad/fememulator
    80 #git clone https://github.com/hgreenlee/fememulator
    83 # Make sure repository is up to date and check out desired tag.
    89 # Set up the correct version of compiler ups product.
    91 if [[ $QUAL =~ ^c ]]; then
    92   compiler_version=`ups depend -M ${SWTRIGGER_HOME_DIR}/srcs/fememulator/ups -m swtrigger.table -q ${QUAL}:${BUILDTYPE} swtrigger | sed -n 's/^.*__\(clang .*\)$/\1/p'`
    94   compiler_version=`ups depend -M ${SWTRIGGER_HOME_DIR}/srcs/fememulator/ups -m swtrigger.table -q ${QUAL}:${BUILDTYPE} swtrigger | sed -n 's/^.*__\(gcc .*\)$/\1/p'`
    96 setup $compiler_version
    98 # Do post-checkout initialization.
   106 if [[ $QUAL =~ ^c ]]; then
   107   cmake .. -DCMAKE_CXX_COMPILER=`which clang++` -DCMAKE_BUILD_TYPE=$BUILDTYPE || exit 1
   109   cmake .. -DCMAKE_CXX_COMPILER=`which g++` -DCMAKE_BUILD_TYPE=$BUILDTYPE || exit 1
   114 make -j$ncores || exit 1
   116 # Assemble ups product.
   118 install_dir=${SWTRIGGER_HOME_DIR}/install/swtrigger/$VERSION
   119 subdir=`get-directory-name subdir ${QUAL}:${BUILDTYPE}`
   120 binary_dir=${install_dir}/$subdir
   121 src_dir=${install_dir}/source
   124 cp -r lib $binary_dir
   125 cp -r ${SWTRIGGER_HOME_DIR}/srcs/fememulator/SWTriggerBase $src_dir
   126 cp -r ${SWTRIGGER_HOME_DIR}/srcs/fememulator/FEMBeamTrigger $src_dir
   127 cp -r ${SWTRIGGER_HOME_DIR}/srcs/fememulator/ups $install_dir
   128 mkdir ${SWTRIGGER_HOME_DIR}/install/.upsfiles
   130 # Make a dbconfig file.
   132 cat <<EOF > ${SWTRIGGER_HOME_DIR}/install/.upsfiles/dbconfig
   136 PROD_DIR_PREFIX = \${UPS_THIS_DB}
   137 UPD_USERCODE_DIR = \${UPS_THIS_DB}/.updfiles
   140 # Declare ups product in temporary products area.
   142 if uname | grep -q Darwin; then
   143   flavor=`ups flavor -2`
   145   flavor=`ups flavor -4`
   147 ups declare -z ${SWTRIGGER_HOME_DIR}/install -r swtrigger/$VERSION -m swtrigger.table -f $flavor -q ${QUAL}:${BUILDTYPE} -U ups swtrigger $VERSION
   149 # Make distribution tarball
   151 cd ${SWTRIGGER_HOME_DIR}/install
   152 dot_version=`echo $VERSION | sed -e 's/_/\./g' | sed -e 's/^v//'`
   153 subdir=`echo $subdir | sed -e 's/\./-/g'`
   154 #qual=`echo $CETPKG_QUAL | sed -e 's/:/-/g'`
   155 tarballname=swtrigger-${dot_version}-${subdir}.tar.bz2
   156 echo "Making ${tarballname}"
   157 tar cjf ${SWTRIGGER_HOME_DIR}/${tarballname} swtrigger
   161 mv ${SWTRIGGER_HOME_DIR}/${tarballname}  $WORKSPACE/copyBack/ || exit 1
   162 ls -l $WORKSPACE/copyBack/
   163 cd $WORKSPACE || exit 1
   164 #rm -rf $WORKSPACE/temp || exit 1