# # $Id: base.in,v 1.30 2004/05/13 18:24:36 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_FIX_PATHS BT_SUBDIR BT_TARGET_FILE BT_TYPE" BT_TARGETS= BT_TYPES= bt_init() { local t for t in ${BT_AUTOTYPES}; do bt_load_type ${t} done for t in ${BT_STAGES}; do BT_TARGET_DEFS+=BT_NO_$(echo ${t} | swcase -u) done } bt_load_type() { local type="${1}" tmp for tmp in ${BT_TYPES}; do [ ${tmp} = ${type} ] && return done [ -f "@DIR_SHARE@/bt_logic/${type}.subr" ] || btcmn_err "cannot load \`${type}' type specification" . @DIR_SHARE@/bt_logic/${type}.subr bt_register_type ${type} } bt_register_type() { local stage type="${1}" BT_TYPES+=${type} isfunc ${type}_init && ${type}_init isfunc ${type}_defs || eval "${type}_defs() { true; }" isfunc ${type}_check || eval "${type}_check() { false; }" for stage in ${BT_STAGES}; do isfunc ${type}_${stage} || eval "${type}_${stage}() { true; }" done } bt_is_oodate() { local stage="${1}" phony="${2}" target="${3}" local dep res res=1 for dep in ${BT_DEPENDS}; do bt_do_target ${stage} ${phony} ${dep} ${BT_TARGET_FILE} && res=0 done if [ ${phony} = yes ] || [ ! -f ${BT_TARGET_FILE} ]; then res=0 fi return ${res} } bt_fix_paths() { local f new values [ ${BT_TOPDIR} = ${BT_WORKDIR} ] && return 0 set -- ${BT_FIX_PATHS} while [ $# -gt 0 ]; do eval values=\"\$$1\" new= for f in ${values}; do if [ -f ${f} ]; then new+=${f} elif [ -f ${BT_SRCDIR}/${f} ]; then new+=${BT_SRCDIR}/${f} else new+=${f} fi done eval $1=\'${new}\' shift done } bt_enter_obj() { BT_SRCDIR=$(pwd) BT_OBJDIR=${BT_WORKDIR}/${BT_SRCDIR##${BT_TOPDIR}} if [ ! -d ${BT_OBJDIR} ]; then mkdir -p ${BT_OBJDIR} btcmn_warn "created object directory ${BT_OBJDIR}" fi cd ${BT_OBJDIR} } bt_leave_obj() { cd ${BT_SRCDIR} } bt_target() { while [ ${#} -gt 0 ]; do BT_TARGETS+=${1} shift done } bt_try_auto() { local stage="${1}" phony="${2}" target="${3}" dependent="${4}" if [ -d ${BT_SRCDIR}/${target} ]; then btcmn_warn "entering directory \`${target}' for \`${stage}'" ( cd ${BT_SRCDIR}/${target} && @DIR_MODS@/bt_logic \ --destdir=${BT_DESTDIR} -w ${BT_WORKDIR} -s ${stage} ) #btcmn_err "\`${stage}' failed in \`${target}' directory" res=$? btcmn_warn "leaving directory \`${target}' for \`${stage}'" return ${res} elif echo ${target} | grep / >/dev/null 2>&1; then oodate ${dependent} ${target} return fi local type for type in ${BT_AUTOTYPES}; do if ${type}_check ${target}; then eval "target_${target}() { BT_TYPE='${type}'; }" return fi done if [ ! -f ${BT_SRCDIR}/${target} ]; then btcmn_err "don't know how to \`${stage}' target \`${target}'" else oodate ${dependent} ${target} fi } # Returns 0 if some target was remade; 1 otherwise. bt_do_target() { local stage="${1}" phony="${2}" target="${3}" dependent="${4}" local oldpwd= res t tmp var if ! isfunc target_${target}; then bt_try_auto $* res=$? isfunc target_${target} || return ${res} fi for var in ${BT_TARGET_DEFS}; do local ${var} eval ${var}=\"\" done for var in ${BT_TARGET_VARS}; do local ${var} done BT_TARGET_FILE="${target}" target_${target} eval tmp=\"\${BT_NO_$(echo ${stage} | swcase -u)}\" [ "${tmp}" = yes ] && return 1 : ${BT_TYPE:=null} if [ -n "${BT_SUBDIR}" ]; then btcmn_warn "entering directory \`${BT_SUBDIR}' for \`${stage}'" olddir=$(pwd) cd ${BT_SUBDIR} bt_enter_obj fi bt_load_type ${BT_TYPE} ${BT_TYPE}_defs ${target} bt_fix_paths res=1 if bt_is_oodate ${stage} ${phony} ${target}; then isfunc target_${target}_pre_${stage} && target_${target}_pre_${stage} if isfunc target_${target}_${stage}; then target_${target}_${stage} else ${BT_TYPE}_${stage} fi isfunc target_${target}_post_${stage} && target_${target}_post_${stage} res=0 fi if [ -n "${BT_SUBDIR}" ]; then btcmn_warn "leaving directory \`${BT_SUBDIR}' for \`${stage}'" bt_leave_obj cd ${olddir} fi return ${res} } bt_run_hooks() { local var="${1}" local f funcs eval funcs=\"\$${var}\" for f in ${funcs}; do ${f} done } bt_source_depends() { local dep obj src for src in ${*}; do if [ ${BT_LIB_MKPIC} = yes ]; then obj=$(echo ${src} | sed -e 's|\.c$|.po|' -e 's|\.cpp$|.po|' \ -e 's|\.cc$|.po|') else obj=$(echo ${src} | sed -e 's|\.c$|.o|' -e 's|\.cpp$|.o|' \ -e 's|\.cc$|.o|') fi dep=$(echo ${src} | sed -e 's|\.c$|.dep|' -e 's|\.cpp$|.dep|' \ -e 's|\.cc$|.dep|') eval "target_${dep}() { BT_TYPE=depend; BT_SOURCES='${src}'; }" eval "target_${obj}() { BT_TYPE=convert; }" BT_DEPENDS+="${dep} ${obj}" BT_OBJECTS+=${obj} done BT_FIX_PATHS+=BT_SOURCES } # Local Variables: *** # mode: shell-script *** # End: *** # vim: syntax=sh