From 5bb0a339be31064900257e04e2ffd32e80911d63 Mon Sep 17 00:00:00 2001 From: Mikko Koppanen Date: Wed, 1 Dec 2010 10:33:07 +0100 Subject: Prefix variables with "ac_zmq_" - Added a macro for checking clang compiler - Moved basic compiler checks to a macro - Added a macro for checking if compiler supports a flag - Added --enable-debug flag - Added a macro for running normal autoconf check with compiler flags - Added a macro for checking for verbose flag for different compilers (-Wall) - Added a macro for turning on strict standards compliance - Added a macro for turning warnings to errors - Added a macro for checking if compiler supports given pragma - Most of the flags now go through checks if the compilers supports them rather than enumerating different compilers - Added DSO symbol visibility for sun compiler - Enabled verbose mode for sun compiler - Fixed build for ICC 12.x by adding -wd279 to size_t checks - Removed pkg-config checks as those don't seem to be used anywhere Signed-off-by: Mikko Koppanen --- acinclude.m4 | 461 +++++++++++++++++++++++++++++++++++++++++++++++----- autogen.sh | 6 - configure.in | 212 ++++++++++++------------ include/zmq.h | 14 +- include/zmq_utils.h | 14 +- 5 files changed, 532 insertions(+), 175 deletions(-) diff --git a/acinclude.m4 b/acinclude.m4 index f16c2c0..e25702c 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -1,12 +1,9 @@ dnl ############################################################################## -dnl # AC_CONFIG_LIBTOOL # -dnl # Configure libtool. $host_os needs to be set before calling this macro # +dnl # AC_ZMQ_CONFIG_LIBTOOL # +dnl # Configure libtool. Requires AC_CANONICAL_HOST # dnl ############################################################################## -AC_DEFUN([AC_CONFIG_LIBTOOL], [{ - - if test "x${host_os}" = "x"; then - AC_MSG_ERROR([AC@&t@_CANONICAL_HOST not called before calling AC@&t@_CONFIG_LIBTOOL]) - fi +AC_DEFUN([AC_ZMQ_CONFIG_LIBTOOL], [{ + AC_REQUIRE([AC_CANONICAL_HOST]) # Libtool configuration for different targets case "${host_os}" in @@ -21,101 +18,479 @@ AC_DEFUN([AC_CONFIG_LIBTOOL], [{ esac }]) - dnl ############################################################################## -dnl # AC_CHECK_LANG_ICC # +dnl # AC_ZMQ_CHECK_LANG_ICC([action-if-found], [action-if-not-found]) # dnl # Check if the current language is compiled using ICC # dnl # Adapted from http://software.intel.com/en-us/forums/showthread.php?t=67984 # dnl ############################################################################## -AC_DEFUN([AC_CHECK_LANG_ICC], +AC_DEFUN([AC_ZMQ_CHECK_LANG_ICC], [AC_CACHE_CHECK([whether we are using Intel _AC_LANG compiler], - [ac_cv_[]_AC_LANG_ABBREV[]_intel_compiler], + [ac_zmq_cv_[]_AC_LANG_ABBREV[]_intel_compiler], [_AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[#ifndef __INTEL_COMPILER error if not ICC #endif ]])], - [is_icc=yes], - [is_icc=no]) -ac_cv_[]_AC_LANG_ABBREV[]_intel_compiler=$is_icc + [ac_zmq_cv_[]_AC_LANG_ABBREV[]_intel_compiler="yes" ; $1], + [ac_zmq_cv_[]_AC_LANG_ABBREV[]_intel_compiler="no" ; $2]) ])]) dnl ############################################################################## -dnl # AC_CHECK_LANG_SUN_STUDIO # +dnl # AC_ZMQ_CHECK_LANG_SUN_STUDIO([action-if-found], [action-if-not-found]) # dnl # Check if the current language is compiled using Sun Studio # dnl ############################################################################## -AC_DEFUN([AC_CHECK_LANG_SUN_STUDIO], +AC_DEFUN([AC_ZMQ_CHECK_LANG_SUN_STUDIO], [AC_CACHE_CHECK([whether we are using Sun Studio _AC_LANG compiler], - [ac_cv_[]_AC_LANG_ABBREV[]_sun_studio_compiler], + [ac_zmq_cv_[]_AC_LANG_ABBREV[]_sun_studio_compiler], [_AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[#if !defined(__SUNPRO_CC) && !defined(__SUNPRO_C) error if not sun studio #endif ]])], - [is_sun_studio=yes], - [is_sun_studio=no]) -ac_cv_[]_AC_LANG_ABBREV[]_sun_studio_compiler=$is_sun_studio + [ac_zmq_cv_[]_AC_LANG_ABBREV[]_sun_studio_compiler="yes" ; $1], + [ac_zmq_cv_[]_AC_LANG_ABBREV[]_sun_studio_compiler="no" ; $2]) ])]) dnl ############################################################################## -dnl # AC_CHECK_DOC_BUILD # +dnl # AC_ZMQ_CHECK_LANG_CLANG([action-if-found], [action-if-not-found]) # +dnl # Check if the current language is compiled using clang # +dnl ############################################################################## +AC_DEFUN([AC_ZMQ_CHECK_LANG_CLANG], + [AC_CACHE_CHECK([whether we are using clang _AC_LANG compiler], + [ac_zmq_cv_[]_AC_LANG_ABBREV[]_clang_compiler], + [_AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], +[[#ifndef __clang__ + error if not clang +#endif +]])], + [ac_zmq_cv_[]_AC_LANG_ABBREV[]_clang_compiler="yes" ; $1], + [ac_zmq_cv_[]_AC_LANG_ABBREV[]_clang_compiler="no" ; $2]) +])]) + +dnl ############################################################################## +dnl # AC_ZMQ_CHECK_DOC_BUILD # dnl # Check whether to build documentation and install man-pages # dnl ############################################################################## -AC_DEFUN([AC_CHECK_DOC_BUILD], [{ +AC_DEFUN([AC_ZMQ_CHECK_DOC_BUILD], [{ # Allow user to disable doc build AC_ARG_WITH([documentation], [AS_HELP_STRING([--without-documentation], [disable documentation build even if asciidoc and xmlto are present [default=no]])]) if test "x$with_documentation" = "xno"; then - build_doc="no" - install_man="no" + ac_zmq_build_doc="no" + ac_zmq_install_man="no" else # Determine whether or not documentation should be built and installed. - build_doc="yes" - install_man="yes" + ac_zmq_build_doc="yes" + ac_zmq_install_man="yes" # Check for asciidoc and xmlto and don't build the docs if these are not installed. - AC_CHECK_PROG(have_asciidoc, asciidoc, yes, no) - AC_CHECK_PROG(have_xmlto, xmlto, yes, no) - if test "x$have_asciidoc" = "xno" -o "x$have_xmlto" = "xno"; then - build_doc="no" + AC_CHECK_PROG(ac_zmq_have_asciidoc, asciidoc, yes, no) + AC_CHECK_PROG(ac_zmq_have_xmlto, xmlto, yes, no) + if test "x$ac_zmq_have_asciidoc" = "xno" -o "x$ac_zmq_have_xmlto" = "xno"; then + ac_zmq_build_doc="no" # Tarballs built with 'make dist' ship with prebuilt documentation. if ! test -f doc/zmq.7; then - install_man="no" + ac_zmq_install_man="no" AC_MSG_WARN([You are building an unreleased version of 0MQ and asciidoc or xmlto are not installed.]) AC_MSG_WARN([Documentation will not be built and manual pages will not be installed.]) fi fi # Do not install man pages if on mingw - if test "x$on_mingw32" = "xyes"; then - install_man="no" + if test "x$ac_zmq_on_mingw32" = "xyes"; then + ac_zmq_install_man="no" fi fi AC_MSG_CHECKING([whether to build documentation]) - AC_MSG_RESULT([$build_doc]) + AC_MSG_RESULT([$ac_zmq_build_doc]) AC_MSG_CHECKING([whether to install manpages]) - AC_MSG_RESULT([$install_man]) + AC_MSG_RESULT([$ac_zmq_install_man]) - AM_CONDITIONAL(BUILD_DOC, test "x$build_doc" = "xyes") - AM_CONDITIONAL(INSTALL_MAN, test "x$install_man" = "xyes") + AM_CONDITIONAL(BUILD_DOC, test "x$ac_zmq_build_doc" = "xyes") + AM_CONDITIONAL(INSTALL_MAN, test "x$ac_zmq_install_man" = "xyes") }]) dnl ############################################################################## -dnl # AC_CHECK_LANG_COMPILER # +dnl # AC_ZMQ_CHECK_LANG_COMPILER([action-if-found], [action-if-not-found]) # dnl # Check that compiler for the current language actually works # dnl ############################################################################## -AC_DEFUN([AC_CHECK_LANG_COMPILER], [{ +AC_DEFUN([AC_ZMQ_CHECK_LANG_COMPILER], [{ # Test that compiler for the current language actually works AC_CACHE_CHECK([whether the _AC_LANG compiler works], - [ac_cv_[]_AC_LANG_ABBREV[]_compiler_works], + [ac_zmq_cv_[]_AC_LANG_ABBREV[]_compiler_works], [AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])], - [ac_cv_[]_AC_LANG_ABBREV[]_compiler_works=yes], - [ac_cv_[]_AC_LANG_ABBREV[]_compiler_works=no]) + [ac_zmq_cv_[]_AC_LANG_ABBREV[]_compiler_works="yes" ; $1], + [ac_zmq_cv_[]_AC_LANG_ABBREV[]_compiler_works="no" ; $2]) ]) - if test "x$ac_cv_[]_AC_LANG_ABBREV[]_compiler_works" != "xyes"; then + if test "x$ac_zmq_cv_[]_AC_LANG_ABBREV[]_compiler_works" != "xyes"; then AC_MSG_ERROR([Unable to find a working _AC_LANG compiler]) fi }]) + +dnl ############################################################################## +dnl # AC_ZMQ_CHECK_COMPILERS # +dnl # Check compiler characteristics. This is so that we can AC_REQUIRE checks # +dnl ############################################################################## +AC_DEFUN([AC_ZMQ_CHECK_COMPILERS], [{ + # For that the compiler works and try to come up with the type + AC_LANG_PUSH([C]) + AC_ZMQ_CHECK_LANG_COMPILER + + AC_ZMQ_CHECK_LANG_ICC + AC_ZMQ_CHECK_LANG_SUN_STUDIO + AC_ZMQ_CHECK_LANG_CLANG + AC_LANG_POP([C]) + + AC_LANG_PUSH(C++) + AC_ZMQ_CHECK_LANG_COMPILER + + AC_ZMQ_CHECK_LANG_ICC + AC_ZMQ_CHECK_LANG_SUN_STUDIO + AC_ZMQ_CHECK_LANG_CLANG + AC_LANG_POP([C++]) + + # Set GCC and GXX variables correctly + if test "x$GCC" = "xyes"; then + if test "xyes" = "x$ac_zmq_cv_c_intel_compiler"; then + GCC="no" + fi + fi + + if test "x$GXX" = "xyes"; then + if test "xyes" = "x$ac_zmq_cv_cxx_intel_compiler"; then + GXX="no" + fi + fi +}]) + +dnl ############################################################################ +dnl # AC_ZMQ_CHECK_LANG_FLAG([flag], [action-if-found], [action-if-not-found]) # +dnl # Check if the compiler supports given flag. Works for C and C++ # +dnl # Sets ac_zmq_cv_[]_AC_LANG_ABBREV[]_supports_flag_[FLAG]=yes/no # +dnl ############################################################################ +AC_DEFUN([AC_ZMQ_CHECK_LANG_FLAG], [{ + + AC_MSG_CHECKING([whether _AC_LANG compiler supports $1]) + + ac_zmq_cv_[]_AC_LANG_ABBREV[]_werror_flag_save=$ac_c_werror_flag + ac_[]_AC_LANG_ABBREV[]_werror_flag="yes" + + case "x[]_AC_LANG_ABBREV" in + xc) + ac_zmq_cv_check_lang_flag_save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $1" + ;; + xcxx) + ac_zmq_cv_check_lang_flag_save_CPPFLAGS="$CPPFLAGS" + CPPFLAGS="$CPPFLAGS $1" + ;; + *) + AC_MSG_WARN([testing compiler characteristic on an unknown language]) + ;; + esac + + AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], + # This hack exist for ICC, which outputs unknown options as remarks + # Remarks are not turned into errors even with -Werror on + [if (grep 'ignoring unknown' conftest.err || + grep 'not supported' conftest.err) >/dev/null 2>&1; then + eval AS_TR_SH(ac_zmq_cv_[]_AC_LANG_ABBREV[]_supports_flag_$1)="no" + else + eval AS_TR_SH(ac_zmq_cv_[]_AC_LANG_ABBREV[]_supports_flag_$1)="yes" + fi], + [eval AS_TR_SH(ac_zmq_cv_[]_AC_LANG_ABBREV[]_supports_flag_$1)="no"]) + + case "x[]_AC_LANG_ABBREV" in + xc) + CFLAGS="$ac_zmq_cv_check_lang_flag_save_CFLAGS" + ;; + xcxx) + CPPFLAGS="$ac_zmq_cv_check_lang_flag_save_CPPFLAGS" + ;; + *) + # nothing to restore + ;; + esac + + # Restore the werror flag + ac_[]_AC_LANG_ABBREV[]_werror_flag=$ac_zmq_cv_[]_AC_LANG_ABBREV[]_werror_flag_save + + # Call the action as the flags are restored + AS_IF([eval test x$]AS_TR_SH(ac_zmq_cv_[]_AC_LANG_ABBREV[]_supports_flag_$1)[ = "xyes"], + [AC_MSG_RESULT(yes) ; $2], [AC_MSG_RESULT(no) ; $3]) + +}]) + +dnl #################################################################################### +dnl # AC_ZMQ_CHECK_LANG_FLAG_PREPEND([flag], [action-if-found], [action-if-not-found]) # +dnl # Check if the compiler supports given flag. Works for C and C++ # +dnl # This macro prepends the flag to CFLAGS or CPPFLAGS accordingly # +dnl # Sets ac_zmq_cv_[]_AC_LANG_ABBREV[]_supports_flag_[FLAG]=yes/no # +dnl #################################################################################### +AC_DEFUN([AC_ZMQ_CHECK_LANG_FLAG_PREPEND], [{ + AC_ZMQ_CHECK_LANG_FLAG([$1]) + case "x[]_AC_LANG_ABBREV" in + xc) + AS_IF([eval test x$]AS_TR_SH(ac_zmq_cv_[]_AC_LANG_ABBREV[]_supports_flag_$1)[ = "xyes"], + [CFLAGS="$1 $CFLAGS"; $2], $3) + ;; + xcxx) + AS_IF([eval test x$]AS_TR_SH(ac_zmq_cv_[]_AC_LANG_ABBREV[]_supports_flag_$1)[ = "xyes"], + [CPPFLAGS="$1 $CPPFLAGS"; $2], $3) + ;; + esac +}]) + +dnl ############################################################################## +dnl # AC_ZMQ_CHECK_ENABLE_DEBUG([action-if-found], [action-if-not-found]) # +dnl # Check whether to enable debug build and set compiler flags accordingly # +dnl ############################################################################## +AC_DEFUN([AC_ZMQ_CHECK_ENABLE_DEBUG], [{ + + # Require compiler specifics + AC_REQUIRE([AC_ZMQ_CHECK_COMPILERS]) + + # This flag is checked also in + AC_ARG_ENABLE([debug], [AS_HELP_STRING([--enable-debug], + [Enable debugging information [default=no]])]) + + AC_MSG_CHECKING(whether to enable debugging information) + + if test "x$enable_debug" = "xyes"; then + + # GCC, clang and ICC + if test "x$GCC" = "xyes" -o \ + "x$ac_zmq_cv_c_intel_compiler" = "xyes" -o \ + "x$ac_zmq_cv_c_clang_compiler" = "xyes"; then + CFLAGS="-g -O0 " + elif test "x$ac_zmq_cv_c_sun_studio_compiler" = "xyes"; then + CFLAGS="-g0 " + fi + + # GCC, clang and ICC + if test "x$GXX" = "xyes" -o \ + "x$ac_zmq_cv_cxx_intel_compiler" = "xyes" -o \ + "x$ac_zmq_cv_cxx_clang_compiler" = "xyes"; then + CPPFLAGS="-g -O0 " + CXXFLAGS="-g -O0 " + # Sun studio + elif test "x$ac_zmq_cv_cxx_sun_studio_compiler" = "xyes"; then + CPPFLAGS="-g0 " + CXXFLAGS="-g0 " + fi + + if test "x$LOCAL_CFLAGS" != "xnone"; then + CFLAGS="${CFLAGS} ${LOCAL_CFLAGS}" + fi + if test "x$LOCAL_CPPFLAGS" != "xnone"; then + CPPFLAGS="${CPPFLAGS} ${LOCAL_CPPFLAGS}" + fi + if test "x$LOCAL_CXXFLAGS" != "xnone"; then + CXXFLAGS="${CXXFLAGS} ${LOCAL_CXXFLAGS}" + fi + AC_MSG_RESULT(yes) + else + AC_MSG_RESULT(no) + fi +}]) + +dnl ############################################################################## +dnl # AC_ZMQ_CHECK_WITH_FLAG([flags], [macro]) # +dnl # Runs a normal autoconf check with compiler flags # +dnl ############################################################################## +AC_DEFUN([AC_ZMQ_CHECK_WITH_FLAG], [{ + ac_zmq_check_with_flag_save_CFLAGS="$CFLAGS" + ac_zmq_check_with_flag_save_CPPFLAGS="$CPPFLAGS" + + CFLAGS="$CFLAGS $1" + CPPFLAGS="$CPPFLAGS $1" + + # Execute the macro + $2 + + CFLAGS="$ac_zmq_check_with_flag_save_CFLAGS" + CPPFLAGS="$ac_zmq_check_with_flag_save_CPPFLAGS" +}]) + +dnl ############################################################################## +dnl # AC_ZMQ_LANG_WALL([action-if-found], [action-if-not-found]) # +dnl # How to define -Wall for the current compiler # +dnl # Sets ac_zmq_cv_[]_AC_LANG_ABBREV[]__wall_flag variable to found style # +dnl ############################################################################## +AC_DEFUN([AC_ZMQ_LANG_WALL], [{ + + AC_MSG_CHECKING([how to enable additional warnings for _AC_LANG compiler]) + + ac_zmq_cv_[]_AC_LANG_ABBREV[]_wall_flag="" + + # C compilers + case "x[]_AC_LANG_ABBREV" in + xc) + # GCC, clang and ICC + if test "x$GCC" = "xyes" -o \ + "x$ac_zmq_cv_[]_AC_LANG_ABBREV[]_intel_compiler" = "xyes" -o \ + "x$ac_zmq_cv_[]_AC_LANG_ABBREV[]_clang_compiler" = "xyes"; then + ac_zmq_cv_[]_AC_LANG_ABBREV[]_wall_flag="-Wall" + # Sun studio + elif test "x$ac_zmq_cv_[]_AC_LANG_ABBREV[]_sun_studio_compiler" = "xyes"; then + ac_zmq_cv_[]_AC_LANG_ABBREV[]_wall_flag="-v" + fi + ;; + xcxx) + # GCC, clang and ICC + if test "x$GXX" = "xyes" -o \ + "x$ac_zmq_cv_[]_AC_LANG_ABBREV[]_intel_compiler" = "xyes" -o \ + "x$ac_zmq_cv_[]_AC_LANG_ABBREV[]_clang_compiler" = "xyes"; then + ac_zmq_cv_[]_AC_LANG_ABBREV[]_wall_flag="-Wall" + # Sun studio + elif test "x$ac_zmq_cv_[]_AC_LANG_ABBREV[]_sun_studio_compiler" = "xyes"; then + ac_zmq_cv_[]_AC_LANG_ABBREV[]_wall_flag="+w" + fi + ;; + *) + ;; + esac + + # Call the action + if test "x$ac_zmq_cv_[]_AC_LANG_ABBREV[]_wall_flag" != "x"; then + AC_MSG_RESULT([$ac_zmq_cv_[]_AC_LANG_ABBREV[]_wall_flag]) + $1 + else + AC_MSG_RESULT([not found]) + $2 + fi +}]) + +dnl #################################################################### +dnl # AC_ZMQ_LANG_STRICT([action-if-found], [action-if-not-found]) # +dnl # Check how to turn on strict standards compliance # +dnl #################################################################### +AC_DEFUN([AC_ZMQ_LANG_STRICT], [{ + AC_MSG_CHECKING([how to enable strict standards compliance in _AC_LANG compiler]) + + ac_zmq_cv_[]_AC_LANG_ABBREV[]_strict_flag="" + + # C compilers + case "x[]_AC_LANG_ABBREV" in + xc) + # GCC, clang and ICC + if test "x$GCC" = "xyes" -o "x$ac_zmq_cv_[]_AC_LANG_ABBREV[]_clang_compiler" = "xyes"; then + ac_zmq_cv_[]_AC_LANG_ABBREV[]_strict_flag="-pedantic" + elif test "x$ac_zmq_cv_[]_AC_LANG_ABBREV[]_intel_compiler" = "xyes"; then + ac_zmq_cv_[]_AC_LANG_ABBREV[]_strict_flag="-strict-ansi" + # Sun studio + elif test "x$ac_zmq_cv_[]_AC_LANG_ABBREV[]_sun_studio_compiler" = "xyes"; then + ac_zmq_cv_[]_AC_LANG_ABBREV[]_strict_flag="-Xc" + fi + ;; + xcxx) + # GCC, clang and ICC + if test "x$GXX" = "xyes" -o "x$ac_zmq_cv_[]_AC_LANG_ABBREV[]_clang_compiler" = "xyes"; then + ac_zmq_cv_[]_AC_LANG_ABBREV[]_strict_flag="-pedantic" + elif test "x$ac_zmq_cv_[]_AC_LANG_ABBREV[]_intel_compiler" = "xyes"; then + ac_zmq_cv_[]_AC_LANG_ABBREV[]_strict_flag="-strict-ansi" + # Sun studio + elif test "x$ac_zmq_cv_[]_AC_LANG_ABBREV[]_sun_studio_compiler" = "xyes"; then + ac_zmq_cv_[]_AC_LANG_ABBREV[]_strict_flag="-compat=5" + fi + ;; + *) + ;; + esac + + # Call the action + if test "x$ac_zmq_cv_[]_AC_LANG_ABBREV[]_strict_flag" != "x"; then + AC_MSG_RESULT([$ac_zmq_cv_[]_AC_LANG_ABBREV[]_strict_flag]) + $1 + else + AC_MSG_RESULT([not found]) + $2 + fi +}]) + +dnl ######################################################################## +dnl # AC_ZMQ_LANG_WERROR([action-if-found], [action-if-not-found]) # +dnl # Check how to turn warnings to errors # +dnl ######################################################################## +AC_DEFUN([AC_ZMQ_LANG_WERROR], [{ + AC_MSG_CHECKING([how to turn warnings to errors in _AC_LANG compiler]) + + ac_zmq_cv_[]_AC_LANG_ABBREV[]_werror_flag="" + + # C compilers + case "x[]_AC_LANG_ABBREV" in + xc) + # GCC, clang and ICC + if test "x$GCC" = "xyes" -o "x$ac_zmq_cv_[]_AC_LANG_ABBREV[]_intel_compiler" = "xyes"; then + ac_zmq_cv_[]_AC_LANG_ABBREV[]_werror_flag="-Werror" + # Sun studio + elif test "x$ac_zmq_cv_[]_AC_LANG_ABBREV[]_sun_studio_compiler" = "xyes"; then + ac_zmq_cv_[]_AC_LANG_ABBREV[]_werror_flag="-errwarn=%all" + fi + ;; + xcxx) + # GCC, clang and ICC + if test "x$GXX" = "xyes" -o "x$ac_zmq_cv_[]_AC_LANG_ABBREV[]_intel_compiler" = "xyes"; then + ac_zmq_cv_[]_AC_LANG_ABBREV[]_werror_flag="-Werror" + # Sun studio + elif test "x$ac_zmq_cv_[]_AC_LANG_ABBREV[]_sun_studio_compiler" = "xyes"; then + ac_zmq_cv_[]_AC_LANG_ABBREV[]_werror_flag="-errwarn=%all" + fi + ;; + *) + ;; + esac + + # Call the action + if test "x$ac_zmq_cv_[]_AC_LANG_ABBREV[]_werror_flag" != "x"; then + AC_MSG_RESULT([$ac_zmq_cv_[]_AC_LANG_ABBREV[]_werror_flag]) + $1 + else + AC_MSG_RESULT([not found]) + $2 + fi +}]) + +dnl ################################################################################ +dnl # AC_ZMQ_CHECK_LANG_PRAGMA([pragma], [action-if-found], [action-if-not-found]) # +dnl # Check if the compiler supports given pragma # +dnl ################################################################################ +AC_DEFUN([AC_ZMQ_CHECK_LANG_PRAGMA], [{ + # Need to know how to enable all warnings + AC_ZMQ_LANG_WALL + + AC_MSG_CHECKING([whether _AC_LANG compiler supports pragma $1]) + + # Save flags + ac_zmq_cv_[]_AC_LANG_ABBREV[]_werror_flag_save=$ac_[]_AC_LANG_ABBREV[]_werror_flag + ac_[]_AC_LANG_ABBREV[]_werror_flag="yes" + + if test "x[]_AC_LANG_ABBREV" = "xc"; then + ac_zmq_cv_check_lang_pragma_save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $ac_zmq_cv_[]_AC_LANG_ABBREV[]_wall_flag" + elif test "x[]_AC_LANG_ABBREV" = "xcxx"; then + ac_zmq_cv_check_lang_pragma_save_CPPFLAGS="$CPPFLAGS" + CPPFLAGS="$CPPFLAGS $ac_zmq_cv_[]_AC_LANG_ABBREV[]_wall_flag" + else + AC_MSG_WARN([testing compiler characteristic on an unknown language]) + fi + + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[#pragma $1]])], + [eval AS_TR_SH(ac_zmq_cv_[]_AC_LANG_ABBREV[]_supports_pragma_$1)="yes" ; AC_MSG_RESULT(yes)], + [eval AS_TR_SH(ac_zmq_cv_[]_AC_LANG_ABBREV[]_supports_pragma_$1)="no" ; AC_MSG_RESULT(no)]) + + if test "x[]_AC_LANG_ABBREV" = "xc"; then + CFLAGS="$ac_zmq_cv_check_lang_pragma_save_CFLAGS" + elif test "x[]_AC_LANG_ABBREV" = "xcxx"; then + CPPFLAGS="$ac_zmq_cv_check_lang_pragma_save_CPPFLAGS" + fi + + ac_[]_AC_LANG_ABBREV[]_werror_flag=$ac_zmq_cv_[]_AC_LANG_ABBREV[]_werror_flag_save + + # Call the action as the flags are restored + AS_IF([eval test x$]AS_TR_SH(ac_zmq_cv_[]_AC_LANG_ABBREV[]_supports_pragma_$1)[ = "xyes"], + [$2], [$3]) +}]) diff --git a/autogen.sh b/autogen.sh index cab10da..b14e278 100755 --- a/autogen.sh +++ b/autogen.sh @@ -18,12 +18,6 @@ # Script to generate all required files from fresh git checkout. -command -v pkg-config >/dev/null 2>&1 -if [ $? -ne 0 ]; then - echo "autogen.sh: error: could not find pkg-config. pkg-config is required to run autogen.sh." 1>&2 - exit 1 -fi - command -v libtool >/dev/null 2>&1 if [ $? -ne 0 ]; then echo "autogen.sh: error: could not find libtool. libtool is required to run autogen.sh." 1>&2 diff --git a/configure.in b/configure.in index b7d524a..f5dd28d 100644 --- a/configure.in +++ b/configure.in @@ -6,7 +6,7 @@ AC_PREREQ(2.61) # the version.sh script. Hence, it should be updated there. # The version in git should reflect the *next* version planned. # -AC_INIT([zeromq],[m4_esyscmd(./version.sh | tr -d '\n')],[zeromq-dev@lists.zeromq.org]) +AC_INIT([zeromq],[m4_esyscmd([./version.sh | tr -d '\n'])],[zeromq-dev@lists.zeromq.org]) AC_CONFIG_AUX_DIR(config) AC_CONFIG_MACRO_DIR(config) @@ -34,70 +34,37 @@ AM_PROG_CC_C_O AC_PROG_SED AC_PROG_AWK -# Host specific checks -AC_CANONICAL_HOST - # Libtool configuration for different targets. See acinclude.m4 -AC_CONFIG_LIBTOOL +AC_ZMQ_CONFIG_LIBTOOL AC_LIBTOOL_WIN32_DLL AC_PROG_LIBTOOL -# For that the compiler works and try to come up with the type -AC_LANG(C) -AC_CHECK_LANG_COMPILER - -AC_CHECK_LANG_ICC -AC_CHECK_LANG_SUN_STUDIO - -AC_LANG(C++) -AC_CHECK_LANG_COMPILER - -AC_CHECK_LANG_ICC -AC_CHECK_LANG_SUN_STUDIO +# Check whether to build a with debug symbols +AC_ZMQ_CHECK_ENABLE_DEBUG # Checks for libraries. AC_CHECK_LIB([pthread], [pthread_create]) -# Extra CFLAGS are appended at the end of CFLAGS for pgm. -LIBZMQ_EXTRA_CFLAGS="" - -# Extra CXXFLAGS are appended at the end of CXXFLAGS for libzmq. -LIBZMQ_EXTRA_CXXFLAGS="" - -# Extra LDFLAGS are appended at the end of LDFLAGS for libzmq. -LIBZMQ_EXTRA_LDFLAGS="" - -# Set a helper variable to indicate GNU C and C++ are in use -if test "x$GCC" = "xyes" -a "x$GXX" = "xyes"; then - gnu_compilers="yes" - - # ICC is detected as GNU compiler, make sure that it's not being used as one - if test "xyes" = "x$ac_cv_c_intel_compiler" -o "xyes" = "x$ac_cv_cpp_intel_compiler"; then - gnu_compilers="no" - fi -else - gnu_compilers="no" -fi - -# Set pedantic when using GNU compilers -if test "x$gnu_compilers" = "xyes"; then - pedantic="yes" -fi +# Set pedantic +ac_zmq_pedantic="yes" # By default compiling with -Werror except OSX. -werror="yes" +ac_zmq_werror="yes" # Whether we are on mingw or not. -on_mingw32="no" +ac_zmq_on_mingw32="no" # Set some default features required by 0MQ code. CPPFLAGS="-D_REENTRANT -D_THREAD_SAFE $CPPFLAGS" +# For host type checks +AC_CANONICAL_HOST + # OS-specific tests case "${host_os}" in *linux*) # Define on Linux to enable all library features. Define if using a gnu compiler - if test "x$gnu_compilers" = "xyes"; then + if test "x$GXX" = "xyes"; then CPPFLAGS="-D_GNU_SOURCE $CPPFLAGS" fi AC_DEFINE(ZMQ_HAVE_LINUX, 1, [Have Linux OS]) @@ -136,10 +103,12 @@ case "${host_os}" in *darwin*) # Define on Darwin to enable all library features CPPFLAGS="-D_DARWIN_C_SOURCE $CPPFLAGS" - pedantic="no" - werror="no" + ac_zmq_pedantic="no" + ac_zmq_werror="no" AC_DEFINE(ZMQ_HAVE_OSX, 1, [Have DarwinOSX OS]) - LIBZMQ_EXTRA_CXXFLAGS+="-Wno-uninitialized" + AC_LANG_PUSH([C++]) + AC_ZMQ_CHECK_LANG_FLAG_PREPEND([-Wno-uninitialized]) + AC_LANG_POP([C++]) ;; *netbsd*) # Define on NetBSD to enable all library features @@ -148,7 +117,7 @@ case "${host_os}" in # NetBSD 5.0 and newer provides atomic operations but we can # only use these on systems where PR #42842 has been fixed so # we must try and link a test program using C++. - netbsd_has_atomic=no + ac_zmq_netbsd_has_atomic=no AC_MSG_CHECKING([whether atomic operations can be used]) AC_LANG_PUSH([C++]) AC_LINK_IFELSE([AC_LANG_PROGRAM( @@ -156,11 +125,11 @@ case "${host_os}" in [[uint32_t value; atomic_cas_32 (&value, 0, 0); return 0;]])], - [netbsd_has_atomic=yes], - [netbsd_has_atomic=no]) + [ac_zmq_netbsd_has_atomic=yes], + [ac_zmq_netbsd_has_atomic=no]) AC_LANG_POP([C++]) - AC_MSG_RESULT([$netbsd_has_atomic]) - if test "x$netbsd_has_atomic" = "xno"; then + AC_MSG_RESULT([$ac_zmq_netbsd_has_atomic]) + if test "x$ac_zmq_netbsd_has_atomic" = "xno"; then AC_DEFINE(ZMQ_FORCE_MUTEXES, 1, [Force to use mutexes]) fi ;; @@ -170,7 +139,7 @@ case "${host_os}" in AC_DEFINE(ZMQ_HAVE_OPENBSD, 1, [Have OpenBSD OS]) ;; *nto-qnx*) - pedantic="no" + ac_zmq_pedantic="no" AC_DEFINE(ZMQ_HAVE_QNXNTO, 1, [Have QNX Neutrino OS]) AC_CHECK_LIB(socket, socket) AC_CHECK_LIB(crypto, RAND_bytes) @@ -181,7 +150,7 @@ case "${host_os}" in ;; *hpux*) # Define on HP-UX to enable all library features - CPPFLAGS="-D_POSIX_C_SOURCE=200112L" + CPPFLAGS="-D_POSIX_C_SOURCE=200112L $CPPFLAGS" AC_DEFINE(ZMQ_HAVE_HPUX, 1, [Have HPUX OS]) AC_CHECK_LIB(rt, sem_init) AC_CHECK_LIB(crypto, RAND_bytes) @@ -197,8 +166,10 @@ case "${host_os}" in AC_CHECK_LIB(iphlpapi, main, , [AC_MSG_ERROR([cannot link with iphlpapi.dll.])]) # mingw32 defines __int64_t as long long - CPPFLAGS="-Wno-long-long ${CPPFLAGS} " - on_mingw32="yes" + AC_LANG_PUSH([C++]) + AC_ZMQ_CHECK_LANG_FLAG_PREPEND([-Wno-long-long]) + AC_LANG_POP([C++]) + ac_zmq_on_mingw32="yes" if test "x$enable_static" = "xyes"; then AC_MSG_ERROR([Building static libraries is not supported under MinGW32]) @@ -210,7 +181,7 @@ case "${host_os}" in AC_DEFINE(ZMQ_HAVE_CYGWIN, 1, [Have Cygwin]) # Cygwin provides libuuid as part of the e2fsprogs package, and somewhat # uselessly installs the library in /usr/lib/e2fsprogs - LDFLAGS="${LDFLAGS} -L/usr/lib/e2fsprogs" + LDFLAGS="-L/usr/lib/e2fsprogs ${LDFLAGS}" AC_CHECK_LIB(uuid, uuid_generate, , [AC_MSG_ERROR([cannot link with -luuid, install the e2fsprogs package.])]) @@ -223,31 +194,38 @@ case "${host_os}" in ;; esac -# Check if the compiler supports -fvisibility=hidden. If so, use it, but not -# on MinGW32 where we use a separate mechanism (__declspec). -_LT_COMPILER_OPTION([if $compiler supports -fvisibility=hidden], - ac_cv_prog_compiler_visibility, - [-fvisibility=hidden], - [], - [have_dso_visibility=yes]) -if test "x$have_dso_visibility" = "xyes" -a "x$on_mingw32" = "xno"; then - LIBZMQ_EXTRA_CFLAGS="-fvisibility=hidden $LIBZMQ_EXTRA_CFLAGS" - LIBZMQ_EXTRA_CXXFLAGS="-fvisibility=hidden $LIBZMQ_EXTRA_CXXFLAGS" +# +# Check if the compiler supports -fvisibility=hidden flag. MinGW32 uses __declspec +# +if test "x$ac_zmq_on_mingw32" != "xyes"; then + AC_LANG_PUSH([C]) + AC_ZMQ_CHECK_LANG_FLAG([-fvisibility=hidden], + [LIBZMQ_EXTRA_CFLAGS="-fvisibility=hidden ${LIBZMQ_EXTRA_CFLAGS}"], + [AC_ZMQ_CHECK_LANG_FLAG([-xldscope=hidden], + [LIBZMQ_EXTRA_CFLAGS="-xldscope=hidden ${LIBZMQ_EXTRA_CFLAGS}"])]) + AC_LANG_POP([C]) + + AC_LANG_PUSH([C++]) + AC_ZMQ_CHECK_LANG_FLAG([-fvisibility=hidden], + [LIBZMQ_EXTRA_CXXFLAGS="-fvisibility=hidden ${LIBZMQ_EXTRA_CXXFLAGS}"], + [AC_ZMQ_CHECK_LANG_FLAG([-xldscope=hidden], + [LIBZMQ_EXTRA_CXXFLAGS="-xldscope=hidden ${LIBZMQ_EXTRA_CXXFLAGS}"])]) + AC_LANG_POP([C++]) fi # CPU-specific optimizations case "${host_cpu}" in *sparc*) - if test "x$gnu_compilers" = "xyes"; then - CPPFLAGS="$CPPFLAGS -mcpu=v9" - fi + AC_LANG_PUSH([C++]) + AC_ZMQ_CHECK_LANG_FLAG_PREPEND([-mcpu=v9]) + AC_LANG_POP([C++]) ;; *) ;; esac # Check whether to build docs / install man pages -AC_CHECK_DOC_BUILD +AC_ZMQ_CHECK_DOC_BUILD # Checks for header files. AC_HEADER_STDC @@ -258,29 +236,27 @@ stdlib.h string.h sys/socket.h sys/time.h unistd.h limits.h) AC_CHECK_HEADERS(ifaddrs.h, [AC_DEFINE(ZMQ_HAVE_IFADDRS, 1, [Have ifaddrs.h header.])]) # Use c++ in subsequent tests -AC_LANG(C++) - -# pkg-config is used if found, however, we need to provide a way to disable it -# entirely when the user knows what she's doing and it's use is undesirable, -# such as when cross-compiling. -AC_ARG_WITH([pkg-config], [AS_HELP_STRING([--without-pkg-config], - [do not use pkg-config [default=no]])]) -if test "x$with_pkg_config" != "xno"; then - AC_CHECK_PROG(have_pkg_config, pkg-config, yes, no) -fi +AC_LANG_PUSH(C++) -# Checks for typedefs, structures, and compiler characteristics. AC_HEADER_STDBOOL AC_C_CONST AC_C_INLINE -AC_TYPE_SIZE_T -AC_TYPE_SSIZE_T +# Checks for typedefs, structures, and compiler characteristics. +if test "x$ac_zmq_cv_[]_AC_LANG_ABBREV[]_intel_compiler" = "xyes"; then + dnl 279: controlling expression is constant + dnl Fixes build with ICC 12.x + AC_ZMQ_CHECK_WITH_FLAG([-wd279], [AC_TYPE_SIZE_T]) + AC_ZMQ_CHECK_WITH_FLAG([-wd279], [AC_TYPE_SSIZE_T]) +else + AC_TYPE_SIZE_T + AC_TYPE_SSIZE_T +fi AC_HEADER_TIME AC_TYPE_UINT32_T AC_C_VOLATILE # PGM extension -pgm_ext="no" +ac_zmq_pgm_ext="no" pgm_basename="libpgm-5.0.91~dfsg" @@ -310,31 +286,38 @@ if test "x$with_pgm_ext" != "xno"; then # ... and on Linux/Windows/Solaris/FreeBSD/OSX systems. case "${host_os}" in *linux*|*mingw32*|*solaris*|*freebsd*|*darwin*) - if test "x$gnu_compilers" = "xyes"; then - LIBZMQ_EXTRA_CXXFLAGS="${LIBZMQ_EXTRA_CXXFLAGS} -Wno-variadic-macros -Wno-long-long " - elif test "x$ac_cv_c_intel_compiler" = "xyes"; then - LIBZMQ_EXTRA_CFLAGS="-strict-ansi -Dasm=__asm__ " - elif test "x$ac_cv_c_sun_studio_compiler" = "xyes"; then - LIBZMQ_EXTRA_CFLAGS="-Xc -Dasm=__asm__ " + AC_MSG_RESULT([yes]) + + AC_LANG_PUSH([C++]) + AC_ZMQ_CHECK_LANG_FLAG([-Wno-variadic-macros], [LIBZMQ_EXTRA_CXXFLAGS="-Wno-variadic-macros $LIBZMQ_EXTRA_CXXFLAGS"]) + AC_ZMQ_CHECK_LANG_FLAG([-Wno-long-long], [LIBZMQ_EXTRA_CXXFLAGS="-Wno-long-long $LIBZMQ_EXTRA_CXXFLAGS"]) + AC_LANG_POP([C++]) + + AC_LANG_PUSH([C]) + AC_ZMQ_LANG_STRICT([LIBZMQ_EXTRA_CFLAGS="$ac_zmq_cv_[]_AC_LANG_ABBREV[]_strict_flag $LIBZMQ_EXTRA_CFLAGS"]) + + if test "x$ac_zmq_cv_[]_AC_LANG_ABBREV[]_intel_compiler" = "xyes" -o \ + "x$ac_zmq_cv_[]_AC_LANG_ABBREV[]_sun_studio_compiler" = "xyes"; then + LIBZMQ_EXTRA_CFLAGS="-Dasm=__asm__ $LIBZMQ_EXTRA_CFLAGS" fi + AC_LANG_POP([C]) ;; *) AC_MSG_ERROR([the PGM extension is not supported on system ${host_os}.]) ;; esac - AC_MSG_RESULT([yes]) # Gzip, Perl and Python are required duing PGM build - AC_CHECK_PROG(have_gzip, gzip, yes, no) - if test "x$have_gzip" != "xyes"; then + AC_CHECK_PROG(ac_zmq_have_gzip, gzip, yes, no) + if test "x$ac_zmq_have_gzip" != "xyes"; then AC_MSG_ERROR([gzip is required for building the PGM extension.]) fi - AC_CHECK_PROG(have_perl, perl, yes, no) - if test "x$have_perl" != "xyes"; then + AC_CHECK_PROG(ac_zmq_have_perl, perl, yes, no) + if test "x$ac_zmq_have_perl" != "xyes"; then AC_MSG_ERROR([perl is required for building the PGM extension.]) fi - AC_CHECK_PROG(have_python, python, yes, no) - if test "x$have_python" != "xyes"; then + AC_CHECK_PROG(ac_zmq_have_python, python, yes, no) + if test "x$ac_zmq_have_python" != "xyes"; then AC_MSG_ERROR([python is required for building the PGM extension.]) fi @@ -346,25 +329,30 @@ if test "x$with_pgm_ext" != "xno"; then # Success! AC_DEFINE(ZMQ_HAVE_OPENPGM, 1, [Have OpenPGM extension]) - pgm_ext="yes" + ac_zmq_pgm_ext="yes" + + # these break OpenPGM so don't specify them if we are building with it. + ac_zmq_pedantic="no" + ac_zmq_werror="no" fi -# -Wall, -Werror and -pedantic are GNU compiler specific. -# Also, these break OpenPGM so don't specify them if we are building with it. -if test "x$gnu_compilers" = "xyes" -a "x$pgm_ext" = "xno"; then - CPPFLAGS="-Wall $CPPFLAGS" +# Set -Wall, -Werror and -pedantic +AC_LANG_PUSH([C++]) - if test "x$pedantic" = "xyes"; then - CPPFLAGS="-pedantic $CPPFLAGS" - fi +# Check how to enable -Wall +AC_ZMQ_LANG_WALL([CPPFLAGS="$ac_zmq_cv_[]_AC_LANG_ABBREV[]_wall_flag $CPPFLAGS"]) - if test "x$werror" = "xyes"; then - CPPFLAGS="-Werror $CPPFLAGS" - fi +if test "x$ac_zmq_werror" = "xyes" -a "x$ac_zmq_cv_[]_AC_LANG_ABBREV[]_sun_studio_compiler" != "xyes"; then + AC_ZMQ_LANG_WERROR([CPPFLAGS="$ac_zmq_cv_[]_AC_LANG_ABBREV[]_werror_flag $CPPFLAGS"]) +fi + +if test "x$ac_zmq_pedantic" = "xyes"; then + AC_ZMQ_LANG_STRICT([CPPFLAGS="$ac_zmq_cv_[]_AC_LANG_ABBREV[]_strict_flag $CPPFLAGS"]) fi +AC_LANG_POP([C++]) -AM_CONDITIONAL(BUILD_PGM, test "x$pgm_ext" = "xyes") -AM_CONDITIONAL(ON_MINGW, test "x$on_mingw32" = "xyes") +AM_CONDITIONAL(BUILD_PGM, test "x$ac_zmq_pgm_ext" = "xyes") +AM_CONDITIONAL(ON_MINGW, test "x$ac_zmq_on_mingw32" = "xyes") # Subst LIBZMQ_EXTRA_CFLAGS & CXXFLAGS & LDFLAGS AC_SUBST(LIBZMQ_EXTRA_CFLAGS) diff --git a/include/zmq.h b/include/zmq.h index 7a63253..692f1c1 100644 --- a/include/zmq.h +++ b/include/zmq.h @@ -30,7 +30,7 @@ extern "C" { #include "winsock2.h" #endif -/* Win32 needs special handling for DLL exports */ +/* Handle DSO symbol visibility */ #if defined _WIN32 # if defined DLL_EXPORT # define ZMQ_EXPORT __declspec(dllexport) @@ -38,9 +38,12 @@ extern "C" { # define ZMQ_EXPORT __declspec(dllimport) # endif #else -# define ZMQ_EXPORT -# if defined __GNUC__ && __GNUC__ >= 4 -# pragma GCC visibility push(default) +# if defined __SUNPRO_C || defined __SUNPRO_CC +# define ZMQ_EXPORT __global +# elif (defined __GNUC__ && __GNUC__ >= 4) || defined __INTEL_COMPILER +# define ZMQ_EXPORT __attribute__ ((visibility("default"))) +# else +# define ZMQ_EXPORT # endif #endif @@ -246,9 +249,6 @@ ZMQ_EXPORT int zmq_poll (zmq_pollitem_t *items, int nitems, long timeout); ZMQ_EXPORT int zmq_device (int device, void * insocket, void* outsocket); #undef ZMQ_EXPORT -#if defined __GNUC__ && __GNUC__ >= 4 && !defined _WIN32 -# pragma GCC visibility pop -#endif #ifdef __cplusplus } diff --git a/include/zmq_utils.h b/include/zmq_utils.h index 6d42bf9..4a0d119 100644 --- a/include/zmq_utils.h +++ b/include/zmq_utils.h @@ -24,7 +24,7 @@ extern "C" { #endif -/* Win32 needs special handling for DLL exports */ +/* Handle DSO symbol visibility */ #if defined _WIN32 # if defined DLL_EXPORT # define ZMQ_EXPORT __declspec(dllexport) @@ -32,9 +32,12 @@ extern "C" { # define ZMQ_EXPORT __declspec(dllimport) # endif #else -# define ZMQ_EXPORT -# if defined __GNUC__ && __GNUC__ >= 4 -# pragma GCC visibility push(default) +# if defined __SUNPRO_C || defined __SUNPRO_CC +# define ZMQ_EXPORT __global +# elif (defined __GNUC__ && __GNUC__ >= 4) || defined __INTEL_COMPILER +# define ZMQ_EXPORT __attribute__ ((visibility("default"))) +# else +# define ZMQ_EXPORT # endif #endif @@ -52,9 +55,6 @@ ZMQ_EXPORT unsigned long zmq_stopwatch_stop (void *watch_); ZMQ_EXPORT void zmq_sleep (int seconds_); #undef ZMQ_EXPORT -#if defined __GNUC__ && __GNUC__ >= 4 && !defined _WIN32 -# pragma GCC visibility pop -#endif #ifdef __cplusplus } -- cgit v1.2.3