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}"
PATH="${TCL_DIR}/bin:${PATH}"
pmodules.configure() {
pbuild::configure() {
case ${OS} in
Linux )
declare -x LIBS="-lz -lpthread"
......@@ -23,7 +23,7 @@ pmodules.configure() {
|| exit 1
}
pmodules.post_install() {
pbuild::post_install() {
rm -v ${PREFIX}/Modules/bin/add.modules
rm -v ${PREFIX}/Modules/bin/mkroot
rm -rfv ${PREFIX}/Modules/modulefiles
......@@ -45,8 +45,8 @@ module() {
# use system gcc to compile
declare -rx CC=gcc
pmodules.add_to_group 'Tools'
pmodules.make_all
pbuild::add_to_group 'Tools'
pbuild::make_all
# Local Variables:
# mode: sh
......
......@@ -12,10 +12,6 @@ if [[ -z ${BUILD_BLOCK} ]]; then
declare -r BUILD_BLOCK="${BUILD_BLOCK_DIR}"/$(basename "$0")
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
......@@ -27,19 +23,16 @@ if [[ "${OS}" == "Darwin" ]]; then
fi
# number of parallel make jobs
declare -i JOBS=3
source "$(readlink ${BUILD_BASEDIR}/config/environment.bash)"
declare -xr BUILD_CONFIGDIR="${BUILD_BASEDIR}/config"
declare -xr BUILD_SCRIPTSDIR="${BUILD_BASEDIR}/scripts"
declare -xr BUILD_TMPDIR="${BUILD_BASEDIR}/tmp"
declare -xr BUILD_DOWNLOADSDIR="${BUILD_BASEDIR}/Downloads"
declare -xr BUILD_VERSIONSFILE="${BUILD_CONFIGDIR}/versions.conf"
source "${BUILD_CONFIGDIR}/Pmodules.conf"
#source "${BUILD_CONFIGDIR}/Pmodules.conf"
declare -x PREFIX=''
declare -x DOCDIR=''
......@@ -688,7 +681,8 @@ check_compiler() {
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() {
cd "${PREFIX}"
# solve multilib problem with LIBRARY_PATH on 64bit Linux
......@@ -715,7 +709,7 @@ pbuild::make_all() {
setup_env2_bootstrap
fi
if [[ ! -d "${PREFIX}" ]] || [[ ${force_rebuild} == 'yes' ]]; then
if [[ ! -d "${PREFIX}" ]] || [[ ${force_rebuild} == 'yes' ]] || [[ ${bootstrap} == 'yes' ]]; then
building='yes'
echo "Building $P/$V ..."
[[ ${dry_run} == yes ]] && std::die 0 ""
......@@ -747,6 +741,9 @@ pbuild::make_all() {
cd "${MODULE_BUILDDIR}"
pbuild::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
post_install
if [[ ${bootstrap} == 'no' ]]; then
......@@ -772,81 +769,12 @@ pbuild::make_all() {
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'
force_rebuild='no'
ENVIRONMENT_ARGS=''
dry_run='no'
bootstrap='no'
enable_cleanup_build='yes'
enable_cleanup_src='no'
......@@ -951,8 +879,7 @@ if [[ ${bootstrap} == no ]]; then
else
unset PMODULES_HOME
unset PMODULES_VERSION
read_versions "${BUILD_BASEDIR}/Bootstrap/Pmodules_version.conf"
source "/opt/psi/config/environment.bash"
std::read_versions "${BUILD_BASEDIR}/config/versions.conf"
fi
P=$(basename $(dirname "${BUILD_BLOCK}"))
......
......@@ -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:
# mode: sh
# 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
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
# well on Linux and Mac OS X with MacPorts.
......@@ -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() {
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}"
}
if [[ -r ${mydir}/${libpbuild} ]]; then
source "${mydir}/${libpbuild}"
elif [[ -r ${mydir}/../lib/${libpbuild} ]]; then
source "${mydir}/../lib/${libpbuild}"
else
echo "Oops: required BASH library '${libpbuild}' not found" 1>&2
exit 1
fi
source "${BUILD_BLOCK}"
......@@ -12,6 +12,7 @@ declare -r bindir="${prefix}/bin"
declare -r libdir="${prefix}/lib"
declare -r libexecdir="${prefix}/libexec"
source "${libdir}/libstd.bash"
source "${libdir}/libpmodules.bash"
PATH="${bindir}:${PATH}"
......
......@@ -14,6 +14,7 @@ declare -r bindir="${prefix}/bin"
declare -r libdir="${prefix}/lib"
declare -r libexecdir="${prefix}/libexec"
source "${libdir}/libstd.bash"
source "${libdir}/libpmodules.bash"
PATH="${bindir}:${PATH}"
......
#!/usr/bin/env pbuild
#!/usr/bin/env modbuild
pmodules.configure() {
pbuild::configure() {
case ${OS} in
Linux )
srcdir="${MODULE_SRCDIR}/unix"
......@@ -15,10 +15,10 @@ pmodules.configure() {
|| exit 1
}
pmodules.post_install() {
pbuild::post_install() {
{ cd "${PREFIX}"/bin && rm -f tclsh && ln -fs tclsh${V%.*} tclsh; };
}
pmodules.add_to_group 'Tools'
pmodules.set_docfiles 'license.terms' 'README'
pmodules.make_all
pbuild::add_to_group 'Tools'
pbuild::set_docfiles 'license.terms' 'README'
pbuild::make_all
#!/usr/bin/env pbuild
#!/usr/bin/env modbuild
pmodules.configure() {
pbuild::configure() {
"${MODULE_SRCDIR}"/configure \
--prefix="${PREFIX}" \
|| exit 1
}
pmodules.add_to_group 'Tools'
pmodules.make_all
pbuild::add_to_group 'Tools'
pbuild::make_all
#!/bin/bash
declare -r BASE_DIR=$(cd "$(dirname $0)/.." && pwd)
declare -r BOOTSTRAP_DIR="${BASE_DIR}/Bootstrap"
source "${BASE_DIR}/lib/lib.bash"
declare -r BOOTSTRAP_DIR=$(dirname "$0")
unset PMODULES_HOME
unset PMODULES_VERSION
read_versions "${BOOTSTRAP_DIR}/Pmodules_version.conf"
source "/opt/psi/config/environment.bash"
source "${BOOTSTRAP_DIR}/Pmodules/libstd.bash"
source "${BOOTSTRAP_DIR}/config/environment.bash"
std::read_versions "${BOOTSTRAP_DIR}/config/versions.conf"
#if [[ -n ${PMODULES_DIR} ]] && [[ "${PMODULES_DIR}" != "/" ]] && [[ -d "${PMODULES_DIR}" ]]; then
# rm -rf "${PMODULES_DIR}"
......@@ -19,7 +18,7 @@ build () {
local -r name="$1"
local -r version="$2"
"${BOOTSTRAP_DIR}/${name}/build" --bootstrap --disable-cleanup "${version}" || \
"${BOOTSTRAP_DIR}/Pmodules/modbuild" "${BOOTSTRAP_DIR}/${name}/build" --disable-cleanup "${version}" || \
std::die 3 "Compiling '${name}' failed!"
}
......
#!/usr/bin/env pbuild
#!/usr/bin/env modbuild
pmodules.configure() {
pbuild::configure() {
"${MODULE_SRCDIR}"/configure \
--prefix="${PREFIX}" \
|| exit 1
}
pmodules.add_to_group 'Tools'
pmodules.make_all
pbuild::add_to_group 'Tools'
pbuild::make_all