acinclude.m4 35.8 KB
Newer Older
1
dnl ##############################################################################
2
dnl # LIBZMQ_CONFIG_LIBTOOL                                                      #
3
dnl # Configure libtool. Requires AC_CANONICAL_HOST                              #
Mikko Koppanen's avatar
Mikko Koppanen committed
4
dnl ##############################################################################
5
AC_DEFUN([LIBZMQ_CONFIG_LIBTOOL],  [{
6
    AC_REQUIRE([AC_CANONICAL_HOST])
Mikko Koppanen's avatar
Mikko Koppanen committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

    # Libtool configuration for different targets
    case "${host_os}" in
        *mingw32*|*cygwin*)
            # Disable static build by default
            AC_DISABLE_STATIC
        ;;
        *)
            # Everything else with static enabled
            AC_ENABLE_STATIC
        ;;
    esac
}])

dnl ##############################################################################
22
dnl # LIBZMQ_CHECK_LANG_ICC([action-if-found], [action-if-not-found])            #
23 24 25
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 ##############################################################################
26
AC_DEFUN([LIBZMQ_CHECK_LANG_ICC],
27
          [AC_CACHE_CHECK([whether we are using Intel _AC_LANG compiler],
28
          [libzmq_cv_[]_AC_LANG_ABBREV[]_intel_compiler],
29 30 31 32 33
          [_AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
[[#ifndef __INTEL_COMPILER
       error if not ICC
#endif
]])],
34 35
          [libzmq_cv_[]_AC_LANG_ABBREV[]_intel_compiler="yes" ; $1],
          [libzmq_cv_[]_AC_LANG_ABBREV[]_intel_compiler="no" ; $2])
36
])])
Mikko Koppanen's avatar
Mikko Koppanen committed
37 38

dnl ##############################################################################
39
dnl # LIBZMQ_CHECK_LANG_SUN_STUDIO([action-if-found], [action-if-not-found])     #
Mikko Koppanen's avatar
Mikko Koppanen committed
40 41
dnl # Check if the current language is compiled using Sun Studio                 #
dnl ##############################################################################
42
AC_DEFUN([LIBZMQ_CHECK_LANG_SUN_STUDIO],
Mikko Koppanen's avatar
Mikko Koppanen committed
43
          [AC_CACHE_CHECK([whether we are using Sun Studio _AC_LANG compiler],
44
          [libzmq_cv_[]_AC_LANG_ABBREV[]_sun_studio_compiler],
Mikko Koppanen's avatar
Mikko Koppanen committed
45 46 47 48 49
          [_AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
[[#if !defined(__SUNPRO_CC) && !defined(__SUNPRO_C)
       error if not sun studio
#endif
]])],
50 51
          [libzmq_cv_[]_AC_LANG_ABBREV[]_sun_studio_compiler="yes" ; $1],
          [libzmq_cv_[]_AC_LANG_ABBREV[]_sun_studio_compiler="no" ; $2])
Mikko Koppanen's avatar
Mikko Koppanen committed
52 53 54
])])

dnl ##############################################################################
55
dnl # LIBZMQ_CHECK_LANG_CLANG([action-if-found], [action-if-not-found])          #
56 57
dnl # Check if the current language is compiled using clang                      #
dnl ##############################################################################
58
AC_DEFUN([LIBZMQ_CHECK_LANG_CLANG],
59
          [AC_CACHE_CHECK([whether we are using clang _AC_LANG compiler],
60
          [libzmq_cv_[]_AC_LANG_ABBREV[]_clang_compiler],
61 62 63 64 65
          [_AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
[[#ifndef __clang__
       error if not clang
#endif
]])],
66 67
          [libzmq_cv_[]_AC_LANG_ABBREV[]_clang_compiler="yes" ; $1],
          [libzmq_cv_[]_AC_LANG_ABBREV[]_clang_compiler="no" ; $2])
68 69
])])

Mikko Koppanen's avatar
Mikko Koppanen committed
70
dnl ##############################################################################
Mikko Koppanen's avatar
Mikko Koppanen committed
71
dnl # LIBZMQ_CHECK_LANG_GCC4([action-if-found], [action-if-not-found])           #
Mikko Koppanen's avatar
Mikko Koppanen committed
72 73
dnl # Check if the current language is compiled using clang                      #
dnl ##############################################################################
74
AC_DEFUN([LIBZMQ_CHECK_LANG_GCC4],
Mikko Koppanen's avatar
Mikko Koppanen committed
75
          [AC_CACHE_CHECK([whether we are using gcc >= 4 _AC_LANG compiler],
76
          [libzmq_cv_[]_AC_LANG_ABBREV[]_gcc4_compiler],
Mikko Koppanen's avatar
Mikko Koppanen committed
77 78 79 80 81
          [_AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
[[#if (!defined __GNUC__ || __GNUC__ < 4)
       error if not gcc4 or higher
#endif
]])],
82 83
          [libzmq_cv_[]_AC_LANG_ABBREV[]_gcc4_compiler="yes" ; $1],
          [libzmq_cv_[]_AC_LANG_ABBREV[]_gcc4_compiler="no" ; $2])
Mikko Koppanen's avatar
Mikko Koppanen committed
84 85
])])

86
dnl ##############################################################################
87
dnl # LIBZMQ_CHECK_DOC_BUILD                                                     #
Mikko Koppanen's avatar
Mikko Koppanen committed
88 89
dnl # Check whether to build documentation and install man-pages                 #
dnl ##############################################################################
90
AC_DEFUN([LIBZMQ_CHECK_DOC_BUILD], [{
91 92 93 94 95
    # 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
96 97
        libzmq_build_doc="no"
        libzmq_install_man="no"
98 99
    else
        # Determine whether or not documentation should be built and installed.
100 101
        libzmq_build_doc="yes"
        libzmq_install_man="yes"
102
        # Check for asciidoc and xmlto and don't build the docs if these are not installed.
103 104 105 106
        AC_CHECK_PROG(libzmq_have_asciidoc, asciidoc, yes, no)
        AC_CHECK_PROG(libzmq_have_xmlto, xmlto, yes, no)
        if test "x$libzmq_have_asciidoc" = "xno" -o "x$libzmq_have_xmlto" = "xno"; then
            libzmq_build_doc="no"
107 108
            # Tarballs built with 'make dist' ship with prebuilt documentation.
            if ! test -f doc/zmq.7; then
109
                libzmq_install_man="no"
110 111 112 113 114 115
                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
116 117
        if test "x$libzmq_on_mingw32" = "xyes"; then
            libzmq_install_man="no"
Mikko Koppanen's avatar
Mikko Koppanen committed
118 119 120 121
        fi
    fi

    AC_MSG_CHECKING([whether to build documentation])
122
    AC_MSG_RESULT([$libzmq_build_doc])
Mikko Koppanen's avatar
Mikko Koppanen committed
123 124

    AC_MSG_CHECKING([whether to install manpages])
125
    AC_MSG_RESULT([$libzmq_install_man])
Mikko Koppanen's avatar
Mikko Koppanen committed
126

127 128
    AM_CONDITIONAL(BUILD_DOC, test "x$libzmq_build_doc" = "xyes")
    AM_CONDITIONAL(INSTALL_MAN, test "x$libzmq_install_man" = "xyes")
Mikko Koppanen's avatar
Mikko Koppanen committed
129
}])
130 131

dnl ##############################################################################
132
dnl # LIBZMQ_CHECK_LANG_COMPILER([action-if-found], [action-if-not-found])       #
133 134
dnl # Check that compiler for the current language actually works                #
dnl ##############################################################################
135
AC_DEFUN([LIBZMQ_CHECK_LANG_COMPILER], [{
136 137
    # Test that compiler for the current language actually works
    AC_CACHE_CHECK([whether the _AC_LANG compiler works],
138
                   [libzmq_cv_[]_AC_LANG_ABBREV[]_compiler_works],
139
                   [AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
140 141
                   [libzmq_cv_[]_AC_LANG_ABBREV[]_compiler_works="yes" ; $1],
                   [libzmq_cv_[]_AC_LANG_ABBREV[]_compiler_works="no" ; $2])
142 143
                   ])

144
    if test "x$libzmq_cv_[]_AC_LANG_ABBREV[]_compiler_works" != "xyes"; then
145 146 147
        AC_MSG_ERROR([Unable to find a working _AC_LANG compiler])
    fi
}])
148 149

dnl ##############################################################################
150
dnl # LIBZMQ_CHECK_COMPILERS                                                     #
151 152
dnl # Check compiler characteristics. This is so that we can AC_REQUIRE checks   #
dnl ##############################################################################
153
AC_DEFUN([LIBZMQ_CHECK_COMPILERS], [{
154 155
    # For that the compiler works and try to come up with the type
    AC_LANG_PUSH([C])
156
    LIBZMQ_CHECK_LANG_COMPILER
157

158 159 160 161
    LIBZMQ_CHECK_LANG_ICC
    LIBZMQ_CHECK_LANG_SUN_STUDIO
    LIBZMQ_CHECK_LANG_CLANG
    LIBZMQ_CHECK_LANG_GCC4
162 163 164
    AC_LANG_POP([C])

    AC_LANG_PUSH(C++)
165
    LIBZMQ_CHECK_LANG_COMPILER
166

167 168 169 170
    LIBZMQ_CHECK_LANG_ICC
    LIBZMQ_CHECK_LANG_SUN_STUDIO
    LIBZMQ_CHECK_LANG_CLANG
    LIBZMQ_CHECK_LANG_GCC4
171 172 173 174
    AC_LANG_POP([C++])

    # Set GCC and GXX variables correctly
    if test "x$GCC" = "xyes"; then
175
        if test "xyes" = "x$libzmq_cv_c_intel_compiler"; then
176 177 178 179 180
            GCC="no"
        fi
    fi

    if test "x$GXX" = "xyes"; then
181
        if test "xyes" = "x$libzmq_cv_cxx_intel_compiler"; then
182 183 184 185 186 187
            GXX="no"
        fi
    fi
}])

dnl ############################################################################
188
dnl # LIBZMQ_CHECK_LANG_FLAG([flag], [action-if-found], [action-if-not-found]) #
189
dnl # Check if the compiler supports given flag. Works for C and C++           #
190
dnl # Sets libzmq_cv_[]_AC_LANG_ABBREV[]_supports_flag_[FLAG]=yes/no           #
191
dnl ############################################################################
192
AC_DEFUN([LIBZMQ_CHECK_LANG_FLAG], [{
193

Mikko Koppanen's avatar
Mikko Koppanen committed
194 195
    AC_REQUIRE([AC_PROG_GREP])

196 197
    AC_MSG_CHECKING([whether _AC_LANG compiler supports $1])

198
    libzmq_cv_[]_AC_LANG_ABBREV[]_werror_flag_save=$ac_[]_AC_LANG_ABBREV[]_werror_flag
199 200 201 202
    ac_[]_AC_LANG_ABBREV[]_werror_flag="yes"

    case "x[]_AC_LANG_ABBREV" in
        xc)
203
            libzmq_cv_check_lang_flag_save_CFLAGS="$CFLAGS"
204 205 206
            CFLAGS="$CFLAGS $1"
        ;;
        xcxx)
207
            libzmq_cv_check_lang_flag_save_CPPFLAGS="$CPPFLAGS"
208 209 210 211 212 213 214 215 216 217
            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
Mikko Koppanen's avatar
Mikko Koppanen committed
218 219
                      [if ($GREP 'ignoring unknown' conftest.err ||
                           $GREP 'not supported' conftest.err) >/dev/null 2>&1; then
220
                           eval AS_TR_SH(libzmq_cv_[]_AC_LANG_ABBREV[]_supports_flag_$1)="no"
221
                       else
222
                           eval AS_TR_SH(libzmq_cv_[]_AC_LANG_ABBREV[]_supports_flag_$1)="yes"
223
                       fi],
224
                      [eval AS_TR_SH(libzmq_cv_[]_AC_LANG_ABBREV[]_supports_flag_$1)="no"])
225 226 227

    case "x[]_AC_LANG_ABBREV" in
        xc)
228
            CFLAGS="$libzmq_cv_check_lang_flag_save_CFLAGS"
229 230
        ;;
        xcxx)
231
            CPPFLAGS="$libzmq_cv_check_lang_flag_save_CPPFLAGS"
232 233 234 235 236 237 238
        ;;
        *)
            # nothing to restore
        ;;
    esac

    # Restore the werror flag
239
    ac_[]_AC_LANG_ABBREV[]_werror_flag=$libzmq_cv_[]_AC_LANG_ABBREV[]_werror_flag_save
240 241

    # Call the action as the flags are restored
242
    AS_IF([eval test x$]AS_TR_SH(libzmq_cv_[]_AC_LANG_ABBREV[]_supports_flag_$1)[ = "xyes"],
243 244 245 246 247
          [AC_MSG_RESULT(yes) ; $2], [AC_MSG_RESULT(no) ; $3])

}])

dnl ####################################################################################
248
dnl # LIBZMQ_CHECK_LANG_FLAG_PREPEND([flag], [action-if-found], [action-if-not-found]) #
249 250
dnl # Check if the compiler supports given flag. Works for C and C++                   #
dnl # This macro prepends the flag to CFLAGS or CPPFLAGS accordingly                   #
251
dnl # Sets libzmq_cv_[]_AC_LANG_ABBREV[]_supports_flag_[FLAG]=yes/no                   #
252
dnl ####################################################################################
253 254
AC_DEFUN([LIBZMQ_CHECK_LANG_FLAG_PREPEND], [{
    LIBZMQ_CHECK_LANG_FLAG([$1])
255 256
    case "x[]_AC_LANG_ABBREV" in
       xc)
257
            AS_IF([eval test x$]AS_TR_SH(libzmq_cv_[]_AC_LANG_ABBREV[]_supports_flag_$1)[ = "xyes"],
258 259 260
                  [CFLAGS="$1 $CFLAGS"; $2], $3)
       ;;
       xcxx)
261
            AS_IF([eval test x$]AS_TR_SH(libzmq_cv_[]_AC_LANG_ABBREV[]_supports_flag_$1)[ = "xyes"],
262 263 264 265 266 267
                  [CPPFLAGS="$1 $CPPFLAGS"; $2], $3)
       ;;
    esac
}])

dnl ##############################################################################
268
dnl # LIBZMQ_CHECK_ENABLE_DEBUG([action-if-found], [action-if-not-found])        #
269 270
dnl # Check whether to enable debug build and set compiler flags accordingly     #
dnl ##############################################################################
271
AC_DEFUN([LIBZMQ_CHECK_ENABLE_DEBUG], [{
272 273

    # Require compiler specifics
274
    AC_REQUIRE([LIBZMQ_CHECK_COMPILERS])
275 276 277 278 279 280 281 282 283 284 285

    # 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 \
286 287
                "x$libzmq_cv_c_intel_compiler" = "xyes" -o \
                "x$libzmq_cv_c_clang_compiler" = "xyes"; then
288
            CFLAGS="-g -O0 "
289
        elif test "x$libzmq_cv_c_sun_studio_compiler" = "xyes"; then
290 291 292 293 294
            CFLAGS="-g0 "
        fi

        # GCC, clang and ICC
        if test "x$GXX" = "xyes" -o \
295 296
                "x$libzmq_cv_cxx_intel_compiler" = "xyes" -o \
                "x$libzmq_cv_cxx_clang_compiler" = "xyes"; then
297 298 299
            CPPFLAGS="-g -O0 "
            CXXFLAGS="-g -O0 "
        # Sun studio
300
        elif test "x$libzmq_cv_cxx_sun_studio_compiler" = "xyes"; then
301 302 303 304
            CPPFLAGS="-g0 "
            CXXFLAGS="-g0 "
        fi

305 306
        if test "x$ZMQ_ORIG_CFLAGS" != "xnone"; then
            CFLAGS="${CFLAGS} ${ZMQ_ORIG_CFLAGS}"
307
        fi
308 309
        if test "x$ZMQ_ORIG_CPPFLAGS" != "xnone"; then
            CPPFLAGS="${CPPFLAGS} ${ZMQ_ORIG_CPPFLAGS}"
310
        fi
311 312
        if test "x$ZMQ_ORIG_CXXFLAGS" != "xnone"; then
            CXXFLAGS="${CXXFLAGS} ${ZMQ_ORIG_CXXFLAGS}"
313 314 315 316 317 318 319
        fi
        AC_MSG_RESULT(yes)
    else
        AC_MSG_RESULT(no)
    fi
}])

320
dnl ##############################################################################
321
dnl # LIBZMQ_WITH_GCOV([action-if-found], [action-if-not-found])                 #
322 323
dnl # Check whether to build with code coverage                                  #
dnl ##############################################################################
324
AC_DEFUN([LIBZMQ_WITH_GCOV], [{
325
    # Require compiler specifics
326
    AC_REQUIRE([LIBZMQ_CHECK_COMPILERS])
327 328 329 330 331 332 333

    AC_ARG_WITH(gcov, [AS_HELP_STRING([--with-gcov=yes/no],
                      [With GCC Code Coverage reporting.])],
                      [ZMQ_GCOV="$withval"])

    AC_MSG_CHECKING(whether to enable code coverage)

Mikko Koppanen's avatar
Mikko Koppanen committed
334
    if test "x$ZMQ_GCOV" = "xyes"; then
335

Mikko Koppanen's avatar
Mikko Koppanen committed
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
        if test "x$GXX" != "xyes"; then
            AC_MSG_ERROR([--with-gcov=yes works only with GCC])
        fi

        CFLAGS="-g -O0 -fprofile-arcs -ftest-coverage"
        if test "x${ZMQ_ORIG_CPPFLAGS}" != "xnone"; then
            CFLAGS="${CFLAGS} ${ZMQ_ORIG_CFLAGS}"
        fi

        CPPFLAGS="-g -O0 -fprofile-arcs -ftest-coverage"
        if test "x${ZMQ_ORIG_CPPFLAGS}" != "xnone"; then
            CPPFLAGS="${CPPFLAGS} ${ZMQ_ORIG_CPPFLAGS}"
        fi

        CXXFLAGS="-fprofile-arcs"
        if test "x${ZMQ_ORIG_CXXFLAGS}" != "xnone"; then
            CXXFLAGS="${CXXFLAGS} ${ZMQ_ORIG_CXXFLAGS}"
        fi
354

Mikko Koppanen's avatar
Mikko Koppanen committed
355
        LIBS="-lgcov ${LIBS}"
356 357 358 359 360 361
    fi

    AS_IF([test "x$ZMQ_GCOV" = "xyes"],
          [AC_MSG_RESULT(yes) ; $1], [AC_MSG_RESULT(no) ; $2])
}])

362
dnl ##############################################################################
363
dnl # LIBZMQ_CHECK_WITH_FLAG([flags], [macro])                                   #
364 365
dnl # Runs a normal autoconf check with compiler flags                           #
dnl ##############################################################################
366 367 368
AC_DEFUN([LIBZMQ_CHECK_WITH_FLAG], [{
    libzmq_check_with_flag_save_CFLAGS="$CFLAGS"
    libzmq_check_with_flag_save_CPPFLAGS="$CPPFLAGS"
369 370 371 372 373 374 375

    CFLAGS="$CFLAGS $1"
    CPPFLAGS="$CPPFLAGS $1"

    # Execute the macro
    $2

376 377
    CFLAGS="$libzmq_check_with_flag_save_CFLAGS"
    CPPFLAGS="$libzmq_check_with_flag_save_CPPFLAGS"
378 379 380
}])

dnl ##############################################################################
381
dnl # LIBZMQ_LANG_WALL([action-if-found], [action-if-not-found])                 #
382
dnl # How to define -Wall for the current compiler                               #
383
dnl # Sets libzmq_cv_[]_AC_LANG_ABBREV[]__wall_flag variable to found style      #
384
dnl ##############################################################################
385
AC_DEFUN([LIBZMQ_LANG_WALL], [{
386 387 388

    AC_MSG_CHECKING([how to enable additional warnings for _AC_LANG compiler])

389
    libzmq_cv_[]_AC_LANG_ABBREV[]_wall_flag=""
390 391 392 393 394 395

    # C compilers
    case "x[]_AC_LANG_ABBREV" in
       xc)
            # GCC, clang and ICC
            if test "x$GCC" = "xyes" -o \
396 397 398
                    "x$libzmq_cv_[]_AC_LANG_ABBREV[]_intel_compiler" = "xyes" -o \
                    "x$libzmq_cv_[]_AC_LANG_ABBREV[]_clang_compiler" = "xyes"; then
                libzmq_cv_[]_AC_LANG_ABBREV[]_wall_flag="-Wall"
399
            # Sun studio
400 401
            elif test "x$libzmq_cv_[]_AC_LANG_ABBREV[]_sun_studio_compiler" = "xyes"; then
                libzmq_cv_[]_AC_LANG_ABBREV[]_wall_flag="-v"
402 403 404 405 406
            fi
       ;;
       xcxx)
            # GCC, clang and ICC
            if test "x$GXX" = "xyes" -o \
407 408 409
                    "x$libzmq_cv_[]_AC_LANG_ABBREV[]_intel_compiler" = "xyes" -o \
                    "x$libzmq_cv_[]_AC_LANG_ABBREV[]_clang_compiler" = "xyes"; then
                libzmq_cv_[]_AC_LANG_ABBREV[]_wall_flag="-Wall"
410
            # Sun studio
411 412
            elif test "x$libzmq_cv_[]_AC_LANG_ABBREV[]_sun_studio_compiler" = "xyes"; then
                libzmq_cv_[]_AC_LANG_ABBREV[]_wall_flag="+w"
413 414 415 416 417 418 419
            fi
       ;;
       *)
       ;;
    esac

    # Call the action
420 421
    if test "x$libzmq_cv_[]_AC_LANG_ABBREV[]_wall_flag" != "x"; then
        AC_MSG_RESULT([$libzmq_cv_[]_AC_LANG_ABBREV[]_wall_flag])
422 423 424 425 426 427 428 429
        $1
    else
        AC_MSG_RESULT([not found])
        $2
    fi
}])

dnl ####################################################################
430
dnl # LIBZMQ_LANG_STRICT([action-if-found], [action-if-not-found])     #
431 432
dnl # Check how to turn on strict standards compliance                 #
dnl ####################################################################
433
AC_DEFUN([LIBZMQ_LANG_STRICT], [{
434 435
    AC_MSG_CHECKING([how to enable strict standards compliance in _AC_LANG compiler])

436
    libzmq_cv_[]_AC_LANG_ABBREV[]_strict_flag=""
437 438 439 440 441

    # C compilers
    case "x[]_AC_LANG_ABBREV" in
       xc)
            # GCC, clang and ICC
442 443 444 445
            if test "x$GCC" = "xyes" -o "x$libzmq_cv_[]_AC_LANG_ABBREV[]_clang_compiler" = "xyes"; then
                libzmq_cv_[]_AC_LANG_ABBREV[]_strict_flag="-pedantic"
            elif test "x$libzmq_cv_[]_AC_LANG_ABBREV[]_intel_compiler" = "xyes"; then
                libzmq_cv_[]_AC_LANG_ABBREV[]_strict_flag="-strict-ansi"
446
            # Sun studio
447 448
            elif test "x$libzmq_cv_[]_AC_LANG_ABBREV[]_sun_studio_compiler" = "xyes"; then
                libzmq_cv_[]_AC_LANG_ABBREV[]_strict_flag="-Xc"
449 450 451 452
            fi
       ;;
       xcxx)
            # GCC, clang and ICC
453 454 455 456
            if test "x$GXX" = "xyes" -o "x$libzmq_cv_[]_AC_LANG_ABBREV[]_clang_compiler" = "xyes"; then
                libzmq_cv_[]_AC_LANG_ABBREV[]_strict_flag="-pedantic"
            elif test "x$libzmq_cv_[]_AC_LANG_ABBREV[]_intel_compiler" = "xyes"; then
                libzmq_cv_[]_AC_LANG_ABBREV[]_strict_flag="-strict-ansi"
457
            # Sun studio
458 459
            elif test "x$libzmq_cv_[]_AC_LANG_ABBREV[]_sun_studio_compiler" = "xyes"; then
                libzmq_cv_[]_AC_LANG_ABBREV[]_strict_flag="-compat=5"
460 461 462 463 464 465 466
            fi
       ;;
       *)
       ;;
    esac

    # Call the action
467 468
    if test "x$libzmq_cv_[]_AC_LANG_ABBREV[]_strict_flag" != "x"; then
        AC_MSG_RESULT([$libzmq_cv_[]_AC_LANG_ABBREV[]_strict_flag])
469 470 471 472 473 474 475 476
        $1
    else
        AC_MSG_RESULT([not found])
        $2
    fi
}])

dnl ########################################################################
477
dnl # LIBZMQ_LANG_WERROR([action-if-found], [action-if-not-found])         #
478 479
dnl # Check how to turn warnings to errors                                 #
dnl ########################################################################
480
AC_DEFUN([LIBZMQ_LANG_WERROR], [{
481 482
    AC_MSG_CHECKING([how to turn warnings to errors in _AC_LANG compiler])

483
    libzmq_cv_[]_AC_LANG_ABBREV[]_werror_flag=""
484 485 486 487 488

    # C compilers
    case "x[]_AC_LANG_ABBREV" in
       xc)
            # GCC, clang and ICC
489 490
            if test "x$GCC" = "xyes" -o "x$libzmq_cv_[]_AC_LANG_ABBREV[]_intel_compiler" = "xyes"; then
                libzmq_cv_[]_AC_LANG_ABBREV[]_werror_flag="-Werror"
491
            # Sun studio
492 493
            elif test "x$libzmq_cv_[]_AC_LANG_ABBREV[]_sun_studio_compiler" = "xyes"; then
                libzmq_cv_[]_AC_LANG_ABBREV[]_werror_flag="-errwarn=%all"
494 495 496 497
            fi
       ;;
       xcxx)
            # GCC, clang and ICC
498 499
            if test "x$GXX" = "xyes" -o "x$libzmq_cv_[]_AC_LANG_ABBREV[]_intel_compiler" = "xyes"; then
                libzmq_cv_[]_AC_LANG_ABBREV[]_werror_flag="-Werror"
500
            # Sun studio
501 502
            elif test "x$libzmq_cv_[]_AC_LANG_ABBREV[]_sun_studio_compiler" = "xyes"; then
                libzmq_cv_[]_AC_LANG_ABBREV[]_werror_flag="-errwarn=%all"
503 504 505 506 507 508 509
            fi
       ;;
       *)
       ;;
    esac

    # Call the action
510 511
    if test "x$libzmq_cv_[]_AC_LANG_ABBREV[]_werror_flag" != "x"; then
        AC_MSG_RESULT([$libzmq_cv_[]_AC_LANG_ABBREV[]_werror_flag])
512 513 514 515 516 517 518 519
        $1
    else
        AC_MSG_RESULT([not found])
        $2
    fi
}])

dnl ################################################################################
520
dnl # LIBZMQ_CHECK_LANG_PRAGMA([pragma], [action-if-found], [action-if-not-found]) #
521 522
dnl # Check if the compiler supports given pragma                                  #
dnl ################################################################################
523
AC_DEFUN([LIBZMQ_CHECK_LANG_PRAGMA], [{
524
    # Need to know how to enable all warnings
525
    LIBZMQ_LANG_WALL
526 527 528 529

    AC_MSG_CHECKING([whether _AC_LANG compiler supports pragma $1])

    # Save flags
530
    libzmq_cv_[]_AC_LANG_ABBREV[]_werror_flag_save=$ac_[]_AC_LANG_ABBREV[]_werror_flag
531 532 533
    ac_[]_AC_LANG_ABBREV[]_werror_flag="yes"

    if test "x[]_AC_LANG_ABBREV" = "xc"; then
534 535
        libzmq_cv_check_lang_pragma_save_CFLAGS="$CFLAGS"
        CFLAGS="$CFLAGS $libzmq_cv_[]_AC_LANG_ABBREV[]_wall_flag"
536
    elif test "x[]_AC_LANG_ABBREV" = "xcxx"; then
537 538
        libzmq_cv_check_lang_pragma_save_CPPFLAGS="$CPPFLAGS"
        CPPFLAGS="$CPPFLAGS $libzmq_cv_[]_AC_LANG_ABBREV[]_wall_flag"
539 540 541 542 543
    else
        AC_MSG_WARN([testing compiler characteristic on an unknown language])
    fi

    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[#pragma $1]])],
544 545
                      [eval AS_TR_SH(libzmq_cv_[]_AC_LANG_ABBREV[]_supports_pragma_$1)="yes" ; AC_MSG_RESULT(yes)],
                      [eval AS_TR_SH(libzmq_cv_[]_AC_LANG_ABBREV[]_supports_pragma_$1)="no" ; AC_MSG_RESULT(no)])
546 547

    if test "x[]_AC_LANG_ABBREV" = "xc"; then
548
        CFLAGS="$libzmq_cv_check_lang_pragma_save_CFLAGS"
549
    elif test "x[]_AC_LANG_ABBREV" = "xcxx"; then
550
        CPPFLAGS="$libzmq_cv_check_lang_pragma_save_CPPFLAGS"
551 552
    fi

553
    ac_[]_AC_LANG_ABBREV[]_werror_flag=$libzmq_cv_[]_AC_LANG_ABBREV[]_werror_flag_save
554 555

    # Call the action as the flags are restored
556
    AS_IF([eval test x$]AS_TR_SH(libzmq_cv_[]_AC_LANG_ABBREV[]_supports_pragma_$1)[ = "xyes"],
557 558
          [$2], [$3])
}])
Mikko Koppanen's avatar
Mikko Koppanen committed
559 560

dnl ################################################################################
561
dnl # LIBZMQ_CHECK_LANG_VISIBILITY([action-if-found], [action-if-not-found])       #
Mikko Koppanen's avatar
Mikko Koppanen committed
562 563
dnl # Check if the compiler supports dso visibility                                #
dnl ################################################################################
564 565 566 567 568 569 570 571 572 573 574 575
AC_DEFUN([LIBZMQ_CHECK_LANG_VISIBILITY], [{

    libzmq_cv_[]_AC_LANG_ABBREV[]_visibility_flag=""

    if test "x$libzmq_cv_[]_AC_LANG_ABBREV[]_intel_compiler" = "xyes" -o \
            "x$libzmq_cv_[]_AC_LANG_ABBREV[]_clang_compiler" = "xyes" -o \
            "x$libzmq_cv_[]_AC_LANG_ABBREV[]_gcc4_compiler" = "xyes"; then
        LIBZMQ_CHECK_LANG_FLAG([-fvisibility=hidden],
                               [libzmq_cv_[]_AC_LANG_ABBREV[]_visibility_flag="-fvisibility=hidden"])
    elif test "x$libzmq_cv_[]_AC_LANG_ABBREV[]_sun_studio_compiler" = "xyes"; then
        LIBZMQ_CHECK_LANG_FLAG([-xldscope=hidden],
                               [libzmq_cv_[]_AC_LANG_ABBREV[]_visibility_flag="-xldscope=hidden"])
Mikko Koppanen's avatar
Mikko Koppanen committed
576 577 578 579
    fi

    AC_MSG_CHECKING(whether _AC_LANG compiler supports dso visibility)

580
    AS_IF([test "x$libzmq_cv_[]_AC_LANG_ABBREV[]_visibility_flag" != "x"],
Mikko Koppanen's avatar
Mikko Koppanen committed
581 582
          [AC_MSG_RESULT(yes) ; $1], [AC_MSG_RESULT(no) ; $2])
}])
583

584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605
dnl ################################################################################
dnl # LIBZMQ_CHECK_SOCK_CLOEXEC([action-if-found], [action-if-not-found])          #
dnl # Check if SOCK_CLOEXEC is supported                                           #
dnl ################################################################################
AC_DEFUN([LIBZMQ_CHECK_SOCK_CLOEXEC], [{
    AC_MSG_CHECKING(whether SOCK_CLOEXEC is supported)
    AC_TRY_RUN([/* SOCK_CLOEXEC test */
#include <sys/types.h>
#include <sys/socket.h>

int main (int argc, char *argv [])
{
    int s = socket (PF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0);
    return (s == -1);
}
    ],
    [AC_MSG_RESULT(yes) ; libzmq_cv_sock_cloexec="yes" ; $1],
    [AC_MSG_RESULT(no)  ; libzmq_cv_sock_cloexec="no"  ; $2],
    [AC_MSG_RESULT(not during cross-compile) ; libzmq_cv_sock_cloexec="no"]
    )
}])

606
dnl ################################################################################
607
dnl # LIBZMQ_CHECK_SO_KEEPALIVE([action-if-found], [action-if-not-found])          #
608 609
dnl # Check if SO_KEEPALIVE is supported                                           #
dnl ################################################################################
610
AC_DEFUN([LIBZMQ_CHECK_SO_KEEPALIVE], [{
611 612 613 614 615 616 617 618 619 620 621 622 623 624
    AC_MSG_CHECKING(whether SO_KEEPALIVE is supported)
    AC_TRY_RUN([/* SO_KEEPALIVE test */
#include <sys/types.h>
#include <sys/socket.h>

int main (int argc, char *argv [])
{
    int s, rc, opt = 1;
    return (
        ((s = socket (PF_INET, SOCK_STREAM, 0)) == -1) ||
        ((rc = setsockopt (s, SOL_SOCKET, SO_KEEPALIVE, (char*) &opt, sizeof (int))) == -1)
    );
}
    ],
625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655
    [AC_MSG_RESULT(yes) ; libzmq_cv_so_keepalive="yes" ; $1],
    [AC_MSG_RESULT(no)  ; libzmq_cv_so_keepalive="no"  ; $2],
    [AC_MSG_RESULT(not during cross-compile) ; libzmq_cv_so_keepalive="no"]
    )
}])

dnl ################################################################################
dnl # LIBZMQ_CHECK_TCP_KEEPCNT([action-if-found], [action-if-not-found])           #
dnl # Check if TCP_KEEPCNT is supported                                            #
dnl ################################################################################
AC_DEFUN([LIBZMQ_CHECK_TCP_KEEPCNT], [{
    AC_MSG_CHECKING(whether TCP_KEEPCNT is supported)
    AC_TRY_RUN([/* TCP_KEEPCNT test */
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>

int main (int argc, char *argv [])
{
    int s, rc, opt = 1;
    return (
        ((s = socket (PF_INET, SOCK_STREAM, 0)) == -1) ||
        ((rc = setsockopt (s, SOL_SOCKET, SO_KEEPALIVE, (char*) &opt, sizeof (int))) == -1) ||
        ((rc = setsockopt (s, IPPROTO_TCP, TCP_KEEPCNT, (char*) &opt, sizeof (int))) == -1)
    );
}
    ],
    [AC_MSG_RESULT(yes) ; libzmq_cv_tcp_keepcnt="yes" ; $1],
    [AC_MSG_RESULT(no)  ; libzmq_cv_tcp_keepcnt="no"  ; $2],
    [AC_MSG_RESULT(not during cross-compile) ; libzmq_cv_tcp_keepcnt="no"]
656 657 658 659
    )
}])

dnl ################################################################################
660 661
dnl # LIBZMQ_CHECK_TCP_KEEPIDLE([action-if-found], [action-if-not-found])          #
dnl # Check if TCP_KEEPIDLE is supported                                           #
662
dnl ################################################################################
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693
AC_DEFUN([LIBZMQ_CHECK_TCP_KEEPIDLE], [{
    AC_MSG_CHECKING(whether TCP_KEEPIDLE is supported)
    AC_TRY_RUN([/* TCP_KEEPIDLE test */
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>

int main (int argc, char *argv [])
{
    int s, rc, opt = 1;
    return (
        ((s = socket (PF_INET, SOCK_STREAM, 0)) == -1) ||
        ((rc = setsockopt (s, SOL_SOCKET, SO_KEEPALIVE, (char*) &opt, sizeof (int))) == -1) ||
        ((rc = setsockopt (s, IPPROTO_TCP, TCP_KEEPIDLE, (char*) &opt, sizeof (int))) == -1)
    );
}
    ],
    [AC_MSG_RESULT(yes) ; libzmq_cv_tcp_keepidle="yes" ; $1],
    [AC_MSG_RESULT(no)  ; libzmq_cv_tcp_keepidle="no"  ; $2],
    [AC_MSG_RESULT(not during cross-compile) ; libzmq_cv_tcp_keepidle="no"]
    )
}])

dnl ################################################################################
dnl # LIBZMQ_CHECK_TCP_KEEPINTVL([action-if-found], [action-if-not-found])          #
dnl # Check if TCP_KEEPINTVL is supported                                           #
dnl ################################################################################
AC_DEFUN([LIBZMQ_CHECK_TCP_KEEPINTVL], [{
    AC_MSG_CHECKING(whether TCP_KEEPINTVL is supported)
    AC_TRY_RUN([/* TCP_KEEPINTVL test */
694 695 696 697 698 699 700 701 702 703 704 705 706 707 708
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>

int main (int argc, char *argv [])
{
    int s, rc, opt = 1;
    return (
        ((s = socket (PF_INET, SOCK_STREAM, 0)) == -1) ||
        ((rc = setsockopt (s, SOL_SOCKET, SO_KEEPALIVE, (char*) &opt, sizeof (int))) == -1) ||
        ((rc = setsockopt (s, IPPROTO_TCP, TCP_KEEPINTVL, (char*) &opt, sizeof (int))) == -1)
    );
}
    ],
709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739
    [AC_MSG_RESULT(yes) ; libzmq_cv_tcp_keepintvl="yes" ; $1],
    [AC_MSG_RESULT(no)  ; libzmq_cv_tcp_keepintvl="no"  ; $2],
    [AC_MSG_RESULT(not during cross-compile) ; libzmq_cv_tcp_keepintvl="no"]
    )
}])

dnl ################################################################################
dnl # LIBZMQ_CHECK_TCP_KEEPALIVE([action-if-found], [action-if-not-found])         #
dnl # Check if TCP_KEEPALIVE is supported                                          #
dnl ################################################################################
AC_DEFUN([LIBZMQ_CHECK_TCP_KEEPALIVE], [{
    AC_MSG_CHECKING(whether TCP_KEEPALIVE is supported)
    AC_TRY_RUN([/* TCP_KEEPALIVE test */
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>

int main (int argc, char *argv [])
{
    int s, rc, opt = 1;
    return (
        ((s = socket (PF_INET, SOCK_STREAM, 0)) == -1) ||
        ((rc = setsockopt (s, SOL_SOCKET, SO_KEEPALIVE, (char*) &opt, sizeof (int))) == -1) ||
        ((rc = setsockopt (s, IPPROTO_TCP, TCP_KEEPALIVE, (char*) &opt, sizeof (int))) == -1)
    );
}
    ],
    [AC_MSG_RESULT(yes) ; libzmq_cv_tcp_keepalive="yes" ; $1],
    [AC_MSG_RESULT(no)  ; libzmq_cv_tcp_keepalive="no"  ; $2],
    [AC_MSG_RESULT(not during cross-compile) ; libzmq_cv_tcp_keepalive="no"]
740 741 742
    )
}])

743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764
dnl ################################################################################
dnl # LIBZMQ_CHECK_POLLER_KQUEUE([action-if-found], [action-if-not-found])         #
dnl # Checks kqueue polling system                                                 #
dnl ################################################################################
AC_DEFUN([LIBZMQ_CHECK_POLLER_KQUEUE], [{
    AC_LINK_IFELSE(
        [AC_LANG_PROGRAM(
        [
#include <sys/types.h>
#include <sys/event.h>
#include <sys/time.h>
        ],
[[
struct kevent t_kev;
kqueue();
]]
        )],
        [libzmq_cv_have_poller_kqueue="yes" ; $1],
        [libzmq_cv_have_poller_kqueue="no" ; $2])
}])

dnl ################################################################################
765 766 767
dnl # LIBZMQ_CHECK_POLLER_EPOLL_RUN([action-if-found], [action-if-not-found])      #
dnl # Checks epoll polling system can actually run #
dnl # For cross-compile, only requires that epoll can link # 
768 769
dnl ################################################################################
AC_DEFUN([LIBZMQ_CHECK_POLLER_EPOLL], [{
770
    AC_RUN_IFELSE(
771 772 773 774 775 776
        [AC_LANG_PROGRAM(
        [
#include <sys/epoll.h>
        ],
[[
struct epoll_event t_ev;
777 778 779
int r;
r = epoll_create(10);
return(r < 0);
780 781 782
]]
        )],
        [libzmq_cv_have_poller_epoll="yes" ; $1],
783
        [libzmq_cv_have_poller_epoll="no" ; $2],
784 785 786 787 788 789 790 791 792 793 794 795 796 797 798
        [
          AC_LINK_IFELSE(
              [AC_LANG_PROGRAM(
              [
#include <sys/epoll.h>
              ],
      [[
      struct epoll_event t_ev;
      epoll_create(10);
      ]]
              )],
              [libzmq_cv_have_poller_epoll="yes" ; $1],
              [libzmq_cv_have_poller_epoll="no" ; $2])
        
        ])
799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846
}])

dnl ################################################################################
dnl # LIBZMQ_CHECK_POLLER_DEVPOLL([action-if-found], [action-if-not-found])        #
dnl # Checks devpoll polling system                                                #
dnl ################################################################################
AC_DEFUN([LIBZMQ_CHECK_POLLER_DEVPOLL], [{
    AC_LINK_IFELSE(
        [AC_LANG_PROGRAM(
        [
#include <sys/devpoll.h>
        ],
[[
struct pollfd t_devpoll;
int fd = open("/dev/poll", O_RDWR);
]]
        )],
        [libzmq_cv_have_poller_devpoll="yes" ; $1],
        [libzmq_cv_have_poller_devpoll="no" ; $2])
}])

dnl ################################################################################
dnl # LIBZMQ_CHECK_POLLER_POLL([action-if-found], [action-if-not-found])           #
dnl # Checks poll polling system                                                   #
dnl ################################################################################
AC_DEFUN([LIBZMQ_CHECK_POLLER_POLL], [{
    AC_LINK_IFELSE(
        [AC_LANG_PROGRAM(
        [
#include <poll.h>
        ],
[[
struct pollfd t_poll;
poll(&t_poll, 1, 1);
]]
        )],
        [libzmq_cv_have_poller_poll="yes" ; $1],
        [libzmq_cv_have_poller_poll="no" ; $2])
}])

dnl ################################################################################
dnl # LIBZMQ_CHECK_POLLER_SELECT([action-if-found], [action-if-not-found])         #
dnl # Checks select polling system                                                 #
dnl ################################################################################
AC_DEFUN([LIBZMQ_CHECK_POLLER_SELECT], [{
    AC_LINK_IFELSE(
        [AC_LANG_PROGRAM(
        [
847 848 849 850 851 852
#ifdef ZMQ_HAVE_WINDOWS
#include "winsock2.h"
#elif defined ZMQ_HAVE_OPENVMS
#include <sys/types.h>
#include <sys/time.h>
#else
853
#include <sys/select.h>
854
#endif
855 856 857 858 859 860 861 862 863
        ],
[[
fd_set t_rfds;
struct timeval tv;

FD_ZERO(&t_rfds);
FD_SET(0, &t_rfds);

tv.tv_sec = 5;
864
tv.tv_usec = 0;
865 866 867 868 869 870 871 872 873 874 875 876 877 878

select(1, &t_rfds, NULL, NULL, &tv);
]]
        )],
        [libzmq_cv_have_poller_select="yes" ; $1],
        [libzmq_cv_have_poller_select="no" ; $2])
}])

dnl ################################################################################
dnl # LIBZMQ_CHECK_POLLER([action-if-found], [action-if-not-found])                #
dnl # Choose polling system                                                        #
dnl ################################################################################
AC_DEFUN([LIBZMQ_CHECK_POLLER], [{

879
    # Allow user to override poller autodetection
880 881 882 883 884 885
    AC_ARG_WITH([poller], [AS_HELP_STRING([--with-poller],
                [choose polling system manually. valid values are kqueue, epoll, devpoll, poll or select [default=autodetect]])])

    case "${with_poller}" in
        kqueue|epoll|devpoll|poll|select)
            # User has chosen polling system
886
            AC_MSG_CHECKING([for suitable polling system skipped for preselect])
887 888 889 890 891 892
            libzmq_cv_poller="${with_poller}"
        ;;

        *)
            # try to find suitable polling system. the order of testing is:
            # kqueue -> epoll -> devpoll -> poll -> select
893
            AC_MSG_CHECKING([for suitable polling system])
894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924
            for subsystem in kqueue epoll devpoll poll select; do

                case "${subsystem}" in
                    kqueue)
                        LIBZMQ_CHECK_POLLER_KQUEUE([libzmq_cv_poller=$subsystem], [])
                    ;;

                    epoll)
                        LIBZMQ_CHECK_POLLER_EPOLL([libzmq_cv_poller=$subsystem], [])
                    ;;

                    devpoll)
                        LIBZMQ_CHECK_POLLER_DEVPOLL([libzmq_cv_poller=$subsystem], [])
                    ;;

                    poll)
                        LIBZMQ_CHECK_POLLER_POLL([libzmq_cv_poller=$subsystem], [])
                    ;;

                    select)
                        LIBZMQ_CHECK_POLLER_SELECT([libzmq_cv_poller=$subsystem], [])
                    ;;
                esac

                if test "x${libzmq_cv_poller}" != "x"; then
                    break
                fi
            done
      ;;
    esac

925
    libzmq_cv_poller_flag=`echo "ZMQ_USE_${libzmq_cv_poller}" | tr a-z A-Z`
926 927 928 929 930

    AS_IF([test "x${libzmq_cv_poller}" != "x"],
          [AC_MSG_RESULT([using $libzmq_cv_poller]) ; $1], [AC_MSG_RESULT(no suitable polling system found) ; $2])
}])