# # $Id: general.in,v 1.100 2004/05/14 16:43:09 jmmv Exp $ # Base support functions # # buildtool # Copyright (c) 2002, 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. # Language=c AutoTypes= # -------------------------------------------------------------------- # Main functions # -------------------------------------------------------------------- bt_init() { if [ -z "${BT_PKG_NAME}" -o -z "${BT_PKG_VERSION}" ]; then btcmn_err "defs file not included or misses information" fi BT_TOPDIR=$(pwd) [ ! -d ${BT_WORKDIR} ] && mkdir -p ${BT_WORKDIR} BT_CONFIGH=${BT_WORKDIR}/bt_config.h BT_CONFIGMK=${BT_WORKDIR}/bt_config.mk BT_CONFIGENV=${BT_WORKDIR}/bt_config.env BT_CONFIGSED=${BT_WORKDIR}/bt_config.sed BT_LOGICENV=${BT_WORKDIR}/bt_logic.env BT_OUTPUT=${BT_WORKDIR}/bt_output : ${BT_PATH:=${PATH}} btcmn_log_start ${BT_WORKDIR}/bt_config.log BT_FILES_CLEANDIRTOP="${BT_CONFIGH} ${BT_CONFIGMK} ${BT_CONFIGENV}" BT_FILES_CLEANDIRTOP+="${BT_LOGICENV}" BT_FILES_CLEANDIRTOP+=$(btcmn_log_name) BT_FILES_CLEANDIRTOP+="${BT_CONFIGSED} ${BT_OUTPUT}" BT_FLAGS_CPP="-I. -I${BT_TOPDIR} -I${BT_WORKDIR} ${BT_FLAGS_CPP}" bt_msg "starting configuration for ${BT_PKG_NAME}-${BT_PKG_VERSION}" bt_define BT_PKG_NAME "${BT_PKG_NAME}" bt_define BT_PKG_VERSION "${BT_PKG_VERSION}" bt_define BT_PKG_LICENSE "${BT_PKG_LICENSE}" bt_define BT_PKG_MAINTAINER "${BT_PKG_MAINTAINER}" bt_define BT_PKG_HOMEPAGE "${BT_PKG_HOMEPAGE}" bt_subst BT_PKG_NAME BT_PKG_VERSION BT_PKG_LICENSE bt_subst BT_PKG_MAINTAINER BT_PKG_HOMEPAGE BT_PKG_COMMENT bt_subst BT_TOPDIR BT_WORKDIR bt_subst BT_CONFIGH BT_CONFIGMK BT_CONFIGENV BT_OUTPUT bt_subst BT_PATH : ${BT_BIN_GROUP:=DEFAULT} : ${BT_BIN_MODE:=0555} : ${BT_BIN_OWNER:=DEFAULT} bt_subst BT_BIN_GROUP BT_BIN_MODE BT_BIN_OWNER : ${BT_DATA_GROUP:=DEFAULT} : ${BT_DATA_MODE:=0644} : ${BT_DATA_OWNER:=DEFAULT} bt_subst BT_DATA_GROUP BT_DATA_MODE BT_DATA_OWNER : ${BT_DIR_GROUP:=DEFAULT} : ${BT_DIR_MODE:=0755} : ${BT_DIR_OWNER:=DEFAULT} bt_subst BT_DIR_GROUP BT_DIR_MODE BT_DIR_OWNER local hook for hook in ${BT_INIT_HOOKS}; do ${hook} done } bt_argsinit() { BT_PREFIX=/usr/local bt_subst BT_PREFIX bt_msg_summary 'Prefix is: ${BT_PREFIX}' if [ "${BT_USE_WORKDIR}" = yes ]; then BT_WORKDIR=${BT_TOPDIR}/work.bt else BT_WORKDIR=${BT_TOPDIR} fi bt_dir BIN '${BT_PREFIX}/bin' \ "Where user executables are installed." bt_dir DOC '${BT_PREFIX}/share/doc/${BT_PKG_NAME}' \ "Where package documentation is installed." bt_dir ETC '${BT_PREFIX}/etc' \ "Where system wide configuration files will be searched." bt_dir EXAMPLES \ '${BT_PREFIX}/share/examples/${BT_PKG_NAME}' \ "Where configuration files (between others) are installed." bt_dir INCLUDE '${BT_PREFIX}/include' \ "Where include files (commonly used by C/C++) are installed." bt_dir INFO '${BT_PREFIX}/info' \ "Where info documentation is installed (top level directory)." bt_dir LIB '${BT_PREFIX}/lib' \ "Where shared and static libraries are installed." bt_dir LIBDATA '${BT_PREFIX}/libdata' \ "Where static data related to libraries are installed." bt_dir LIBEXEC '${BT_PREFIX}/libexec' \ "Where executables related to libraries are installed." bt_dir MAN '${BT_PREFIX}/man' \ "Where manual pages are installed (top level directory)." bt_dir PKGFLAGS '/usr/local/share/buildtool/pkgflags' \ "Where package flags files are installed." bt_dir SBIN '${BT_PREFIX}/sbin' \ "Where super-user executables are installed." bt_dir SHARE '${BT_PREFIX}/share' \ "Where machine independant data is installed." bt_dir VAR '${BT_PREFIX}/var' \ "Where variable data will be created." bt_feature SHARED auto \ "Whether shared libraries are built (yes, no, auto)." bt_feature STATIC auto \ "Whether static libraries are built (yes, no, auto)." bt_feature RPATH yes \ "Whether rpath is supported or wanted (yes, no)." # Developer mode bt_feature DEVELOPER no \ "Whether developer mode is enabled or not (yes, no)." bt_msg_summary 'Developer mode: ${BT_FEATURE_DEVELOPER}' # Install documentation? bt_feature DOC yes \ "Whether to install documentation or not (yes, no)." bt_msg_summary 'Install documentation: ${BT_FEATURE_DOC}' } bt_finish() { local hook for hook in ${BT_FINISH_HOOKS}; do ${hook} done bt_generate_configenv bt_generate_logicenv btcmn_log_msg "Configuration successful" } bt_define() { local value=$(echo $2 | tr ' ' '¬') if [ -z ${value} ]; then Defines_Quoted_List+=$1 else Defines_Quoted_List+="$1=${value}" fi } bt_define_unquoted() { value=$(echo $2 | tr ' ' '¬') if [ -z ${value} ]; then Defines_Unquoted_List+=$1 else Defines_Unquoted_List+="$1=${value}" fi } bt_subst() { local var for var in $*; do Subst_List+=${var} done } bt_subst_cache() { Subst_List+=${Cache_List} } bt_cache() { local var for var in $*; do Cache_List+=${var} done } bt_subrload() { local d found name path name=$1.subr path=$(echo ${BT_PATH_SUBRS}:/usr/local/share/buildtool/bt_config | tr ':' ' ') echo "bt_config: loading subroutines ${name}" found= for d in ${path}; do if [ -f ${d}/${name} ]; then . "${d}/${name}" found=yes fi done if [ -z "${found}" ]; then bt_err "cannot load required subroutine file ${name}." \ "if it exists, set a proper path in BT_PATH_SUBRS." fi } bt_def_name() { if [ ${BT_REQUIRE} '<' 0.16 ]; then echo "${1}_$(echo $3 | swcase -ud)" else echo "${1}_$(echo $2 | swcase -ud)_$(echo $3 | swcase -ud)" fi } bt_cache_name() { echo "${1}_$(echo $2 | swcase -ud)_$(echo $3 | swcase -ud)" } bt_define_ml_check() { eval "$1() { \ if ! isfunc ${1}_\${Language}; then btcmn_warn \"the \\\`$1' check is not supported by the \\\`\${Language}' language\" # NOLINT else ${1}_\${Language} \"\$@\" fi }" } # -------------------------------------------------------------------- # File generation functions # -------------------------------------------------------------------- bt_generate_output() { local sep var [ -z "${BT_PROG_SH}" ] && bt_check_prog_sh bt_msg "creating bt_output" AutoTypes+=output cat > ${BT_OUTPUT} < \${f} elif [ -f \${BT_SRCDIR}/\${f}.in ]; then echo "\${progname}: creating \${f}" sed -f \${configsed} < \${BT_SRCDIR}/\${f}.in > \${f} else echo "\${progname}: \${f}.in not found" fi done EOF chmod +x ${BT_OUTPUT} rm -f ${BT_CONFIGSED} touch ${BT_CONFIGSED} for var in ${Subst_List}; do eval val=\"\$${var}\" sep=, echo ${var}${val} | grep ${sep} >/dev/null && sep='|' eval eval echo \\\"\""s${sep}@${var}@${sep}${val}${sep}g"\"\\\" \ >> ${BT_CONFIGSED} done [ $# -gt 0 ] && ${BT_OUTPUT} } bt_generate_configh() { local var bt_msg "generating C include header" rm -f ${BT_CONFIGH} echo "/* File generated by buildtool */" > ${BT_CONFIGH} echo >> ${BT_CONFIGH} for var in ${Defines_Quoted_List}; do var=$(echo ${var} | sed -e 's|=\(.*\)| \"\1\"|g') var=$(echo ${var} | tr '¬' ' ') echo "#define ${var}" >> ${BT_CONFIGH} done for var in ${Defines_Unquoted_List}; do var=$(echo ${var} | tr '=¬' ' ') echo "#define ${var}" >> ${BT_CONFIGH} done } bt_generate_configenv() { local val var bt_msg "generating configuration environment" rm -f ${BT_CONFIGENV} echo "# File generated by buildtool" > ${BT_CONFIGENV} echo >> ${BT_CONFIGENV} for var in ${Subst_List}; do eval val=\"\$${var}\" echo "${var}=\"${val}\"" >> ${BT_CONFIGENV} done } bt_generate_logicenv() { local t bt_msg "generating package dependent build logic" rm -f ${BT_LOGICENV} cat >${BT_LOGICENV} </dev/null 2>&1 || true } EOF [ ${BT_FEATURE_DOC} = yes ] && cat >>${BT_LOGICENV} <&2 shift while [ $# -gt 0 ]; do echo " $1" 1>&2 shift done } bt_err() { echo "bt_config: *** STOP ***" 1>&2 while [ $# -gt 0 ]; do echo "$1" 1>&2 btcmn_log_msg "ERROR: $1" shift done exit 1 } # -------------------------------------------------------------------- # Shell-list management # -------------------------------------------------------------------- bt_list_contains() { local listname=$1 item="$2" local i items eval items=\"\$${listname}\" for i in ${items}; do [ ${i} = ${item} ] && return 0 done return 1 } # -------------------------------------------------------------------- # Language control # -------------------------------------------------------------------- bt_language_select() { local lang lang=$(echo $1 | swcase -ld) btcmn_log_msg "LANGUAGE SELECT: ${lang}" Language="${lang}" } # XXX: Remove bt_language_is_supported() { local listname listname=${1}_languages if ! bt_list_contains "${listname}" "${Language}"; then bt_warn "$1 does not support the selected \`${Language}' language" return 1 fi return 0 } # -------------------------------------------------------------------- # Features # -------------------------------------------------------------------- Features= bt_feature() { local val Features+=$1 eval val=\"\${BT_FEATURE_$1}\" if [ -z "${val}" ]; then eval BT_FEATURE_$1=\'$2\' fi eval BT_FEATURECMT_$1=\'$3\' bt_subst BT_FEATURE_$1 } bt_feature_list() { local cmt f val for f in $(echo ${Features} | tr ' ' '\n' | sort); do eval val=\"\${BT_FEATURE_${f}}\" eval cmt=\"\${BT_FEATURECMT_${f}}\" echo " ${f} - Current value: \`${val}'." 1>&2 echo " ${cmt}" 1>&2 done } bt_feature_parse() { local name val name=$(echo $1 | cut -d '=' -f 1 | swcase -ud) val=$(echo $1 | cut -d '=' -f 2) if ! bt_list_contains Features ${name}; then bt_warn "unknown feature ${name}" return fi [ -z "${val}" ] && val=yes eval BT_FEATURE_${name}=\"${val}\" } # -------------------------------------------------------------------- # Directories # -------------------------------------------------------------------- Dirs= bt_dir() { local val Dirs+=$1 eval val=\"\${BT_DIR_${1}}\" if [ -z "${val}" ]; then eval BT_DIR_$1=\'$2\' fi eval BT_DIRCMT_$1=\'$3\' bt_subst BT_DIR_$1 } bt_dir_list() { local cmt d val for d in $(echo ${Dirs} | tr ' ' '\n' | sort); do eval val=\"\${BT_DIR_${d}}\" eval cmt=\"\${BT_DIRCMT_${d}}\" echo " ${d} - Current value: \`${val}'." 1>&2 echo " ${cmt}" 1>&2 done } bt_dir_parse() { local name val name=$(echo $1 | cut -d '=' -f 1 | swcase -ud) val=$(echo $1 | cut -d '=' -f 2) eval BT_DIR_${name}=\"${val}\" } # Local Variables: *** # mode: shell-script *** # End: *** # vim: syntax=sh # # $Id: envs.in,v 1.5 2003/09/26 17:03:32 jmmv Exp $ # Detect language environments. # # 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. # # -------------------------------------------------------------------- # Language environments # -------------------------------------------------------------------- bt_define_ml_check bt_check_env __GNUC_WARN="-Wall -Wstrict-prototypes -Wmissing-prototypes \ -Wpointer-arith -Wreturn-type -Wswitch \ -Wcast-qual -Wwrite-strings" bt_check_env_c() { local lang wflag [ ${BT_ENV_C:-NULL} != NULL ] && return lang=${Language} bt_language_select c bt_check_prog_cc bt_check_prog_cpp bt_check_prog_ld bt_check_hdr_std_c bt_language_select ${lang} BT_ENV_C=yes if [ $(echo ${BT_FEATURE_DEVELOPER} | swcase -ld) = yes ]; then if [ ${BT_PROG_CC_NAME} = gnu ]; then for wflag in -g ${__GNUC_WARN} ${BT_FLAGS_CC_WARN}; do bt_check_prog_cc_flag ${wflag} && \ BT_FLAGS_CC+=${wflag} done fi fi bt_check_lib_howto bt_check_prog_depgen } bt_check_env_cxx() { local lang wflag [ ${BT_ENV_CXX:-NULL} != NULL ] && return lang=${Language} bt_language_select cxx bt_check_prog_cxx bt_check_prog_cpp bt_check_prog_ld bt_check_hdr_std_cxx bt_language_select ${lang} BT_ENV_CXX=yes if [ $(echo ${BT_FEATURE_DEVELOPER} | swcase -ld) = yes ]; then if [ ${BT_PROG_CXX_NAME} = gnu ]; then for wflag in -g ${__GNUC_WARN} ${BT_FLAGS_CXX_WARN}; do bt_check_prog_cxx_flag ${wflag} && \ BT_FLAGS_CXX+=${wflag} done fi fi bt_check_lib_howto bt_check_prog_depgen } # Local Variables: *** # mode: shell-script *** # End: *** # vim: syntax=sh # # $Id: funcs.in,v 1.15 2004/05/14 16:43:09 jmmv Exp $ # Function checks # # buildtool # Copyright (c) 2002, 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. # # -------------------------------------------------------------------- # Generic function checks # -------------------------------------------------------------------- bt_define_ml_check bt_check_func bt_check_func_c() { btown_check_func c "$@"; } bt_check_func_cxx() { btown_check_func cxx "$@"; } btown_check_func() { local lang="$1" funcname="$2" local defname=$(bt_def_name BT_HAVE_FUNC ${lang} ${funcname}) local cachename=$(bt_cache_name BT_HAVE_FUNC ${lang} ${funcname}) local cv ret bt_cache ${cachename} bt_msg_chk "for ${lang} function ${funcname}" eval cv=\"\${${cachename}:-unset}\" if [ ${cv} = yes ]; then bt_define ${defname} bt_msg_result "yes (cached)" ret=0 elif [ ${cv} = no ]; then bt_msg_result "no (cached)" ret=1 else bt_try_hdr_save_${lang} bt_try_hdr_zap_${lang} bt_try_compile_${lang} < int main() { return 0; } EOF ret=$? if [ ${ret} -eq 0 ]; then eval ${cachename}=yes bt_define ${defname} bt_msg_result yes else eval ${cachename}=no bt_msg_result no fi fi return ${ret} } # -------------------------------------------------------------------- # Specific header checks # -------------------------------------------------------------------- bt_define_ml_check bt_check_hdr_std bt_check_hdr_std_c() { btown_check_hdr_std c; } bt_check_hdr_std_cxx() { btown_check_hdr_std cxx; } btown_check_hdr_std() { local lang=$1 if bt_check_hdr_${lang} stdio.h; then echo "#include " | bt_try_hdr_append_${lang} else bt_err "stdio.h not found; compiler is seriously broken" fi if bt_check_hdr_${lang} sys/types.h; then echo "#include " | bt_try_hdr_append_${lang} fi if bt_check_hdr_${lang} sys/stat.h; then echo "#include " | bt_try_hdr_append_${lang} fi if bt_check_hdr_${lang} stdlib.h; then echo "#include " | bt_try_hdr_append_${lang} fi if bt_check_hdr_${lang} string.h; then echo "#include " | bt_try_hdr_append_${lang} fi if bt_check_hdr_${lang} unistd.h; then echo "#include " | bt_try_hdr_append_${lang} fi } bt_check_hdr_time() { local msg if bt_check_hdr sys/time.h; then bt_try_hdr_save_${Language} echo "#include " | bt_try_hdr_append_${Language} msg="whether sys/time.h and time.h can be included together" if bt_check_hdr time.h; then bt_define BT_HDR_SYS_TIME_WITH_TIME bt_msg_chk ${msg} bt_msg_result yes else bt_msg_chk ${msg} bt_msg_result no fi bt_try_hdr_restore_${Language} fi } # Local Variables: *** # mode: shell-script *** # End: *** # vim: syntax=sh # # $Id: libs.in,v 1.48 2004/02/03 22:58:55 jmmv Exp $ # Library checks # # buildtool # Copyright (c) 2002, 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. # # -------------------------------------------------------------------- # Generic library checks # -------------------------------------------------------------------- bt_define_ml_check bt_check_lib bt_check_lib_c() { btown_check_lib c "$@"; } bt_check_lib_cxx() { btown_check_lib cxx "$@"; } btown_check_lib() { local lang="$1" libname="$2" funcname="$3" local defname cachename local cv ret if [ -z "${funcname}" ]; then defname=$(bt_def_name BT_HAVE_LIB ${lang} ${libname}) cachename=$(bt_cache_name BT_HAVE_LIB ${lang} ${libname}) bt_msg_chk "for ${lang} library ${libname}" funcname=main else defname=$(bt_def_name BT_HAVE_FUNC ${lang} ${funcname}) cachename=$(bt_cache_name BT_HAVE_FUNC ${lang} ${funcname}) bt_msg_chk "for ${lang} function ${funcname} in library ${libname}" fi bt_cache ${cachename} eval cv=\"\${${cachename}:-name}\" if [ ${cv} = yes ]; then bt_define ${defname} bt_msg_result "yes (cached)" ret=0 elif [ ${cv} = no ]; then bt_msg_result "no (cached)" ret=1 else local savelibs="${BT_LIBS}" BT_LIBS+=-l${libname} bt_try_compile_${lang} < int main(void) { printf("%d", sizeof(${type})); return 0; } EOF ) ret=$? if [ ${ret} -eq 0 ]; then bt_define_unquoted ${defname} ${size} eval ${defname}=\"${size}\" eval ${cachename}=\"${size}\" bt_msg_result ${size} else eval ${cachename}="\"unknown type\"" bt_msg_result "unknown type" fi elif [ ${cv} = "unknown type" ]; then bt_msg_result "${cv} (cached)" ret=1 else bt_define_unquoted ${defname} ${cv} eval ${defname}=\"${cv}\" bt_msg_result "${cv} (cached)" ret=0 fi return ${ret} } bt_define_ml_check bt_check_bits bt_check_bits_c() { btown_check_bits c; } bt_check_bits_cxx() { btown_check_bits cxx; } btown_check_bits() { local lang="$1" local so_char so_short so_int so_long so_long_long bt_check_sizeof char eval so_char=\"\$$(bt_def_name BT_SIZEOF ${lang} char)\" bt_check_sizeof short eval so_short=\"\$$(bt_def_name BT_SIZEOF ${lang} short)\" bt_check_sizeof int eval so_int=\"\$$(bt_def_name BT_SIZEOF ${lang} int)\" bt_check_sizeof long eval so_long=\"\$$(bt_def_name BT_SIZEOF ${lang} long)\" bt_check_sizeof "long long" eval so_long_long=\"\$$(bt_def_name BT_SIZEOF ${lang} "long long")\" # Determine 8 bits size if [ ${so_char} -eq 1 ]; then BT_TYPE_BITS8_S="signed char" BT_TYPE_BITS8_U="unsigned char" bt_define_unquoted BT_TYPE_BITS8_S "signed char" bt_define_unquoted BT_TYPE_BITS8_U "unsigned char" elif [ ${so_short} -eq 1 ]; then BT_TYPE_BITS8_S="signed short" BT_TYPE_BITS8_U="unsigned short" bt_define_unquoted BT_TYPE_BITS8_S "signed short" bt_define_unquoted BT_TYPE_BITS8_U "unsigned short" elif [ ${so_int} -eq 1 ]; then BT_TYPE_BITS8_S="signed int" BT_TYPE_BITS8_U="unsigned int" bt_define_unquoted BT_TYPE_BITS8_S "signed int" bt_define_unquoted BT_TYPE_BITS8_U "unsigned int" elif [ ${so_long} -eq 1 ]; then BT_TYPE_BITS8_S="signed long" BT_TYPE_BITS8_U="unsigned long" bt_define_unquoted BT_TYPE_BITS8_S "signed long" bt_define_unquoted BT_TYPE_BITS8_U "unsigned long" elif [ ${so_long_long} -eq 1 ]; then BT_TYPE_BITS8_S="signed long long" BT_TYPE_BITS8_U="unsigned long long" bt_define_unquoted BT_TYPE_BITS8_S "signed long long" bt_define_unquoted BT_TYPE_BITS8_U "unsigned long long" fi bt_subst BT_TYPE_BITS8_S BT_TYPE_BITS8_U # Determine 16 bits size if [ ${so_char} -eq 2 ]; then BT_TYPE_BITS16_S="signed char" BT_TYPE_BITS16_U="unsigned char" bt_define_unquoted BT_TYPE_BITS16_S "signed char" bt_define_unquoted BT_TYPE_BITS16_U "unsigned char" elif [ ${so_short} -eq 2 ]; then BT_TYPE_BITS16_S="signed short" BT_TYPE_BITS16_U="unsigned short" bt_define_unquoted BT_TYPE_BITS16_S "signed short" bt_define_unquoted BT_TYPE_BITS16_U "unsigned short" elif [ ${so_int} -eq 2 ]; then BT_TYPE_BITS16_S="signed int" BT_TYPE_BITS16_U="unsigned int" bt_define_unquoted BT_TYPE_BITS16_S "signed int" bt_define_unquoted BT_TYPE_BITS16_U "unsigned int" elif [ ${so_long} -eq 2 ]; then BT_TYPE_BITS16_S="signed long" BT_TYPE_BITS16_U="unsigned long" bt_define_unquoted BT_TYPE_BITS16_S "signed long" bt_define_unquoted BT_TYPE_BITS16_U "unsigned long" elif [ ${so_long_long} -eq 2 ]; then BT_TYPE_BITS16_S="signed long long" BT_TYPE_BITS16_U="unsigned long long" bt_define_unquoted BT_TYPE_BITS16_S "signed long long" bt_define_unquoted BT_TYPE_BITS16_U "unsigned long long" fi bt_subst BT_TYPE_BITS16_S BT_TYPE_BITS16_U # Determine 32 bits size if [ ${so_char} -eq 4 ]; then BT_TYPE_BITS32_S="signed char" BT_TYPE_BITS32_U="unsigned char" bt_define_unquoted BT_TYPE_BITS32_S "signed char" bt_define_unquoted BT_TYPE_BITS32_U "unsigned char" elif [ ${so_short} -eq 4 ]; then BT_TYPE_BITS32_S="signed short" BT_TYPE_BITS32_U="unsigned short" bt_define_unquoted BT_TYPE_BITS32_S "signed short" bt_define_unquoted BT_TYPE_BITS32_U "unsigned short" elif [ ${so_int} -eq 4 ]; then BT_TYPE_BITS32_S="signed int" BT_TYPE_BITS32_U="unsigned int" bt_define_unquoted BT_TYPE_BITS32_S "signed int" bt_define_unquoted BT_TYPE_BITS32_U "unsigned int" elif [ ${so_long} -eq 4 ]; then BT_TYPE_BITS32_S="signed long" BT_TYPE_BITS32_U="unsigned long" bt_define_unquoted BT_TYPE_BITS32_S "signed long" bt_define_unquoted BT_TYPE_BITS32_U "unsigned long" elif [ ${so_long_long} -eq 4 ]; then BT_TYPE_BITS32_S="signed long long" BT_TYPE_BITS32_U="unsigned long long" bt_define_unquoted BT_TYPE_BITS32_S "signed long long" bt_define_unquoted BT_TYPE_BITS32_U "unsigned long long" fi bt_subst BT_TYPE_BITS32_S BT_TYPE_BITS32_U # Determine 64 bits size if [ ${so_char} -eq 8 ]; then BT_TYPE_BITS64_S="signed char" BT_TYPE_BITS64_U="unsigned char" bt_define_unquoted BT_TYPE_BITS64_S "signed char" bt_define_unquoted BT_TYPE_BITS64_U "unsigned char" elif [ ${so_short} -eq 8 ]; then BT_TYPE_BITS64_S="signed short" BT_TYPE_BITS64_U="unsigned short" bt_define_unquoted BT_TYPE_BITS64_S "signed short" bt_define_unquoted BT_TYPE_BITS64_U "unsigned short" elif [ ${so_int} -eq 8 ]; then BT_TYPE_BITS64_S="signed int" BT_TYPE_BITS64_U="unsigned int" bt_define_unquoted BT_TYPE_BITS64_S "signed int" bt_define_unquoted BT_TYPE_BITS64_U "unsigned int" elif [ ${so_long} -eq 8 ]; then BT_TYPE_BITS64_S="signed long" BT_TYPE_BITS64_U="unsigned long" bt_define_unquoted BT_TYPE_BITS64_S "signed long" bt_define_unquoted BT_TYPE_BITS64_U "unsigned long" elif [ ${so_long_long} -eq 8 ]; then BT_TYPE_BITS64_S="signed long long" BT_TYPE_BITS64_U="unsigned long long" bt_define_unquoted BT_TYPE_BITS64_S "signed long long" bt_define_unquoted BT_TYPE_BITS64_U "unsigned long long" fi bt_subst BT_TYPE_BITS64_S BT_TYPE_BITS64_U } bt_check_host() { bt_msg_chk "for host system name" BT_HOST_OS=$(uname -s) bt_msg_result ${BT_HOST_OS} bt_msg_chk "for host system type" BT_HOST_TYPE=$(uname -s)-$(uname -r)-$(uname -m) bt_msg_result ${BT_HOST_TYPE} # TODO: Check endian type } bt_check_pkgflags() { local varc=$1 varl=$2; shift 2 local res bt_msg_chk "for $@ flags" btcmn_run_module pkgflags "$@" >/dev/null 2>&1 res=$? if [ ${res} -eq 0 ]; then eval ${varc}=\'$(btcmn_run_module pkgflags -c "$@" 2>/dev/null)\' eval ${varl}=\'$(btcmn_run_module pkgflags -l "$@" 2>/dev/null)\' bt_msg_result found return 0 else bt_msg_result "not found" return ${res} fi } bt_define_ml_check bt_check_attribute bt_check_attribute_c() { btown_check_attribute c; } bt_check_attribute_cxx() { btown_check_attribute cxx; } btown_check_attribute() { local lang=$1 local defname=$(bt_def_name BT_HAVE_KEYWORD ${lang} ATTRIBUTE) local cachename=$(bt_cache_name BT_HAVE_KEYWORD ${lang} ATTRIBUTE) local cv ret bt_cache ${cachename} bt_msg_chk "for ${lang} __attribute__ keyword" eval cv=\"\${${cachename}:-unset}\" if [ ${cv} = yes ]; then bt_msg_result "yes (cached)" ret=0 elif [ ${cv} = no ]; then bt_define_unquoted "__attribute__(x)" bt_msg_result "no (cached)" ret=1 else bt_try_compile_${lang} < static void foo(void) __attribute__((noreturn)); static void foo(void) {} int main() { return 0; } EOF ret=$? if [ ${ret} -eq 0 ]; then eval ${cachename}=yes bt_msg_result yes else eval ${cachename}=no bt_define_unquoted "__attribute__(x)" bt_msg_result no fi fi return ${ret} } # -------------------------------------------------------------------- # Generic types # -------------------------------------------------------------------- bt_define_ml_check bt_check_type bt_check_type_c() { btown_check_type c "$@"; } bt_check_type_cxx() { btown_check_type cxx "$@"; } btown_check_type() { local lang=$1 type="$2" local defname=$(bt_def_name BT_HAVE_TYPE ${lang} "${type}") local cachename=$(bt_cache_name BT_HAVE_TYPE ${lang} "${type}") local cv ret bt_cache ${cachename} bt_msg_chk "for ${lang} type ${type}" eval cv=\"\${${cachename}:-unset}\" if [ ${cv} = yes ]; then bt_define ${defname} bt_msg_result "yes (cached)" ret=0 elif [ ${cv} = no ]; then bt_msg_result "no (cached)" ret=1 else bt_try_compile_${lang} < int main(void) { #if defined(__GNUC__) printf("gnu"); /* NOLINT */ #elif defined(__SUNPRO_C) printf("sunpro"); /* NOLINT */ #else printf("unknown"); /* NOLINT */ #endif return 0; } EOF ) bt_msg_result ${BT_PROG_CC_NAME} if [ ${BT_PROG_CC_NAME} != gnu ]; then bt_warn "Using a C compiler that is not GNU C." \ "Buildtool may behave unexpectedly; please report any problems." # NOLINT fi else bt_msg_result "${BT_PROG_CC_NAME} (cached)" fi bt_msg_chk "for C compiler version" if [ -z "${BT_PROG_CC_VERSION}" ]; then case ${BT_PROG_CC_NAME} in gnu) BT_PROG_CC_VERSION=$(${BT_PROG_CC} -dumpversion) if echo ${BT_PROG_CC_VERSION} | grep egcs >/dev/null; then BT_PROG_CC_VERSION=2.8.1 fi ;; *) BT_PROG_CC_VERSION=unknown ;; esac bt_msg_result ${BT_PROG_CC_VERSION} else bt_msg_result "${BT_PROG_CC_VERSION} (cached)" fi bt_subst BT_PROG_CC_NAME bt_subst BT_PROG_CC_VERSION bt_subst BT_FLAGS_CPP bt_subst BT_FLAGS_CC bt_subst BT_LIBS return 0 fi bt_err "no C compiler available, cannot continue" } bt_check_prog_cc_flag() { local flag="$1" local cachename=$(bt_cache_name BT_PROG_HAVE_FLAG c ${flag}) local cv ret saved_flags_cc [ -z "${BT_PROG_CC}" ] && bt_check_prog_cc bt_cache ${cachename} bt_msg_chk "for c compiler flag ${flag}" eval cv=\"\${${cachename}:-name}\" if [ ${cv} = yes ]; then bt_msg_result "yes (cached)" ret=0 elif [ ${cv} = no ]; then bt_msg_result "no (cached)" ret=1 else saved_flags_cc=${BT_FLAGS_CC} BT_FLAGS_CC+=${flag} bt_try_compile_c < int main(void) { return 0; } EOF ret=$? if [ ${ret} -eq 0 ]; then eval ${cachename}=yes bt_msg_result yes else eval ${cachename}=no bt_msg_result no fi BT_FLAGS_CC=${saved_flags_cc} fi return ${ret} } bt_check_prog_cpp() { if bt_check_progs BT_PROG_CPP cpp; then bt_subst BT_FLAGS_CPP return 0 fi return 1 } bt_check_prog_cxx() { if bt_check_progs BT_PROG_CXX "g++ c++ cxx cc++ gcc CC"; then bt_msg_chk "for C++ compiler name" if [ -z "${BT_PROG_CXX_NAME}" ]; then BT_PROG_CXX_NAME=$(bt_try_run_cxx < int main(void) { #if defined(__GNUC__) printf("gnu"); /* NOLINT */ #elif defined(__SUNPRO_C) printf("sunpro"); /* NOLINT */ #else printf("unknown"); /* NOLINT */ #endif } EOF ) bt_msg_result ${BT_PROG_CXX_NAME} if [ ${BT_PROG_CXX_NAME} != gnu ]; then bt_warn "Using a C++ compiler that is not GNU C++." \ "Buildtool may behave unexpectedly; please report any problems." # NOLINT fi else bt_msg_result "${BT_PROG_CXX_NAME} (cached)" fi bt_msg_chk "for C++ compiler version" if [ -z "${BT_PROG_CXX_VERSION}" ]; then case ${BT_PROG_CXX_NAME} in gnu) BT_PROG_CXX_VERSION=$(${BT_PROG_CXX} -dumpversion) if echo ${BT_PROG_CXX_VERSION} | grep egcs >/dev/null; then BT_PROG_CXX_VERSION=2.8.1 fi ;; *) BT_PROG_CXX_VERSION=unknown ;; esac bt_msg_result ${BT_PROG_CXX_VERSION} else bt_msg_result "${BT_PROG_CXX_VERSION} (cached)" fi bt_subst BT_PROG_CXX_NAME bt_subst BT_PROG_CXX_VERSION bt_subst BT_FLAGS_CPP bt_subst BT_FLAGS_CXX bt_subst BT_LIBS return 0 fi bt_err "no C++ compiler available, cannot continue" } bt_check_prog_cxx_flag() { local flag="$1" local cachename=$(bt_cache_name BT_PROG_HAVE_FLAG cxx ${flag}) local cv ret saved_flags_cxx [ -z "${BT_PROG_CXX}" ] && bt_check_prog_cxx bt_cache ${cachename} bt_msg_chk "for cxx compiler flag ${flag}" eval cv=\"\${${cachename}:-name}\" if [ ${cv} = yes ]; then bt_msg_result "yes (cached)" ret=0 elif [ ${cv} = no ]; then bt_msg_result "no (cached)" ret=1 else saved_flags_cxx=${BT_FLAGS_CXX} BT_FLAGS_CXX+=${flag} bt_try_compile_cxx < int main(void) { return 0; } EOF ret=$? if [ ${ret} -eq 0 ]; then eval ${cachename}=yes bt_msg_result yes else eval ${cachename}=no bt_msg_result no fi BT_FLAGS_CXX=${saved_flags_cxx} fi return ${ret} } bt_check_prog_depgen() { if [ -n "${BT_PROG_FASTDEP}" ] || bt_check_progs BT_PROG_FASTDEP fastdep then BT_PROG_DEPGEN=${BT_PROG_FASTDEP} else BT_PROG_DEPGEN= [ -n "${BT_PROG_CPP}" ] && BT_PROG_DEPGEN="${BT_PROG_CPP} -M" [ -n "${BT_PROG_CC}" -a ${BT_PROG_CC_NAME:-unset} = gnu ] && \ BT_PROG_DEPGEN="${BT_PROG_CC} -MM" [ -n "${BT_PROG_CXX}" -a ${BT_PROG_CXX_NAME:-unset} = gnu ] && \ BT_PROG_DEPGEN="${BT_PROG_CXX} -MM" fi bt_subst BT_PROG_DEPGEN } bt_check_prog_info() { local res=0 if ! bt_check_progs BT_PROG_MAKEINFO makeinfo; then res=1 fi if ! bt_check_progs BT_PROG_INSTALLINFO install-info; then res=1 fi return ${res} } bt_check_prog_lex() { if bt_check_progs BT_PROG_LEX flex; then BT_LIBS_LEX=-lfl elif bt_check_progs BT_PROG_LEX lex; then BT_LIBS_LEX=-ll else return 1 fi bt_subst BT_LIBS_LEX return 0 } bt_check_prog_ld() { if bt_check_progs BT_PROG_LD ld; then bt_subst BT_FLAGS_LD return 0 fi return 1 } bt_check_prog_m4() { bt_check_progs BT_PROG_M4 "gm4 m4" } bt_check_prog_make() { local ret=1 tmp if bt_check_progs BT_PROG_MAKE "gmake bmake make"; then bt_msg_chk "for make type" if [ -z "${BT_PROG_MAKE_TYPE}" ]; then tmp=$(${BT_PROG_MAKE} --version 2>/dev/null | head -n 1 | grep GNU) if [ -n "${tmp}" ]; then BT_PROG_MAKE_TYPE=gnu else cat >${BT_WORKDIR}/bt_test.mk </dev/null 2>&1; then BT_PROG_MAKE_TYPE=bsd else BT_PROG_MAKE_TYPE=unknown fi rm -f ${BT_WORKDIR}/bt_test.mk fi bt_msg_result "${BT_PROG_MAKE_TYPE}" else bt_msg_result "${BT_PROG_MAKE_TYPE} (cached)" fi bt_subst BT_PROG_MAKE_TYPE ret=0 fi return ${ret} } bt_check_prog_sh() { bt_check_progs BT_PROG_SH "ksh pdksh sh bash zsh" } bt_check_prog_yacc() { local proglist="${1:-bison byacc yacc}" bt_check_progs BT_PROG_YACC "${proglist}" } # Local Variables: *** # mode: shell-script *** # End: *** # vim: syntax=sh # # $Id: try.in,v 1.11 2004/05/08 20:12:55 jmmv Exp $ # Compile and run C/C++ test programs. # # 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_try_init # Initialize the header files for the tests. # BT_INIT_HOOKS+=bt_try_init bt_try_init() { BT_TRY_TESTHDR_C=${BT_WORKDIR}/testhdr.c BT_TRY_TESTHDR_CXX=${BT_WORKDIR}/testhdr.cc rm -f ${BT_TRY_TESTHDR_C} ${BT_TRY_TESTHDR_CXX} touch ${BT_TRY_TESTHDR_C} ${BT_TRY_TESTHDR_CXX} } # ------------------------------------------------------------------------- # # bt_try_finish # Remove the temporary files containing definitions for tests. # BT_FINISH_HOOKS+=bt_try_finish bt_try_finish() { rm -f ${BT_TRY_TESTHDR_C} ${BT_TRY_TESTHDR_CXX} rm -f ${BT_TRY_TESTHDR_C}.old ${BT_TRY_TESTHDR_CXX}.old } # ------------------------------------------------------------------------- # # bt_try_hdr_append_c # Append the contents from stdin to the C test header file. # bt_try_hdr_append_c() { cat >> ${BT_TRY_TESTHDR_C} } # ------------------------------------------------------------------------- # # bt_try_hdr_append_cxx # Append the contents from stdin to the C++ test header file. # bt_try_hdr_append_cxx() { cat >> ${BT_TRY_TESTHDR_CXX} } # ------------------------------------------------------------------------- # # bt_try_hdr_save_c # Save a copy of the current C test header so that it can be modified # before a test and restored afterwards in case of failure. # Should not be needed in most cases. # bt_try_hdr_save_c() { cp ${BT_TRY_TESTHDR_C} ${BT_TRY_TESTHDR_C}.old } # ------------------------------------------------------------------------- # # bt_try_hdr_save_cxx # Save a copy of the current C++ test header so that it can be modified # before a test and restored afterwards in case of failure. # Should not be needed in most cases. # bt_try_hdr_save_cxx() { cp ${BT_TRY_TESTHDR_CXX} ${BT_TRY_TESTHDR_CXX}.old } # ------------------------------------------------------------------------- # # bt_try_hdr_restore_c # Restore a previous copy of the C test header. # bt_try_hdr_restore_c() { mv ${BT_TRY_TESTHDR_C}.old ${BT_TRY_TESTHDR_C} } # ------------------------------------------------------------------------- # # bt_try_hdr_restore_cxx # Restore a previous copy of the C++ test header. # bt_try_hdr_restore_cxx() { mv ${BT_TRY_TESTHDR_CXX}.old ${BT_TRY_TESTHDR_CXX} } # ------------------------------------------------------------------------- # # bt_try_hdr_zap_c # Clear the contents of the C test header file. # bt_try_hdr_zap_c() { rm -f ${BT_TRY_TESTHDR_C} touch ${BT_TRY_TESTHDR_C} } # ------------------------------------------------------------------------- # # bt_try_hdr_zap_cxx # Clear the contents of the C++ test header file. # bt_try_hdr_zap_cxx() { rm -f ${BT_TRY_TESTHDR_CXX} touch ${BT_TRY_TESTHDR_CXX} } # ------------------------------------------------------------------------- # # bt_try_compile_c # Compiles the C program given through standard input. # Returns 0 on success, 1 if compilation failed. # bt_try_compile_c() { btown_try_c compile; } # ------------------------------------------------------------------------- # # bt_try_compile_c # Compiles the C++ program given through standard input. # Returns 0 on success, 1 if compilation failed. # bt_try_compile_cxx() { btown_try_cxx compile; } # ------------------------------------------------------------------------- # # bt_try_run_c # Compiles and executes the C program given through standard input. # If compilation fails, the configuration process is aborted. # Otherwise, the exit status of the program is returned. # bt_try_run_c() { btown_try_c run; } # ------------------------------------------------------------------------- # # bt_try_run_cxx # Compiles and executes the C++ program given through standard input. # If compilation fails, the configuration process is aborted. # Otherwise, the exit status of the program is returned. # bt_try_run_cxx() { btown_try_cxx run; } # ------------------------------------------------------------------------- # # btown_try_c compile|run # Helper function used by bt_try_compile_c and bt_try_run_c. # btown_try_c() { local action=$1 cmd exitstat hdr cp ${BT_TRY_TESTHDR_C} ${BT_WORKDIR}/bt_test.c if [ -n "${BT_INCLUDE_FILES}" ]; then # XXX: Compatibility stuff - to be removed. echo 1>&2 btcmn_warn "usage of BT_INCLUDE_FILES is deprecated!" \ "switch your code to use the bt_try_append_c function" for hdr in ${BT_INCLUDE_FILES}; do echo "#include <${hdr}>" >> ${BT_WORKDIR}/bt_test.cc done fi cat >> ${BT_WORKDIR}/bt_test.c cmd="${BT_PROG_CC} ${BT_FLAGS_CPP} ${BT_FLAGS_CC} ${BT_FLAGS_LD}" cmd+="${BT_LIBS} -o ${BT_WORKDIR}/bt_test ${BT_WORKDIR}/bt_test.c" echo "BUILDING C TEST PROGRAM: ${cmd}" >> $(btcmn_log_name) ${cmd} >> $(btcmn_log_name) 2>&1 if [ $? -eq 0 ]; then rm -f ${BT_WORKDIR}/bt_test.c if [ ${action} = compile ]; then rm -f ${BT_WORKDIR}/bt_test return 0 else ${BT_WORKDIR}/bt_test exitstat=$? rm -f ${BT_WORKDIR}/bt_test return ${exitstat} fi else echo "C TEST PROGRAM FAILED:" >> $(btcmn_log_name) cat ${BT_WORKDIR}/bt_test.c >> $(btcmn_log_name) rm -f ${BT_WORKDIR}/bt_test.c ${BT_WORKDIR}/bt_test if [ ${action} = compile ]; then return 1 else btcmn_err "failed to run the C test program" \ "check $(btcmn_log_name) to see what happened" fi fi } # ------------------------------------------------------------------------- # # btown_try_cxx compile|run # Helper function used by bt_try_compile_cxx and bt_try_run_cxx. # btown_try_cxx() { local action=$1 cmd exitstat hdr cp ${BT_TRY_TESTHDR_CXX} ${BT_WORKDIR}/bt_test.cc if [ -n "${BT_INCLUDE_FILES}" ]; then # XXX: Compatibility stuff - to be removed. echo 1>&2 btcmn_warn "usage of BT_INCLUDE_FILES is deprecated!" \ "switch your code to use the bt_try_append_cxx function" for hdr in ${BT_INCLUDE_FILES}; do echo "#include <${hdr}>" >> ${BT_WORKDIR}/bt_test.cc done fi cat >> ${BT_WORKDIR}/bt_test.cc cmd="${BT_PROG_CXX} ${BT_FLAGS_CPP} ${BT_FLAGS_CXX} ${BT_FLAGS_LD}" cmd+="${BT_LIBS} -o ${BT_WORKDIR}/bt_test ${BT_WORKDIR}/bt_test.cc" echo "BUILDING C++ TEST PROGRAM: ${cmd}" >> $(btcmn_log_name) ${cmd} >> $(btcmn_log_name) 2>&1 if [ $? -eq 0 ]; then rm -f ${BT_WORKDIR}/bt_test.cc if [ ${action} = compile ]; then rm -f ${BT_WORKDIR}/bt_test return 0 else ${BT_WORKDIR}/bt_test exitstat=$? rm -f ${BT_WORKDIR}/bt_test return ${exitstat} fi else echo "C++ TEST PROGRAM FAILED:" >> $(btcmn_log_name) cat ${BT_WORKDIR}/bt_test.cc >> $(btcmn_log_name) rm -f ${BT_WORKDIR}/bt_test.cc ${BT_WORKDIR}/bt_test if [ ${action} = compile ]; then return 1 else btcmn_err "failed to run the C test program" \ "check $(btcmn_log_name) to see what happened" fi fi } # Local Variables: *** # mode: shell-script *** # End: *** # vim: syntax=sh