1335640Shselaskydnl Copyright (c) 1995, 1996, 1997, 1998 2335640Shselaskydnl The Regents of the University of California. All rights reserved. 3335640Shselaskydnl 4335640Shselaskydnl Redistribution and use in source and binary forms, with or without 5335640Shselaskydnl modification, are permitted provided that: (1) source code distributions 6335640Shselaskydnl retain the above copyright notice and this paragraph in its entirety, (2) 7335640Shselaskydnl distributions including binary code include the above copyright notice and 8335640Shselaskydnl this paragraph in its entirety in the documentation or other materials 9335640Shselaskydnl provided with the distribution, and (3) all advertising materials mentioning 10335640Shselaskydnl features or use of this software display the following acknowledgement: 11335640Shselaskydnl ``This product includes software developed by the University of California, 12335640Shselaskydnl Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 13335640Shselaskydnl the University nor the names of its contributors may be used to endorse 14335640Shselaskydnl or promote products derived from this software without specific prior 15335640Shselaskydnl written permission. 16335640Shselaskydnl THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 17335640Shselaskydnl WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 18335640Shselaskydnl MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 19335640Shselaskydnl 20335640Shselaskydnl LBL autoconf macros 21335640Shselaskydnl 22335640Shselasky 23335640Shselaskydnl 24335640Shselaskydnl Do whatever AC_LBL_C_INIT work is necessary before using AC_PROG_CC. 25335640Shselaskydnl 26335640Shselaskydnl It appears that newer versions of autoconf (2.64 and later) will, 27335640Shselaskydnl if you use AC_TRY_COMPILE in a macro, stick AC_PROG_CC at the 28335640Shselaskydnl beginning of the macro, even if the macro itself calls AC_PROG_CC. 29335640Shselaskydnl See the "Prerequisite Macros" and "Expanded Before Required" sections 30335640Shselaskydnl in the Autoconf documentation. 31335640Shselaskydnl 32335640Shselaskydnl This causes a steaming heap of fail in our case, as we were, in 33335640Shselaskydnl AC_LBL_C_INIT, doing the tests we now do in AC_LBL_C_INIT_BEFORE_CC, 34335640Shselaskydnl calling AC_PROG_CC, and then doing the tests we now do in 35335640Shselaskydnl AC_LBL_C_INIT. Now, we run AC_LBL_C_INIT_BEFORE_CC, AC_PROG_CC, 36335640Shselaskydnl and AC_LBL_C_INIT at the top level. 37335640Shselaskydnl 38335640ShselaskyAC_DEFUN(AC_LBL_C_INIT_BEFORE_CC, 39335640Shselasky[ 40335640Shselasky AC_BEFORE([$0], [AC_LBL_C_INIT]) 41335640Shselasky AC_BEFORE([$0], [AC_PROG_CC]) 42335640Shselasky AC_BEFORE([$0], [AC_LBL_FIXINCLUDES]) 43335640Shselasky AC_BEFORE([$0], [AC_LBL_DEVEL]) 44335640Shselasky AC_ARG_WITH(gcc, [ --without-gcc don't use gcc]) 45335640Shselasky $1="" 46335640Shselasky if test "${srcdir}" != "." ; then 47335640Shselasky $1="-I\$(srcdir)" 48335640Shselasky fi 49335640Shselasky if test "${CFLAGS+set}" = set; then 50335640Shselasky LBL_CFLAGS="$CFLAGS" 51335640Shselasky fi 52335640Shselasky if test -z "$CC" ; then 53335640Shselasky case "$host_os" in 54335640Shselasky 55335640Shselasky bsdi*) 56335640Shselasky AC_CHECK_PROG(SHLICC2, shlicc2, yes, no) 57335640Shselasky if test $SHLICC2 = yes ; then 58335640Shselasky CC=shlicc2 59335640Shselasky export CC 60335640Shselasky fi 61335640Shselasky ;; 62335640Shselasky esac 63335640Shselasky fi 64335640Shselasky if test -z "$CC" -a "$with_gcc" = no ; then 65335640Shselasky CC=cc 66335640Shselasky export CC 67335640Shselasky fi 68335640Shselasky]) 69335640Shselasky 70335640Shselaskydnl 71335640Shselaskydnl Determine which compiler we're using (cc or gcc) 72335640Shselaskydnl If using gcc, determine the version number 73335640Shselaskydnl If using cc: 74335640Shselaskydnl require that it support ansi prototypes 75335640Shselaskydnl use -O (AC_PROG_CC will use -g -O2 on gcc, so we don't need to 76335640Shselaskydnl do that ourselves for gcc) 77335640Shselaskydnl add -g flags, as appropriate 78335640Shselaskydnl explicitly specify /usr/local/include 79335640Shselaskydnl 80335640Shselaskydnl NOTE WELL: with newer versions of autoconf, "gcc" means any compiler 81335640Shselaskydnl that defines __GNUC__, which means clang, for example, counts as "gcc". 82335640Shselaskydnl 83335640Shselaskydnl usage: 84335640Shselaskydnl 85335640Shselaskydnl AC_LBL_C_INIT(copt, incls) 86335640Shselaskydnl 87335640Shselaskydnl results: 88335640Shselaskydnl 89335640Shselaskydnl $1 (copt set) 90335640Shselaskydnl $2 (incls set) 91335640Shselaskydnl CC 92335640Shselaskydnl LDFLAGS 93335640Shselaskydnl LBL_CFLAGS 94335640Shselaskydnl 95335640ShselaskyAC_DEFUN(AC_LBL_C_INIT, 96335640Shselasky[ 97335640Shselasky AC_BEFORE([$0], [AC_LBL_FIXINCLUDES]) 98335640Shselasky AC_BEFORE([$0], [AC_LBL_DEVEL]) 99335640Shselasky AC_BEFORE([$0], [AC_LBL_SHLIBS_INIT]) 100335640Shselasky if test "$GCC" = yes ; then 101335640Shselasky # 102335640Shselasky # -Werror forces warnings to be errors. 103335640Shselasky # 104335640Shselasky ac_lbl_cc_force_warning_errors=-Werror 105335640Shselasky 106335640Shselasky # 107335640Shselasky # Try to have the compiler default to hiding symbols, 108335640Shselasky # so that only symbols explicitly exported with 109335640Shselasky # PCAP_API will be visible outside (shared) libraries. 110335640Shselasky # 111335640Shselasky AC_LBL_CHECK_COMPILER_OPT($1, -fvisibility=hidden) 112335640Shselasky else 113335640Shselasky $2="$$2 -I/usr/local/include" 114335640Shselasky LDFLAGS="$LDFLAGS -L/usr/local/lib" 115335640Shselasky 116335640Shselasky case "$host_os" in 117335640Shselasky 118335640Shselasky darwin*) 119335640Shselasky # 120335640Shselasky # This is assumed either to be GCC or clang, both 121335640Shselasky # of which use -Werror to force warnings to be errors. 122335640Shselasky # 123335640Shselasky ac_lbl_cc_force_warning_errors=-Werror 124335640Shselasky 125335640Shselasky # 126335640Shselasky # Try to have the compiler default to hiding symbols, 127335640Shselasky # so that only symbols explicitly exported with 128335640Shselasky # PCAP_API will be visible outside (shared) libraries. 129335640Shselasky # 130335640Shselasky AC_LBL_CHECK_COMPILER_OPT($1, -fvisibility=hidden) 131335640Shselasky ;; 132335640Shselasky 133335640Shselasky hpux*) 134335640Shselasky # 135335640Shselasky # HP C, which is what we presume we're using, doesn't 136335640Shselasky # exit with a non-zero exit status if we hand it an 137335640Shselasky # invalid -W flag, can't be forced to do so even with 138335640Shselasky # +We, and doesn't handle GCC-style -W flags, so we 139335640Shselasky # don't want to try using GCC-style -W flags. 140335640Shselasky # 141335640Shselasky ac_lbl_cc_dont_try_gcc_dashW=yes 142335640Shselasky ;; 143335640Shselasky 144335640Shselasky irix*) 145335640Shselasky # 146335640Shselasky # MIPS C, which is what we presume we're using, doesn't 147335640Shselasky # necessarily exit with a non-zero exit status if we 148335640Shselasky # hand it an invalid -W flag, can't be forced to do 149335640Shselasky # so, and doesn't handle GCC-style -W flags, so we 150335640Shselasky # don't want to try using GCC-style -W flags. 151335640Shselasky # 152335640Shselasky ac_lbl_cc_dont_try_gcc_dashW=yes 153335640Shselasky # 154335640Shselasky # It also, apparently, defaults to "char" being 155335640Shselasky # unsigned, unlike most other C implementations; 156335640Shselasky # I suppose we could say "signed char" whenever 157335640Shselasky # we want to guarantee a signed "char", but let's 158335640Shselasky # just force signed chars. 159335640Shselasky # 160335640Shselasky # -xansi is normally the default, but the 161335640Shselasky # configure script was setting it; perhaps -cckr 162335640Shselasky # was the default in the Old Days. (Then again, 163335640Shselasky # that would probably be for backwards compatibility 164335640Shselasky # in the days when ANSI C was Shiny and New, i.e. 165335640Shselasky # 1989 and the early '90's, so maybe we can just 166335640Shselasky # drop support for those compilers.) 167335640Shselasky # 168335640Shselasky # -g is equivalent to -g2, which turns off 169335640Shselasky # optimization; we choose -g3, which generates 170335640Shselasky # debugging information but doesn't turn off 171335640Shselasky # optimization (even if the optimization would 172335640Shselasky # cause inaccuracies in debugging). 173335640Shselasky # 174335640Shselasky $1="$$1 -xansi -signed -g3" 175335640Shselasky ;; 176335640Shselasky 177335640Shselasky osf*) 178335640Shselasky # 179335640Shselasky # Presumed to be DEC OSF/1, Digital UNIX, or 180335640Shselasky # Tru64 UNIX. 181335640Shselasky # 182335640Shselasky # The DEC C compiler, which is what we presume we're 183335640Shselasky # using, doesn't exit with a non-zero exit status if we 184335640Shselasky # hand it an invalid -W flag, can't be forced to do 185335640Shselasky # so, and doesn't handle GCC-style -W flags, so we 186335640Shselasky # don't want to try using GCC-style -W flags. 187335640Shselasky # 188335640Shselasky ac_lbl_cc_dont_try_gcc_dashW=yes 189335640Shselasky # 190335640Shselasky # -g is equivalent to -g2, which turns off 191335640Shselasky # optimization; we choose -g3, which generates 192335640Shselasky # debugging information but doesn't turn off 193335640Shselasky # optimization (even if the optimization would 194335640Shselasky # cause inaccuracies in debugging). 195335640Shselasky # 196335640Shselasky $1="$$1 -g3" 197335640Shselasky ;; 198335640Shselasky 199335640Shselasky solaris*) 200335640Shselasky # 201335640Shselasky # Assumed to be Sun C, which requires -errwarn to force 202335640Shselasky # warnings to be treated as errors. 203335640Shselasky # 204335640Shselasky ac_lbl_cc_force_warning_errors=-errwarn 205335640Shselasky 206335640Shselasky # 207335640Shselasky # Try to have the compiler default to hiding symbols, 208335640Shselasky # so that only symbols explicitly exported with 209335640Shselasky # PCAP_API will be visible outside (shared) libraries. 210335640Shselasky # 211335640Shselasky AC_LBL_CHECK_COMPILER_OPT($1, -xldscope=hidden) 212335640Shselasky ;; 213335640Shselasky 214335640Shselasky ultrix*) 215335640Shselasky AC_MSG_CHECKING(that Ultrix $CC hacks const in prototypes) 216335640Shselasky AC_CACHE_VAL(ac_cv_lbl_cc_const_proto, 217335640Shselasky AC_TRY_COMPILE( 218335640Shselasky [#include <sys/types.h>], 219335640Shselasky [struct a { int b; }; 220335640Shselasky void c(const struct a *)], 221335640Shselasky ac_cv_lbl_cc_const_proto=yes, 222335640Shselasky ac_cv_lbl_cc_const_proto=no)) 223335640Shselasky AC_MSG_RESULT($ac_cv_lbl_cc_const_proto) 224335640Shselasky if test $ac_cv_lbl_cc_const_proto = no ; then 225335640Shselasky AC_DEFINE(const,[], 226335640Shselasky [to handle Ultrix compilers that don't support const in prototypes]) 227335640Shselasky fi 228335640Shselasky ;; 229335640Shselasky esac 230335640Shselasky $1="$$1 -O" 231335640Shselasky fi 232335640Shselasky]) 233335640Shselasky 234335640Shselaskydnl 235335640Shselaskydnl Check whether, if you pass an unknown warning option to the 236335640Shselaskydnl compiler, it fails or just prints a warning message and succeeds. 237335640Shselaskydnl Set ac_lbl_unknown_warning_option_error to the appropriate flag 238335640Shselaskydnl to force an error if it would otherwise just print a warning message 239335640Shselaskydnl and succeed. 240335640Shselaskydnl 241335640ShselaskyAC_DEFUN(AC_LBL_CHECK_UNKNOWN_WARNING_OPTION_ERROR, 242335640Shselasky [ 243335640Shselasky AC_MSG_CHECKING([whether the compiler fails when given an unknown warning option]) 244335640Shselasky save_CFLAGS="$CFLAGS" 245335640Shselasky CFLAGS="$CFLAGS -Wxyzzy-this-will-never-succeed-xyzzy" 246335640Shselasky AC_TRY_COMPILE( 247335640Shselasky [], 248335640Shselasky [return 0], 249335640Shselasky [ 250335640Shselasky AC_MSG_RESULT([no]) 251335640Shselasky # 252335640Shselasky # We're assuming this is clang, where 253335640Shselasky # -Werror=unknown-warning-option is the appropriate 254335640Shselasky # option to force the compiler to fail. 255335640Shselasky # 256335640Shselasky ac_lbl_unknown_warning_option_error="-Werror=unknown-warning-option" 257335640Shselasky ], 258335640Shselasky [ 259335640Shselasky AC_MSG_RESULT([yes]) 260335640Shselasky ]) 261335640Shselasky CFLAGS="$save_CFLAGS" 262335640Shselasky ]) 263335640Shselasky 264335640Shselaskydnl 265335640Shselaskydnl Check whether the compiler option specified as the second argument 266335640Shselaskydnl is supported by the compiler and, if so, add it to the macro 267335640Shselaskydnl specified as the first argument 268335640Shselaskydnl 269356341Scydnl If a third argument is supplied, treat it as C code to be compiled 270356341Scydnl with the flag in question, and the "treat warnings as errors" flag 271356341Scydnl set, and don't add the flag to the first argument if the compile 272356341Scydnl fails; this is for warning options cause problems that can't be 273356341Scydnl worked around. If a third argument is supplied, a fourth argument 274356341Scydnl should also be supplied; it's a message desribing what the test 275356341Scydnl program is checking. 276356341Scydnl 277335640ShselaskyAC_DEFUN(AC_LBL_CHECK_COMPILER_OPT, 278335640Shselasky [ 279335640Shselasky AC_MSG_CHECKING([whether the compiler supports the $2 option]) 280335640Shselasky save_CFLAGS="$CFLAGS" 281335640Shselasky if expr "x$2" : "x-W.*" >/dev/null 282335640Shselasky then 283335640Shselasky CFLAGS="$CFLAGS $ac_lbl_unknown_warning_option_error $2" 284335640Shselasky elif expr "x$2" : "x-f.*" >/dev/null 285335640Shselasky then 286335640Shselasky CFLAGS="$CFLAGS -Werror $2" 287335640Shselasky elif expr "x$2" : "x-m.*" >/dev/null 288335640Shselasky then 289335640Shselasky CFLAGS="$CFLAGS -Werror $2" 290335640Shselasky else 291335640Shselasky CFLAGS="$CFLAGS $2" 292335640Shselasky fi 293335640Shselasky AC_TRY_COMPILE( 294335640Shselasky [], 295335640Shselasky [return 0], 296335640Shselasky [ 297335640Shselasky AC_MSG_RESULT([yes]) 298356341Scy can_add_to_cflags=yes 299356341Scy # 300356341Scy # The compile supports this; do we have some C code for 301356341Scy # which the warning should *not* appear? 302356341Scy # We test the fourth argument because the third argument 303356341Scy # could contain quotes, breaking the test. 304356341Scy # 305356341Scy if test "x$4" != "x" 306356341Scy then 307356341Scy CFLAGS="$CFLAGS $ac_lbl_cc_force_warning_errors" 308356341Scy AC_MSG_CHECKING(whether $2 $4) 309356341Scy AC_COMPILE_IFELSE( 310356341Scy [AC_LANG_SOURCE($3)], 311356341Scy [ 312356341Scy # 313356341Scy # Not a problem. 314356341Scy # 315356341Scy AC_MSG_RESULT(no) 316356341Scy ], 317356341Scy [ 318356341Scy # 319356341Scy # A problem. 320356341Scy # 321356341Scy AC_MSG_RESULT(yes) 322356341Scy can_add_to_cflags=no 323356341Scy ]) 324356341Scy fi 325335640Shselasky CFLAGS="$save_CFLAGS" 326356341Scy if test x"$can_add_to_cflags" = "xyes" 327356341Scy then 328356341Scy $1="$$1 $2" 329356341Scy fi 330335640Shselasky ], 331335640Shselasky [ 332335640Shselasky AC_MSG_RESULT([no]) 333335640Shselasky CFLAGS="$save_CFLAGS" 334335640Shselasky ]) 335335640Shselasky ]) 336335640Shselasky 337335640Shselaskydnl 338335640Shselaskydnl Check whether the compiler supports an option to generate 339335640Shselaskydnl Makefile-style dependency lines 340335640Shselaskydnl 341335640Shselaskydnl GCC uses -M for this. Non-GCC compilers that support this 342335640Shselaskydnl use a variety of flags, including but not limited to -M. 343335640Shselaskydnl 344335640Shselaskydnl We test whether the flag in question is supported, as older 345335640Shselaskydnl versions of compilers might not support it. 346335640Shselaskydnl 347335640Shselaskydnl We don't try all the possible flags, just in case some flag means 348335640Shselaskydnl "generate dependencies" on one compiler but means something else 349335640Shselaskydnl on another compiler. 350335640Shselaskydnl 351335640Shselaskydnl Most compilers that support this send the output to the standard 352335640Shselaskydnl output by default. IBM's XLC, however, supports -M but sends 353335640Shselaskydnl the output to {sourcefile-basename}.u, and AIX has no /dev/stdout 354335640Shselaskydnl to work around that, so we don't bother with XLC. 355335640Shselaskydnl 356335640ShselaskyAC_DEFUN(AC_LBL_CHECK_DEPENDENCY_GENERATION_OPT, 357335640Shselasky [ 358335640Shselasky AC_MSG_CHECKING([whether the compiler supports generating dependencies]) 359335640Shselasky if test "$GCC" = yes ; then 360335640Shselasky # 361335640Shselasky # GCC, or a compiler deemed to be GCC by AC_PROG_CC (even 362335640Shselasky # though it's not); we assume that, in this case, the flag 363335640Shselasky # would be -M. 364335640Shselasky # 365335640Shselasky ac_lbl_dependency_flag="-M" 366335640Shselasky else 367335640Shselasky # 368335640Shselasky # Not GCC or a compiler deemed to be GCC; what platform is 369335640Shselasky # this? (We're assuming that if the compiler isn't GCC 370335640Shselasky # it's the compiler from the vendor of the OS; that won't 371335640Shselasky # necessarily be true for x86 platforms, where it might be 372335640Shselasky # the Intel C compiler.) 373335640Shselasky # 374335640Shselasky case "$host_os" in 375335640Shselasky 376335640Shselasky irix*|osf*|darwin*) 377335640Shselasky # 378335640Shselasky # MIPS C for IRIX, DEC C, and clang all use -M. 379335640Shselasky # 380335640Shselasky ac_lbl_dependency_flag="-M" 381335640Shselasky ;; 382335640Shselasky 383335640Shselasky solaris*) 384335640Shselasky # 385335640Shselasky # Sun C uses -xM. 386335640Shselasky # 387335640Shselasky ac_lbl_dependency_flag="-xM" 388335640Shselasky ;; 389335640Shselasky 390335640Shselasky hpux*) 391335640Shselasky # 392335640Shselasky # HP's older C compilers don't support this. 393335640Shselasky # HP's newer C compilers support this with 394335640Shselasky # either +M or +Make; the older compilers 395335640Shselasky # interpret +M as something completely 396335640Shselasky # different, so we use +Make so we don't 397335640Shselasky # think it works with the older compilers. 398335640Shselasky # 399335640Shselasky ac_lbl_dependency_flag="+Make" 400335640Shselasky ;; 401335640Shselasky 402335640Shselasky *) 403335640Shselasky # 404335640Shselasky # Not one of the above; assume no support for 405335640Shselasky # generating dependencies. 406335640Shselasky # 407335640Shselasky ac_lbl_dependency_flag="" 408335640Shselasky ;; 409335640Shselasky esac 410335640Shselasky fi 411335640Shselasky 412335640Shselasky # 413335640Shselasky # Is ac_lbl_dependency_flag defined and, if so, does the compiler 414335640Shselasky # complain about it? 415335640Shselasky # 416335640Shselasky # Note: clang doesn't seem to exit with an error status when handed 417335640Shselasky # an unknown non-warning error, even if you pass it 418335640Shselasky # -Werror=unknown-warning-option. However, it always supports 419335640Shselasky # -M, so the fact that this test always succeeds with clang 420335640Shselasky # isn't an issue. 421335640Shselasky # 422335640Shselasky if test ! -z "$ac_lbl_dependency_flag"; then 423335640Shselasky AC_LANG_CONFTEST( 424335640Shselasky [AC_LANG_SOURCE([[int main(void) { return 0; }]])]) 425335640Shselasky if AC_RUN_LOG([eval "$CC $ac_lbl_dependency_flag conftest.c >/dev/null 2>&1"]); then 426335640Shselasky AC_MSG_RESULT([yes, with $ac_lbl_dependency_flag]) 427335640Shselasky DEPENDENCY_CFLAG="$ac_lbl_dependency_flag" 428335640Shselasky MKDEP='${srcdir}/mkdep' 429335640Shselasky else 430335640Shselasky AC_MSG_RESULT([no]) 431335640Shselasky # 432335640Shselasky # We can't run mkdep, so have "make depend" do 433335640Shselasky # nothing. 434335640Shselasky # 435335640Shselasky MKDEP='${srcdir}/nomkdep' 436335640Shselasky fi 437335640Shselasky rm -rf conftest* 438335640Shselasky else 439335640Shselasky AC_MSG_RESULT([no]) 440335640Shselasky # 441335640Shselasky # We can't run mkdep, so have "make depend" do 442335640Shselasky # nothing. 443335640Shselasky # 444335640Shselasky MKDEP='${srcdir}/nomkdep' 445335640Shselasky fi 446335640Shselasky AC_SUBST(DEPENDENCY_CFLAG) 447335640Shselasky AC_SUBST(MKDEP) 448335640Shselasky ]) 449335640Shselasky 450335640Shselaskydnl 451335640Shselaskydnl Determine what options are needed to build a shared library 452335640Shselaskydnl 453335640Shselaskydnl usage: 454335640Shselaskydnl 455335640Shselaskydnl AC_LBL_SHLIBS_INIT 456335640Shselaskydnl 457335640Shselaskydnl results: 458335640Shselaskydnl 459335640Shselaskydnl V_SHLIB_CCOPT (modified to build position-independent code) 460335640Shselaskydnl V_SHLIB_CMD 461335640Shselaskydnl V_SHLIB_OPT 462335640Shselaskydnl V_SONAME_OPT 463335640Shselaskydnl V_RPATH_OPT 464335640Shselaskydnl 465335640ShselaskyAC_DEFUN(AC_LBL_SHLIBS_INIT, 466335640Shselasky [AC_PREREQ(2.50) 467335640Shselasky if test "$GCC" = yes ; then 468335640Shselasky # 469335640Shselasky # On platforms where we build a shared library: 470335640Shselasky # 471335640Shselasky # add options to generate position-independent code, 472335640Shselasky # if necessary (it's the default in AIX and Darwin/macOS); 473335640Shselasky # 474335640Shselasky # define option to set the soname of the shared library, 475335640Shselasky # if the OS supports that; 476335640Shselasky # 477335640Shselasky # add options to specify, at link time, a directory to 478335640Shselasky # add to the run-time search path, if that's necessary. 479335640Shselasky # 480335640Shselasky V_SHLIB_CMD="\$(CC)" 481335640Shselasky V_SHLIB_OPT="-shared" 482335640Shselasky case "$host_os" in 483335640Shselasky 484335640Shselasky aix*) 485335640Shselasky ;; 486335640Shselasky 487356341Scy freebsd*|netbsd*|openbsd*|dragonfly*|linux*|osf*|midipix*) 488335640Shselasky # 489335640Shselasky # Platforms where the linker is the GNU linker 490335640Shselasky # or accepts command-line arguments like 491335640Shselasky # those the GNU linker accepts. 492335640Shselasky # 493335640Shselasky # Some instruction sets require -fPIC on some 494335640Shselasky # operating systems. Check for them. If you 495335640Shselasky # have a combination that requires it, add it 496335640Shselasky # here. 497335640Shselasky # 498335640Shselasky PIC_OPT=-fpic 499335640Shselasky case "$host_cpu" in 500335640Shselasky 501335640Shselasky sparc64*) 502335640Shselasky case "$host_os" in 503335640Shselasky 504356341Scy freebsd*|openbsd*|linux*) 505335640Shselasky PIC_OPT=-fPIC 506335640Shselasky ;; 507335640Shselasky esac 508335640Shselasky ;; 509335640Shselasky esac 510335640Shselasky V_SHLIB_CCOPT="$V_SHLIB_CCOPT $PIC_OPT" 511335640Shselasky V_SONAME_OPT="-Wl,-soname," 512335640Shselasky V_RPATH_OPT="-Wl,-rpath," 513335640Shselasky ;; 514335640Shselasky 515335640Shselasky hpux*) 516335640Shselasky V_SHLIB_CCOPT="$V_SHLIB_CCOPT -fpic" 517335640Shselasky # 518335640Shselasky # XXX - this assumes GCC is using the HP linker, 519335640Shselasky # rather than the GNU linker, and that the "+h" 520335640Shselasky # option is used on all HP-UX platforms, both .sl 521335640Shselasky # and .so. 522335640Shselasky # 523335640Shselasky V_SONAME_OPT="-Wl,+h," 524335640Shselasky # 525335640Shselasky # By default, directories specifed with -L 526335640Shselasky # are added to the run-time search path, so 527335640Shselasky # we don't add them in pcap-config. 528335640Shselasky # 529335640Shselasky ;; 530335640Shselasky 531335640Shselasky solaris*) 532335640Shselasky V_SHLIB_CCOPT="$V_SHLIB_CCOPT -fpic" 533335640Shselasky # 534335640Shselasky # XXX - this assumes GCC is using the Sun linker, 535335640Shselasky # rather than the GNU linker. 536335640Shselasky # 537335640Shselasky V_SONAME_OPT="-Wl,-h," 538335640Shselasky V_RPATH_OPT="-Wl,-R," 539335640Shselasky ;; 540335640Shselasky esac 541335640Shselasky else 542335640Shselasky # 543335640Shselasky # Set the appropriate compiler flags and, on platforms 544335640Shselasky # where we build a shared library: 545335640Shselasky # 546335640Shselasky # add options to generate position-independent code, 547335640Shselasky # if necessary (it's the default in Darwin/macOS); 548335640Shselasky # 549335640Shselasky # if we generate ".so" shared libraries, define the 550335640Shselasky # appropriate options for building the shared library; 551335640Shselasky # 552335640Shselasky # add options to specify, at link time, a directory to 553335640Shselasky # add to the run-time search path, if that's necessary. 554335640Shselasky # 555335640Shselasky # Note: spaces after V_SONAME_OPT are significant; on 556335640Shselasky # some platforms the soname is passed with a GCC-like 557335640Shselasky # "-Wl,-soname,{soname}" option, with the soname part 558335640Shselasky # of the option, while on other platforms the C compiler 559335640Shselasky # driver takes it as a regular option with the soname 560335640Shselasky # following the option. The same applies to V_RPATH_OPT. 561335640Shselasky # 562335640Shselasky case "$host_os" in 563335640Shselasky 564335640Shselasky aix*) 565335640Shselasky V_SHLIB_CMD="\$(CC)" 566335640Shselasky V_SHLIB_OPT="-G -bnoentry -bexpall" 567335640Shselasky ;; 568335640Shselasky 569335640Shselasky freebsd*|netbsd*|openbsd*|dragonfly*|linux*) 570335640Shselasky # 571335640Shselasky # "cc" is GCC. 572335640Shselasky # 573335640Shselasky V_SHLIB_CCOPT="$V_SHLIB_CCOPT -fpic" 574335640Shselasky V_SHLIB_CMD="\$(CC)" 575335640Shselasky V_SHLIB_OPT="-shared" 576335640Shselasky V_SONAME_OPT="-Wl,-soname," 577335640Shselasky V_RPATH_OPT="-Wl,-rpath," 578335640Shselasky ;; 579335640Shselasky 580335640Shselasky hpux*) 581335640Shselasky V_SHLIB_CCOPT="$V_SHLIB_CCOPT +z" 582335640Shselasky V_SHLIB_CMD="\$(LD)" 583335640Shselasky V_SHLIB_OPT="-b" 584335640Shselasky V_SONAME_OPT="+h " 585335640Shselasky # 586335640Shselasky # By default, directories specifed with -L 587335640Shselasky # are added to the run-time search path, so 588335640Shselasky # we don't add them in pcap-config. 589335640Shselasky # 590335640Shselasky ;; 591335640Shselasky 592335640Shselasky osf*) 593335640Shselasky # 594335640Shselasky # Presumed to be DEC OSF/1, Digital UNIX, or 595335640Shselasky # Tru64 UNIX. 596335640Shselasky # 597335640Shselasky V_SHLIB_CMD="\$(CC)" 598335640Shselasky V_SHLIB_OPT="-shared" 599335640Shselasky V_SONAME_OPT="-soname " 600335640Shselasky V_RPATH_OPT="-rpath " 601335640Shselasky ;; 602335640Shselasky 603335640Shselasky solaris*) 604335640Shselasky V_SHLIB_CCOPT="$V_SHLIB_CCOPT -Kpic" 605335640Shselasky V_SHLIB_CMD="\$(CC)" 606335640Shselasky V_SHLIB_OPT="-G" 607335640Shselasky V_SONAME_OPT="-h " 608335640Shselasky V_RPATH_OPT="-R" 609335640Shselasky ;; 610335640Shselasky esac 611335640Shselasky fi 612335640Shselasky]) 613335640Shselasky 614335640Shselasky# 615335640Shselasky# Try compiling a sample of the type of code that appears in 616335640Shselasky# gencode.c with "inline", "__inline__", and "__inline". 617335640Shselasky# 618335640Shselasky# Autoconf's AC_C_INLINE, at least in autoconf 2.13, isn't good enough, 619335640Shselasky# as it just tests whether a function returning "int" can be inlined; 620335640Shselasky# at least some versions of HP's C compiler can inline that, but can't 621335640Shselasky# inline a function that returns a struct pointer. 622335640Shselasky# 623335640Shselasky# Make sure we use the V_CCOPT flags, because some of those might 624335640Shselasky# disable inlining. 625335640Shselasky# 626335640ShselaskyAC_DEFUN(AC_LBL_C_INLINE, 627335640Shselasky [AC_MSG_CHECKING(for inline) 628335640Shselasky save_CFLAGS="$CFLAGS" 629335640Shselasky CFLAGS="$V_CCOPT" 630335640Shselasky AC_CACHE_VAL(ac_cv_lbl_inline, [ 631335640Shselasky ac_cv_lbl_inline="" 632335640Shselasky ac_lbl_cc_inline=no 633335640Shselasky for ac_lbl_inline in inline __inline__ __inline 634335640Shselasky do 635335640Shselasky AC_TRY_COMPILE( 636335640Shselasky [#define inline $ac_lbl_inline 637335640Shselasky static inline struct iltest *foo(void); 638335640Shselasky struct iltest { 639335640Shselasky int iltest1; 640335640Shselasky int iltest2; 641335640Shselasky }; 642335640Shselasky 643335640Shselasky static inline struct iltest * 644335640Shselasky foo() 645335640Shselasky { 646335640Shselasky static struct iltest xxx; 647335640Shselasky 648335640Shselasky return &xxx; 649335640Shselasky }],,ac_lbl_cc_inline=yes,) 650335640Shselasky if test "$ac_lbl_cc_inline" = yes ; then 651335640Shselasky break; 652335640Shselasky fi 653335640Shselasky done 654335640Shselasky if test "$ac_lbl_cc_inline" = yes ; then 655335640Shselasky ac_cv_lbl_inline=$ac_lbl_inline 656335640Shselasky fi]) 657335640Shselasky CFLAGS="$save_CFLAGS" 658335640Shselasky if test ! -z "$ac_cv_lbl_inline" ; then 659335640Shselasky AC_MSG_RESULT($ac_cv_lbl_inline) 660335640Shselasky else 661335640Shselasky AC_MSG_RESULT(no) 662335640Shselasky fi 663335640Shselasky AC_DEFINE_UNQUOTED(inline, $ac_cv_lbl_inline, [Define as token for inline if inlining supported])]) 664335640Shselasky 665335640Shselaskydnl 666335640Shselaskydnl If using gcc, make sure we have ANSI ioctl definitions 667335640Shselaskydnl 668335640Shselaskydnl usage: 669335640Shselaskydnl 670335640Shselaskydnl AC_LBL_FIXINCLUDES 671335640Shselaskydnl 672335640ShselaskyAC_DEFUN(AC_LBL_FIXINCLUDES, 673335640Shselasky [if test "$GCC" = yes ; then 674335640Shselasky AC_MSG_CHECKING(for ANSI ioctl definitions) 675335640Shselasky AC_CACHE_VAL(ac_cv_lbl_gcc_fixincludes, 676335640Shselasky AC_TRY_COMPILE( 677335640Shselasky [/* 678335640Shselasky * This generates a "duplicate case value" when fixincludes 679335640Shselasky * has not be run. 680335640Shselasky */ 681335640Shselasky# include <sys/types.h> 682335640Shselasky# include <sys/time.h> 683335640Shselasky# include <sys/ioctl.h> 684335640Shselasky# ifdef HAVE_SYS_IOCCOM_H 685335640Shselasky# include <sys/ioccom.h> 686335640Shselasky# endif], 687335640Shselasky [switch (0) { 688335640Shselasky case _IO('A', 1):; 689335640Shselasky case _IO('B', 1):; 690335640Shselasky }], 691335640Shselasky ac_cv_lbl_gcc_fixincludes=yes, 692335640Shselasky ac_cv_lbl_gcc_fixincludes=no)) 693335640Shselasky AC_MSG_RESULT($ac_cv_lbl_gcc_fixincludes) 694335640Shselasky if test $ac_cv_lbl_gcc_fixincludes = no ; then 695335640Shselasky # Don't cache failure 696335640Shselasky unset ac_cv_lbl_gcc_fixincludes 697335640Shselasky AC_MSG_ERROR(see the INSTALL for more info) 698335640Shselasky fi 699335640Shselasky fi]) 700335640Shselasky 701335640Shselaskydnl 702335640Shselaskydnl Checks to see if union wait is used with WEXITSTATUS() 703335640Shselaskydnl 704335640Shselaskydnl usage: 705335640Shselaskydnl 706335640Shselaskydnl AC_LBL_UNION_WAIT 707335640Shselaskydnl 708335640Shselaskydnl results: 709335640Shselaskydnl 710335640Shselaskydnl DECLWAITSTATUS (defined) 711335640Shselaskydnl 712335640ShselaskyAC_DEFUN(AC_LBL_UNION_WAIT, 713335640Shselasky [AC_MSG_CHECKING(if union wait is used) 714335640Shselasky AC_CACHE_VAL(ac_cv_lbl_union_wait, 715335640Shselasky AC_TRY_COMPILE([ 716335640Shselasky# include <sys/types.h> 717335640Shselasky# include <sys/wait.h>], 718335640Shselasky [int status; 719335640Shselasky u_int i = WEXITSTATUS(status); 720335640Shselasky u_int j = waitpid(0, &status, 0);], 721335640Shselasky ac_cv_lbl_union_wait=no, 722335640Shselasky ac_cv_lbl_union_wait=yes)) 723335640Shselasky AC_MSG_RESULT($ac_cv_lbl_union_wait) 724335640Shselasky if test $ac_cv_lbl_union_wait = yes ; then 725335640Shselasky AC_DEFINE(DECLWAITSTATUS,union wait,[type for wait]) 726335640Shselasky else 727335640Shselasky AC_DEFINE(DECLWAITSTATUS,int,[type for wait]) 728335640Shselasky fi]) 729335640Shselasky 730335640Shselaskydnl 731335640Shselaskydnl Checks to see if -R is used 732335640Shselaskydnl 733335640Shselaskydnl usage: 734335640Shselaskydnl 735335640Shselaskydnl AC_LBL_HAVE_RUN_PATH 736335640Shselaskydnl 737335640Shselaskydnl results: 738335640Shselaskydnl 739335640Shselaskydnl ac_cv_lbl_have_run_path (yes or no) 740335640Shselaskydnl 741335640ShselaskyAC_DEFUN(AC_LBL_HAVE_RUN_PATH, 742335640Shselasky [AC_MSG_CHECKING(for ${CC-cc} -R) 743335640Shselasky AC_CACHE_VAL(ac_cv_lbl_have_run_path, 744335640Shselasky [echo 'main(){}' > conftest.c 745335640Shselasky ${CC-cc} -o conftest conftest.c -R/a1/b2/c3 >conftest.out 2>&1 746335640Shselasky if test ! -s conftest.out ; then 747335640Shselasky ac_cv_lbl_have_run_path=yes 748335640Shselasky else 749335640Shselasky ac_cv_lbl_have_run_path=no 750335640Shselasky fi 751335640Shselasky rm -f -r conftest*]) 752335640Shselasky AC_MSG_RESULT($ac_cv_lbl_have_run_path) 753335640Shselasky ]) 754335640Shselasky 755335640Shselaskydnl 756335640Shselaskydnl Checks to see if unaligned memory accesses fail 757335640Shselaskydnl 758335640Shselaskydnl usage: 759335640Shselaskydnl 760335640Shselaskydnl AC_LBL_UNALIGNED_ACCESS 761335640Shselaskydnl 762335640Shselaskydnl results: 763335640Shselaskydnl 764335640Shselaskydnl LBL_ALIGN (DEFINED) 765335640Shselaskydnl 766335640ShselaskyAC_DEFUN(AC_LBL_UNALIGNED_ACCESS, 767335640Shselasky [AC_MSG_CHECKING(if unaligned accesses fail) 768335640Shselasky AC_CACHE_VAL(ac_cv_lbl_unaligned_fail, 769335640Shselasky [case "$host_cpu" in 770335640Shselasky 771335640Shselasky # 772335640Shselasky # These are CPU types where: 773335640Shselasky # 774335640Shselasky # the CPU faults on an unaligned access, but at least some 775335640Shselasky # OSes that support that CPU catch the fault and simulate 776335640Shselasky # the unaligned access (e.g., Alpha/{Digital,Tru64} UNIX) - 777335640Shselasky # the simulation is slow, so we don't want to use it; 778335640Shselasky # 779335640Shselasky # the CPU, I infer (from the old 780335640Shselasky # 781335640Shselasky # XXX: should also check that they don't do weird things (like on arm) 782335640Shselasky # 783335640Shselasky # comment) doesn't fault on unaligned accesses, but doesn't 784335640Shselasky # do a normal unaligned fetch, either (e.g., presumably, ARM); 785335640Shselasky # 786335640Shselasky # for whatever reason, the test program doesn't work 787335640Shselasky # (this has been claimed to be the case for several of those 788335640Shselasky # CPUs - I don't know what the problem is; the problem 789335640Shselasky # was reported as "the test program dumps core" for SuperH, 790335640Shselasky # but that's what the test program is *supposed* to do - 791335640Shselasky # it dumps core before it writes anything, so the test 792335640Shselasky # for an empty output file should find an empty output 793335640Shselasky # file and conclude that unaligned accesses don't work). 794335640Shselasky # 795335640Shselasky # This run-time test won't work if you're cross-compiling, so 796335640Shselasky # in order to support cross-compiling for a particular CPU, 797335640Shselasky # we have to wire in the list of CPU types anyway, as far as 798335640Shselasky # I know, so perhaps we should just have a set of CPUs on 799335640Shselasky # which we know it doesn't work, a set of CPUs on which we 800335640Shselasky # know it does work, and have the script just fail on other 801335640Shselasky # cpu types and update it when such a failure occurs. 802335640Shselasky # 803335640Shselasky alpha*|arm*|bfin*|hp*|mips*|sh*|sparc*|ia64|nv1) 804335640Shselasky ac_cv_lbl_unaligned_fail=yes 805335640Shselasky ;; 806335640Shselasky 807335640Shselasky *) 808335640Shselasky cat >conftest.c <<EOF 809335640Shselasky# include <sys/types.h> 810335640Shselasky# include <sys/wait.h> 811335640Shselasky# include <stdio.h> 812335640Shselasky unsigned char a[[5]] = { 1, 2, 3, 4, 5 }; 813335640Shselasky main() { 814335640Shselasky unsigned int i; 815335640Shselasky pid_t pid; 816335640Shselasky int status; 817335640Shselasky /* avoid "core dumped" message */ 818335640Shselasky pid = fork(); 819335640Shselasky if (pid < 0) 820335640Shselasky exit(2); 821335640Shselasky if (pid > 0) { 822335640Shselasky /* parent */ 823335640Shselasky pid = waitpid(pid, &status, 0); 824335640Shselasky if (pid < 0) 825335640Shselasky exit(3); 826335640Shselasky exit(!WIFEXITED(status)); 827335640Shselasky } 828335640Shselasky /* child */ 829335640Shselasky i = *(unsigned int *)&a[[1]]; 830335640Shselasky printf("%d\n", i); 831335640Shselasky exit(0); 832335640Shselasky } 833335640ShselaskyEOF 834335640Shselasky ${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS \ 835335640Shselasky conftest.c $LIBS >/dev/null 2>&1 836335640Shselasky if test ! -x conftest ; then 837335640Shselasky dnl failed to compile for some reason 838335640Shselasky ac_cv_lbl_unaligned_fail=yes 839335640Shselasky else 840335640Shselasky ./conftest >conftest.out 841335640Shselasky if test ! -s conftest.out ; then 842335640Shselasky ac_cv_lbl_unaligned_fail=yes 843335640Shselasky else 844335640Shselasky ac_cv_lbl_unaligned_fail=no 845335640Shselasky fi 846335640Shselasky fi 847335640Shselasky rm -f -r conftest* core core.conftest 848335640Shselasky ;; 849335640Shselasky esac]) 850335640Shselasky AC_MSG_RESULT($ac_cv_lbl_unaligned_fail) 851335640Shselasky if test $ac_cv_lbl_unaligned_fail = yes ; then 852335640Shselasky AC_DEFINE(LBL_ALIGN,1,[if unaligned access fails]) 853335640Shselasky fi]) 854335640Shselasky 855335640Shselaskydnl 856335640Shselaskydnl If the file .devel exists: 857335640Shselaskydnl Add some warning flags if the compiler supports them 858335640Shselaskydnl If an os prototype include exists, symlink os-proto.h to it 859335640Shselaskydnl 860335640Shselaskydnl usage: 861335640Shselaskydnl 862335640Shselaskydnl AC_LBL_DEVEL(copt) 863335640Shselaskydnl 864335640Shselaskydnl results: 865335640Shselaskydnl 866335640Shselaskydnl $1 (copt appended) 867335640Shselaskydnl HAVE_OS_PROTO_H (defined) 868335640Shselaskydnl os-proto.h (symlinked) 869335640Shselaskydnl 870335640ShselaskyAC_DEFUN(AC_LBL_DEVEL, 871335640Shselasky [rm -f os-proto.h 872335640Shselasky if test "${LBL_CFLAGS+set}" = set; then 873335640Shselasky $1="$$1 ${LBL_CFLAGS}" 874335640Shselasky fi 875335640Shselasky if test -f .devel ; then 876335640Shselasky # 877335640Shselasky # Skip all the warning option stuff on some compilers. 878335640Shselasky # 879335640Shselasky if test "$ac_lbl_cc_dont_try_gcc_dashW" != yes; then 880335640Shselasky AC_LBL_CHECK_UNKNOWN_WARNING_OPTION_ERROR() 881356341Scy AC_LBL_CHECK_COMPILER_OPT($1, -W) 882335640Shselasky AC_LBL_CHECK_COMPILER_OPT($1, -Wall) 883356341Scy AC_LBL_CHECK_COMPILER_OPT($1, -Wcomma) 884356341Scy AC_LBL_CHECK_COMPILER_OPT($1, -Wdeclaration-after-statement) 885356341Scy AC_LBL_CHECK_COMPILER_OPT($1, -Wdocumentation) 886356341Scy AC_LBL_CHECK_COMPILER_OPT($1, -Wformat-nonliteral) 887356341Scy AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-noreturn) 888356341Scy AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-prototypes) 889356341Scy AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-variable-declarations) 890356341Scy AC_LBL_CHECK_COMPILER_OPT($1, -Wshadow) 891335640Shselasky AC_LBL_CHECK_COMPILER_OPT($1, -Wsign-compare) 892335640Shselasky AC_LBL_CHECK_COMPILER_OPT($1, -Wstrict-prototypes) 893356341Scy AC_LBL_CHECK_COMPILER_OPT($1, -Wunused-parameter) 894335640Shselasky AC_LBL_CHECK_COMPILER_OPT($1, -Wused-but-marked-unused) 895335640Shselasky # Warns about safeguards added in case the enums are 896335640Shselasky # extended 897335640Shselasky # AC_LBL_CHECK_COMPILER_OPT($1, -Wcovered-switch-default) 898356341Scy # 899356341Scy # This can cause problems with ntohs(), ntohl(), 900356341Scy # htons(), and htonl() on some platforms, such 901356341Scy # as OpenBSD 6.3 with Clang 5.0.1. I guess the 902356341Scy # problem is that the macro that ultimately does 903356341Scy # the byte-swapping involves a conditional 904356341Scy # expression that tests whether the value being 905356341Scy # swapped is a compile-time constant or not, 906356341Scy # using __builtin_constant_p(), and, depending 907356341Scy # on whether it is, does a compile-time swap or 908356341Scy # a run-time swap; perhaps the compiler always 909356341Scy # considers one of the two results of the 910356341Scy # conditional expressin is never evaluated, 911356341Scy # because the conditional check is done at 912356341Scy # compile time, and thus always says "that 913356341Scy # expression is never executed". 914356341Scy # 915356341Scy # (Perhaps there should be a way of flagging 916356341Scy # an expression that you *want* evaluated at 917356341Scy # compile time, so that the compiler 1) warns 918356341Scy # if it *can't* be evaluated at compile time 919356341Scy # and 2) *doesn't* warn that the true or false 920356341Scy # branch will never be reached.) 921356341Scy # 922356341Scy AC_LBL_CHECK_COMPILER_OPT($1, -Wunreachable-code, 923356341Scy [ 924356341Scy#include <arpa/inet.h> 925356341Scy 926356341Scyunsigned short 927356341Scytestme(unsigned short a) 928356341Scy{ 929356341Scy return ntohs(a); 930356341Scy} 931356341Scy ], 932356341Scy [generates warnings from ntohs()]) 933335640Shselasky fi 934335640Shselasky AC_LBL_CHECK_DEPENDENCY_GENERATION_OPT() 935335640Shselasky # 936335640Shselasky # We used to set -n32 for IRIX 6 when not using GCC (presumed 937335640Shselasky # to mean that we're using MIPS C or MIPSpro C); it specified 938335640Shselasky # the "new" faster 32-bit ABI, introduced in IRIX 6.2. I'm 939335640Shselasky # not sure why that would be something to do *only* with a 940335640Shselasky # .devel file; why should the ABI for which we produce code 941335640Shselasky # depend on .devel? 942335640Shselasky # 943335640Shselasky os=`echo $host_os | sed -e 's/\([[0-9]][[0-9]]*\)[[^0-9]].*$/\1/'` 944335640Shselasky name="lbl/os-$os.h" 945335640Shselasky if test -f $name ; then 946335640Shselasky ln -s $name os-proto.h 947335640Shselasky AC_DEFINE(HAVE_OS_PROTO_H, 1, 948335640Shselasky [if there's an os_proto.h for this platform, to use additional prototypes]) 949335640Shselasky else 950335640Shselasky AC_MSG_WARN(can't find $name) 951335640Shselasky fi 952335640Shselasky fi]) 953335640Shselasky 954335640Shselaskydnl 955335640Shselaskydnl Improved version of AC_CHECK_LIB 956335640Shselaskydnl 957335640Shselaskydnl Thanks to John Hawkinson (jhawk@mit.edu) 958335640Shselaskydnl 959335640Shselaskydnl usage: 960335640Shselaskydnl 961335640Shselaskydnl AC_LBL_CHECK_LIB(LIBRARY, FUNCTION [, ACTION-IF-FOUND [, 962335640Shselaskydnl ACTION-IF-NOT-FOUND [, OTHER-LIBRARIES]]]) 963335640Shselaskydnl 964335640Shselaskydnl results: 965335640Shselaskydnl 966335640Shselaskydnl LIBS 967335640Shselaskydnl 968335640Shselaskydnl XXX - "AC_LBL_LIBRARY_NET" was redone to use "AC_SEARCH_LIBS" 969335640Shselaskydnl rather than "AC_LBL_CHECK_LIB", so this isn't used any more. 970335640Shselaskydnl We keep it around for reference purposes in case it's ever 971335640Shselaskydnl useful in the future. 972335640Shselaskydnl 973335640Shselasky 974335640Shselaskydefine(AC_LBL_CHECK_LIB, 975335640Shselasky[AC_MSG_CHECKING([for $2 in -l$1]) 976335640Shselaskydnl Use a cache variable name containing the library, function 977335640Shselaskydnl name, and extra libraries to link with, because the test really is 978335640Shselaskydnl for library $1 defining function $2, when linked with potinal 979335640Shselaskydnl library $5, not just for library $1. Separate tests with the same 980335640Shselaskydnl $1 and different $2's or $5's may have different results. 981335640Shselaskyac_lib_var=`echo $1['_']$2['_']$5 | sed 'y%./+- %__p__%'` 982335640ShselaskyAC_CACHE_VAL(ac_cv_lbl_lib_$ac_lib_var, 983335640Shselasky[ac_save_LIBS="$LIBS" 984335640ShselaskyLIBS="-l$1 $5 $LIBS" 985335640ShselaskyAC_TRY_LINK(dnl 986335640Shselaskyifelse([$2], [main], , dnl Avoid conflicting decl of main. 987335640Shselasky[/* Override any gcc2 internal prototype to avoid an error. */ 988335640Shselasky]ifelse(AC_LANG, CPLUSPLUS, [#ifdef __cplusplus 989335640Shselaskyextern "C" 990335640Shselasky#endif 991335640Shselasky])dnl 992335640Shselasky[/* We use char because int might match the return type of a gcc2 993335640Shselasky builtin and then its argument prototype would still apply. */ 994335640Shselaskychar $2(); 995335640Shselasky]), 996335640Shselasky [$2()], 997335640Shselasky eval "ac_cv_lbl_lib_$ac_lib_var=yes", 998335640Shselasky eval "ac_cv_lbl_lib_$ac_lib_var=no") 999335640ShselaskyLIBS="$ac_save_LIBS" 1000335640Shselasky])dnl 1001335640Shselaskyif eval "test \"`echo '$ac_cv_lbl_lib_'$ac_lib_var`\" = yes"; then 1002335640Shselasky AC_MSG_RESULT(yes) 1003335640Shselasky ifelse([$3], , 1004335640Shselasky[changequote(, )dnl 1005335640Shselasky ac_tr_lib=HAVE_LIB`echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g' \ 1006335640Shselasky -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` 1007335640Shselaskychangequote([, ])dnl 1008335640Shselasky AC_DEFINE_UNQUOTED($ac_tr_lib) 1009335640Shselasky LIBS="-l$1 $LIBS" 1010335640Shselasky], [$3]) 1011335640Shselaskyelse 1012335640Shselasky AC_MSG_RESULT(no) 1013335640Shselaskyifelse([$4], , , [$4 1014335640Shselasky])dnl 1015335640Shselaskyfi 1016335640Shselasky]) 1017335640Shselasky 1018335640Shselaskydnl 1019335640Shselaskydnl AC_LBL_LIBRARY_NET 1020335640Shselaskydnl 1021335640Shselaskydnl This test is for network applications that need socket functions and 1022335640Shselaskydnl getaddrinfo()/getnameinfo()-ish functions. We now require 1023335640Shselaskydnl getaddrinfo() and getnameinfo(). We also prefer versions of 1024335640Shselaskydnl recvmsg() that conform to the Single UNIX Specification, so that we 1025335640Shselaskydnl can check whether a datagram received with recvmsg() was truncated 1026335640Shselaskydnl when received due to the buffer being too small. 1027335640Shselaskydnl 1028335640Shselaskydnl On most operating systems, they're available in the system library. 1029335640Shselaskydnl 1030335640Shselaskydnl Under Solaris, we need to link with libsocket and libnsl to get 1031335640Shselaskydnl getaddrinfo() and getnameinfo() and, if we have libxnet, we need to 1032335640Shselaskydnl link with libxnet before libsocket to get a version of recvmsg() 1033335640Shselaskydnl that conforms to the Single UNIX Specification. 1034335640Shselaskydnl 1035335640Shselaskydnl We use getaddrinfo() because we want a portable thread-safe way 1036335640Shselaskydnl of getting information for a host name or port; there exist _r 1037335640Shselaskydnl versions of gethostbyname() and getservbyname() on some platforms, 1038335640Shselaskydnl but not on all platforms. 1039335640Shselaskydnl 1040335640ShselaskyAC_DEFUN(AC_LBL_LIBRARY_NET, [ 1041335640Shselasky # 1042335640Shselasky # Most operating systems have getaddrinfo() in the default searched 1043335640Shselasky # libraries (i.e. libc). Check there first. 1044335640Shselasky # 1045335640Shselasky AC_CHECK_FUNC(getaddrinfo,, 1046335640Shselasky [ 1047335640Shselasky # 1048335640Shselasky # Not found in the standard system libraries. 1049335640Shselasky # Try libsocket, which requires libnsl. 1050335640Shselasky # 1051335640Shselasky AC_CHECK_LIB(socket, getaddrinfo, 1052335640Shselasky [ 1053335640Shselasky # 1054335640Shselasky # OK, we found it in libsocket. 1055335640Shselasky # 1056335640Shselasky LIBS="-lsocket -lnsl $LIBS" 1057335640Shselasky ], 1058335640Shselasky [ 1059335640Shselasky # 1060335640Shselasky # We didn't find it. 1061335640Shselasky # 1062335640Shselasky AC_MSG_ERROR([getaddrinfo is required, but wasn't found]) 1063335640Shselasky ], -lnsl) 1064335640Shselasky 1065335640Shselasky # 1066335640Shselasky # OK, do we have recvmsg() in libxnet? 1067335640Shselasky # We also link with libsocket and libnsl. 1068335640Shselasky # 1069335640Shselasky AC_CHECK_LIB(xnet, recvmsg, 1070335640Shselasky [ 1071335640Shselasky # 1072335640Shselasky # Yes - link with it as well. 1073335640Shselasky # 1074335640Shselasky LIBS="-lxnet $LIBS" 1075335640Shselasky ], , -lsocket -lnsl) 1076335640Shselasky ]) 1077335640Shselasky # DLPI needs putmsg under HPUX so test for -lstr while we're at it 1078335640Shselasky AC_SEARCH_LIBS(putmsg, str) 1079335640Shselasky]) 1080