#!/bin/bash # # This script will generate a Makefile according to the options one requests. # The Makefile will then allow one to build and install the FastJet contrib. # # See # configure --help # for information about how to use this script # load common setup . `dirname $0`/scripts/internal/common.sh #------------------------------------------------------------------------ # the list of contribs supported by this script #------------------------------------------------------------------------ all_contribs=$(find . -mindepth 2 -maxdepth 2 -not -print \ | grep -e VERSION -e FJCONTRIB.cfg | sort | sed 's/\.\///g;s/\/.*$//g' | grep -v "Template") #------------------------------------------------------------------------ # default values prior to the arg parsing #------------------------------------------------------------------------ only_contribs="" excluded_contribs="" fjconfig="fastjet-config" #------------------------------------------------------------------------ # print a usage message and exit #------------------------------------------------------------------------ # exit code passed as argument: # 0 if it is a normal call # 1 if it is due to a misusage. usage(){ cat 1>&2 <> $makefileinc echo "# $0 $*" >> $makefileinc for arg do case "$arg" in --help|-h) usage 0 ;; --list) echo $all_contribs exit 0 ;; --*=*) arg_name=`option_name $arg` arg_value=`option_value $arg` case $arg_name in prefix) prefix="$arg_value" ;; fastjet_config) fjconfig="$arg_value" ;; only) only_contribs="${arg_value//,/ }" # replace all commas with a blank ;; exclude) excluded_contribs="${arg_value//,/ }" # replace all commas with a blank ;; *) write_error "$arg: unrecognised argument" ;; esac ;; [A-Z]*=*) # variables that go into the $makefileinc echo "$arg" >> $makefileinc ;; *) write_error "$arg is not a recognised argument. Aborting" ;; esac done #------------------------------------------------------------------------ # check for fastjet-config and set up prefix #------------------------------------------------------------------------ # exit if fastjet-config is not found (bad file name or not in path) if ! [ `command -v $fjconfig` ]; then echo "Error:" $fjconfig" has not been found." echo " You may explicitly specify the location of fastjet-config " echo " with the option --fastjet-config=...." echo "Exiting" exit 1 fi # write out full path to fastjet-config + version fjconfig=$(command -v $fjconfig) echo "Using $fjconfig, corresponding to fastjet version" $($fjconfig --version) echo # if prefix has not been set explicitly from command line, set it to # the one returned by 'fastjet-config --prefix' if [ "x"$prefix == "x" ] ; then prefix=`$fjconfig --prefix` fi # generate the rest of $makefileinc echo "FASTJETCONFIG=$fjconfig" >> $makefileinc echo "PREFIX=$prefix" >> $makefileinc echo 'install_script = $(SHELL) ../utils/install-sh' >> $makefileinc echo 'check_script = ../utils/check.sh' >> $makefileinc #------------------------------------------------------------------------ # check for C++11 support (needed as of version 1.047 of fjcontrib) # and add in options if needed #------------------------------------------------------------------------ checkc11(){ fjcdir=$(pwd) tmpdir=$(mktemp -d) pushd $tmpdir > /dev/null cp -p $fjcdir/scripts/c11check/Makefile $fjcdir/scripts/c11check/c11check.cc . makeoutput=$(make FJCDIR=$fjcdir c11check 2>&1) c11retcode=$? popd > /dev/null rm -rf $tmpdir return $c11retcode } echo "Checking for c++11 support" checkc11 if [ $? -ne 0 ] then echo "Adding compile-time flag to support c++11" echo "Make sure you use c++11 when compiling/linking with fjcontrib" echo "CXXFLAGS+=-std=c++11" >> $makefileinc checkc11 if [ $? -ne 0 ] then echo "Failed to set up C++11 support. Error was" echo "$makeoutput" exit -1 fi else echo "c++11 already supported with existing CXXFLAGS" fi #------------------------------------------------------------------------ # construct the list of directories to recurse into #------------------------------------------------------------------------ included_contribs="" if [ "x${only_contribs}" == "x" ] ; then included_contribs="$all_contribs" else included_contribs="$only_contribs" fi built_contribs="" if [ "x${excluded_contribs}" == "x" ] ; then built_contribs="$included_contribs" else built_contribs="" for contrib in $included_contribs; do if ! is_in_list $contrib ${excluded_contribs} ; then built_contribs="$built_contribs $contrib" fi done fi #------------------------------------------------------------------------ # create the Makefile #------------------------------------------------------------------------ TAB="$(printf '\t')" # cat >Makefile <Makefile < Makefile #------------------------------------------------------------------------ # write output and config.log file #------------------------------------------------------------------------ # order contribs alphabetically (making sure we use LC_ALL=C") LC_ALL=C sorted_built_contribs=`echo $built_contribs | tr " " "\n" | sort | tr "\n" " "` # build up the dependencies for the sub-directories fjversion=`$fjconfig --version` for contrib in $sorted_built_contribs do if [[ -f $contrib/VERSION && -f $contrib/FJCONTRIB.cfg ]]; then echo "ERROR: $contrib has both $contrib/VERSION and $contrib/FJCONTRIB.cfg files." echo "Only one of these should be present. In newer contribs, please use FJCONTRIB.cfg" exit 1 fi get_dependencies $contrib dependencies min_versions min_fj_version echo "Processing dependencies for $contrib" # first, check if there's a minimal required FastJet version if [ ! x$min_fj_version = x ]; then if ! version_is_at_least ${fjversion} ${min_fj_version}; then echo "$contrib requires Fastjet $min_fj_version or higher. Fastjet $fjversion < $min_fj_version has been found." echo Bailing out of the configure process exit 1 fi fi # then, check potential dependencies on other contribs deps="" for i in "${!dependencies[@]}"; do echo " ${dependencies[i]} (needs v>=${min_versions[i]})" if ! item_is_in_list ${dependencies[i]} "${sorted_built_contribs}"; then echo " not in the list of built contribs" echo Bailing out of the configure process exit 1 fi if [ -d ${dependencies[i]} ]; then read_tag ${dependencies[i]} version dep_version echo -n " found ${dep_version}" if version_is_at_least ${dep_version} ${min_versions[i]}; then echo " (>= ${min_versions[i]})" else echo " (< ${min_versions[i]})" echo The version of ${dependencies[i]} found is ${dep_version}, but at least ${min_versions[i]} is required echo Bailing out of the configure process exit 1 fi else echo " not found" echo Bailing out of the configure process exit 1 fi deps="$deps ${dependencies[i]}.all" done #deps=$(echo $dependencies | tr " " "\n") #echo "Dependencies for $contrib: " $deps #echo "Dependencies for $contrib: " $deps cat >> Makefile < config.log echo -e "The command line invocation was\n" >> config.log echo -e " $0 $@\n" >> config.log for contrib in $sorted_built_contribs do read_tag $contrib version contribversion printf " %-22s v%s\n" $contrib $contribversion >> config.log done echo -e "\nInstallation prefix: "$prefix"\n" >> config.log