Files
geant4/environments/g4py/tools/g4package/g4pack
T
2016-06-09 14:55:03 +02:00

243 lines
5.7 KiB
Bash
Executable File

#! /bin/sh -
# ======================================================================
# A script for Geant4 packaging
#
# ======================================================================
export LANG=C
IFS='
'
PATH=/bin:/usr/bin
export PATH
# ======================================================================
# help message
# ======================================================================
show_help() {
cat <<EOF
Usage: g4pack [<options>]
Options:
--help, -h print this message
--with-g4system=G4SYSTEM G4SYSTEM [\$G4SYSTEM]
--with-g4-dir=DIR Geant4 dir [\$G4INSTALL]
--with-clhep-dir=DIR CLHEP dir [\$CLHEP_BASE_DIR]
--with-lib-dir=DIR G4 static granular libdir [lib]
--with-glib-dir=DIR G4 global static libdir [glib]
--with-slib-dir=DIR G4 global shared libdir [slib]
--with-install-dir=DIR install path (MacOSX only)
Enable/disable options: prefix with either --enable- or --disable-
lib packing static granular lib [disable]
glib packing global static lib [enable]
slib packing global shared lib [enable]
EOF
}
# ======================================================================
# rebuild shared library (MacOSX only)
# ======================================================================
rebuild_sharedlib() {
mkdir tmp
mv lib*.dylib ./tmp
liblist=lib*.a
for lib in $liblist
do
slibname=${lib%.*}.dylib
#check linked libraries...
extliblist=`otool -L tmp/$slibname | grep -v /usr/lib | grep -v $slibname | awk '{print $1}'`
ar x $lib
g++ -dynamiclib -single_module -undefined dynamic_lookup \
-install_name $install_dir/lib/$slibname \
$extliblist -o $slibname *.o
rm *.o __.SYMDEF
chmod 755 $slibname
done
rm -r tmp
}
# ======================================================================
# main
# ======================================================================
# default values
g4system=${G4SYSTEM:-XXX}
g4dir=${G4INSTALL:-/zzz}
clhepdir=${CLHEP_BASE_DIR:-/zzz}
install_dir=/zzz
libdir=lib
glibdir=glib
slibdir=slib
enable_lib=0
enable_glib=1
enable_slib=1
# parsing options
while test $# -gt 0
do
case $1 in
-*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
*) optarg= ;;
esac
case $1 in
--help|-h) show_help; exit 0 ;;
# ---------------------------------------------------------------
--with-g4system=*) g4system=$optarg ;;
--with-g4-dir=*) g4dir=$optarg ;;
--with-clhep-dir=*) clhepdir=$optarg ;;
--with-lib-dir=*) libdir=$optarg ;;
--with-glib-dir=*) glibdir=$optarg ;;
--with-slib-dir=*) slibdir=$optarg ;;
--with-install-dir=*) install_dir=$optarg ;;
# ---------------------------------------------------------------
--enable-lib ) enable_lib=1 ;;
--disable-lib ) enable_lib=0 ;;
--enable-glib ) enable_glib=1 ;;
--disable-glib ) enable_glib=0 ;;
--enable-slib ) enable_slib=1 ;;
--disable-slib ) enable_slib=0 ;;
# ---------------------------------------------------------------
-*)
echo "Unrecognized option: $1"
exit -1
;;
*)
echo "Invalid argument: $1"
exit -1
;;
esac
shift
done
# check something
shlib=so
if [ $g4system == Darwin-g++ ]; then
shlib=dylib
fi
echo -n "Checking for G4 dir ..."
if [ ! -d $g4dir ]; then
echo "no"
echo "### $g4dir does not exist."
exit -1
fi
echo $g4dir
echo -n "Checking for CLHEP dir ..."
if [ ! -d $clhepdir ]; then
echo "no"
echo "### $clhepdir does not exist."
exit -1
fi
echo $clhepdir
echo -n "Checking for G4SYSTEM ..."
if [ ! -e $g4dir/config/sys/$g4system.gmk ]; then
echo "no"
echo "### $g4system is invalid."
exit -1
fi
echo $g4system
if [ $enable_lib == 1 ]; then
echo -n "Checking for lib dir ..."
if [ ! -d $g4dir/$libdir ]; then
echo "no"
echo "### $libdir is invalid."
exit -1
fi
echo $libdir
fi
if [ $enable_glib == 1 ]; then
echo -n "Checking for glib dir ..."
if [ ! -d $g4dir/$glibdir ]; then
echo "no"
echo "### $glibdir is invalid."
exit -1
fi
echo $glibdir
fi
if [ $enable_slib == 1 ]; then
echo -n "Checking for glib dir ..."
if [ ! -d $g4dir/$slibdir ]; then
echo "no"
echo "### $slibdir is invalid."
exit -1
fi
echo $slibdir
fi
# ----------------------------------------------------------------------
# ok go ahead
echo ""
echo "Packing ..."
g4packdir=g4
if [ -d $g4packdir ]; then
echo "### $g4packdir/ already exist. Please move it."
exit -1
fi
mkdir -p $g4packdir
mkdir -p $g4packdir/include
mkdir -p $g4packdir/lib
# CLHEP
cp -pR $clhepdir/include/CLHEP $g4packdir/include/
cp -pR $clhepdir/lib/libCLHEP-[12]* $g4packdir/lib/
# Geant4
cp -pR $g4dir/include $g4packdir/include/
mv $g4packdir/include/include $g4packdir/include/Geant4
rm $g4packdir/include/Geant4/README
if [ $enable_glib == 1 ]; then
cp -pR $g4dir/$glibdir/$g4system/lib* $g4packdir/lib
fi
if [ $enable_slib == 1 ]; then
cp -pR $g4dir/$slibdir/$g4system/lib* $g4packdir/lib
if [ $g4system == Darwin-g++ ]; then
if [ $enable_glib == 0 ]; then
echo "### gobal static library is required for the operation."
exit -1
fi
pushd $g4packdir/lib >& /dev/null
rebuild_sharedlib
popd >& /dev/null
fi
fi
if [ $enable_lib == 1 ]; then
cp -pR $g4dir/$libdir/$g4system/lib* $g4packdir/lib
fi
# CLHEP links
pushd $g4packdir/lib >& /dev/null
ln -s libCLHEP-[12]*.a libCLHEP.a
ln -s libCLHEP-[12]*.$shlib libCLHEP.$shlib
popd >& /dev/null
exit 0