acinclude.m4 48.2 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

    # Libtool configuration for different targets
    case "${host_os}" in
10
        *mingw*|*cygwin*|*msys*)
Mikko Koppanen's avatar
Mikko Koppanen committed
11 12 13 14 15 16 17 18 19 20 21
            # 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
    # Man pages are built/installed if asciidoc and xmlto are present
    #   --with-docs=no overrides this
    AC_ARG_WITH([docs],
95 96
        AS_HELP_STRING([--without-docs],
            [Don't build and install man pages [default=build]]),
97
        [with_docs=$withval])
98 99
    AC_ARG_WITH([documentation], [AS_HELP_STRING([--without-documentation],
        [Don't build and install man pages [default=build] DEPRECATED: use --without-docs])])
100

101 102 103 104
    if test "x$with_documentation" = "xno"; then
        AC_MSG_WARN([--without-documentation is DEPRECATED and will be removed in the next release, use --without-docs])
    fi
    if test "x$with_docs" = "xno" || test "x$with_documentation" = "xno"; then
105 106
        libzmq_build_doc="no"
        libzmq_install_man="no"
107 108
    else
        # Determine whether or not documentation should be built and installed.
109 110
        libzmq_build_doc="yes"
        libzmq_install_man="yes"
111
        # Check for asciidoc and xmlto and don't build the docs if these are not installed.
112 113 114 115
        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"
116 117
            # Tarballs built with 'make dist' ship with prebuilt documentation.
            if ! test -f doc/zmq.7; then
118
                libzmq_install_man="no"
119 120 121 122 123 124
                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
125
        if test "x$libzmq_on_mingw" = "xyes"; then
126
            libzmq_install_man="no"
Mikko Koppanen's avatar
Mikko Koppanen committed
127 128 129 130
        fi
    fi

    AC_MSG_CHECKING([whether to build documentation])
131
    AC_MSG_RESULT([$libzmq_build_doc])
Mikko Koppanen's avatar
Mikko Koppanen committed
132 133

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

136 137
    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
138
}])
139 140

dnl ##############################################################################
141
dnl # LIBZMQ_CHECK_LANG_COMPILER([action-if-found], [action-if-not-found])       #
142 143
dnl # Check that compiler for the current language actually works                #
dnl ##############################################################################
144
AC_DEFUN([LIBZMQ_CHECK_LANG_COMPILER], [{
145 146
    # Test that compiler for the current language actually works
    AC_CACHE_CHECK([whether the _AC_LANG compiler works],
147
                   [libzmq_cv_[]_AC_LANG_ABBREV[]_compiler_works],
148
                   [AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
149 150
                   [libzmq_cv_[]_AC_LANG_ABBREV[]_compiler_works="yes" ; $1],
                   [libzmq_cv_[]_AC_LANG_ABBREV[]_compiler_works="no" ; $2])
151 152
                   ])

153
    if test "x$libzmq_cv_[]_AC_LANG_ABBREV[]_compiler_works" != "xyes"; then
154 155 156
        AC_MSG_ERROR([Unable to find a working _AC_LANG compiler])
    fi
}])
157 158

dnl ##############################################################################
159
dnl # LIBZMQ_CHECK_COMPILERS                                                     #
160 161
dnl # Check compiler characteristics. This is so that we can AC_REQUIRE checks   #
dnl ##############################################################################
162
AC_DEFUN([LIBZMQ_CHECK_COMPILERS], [{
163 164
    # For that the compiler works and try to come up with the type
    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
    AC_LANG_POP([C])

    AC_LANG_PUSH(C++)
174
    LIBZMQ_CHECK_LANG_COMPILER
175

176 177 178 179
    LIBZMQ_CHECK_LANG_ICC
    LIBZMQ_CHECK_LANG_SUN_STUDIO
    LIBZMQ_CHECK_LANG_CLANG
    LIBZMQ_CHECK_LANG_GCC4
180 181 182 183
    AC_LANG_POP([C++])

    # Set GCC and GXX variables correctly
    if test "x$GCC" = "xyes"; then
184
        if test "xyes" = "x$libzmq_cv_c_intel_compiler"; then
185 186 187 188 189
            GCC="no"
        fi
    fi

    if test "x$GXX" = "xyes"; then
190
        if test "xyes" = "x$libzmq_cv_cxx_intel_compiler"; then
191 192 193 194 195 196
            GXX="no"
        fi
    fi
}])

dnl ############################################################################
197
dnl # LIBZMQ_CHECK_LANG_FLAG([flag], [action-if-found], [action-if-not-found]) #
198
dnl # Check if the compiler supports given flag. Works for C and C++           #
199
dnl # Sets libzmq_cv_[]_AC_LANG_ABBREV[]_supports_flag_[FLAG]=yes/no           #
200
dnl ############################################################################
201
AC_DEFUN([LIBZMQ_CHECK_LANG_FLAG], [{
202

Mikko Koppanen's avatar
Mikko Koppanen committed
203 204
    AC_REQUIRE([AC_PROG_GREP])

205 206
    AC_MSG_CHECKING([whether _AC_LANG compiler supports $1])

207
    libzmq_cv_[]_AC_LANG_ABBREV[]_werror_flag_save=$ac_[]_AC_LANG_ABBREV[]_werror_flag
208 209 210 211
    ac_[]_AC_LANG_ABBREV[]_werror_flag="yes"

    case "x[]_AC_LANG_ABBREV" in
        xc)
212
            libzmq_cv_check_lang_flag_save_CFLAGS="$CFLAGS"
213 214 215
            CFLAGS="$CFLAGS $1"
        ;;
        xcxx)
216
            libzmq_cv_check_lang_flag_save_CPPFLAGS="$CPPFLAGS"
217 218 219 220 221 222 223 224 225 226
            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
227 228
                      [if ($GREP 'ignoring unknown' conftest.err ||
                           $GREP 'not supported' conftest.err) >/dev/null 2>&1; then
229
                           eval AS_TR_SH(libzmq_cv_[]_AC_LANG_ABBREV[]_supports_flag_$1)="no"
230
                       else
231
                           eval AS_TR_SH(libzmq_cv_[]_AC_LANG_ABBREV[]_supports_flag_$1)="yes"
232
                       fi],
233
                      [eval AS_TR_SH(libzmq_cv_[]_AC_LANG_ABBREV[]_supports_flag_$1)="no"])
234 235 236

    case "x[]_AC_LANG_ABBREV" in
        xc)
237
            CFLAGS="$libzmq_cv_check_lang_flag_save_CFLAGS"
238 239
        ;;
        xcxx)
240
            CPPFLAGS="$libzmq_cv_check_lang_flag_save_CPPFLAGS"
241 242 243 244 245 246 247
        ;;
        *)
            # nothing to restore
        ;;
    esac

    # Restore the werror flag
248
    ac_[]_AC_LANG_ABBREV[]_werror_flag=$libzmq_cv_[]_AC_LANG_ABBREV[]_werror_flag_save
249 250

    # Call the action as the flags are restored
251
    AS_IF([eval test x$]AS_TR_SH(libzmq_cv_[]_AC_LANG_ABBREV[]_supports_flag_$1)[ = "xyes"],
252 253 254 255 256
          [AC_MSG_RESULT(yes) ; $2], [AC_MSG_RESULT(no) ; $3])

}])

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

dnl ##############################################################################
277
dnl # LIBZMQ_CHECK_ENABLE_DEBUG([action-if-found], [action-if-not-found])        #
278 279
dnl # Check whether to enable debug build and set compiler flags accordingly     #
dnl ##############################################################################
280
AC_DEFUN([LIBZMQ_CHECK_ENABLE_DEBUG], [{
281 282

    # Require compiler specifics
283
    AC_REQUIRE([LIBZMQ_CHECK_COMPILERS])
284 285 286

    # This flag is checked also in
    AC_ARG_ENABLE([debug], [AS_HELP_STRING([--enable-debug],
287
        [enable debugging information [default=disabled]])])
288 289 290 291 292 293 294

    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 \
295 296
                "x$libzmq_cv_c_intel_compiler" = "xyes" -o \
                "x$libzmq_cv_c_clang_compiler" = "xyes"; then
297
            CFLAGS="-g -O0 "
298
        elif test "x$libzmq_cv_c_sun_studio_compiler" = "xyes"; then
299 300 301 302 303
            CFLAGS="-g0 "
        fi

        # GCC, clang and ICC
        if test "x$GXX" = "xyes" -o \
304 305
                "x$libzmq_cv_cxx_intel_compiler" = "xyes" -o \
                "x$libzmq_cv_cxx_clang_compiler" = "xyes"; then
306 307 308
            CPPFLAGS="-g -O0 "
            CXXFLAGS="-g -O0 "
        # Sun studio
309
        elif test "x$libzmq_cv_cxx_sun_studio_compiler" = "xyes"; then
310 311 312 313
            CPPFLAGS="-g0 "
            CXXFLAGS="-g0 "
        fi

314 315
        if test "x$ZMQ_ORIG_CFLAGS" != "xnone"; then
            CFLAGS="${CFLAGS} ${ZMQ_ORIG_CFLAGS}"
316
        fi
317 318
        if test "x$ZMQ_ORIG_CPPFLAGS" != "xnone"; then
            CPPFLAGS="${CPPFLAGS} ${ZMQ_ORIG_CPPFLAGS}"
319
        fi
320 321
        if test "x$ZMQ_ORIG_CXXFLAGS" != "xnone"; then
            CXXFLAGS="${CXXFLAGS} ${ZMQ_ORIG_CXXFLAGS}"
322 323 324 325 326 327 328
        fi
        AC_MSG_RESULT(yes)
    else
        AC_MSG_RESULT(no)
    fi
}])

329
dnl ##############################################################################
330
dnl # LIBZMQ_WITH_GCOV([action-if-found], [action-if-not-found])                 #
331 332
dnl # Check whether to build with code coverage                                  #
dnl ##############################################################################
333
AC_DEFUN([LIBZMQ_WITH_GCOV], [{
334
    # Require compiler specifics
335
    AC_REQUIRE([LIBZMQ_CHECK_COMPILERS])
336 337

    AC_ARG_WITH(gcov, [AS_HELP_STRING([--with-gcov=yes/no],
338
                      [with GCC Code Coverage reporting.])],
339 340 341 342
                      [ZMQ_GCOV="$withval"])

    AC_MSG_CHECKING(whether to enable code coverage)

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

Mikko Koppanen's avatar
Mikko Koppanen committed
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
        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
363

Mikko Koppanen's avatar
Mikko Koppanen committed
364
        LIBS="-lgcov ${LIBS}"
365 366 367 368 369 370
    fi

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

371
dnl ##############################################################################
372
dnl # LIBZMQ_CHECK_WITH_FLAG([flags], [macro])                                   #
373 374
dnl # Runs a normal autoconf check with compiler flags                           #
dnl ##############################################################################
375 376 377
AC_DEFUN([LIBZMQ_CHECK_WITH_FLAG], [{
    libzmq_check_with_flag_save_CFLAGS="$CFLAGS"
    libzmq_check_with_flag_save_CPPFLAGS="$CPPFLAGS"
378 379 380 381 382 383 384

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

    # Execute the macro
    $2

385 386
    CFLAGS="$libzmq_check_with_flag_save_CFLAGS"
    CPPFLAGS="$libzmq_check_with_flag_save_CPPFLAGS"
387 388 389
}])

dnl ##############################################################################
390
dnl # LIBZMQ_LANG_WALL([action-if-found], [action-if-not-found])                 #
391
dnl # How to define -Wall for the current compiler                               #
392
dnl # Sets libzmq_cv_[]_AC_LANG_ABBREV[]__wall_flag variable to found style      #
393
dnl ##############################################################################
394
AC_DEFUN([LIBZMQ_LANG_WALL], [{
395 396 397

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

398
    libzmq_cv_[]_AC_LANG_ABBREV[]_wall_flag=""
399 400 401 402 403 404

    # C compilers
    case "x[]_AC_LANG_ABBREV" in
       xc)
            # GCC, clang and ICC
            if test "x$GCC" = "xyes" -o \
405 406 407
                    "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"
408
            # Sun studio
409 410
            elif test "x$libzmq_cv_[]_AC_LANG_ABBREV[]_sun_studio_compiler" = "xyes"; then
                libzmq_cv_[]_AC_LANG_ABBREV[]_wall_flag="-v"
411 412 413 414 415
            fi
       ;;
       xcxx)
            # GCC, clang and ICC
            if test "x$GXX" = "xyes" -o \
416 417 418
                    "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"
419
            # Sun studio
420 421
            elif test "x$libzmq_cv_[]_AC_LANG_ABBREV[]_sun_studio_compiler" = "xyes"; then
                libzmq_cv_[]_AC_LANG_ABBREV[]_wall_flag="+w"
422 423 424 425 426 427 428
            fi
       ;;
       *)
       ;;
    esac

    # Call the action
429 430
    if test "x$libzmq_cv_[]_AC_LANG_ABBREV[]_wall_flag" != "x"; then
        AC_MSG_RESULT([$libzmq_cv_[]_AC_LANG_ABBREV[]_wall_flag])
431 432 433 434 435 436 437 438
        $1
    else
        AC_MSG_RESULT([not found])
        $2
    fi
}])

dnl ####################################################################
439
dnl # LIBZMQ_LANG_STRICT([action-if-found], [action-if-not-found])     #
440 441
dnl # Check how to turn on strict standards compliance                 #
dnl ####################################################################
442
AC_DEFUN([LIBZMQ_LANG_STRICT], [{
443 444
    AC_MSG_CHECKING([how to enable strict standards compliance in _AC_LANG compiler])

445
    libzmq_cv_[]_AC_LANG_ABBREV[]_strict_flag=""
446 447 448 449 450

    # C compilers
    case "x[]_AC_LANG_ABBREV" in
       xc)
            # GCC, clang and ICC
451 452 453 454
            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"
455
            # Sun studio
456 457
            elif test "x$libzmq_cv_[]_AC_LANG_ABBREV[]_sun_studio_compiler" = "xyes"; then
                libzmq_cv_[]_AC_LANG_ABBREV[]_strict_flag="-Xc"
458 459 460 461
            fi
       ;;
       xcxx)
            # GCC, clang and ICC
462 463 464 465
            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"
466
            # Sun studio
467 468
            elif test "x$libzmq_cv_[]_AC_LANG_ABBREV[]_sun_studio_compiler" = "xyes"; then
                libzmq_cv_[]_AC_LANG_ABBREV[]_strict_flag="-compat=5"
469 470 471 472 473 474 475
            fi
       ;;
       *)
       ;;
    esac

    # Call the action
476 477
    if test "x$libzmq_cv_[]_AC_LANG_ABBREV[]_strict_flag" != "x"; then
        AC_MSG_RESULT([$libzmq_cv_[]_AC_LANG_ABBREV[]_strict_flag])
478 479 480 481 482 483 484 485
        $1
    else
        AC_MSG_RESULT([not found])
        $2
    fi
}])

dnl ########################################################################
486
dnl # LIBZMQ_LANG_WERROR([action-if-found], [action-if-not-found])         #
487 488
dnl # Check how to turn warnings to errors                                 #
dnl ########################################################################
489
AC_DEFUN([LIBZMQ_LANG_WERROR], [{
490 491
    AC_MSG_CHECKING([how to turn warnings to errors in _AC_LANG compiler])

492
    libzmq_cv_[]_AC_LANG_ABBREV[]_werror_flag=""
493 494 495 496 497

    # C compilers
    case "x[]_AC_LANG_ABBREV" in
       xc)
            # GCC, clang and ICC
498 499
            if test "x$GCC" = "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
            fi
       ;;
       xcxx)
            # GCC, clang and ICC
507 508
            if test "x$GXX" = "xyes" -o "x$libzmq_cv_[]_AC_LANG_ABBREV[]_intel_compiler" = "xyes"; then
                libzmq_cv_[]_AC_LANG_ABBREV[]_werror_flag="-Werror"
509
            # Sun studio
510 511
            elif test "x$libzmq_cv_[]_AC_LANG_ABBREV[]_sun_studio_compiler" = "xyes"; then
                libzmq_cv_[]_AC_LANG_ABBREV[]_werror_flag="-errwarn=%all"
512 513 514 515 516 517 518
            fi
       ;;
       *)
       ;;
    esac

    # Call the action
519 520
    if test "x$libzmq_cv_[]_AC_LANG_ABBREV[]_werror_flag" != "x"; then
        AC_MSG_RESULT([$libzmq_cv_[]_AC_LANG_ABBREV[]_werror_flag])
521 522 523 524 525 526 527 528
        $1
    else
        AC_MSG_RESULT([not found])
        $2
    fi
}])

dnl ################################################################################
529
dnl # LIBZMQ_CHECK_LANG_PRAGMA([pragma], [action-if-found], [action-if-not-found]) #
530 531
dnl # Check if the compiler supports given pragma                                  #
dnl ################################################################################
532
AC_DEFUN([LIBZMQ_CHECK_LANG_PRAGMA], [{
533
    # Need to know how to enable all warnings
534
    LIBZMQ_LANG_WALL
535 536 537 538

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

    # Save flags
539
    libzmq_cv_[]_AC_LANG_ABBREV[]_werror_flag_save=$ac_[]_AC_LANG_ABBREV[]_werror_flag
540 541 542
    ac_[]_AC_LANG_ABBREV[]_werror_flag="yes"

    if test "x[]_AC_LANG_ABBREV" = "xc"; then
543 544
        libzmq_cv_check_lang_pragma_save_CFLAGS="$CFLAGS"
        CFLAGS="$CFLAGS $libzmq_cv_[]_AC_LANG_ABBREV[]_wall_flag"
545
    elif test "x[]_AC_LANG_ABBREV" = "xcxx"; then
546 547
        libzmq_cv_check_lang_pragma_save_CPPFLAGS="$CPPFLAGS"
        CPPFLAGS="$CPPFLAGS $libzmq_cv_[]_AC_LANG_ABBREV[]_wall_flag"
548 549 550 551 552
    else
        AC_MSG_WARN([testing compiler characteristic on an unknown language])
    fi

    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[#pragma $1]])],
553 554
                      [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)])
555 556

    if test "x[]_AC_LANG_ABBREV" = "xc"; then
557
        CFLAGS="$libzmq_cv_check_lang_pragma_save_CFLAGS"
558
    elif test "x[]_AC_LANG_ABBREV" = "xcxx"; then
559
        CPPFLAGS="$libzmq_cv_check_lang_pragma_save_CPPFLAGS"
560 561
    fi

562
    ac_[]_AC_LANG_ABBREV[]_werror_flag=$libzmq_cv_[]_AC_LANG_ABBREV[]_werror_flag_save
563 564

    # Call the action as the flags are restored
565
    AS_IF([eval test x$]AS_TR_SH(libzmq_cv_[]_AC_LANG_ABBREV[]_supports_pragma_$1)[ = "xyes"],
566 567
          [$2], [$3])
}])
Mikko Koppanen's avatar
Mikko Koppanen committed
568 569

dnl ################################################################################
570
dnl # LIBZMQ_CHECK_LANG_VISIBILITY([action-if-found], [action-if-not-found])       #
Mikko Koppanen's avatar
Mikko Koppanen committed
571 572
dnl # Check if the compiler supports dso visibility                                #
dnl ################################################################################
573 574 575 576 577 578 579 580 581 582 583 584
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
585 586 587 588
    fi

    AC_MSG_CHECKING(whether _AC_LANG compiler supports dso visibility)

589
    AS_IF([test "x$libzmq_cv_[]_AC_LANG_ABBREV[]_visibility_flag" != "x"],
Mikko Koppanen's avatar
Mikko Koppanen committed
590 591
          [AC_MSG_RESULT(yes) ; $1], [AC_MSG_RESULT(no) ; $2])
}])
592

593 594 595 596 597
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], [{
598 599
    AC_CACHE_CHECK([whether SOCK_CLOEXEC is supported], [libzmq_cv_sock_cloexec],
        [AC_TRY_RUN([/* SOCK_CLOEXEC test */
600 601 602 603 604 605 606 607
#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);
}
608 609 610 611 612
        ],
        [libzmq_cv_sock_cloexec="yes"],
        [libzmq_cv_sock_cloexec="no"],
        [libzmq_cv_sock_cloexec="not during cross-compile"]
        )]
613
    )
614
    AS_IF([test "x$libzmq_cv_sock_cloexec" = "xyes"], [$1], [$2])
615 616
}])

617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641
dnl ################################################################################
dnl # LIBZMQ_CHECK_O_CLOEXEC([action-if-found], [action-if-not-found])          #
dnl # Check if O_CLOEXEC is supported                                           #
dnl ################################################################################
AC_DEFUN([LIBZMQ_CHECK_O_CLOEXEC], [{
    AC_CACHE_CHECK([whether O_CLOEXEC is supported], [libzmq_cv_o_cloexec],
        [AC_TRY_RUN([/* O_CLOEXEC test */
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int main (int argc, char *argv [])
{
    int s = open ("/dev/null", O_CLOEXEC | O_RDONLY);
    return (s == -1);
}
        ],
        [libzmq_cv_o_cloexec="yes"],
        [libzmq_cv_o_cloexec="no"],
        [libzmq_cv_o_cloexec="not during cross-compile"]
        )]
    )
    AS_IF([test "x$libzmq_cv_o_cloexec" = "xyes"], [$1], [$2])
}])

642
dnl ################################################################################
643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665
dnl # LIBZMQ_CHECK_EVENTFD_CLOEXEC([action-if-found], [action-if-not-found])          #
dnl # Check if EFD_CLOEXEC is supported                                           #
dnl ################################################################################
AC_DEFUN([LIBZMQ_CHECK_EVENTFD_CLOEXEC], [{
    AC_CACHE_CHECK([whether EFD_CLOEXEC is supported], [libzmq_cv_efd_cloexec],
        [AC_TRY_RUN([/* EFD_CLOEXEC test */
#include <sys/eventfd.h>

int main (int argc, char *argv [])
{
    int s = eventfd (0, EFD_CLOEXEC);
    return (s == -1);
}
        ],
        [libzmq_cv_efd_cloexec="yes"],
        [libzmq_cv_efd_cloexec="no"],
        [libzmq_cv_efd_cloexec="not during cross-compile"]
        )]
    )
    AS_IF([test "x$libzmq_cv_efd_cloexec" = "xyes"], [$1], [$2])
}])

dnl ################################################################################
666 667 668 669 670
dnl # LIBZMQ_CHECK_ATOMIC_INSTRINSICS([action-if-found], [action-if-not-found])    #
dnl # Check if compiler supoorts __atomic_Xxx intrinsics                           #
dnl ################################################################################
AC_DEFUN([LIBZMQ_CHECK_ATOMIC_INTRINSICS], [{
    AC_MSG_CHECKING(whether compiler supports __atomic_Xxx intrinsics)
671
    AC_LINK_IFELSE([AC_LANG_SOURCE([
672 673 674 675 676 677 678 679
/* atomic intrinsics test */
int v = 0;
int main (int, char **)
{
    int t = __atomic_add_fetch (&v, 1, __ATOMIC_ACQ_REL);
    return t;
}
    ])],
680 681 682
    [AC_MSG_RESULT(yes) ; GCC_ATOMIC_BUILTINS_SUPPORTED=1 libzmq_cv_has_atomic_instrisics="yes" ; $1])

    if test "x$GCC_ATOMIC_BUILTINS_SUPPORTED" != x1; then
683 684
        save_LIBS=$LIBS
        LIBS="$LIBS -latomic"
685 686 687 688 689 690 691 692 693
        AC_LINK_IFELSE([AC_LANG_SOURCE([
        /* atomic intrinsics test */
        int v = 0;
        int main (int, char **)
        {
            int t = __atomic_add_fetch (&v, 1, __ATOMIC_ACQ_REL);
            return t;
        }
        ])],
694 695
        [AC_MSG_RESULT(yes) ; libzmq_cv_has_atomic_instrisics="yes" ; $1],
        [AC_MSG_RESULT(no) ; libzmq_cv_has_atomic_instrisics="no" LIBS=$save_LIBS ; $2])
696
    fi
697 698
}])

699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725
dnl ################################################################################
dnl # LIBZMQ_CHECK_SO_BINDTODEVICE([action-if-found], [action-if-not-found])          #
dnl # Check if SO_BINDTODEVICE is supported                                           #
dnl ################################################################################
AC_DEFUN([LIBZMQ_CHECK_SO_BINDTODEVICE], [{
    AC_CACHE_CHECK([whether SO_BINDTODEVICE is supported], [libzmq_cv_so_bindtodevice],
        [AC_TRY_RUN([/* SO_BINDTODEVICE test */
#include <sys/socket.h>

int main (int argc, char *argv [])
{
/* Actually making the setsockopt() call requires CAP_NET_RAW */
#ifndef SO_BINDTODEVICE
    return 1;
#else
    return 0;
#endif
}
        ],
        [libzmq_cv_so_bindtodevice="yes"],
        [libzmq_cv_so_bindtodevice="no"],
        [libzmq_cv_so_bindtodevice="not during cross-compile"]
        )]
    )
    AS_IF([test "x$libzmq_cv_so_bindtodevice" = "xyes"], [$1], [$2])
}])

726
dnl ################################################################################
727
dnl # LIBZMQ_CHECK_SO_KEEPALIVE([action-if-found], [action-if-not-found])          #
728 729
dnl # Check if SO_KEEPALIVE is supported                                           #
dnl ################################################################################
730
AC_DEFUN([LIBZMQ_CHECK_SO_KEEPALIVE], [{
731 732
    AC_CACHE_CHECK([whether SO_KEEPALIVE is supported], [libzmq_cv_so_keepalive],
        [AC_TRY_RUN([/* SO_KEEPALIVE test */
733 734 735 736 737 738 739 740 741 742 743
#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)
    );
}
744 745 746 747 748
        ],
        [libzmq_cv_so_keepalive="yes"],
        [libzmq_cv_so_keepalive="no"],
        [libzmq_cv_so_keepalive="not during cross-compile"]
        )]
749
    )
750
    AS_IF([test "x$libzmq_cv_so_keepalive" = "xyes"], [$1], [$2])
751 752 753 754 755 756 757
}])

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], [{
758 759
    AC_CACHE_CHECK([whether TCP_KEEPCNT is supported], [libzmq_cv_tcp_keepcnt],
        [AC_TRY_RUN([/* TCP_KEEPCNT test */
760 761 762 763 764 765 766 767 768 769 770 771 772 773
#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)
    );
}
774 775 776 777 778
        ],
        [libzmq_cv_tcp_keepcnt="yes"],
        [libzmq_cv_tcp_keepcnt="no"],
        [libzmq_cv_tcp_keepcnt="not during cross-compile"]
        )]
779
    )
780
    AS_IF([test "x$libzmq_cv_tcp_keepcnt" = "xyes"], [$1], [$2])
781 782 783
}])

dnl ################################################################################
784 785
dnl # LIBZMQ_CHECK_TCP_KEEPIDLE([action-if-found], [action-if-not-found])          #
dnl # Check if TCP_KEEPIDLE is supported                                           #
786
dnl ################################################################################
787
AC_DEFUN([LIBZMQ_CHECK_TCP_KEEPIDLE], [{
788 789
    AC_CACHE_CHECK([whether TCP_KEEPIDLE is supported], [libzmq_cv_tcp_keepidle],
        [AC_TRY_RUN([/* TCP_KEEPIDLE test */
790 791 792 793 794 795 796 797 798 799 800 801 802 803
#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)
    );
}
804 805 806 807 808
        ],
        [libzmq_cv_tcp_keepidle="yes"],
        [libzmq_cv_tcp_keepidle="no"],
        [libzmq_cv_tcp_keepidle="not during cross-compile"]
        )]
809
    )
810
    AS_IF([test "x$libzmq_cv_tcp_keepidle" = "xyes"], [$1], [$2])
811 812 813 814 815 816 817
}])

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], [{
818 819
    AC_CACHE_CHECK([whether TCP_KEEPINTVL is supported], [libzmq_cv_tcp_keepintvl],
        [AC_TRY_RUN([/* TCP_KEEPINTVL test */
820 821 822 823 824 825 826 827 828 829 830 831 832 833
#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)
    );
}
834 835 836 837 838
        ],
        [libzmq_cv_tcp_keepintvl="yes"],
        [libzmq_cv_tcp_keepintvl="no"],
        [libzmq_cv_tcp_keepintvl="not during cross-compile"]
        )]
839
    )
840
    AS_IF([test "x$libzmq_cv_tcp_keepintvl" = "xyes"], [$1], [$2])
841 842 843 844 845 846 847
}])

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], [{
848 849
    AC_CACHE_CHECK([whether TCP_KEEPALIVE is supported], [libzmq_cv_tcp_keepalive],
        [AC_TRY_RUN([/* TCP_KEEPALIVE test */
850 851 852 853 854 855 856 857 858 859 860 861 862 863
#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)
    );
}
864 865 866 867 868
        ],
        [libzmq_cv_tcp_keepalive="yes"],
        [libzmq_cv_tcp_keepalive="no"],
        [libzmq_cv_tcp_keepalive="not during cross-compile"]
        )]
869
    )
870
    AS_IF([test "x$libzmq_cv_tcp_keepalive" = "xyes"], [$1], [$2])
871 872
}])

873 874 875 876 877 878 879 880 881 882 883 884
dnl ################################################################################
dnl # LIBZMQ_CHECK_GETRANDOM([action-if-found], [action-if-not-found])  #
dnl # Checks if getrandom is supported                                  #
dnl ################################################################################
AC_DEFUN([LIBZMQ_CHECK_GETRANDOM], [{
    AC_CACHE_CHECK([whether getrandom is supported], [libzmq_cv_getrandom],
        [AC_TRY_RUN([/* thread-local storage test */
#include <sys/random.h>

int main (int argc, char *argv [])
{
    char buf[4];
885 886
    int rc = getrandom(buf, 4, 0);
    return rc == -1 ? 1 : 0;
887 888 889 890 891 892 893 894 895 896
}
        ],
        [libzmq_cv_getrandom="yes"],
        [libzmq_cv_getrandom="no"],
        [libzmq_cv_getrandom="not during cross-compile"]
        )]
    )
    AS_IF([test "x$libzmq_cv_getrandom" = "xyes"], [$1], [$2])
}])

897 898 899 900 901
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], [{
902 903
    AC_LINK_IFELSE([
        AC_LANG_PROGRAM([
904 905 906
#include <sys/types.h>
#include <sys/event.h>
#include <sys/time.h>
907
        ],[[
908 909
struct kevent t_kev;
kqueue();
910 911 912
        ]])],
        [$1], [$2]
    )
913 914 915
}])

dnl ################################################################################
916
dnl # LIBZMQ_CHECK_POLLER_EPOLL_RUN([action-if-found], [action-if-not-found])      #
917
dnl # LIBZMQ_CHECK_POLLER_EPOLL_CLOEXEC([action-if-found], [action-if-not-found])  #
918
dnl # Checks epoll polling system can actually run #
919
dnl # For cross-compile, only requires that epoll can link #
920 921
dnl ################################################################################
AC_DEFUN([LIBZMQ_CHECK_POLLER_EPOLL], [{
922 923
    AC_RUN_IFELSE([
        AC_LANG_PROGRAM([
924
#include <sys/epoll.h>
925
        ],[[
926
struct epoll_event t_ev;
927 928 929
int r;
r = epoll_create(10);
return(r < 0);
930 931 932 933
        ]])],
        [$1],[$2],[
            AC_LINK_IFELSE([
                AC_LANG_PROGRAM([
934
#include <sys/epoll.h>
935 936 937 938 939 940 941 942
                ],[[
struct epoll_event t_ev;
epoll_create(10);
                ]])],
                [$1], [$2]
            )
        ]
    )
943 944
}])

945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968
AC_DEFUN([LIBZMQ_CHECK_POLLER_EPOLL_CLOEXEC], [{
    AC_RUN_IFELSE([
        AC_LANG_PROGRAM([
#include <sys/epoll.h>
        ],[[
struct epoll_event t_ev;
int r;
r = epoll_create1(EPOLL_CLOEXEC);
return(r < 0);
        ]])],
        [$1],[$2],[
            AC_LINK_IFELSE([
                AC_LANG_PROGRAM([
#include <sys/epoll.h>
                ],[[
struct epoll_event t_ev;
epoll_create1(EPOLL_CLOEXEC);
                ]])],
                [$1], [$2]
            )
        ]
    )
}])

969 970 971 972 973
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], [{
974 975
    AC_LINK_IFELSE([
        AC_LANG_PROGRAM([
976
#include <sys/devpoll.h>
977
        ],[[
978 979
struct pollfd t_devpoll;
int fd = open("/dev/poll", O_RDWR);
980 981 982
        ]])],
        [$1], [$2]
    )
983 984
}])

985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000
dnl ################################################################################
dnl # LIBZMQ_CHECK_POLLER_POLLSET([action-if-found], [action-if-not-found])        #
dnl # Checks pollset polling system                                                #
dnl ################################################################################
AC_DEFUN([LIBZMQ_CHECK_POLLER_POLLSET], [{
    AC_LINK_IFELSE([
        AC_LANG_PROGRAM([
#include <sys/poll.h>
#include <sys/pollset.h>
        ],[[
pollset_t ps = pollset_create(-1);
        ]])],
        [$1], [$2]
    )
}])

1001 1002 1003 1004 1005
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], [{
1006 1007
    AC_LINK_IFELSE([
        AC_LANG_PROGRAM([
1008
#include <poll.h>
1009
        ],[[
1010 1011
struct pollfd t_poll;
poll(&t_poll, 1, 1);
1012 1013 1014
        ]])],
        [$1], [$2]
    )
1015 1016 1017 1018 1019 1020 1021
}])

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], [{
1022 1023
    AC_LINK_IFELSE([
        AC_LANG_PROGRAM([
1024 1025 1026 1027 1028 1029
#ifdef ZMQ_HAVE_WINDOWS
#include "winsock2.h"
#elif defined ZMQ_HAVE_OPENVMS
#include <sys/types.h>
#include <sys/time.h>
#else
1030
#include <sys/select.h>
1031
#endif
1032
        ],[[
1033 1034 1035 1036 1037
fd_set t_rfds;
struct timeval tv;
FD_ZERO(&t_rfds);
FD_SET(0, &t_rfds);
tv.tv_sec = 5;
1038
tv.tv_usec = 0;
1039
select(1, &t_rfds, 0, 0, &tv);
1040 1041 1042
        ]])],
        [$1],[$2]
    )
1043 1044 1045 1046 1047 1048 1049
}])

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

1050
AC_DEFUN([LIBZMQ_CHECK_POLLER], [{
1051
    # Allow user to override poller autodetection
1052 1053
    AC_ARG_WITH([poller],
        [AS_HELP_STRING([--with-poller],
1054
        [choose I/O thread polling system manually. Valid values are 'kqueue', 'epoll', 'devpoll', 'pollset', 'poll', 'select', 'wepoll', or 'auto'. [default=auto]])])
1055 1056 1057 1058 1059

    # Allow user to override poller autodetection
    AC_ARG_WITH([api_poller],
        [AS_HELP_STRING([--with-api-poller],
        [choose zmq_poll(er)_* API polling system manually. Valid values are 'poll', 'select', or 'auto'. [default=auto]])])
1060

1061 1062 1063 1064 1065 1066 1067
    if test "x$with_poller" == "x"; then
        pollers=auto
    else
        pollers=$with_poller
    fi
    if test "$pollers" == "auto"; then
        # We search for pollers in this order
1068
        pollers="kqueue epoll devpoll pollset poll select"
1069
    fi
1070

1071
    # try to find suitable polling system. the order of testing is:
1072
    AC_MSG_NOTICE([Choosing I/O thread polling system from '$pollers'...])
1073 1074 1075 1076 1077
    poller_found=0
    for poller in $pollers; do
        case "$poller" in
            kqueue)
                LIBZMQ_CHECK_POLLER_KQUEUE([
1078 1079
                    AC_MSG_NOTICE([Using 'kqueue' I/O thread polling system])
                    AC_DEFINE(ZMQ_IOTHREAD_POLLER_USE_KQUEUE, 1, [Use 'kqueue' I/O thread polling system])
1080 1081 1082 1083
                    poller_found=1
                ])
            ;;
            epoll)
1084 1085 1086 1087 1088 1089 1090
                case "$host_os" in
                    solaris*|sunos*)
                        # Recent illumos and Solaris systems did add epoll()
                        # syntax, but it does not fully satisfy expectations
                        # that ZMQ has from Linux systems. Unless you undertake
                        # to fix the integration, do not disable this exception
                        # and use select() or poll() on Solarish OSes for now.
1091
                        AC_MSG_NOTICE([NOT using 'epoll' I/O thread polling system on '$host_os']) ;;
1092 1093
                    *)
                        LIBZMQ_CHECK_POLLER_EPOLL_CLOEXEC([
1094 1095 1096
                            AC_MSG_NOTICE([Using 'epoll' I/O thread polling system with CLOEXEC])
                            AC_DEFINE(ZMQ_IOTHREAD_POLLER_USE_EPOLL, 1, [Use 'epoll' I/O thread polling system])
                            AC_DEFINE(ZMQ_IOTHREAD_POLLER_USE_EPOLL_CLOEXEC, 1, [Use 'epoll' I/O thread polling system with CLOEXEC])
1097 1098 1099
                            poller_found=1
                            ],[
                            LIBZMQ_CHECK_POLLER_EPOLL([
1100 1101
                                AC_MSG_NOTICE([Using 'epoll' I/O thread polling system with CLOEXEC])
                                AC_DEFINE(ZMQ_IOTHREAD_POLLER_USE_EPOLL, 1, [Use 'epoll' I/O thread polling system])
1102 1103 1104 1105 1106
                                poller_found=1
                            ])
                        ])
                        ;;
                esac
1107 1108 1109
            ;;
            devpoll)
                LIBZMQ_CHECK_POLLER_DEVPOLL([
1110 1111
                    AC_MSG_NOTICE([Using 'devpoll' I/O thread polling system])
                    AC_DEFINE(ZMQ_IOTHREAD_POLLER_USE_DEVPOLL, 1, [Use 'devpoll' I/O thread polling system])
1112 1113 1114
                    poller_found=1
                ])
            ;;
1115 1116
            pollset)
                LIBZMQ_CHECK_POLLER_POLLSET([
1117 1118
                    AC_MSG_NOTICE([Using 'pollset' I/O thread polling system])
                    AC_DEFINE(ZMQ_IOTHREAD_POLLER_USE_POLLSET, 1, [Use 'pollset' I/O thread polling system])
1119 1120 1121
                    poller_found=1
                ])
            ;;
1122 1123
            poll)
                LIBZMQ_CHECK_POLLER_POLL([
1124 1125
                    AC_MSG_NOTICE([Using 'poll' I/O thread polling system])
                    AC_DEFINE(ZMQ_IOTHREAD_POLLER_USE_POLL, 1, [Use 'poll' I/O thread polling system])
1126 1127 1128 1129 1130
                    poller_found=1
                ])
            ;;
            select)
                LIBZMQ_CHECK_POLLER_SELECT([
1131 1132
                    AC_MSG_NOTICE([Using 'select' I/O thread polling system])
                    AC_DEFINE(ZMQ_IOTHREAD_POLLER_USE_SELECT, 1, [Use 'select' I/O thread polling system])
1133 1134 1135
                    poller_found=1
                ])
            ;;
1136 1137 1138 1139 1140 1141
            wepoll)
                # wepoll can only be manually selected
                AC_MSG_NOTICE([Using 'wepoll' I/O thread polling system])
                AC_DEFINE(ZMQ_IOTHREAD_POLLER_USE_EPOLL, 1, [Use 'epoll' I/O thread polling system])
                poller_found=1
            ;;
1142 1143 1144 1145 1146 1147
        esac
        test $poller_found -eq 1 && break
    done
    if test $poller_found -eq 0; then
        AC_MSG_ERROR([None of '$pollers' are valid pollers on this platform])
    fi
1148 1149 1150 1151 1152 1153
    if test "x$with_api_poller" == "x"; then
        with_api_poller=auto
    fi
	if test "x$with_api_poller" == "xauto"; then
		if test $poller == "select"; then
			api_poller=select
1154 1155
		elif test $poller == "wepoll"; then
			api_poller=select
1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170
		else		
			api_poller=poll
		fi
	else
		api_poller=$with_api_poller
	fi
	if test "$api_poller" == "select"; then
		AC_MSG_NOTICE([Using 'select' zmq_poll(er)_* API polling system])
		AC_DEFINE(ZMQ_POLL_BASED_ON_SELECT, 1, [Use 'select' zmq_poll(er)_* API polling system])
	elif test "$api_poller" == "poll"; then
		AC_MSG_NOTICE([Using 'poll' zmq_poll(er)_* API polling system])
		AC_DEFINE(ZMQ_POLL_BASED_ON_POLL, 1, [Use 'poll' zmq_poll(er)_* API polling system])
	else
        AC_MSG_ERROR([Invalid API poller '$api_poller' specified])
	fi
1171
}])
1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191

dnl ##############################################################################
dnl # LIBZMQ_CHECK_CACHELINE                                                     #
dnl # Check cacheline size for alignment purposes                                #
dnl ##############################################################################
AC_DEFUN([LIBZMQ_CHECK_CACHELINE], [{

    zmq_cacheline_size=64
    AC_CHECK_TOOL(libzmq_getconf, getconf)
    if ! test "x$libzmq_getconf" = "x"; then
        zmq_cacheline_size=$($libzmq_getconf LEVEL1_DCACHE_LINESIZE 2>/dev/null || echo 64)
        if test "x$zmq_cacheline_size" = "x0" -o  "x$zmq_cacheline_size" = "x-1"; then
            # getconf on some architectures does not know the size, try to fallback to
            # the value the kernel knows on Linux
            zmq_cacheline_size=$(cat /sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size 2>/dev/null || echo 64)
        fi
    fi
	AC_MSG_NOTICE([Using "$zmq_cacheline_size" bytes alignment for lock-free data structures])
	AC_DEFINE_UNQUOTED(ZMQ_CACHELINE_SIZE, $zmq_cacheline_size, [Using "$zmq_cacheline_size" bytes alignment for lock-free data structures])
}])
1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232

dnl ################################################################################
dnl # LIBZMQ_CHECK_CV_IMPL([action-if-found], [action-if-not-found])               #
dnl # Choose condition variable implementation                                     #
dnl ################################################################################

AC_DEFUN([LIBZMQ_CHECK_CV_IMPL], [{
    # Allow user to override condition variable autodetection
    AC_ARG_WITH([cv-impl],
        [AS_HELP_STRING([--with-cv-impl],
        [choose condition variable implementation manually. Valid values are 'stl11', 'pthread', 'none', or 'auto'. [default=auto]])])

    if test "x$with_cv_impl" == "x"; then
        cv_impl=auto
    else
        cv_impl=$with_cv_impl
    fi
    case $host_os in
      vxworks*)
        cv_impl="vxworks"
        AC_DEFINE(ZMQ_USE_CV_IMPL_VXWORKS, 1, [Use vxworks condition variable implementation.])
      ;;
    esac
    if test "$cv_impl" == "auto" || test "$cv_impl" == "stl11"; then
        AC_LANG_PUSH([C++])
        AC_CHECK_HEADERS(condition_variable, [stl11="yes"
            AC_DEFINE(ZMQ_USE_CV_IMPL_STL11, 1, [Use stl11 condition variable implementation.])],
            [stl11="no"])
        AC_LANG_POP([C++])
        if test "$cv_impl" == "stl11" && test "x$stl11" == "xno"; then
            AC_MSG_ERROR([--with-cv-impl set to stl11 but cannot find condition_variable])
        fi
    fi
    if test "$cv_impl" == "pthread" || test "x$stl11" == "xno"; then
        AC_DEFINE(ZMQ_USE_CV_IMPL_PTHREADS, 1, [Use pthread condition variable implementation.])
    fi
    if test "$cv_impl" == "none"; then
        AC_DEFINE(ZMQ_USE_CV_IMPL_NONE, 1, [Use no condition variable implementation.])
    fi
       AC_MSG_NOTICE([Using "$cv_impl" condition variable implementation.])
}])