Commit 180de2f4 authored by gsell's avatar gsell

Bootstrap:

- new command 'modbuild' to build modules
- separate bootstrapping from other build-blocks
- review BASH libraries
- adapt build-blocks in bootstrapping
parent 2cdf1f15
#!/usr/bin/env pbuild #!/usr/bin/env modbuild
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}"
pmodules.configure() { pbuild::configure() {
case ${OS} in case ${OS} in
Linux ) Linux )
declare -x LIBS="-lz -lpthread" declare -x LIBS="-lz -lpthread"
...@@ -23,7 +23,7 @@ pmodules.configure() { ...@@ -23,7 +23,7 @@ pmodules.configure() {
|| exit 1 || exit 1
} }
pmodules.post_install() { pbuild::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
...@@ -45,8 +45,8 @@ module() { ...@@ -45,8 +45,8 @@ module() {
# use system gcc to compile # use system gcc to compile
declare -rx CC=gcc declare -rx CC=gcc
pmodules.add_to_group 'Tools' pbuild::add_to_group 'Tools'
pmodules.make_all pbuild::make_all
# Local Variables: # Local Variables:
# mode: sh # mode: sh
......
...@@ -12,10 +12,6 @@ if [[ -z ${BUILD_BLOCK} ]]; then ...@@ -12,10 +12,6 @@ if [[ -z ${BUILD_BLOCK} ]]; then
declare -r BUILD_BLOCK="${BUILD_BLOCK_DIR}"/$(basename "$0") declare -r BUILD_BLOCK="${BUILD_BLOCK_DIR}"/$(basename "$0")
fi fi
declare -rx SHLIBDIR=$( cd $(dirname "$BASH_SOURCE") && pwd )
source "${SHLIBDIR}/lib.bash"
declare -rx BUILD_BASEDIR=$(std::abspath "${SHLIBDIR}/..")
PATH=/usr/bin:/bin:/usr/sbin:/sbin PATH=/usr/bin:/bin:/usr/sbin:/sbin
...@@ -27,19 +23,16 @@ if [[ "${OS}" == "Darwin" ]]; then ...@@ -27,19 +23,16 @@ if [[ "${OS}" == "Darwin" ]]; then
fi fi
# number of parallel make jobs # number of parallel make jobs
declare -i JOBS=3 declare -i JOBS=3
source "$(readlink ${BUILD_BASEDIR}/config/environment.bash)"
declare -xr BUILD_CONFIGDIR="${BUILD_BASEDIR}/config" declare -xr BUILD_CONFIGDIR="${BUILD_BASEDIR}/config"
declare -xr BUILD_SCRIPTSDIR="${BUILD_BASEDIR}/scripts" declare -xr BUILD_SCRIPTSDIR="${BUILD_BASEDIR}/scripts"
declare -xr BUILD_TMPDIR="${BUILD_BASEDIR}/tmp" declare -xr BUILD_TMPDIR="${BUILD_BASEDIR}/tmp"
declare -xr BUILD_DOWNLOADSDIR="${BUILD_BASEDIR}/Downloads" declare -xr BUILD_DOWNLOADSDIR="${BUILD_BASEDIR}/Downloads"
declare -xr BUILD_VERSIONSFILE="${BUILD_CONFIGDIR}/versions.conf" declare -xr BUILD_VERSIONSFILE="${BUILD_CONFIGDIR}/versions.conf"
source "${BUILD_CONFIGDIR}/Pmodules.conf" #source "${BUILD_CONFIGDIR}/Pmodules.conf"
declare -x PREFIX='' declare -x PREFIX=''
declare -x DOCDIR='' declare -x DOCDIR=''
...@@ -688,7 +681,8 @@ check_compiler() { ...@@ -688,7 +681,8 @@ check_compiler() {
std::die 0 "Package cannot be build with ${COMPILER}/${COMPILER_VERSION}." std::die 0 "Package cannot be build with ${COMPILER}/${COMPILER_VERSION}."
} }
# unfortunatelly we need sometime an OS depended post-install
# unfortunatelly sometime we need an OS depended post-install
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
...@@ -715,7 +709,7 @@ pbuild::make_all() { ...@@ -715,7 +709,7 @@ pbuild::make_all() {
setup_env2_bootstrap setup_env2_bootstrap
fi fi
if [[ ! -d "${PREFIX}" ]] || [[ ${force_rebuild} == 'yes' ]]; then if [[ ! -d "${PREFIX}" ]] || [[ ${force_rebuild} == 'yes' ]] || [[ ${bootstrap} == 'yes' ]]; then
building='yes' building='yes'
echo "Building $P/$V ..." echo "Building $P/$V ..."
[[ ${dry_run} == yes ]] && std::die 0 "" [[ ${dry_run} == yes ]] && std::die 0 ""
...@@ -747,6 +741,9 @@ pbuild::make_all() { ...@@ -747,6 +741,9 @@ pbuild::make_all() {
cd "${MODULE_BUILDDIR}" cd "${MODULE_BUILDDIR}"
pbuild::install pbuild::install
pbuild::post_install pbuild::post_install
if typeset -F pbuild::post_install_${OS} 1>/dev/null 2>&1; then
pbuild::post_install_${OS} "$@"
fi
pbuild::install_doc pbuild::install_doc
post_install post_install
if [[ ${bootstrap} == 'no' ]]; then if [[ ${bootstrap} == 'no' ]]; then
...@@ -772,81 +769,12 @@ pbuild::make_all() { ...@@ -772,81 +769,12 @@ pbuild::make_all() {
return 0 return 0
} }
#
# legacy functions, should be removed asap
#
pmodules.supported_os() {
pbuild::supported_os "$@"
}
pmodules.add_to_group() {
pbuild::add_to_group "@"
}
pmodules.set_build_dependencies() {
pbuild::set_build_dependencies "$@"
}
pmodules.set_runtime_dependencies() {
pbuild::set_runtime_dependencies "$@"
}
pmodules.set_docfiles() {
pbuild::set_docfiles "$@"
}
pmodules.set_supported_compilers() {
pbuild::set_supported_compilers "$@"
}
pmodules.cleanup_env() {
pbuild::cleanup_env "$@"
}
pmodules.pre_configure() {
pbuild::pre_configure "$@"
}
pmodules.configure() {
pbuild::configure "$@"
}
pmodules.build() {
pbuild::build "$@"
}
pmodules.install() {
pbuild::install "$@"
}
pmodules.post_install() {
pbuild::post_install "$@"
}
pmodules.install_doc() {
pbuild::install_doc "$@"
}
pmodules.cleanup_build() {
pbuild::cleanup_build "$@"
}
pmodules.cleanup_src() {
pbuild::cleanup_src "$@"
}
pmodules.make_all() {
pbuild::make_all "$@"
}
############################################################################## ##############################################################################
# #
debug_on='no' debug_on='no'
force_rebuild='no' force_rebuild='no'
ENVIRONMENT_ARGS='' ENVIRONMENT_ARGS=''
dry_run='no' dry_run='no'
bootstrap='no'
enable_cleanup_build='yes' enable_cleanup_build='yes'
enable_cleanup_src='no' enable_cleanup_src='no'
...@@ -951,8 +879,7 @@ if [[ ${bootstrap} == no ]]; then ...@@ -951,8 +879,7 @@ if [[ ${bootstrap} == no ]]; then
else else
unset PMODULES_HOME unset PMODULES_HOME
unset PMODULES_VERSION unset PMODULES_VERSION
read_versions "${BUILD_BASEDIR}/Bootstrap/Pmodules_version.conf" std::read_versions "${BUILD_BASEDIR}/config/versions.conf"
source "/opt/psi/config/environment.bash"
fi fi
P=$(basename $(dirname "${BUILD_BLOCK}")) P=$(basename $(dirname "${BUILD_BLOCK}"))
......
...@@ -35,121 +35,6 @@ pmodules::check_env() { ...@@ -35,121 +35,6 @@ pmodules::check_env() {
} }
std::log() {
local -ri fd=$1
local -r fmt="$2\n"
shift 2
printf -- "$fmt" "$@" 1>&$fd
}
std::info() {
std::log 2 "$1" "${@:2}"
}
std::error() {
std::log 2 "$1" "${@:2}"
}
std::debug() {
[[ ${PMODULES_DEBUG} ]] || return 0
std::log 2 "$@"
}
std::die() {
local -ri ec=$1
shift
if [[ -n $@ ]]; then
local -r fmt=$1
shift
std::log 2 "$fmt" "$@"
fi
exit $ec
}
#
# get answer to yes/no question
#
# $1: prompt
#
std::get_YN_answer() {
local -r prompt="$1"
local ans
read -p "${prompt}" ans
case ${ans} in
y|Y )
return 0;;
* )
return 1;;
esac
}
#
# return normalized abolute pathname
# $1: filename
std::get_abspath() {
local -r fname=$1
[[ -r "${fname}" ]] || return 1
if [[ -d ${fname} ]]; then
echo $(cd "${fname}" && pwd)
else
local -r dname=$(dirname "${fname}")
echo $(cd "${dname}" && pwd)/$(basename "${fname}")
fi
}
std::append_path () {
local -r P=$1
local -r d=$2
if ! echo ${!P} | egrep -q "(^|:)${d}($|:)" ; then
if [[ -z ${!P} ]]; then
eval $P=${d}
else
eval $P=${!P}:${d}
fi
fi
}
std::prepend_path () {
local -r P=$1
local -r d=$2
if ! echo ${!P} | egrep -q "(^|:)${d}($|:)" ; then
if [[ -z ${!P} ]]; then
eval $P=${d}
else
eval $P=${d}:${!P}
fi
fi
}
std::remove_path() {
local -r P=$1
local -r d=$2
local new_path=''
local -r _P=( ${!P//:/ } )
# loop over all entries in path
for entry in "${_P[@]}"; do
[[ "${entry}" != "${d}" ]] && new_path+=":${entry}"
done
# remove leading ':'
eval ${P}="${new_path:1}"
}
#
# split file name
#
std::split_fname() {
local -r savedIFS="${IFS}"
IFS='/'
local std__split_fname_result__=( $(echo "${@: -1}") )
IFS=${savedIFS}
eval $1=\(\"\${std__split_fname_result__[@]}\"\)
if (( $# >= 3 )); then
eval $2=${#std__split_fname_result__[@]}
fi
}
# Local Variables: # Local Variables:
# mode: sh # mode: sh
# sh-basic-offset: 8 # sh-basic-offset: 8
......
#!/bin/bash
#
# logging/message functions
#
std::log() {
local -ri fd=$1
local -r fmt="$2\n"
shift 2
printf -- "$fmt" "$@" 1>&$fd
}
std::info() {
std::log 2 "$1" "${@:2}"
}
std::error() {
std::log 2 "$1" "${@:2}"
}
std::debug() {
[[ ${PMODULES_DEBUG} ]] || return 0
std::log 2 "$@"
}
std::die() {
local -ri ec=$1
shift
if [[ -n $@ ]]; then
local -r fmt=$1
shift
std::log 2 "$fmt" "$@"
fi
exit $ec
}
#
# get answer to yes/no question
#
# $1: prompt
#
std::get_YN_answer() {
local -r prompt="$1"
local ans
read -p "${prompt}" ans
case ${ans} in
y|Y )
return 0;;
* )
return 1;;
esac
}
#
# return normalized abolute pathname
# $1: filename
std::get_abspath() {
local -r fname=$1
[[ -r "${fname}" ]] || return 1
if [[ -d ${fname} ]]; then
echo $(cd "${fname}" && pwd)
else
local -r dname=$(dirname "${fname}")
echo $(cd "${dname}" && pwd)/$(basename "${fname}")
fi
}
std::append_path () {
local -r P=$1
local -r d=$2
if ! echo ${!P} | egrep -q "(^|:)${d}($|:)" ; then
if [[ -z ${!P} ]]; then
eval $P=${d}
else
eval $P=${!P}:${d}
fi
fi
}
std::prepend_path () {
local -r P=$1
local -r d=$2
if ! echo ${!P} | egrep -q "(^|:)${d}($|:)" ; then
if [[ -z ${!P} ]]; then
eval $P=${d}
else
eval $P=${d}:${!P}
fi
fi
}
std::remove_path() {
local -r P=$1
local -r d=$2
local new_path=''
local -r _P=( ${!P//:/ } )
# loop over all entries in path
for entry in "${_P[@]}"; do
[[ "${entry}" != "${d}" ]] && new_path+=":${entry}"
done
# remove leading ':'
eval ${P}="${new_path:1}"
}
#
# split file name
#
std::split_fname() {
local -r savedIFS="${IFS}"
IFS='/'
local std__split_fname_result__=( $(echo "${@: -1}") )
IFS=${savedIFS}
eval $1=\(\"\${std__split_fname_result__[@]}\"\)
if (( $# >= 3 )); then
eval $2=${#std__split_fname_result__[@]}
fi
}
std::read_versions() {
local -r fname="$1"
local varname=''
while read _name _version; do
[[ -z ${_name} ]] && continue
[[ -z ${_version} ]] && continue
[[ "${_name:0:1}" == '#' ]] && continue
var_name=$(echo ${_name} | tr [:lower:] [:upper:])_VERSION
# don't set version, if already set
if [[ -z ${!var_name} ]]; then
eval ${var_name}="${_version}"
fi
done < "${fname}"
}
# Local Variables:
# mode: sh
# sh-basic-offset: 8
# tab-width: 8
# End:
#!/bin/bash #!/bin/bash
set -x
declare -r mydir=$(dirname "$0")
declare -r libpbuild='libpbuild.bash'
declare -r libstd='libstd.bash'
declare -r pmodule_environment='environment.bash'
# source BASH library with standard functions
if [[ -r ${mydir}/${libstd} ]]; then
source "${mydir}/${libstd}"
elif [[ -r ${mydir}/../lib/${libstd} ]]; then
source "${mydir}/../lib/${libstd}"
else
echo "Oops: required BASH library '${libstd}' not found" 1>&2
exit 1
fi
declare -rx BUILD_BLOCK=$(std::get_abspath "$1")
declare -rx BUILD_BLOCK_DIR=$(dirname "${BUILD_BLOCK}")
shift 1
# source Pmodule environment configuration
if [[ -r ${mydir}/../config/${pmodule_environment} ]]; then
# we are bootstrapping
source "${mydir}/../config/${pmodule_environment}"
declare -rx BUILD_BASEDIR=$(std::get_abspath "${mydir}/..")
bootstrap='yes'
elif [[ -n ${PMODULES_ROOT} ]] && [[ -n ${PMODULES_CONFIG_DIR} ]] && \
[[ -r ${PMODULES_ROOT}/${PMODULES_CONFIG_DIR}/${pmodule_environment} ]]; then
source ${PMODULES_ROOT}/${PMODULES_CONFIG_DIR}/${pmodule_environment}
declare -rx BUILD_BASEDIR=$(std::get_abspath "${BUILD_BLOCK_DIR}/../../..")
bootstrap='no'
fi
# #
# We need GNU versions of the following utilities. This code works # We need GNU versions of the following utilities. This code works
# well on Linux and Mac OS X with MacPorts. # well on Linux and Mac OS X with MacPorts.
...@@ -54,87 +90,16 @@ std::error_handler() { ...@@ -54,87 +90,16 @@ std::error_handler() {
} }
# #
# logging/message functions # run build
# #
std::log() {
local -ri fd=$1
local -r fmt="$2\n"
shift 2
printf -- "$fmt" "$@" >> /dev/fd/$fd
}
std::info() {
std::log 2 "$1\n" "${@:2}"
}
std::error() {
std::log 2 "$1\n" "${@:2}"
}
std::debug() {
[[ ${PMODULES_DEBUG} ]] || return 0
std::log 2 "$@"
}
std::die() {
local -ri ec=$1
shift
local cout
if (( ec == 0)); then
cout='1'
else
cout='2'
fi
if [[ -n $@ ]]; then
local -r fmt=$1
shift
std::log $cout "$fmt" "$@"
fi
exit $ec
}
std::abspath () {
readlink -f "$1"
}
std::append_path () {
local -r P=$1
local -r d=$2
if ! egrep -q "(^|:)${d}($|:)" <<<${!P} ; then
if [[ -z ${!P} ]]; then
eval $P=${d}
else
eval $P=${!P}:${d}
fi
fi
}
std::prepend_path () {
local -r P=$1
local -r d=$2
if ! egrep -q "(^|:)${d}($|:)" <<<${!P} ; then
if [[ -z ${!P} ]]; then
eval $P=${d}
else
eval $P="${d}:${!P}"
fi
fi
}
read_versions() { if [[ -r ${mydir}/${libpbuild} ]]; then
local -r fname="$1" source "${mydir}/${libpbuild}"
local varname='' elif [[ -r ${mydir}/../lib/${libpbuild} ]]; then
while read _name _version; do source "${mydir}/../lib/${libpbuild}"
[[ -z ${_name} ]] && continue else
[[ -z ${_version} ]] && continue echo "Oops: required BASH library '${libpbuild}' not found" 1>&2
[[ "${_name:0:1}" == '#' ]] && continue exit 1
var_name=$(echo ${_name} | tr [:lower:] [:upper:])_VERSION fi
# don't set version, if already set
if [[ -z ${!var_name} ]]; then
eval ${var_name}="${_version}"
fi
done < "${fname}"
}
source "${BUILD_BLOCK}"
...@@ -12,6 +12,7 @@ declare -r bindir="${prefix}/bin" ...@@ -12,6 +12,7 @@ declare -r bindir="${prefix}/bin"
declare -r libdir="${prefix}/lib" declare -r libdir="${prefix}/lib"
declare -r libexecdir="${prefix}/libexec" declare -r libexecdir="${prefix}/libexec"
source "${libdir}/libstd.bash"
source "${libdir}/libpmodules.bash" source "${libdir}/libpmodules.bash"
PATH="${bindir}:${PATH}" PATH="${bindir}:${PATH}"
......
...@@ -14,6 +14,7 @@ declare -r bindir="${prefix}/bin" ...@@ -14,6 +14,7 @@ declare -r bindir="${prefix}/bin"
declare -r libdir="${prefix}/lib" declare -r libdir="${prefix}/lib"
declare -r libexecdir="${prefix}/libexec" declare -r libexecdir="${prefix}/libexec"
source "${libdir}/libstd.bash"
source "${libdir}/libpmodules.bash" source "${libdir}/libpmodules.bash"
PATH="${bindir}:${PATH}" PATH="${bindir}:${PATH}"
......
#!/usr/bin/env pbuild #!/usr/bin/env modbuild
pmodules.configure() { pbuild::configure() {
case ${OS} in case ${OS} in
Linux ) Linux )
srcdir="${MODULE_SRCDIR}/unix"