# # $Id: pthread.subr,v 1.13 2004/03/30 12:44:16 jmmv Exp $ # bt_config module: pthread detection # # buildtool # Copyright (c) 2002, 2003, 2004 Julio M. Merino Vidal # # This code was originally contributed by Juan J. Martínez. # # 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. # pthread_feature() { bt_feature PTHREAD auto \ "Whether threading support is wanted or not (yes, no, auto)." } bt_define_ml_check pthread_check pthread_check_c() { pthreadown_check c; } pthread_check_cxx() { pthreadown_check cxx; } pthreadown_check() { local lang="$1" local flags="pthreads pthread lthread none -Kthread -kthread \ -pthread -pthreads -mthreads --thread-safe -mt" local flag res saved_flags_ld saved_libs if [ ${BT_FEATURE_PTHREAD:-auto} = no ]; then echo "pthread support disabled as requested" bt_msg_summary 'Threading support: no' return 0 fi for flag in ${flags}; do PTHREAD_LIBS= PTHREAD_FLAGS_LD= case ${flag} in none) bt_msg_chk "pthread without flags" ;; -*) bt_msg_chk "pthread with ${flag}" PTHREAD_FLAGS_LD=${flag} ;; *) bt_msg_chk "pthread library -l${flag}" PTHREAD_LIBS="-l${flag}" ;; esac saved_flags_ld=${BT_FLAGS_LD} saved_libs=${BT_LIBS} BT_FLAGS_LD+=${PTHREAD_FLAGS_LD} BT_LIBS+=${PTHREAD_LIBS} bt_try_compile_${lang} < void *start_routine(void *unused) {} int main() { pthread_t th; pthread_create(&th, 0, start_routine, 0); pthread_join(th, 0); return 0; } EOF res=$? BT_FLAGS_LD=${saved_flags_ld} BT_LIBS=${saved_libs} if [ ${res} -eq 0 ]; then bt_subst PTHREAD_FLAGS_LD bt_subst PTHREAD_LIBS bt_msg_result yes if [ ${BT_FEATURE_PTHREAD:-unset} != unset ]; then bt_msg_summary 'Threading support: yes' fi return 0 else bt_msg_result no fi done if [ ${BT_FEATURE_PTHREAD:-unset} = yes ]; then bt_err "threading support not found." \ "Disable it manually with --disable-pthread." elif [ ${BT_FEATURE_PTHREAD:-unset} != unset ]; then bt_msg_summary 'Threading support: no' fi return 1 } # Local Variables: *** # mode: shell-script *** # End: *** # vim: syntax=sh