#!/usr/lib/buildtool/bt_sh
# $Id: sh_head.in,v 1.26 2003/09/29 18:41:46 jmmv Exp $
# Common header for shell scripts, including shared functions.
#
# buildtool
# Copyright (c) 2003 Julio M. Merino Vidal.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in
#    the documentation and/or other materials provided with the
#    distribution.
# 3. Neither the name of the author nor the names of contributors may
#    be used to endorse or promote products derived from this software
#    without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#

ProgName=${0##*/}
LogName=

ConfigFile=
DefsFile=
DocsFile=
LogicFile=

# -------------------------------------------------------------------------

#
# btcmn_err message
#   Show error message on stderr and exit with error status.
#
btcmn_err() {
    local spaces=$(echo ${ProgName} | sed -e 's/./ /g')

    echo "${ProgName}: $1" 1>&2
    shift
    while [ $# -gt 0 ]; do
        echo "${spaces}  $1"
        shift
    done
    exit 1
}

# -------------------------------------------------------------------------

#
# btcmn_warn message
#   Show warning message on stderr.
#
btcmn_warn() {
    local spaces=$(echo ${ProgName} | sed -e 's/./ /g')

    echo "${ProgName}: $1" 1>&2
    shift
    while [ $# -gt 0 ]; do
        echo "${spaces}  $1"
        shift
    done
}

# -------------------------------------------------------------------------

#
# btcmn_log_start name
#    Open the given log file and add a header to it for the current
#    session.
#
btcmn_log_start() {
    LogName=$1
    [ -f ${LogName} ] && echo >> ${LogName}
    echo "-------------------------------------------------------------------------" >> ${LogName} # NOLINT
    echo "LOG STARTED FOR MODULE ${ProgName} ON $(date)" >> ${LogName}
    echo >> ${LogName}
}

# -------------------------------------------------------------------------

#
# btcmn_log_name
#    Get the current log name.
#
btcmn_log_name() {
    echo ${LogName}
}

# -------------------------------------------------------------------------

#
# btcmn_log_msg text
#    Append the given message to the log file.
#
btcmn_log_msg() {
    echo $* >> ${LogName}
}

# -------------------------------------------------------------------------

#
# btcmn_req_project
#   Check if we are executing Buildtool inside a buildtoolized project.
#   If so, set BT_TOPDIR to its top directory, set all *File variables
#   pointing to the right script, check if the current Buildtool version
#   is enough to work with this project and automatically source the defs
#   block.  The function does not return if the check fails.
#
btcmn_req_project() {
    local major minor oldpwd

    config() {
        btcmn_err "no config() function defined; cannot continue."
    }

    defs() {
        btcmn_err "no defs() function defined; cannot continue."
    }

    docs() {
        btcmn_err "no docs() function defined; cannot continue."
    }

    oldpwd=$(pwd)
    BT_TOPDIR=
    while [ -z "${BT_TOPDIR}" -a $(pwd) != / ]; do
        if [ -f Generic.bt -o -f Defs.bt ]; then
            BT_TOPDIR=$(pwd)
        else
            cd ..
        fi
    done
    [ -z "${BT_TOPDIR}" ] &&
        btcmn_err \
            "this module needs to be run from inside a Buildtool project"

    if [ -f Config.bt ]; then
        ConfigFile=${BT_TOPDIR}/Config.bt
    else
        ConfigFile=${BT_TOPDIR}/Generic.bt
    fi

    if [ -f Defs.bt ]; then
        DefsFile=${BT_TOPDIR}/Defs.bt
    else
        DefsFile=${BT_TOPDIR}/Generic.bt
    fi

    if [ -f Docs.bt ]; then
        DocsFile=${BT_TOPDIR}/Docs.bt
    else
        DocsFile=${BT_TOPDIR}/Generic.bt
    fi

    if [ -f Logic.bt ]; then
        LogicFile=${BT_TOPDIR}/Logic.bt
    else
        LogicFile=${BT_TOPDIR}/Generic.bt
    fi

    cd ${oldpwd}

    [ -f Logic.bt ] && LogicFile=$(pwd)/Logic.bt

    BT_REQUIRE=
    . ${DefsFile}
    defs
    if [ -z "${BT_REQUIRE}" ]; then
        btcmn_err "broken package; does not define BT_REQUIRE"
    fi

    major=$(echo ${BT_REQUIRE} | cut -d . -f 1)
    minor=$(echo ${BT_REQUIRE} | cut -d . -f 2)

    [ ${major} -ne 0 -a ${major} -ne 0 ] && \
        btcmn_err "this package requires the Buildtool ${major}.x branch"
    [ ${minor} -gt 15 ] && \
        btcmn_err "this package requires Buildtool ${BT_REQUIRE}"
}

# -------------------------------------------------------------------------

#
# btcmn_req_config
#   Check for the presence of the config script and source it if found.
#   Does not return if the file is not found.
#
btcmn_req_config() {
    [ ! -f ${ConfigFile} ] && btcmn_err "cannot open ${ConfigFile}"
    config_init() { return 0; }
    config() { return 0; }
    . ${ConfigFile}
}

# -------------------------------------------------------------------------

#
# btcmn_req_defs
#   Check for the presence of the defs script and source it if found.
#   Does not return if the file is not found.
#
btcmn_req_defs() {
    [ ! -f ${DefsFile} ] && btcmn_err "cannot open ${DefsFile}"
    defs() { return 0; }
    . ${DefsFile}
}

# -------------------------------------------------------------------------

#
# btcmn_req_docs
#   Check for the presence of the docs script and source it if found.
#   Does not return if the file is not found.
#
btcmn_req_docs() {
    [ ! -f ${DocsFile} ] && btcmn_err "cannot open ${DocsFile}"
    docs() { return 0; }
    . ${DocsFile}
}

# -------------------------------------------------------------------------

#
# btcmn_req_logic
#   Check for the presence of the logic script and source it if found.
#   Does not return if the file is not found.
#
btcmn_req_logic() {
    [ ! -f ${LogicFile} ] && btcmn_err "cannot open ${LogicFile}"
    logic() { return 0; }
    . ${LogicFile}
}

# -------------------------------------------------------------------------

#
# btcmn_req_runtime
#   Check if we were executed by the main buildtool wrapper program.
#
btcmn_req_runtime() {
    if [ ${__BUILDTOOL:-no} != yes ]; then
        btcmn_err "this program must be run through Buildtool"
    fi
}

# -------------------------------------------------------------------------

#
# btcmn_run_module module [args]
#   Execute the given module passing all extra arguments to it.
#
btcmn_run_module() {
    local module="$1"; shift

    case ${module} in
        config)
            btcmn_req_project
            __BUILDTOOL=yes /usr/lib/buildtool/bt_sh ${BT_SH_FLAGS} \
                /usr/lib/buildtool/bt_config ${BT_PKG_CONFIG_FLAGS} "$@"
            ;;
        dist)
            btcmn_req_project
            __BUILDTOOL=yes /usr/lib/buildtool/bt_sh ${BT_SH_FLAGS} \
                /usr/lib/buildtool/bt_dist ${BT_PKG_DIST_FLAGS} "$@"
            ;;
        doc)
            btcmn_req_project
            __BUILDTOOL=yes /usr/lib/buildtool/bt_sh ${BT_SH_FLAGS} \
                /usr/lib/buildtool/bt_doc ${BT_PKG_DOC_FLAGS} "$@"
            ;;
        lint)
            btcmn_req_project
            __BUILDTOOL=yes /usr/lib/buildtool/bt_sh ${BT_SH_FLAGS} \
                /usr/lib/buildtool/bt_lint ${BT_PKG_LINT_FLAGS} "$@"
            ;;
        logic)
            btcmn_req_project
            __BUILDTOOL=yes /usr/lib/buildtool/bt_sh ${BT_SH_FLAGS} \
                /usr/lib/buildtool/bt_logic ${BT_PKG_LOGIC_FLAGS} "$@"
            ;;
        pkgflags)
            __BUILDTOOL=yes /usr/lib/buildtool/bt_sh ${BT_SH_FLAGS} \
                /usr/lib/buildtool/bt_pkgflags "$@"
            ;;
        swcgen)
            __BUILDTOOL=yes /usr/lib/buildtool/bt_sh ${BT_SH_FLAGS} \
                /usr/lib/buildtool/bt_swcgen "$@"
            ;;
        wizard)
            __BUILDTOOL=yes /usr/lib/buildtool/bt_sh ${BT_SH_FLAGS} \
                /usr/lib/buildtool/bt_wizard "$@"
            ;;
        *)
            btcmn_err "no such module \`${module}' (internal error)"
            ;;
    esac
}

# -------------------------------------------------------------------------

# Local Variables: ***
# mode: shell-script ***
# End: ***
# vim: syntax=sh
#
# $Id: base.in,v 1.24 2004/02/04 13:32:43 jmmv Exp $
# Base functions.
#
# buildtool
# Copyright (c) 2003, 2004 Julio M. Merino Vidal.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in
#    the documentation and/or other materials provided with the
#    distribution.
# 3. Neither the name of the author nor the names of contributors may
#    be used to endorse or promote products derived from this software
#    without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#

BT_TARGET_DEFS="BT_DEPENDS BT_SUBDIR BT_TARGET_FILE BT_TARGET_NAME BT_TYPE"
BT_TARGET_VARS=
BT_TARGETS=
BT_TYPES=
BT_AUTOTYPES=

: ${BT_RECURSING:=no}

bt_init() {
    bt_load_type convert
    BT_AUTOTYPES+=convert

    if [ -n "${BT_OUTPUT}" ]; then
        bt_load_type output
        BT_AUTOTYPES+=output
    fi
}

bt_load_type() {
    local t="${1}"
    local tmp

    : ${t:=${BT_TYPE}}

    for tmp in ${BT_TYPES}; do
        [ ${tmp} = ${t} ] && return
    done

    if [ ! -f "/usr/share/buildtool/bt_logic/${t}.subr" ]; then
        btcmn_err \
            "cannot load \`${t}' type specification in target \`${BT_TARGET}'"
    fi

    . /usr/share/buildtool/bt_logic/${t}.subr

    bt_register_type ${t}
}

bt_register_type() {
    BT_TYPES+=${1}

    if isfunc ${1}_init; then
        ${1}_init
    fi

    if ! isfunc ${1}_defs; then
        eval "${1}_defs() { return 0; }"
    fi

    for s in ${BT_STAGES}; do
        if ! isfunc ${1}_${s}_is_oodate; then
            eval "${1}_${s}_is_oodate() { return 0; }"
        fi
        if ! isfunc ${1}_${s}; then
            eval "${1}_${s}() { return 0; }"
        fi
    done
}

bt_try_auto() {
    local t

    if [ -d "${BT_TARGET}" ]; then
        btcmn_warn "entering directory \`${BT_TARGET}' for \`${BT_STAGE}'"
        ( cd ${BT_TARGET} && BT_RECURSING=yes \
            /usr/lib/buildtool/bt_logic -s ${BT_STAGE} ) || \
            btcmn_err "\`${BT_STAGE}' failed in \`${BT_TARGET}' directory"
        btcmn_warn "leaving directory \`${BT_TARGET}' for \`${BT_STAGE}'"
        return 1
    fi

    for t in ${BT_AUTOTYPES}; do
        if ${t}_check ${BT_TARGET}; then
            eval "target_${BT_TARGET}() { BT_TYPE='${t}'; }"
            return 0
        fi
    done

    if [ -f "${BT_TARGET}" ]; then
        return 1
    fi

    btcmn_err \
        "no such target \`${BT_TARGET}' (no function \`target_${BT_TARGET}')"
}

bt_check_oodate() {
    [ -z "${BT_DEPENDS}" ] && return 0
    /usr/lib/buildtool/oodate ${BT_TARGET_FILE} ${BT_DEPENDS}
}

bt_target() {
    BT_TARGETS+=$*
}

bt_do_targets() {
    while [ $# -gt 0 ]; do
        [ -n "${LogFile}" ] && \
            echo "===> STAGE: \`${BT_STAGE}', TARGET \`${1}' STARTED" >> \
                ${LogFile}
        bt_do_target ${1}
        [ -n "${LogFile}" ] && \
            echo "===> STAGE: \`${BT_STAGE}', TARGET \`${1}' FINISHED" >> \
                ${LogFile}
        shift
    done
}

bt_do_target() {
    local BT_TARGET=${1}
    local tmp var

    if [ -n "$(echo ${BT_TARGET} | grep /)" ]; then
        if [ -f "${BT_TARGET}" ]; then
            return
        else
            btcmn_err "don't know how to \`${BT_STAGE}' target \`${BT_TARGET}'"
        fi
    fi

    if ! isfunc target_${BT_TARGET}; then
        bt_try_auto || return
    fi

    # Clear all target definitions and set values for the current target.
    for var in ${BT_TARGET_DEFS}; do
        local ${var}
        eval ${var}=\"\"
    done
    for var in ${BT_TARGET_VARS}; do
        local ${var}
    done
    target_${BT_TARGET}

    eval tmp=\"\${BT_NO_$(echo ${BT_STAGE} | swcase -u)}\"
    [ "${tmp}" = yes ] && return

    : ${BT_TYPE:=null}
    : ${BT_TARGET_FILE:=${BT_TARGET}}
    : ${BT_TARGET_NAME:=${BT_TARGET}}

    bt_load_type ${BT_TYPE}
    ${BT_TYPE}_defs

    if [ -n "${BT_SUBDIR}" ]; then
        btcmn_warn "entering directory \`${BT_SUBDIR}' for \`${BT_STAGE}'"
        cd ${BT_SUBDIR}
    fi

    [ -n "${BT_DEPENDS}" ] && bt_do_targets ${BT_DEPENDS}

    if [ "${BT_PHONY}" = yes ] || bt_check_oodate; then
        if isfunc target_${BT_TARGET}_pre_${BT_STAGE}; then
            target_${BT_TARGET}_pre_${BT_STAGE}
        fi

        if isfunc target_${BT_TARGET}_${BT_STAGE}; then
            target_${BT_TARGET}_${BT_STAGE}
        else
            ${BT_TYPE}_${BT_STAGE}
        fi

        if isfunc target_${BT_TARGET}_post_${BT_STAGE}; then
            target_${BT_TARGET}_post_${BT_STAGE}
        fi
    fi

    if [ -n "${BT_SUBDIR}" ]; then
        btcmn_warn "leaving directory \`${BT_SUBDIR}' for \`${BT_STAGE}'"
        cd -
    fi
}

# Local Variables: ***
# mode: shell-script ***
# End: ***
# vim: syntax=sh
#
# $Id: cmds.in,v 1.6 2003/09/23 16:40:24 jmmv Exp $
# Functions to indirectly call system commands.
#
# buildtool
# Copyright (c) 2003 Julio M. Merino Vidal.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in
#    the documentation and/or other materials provided with the
#    distribution.
# 3. Neither the name of the author nor the names of contributors may
#    be used to endorse or promote products derived from this software
#    without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#

bt_die() {
    btcmn_err "\`${BT_STAGE}' stopped; command exited with error status \`$?'"
}

bt_exec() {
    [ -n "${LogFile}" ] && echo "[exec] $*" >> ${LogFile}
    echo "[exec] $*"
    $* || bt_die
}

bt_remove() {
    [ -n "${LogFile}" ] && echo "[remove] $*" >> ${LogFile}
    echo "[remove] $*"
    rm -f $*
}

# Local Variables: ***
# mode: shell-script ***
# End: ***
# vim: syntax=sh
#
# $Id: compile.in,v 1.39 2004/02/03 22:59:10 jmmv Exp $
# C/C++ code compilation functions.
#
# buildtool
# Copyright (c) 2003, 2004 Julio M. Merino Vidal.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in
#    the documentation and/or other materials provided with the
#    distribution.
# 3. Neither the name of the author nor the names of contributors may
#    be used to endorse or promote products derived from this software
#    without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#

BT_TARGET_VARS+="BT_FLAGS_CPP BT_FLAGS_CC BT_FLAGS_CXX"

btown_compile_parse_args() {
    local arg=
    local res=
    local obj= src=
    local flags_D= flags_I= flags_O= flags_W= flags_other= flags_unknown=

    [ -n "${LogFile}" ] && echo "[compile: original call] $*" >> ${LogFile}

    while [ $# -gt 0 ]; do
        arg=$(echo ${1} | sed -e 's|"|\\"|g')
        case ${arg} in
            -D*)
                flags_D+=${arg}
                ;;

            -I*)
                arg=$(echo ${arg} | sed -e s/-I//)
                [ -d ${arg} ] && flags_I="${flags_I} -I$(cd ${arg} && pwd)"
                ;;

            -L*|-l*|-Wl*)
                ;;

            -O*)
                flags_O+=${arg}
                ;;

            -W*)
                flags_W+=${arg}
                ;;

            -c)
                ;;

            -g)
                flags_other+=${arg}
                ;;

            -o)
                obj=${2}; shift
                ;;

            *)
                if echo ${arg} | grep '^-' >/dev/null; then
                    btcmn_warn "compile: passing unhandled option \`${arg}'"
                    flags_unknown+=${arg}
                else
                    src=${arg}
                fi
                ;;
        esac
        shift
    done

    if echo ${obj} | grep '.po$' >/dev/null; then
        flags_other+=${BT_LIB_PIC_COMPILE_PREARGS}
    fi

    res="${flags_D} ${flags_I} ${flags_W} ${flags_O} ${flags_other} ${flags_unknown} -o ${obj} -c ${src}" # NOLINT
    [ -n "${LogFile}" ] && \
        echo "[compile: call rewrote as] ${res}" >> ${LogFile}
    echo ${res}
}

bt_compile_c() {
    local cmd

    [ -z ${BT_PROG_CC} ] && btcmn_err \
        "compile: no C compiler available (BT_PROG_CC is not set)" \
        "         add a call to bt_check_env_c in your config script"

    cmd="${BT_PROG_CC} $(btown_compile_parse_args $*)"
    echo "[compile] ${cmd}"
    ${cmd} || bt_die
}

bt_compile_cxx() {
    local cmd

    [ -z ${BT_PROG_CXX} ] && btcmn_err \
        "compile: no C++ compiler available (BT_PROG_CXX is not set)" \
        "         add a call to bt_check_env_c in your config script"

    cmd="${BT_PROG_CXX} $(btown_compile_parse_args $*)"
    echo "[compile] ${cmd}"
    ${cmd} || bt_die
}

# Local Variables: ***
# mode: shell-script ***
# End: ***
# vim: syntax=sh
#
# $Id: docs.in,v 1.6 2004/02/03 22:59:10 jmmv Exp $
# Functions to handle package documents.
#
# buildtool
# Copyright (c) 2003, 2004 Julio M. Merino Vidal.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in
#    the documentation and/or other materials provided with the
#    distribution.
# 3. Neither the name of the author nor the names of contributors may
#    be used to endorse or promote products derived from this software
#    without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#

BT_DOCS=
BT_INSTALL_DOCS=yes

bt_doc() {
    BT_DOCS+=${1}
}

bt_deinstall_docs() {
    local f

    [ ${BT_INSTALL_DOCS} = no ] && return

    for f in ${BT_DOCS}; do
        bt_remove ${BT_DIR_DOC}/${f}
    done
    rmdir -p ${BT_DIR_DOC} >/dev/null 2>&1 || true
}

bt_install_docs() {
    local f

    [ ${BT_INSTALL_DOCS} = no ] && return

    bt_install_dir ${BT_DIR_DOC}
    for f in ${BT_DOCS}; do
        bt_install_data ${f} ${BT_DIR_DOC}
    done
}

# Local Variables: ***
# mode: shell-script ***
# End: ***
# vim: syntax=sh
#
# $Id: install.in,v 1.22 2003/09/26 17:03:33 jmmv Exp $
# Generic install functions.
#
# buildtool
# Copyright (c) 2003 Julio M. Merino Vidal.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in
#    the documentation and/or other materials provided with the
#    distribution.
# 3. Neither the name of the author nor the names of contributors may
#    be used to endorse or promote products derived from this software
#    without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#

btown_install_parse_args() {
    local group mode owner

    group="${1}"; mode="${2}"; owner="${3}"; shift 3

    while [ $# -gt 0 ]; do
        case ${1} in
            -g)
                group=${2}; shift
                ;;
            -m)
                mode=${2}; shift
                ;;
            -o)
                owner=${2}; shift
                ;;
            *)
                if echo ${1} | grep '^-' >/dev/null; then
                    btcmn_err "install: unknown option \`${1}'"
                else
                    break
                fi
                ;;
        esac
        shift
    done

    echo ${group} ${mode} ${owner} $*
}

btown_install_files() {
    local dir f msg srcs target

    msg=${1}; shift

    if [ $# -eq 2 ]; then
        if [ -d ${2} ]; then
            target=${2}/${1##*/}
        else
            target=${2}
        fi
        echo "[install] installing ${msg} file ${target}"
        cp -f ${1} ${target} || bt_die
        chmod ${mode} ${target} || bt_die
        if [ ${owner} != DEFAULT ]; then
            chown ${owner} ${target} || bt_die
        fi
        if [ ${group} != DEFAULT ]; then
            chgrp ${group} ${target} || bt_die
        fi
    else
        srcs=
        while [ $# -gt 1 ]; do
            srcs+=${1}
            shift
        done
        dir="${1}"

        [ ! -d "${dir}" ] && \
            btcmn_err "install: last argument must be a directory"

        for f in ${srcs}; do
            target=${dir}/${f##*/}
            echo "[install] installing ${msg} file ${target}"
            cp -f ${f} ${target} || bt_die
            chmod ${mode} ${target} || bt_die
            if [ ${owner} != DEFAULT ]; then
                chown ${owner} ${target} || bt_die
            fi
            if [ ${group} != DEFAULT ]; then
                chgrp ${group} ${target} || bt_die
            fi
        done
    fi
}

bt_install_bin() {
    local group mode owner

    set -- $(btown_install_parse_args ${BT_BIN_GROUP} ${BT_BIN_MODE} \
        ${BT_BIN_OWNER} $*)

    group="${1}"; mode="${2}"; owner="${3}"; shift 3

    btown_install_files binary $*
}

bt_install_data() {
    local group mode owner

    set -- $(btown_install_parse_args ${BT_DATA_GROUP} ${BT_DATA_MODE} \
        ${BT_DATA_OWNER} $*)

    group="${1}"; mode="${2}"; owner="${3}"; shift 3

    btown_install_files data $*
}

bt_install_dir() {
    local group mode owner

    set -- $(btown_install_parse_args ${BT_DIR_GROUP} ${BT_DIR_MODE} \
        ${BT_DIR_OWNER} $*)

    group="${1}"; mode="${2}"; owner="${3}"; shift 3

    while [ $# -gt 0 ]; do
        if [ ! -d ${1} ]; then
            echo "[install] creating missing directory ${1}"
            mkdir -p ${1} || bt_die
            chmod ${mode} ${1} || bt_die
            if [ ${owner} != DEFAULT ]; then
                chown ${owner} ${1} || bt_die
            fi
            if [ ${group} != DEFAULT ]; then
                chgrp ${group} ${1} || bt_die
            fi
        fi
        shift
    done
}

bt_install_symlink() {
    bt_exec ln -fs $* || bt_die
}

# Local Variables: ***
# mode: shell-script ***
# End: ***
# vim: syntax=sh
#
# $Id: link.in,v 1.47 2004/02/03 22:59:10 jmmv Exp $
# C/C++ object linking functions.
#
# buildtool
# Copyright (c) 2003, 2004 Julio M. Merino Vidal.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in
#    the documentation and/or other materials provided with the
#    distribution.
# 3. Neither the name of the author nor the names of contributors may
#    be used to endorse or promote products derived from this software
#    without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#

BT_TARGET_VARS+="BT_FLAGS_LD BT_LIBS"

btown_link_parse_args() {
    local arg=
    local res=
    local archives= libs= objs= targets=
    local dirs_libs= dirs_rpath=
    local flags_L= flags_other= flags_rpath= flags_unknown=
    local shared=no

    [ -n "${LogFile}" ] && echo "[link: original call] $*" >> ${LogFile}

    while [ $# -gt 0 ]; do
        arg=$(echo ${1} | sed -e 's|"|\\"|g')
        case ${arg} in
            -L*)
                arg=$(echo ${arg} | sed -e s/-L//)
                if [ -d ${arg} ]; then
                    arg=$(cd ${arg} && pwd)
                    flags_L+=-L${arg}
                    dirs_libs+=${arg}
                    dirs_rpath+=${arg}
                fi
                ;;

            -Wl,-r*|-Wl,-R*|-rpath=*)
                arg=$(echo ${arg} | sed -e s/-Wl,-r// -e s/-Wl,-R// \
                    -e s/-rpath=//)
                [ -d ${arg} ] && arg=$(cd ${arg} && pwd)
                dirs_rpath+=${arg}
                ;;

            -export-dynamic)
                flags_other+=${BT_LIB_FLAG_EXPORTDYNAMIC}
                ;;

            -l*)
                if [ ${BT_LIB_MKPIC} = yes ]; then
                    libs+=${arg}
                else
                    local d found=no
                    arg=$(echo ${arg} | sed -e s/-l//)
                    for d in ${dirs_libs}; do
                        if [ -f ${d}/lib${arg}.a ]; then
                            archives+=${d}/lib${arg}.a
                            found=yes
                            break
                        fi
                    done
                    [ ${found} = no ] && libs="${libs} ${arg}"
                fi
                ;;

            -o)
                target=${2}; shift
                ;;

            -shared)
                shared=yes
                ;;

            -soname=*)
                arg=$(echo ${arg} | sed -e 's/-soname=//')
                if [ ${BT_LIB_PIC_SONAME} = yes ]; then
                    flags_other="-Wl,-soname=${arg}"
                fi
                shared=yes
                ;;

            *)
                if echo ${arg} | grep '^-' >/dev/null; then
                    btcmn_warn "link: passing unhandled option \`${arg}'"
                    flags_unknown+=${arg}
                elif echo ${arg} | grep '.a$' >/dev/null; then
                    archives+=${arg}
                else
                    objects+=${arg}
                fi
                ;;
        esac
        shift
    done

    if [ ${BT_FEATURE_RPATH} = yes ]; then
        local d
        for d in ${BT_DIR_LIB} ${dirs_rpath}; do
            flags_rpath+=${BT_LINK_FLAG_RPATH}${d}
        done
    fi

    if [ ${shared} = yes ]; then
        flags_other="-shared ${flags_other}"
    fi

    res="${flags_L} ${flags_rpath} ${flags_other} ${flags_unknown} -o ${target} ${objects} ${archives} ${libs}" # NOLINT
    [ -n "${LogFile}" ] && echo "[link: call rewrote as] ${res}" >> ${LogFile}
    echo ${res}
}

bt_link_c() {
    local cmd

    [ -z ${BT_PROG_CC} ] && btcmn_err \
        "link: no C linker available (BT_PROG_CC is not set)" \
        "      add a call to bt_check_env_c in your config script"

    cmd="${BT_PROG_CC} $(btown_link_parse_args $*)"
    echo "[link] ${cmd}"
    ${cmd} || bt_die
}

bt_link_cxx() {
    local cmd

    [ -z ${BT_PROG_CXX} ] && btcmn_err \
        "link: no C++ linker available (BT_PROG_CXX is not set)" \
        "      add a call to bt_check_env_c in your config script"

    cmd="${BT_PROG_CXX} $(btown_link_parse_args $*)"
    echo "[link] ${cmd}"
    ${cmd} || bt_die
}

# Local Variables: ***
# mode: shell-script ***
# End: ***
# vim: syntax=sh
#
# $Id: stages.in,v 1.13 2004/02/04 13:32:44 jmmv Exp $
# Standard stage definitions.
#
# buildtool
# Copyright (c) 2003, 2004 Julio M. Merino Vidal.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in
#    the documentation and/or other materials provided with the
#    distribution.
# 3. Neither the name of the author nor the names of contributors may
#    be used to endorse or promote products derived from this software
#    without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#

BT_STAGES="build clean cleandir deinstall install"
BT_TARGET_DEFS="${BT_TARGET_DEFS} BT_NO_BUILD BT_NO_CLEAN BT_NO_CLEANDIR \
                BT_NO_DEINSTALL BT_NO_INSTALL"

pre_build() { return 0; }
post_build() { return 0; }
pre_clean() { return 0; }
post_clean() { return 0; }
pre_cleandir() { return 0; }
post_cleandir() { return 0; }
pre_deinstall() { return 0; }
post_deinstall() { return 0; }
pre_install() { return 0; }
post_install() { return 0; }

build() {
    local BT_STAGE=build BT_PHONY=no

    pre_build
    bt_do_targets $*
    post_build
}

clean() {
    local BT_STAGE=clean BT_PHONY=yes

    pre_clean
    bt_do_targets $*
    post_clean
}

cleandir() {
    local BT_STAGE=cleandir BT_PHONY=yes

    [ ${BT_RECURSING} = no ] && clean $*

    pre_cleandir
    bt_do_targets $*
    post_cleandir

    [ $(pwd) = ${BT_TOPDIR} -a -z "${_BT_CMDTARGETS}" ] && \
        bt_remove ${BT_FILES_CLEANDIRTOP}
    [ -n "${LogFile}" ] && bt_remove ${LogFile}
}

deinstall() {
    local BT_STAGE=deinstall BT_PHONY=yes

    pre_deinstall
    bt_do_targets $*
    post_deinstall

    [ $(pwd) = ${BT_TOPDIR} ] && bt_deinstall_docs
}

install() {
    local BT_STAGE=install BT_PHONY=yes

    [ ${BT_RECURSING} = no ] && build $*

    pre_install
    bt_do_targets $*
    post_install

    [ $(pwd) = ${BT_TOPDIR} ] && bt_install_docs
}

# Local Variables: ***
# mode: shell-script ***
# End: ***
# vim: syntax=sh
#
# $Id: frontend.in,v 1.36 2004/02/04 13:32:44 jmmv Exp $
# bt_logic's frontend.
#
# buildtool
# Copyright (c) 2003, 2004 Julio M. Merino Vidal.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in
#    the documentation and/or other materials provided with the
#    distribution.
# 3. Neither the name of the author nor the names of contributors may
#    be used to endorse or promote products derived from this software
#    without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#

usage() {
    local exitstatus=${1}
    local detailed=${2}

    [ ${detailed} = yes ] && echo "buildtool version 0.15" 1>&2

    echo "usage: ${ProgName} [extra opts] {-s ,--stage=}name" \
        "[target1 ... targetN]" 1>&2

    if [ ${detailed} = yes ]; then
        cat 1>&2 <<EOF

Available options:
    {-f |--file=}file       Set script name.
    {-l |--logfile=}file    Set log file name and enable logging.
    {-h|--help}             Show this help message.
    {-s |--stage=}name      Specifiy stage to be executed.

See buildtool(1) for more information.
EOF
    fi

    exit ${exitstatus}
}

main() {
    btcmn_req_runtime

    scrfile=
    LogFile=
    Stage=

    while [ $# -gt 0 ]; do
        [ -z "$(echo ${1} | grep ^-)" ] && break

        case "${1}" in
            -f)
                if echo ${2} | grep / >/dev/null; then
                    scrfile="./${2}"
                else
                    scrfile="${2}"
                fi
                shift
                ;;
            --file=*)
                arg=$(echo ${1} | sed -e 's|--file=||')
                if echo ${arg} | grep / >/dev/null; then
                    scrfile="./${arg}"
                else
                    scrfile="${arg}"
                fi
                ;;
            -h|--help)
                usage 0 yes
                ;;
            -l)
                LogFile="${2}"; shift
                ;;
            --logfile=*)
                LogFile=$(echo ${1} | sed -e 's|--logfile=||')
                ;;
            -s)
                Stage="${2}"; shift
                ;;
            --stage=*)
                Stage=$(echo ${1} | sed -e 's|--stage=||')
                ;;
            --)
                shift; break
                ;;
            *)
                btcmn_warn "unknown option \`${1}'"
                usage 1 no
                ;;
        esac
        shift
    done

    btcmn_req_project

    [ -n "${scrfile}" ] && LogicFile="${scrfile}"

    if [ ! -f "${BT_TOPDIR}/bt_config.env" ]; then
        btcmn_err "the package is not configured (use \`buildtool config')"
    fi
    . ${BT_TOPDIR}/bt_config.env

    bt_init

    btcmn_req_docs
    btcmn_req_logic

    [ ${BT_FEATURE_DEVELOPER} = yes -a -z "${LogFile}" ] && \
        LogFile=.bt_logic.log

    docs
    logic

    _BT_CMDTARGETS="$*"
    if [ $# -gt 0 ]; then
        BT_TARGETS=
        bt_target $*
    fi

    if ! isfunc ${Stage}; then
        btcmn_warn "unknown stage \`${Stage}'"
    else
        if [ -n "${LogFile}" ]; then
            [ -f "${LogFile}" ] && echo >> ${LogFile}
            echo "---------------------------------------------------------------------------" >> ${LogFile} # NOLINT
            echo "bt_logic session started at $(date)" >> ${LogFile}
            echo >> ${LogFile}
        fi
        eval ${Stage} ${BT_TARGETS}
    fi

    return 0
}

# Local Variables: ***
# mode: shell-script ***
# End: ***
# vim: syntax=sh
#
# $Id: sh_tail.in,v 1.3 2003/09/23 16:40:23 jmmv Exp $
# Common footer for shell scripts.
#
# buildtool
# Copyright (c) 2003 Julio M. Merino Vidal.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in
#    the documentation and/or other materials provided with the
#    distribution.
# 3. Neither the name of the author nor the names of contributors may
#    be used to endorse or promote products derived from this software
#    without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#

main "$@"

# Local Variables: ***
# mode: shell-script ***
# End: ***
# vim: syntax=sh
