#!/bin/bash # g4blmake - build user code into G4beamline # # Usage: # g4blmake [-h|-?|--help] [source1.cc source2.cc ...] # Makes a private build of g4beamline incorporating the listed # source files (*.cc *.C *.cpp by default). # # See the G4beamline User's Guide for instructions and suggestions # on how to write code that G4beamline can use. # # You can include new versions of G4beamline or library source files, # as long as their filenames are the same, as are the classes (etc.) # that they implement. # # This script must be run via an absolute pathname, using the # bin directory of the distribution. That implies that the # G4beamline "g4bl-setup.sh" command should be source-d by your shell. # # If G4BL_DIR is set in the environment, then it is used instead of # the above. There may well be problems if this script is not the same # as the version in $G4BL_DIR/bin. # # G4BL_DIR is used to find the files needed to compile and link into # G4beamline. It must point to a directory in which the G4beamline # libraries and source have already been built. export G4BLMAKE=$USER VERBOSE=false SOURCEFILES="" while test "$1" do case "$1" in -h|-\?|--help) echo >&2 "USAGE:" echo >&2 ' g4blmake [-h|-?|--help] [-v] [source1.cc ...]' echo >&2 'Source files default to *.cc *.cpp *.C' echo >&2 "See the G4beamline User's Guide for instructions and" echo >&2 "suggestions on how to write code for G4beamline." echo >&2 "G4beamline include paths and libraries are supplied." echo >&2 "Flags to the compiler can be passed in CPPFLAGS." echo >&2 "Extra libraries can be passed in EXTRALIBS." exit ;; -v) VERBOSE=true ;; *) SOURCEFILES="$SOURCEFILES $1" ;; esac shift done # find G4BL_DIR if test "$G4BL_DIR" = "" then G4BL_DIR=`dirname "$0"` G4BL_DIR=`\cd "$G4BL_DIR" >&- 2>&- && pwd` G4BL_DIR=`dirname "$G4BL_DIR"` if test -x /bin/cygpath then G4BL_DIR=`/bin/cygpath -m "$G4BL_DIR"` fi fi export G4BL_DIR # get SOURCEFILES if test -z "$SOURCEFILES" then for i in *.cc *.cpp *.C do if test -r "$i" then SOURCEFILES="$SOURCEFILES $i" fi done fi SOURCEFILES=${SOURCEFILES# } # remove any initial space if test -z "$SOURCEFILES" then echo >&2 "g4blmake: no source files found" exit 1 fi echo >&2 "compiling $SOURCEFILES, and linking g4beamline" CPPFLAGS="$CPPFLAGS $($G4BL_DIR/bin/g4bl-config --include)" LIBS="$EXTRALIBS $($G4BL_DIR/bin/g4bl-config --libs)" MAIN="$($G4BL_DIR/bin/g4bl-config --main)" OBJS="$($G4BL_DIR/bin/g4bl-config --objs)" # remove duplicates from OBJS TMP='' for i in $OBJS do KEEP=true F=`basename $i` F="${F%.*}" for j in $SOURCEFILES do G=`basename $j` G="${G%.*}" if test "$F" = "$G" then KEEP=false break fi done if $KEEP then TMP="$TMP $i" fi done OBJS="$TMP" # construct CMD if test `$G4BL_DIR/bin/g4bl-config --sys` = WIN32 then VCFLAGS=`$G4BL_DIR/bin/g4bl-config --vcflags` CMD="cl $VCFLAGS $CPPFLAGS /Feg4beamline $MAIN $SOURCEFILES $OBJS $LIBS" else CMD="g++ $CPPFLAGS -o g4beamline $MAIN $SOURCEFILES $OBJS $LIBS" fi # compile and link g4beamline if $VERBOSE then echo $CMD fi $CMD # check compilation if test "$?" != 0 then echo >&2 "g4blmake: FAILED!" exit 1 else echo >&2 "Success! To execute this program you should do:" echo >&2 " export G4BEAMLINE=$PWD/g4beamline" echo >&2 " g4bl [...]" echo >&2 fi