Commit b129a8d0 authored by gsell's avatar gsell
Browse files

- em.xyz renamed to pmodules.xxy

- underscore removed as prefix of function names
- keyword function removed
parent e26a9fae
...@@ -34,7 +34,7 @@ set -o errexit ...@@ -34,7 +34,7 @@ set -o errexit
trap "error_handler" ERR trap "error_handler" ERR
function error_handler() { error_handler() {
local -i ec=$? local -i ec=$?
exit ${ec} exit ${ec}
......
...@@ -56,7 +56,7 @@ declare -x DYLD_LIBRARY_PATH ...@@ -56,7 +56,7 @@ declare -x DYLD_LIBRARY_PATH
############################################################################## ##############################################################################
# #
function usage() { usage() {
error " error "
Usage: $0 [OPTIONS..] [VERSION] [ENV=VALUE...] Usage: $0 [OPTIONS..] [VERSION] [ENV=VALUE...]
...@@ -104,28 +104,24 @@ is_release () { ...@@ -104,28 +104,24 @@ is_release () {
############################################################################## ##############################################################################
# #
# test whether a module is loaded or not # set supported OS
# #
# $1: module name # $1: OS (as printed by 'uname -s')
# #
em.is_loaded() { pmodules.supported_os() {
[[ :${LOADEDMODULES}: =~ :$1: ]]
}
function em.set_release() {
is_release "$1" || die 1 "$P: unknown release type: $1"
[[ "$1" == "deprecated" ]] && die 0 "$P: is deprecated, we don't rebuild it."
MODULE_RELEASE="$1"
}
function em.supported_os() {
for os in "$@"; do for os in "$@"; do
[[ ${os} == ${OS} ]] && return 0 [[ ${os} == ${OS} ]] && return 0
done done
die 0 "${P}: Not available for ${OS}." die 0 "${P}: Not available for ${OS}."
} }
function em.add_to_group() { ##############################################################################
#
# install module in given group
#
# $1: group
#
pmodules.add_to_group() {
if [[ -z ${1} ]]; then if [[ -z ${1} ]]; then
die 42 "${FUNCNAME}: Missing group argument." die 42 "${FUNCNAME}: Missing group argument."
fi fi
...@@ -135,31 +131,36 @@ function em.add_to_group() { ...@@ -135,31 +131,36 @@ function em.add_to_group() {
MODULE_GROUP=$1 MODULE_GROUP=$1
} }
em.add_to_family() { ##############################################################################
em.add_to_group "$@" #
} # install module in given group
#
function em.set_build_dependencies() { # $1: group
#
pmodules.set_build_dependencies() {
MODULE_BUILD_DEPENDENCIES=("$@") MODULE_BUILD_DEPENDENCIES=("$@")
} }
function em.set_runtime_dependencies() { pmodules.set_docfiles() {
MODULE_DEPENDENCIES=("$@") MODULE_DOCFILES=("$@")
} }
function em.set_supported_compilers() { module_is_available() {
MODULE_SUPPORTED_COMPILERS=("$@") [[ -n $("${MODULECMD}" bash avail "$1" 2>&1 1>/dev/null) ]]
} }
function em.set_docfiles() { ##############################################################################
MODULE_DOCFILES=("$@") #
# test whether a module is loaded or not
#
# $1: module name
#
is_loaded() {
[[ :${LOADEDMODULES}: =~ :$1: ]]
} }
function module_is_available() {
[[ -n $("${MODULECMD}" bash avail "$1" 2>&1 1>/dev/null) ]]
}
function _load_build_dependencies() { load_build_dependencies() {
for m in "${MODULE_BUILD_DEPENDENCIES[@]}"; do for m in "${MODULE_BUILD_DEPENDENCIES[@]}"; do
[[ -z $m ]] && continue [[ -z $m ]] && continue
if [[ ! $m =~ "*/*" ]]; then if [[ ! $m =~ "*/*" ]]; then
...@@ -170,7 +171,7 @@ function _load_build_dependencies() { ...@@ -170,7 +171,7 @@ function _load_build_dependencies() {
echo "$m: warning: No version set, loading default ..." echo "$m: warning: No version set, loading default ..."
fi fi
fi fi
em.is_loaded "$m" && continue is_loaded "$m" && continue
if ! module_is_available "$m"; then if ! module_is_available "$m"; then
debug "${m}: module not available" debug "${m}: module not available"
local rels=( ${releases//:/ } ) local rels=( ${releases//:/ } )
...@@ -240,12 +241,12 @@ function _load_build_dependencies() { ...@@ -240,12 +241,12 @@ function _load_build_dependencies() {
} }
if [[ ${bootstrap} == yes ]]; then if [[ ${bootstrap} == yes ]]; then
function _load_build_dependencies() { load_build_dependencies() {
: :
} }
fi fi
function _write_runtime_dependencies() { write_runtime_dependencies() {
local -r fname="${PREFIX}/.dependencies" local -r fname="${PREFIX}/.dependencies"
info "Writing run-time dependencies to ${fname}" info "Writing run-time dependencies to ${fname}"
local dep local dep
...@@ -260,7 +261,7 @@ function _write_runtime_dependencies() { ...@@ -260,7 +261,7 @@ function _write_runtime_dependencies() {
done done
} }
function _write_build_dependencies() { write_build_dependencies() {
local -r fname="${PREFIX}/.build_dependencies" local -r fname="${PREFIX}/.build_dependencies"
info "Writing build dependencies to ${fname}" info "Writing build dependencies to ${fname}"
local dep local dep
...@@ -279,7 +280,7 @@ function _write_build_dependencies() { ...@@ -279,7 +280,7 @@ function _write_build_dependencies() {
# #
# cleanup environment # cleanup environment
# #
em.cleanup_env() { pmodules.cleanup_env() {
C_INCLUDE_PATH='' C_INCLUDE_PATH=''
CPLUS_INCLUDE_PATH='' CPLUS_INCLUDE_PATH=''
...@@ -320,7 +321,7 @@ em.cleanup_env() { ...@@ -320,7 +321,7 @@ em.cleanup_env() {
# $2: name without version # $2: name without version
# $3: version # $3: version
# #
function find_tarball() { find_tarball() {
local -r dir=$1 local -r dir=$1
local -r name=$2 local -r name=$2
local -r version=$3 local -r version=$3
...@@ -346,7 +347,7 @@ function find_tarball() { ...@@ -346,7 +347,7 @@ function find_tarball() {
} }
#setup module specific environment #setup module specific environment
function _setup_env2() { setup_env2() {
if [[ -z ${MODULE_GROUP} ]]; then if [[ -z ${MODULE_GROUP} ]]; then
die 1 "$P: group not set." die 1 "$P: group not set."
fi fi
...@@ -499,7 +500,7 @@ function _setup_env2() { ...@@ -499,7 +500,7 @@ function _setup_env2() {
} }
# redefine function for bootstrapping # redefine function for bootstrapping
function _setup_env2_bootstrap() { setup_env2_bootstrap() {
if [[ -z ${MODULE_GROUP} ]]; then if [[ -z ${MODULE_GROUP} ]]; then
die 1 "$P: group not set." die 1 "$P: group not set."
fi fi
...@@ -538,7 +539,7 @@ function _setup_env2_bootstrap() { ...@@ -538,7 +539,7 @@ function _setup_env2_bootstrap() {
PATH+=":${PREFIX}/bin" PATH+=":${PREFIX}/bin"
} }
function _prep() { prep() {
# untar sources # untar sources
if [[ ! -d ${MODULE_SRCDIR} ]]; then if [[ ! -d ${MODULE_SRCDIR} ]]; then
...@@ -551,34 +552,34 @@ function _prep() { ...@@ -551,34 +552,34 @@ function _prep() {
} }
function em.pre_configure() { pmodules.pre_configure() {
: :
} }
function em.configure() { pmodules.configure() {
${MODULE_SRCDIR}/configure \ ${MODULE_SRCDIR}/configure \
--prefix="${PREFIX}" --prefix="${PREFIX}"
} }
function em.build() { pmodules.build() {
make -j${JOBS} make -j${JOBS}
} }
function em.install() { pmodules.install() {
make install make install
} }
function em.post_install() { pmodules.post_install() {
: :
} }
function em.install_doc() { pmodules.install_doc() {
info "Installing documentation to ${DOCDIR}" info "Installing documentation to ${DOCDIR}"
install -m 0755 -d "${DOCDIR}" install -m 0755 -d "${DOCDIR}"
install -m0444 "${MODULE_DOCFILES[@]/#/${MODULE_SRCDIR}/}" "${BUILDSCRIPT}" "${DOCDIR}" install -m0444 "${MODULE_DOCFILES[@]/#/${MODULE_SRCDIR}/}" "${BUILDSCRIPT}" "${DOCDIR}"
} }
function _set_legacy_link() { set_legacy_link() {
local -r link_name="${PMODULES_ROOT}/${PMODULES_MODULEFILES_DIR}/${MODULE_GROUP}/${MODULE_NAME}" local -r link_name="${PMODULES_ROOT}/${PMODULES_MODULEFILES_DIR}/${MODULE_GROUP}/${MODULE_NAME}"
local -r dir_name=${link_name%/*} local -r dir_name=${link_name%/*}
local -r release_file="${dir_name}/.release-${MODULE_NAME##*/}" local -r release_file="${dir_name}/.release-${MODULE_NAME##*/}"
...@@ -598,7 +599,7 @@ function _set_legacy_link() { ...@@ -598,7 +599,7 @@ function _set_legacy_link() {
echo "${MODULE_RELEASE}" > "${release_file}" echo "${MODULE_RELEASE}" > "${release_file}"
} }
function _set_link() { set_link() {
local -r link_name="${PMODULES_ROOT}/${MODULE_GROUP}/${PMODULES_MODULEFILES_DIR}/${MODULE_NAME}" local -r link_name="${PMODULES_ROOT}/${MODULE_GROUP}/${PMODULES_MODULEFILES_DIR}/${MODULE_NAME}"
local -r dir_name=${link_name%/*} local -r dir_name=${link_name%/*}
local -r release_file="${dir_name}/.release-${MODULE_NAME##*/}" local -r release_file="${dir_name}/.release-${MODULE_NAME##*/}"
...@@ -618,7 +619,7 @@ function _set_link() { ...@@ -618,7 +619,7 @@ function _set_link() {
echo "${MODULE_RELEASE}" > "${release_file}" echo "${MODULE_RELEASE}" > "${release_file}"
} }
function em.cleanup_build() { pmodules.cleanup_build() {
[[ -n "${MODULE_BUILDDIR}" ]] \ [[ -n "${MODULE_BUILDDIR}" ]] \
|| die 1 "Oops: internal error: MODULE_BUILDDIR is set to empty string..." || die 1 "Oops: internal error: MODULE_BUILDDIR is set to empty string..."
[[ "${MODULE_BUILDDIR}" == "/" ]] \ [[ "${MODULE_BUILDDIR}" == "/" ]] \
...@@ -629,7 +630,7 @@ function em.cleanup_build() { ...@@ -629,7 +630,7 @@ function em.cleanup_build() {
rm -rf "/${MODULE_BUILDDIR}" rm -rf "/${MODULE_BUILDDIR}"
} }
function em.cleanup_src() { pmodules.cleanup_src() {
( (
[[ -d /${MODULE_SRCDIR} ]] || return 0 [[ -d /${MODULE_SRCDIR} ]] || return 0
cd "/${MODULE_SRCDIR}/.."; cd "/${MODULE_SRCDIR}/..";
...@@ -641,7 +642,7 @@ function em.cleanup_src() { ...@@ -641,7 +642,7 @@ function em.cleanup_src() {
return 0 return 0
} }
function _check_compiler() { check_compiler() {
test -z ${MODULE_SUPPORTED_COMPILERS} && return 0 test -z ${MODULE_SUPPORTED_COMPILERS} && return 0
for cc in ${MODULE_SUPPORTED_COMPILERS[@]}; do for cc in ${MODULE_SUPPORTED_COMPILERS[@]}; do
if [[ ${COMPILER}/${COMPILER_VERSION} =~ ${cc} ]]; then if [[ ${COMPILER}/${COMPILER_VERSION} =~ ${cc} ]]; then
...@@ -652,62 +653,62 @@ function _check_compiler() { ...@@ -652,62 +653,62 @@ function _check_compiler() {
} }
# unfortunatelly we need sometime an OS depended post-install # unfortunatelly we need sometime an OS depended post-install
function _post_install_linux() { post_install_linux() {
cd "${PREFIX}" cd "${PREFIX}"
# solve multilib problem with LIBRARY_PATH on 64bit Linux # solve multilib problem with LIBRARY_PATH on 64bit Linux
[[ -d "lib" ]] && [[ ! -d "lib64" ]] && ln -s lib lib64 [[ -d "lib" ]] && [[ ! -d "lib64" ]] && ln -s lib lib64
return 0 return 0
} }
function _post_install() { post_install() {
info "Run post-installation for ${OS} ..." info "Run post-installation for ${OS} ..."
[[ "${OS}" == "Linux" ]] && _post_install_linux [[ "${OS}" == "Linux" ]] && post_install_linux
info "Post-installation done ..." info "Post-installation done ..."
return 0 return 0
} }
function em.make_all() { pmodules.make_all() {
local building='no' local building='no'
echo "${P}:" echo "${P}:"
_setup_env1 _setup_env1
_load_build_dependencies load_build_dependencies
# setup module specific environment # setup module specific environment
if [[ ${bootstrap} == no ]]; then if [[ ${bootstrap} == no ]]; then
_setup_env2 setup_env2
else else
_setup_env2_bootstrap setup_env2_bootstrap
fi fi
if [[ ! -d "${PREFIX}" ]] || [[ ${force_rebuild} == 'yes' ]]; then if [[ ! -d "${PREFIX}" ]] || [[ ${force_rebuild} == 'yes' ]]; then
building='yes' building='yes'
echo "Building $P/$V ..." echo "Building $P/$V ..."
[[ ${dry_run} == yes ]] && die 0 "" [[ ${dry_run} == yes ]] && die 0 ""
_check_compiler check_compiler
_prep prep
cd "${MODULE_SRCDIR}" cd "${MODULE_SRCDIR}"
em.pre_configure pmodules.pre_configure
cd "${MODULE_BUILDDIR}" cd "${MODULE_BUILDDIR}"
em.configure pmodules.configure
em.build pmodules.build
em.install pmodules.install
em.post_install pmodules.post_install
em.install_doc pmodules.install_doc
_post_install post_install
if [[ ${bootstrap} == 'no' ]]; then if [[ ${bootstrap} == 'no' ]]; then
_write_runtime_dependencies write_runtime_dependencies
_write_build_dependencies write_build_dependencies
fi fi
[[ ${enable_cleanup_build} == yes ]] && em.cleanup_build [[ ${enable_cleanup_build} == yes ]] && pmodules.cleanup_build
[[ ${enable_cleanup_src} == yes ]] && em.cleanup_src [[ ${enable_cleanup_src} == yes ]] && pmodules.cleanup_src
else else
echo "Not rebuilding $P/$V ..." echo "Not rebuilding $P/$V ..."
fi fi
if [[ ${bootstrap} == 'no' ]]; then if [[ ${bootstrap} == 'no' ]]; then
if [[ -d "${PMODULES_ROOT}/${PMODULES_MODULEFILES_DIR}" ]]; then if [[ -d "${PMODULES_ROOT}/${PMODULES_MODULEFILES_DIR}" ]]; then
_set_legacy_link set_legacy_link
fi fi
_set_link set_link
fi fi
return 0 return 0
} }
...@@ -722,7 +723,7 @@ bootstrap='no' ...@@ -722,7 +723,7 @@ bootstrap='no'
enable_cleanup_build='yes' enable_cleanup_build='yes'
enable_cleanup_src='no' enable_cleanup_src='no'
em.cleanup_env pmodules.cleanup_env
# array collecting all modules specified on the command line via '--with=module' # array collecting all modules specified on the command line via '--with=module'
with_modules=() with_modules=()
......
#!/bin/bash #!/bin/bash
#set -o functrace #set -o functrace
source "$(dirname $0)/../../../lib/libem.bash" source "$(dirname $0)/../../../lib/libpmodules.bash"
TCL_DIR="${PMODULES_ROOT}/Tools/Pmodules/${PMODULES_VERSION}" TCL_DIR="${PMODULES_ROOT}/Tools/Pmodules/${PMODULES_VERSION}"
PATH="${TCL_DIR}/bin:${PATH}" PATH="${TCL_DIR}/bin:${PATH}"
function em.configure() { pmodules.configure() {
case ${OS} in case ${OS} in
Linux ) Linux )
declare -x LIBS="-lz -lpthread" declare -x LIBS="-lz -lpthread"
...@@ -25,7 +25,7 @@ function em.configure() { ...@@ -25,7 +25,7 @@ function em.configure() {
|| exit 1 || exit 1
} }
function em.post_install() { pmodules.post_install() {
rm -v ${PREFIX}/Modules/bin/add.modules rm -v ${PREFIX}/Modules/bin/add.modules
rm -v ${PREFIX}/Modules/bin/mkroot rm -v ${PREFIX}/Modules/bin/mkroot
rm -rfv ${PREFIX}/Modules/modulefiles rm -rfv ${PREFIX}/Modules/modulefiles
...@@ -47,8 +47,8 @@ module() { ...@@ -47,8 +47,8 @@ module() {
# use system gcc to compile # use system gcc to compile
declare -rx CC=gcc declare -rx CC=gcc
em.add_to_family 'Tools' pmodules.add_to_group 'Tools'
em.make_all pmodules.make_all
# Local Variables: # Local Variables:
# mode: sh # mode: sh
......
...@@ -108,7 +108,7 @@ prepend_path () { ...@@ -108,7 +108,7 @@ prepend_path () {
# Based on solution published here: # Based on solution published here:
# https://stackoverflow.com/questions/273909/how-do-i-manipulate-path-elements-in-shell-scripts # https://stackoverflow.com/questions/273909/how-do-i-manipulate-path-elements-in-shell-scripts
# #
function replace_path () { replace_path () {
local -r path=$1 local -r path=$1
local -r removepat=$2 local -r removepat=$2
local -r replacestr=$3 local -r replacestr=$3
......
...@@ -13,7 +13,7 @@ declare -A fmmap # module name to family member mapping ...@@ -13,7 +13,7 @@ declare -A fmmap # module name to family member mapping
declare -a relmap # module info index to release mapping declare -a relmap # module info index to release mapping
declare tempfile # temporary dialog results declare tempfile # temporary dialog results
function set_difference() { # $1 \ $2 set_difference() { # $1 \ $2
local -a operand1=($1) local -a operand1=($1)
local -a operand2=($2) local -a operand2=($2)
local -A members local -A members
...@@ -27,7 +27,7 @@ function set_difference() { # $1 \ $2 ...@@ -27,7 +27,7 @@ function set_difference() { # $1 \ $2
echo ${!members[@]} echo ${!members[@]}
} }
function set_merge() { # $1 U $2 (where $1 and $2 are disjoint) set_merge() { # $1 U $2 (where $1 and $2 are disjoint)
if [[ -z "$1" ]]; then if [[ -z "$1" ]]; then
echo "$2" echo "$2"
elif [[ -z "$2" ]]; then elif [[ -z "$2" ]]; then
...@@ -37,7 +37,7 @@ function set_merge() { # $1 U $2 (where $1 and $2 are disjoint) ...@@ -37,7 +37,7 @@ function set_merge() { # $1 U $2 (where $1 and $2 are disjoint)
fi fi
} }
function set_union() { # $1 U $2 (sorted) set_union() { # $1 U $2 (sorted)
local -a operand1=($1) local -a operand1=($1)
local -a operand2=($2) local -a operand2=($2)
local -A members local -A members
...@@ -49,7 +49,7 @@ function set_union() { # $1 U $2 (sorted) ...@@ -49,7 +49,7 @@ function set_union() { # $1 U $2 (sorted)
} }
# unique id for a module # unique id for a module
function unique_id() { # $1: module info index unique_id() { # $1: module info index
local -a minfo=( ${modlist[$1]} ) local -a minfo=( ${modlist[$1]} )
if (( ${#minfo[@]} < 4 )); then if (( ${#minfo[@]} < 4 )); then
echo ${minfo[0]} echo ${minfo[0]}
...@@ -58,7 +58,7 @@ function unique_id() { # $1: module info index ...@@ -58,7 +58,7 @@ function unique_id() { # $1: module info index
fi fi
} }
function mod_path() { # $1: module info index mod_path() { # $1: module info index
local -i i local -i i
local -a m=(${modlist[$1]}) local -a m=(${modlist[$1]})
local res="$PMODULES_ROOT/${fmmap[${m[0]%%/*}]}/${m[0]}" local res="$PMODULES_ROOT/${fmmap[${m[0]%%/*}]}/${m[0]}"
...@@ -68,7 +68,7 @@ function mod_path() { # $1: module info index ...@@ -68,7 +68,7 @@ function mod_path() { # $1: module info index
echo "$res"