#!/bin/bash # define functions needed later on #_____________________________________________________________________ # checks if one of the files is existing and print message # updated to check a list of packages because some libraries # have slightly different names on differnt platforms function not_there { pack=$1 shift files=$* retval=0 for file in $files;do if [ -e $file ]; then echo "*** Package $pack is OK ***" | tee -a $logfile return 1 fi done echo "*** Compiling $pack ................ " | tee -a $logfile return 0 } #_____________________________________________________________________ # check if package is already unpacked and do the unpacking if # necessary function untar { pack=$1 tarf=$2 if [ -d $pack ]; then echo "*** Package $pack already unpacked ***" | tee -a $logfile else echo "*** Unpacking $tarf .............." | tee -a $logfile if [ "$platform" != "solaris" ]; then if [ "$(file $tarf | grep -c gzip)" = "1" ]; then tar zxf $tarf elif [ "$(file $tarf | grep -c bzip2)" = "1" ]; then tar xjf $tarf else echo "--E-- Cannot unpack package $pack" exit fi else if [ "$(file $tarf | grep -c gzip)" = "1" ]; then /usr/sfw/bin/gtar xzf $tarf elif [ "$(file $tarf | grep -c bzip2)" = "1" ]; then /usr/sfw/bin/gtar xjf $tarf else echo "--E-- Cannot unpack package $pack" exit fi fi fi } #_____________________________________________________________________ # check if file exists after the compilation process # return error code function check_success { pack=$1 file=$2 if [ -e $file ]; then echo "*** $1 compiled successfully ***" | tee -a $logfile return 1 else echo "*** ERROR: $1 could not be created." | tee -a $logfile return 0 fi } #_____________________________________________________________________ # scripts perform sed command differently on linux and on Mac Os X # return error code # first parameter is the text to search for, the second is the # replacement and the third one defines the filename # with the fourth on defines if the the string # contains a / function mysed { # Assert that we got enough arguments if [ $# -lt 3 ]; then echo "mysed: 3 or 4 arguments needed" echo "Script was called only with $# arguments" echo "Searchstring: $1" echo "Replacement : $2" echo "Filename : $3" if [ $# -eq 4 ]; then echo "Option : $4" fi return 1 fi old=$1 new=$2 change_file=$3 if [ $# -eq 4 ]; then has_slash=yes fi if [ "$platform" = "linux" ]; then if [ "$has_slash" = "yes" ]; then sed -e "s#$old#$new#g" -i'' $change_file else sed -e "s/$old/$new/g" -i'' $change_file fi elif [ "$platform" = "macosx" ]; then if [ "$has_slash" = "yes" ]; then sed -e "s#$old#$new#g" -i '' $change_file else sed -e "s/$old/$new/g" -i '' $change_file fi elif [ "$platform" = "solaris" ]; then mv $change_file tmpfile if [ "$has_slash" = "yes" ]; then sed -e "s#$old#$new#g" tmpfile > $change_file else sed -e "s/$old/$new/g" tmpfile > $change_file fi rm tmpfile fi } #_____________________________________________________________________ function check_library { # The function is inspired by the ROOT configure script and adapted # to run on linux and Mac OS X # # This function will try to find out if a library [$1] contains 64 bit # or 32 bit code. Currently works only for linux and Mac OS X. # The result of the check is stored in lib_is, which should be # immediately copied or used , since the variable # will be overwritten at next invocation of this function. chklibname=$1 lib_is=0 # Assert that we got enough arguments if [ $# -ne 1 ]; then echo "check_library: not 1 argument" return 1 fi if [ "x`basename $chklibname .a`" != "x`basename $chklibname`" ]; then # we have an archive .a file if [ "$platform" = "linux" ]; then objdump -a $1 | grep 'x86-64' > /dev/null 2>& 1 ret=$? elif [ "$platform" = "macosx" ]; then # 0xfeedfacf is the magic key for 64bit files otool -h $1 | grep '0xfeedfacf' > /dev/null 2>& 1 ret=$? elif [ "$platform" = "solaris" ]; then # Since I don't have a 64bit machine in can only test for 32bit # because i don't now the result on a 64bit machine. /usr/sfw/bin/gobjdump -a $1 | grep 'elf32-i386' > /dev/null 2>& 1 ret1=$? if [ $ret1 -eq 0 ]; then ret=1 else ret=0 fi fi else if [ "$platform" = "solaris" ]; then file $1 | grep '64-Bit' > /dev/null 2>& 1 ret=$? if [ $ret -eq 1 ];then file $1 | grep '64-bit' > /dev/null 2>& 1 ret=$? fi else file -L $1 | grep '64-bit' > /dev/null 2>& 1 ret=$? fi fi if [ $ret -eq 0 ]; then lib_is=64bit else lib_is=32bit fi } #_____________________________________________________________________ function check_all_libraries { # This function loops over all libraries in the given path and # checks if the library contains code as given in $system. # Assert that we got enough arguments if [ $# -ne 1 ]; then echo "check_all_libraries: not 1 argument" return 1 fi chkdirname=$1 echo "**** Checking libraries in $chkdirname ****" | tee -a $logfile_lib if [ "$platform" = "linux" -o "$platform" = "solaris" ]; then shared_ext=so elif [ "$platform" = "macosx" ]; then shared_ext=dylib fi oldpwd=$(pwd) cd $chkdirname if [ "$(find . -name "lib*.$shared_ext" | wc -l)" != "0" ]; then for file in $(ls *.$shared_ext); do check_library $file if [ "$lib_is" != "$system" ]; then echo "Library $file is $lib_is, but system is $system" | tee -a $logfile_lib # else # echo "Library $file is ok" | tee -a $logfile_lib fi done fi if [ "$(find . -name "lib*.a" | wc -l)" != "0" ]; then for file in $(ls lib*.a); do check_library $file if [ "$lib_is" != "$system" ]; then echo "Library $file is $lib_is, but system is $system" | tee -a $logfile_lib # else # echo "Library $file is ok" | tee -a $logfile_lib fi done fi cd $oldpwd } #_____________________________________________________________________ function is_in_path { # This function checks if a file exists in the $PATH. # To do so it uses which. # There are several versions of which available with different # return values. Either it is "" or "no searched program in PATH" or # "/usr/bin/which: no ". # To check for all differnt versions check if the return statement is # not "". # If it is not "" check if the return value starts with no or have # the string "no in the return string. If so set # return value to "". So all negative return statements go to "". # If program is found in Path return 1, else return 0. searched_program=$1 answer=$(which $searched_program) if [ "$answer" != "" ]; then no_program=$(which $searched_program | grep -c '^no' ) no_program1=$(which $searched_program | grep -c "^no $searched_program") if [ "$no_program" != "0" -o "$no_program1" != "0" ]; then answer="" fi fi if [ "$answer" != "" ]; then return 1 else return 0 fi } #------------------------------------ function create_links { # create symbolic links from files with suffix $2 to $1 ext1=$1 ext2=$2 for file in $(ls *.$ext1); do ln -s $file ${file%.*}.$ext2 done }