#!/usr/bin/env bash # configure is a part of the PYTHIA event generator. # Copyright (C) 2017 Torbjorn Sjostrand. # PYTHIA is licenced under the GNU GPL version 2, see COPYING for details. # Please respect the MCnet Guidelines, see GUIDELINES for details. # Author: Philip Ilten, October 2014 - May 2015. # # This is is the configuration script which should be run prior to building # PYTHIA. Example usage is: # ./configure --with-lhapdf5 # For help please use: # ./configure --help # which will print a full list of configuration options. ################################################################################ # VARIABLES: Global variables not defined via command line arguments. # CFG_FILE: The Makefile configuration file. # USAGE: Text printed when the --help option is passed. # OPTIONS: List of valid options that can be passed by the user. ################################################################################ CFG_FILE="Makefile.inc" read -d "" USAGE << "BLOCKTEXT" Usage: ./configure [OPTIONS] The available options are defined below. Defaults for the options are specified by square brackets in the option description. Arguments to the options are indicated in caps, i.e. DIR. Configuration options. --help : Print this help message (also -h, --h, and -help). --enable-debug : Turn on debugging and disable optimization. --enable-64bit : Turn on 64-bit compilation. --enable-shared : Build the shared PYTHIA library during compilation. --lcg=PLATFORM : Specify the LCG platform to use when the --with-PACKAGE-version option, described below, is set for a given optional package [x86_64-slc6-gcc48-opt]. The packages are accessed via the path /afs/cern.ch/sw/lcg/releases on AFS. Optional external packages. --with-PACKAGE[=DIR] : Use the external PACKAGE from the list below with its top directory optionally set by DIR. If the enabled PACKAGE requires other external packages, these packages will also be enabled. --with-PACKAGE-bin=DIR : Set the path to the PACKAGE binaries. --with-PACKAGE-lib=DIR : Set the path to the PACKAGE libraries. --with-PACKAGE-include=DIR : Set the path to the PACKAGE headers. --with-PACKAGE-version=VER : When using an LCG platform, set with the option --lcg above, automatically set the PACKAGE path for the given version VER. --with-lhapdf6-plugin=CODE : Set the LHAPDF6 plugin code [LHAPDF5.h]. LHAPDF5.h uses the FORTRAN wrapper while LHAPDF6.h uses the native C++ interface (requires BOOST headers). evtgen : Particle decays with the EvtGen decay pacakge, requires HEPMC2. fastjet3 : Building of jets using the FastJet package, version 3. hepmc2 : Export PYTHIA events to the HEPMC format, version 2. hepmc3 : Export PYTHIA events to the HEPMC format, version 3. lhapdf5 : Support the use of external PDF sets via LHAPDF, version 5. lhapdf6 : Support the use of external PDF sets via LHAPDF, version 6. powheg : Hard process production with POWHEGBOX matrix element executables. promc : Export PYTHIA events to the PROMC format. root : Use ROOT trees and histograms with PYTHIA. gzip : Enable reading of GZIPPED files using the libz library. boost : Needed for LHAPDF6 when using the LHAPDF6.h plugin. python : Interface to use PYTHIA in Python. Installation directories. --prefix=DIR : Directory to install PYTHIA [$PWD]. --prefix-COMPONENT=DIR : Set the installation directory for each PYTHIA COMPONENT from the following list. bin : Binaries, including the configuration script [PREFIX/bin]. lib : Libraries, both shared and static [PREFIX/lib]. include : Source headers [PREFIX/include/Pythia8]. share : Shared data, including configuration, READMEs, documentation, and examples [PREFIX/share/Pythia8]. Advanced options. --arch=ARCH : Architecture of the system. When not set, this is determined automatically. Options are LINUX for *nix systems and DARWIN for OS X. --cxx=COMPILER : Use this C++ compiler [g++]. --cxx-common='FLAGS' : Set the common C++ flags. --cxx-shared='FLAGS' : Set the shared C++ flags. --cxx-soname='FLAGS' : Use these C++ flags when setting shared library names. --lib-suffix=SUF : Shared library name suffix: [.so] for Linux and [.dylib] for OS X. BLOCKTEXT OPTIONS="-h --h -help --help --enable-debug --enable-64bit" OPTIONS+=" --enable-shared --lcg" OPTIONS+=" --prefix --prefix-bin --prefix-lib --prefix-include --prefix-share" for PKG in "evtgen" "fastjet3" "hepmc2" "hepmc3" "lhapdf5" "lhapdf6" "powheg"\ "promc" "root" "gzip" "boost" "python"; do OPTIONS+=" --with-$PKG --with-$PKG-bin --with-$PKG-lib --with-$PKG-include" OPTIONS+=" --with-$PKG-version"; done OPTIONS+=" --with-lhapdf6-plugin" OPTIONS+=" --arch --cxx --cxx-common --cxx-shared --cxx-soname --lib-suffix" ################################################################################ # FUNCTION: Configure a package. # configure_package # #
# The following array structure stores the package configuration to the global # variable _CFG. # 0: Use the package. 5: Header dependencies. # 1: Binary directory. 6: Library dependencies. # 2: Include directory. 7: Package dependencies. # 3: Library directory. 8: Dependency messages (empty if success). # 4: Binary dependencies. # Note that the global variable CXX must be defined prior to calling this # function. ################################################################################ function configure_package() { # Check global package variable and set the local package variables. local PKG=$(echo $1 | awk '{print toupper($0)}') eval local PKG_CFG=\${${PKG}_CFG[0]} if [ "${PKG_CFG[0]}" != true ]; then PKG_CFG[0]=false; fi PKG_CFG[4]=$6; PKG_CFG[5]=$7; PKG_CFG[6]=$8; PKG_CFG[7]=$9; PKG_CFG[8]="" local LCG_DIR=$2; local PKG_BIN=$3; local PKG_INC=$4; local PKG_LIB=$5; local WARN="WARNING: Disabling $PKG -" eval PKG_CFG[1]=\$${PKG}_BIN; eval PKG_CFG[2]=\$${PKG}_INCLUDE eval PKG_CFG[3]=\$${PKG}_LIB eval local PKG_DIR=\$$PKG; eval local PKG_SET=\$${PKG}_SET eval local PKG_VER=\$${PKG}_VERSION if [ "$PKG_SET" = true ] || [ -n "${PKG_CFG[1]}" ] || \ [ -n "${PKG_CFG[2]}" ] || [ -n "${PKG_CFG[3]}" ] || \ [ -n "${PKG_VER}" ]; then PKG_CFG[0]=true; fi if [ -z "${PKG_CFG[2]}" ]; then PKG_CFG[2]="./"; fi if [ -z "${PKG_CFG[3]}" ]; then PKG_CFG[3]="./"; fi # Set package path for LCG if available and requested. if [ -n "$PKG_VER" ] && [ -n "$LCG_DIR" ]; then if [ ! -d $LCG_DIR/$PKG_VER ]; then echo "$WARN version $PKG_VER not available via LCG." elif [ ! -d $LCG_DIR/$PKG_VER/$LCG ]; then echo "$WARN platform $LCG not available via LCG." else PKG_DIR=$LCG_DIR/$PKG_VER/$LCG; fi elif [ -n "$PKG_VER" ]; then echo "$WARN package not available via LCG."; fi # Set binary, include, and library paths from specified package path. if [ -n "$PKG_DIR" ]; then if [ -z "${PKG_CFG[1]}" ]; then PKG_CFG[1]=$PKG_DIR/$PKG_BIN; fi; if [ "${PKG_CFG[2]}" = "./" ]; then PKG_CFG[2]=$PKG_DIR/$PKG_INC; fi; if [ "${PKG_CFG[3]}" = "./" ]; then PKG_CFG[3]=$PKG_DIR/$PKG_LIB; fi; fi # Check header and library dependencies and store warnings. IFS="," for BIN in ${PKG_CFG[4]}; do if [ -n "${PKG_CFG[1]}" ]; then if ! type "${PKG_CFG[1]}/$BIN" &> /dev/null; then PKG_CFG[8]="${PKG_CFG[8]},$WARN binary $BIN missing."; fi; elif ! type "$BIN" &> /dev/null; then PKG_CFG[8]="${PKG_CFG[8]},$WARN binary $BIN missing."; fi; done if [ -z "${PKG_CFG[2]}" ]; then PKG_CFG[2]="./"; fi; for INC in ${PKG_CFG[5]}; do local TEST=$(echo "#include \"$INC\"" | $CXX -o /dev/null -x c - \ -I${PKG_CFG[2]} 2>&1 | grep -e "$INC: No such file" \ -e "'$INC' file not found") if [ -n "$TEST" ]; then PKG_CFG[8]="${PKG_CFG[8]},$WARN header $INC missing."; fi; done if [ -z "${PKG_CFG[3]}" ]; then PKG_CFG[1]="./"; fi; for LIB in ${PKG_CFG[6]}; do local TEST=$(echo "int main(){}" | $CXX -o /dev/null -x c - \ -L${PKG_CFG[3]} -l$LIB 2>&1 | grep "\-l$LIB") if [ -n "$TEST" ]; then PKG_CFG[8]="${PKG_CFG[8]},$WARN library $LIB missing."; fi; done IFS=" " # Export local package to global variable and update global package list. for IDX in ${!PKG_CFG[@]}; do eval ${PKG}_CFG[$IDX]=\"${PKG_CFG[$IDX]}\"; done PKG_LIST+=($PKG) # Flag inter-package dependencies (if this package available). if [ "${PKG_CFG[0]}" = true ] && [ -z "${PKG_CFG[8]}" ]; then IFS=","; for PKG in ${PKG_CFG[7]}; do eval ${PKG}_CFG[0]=true; done; IFS=" "; fi } ################################################################################ # MAIN: The main execution of the configuration script. ################################################################################ # Check if help requested. for VAR in "$@"; do if [ "$VAR" = "-h" ] || [ "$VAR" = "--h" ] || [ "$VAR" = "-help" ] \ || [ "$VAR" = "--help" ]; then echo "$USAGE"; exit; fi; done # Parse the user arguments and evaluate each as a global variable. echo "# PYTHIA configuration file." > $CFG_FILE echo "# Generated on" `date` "with the user supplied options:" >> $CFG_FILE for VAR in "$@"; do if [[ $OPTIONS =~ (^| )${VAR%%=*}($| ) ]]; then echo "# $VAR" >> $CFG_FILE; else echo "WARNING: Ignoring invalid option \"${VAR%=*}\"."; continue; fi; VAR=${VAR#--with-}; VAR=${VAR#--}; KEY=${VAR%%=*}; VAL=${VAR#$KEY}; VAL=${VAL#*=}; KEY=${KEY//"-"/"_"}; KEY=$(echo $KEY | awk '{print toupper($0)}'); VAL=$(eval echo $VAL) eval $KEY=\"$VAL\"; eval ${KEY}_SET=true; done # Set the compilation flags and options (order matters). if [ "$LCG_SET" != true ]; then LCG=x86_64-slc6-gcc48-opt; fi [ "$ENABLE_DEBUG_SET" = true ] && ENABLE_DEBUG="-g " || ENABLE_DEBUG="-O2 " [ "$ENABLE_64BIT_SET" = true ] && ENABLE_64BIT="-m64 " || ENABLE_64BIT="" [ "$ENABLE_SHARED_SET" = true ] && ENABLE_SHARED="true" || ENABLE_SHARED="false" if [ -z "$ARCH" ]; then ARCH=$(uname | grep -i -o -e Linux -e Darwin); fi ARCH=$(echo $ARCH | awk '{print toupper($0)}') if [ "$ARCH" != "LINUX" ] && [ "$ARCH" != "DARWIN" ]; then echo "WARNING: Unknown architecture $ARCH, set as LINUX."; ARCH="LINUX"; fi if [ -z "$CXX" ]; then CXX="g++"; fi if [ -z "$CXX_COMMON" ]; then CXX_COMMON="${ENABLE_DEBUG}${ENABLE_64BIT}-std=c++98" CXX_COMMON="$CXX_COMMON -pedantic -W -Wall -Wshadow -fPIC"; fi if [ -z "$CXX_SHARED" ]; then if [ "$ARCH" = "LINUX" ]; then CXX_SHARED="-shared"; fi if [ "$ARCH" = "DARWIN" ]; then CXX_SHARED="-dynamiclib"; fi; fi if [ -z "$CXX_SONAME" ]; then if [ "$ARCH" = "LINUX" ]; then CXX_SONAME="-Wl,-soname,"; fi if [ "$ARCH" = "DARWIN" ]; then CXX_SONAME="-Wl,-dylib_install_name,@rpath/" fi; fi if [ -z "$LIB_SUFFIX" ]; then if [ "$ARCH" = "LINUX" ]; then LIB_SUFFIX=".so"; fi if [ "$ARCH" = "DARWIN" ]; then LIB_SUFFIX=".dylib"; fi; fi # Configure the installation directories (order matters). if [ "$PREFIX_SET" != true ]; then PREFIX=$PWD; fi if [ -z "$PREFIX_BIN" ]; then PREFIX_BIN=$PREFIX/bin; fi if [ -z "$PREFIX_INCLUDE" ]; then PREFIX_INCLUDE=$PREFIX/include; fi if [ -z "$PREFIX_LIB" ]; then PREFIX_LIB=$PREFIX/lib; fi if [ -z "$PREFIX_SHARE" ]; then PREFIX_SHARE=$PREFIX/share/Pythia8; fi # Configure the packages (order does not matter). configure_package "EVTGEN"\ "/afs/cern.ch/sw/lcg/releases/MCGenerators/evtgen/1.3.0-9000e"\ "bin" "include" "lib" "" "EvtGen/EvtGen.hh" "EvtGen" "HEPMC2" configure_package "FASTJET3" "/afs/cern.ch/sw/lcg/releases/fastjet"\ "bin" "include" "lib" "" "fastjet/config.h" "fastjet" "" configure_package "HEPMC2" "/afs/cern.ch/sw/lcg/releases/HepMC"\ "bin" "include" "lib" "" "HepMC/GenEvent.h" "HepMC" "" configure_package "HEPMC3" "" \ "bin" "include" "lib" "" "HepMC/GenEvent.h" "HepMC" "" configure_package "LHAPDF5" "/afs/cern.ch/sw/lcg/releases/MCGenerators/lhapdf"\ "bin" "include" "lib" "" "" "LHAPDF" "" if [ "$LHAPDF6_PLUGIN" = "LHAPDF6.h" ]; then configure_package\ "LHAPDF6" "/afs/cern.ch/sw/lcg/releases/MCGenerators/lhapdf6"\ "bin" "include" "lib" "" "LHAPDF/LHAPDF.h" "LHAPDF" "BOOST" else LHAPDF6_PLUGIN="LHAPDF5.h"; configure_package\ "LHAPDF6" "/afs/cern.ch/sw/lcg/releases/MCGenerators/lhapdf6"\ "bin" "include" "lib" "" "" "LHAPDF" ""; fi configure_package "POWHEG" "" "bin" "" "lib" "hvq" "" "" "" configure_package "PROMC" ""\ "bin" "" "lib" "" "src/ProMCBook.h" "promc" "GZIP" configure_package "ROOT" "/afs/cern.ch/sw/lcg/releases/ROOT"\ "bin" "include" "lib" "rootcint,root-config" "TH1D.h" "" "" configure_package "GZIP" "" "" "include" "lib" "" "zlib.h" "z" "" configure_package "BOOST" "/afs/cern.ch/sw/lcg/releases/Boost"\ "bin" "include" "lib" "" "boost/shared_ptr.hpp" "" "" configure_package "PYTHON" "/afs/cern.ch/sw/lcg/external/Python"\ "bin" "include" "lib" "python" "Python.h" "" "" # Check package dependencies (order does not matter). for IDX in ${!PKG_LIST[@]}; do PKG=${PKG_LIST[$IDX]} eval PKG_USE=\${${PKG}_CFG[0]}; eval PKG_WRN=\${${PKG}_CFG[8]} if [ "$PKG_USE" = true ] && [ -n "$PKG_WRN" ]; then eval ${PKG}_CFG[0]=false; IFS="," for WRN in $PKG_WRN; do if [ -n "$WRN" ]; then echo $WRN; fi; done; IFS=" "; fi; done # Check package inter-dependencies (order does not matter). for IDX in ${!PKG_LIST[@]}; do PKG=${PKG_LIST[$IDX]} eval PKG_USE=\${${PKG}_CFG[0]}; eval PKG_DPS=\${${PKG}_CFG[7]} if [ "$PKG_USE" = true ]; then IFS="," for DEP in $PKG_DPS; do eval DEP_USE=\${${DEP}_CFG[0]} if [ "$DEP_USE" != true ]; then eval ${PKG}_CFG[0]=false echo "WARNING: Disabling $PKG - requires $DEP."; fi; done; IFS=" "; fi; done # Write the configuation to screen and file, update the pythia8-config script. sed 's|^CFG_FILE=.*|CFG_FILE='"$PREFIX_SHARE"'/examples/Makefile.inc|;n' \ bin/pythia8-config > bin/tmp chmod a+x bin/tmp; mv bin/tmp bin/pythia8-config echo "---------------------------------------------------------------------" echo "| PYTHIA Configuration Summary |" echo "---------------------------------------------------------------------" echo "Configured for $ARCH with the following options:" if [ "$ENABLE_DEBUG_SET" = true ]; then echo "--enable-debug"; fi if [ "$ENABLE_64BIT_SET" = true ]; then echo "--enable-64bit"; fi if [ "$ENABLE_SHARED_SET" = true ]; then echo "--enable-shared"; fi if [ "$LCG_SET" = true ]; then echo "--lcg=$LCG"; fi cat >> $CFG_FILE << BLOCKTEXT # Install directory prefixes. PREFIX_BIN=$PREFIX_BIN PREFIX_INCLUDE=$PREFIX_INCLUDE PREFIX_LIB=$PREFIX_LIB PREFIX_SHARE=$PREFIX_SHARE # Compilation flags (see ./configure --help for further documentation). ENABLE_SHARED=$ENABLE_SHARED CXX=$CXX CXX_COMMON=$CXX_COMMON CXX_SHARED=$CXX_SHARED CXX_SONAME=$CXX_SONAME LIB_SUFFIX=$LIB_SUFFIX BLOCKTEXT echo "" echo "The following optional external packages will be used:" for IDX in ${!PKG_LIST[@]}; do PKG=${PKG_LIST[$IDX]} eval PKG_USE=\${${PKG}_CFG[0]} if [ "$PKG_USE" = true ]; then echo "* $PKG" eval PKG_BIN=\${${PKG}_CFG[1]}; eval PKG_INC=\${${PKG}_CFG[2]}; eval PKG_LIB=\${${PKG}_CFG[3]}; if [ -n "$PKG_BIN" ]; then PKG_BIN+=/; fi else PKG_BIN=""; PKG_INC="./"; PKG_LIB="./"; fi cat >> $CFG_FILE << BLOCKTEXT # $PKG configuration. ${PKG}_USE=$PKG_USE ${PKG}_BIN=$PKG_BIN ${PKG}_INCLUDE=$PKG_INC ${PKG}_LIB=$PKG_LIB BLOCKTEXT if [ "$PKG" = "LHAPDF6" ]; then echo "${PKG}_PLUGIN=$LHAPDF6_PLUGIN" >> $CFG_FILE; fi if [ "$PKG" = "LHAPDF5" ]; then echo "${PKG}_PLUGIN=LHAPDF5.h" >> $CFG_FILE; fi done echo ""