#!/bin/sh # Link fluka script CURDIR=$(dirname "$0") usage() { cat < -b -a -m
-L -O -d [obj files...] EOF } help() { usage cat < name of the executable to be created, if more are specified, the last one is taken, default is fluka -b user library to be added in the link sequence, before the fluka library, more than one library will be specified and they will be searched in order. The name of the file must be lib.a -l like -b -a user library to be added in the link sequence, after the fluka library, more than one library will be specified and they will be searched in order. The name of the file must be lib.a -O user library to be added in the link sequence AS OBJECT file. The name of the file must be lib.a -m main program to be used, it will be extracted from the fluka library and linked as first object code -L directory where libraries should be searched. The default is ${FTOP}. This option can be repeated and the directories will searched in the order given -d include dpmjet and rqmd in the libraries -h print this help file obj object files to be linked after
(if specified) but before the user libraries author: Vasilis.Vlachoudis@cern.ch date: 2019.06.01 EOF } if [ "$1" = "" ]; then usage exit fi OUTPUT="fluka" MAIN="fluka" OBJ="" DIR=$(dirname "${CURDIR}") CONFIG=${CURDIR}/fluka-config FC=$(${CONFIG} --compiler) CC=gcc INC=$(${CONFIG} --include) CFLAGS=$(${CONFIG} --cflags) FFLAGS=$(${CONFIG} --fflags) LFLAGS=$(${CONFIG} --lflags) LIBPATH=$(${CONFIG} --libpath) LIB=$(${CONFIG} --lib) USERLIBPATH="" BEFORE="" AFTER="" OBJS="" INTOBJS="" LOBJS="" SOURCE="" while [ $# -gt 0 ]; do while getopts "hdo:b:l:a:O:m:L:" opt; do case $opt in h) help exit ;; o) OUTPUT=${OPTARG} ;; m) MAIN=${OPTARG} ;; d) # Interface object files for RQMD/DPMET are returned by fluka-config # This way an error is raised at compilation if any of those files # is accidentaly missing INTOBJS=$(${CONFIG} --intobjs) # Note that the library order matters for the driver compilation LIB="$(${CONFIG} --rqmdlib) ${LIB} $(${CONFIG} --dpmlib) -lfluka" ;; b|l) BEFORE="${BEFORE} -l${OPTARG}" ;; a) AFTER="${AFTER} -l${OPTARG}" ;; O) LOBJS="${LOBJS} lib${OPTARG}.a" ;; L) USERLIBPATH="-L${OPTARG}" ;; *) echo "Unknown option $opt" ;; esac done # shift the remaining arguments shift `expr $OPTIND - 1` # check if any arguments left? if [ $# -gt 0 ] ; then SOURCE=$* break fi done # Compile the necessary source files if required for filename in ${SOURCE}; do # find extension name="${filename%.*}" ext="${filename##*.}" basename="$(basename "${filename%.*}")" case $ext in f|for|F|FOR) echo ${FC} -c ${INC} ${FFLAGS} ${filename} ${FC} -c ${INC} ${FFLAGS} ${filename} OBJS="${OBJS} ${basename}.o" ;; c) echo ${CC} -c ${INC} ${CFLAGS} ${filename} ${CC} -c ${INC} ${CFLAGS} ${filename} OBJS="${OBJS} ${basename}.o" ;; o) OBJS="${OBJS} ${filename}" ;; *) echo "Unknown file specified ${filename}" exit 1 ;; esac done echo ${FC} -o ${OUTPUT} ${LFLAGS} ${OBJS} ${INTOBJS} ${LOBJS} ${USERLIBPATH} ${BEFORE} ${LIBPATH} ${LIB} ${AFTER} ${FC} -o ${OUTPUT} ${LFLAGS} ${OBJS} ${INTOBJS} ${LOBJS} ${USERLIBPATH} ${BEFORE} ${LIBPATH} ${LIB} ${AFTER}