BASIS  r3148
basis.sh
Go to the documentation of this file.
00001 ##############################################################################
00002 # @file  basis.sh
00003 # @brief BASIS utilities of BASIS package.
00004 #
00005 # @note The basis.sh module was automatically created by BASIS from the
00006 #       template file basis.sh.in which is part of BASIS.
00007 #
00008 # This module sources the modules of the project-independent BASIS Bash Utilities
00009 # which are part of the BASIS installation. Hence, it is sufficient to only
00010 # source this module.
00011 #
00012 # @note In Bash, there is no concept of namespaces. Hence, the utility functions
00013 #       are all defined by the utilities.sh module which is part of the BASIS
00014 #       installation. See the documentation of this module for conflicts that
00015 #       may be caused by this lack of namespaces and how to circumvent these.
00016 #       This module is mainly intended for use in executable scripts, not modules.
00017 #
00018 # Copyright (c) 2011, 2012, 2013 University of Pennsylvania. All rights reserved.<br />
00019 # See https://www.cbica.upenn.edu/sbia/software/license.html or COPYING file.
00020 #
00021 # Contact: SBIA Group <sbia-software at uphs.upenn.edu>
00022 #
00023 # @ingroup BasisBashUtilities
00024 ##############################################################################
00025 
00026 [ "${_BASIS_BASIS_INCLUDED}" == 'true' ] || {
00027 _BASIS_BASIS_INCLUDED='true'
00028 
00029 
00030 # ============================================================================
00031 # configuration of utilities
00032 # ============================================================================
00033 
00034 # the functions of the utilities.sh module make use of the following constants
00035 # these constants need to be set before sourcing utilities.sh as otherwise
00036 # this module will initialize them and set them to readonly
00037 
00038 ## @addtogroup BasisBashUtilities
00039 # @{
00040 
00041 
00042 ## @brief Project name.
00043 readonly PROJECT='BASIS'
00044 ## @brief Project version.
00045 readonly VERSION='0.0.0'
00046 ## @brief Major project version.
00047 readonly VERSION_MAJOR='0'
00048 ## @brief Minor project version.
00049 readonly VERSION_MINOR='0'
00050 ## @brief Project patch number.
00051 readonly VERSION_PATCH='0'
00052 ## @brief Project release.
00053 readonly RELEASE='r3148'
00054 ## @brief Default copyright of executables.
00055 COPYRIGHT='2011, 2012, 2013 University of Pennsylvania'
00056 ## @brief Default license of executables.
00057 LICENSE='See https://www.cbica.upenn.edu/sbia/software/license.html or COPYING file.'
00058 ## @brief Default contact to use for help output of executables.
00059 CONTACT='SBIA Group <sbia-software at uphs.upenn.edu>'
00060 
00061 # if the following variables are not set, they are initialized to the
00062 # default values configured in the basis.utilitis module and then marked
00063 # as readonly by this module. otherwise, mark variables as readonly here
00064 [ -n "${COPYRIGHT}" ] && readonly COPYRIGHT
00065 [ -n "${LICENSE}"   ] && readonly LICENSE
00066 [ -n "${CONTACT}"   ] && readonly CONTACT
00067 
00068 
00069 ## @}
00070 # end of Doxygen group
00071 
00072 readonly _BASIS_TARGET_UID_PREFIX='basis'
00073 readonly _BASIS_EXECUTABLE_TARGETS_BASE="`cd -P -- \`dirname -- "${BASH_SOURCE}"\` && pwd`"
00074 _BASIS_BASH_LIBRARY_DIR='..'
00075 if [ "${_BASIS_BASH_LIBRARY_DIR:0:1}" != '/' ]; then
00076     _BASIS_BASH_LIBRARY_DIR="${_BASIS_EXECUTABLE_TARGETS_BASE}/${_BASIS_BASH_LIBRARY_DIR}"
00077 fi
00078 readonly _BASIS_BASH_LIBRARY_DIR
00079 
00080 # ============================================================================
00081 # source implementations of utility functions
00082 # ============================================================================
00083 
00084 # source project-independent utility functions
00085 if [ -z "${BASIS_BASHPATH}" ]; then
00086     _path=''
00087     _paths="${BASHPATH}:" # ATTENTION: Trailing ':' required to terminate while loop!
00088     while [ -n "${_paths}" ]; do
00089         _path="${_paths%%:*}"
00090         [ "${_path:0:1}" == '/' ] && [ -f "${_path}/basis/utilities.sh" ] && break
00091         _path=''
00092         _paths="${_paths#*:}"
00093     done
00094     if [ -n "${_path}" ]; then
00095         BASIS_BASHPATH="${_path}"
00096     else
00097         BASIS_BASHPATH="${_BASIS_BASH_LIBRARY_DIR}"
00098     fi
00099 fi
00100 if [ ! -f "${BASIS_BASHPATH}/basis/utilities.sh" ]; then
00101     echo "Module basis.utilities not found at ${BASIS_BASHPATH}!" 1>&2
00102     echo "Specify path using the BASHPATH or BASIS_BASHPATH environment variable." 1>&2
00103     exit 1
00104 fi
00105 . "${BASIS_BASHPATH}/basis/utilities.sh"
00106 if [[ $? -ne 0 ]]; then
00107     echo "Failed to import basis.utilities module!" 1>&2
00108     exit 1
00109 fi
00110 
00111 # ============================================================================
00112 # initialize executable target information
00113 # ============================================================================
00114 
00115 # ----------------------------------------------------------------------------
00116 # @brief Initialize executable target information.
00117 #
00118 # This function initializes the structures of information about the executable
00119 # build targets. If this function is executed another time, it does nothing
00120 # because the structures are initialized already. In order to reduce the start
00121 # time of applications that do not make use of this module, the initialization
00122 # is only performed on demand.
00123 #
00124 # The initialization is done in get_target_uid() as this function is always
00125 # called first before any lookup of information.
00126 #
00127 # @returns Nothing.
00128 #
00129 # @retval 0 On success.
00130 # @retval 1 On failure.
00131 _basis_executabletargetinfo_initialize()
00132 {
00133     [ $# -eq 0 ] || return 1
00134     [[ "${_BASIS_EXECUTABLETARGETINFO_INITIALIZED}" == true ]] && return 0
00135 
00136     _basis_executabletargetinfo_add 'basis.basisproject'      LOCATION '../../../bin/basisproject'
00137     _basis_executabletargetinfo_add 'basis.doxyfilter'        LOCATION '../../doxyfilter'
00138     _basis_executabletargetinfo_add 'basis.doxyfilter-perl'   LOCATION '../../doxyfilter-perl'
00139     _basis_executabletargetinfo_add 'basis.testdriver'        LOCATION '../../testdriver'
00140     _basis_executabletargetinfo_add 'basis.basistest-svn'     LOCATION '../../basistest-svn'
00141     _basis_executabletargetinfo_add 'basis.basistest-slave'   LOCATION '../../basistest-slave'
00142     _basis_executabletargetinfo_add 'basis.basistest-master'  LOCATION '../../basistest-master'
00143     _basis_executabletargetinfo_add 'basis.basistest-cron'    LOCATION '../../basistest-cron'
00144     _basis_executabletargetinfo_add 'basis.basistest'         LOCATION '../../../bin/basistest'
00145     _basis_executabletargetinfo_add 'basis.dummy_command'     LOCATION '../../../bin/dummy_command'
00146     _basis_executabletargetinfo_add 'basis.test_matlabtools'  LOCATION ''
00147     _basis_executabletargetinfo_add 'basis.test_basisproject' LOCATION ''
00148     _basis_executabletargetinfo_add 'basis.test_os'           LOCATION '../../../bin/test_os'
00149     _basis_executabletargetinfo_add 'basis.test_path'         LOCATION '../../../bin/test_path'
00150     _basis_executabletargetinfo_add 'basis.test_subprocess'   LOCATION '../../../bin/test_subprocess'
00151     _basis_executabletargetinfo_add 'basis.test_core'         LOCATION ''
00152     _basis_executabletargetinfo_add 'basis.test_shutilities'  LOCATION ''
00153     _basis_executabletargetinfo_add 'basis.test_shtap'        LOCATION ''
00154     _basis_executabletargetinfo_add 'basis.parseargs'         LOCATION '../../../bin/parseargs'
00155     _basis_executabletargetinfo_add 'basis.test_utilities'    LOCATION ''
00156 
00157     _BASIS_EXECUTABLETARGETINFO_INITIALIZED='true'
00158     return 0
00159 }
00160 
00161 # ============================================================================
00162 # aliases (optional)
00163 # ============================================================================
00164 
00165 if [ "${basis_use_executable_aliases}" == 'true' ]; then
00166     # define aliases of build target names to executable file paths
00167     alias 'basis.basisproject'=`get_executable_path 'basis.basisproject'`
00168     alias 'basis.doxyfilter'=`get_executable_path 'basis.doxyfilter'`
00169     alias 'basis.doxyfilter-perl'=`get_executable_path 'basis.doxyfilter-perl'`
00170     alias 'basis.testdriver'=`get_executable_path 'basis.testdriver'`
00171     alias 'basis.basistest-svn'=`get_executable_path 'basis.basistest-svn'`
00172     alias 'basis.basistest-slave'=`get_executable_path 'basis.basistest-slave'`
00173     alias 'basis.basistest-master'=`get_executable_path 'basis.basistest-master'`
00174     alias 'basis.basistest-cron'=`get_executable_path 'basis.basistest-cron'`
00175     alias 'basis.basistest'=`get_executable_path 'basis.basistest'`
00176     alias 'basis.dummy_command'=`get_executable_path 'basis.dummy_command'`
00177     alias 'basis.test_matlabtools'=`get_executable_path 'basis.test_matlabtools'`
00178     alias 'basis.test_basisproject'=`get_executable_path 'basis.test_basisproject'`
00179     alias 'basis.test_os'=`get_executable_path 'basis.test_os'`
00180     alias 'basis.test_path'=`get_executable_path 'basis.test_path'`
00181     alias 'basis.test_subprocess'=`get_executable_path 'basis.test_subprocess'`
00182     alias 'basis.test_core'=`get_executable_path 'basis.test_core'`
00183     alias 'basis.test_shutilities'=`get_executable_path 'basis.test_shutilities'`
00184     alias 'basis.test_shtap'=`get_executable_path 'basis.test_shtap'`
00185     alias 'basis.parseargs'=`get_executable_path 'basis.parseargs'`
00186     alias 'basis.test_utilities'=`get_executable_path 'basis.test_utilities'`
00187 
00188     # define short aliases for this project's targets
00189     alias 'basisproject'='basis.basisproject'
00190     alias 'doxyfilter'='basis.doxyfilter'
00191     alias 'doxyfilter-perl'='basis.doxyfilter-perl'
00192     alias 'testdriver'='basis.testdriver'
00193     alias 'basistest-svn'='basis.basistest-svn'
00194     alias 'basistest-slave'='basis.basistest-slave'
00195     alias 'basistest-master'='basis.basistest-master'
00196     alias 'basistest-cron'='basis.basistest-cron'
00197     alias 'basistest'='basis.basistest'
00198     alias 'dummy_command'='basis.dummy_command'
00199     alias 'test_matlabtools'='basis.test_matlabtools'
00200     alias 'test_basisproject'='basis.test_basisproject'
00201     alias 'test_os'='basis.test_os'
00202     alias 'test_path'='basis.test_path'
00203     alias 'test_subprocess'='basis.test_subprocess'
00204     alias 'test_core'='basis.test_core'
00205     alias 'test_shutilities'='basis.test_shutilities'
00206     alias 'test_shtap'='basis.test_shtap'
00207     alias 'parseargs'='basis.parseargs'
00208     alias 'test_utilities'='basis.test_utilities'
00209 
00210     # enable expansion of aliases also in non-interactive shells
00211     shopt -s expand_aliases
00212 fi
00213 
00214 
00215 } # _BASIS_BASIS_INCLUDED