From patchwork Tue Jan 2 18:13:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10141185 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6251A6035E for ; Tue, 2 Jan 2018 18:13:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5500F28DAA for ; Tue, 2 Jan 2018 18:13:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 49E9E28DAC; Tue, 2 Jan 2018 18:13:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 80A4128DAB for ; Tue, 2 Jan 2018 18:13:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751317AbeABSNq (ORCPT ); Tue, 2 Jan 2018 13:13:46 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:36146 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751238AbeABSNo (ORCPT ); Tue, 2 Jan 2018 13:13:44 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1514918022; x=1546454022; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=oNxuun5DM0gjOJ+5sZdPL+OHRCY6oNOYd2SAmuGWFsE=; b=WigtZ6pMnMAnSfWmxsKed4ZpeIF0UMN/a4fT02PA4/xc9Ki5+k41JqhG ThEEMJ0KNmK/GMrWLU0A7l9G/2EVqigrEuUaFs1DBwSZPUSSIK28Mx2Fh tQT/I8PK6SwtKAWYTRBRlQMsuuRv/0Dnz7051ljp/RTD05oEgiWEckoHb V+BksfZc8apWzfCqLiJc1ln04SAYzxgUZ1KXDBsJdOSsic3kD8TFGGpCd bfK1h+VEHES7Vwouuta30nV5cx3HxmMwBi2qA9d95NX1wIT/so89C/y00 0whLJLAxNBYNBwrhsu0jrfTK5+dWT+VKTuwVgO7EwvPM43P95Oy2HdFSP w==; X-IronPort-AV: E=Sophos;i="5.45,498,1508774400"; d="scan'208";a="163812928" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 03 Jan 2018 02:33:41 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 02 Jan 2018 10:09:53 -0800 Received: from thinkpad-bart.sdcorp.global.sandisk.com (HELO thinkpad-bart.int.fusionio.com) ([10.11.171.236]) by uls-op-cesaip02.wdc.com with ESMTP; 02 Jan 2018 10:13:42 -0800 From: Bart Van Assche To: Doug Gilbert Cc: Hannes Reinecke , Bean Huo , linux-scsi@vger.kernel.org, Bart Van Assche Subject: [PATCH for sg3_utils 2/4] configure.ac: Only link with the pthread library if required Date: Tue, 2 Jan 2018 10:13:39 -0800 Message-Id: <20180102181341.13435-3-bart.vanassche@wdc.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180102181341.13435-1-bart.vanassche@wdc.com> References: <20180102181341.13435-1-bart.vanassche@wdc.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Let the configure script detect whether pthread functions occur in the pthread library (all platforms except Android) or in the C library (Android). From the autoconf manual: action-if-found is a list of shell commands to run if the link with the library succeeds; action-if-not-found is a list of shell commands to run if the link fails. If action-if-found is not specified, the default action prepends -llibrary to LIBS and defines 'HAVE_LIBlibrary' (in all capitals). Signed-off-by: Bart Van Assche --- Makefile.in | 1 + config.h.in | 4 +-- configure | 94 +++++++++++++++-------------------------------------- configure.ac | 10 ++++-- doc/Makefile.in | 1 + include/Makefile.in | 1 + lib/Makefile.in | 1 + scripts/Makefile.in | 1 + src/Makefile.am | 2 +- src/Makefile.in | 3 +- 10 files changed, 45 insertions(+), 73 deletions(-) diff --git a/Makefile.in b/Makefile.in index 0054cfe62bd6..4e2b06453f28 100644 --- a/Makefile.in +++ b/Makefile.in @@ -261,6 +261,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ +PTHREAD_LIB = @PTHREAD_LIB@ RANLIB = @RANLIB@ SED = @SED@ SET_MAKE = @SET_MAKE@ diff --git a/config.h.in b/config.h.in index b33212f47d27..b5c6715ade05 100644 --- a/config.h.in +++ b/config.h.in @@ -36,10 +36,10 @@ /* Define to 1 if you have the `posix_memalign' function. */ #undef HAVE_POSIX_MEMALIGN -/* Found pthread_cancel */ +/* Define to 1 if you have the `pthread_cancel' function. */ #undef HAVE_PTHREAD_CANCEL -/* Found pthread_kill */ +/* Define to 1 if you have the `pthread_kill' function. */ #undef HAVE_PTHREAD_KILL /* Define to 1 if you have the header file. */ diff --git a/configure b/configure index 5fe9a187a373..59b01f4fdf5b 100755 --- a/configure +++ b/configure @@ -652,6 +652,7 @@ OS_FREEBSD_TRUE os_libs os_cflags GETOPT_O_FILES +PTHREAD_LIB CPP LT_SYS_LIBRARY_PATH OTOOL64 @@ -12332,9 +12333,10 @@ _ACEOF fi done -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing pthread_cancel" >&5 -$as_echo_n "checking for library containing pthread_cancel... " >&6; } -if ${ac_cv_search_pthread_cancel+:} false; then : +SAVED_LIBS=$LIBS +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing pthread_create" >&5 +$as_echo_n "checking for library containing pthread_create... " >&6; } +if ${ac_cv_search_pthread_create+:} false; then : $as_echo_n "(cached) " >&6 else ac_func_search_save_LIBS=$LIBS @@ -12347,11 +12349,11 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext #ifdef __cplusplus extern "C" #endif -char pthread_cancel (); +char pthread_create (); int main () { -return pthread_cancel (); +return pthread_create (); ; return 0; } @@ -12364,89 +12366,47 @@ for ac_lib in '' pthread; do LIBS="-l$ac_lib $ac_func_search_save_LIBS" fi if ac_fn_c_try_link "$LINENO"; then : - ac_cv_search_pthread_cancel=$ac_res + ac_cv_search_pthread_create=$ac_res fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext - if ${ac_cv_search_pthread_cancel+:} false; then : + if ${ac_cv_search_pthread_create+:} false; then : break fi done -if ${ac_cv_search_pthread_cancel+:} false; then : +if ${ac_cv_search_pthread_create+:} false; then : else - ac_cv_search_pthread_cancel=no + ac_cv_search_pthread_create=no fi rm conftest.$ac_ext LIBS=$ac_func_search_save_LIBS fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_pthread_cancel" >&5 -$as_echo "$ac_cv_search_pthread_cancel" >&6; } -ac_res=$ac_cv_search_pthread_cancel +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_pthread_create" >&5 +$as_echo "$ac_cv_search_pthread_create" >&6; } +ac_res=$ac_cv_search_pthread_create if test "$ac_res" != no; then : test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" -$as_echo "#define HAVE_PTHREAD_CANCEL 1" >>confdefs.h - fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing pthread_kill" >&5 -$as_echo_n "checking for library containing pthread_kill... " >&6; } -if ${ac_cv_search_pthread_kill+:} false; then : - $as_echo_n "(cached) " >&6 -else - ac_func_search_save_LIBS=$LIBS -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char pthread_kill (); -int -main () -{ -return pthread_kill (); - ; - return 0; -} +# AC_SEARCH_LIBS adds libraries at the start of $LIBS so remove $SAVED_LIBS +# from the end of $LIBS. +pthread_lib=${LIBS%${SAVED_LIBS}} +for ac_func in pthread_cancel pthread_kill +do : + as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` +ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" +if eval test \"x\$"$as_ac_var"\" = x"yes"; then : + cat >>confdefs.h <<_ACEOF +#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 _ACEOF -for ac_lib in '' pthread; do - if test -z "$ac_lib"; then - ac_res="none required" - else - ac_res=-l$ac_lib - LIBS="-l$ac_lib $ac_func_search_save_LIBS" - fi - if ac_fn_c_try_link "$LINENO"; then : - ac_cv_search_pthread_kill=$ac_res -fi -rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext - if ${ac_cv_search_pthread_kill+:} false; then : - break -fi -done -if ${ac_cv_search_pthread_kill+:} false; then : -else - ac_cv_search_pthread_kill=no -fi -rm conftest.$ac_ext -LIBS=$ac_func_search_save_LIBS fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_pthread_kill" >&5 -$as_echo "$ac_cv_search_pthread_kill" >&6; } -ac_res=$ac_cv_search_pthread_kill -if test "$ac_res" != no; then : - test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" - -$as_echo "#define HAVE_PTHREAD_KILL 1" >>confdefs.h +done -fi +LIBS=$SAVED_LIBS +PTHREAD_LIB=$pthread_lib diff --git a/configure.ac b/configure.ac index 129c2f9d4d4d..6164850d0aa3 100644 --- a/configure.ac +++ b/configure.ac @@ -25,8 +25,14 @@ AC_CHECK_FUNCS(posix_fadvise) AC_CHECK_FUNCS(posix_memalign) AC_CHECK_FUNCS(sysconf) AC_CHECK_FUNCS(lseek64) -AC_SEARCH_LIBS([pthread_cancel], [pthread], [AC_DEFINE(HAVE_PTHREAD_CANCEL, 1, [Found pthread_cancel])], []) -AC_SEARCH_LIBS([pthread_kill], [pthread], [AC_DEFINE(HAVE_PTHREAD_KILL, 1, [Found pthread_kill])], []) +SAVED_LIBS=$LIBS +AC_SEARCH_LIBS([pthread_create], [pthread]) +# AC_SEARCH_LIBS adds libraries at the start of $LIBS so remove $SAVED_LIBS +# from the end of $LIBS. +pthread_lib=${LIBS%${SAVED_LIBS}} +AC_CHECK_FUNCS([pthread_cancel pthread_kill]) +LIBS=$SAVED_LIBS +AC_SUBST(PTHREAD_LIB, [$pthread_lib]) AC_SUBST(GETOPT_O_FILES) AC_CANONICAL_HOST diff --git a/doc/Makefile.in b/doc/Makefile.in index 012c294ccf6b..5b3f009554af 100644 --- a/doc/Makefile.in +++ b/doc/Makefile.in @@ -219,6 +219,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ +PTHREAD_LIB = @PTHREAD_LIB@ RANLIB = @RANLIB@ SED = @SED@ SET_MAKE = @SET_MAKE@ diff --git a/include/Makefile.in b/include/Makefile.in index f0f4a2b17745..0016be3edf15 100644 --- a/include/Makefile.in +++ b/include/Makefile.in @@ -239,6 +239,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ +PTHREAD_LIB = @PTHREAD_LIB@ RANLIB = @RANLIB@ SED = @SED@ SET_MAKE = @SET_MAKE@ diff --git a/lib/Makefile.in b/lib/Makefile.in index 2594c724aa96..35d83c1d3dd6 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -283,6 +283,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ +PTHREAD_LIB = @PTHREAD_LIB@ RANLIB = @RANLIB@ SED = @SED@ SET_MAKE = @SET_MAKE@ diff --git a/scripts/Makefile.in b/scripts/Makefile.in index 0a81294b1d67..1daa3818f5cb 100644 --- a/scripts/Makefile.in +++ b/scripts/Makefile.in @@ -208,6 +208,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ +PTHREAD_LIB = @PTHREAD_LIB@ RANLIB = @RANLIB@ SED = @SED@ SET_MAKE = @SET_MAKE@ diff --git a/src/Makefile.am b/src/Makefile.am index 4c3bb1caff71..33c7be515b8d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -86,7 +86,7 @@ sg_modes_LDADD = ../lib/libsgutils2.la @os_libs@ sg_opcodes_LDADD = ../lib/libsgutils2.la @os_libs@ -sgp_dd_LDADD = ../lib/libsgutils2.la @os_libs@ -lpthread +sgp_dd_LDADD = ../lib/libsgutils2.la @os_libs@ @PTHREAD_LIB@ sg_persist_LDADD = ../lib/libsgutils2.la @os_libs@ diff --git a/src/Makefile.in b/src/Makefile.in index 3117f2528d76..eec196432869 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -499,6 +499,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ +PTHREAD_LIB = @PTHREAD_LIB@ RANLIB = @RANLIB@ SED = @SED@ SET_MAKE = @SET_MAKE@ @@ -590,7 +591,7 @@ sg_map_LDADD = ../lib/libsgutils2.la @os_libs@ sgm_dd_LDADD = ../lib/libsgutils2.la @os_libs@ sg_modes_LDADD = ../lib/libsgutils2.la @os_libs@ sg_opcodes_LDADD = ../lib/libsgutils2.la @os_libs@ -sgp_dd_LDADD = ../lib/libsgutils2.la @os_libs@ -lpthread +sgp_dd_LDADD = ../lib/libsgutils2.la @os_libs@ @PTHREAD_LIB@ sg_persist_LDADD = ../lib/libsgutils2.la @os_libs@ sg_prevent_LDADD = ../lib/libsgutils2.la @os_libs@ sg_raw_LDADD = ../lib/libsgutils2.la @os_libs@