blob: 786423bfdf84003b3c7f9d8bea3c241311234f18 [file] [log] [blame]
The Android Open Source Project478ab6c2009-03-03 19:30:05 -08001dnl Copyright (c) 1995, 1996, 1997, 1998
2dnl The Regents of the University of California. All rights reserved.
3dnl
4dnl Redistribution and use in source and binary forms, with or without
5dnl modification, are permitted provided that: (1) source code distributions
6dnl retain the above copyright notice and this paragraph in its entirety, (2)
7dnl distributions including binary code include the above copyright notice and
8dnl this paragraph in its entirety in the documentation or other materials
9dnl provided with the distribution, and (3) all advertising materials mentioning
10dnl features or use of this software display the following acknowledgement:
11dnl ``This product includes software developed by the University of California,
12dnl Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
13dnl the University nor the names of its contributors may be used to endorse
14dnl or promote products derived from this software without specific prior
15dnl written permission.
16dnl THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
17dnl WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
18dnl MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19dnl
20dnl LBL autoconf macros
21dnl
22
23dnl
JP Abgrall511eca32014-02-12 13:46:45 -080024dnl Do whatever AC_LBL_C_INIT work is necessary before using AC_PROG_CC.
The Android Open Source Project478ab6c2009-03-03 19:30:05 -080025dnl
JP Abgrall511eca32014-02-12 13:46:45 -080026dnl It appears that newer versions of autoconf (2.64 and later) will,
27dnl if you use AC_TRY_COMPILE in a macro, stick AC_PROG_CC at the
28dnl beginning of the macro, even if the macro itself calls AC_PROG_CC.
29dnl See the "Prerequisite Macros" and "Expanded Before Required" sections
30dnl in the Autoconf documentation.
The Android Open Source Project478ab6c2009-03-03 19:30:05 -080031dnl
JP Abgrall511eca32014-02-12 13:46:45 -080032dnl This causes a steaming heap of fail in our case, as we were, in
33dnl AC_LBL_C_INIT, doing the tests we now do in AC_LBL_C_INIT_BEFORE_CC,
34dnl calling AC_PROG_CC, and then doing the tests we now do in
35dnl AC_LBL_C_INIT. Now, we run AC_LBL_C_INIT_BEFORE_CC, AC_PROG_CC,
36dnl and AC_LBL_C_INIT at the top level.
The Android Open Source Project478ab6c2009-03-03 19:30:05 -080037dnl
JP Abgrall511eca32014-02-12 13:46:45 -080038AC_DEFUN(AC_LBL_C_INIT_BEFORE_CC,
39[
40 AC_BEFORE([$0], [AC_LBL_C_INIT])
The Android Open Source Project478ab6c2009-03-03 19:30:05 -080041 AC_BEFORE([$0], [AC_PROG_CC])
42 AC_BEFORE([$0], [AC_LBL_FIXINCLUDES])
43 AC_BEFORE([$0], [AC_LBL_DEVEL])
44 AC_ARG_WITH(gcc, [ --without-gcc don't use gcc])
JP Abgrall511eca32014-02-12 13:46:45 -080045 $1=""
The Android Open Source Project478ab6c2009-03-03 19:30:05 -080046 if test "${srcdir}" != "." ; then
JP Abgrall511eca32014-02-12 13:46:45 -080047 $1="-I\$(srcdir)"
The Android Open Source Project478ab6c2009-03-03 19:30:05 -080048 fi
49 if test "${CFLAGS+set}" = set; then
50 LBL_CFLAGS="$CFLAGS"
51 fi
52 if test -z "$CC" ; then
JP Abgrall511eca32014-02-12 13:46:45 -080053 case "$host_os" in
The Android Open Source Project478ab6c2009-03-03 19:30:05 -080054
55 bsdi*)
56 AC_CHECK_PROG(SHLICC2, shlicc2, yes, no)
57 if test $SHLICC2 = yes ; then
58 CC=shlicc2
59 export CC
60 fi
61 ;;
62 esac
63 fi
64 if test -z "$CC" -a "$with_gcc" = no ; then
65 CC=cc
66 export CC
67 fi
JP Abgrall511eca32014-02-12 13:46:45 -080068])
69
70dnl
71dnl Determine which compiler we're using (cc or gcc)
72dnl If using gcc, determine the version number
73dnl If using cc:
74dnl require that it support ansi prototypes
75dnl use -O (AC_PROG_CC will use -g -O2 on gcc, so we don't need to
76dnl do that ourselves for gcc)
77dnl add -g flags, as appropriate
78dnl explicitly specify /usr/local/include
79dnl
80dnl NOTE WELL: with newer versions of autoconf, "gcc" means any compiler
81dnl that defines __GNUC__, which means clang, for example, counts as "gcc".
82dnl
83dnl usage:
84dnl
85dnl AC_LBL_C_INIT(copt, incls)
86dnl
87dnl results:
88dnl
89dnl $1 (copt set)
90dnl $2 (incls set)
91dnl CC
92dnl LDFLAGS
93dnl LBL_CFLAGS
94dnl
95AC_DEFUN(AC_LBL_C_INIT,
96[
97 AC_BEFORE([$0], [AC_LBL_FIXINCLUDES])
98 AC_BEFORE([$0], [AC_LBL_DEVEL])
99 AC_BEFORE([$0], [AC_LBL_SHLIBS_INIT])
The Android Open Source Project478ab6c2009-03-03 19:30:05 -0800100 if test "$GCC" = yes ; then
JP Abgrall511eca32014-02-12 13:46:45 -0800101 #
102 # -Werror forces warnings to be errors.
103 #
104 ac_lbl_cc_force_warning_errors=-Werror
Elliott Hughes965a4b52017-05-15 10:37:39 -0700105
106 #
107 # Try to have the compiler default to hiding symbols,
108 # so that only symbols explicitly exported with
109 # PCAP_API will be visible outside (shared) libraries.
110 #
111 AC_LBL_CHECK_COMPILER_OPT($1, -fvisibility=hidden)
The Android Open Source Project478ab6c2009-03-03 19:30:05 -0800112 else
The Android Open Source Project478ab6c2009-03-03 19:30:05 -0800113 $2="$$2 -I/usr/local/include"
114 LDFLAGS="$LDFLAGS -L/usr/local/lib"
115
JP Abgrall511eca32014-02-12 13:46:45 -0800116 case "$host_os" in
117
118 darwin*)
119 #
120 # This is assumed either to be GCC or clang, both
121 # of which use -Werror to force warnings to be errors.
122 #
123 ac_lbl_cc_force_warning_errors=-Werror
Elliott Hughes965a4b52017-05-15 10:37:39 -0700124
125 #
126 # Try to have the compiler default to hiding symbols,
127 # so that only symbols explicitly exported with
128 # PCAP_API will be visible outside (shared) libraries.
129 #
130 AC_LBL_CHECK_COMPILER_OPT($1, -fvisibility=hidden)
JP Abgrall511eca32014-02-12 13:46:45 -0800131 ;;
132
133 hpux*)
134 #
135 # HP C, which is what we presume we're using, doesn't
136 # exit with a non-zero exit status if we hand it an
137 # invalid -W flag, can't be forced to do so even with
138 # +We, and doesn't handle GCC-style -W flags, so we
139 # don't want to try using GCC-style -W flags.
140 #
141 ac_lbl_cc_dont_try_gcc_dashW=yes
142 ;;
The Android Open Source Project478ab6c2009-03-03 19:30:05 -0800143
144 irix*)
JP Abgrall511eca32014-02-12 13:46:45 -0800145 #
146 # MIPS C, which is what we presume we're using, doesn't
147 # necessarily exit with a non-zero exit status if we
148 # hand it an invalid -W flag, can't be forced to do
149 # so, and doesn't handle GCC-style -W flags, so we
150 # don't want to try using GCC-style -W flags.
151 #
152 ac_lbl_cc_dont_try_gcc_dashW=yes
153 #
154 # It also, apparently, defaults to "char" being
155 # unsigned, unlike most other C implementations;
156 # I suppose we could say "signed char" whenever
157 # we want to guarantee a signed "char", but let's
158 # just force signed chars.
159 #
160 # -xansi is normally the default, but the
161 # configure script was setting it; perhaps -cckr
162 # was the default in the Old Days. (Then again,
163 # that would probably be for backwards compatibility
164 # in the days when ANSI C was Shiny and New, i.e.
165 # 1989 and the early '90's, so maybe we can just
166 # drop support for those compilers.)
167 #
168 # -g is equivalent to -g2, which turns off
169 # optimization; we choose -g3, which generates
170 # debugging information but doesn't turn off
171 # optimization (even if the optimization would
172 # cause inaccuracies in debugging).
173 #
174 $1="$$1 -xansi -signed -g3"
The Android Open Source Project478ab6c2009-03-03 19:30:05 -0800175 ;;
176
177 osf*)
JP Abgrall511eca32014-02-12 13:46:45 -0800178 #
179 # Presumed to be DEC OSF/1, Digital UNIX, or
180 # Tru64 UNIX.
181 #
182 # The DEC C compiler, which is what we presume we're
183 # using, doesn't exit with a non-zero exit status if we
184 # hand it an invalid -W flag, can't be forced to do
185 # so, and doesn't handle GCC-style -W flags, so we
186 # don't want to try using GCC-style -W flags.
187 #
188 ac_lbl_cc_dont_try_gcc_dashW=yes
189 #
190 # -g is equivalent to -g2, which turns off
191 # optimization; we choose -g3, which generates
192 # debugging information but doesn't turn off
193 # optimization (even if the optimization would
194 # cause inaccuracies in debugging).
195 #
196 $1="$$1 -g3"
197 ;;
198
199 solaris*)
200 #
201 # Assumed to be Sun C, which requires -errwarn to force
202 # warnings to be treated as errors.
203 #
204 ac_lbl_cc_force_warning_errors=-errwarn
Elliott Hughes965a4b52017-05-15 10:37:39 -0700205
206 #
207 # Try to have the compiler default to hiding symbols,
208 # so that only symbols explicitly exported with
209 # PCAP_API will be visible outside (shared) libraries.
210 #
211 AC_LBL_CHECK_COMPILER_OPT($1, -xldscope=hidden)
The Android Open Source Project478ab6c2009-03-03 19:30:05 -0800212 ;;
213
214 ultrix*)
215 AC_MSG_CHECKING(that Ultrix $CC hacks const in prototypes)
216 AC_CACHE_VAL(ac_cv_lbl_cc_const_proto,
217 AC_TRY_COMPILE(
218 [#include <sys/types.h>],
219 [struct a { int b; };
220 void c(const struct a *)],
221 ac_cv_lbl_cc_const_proto=yes,
222 ac_cv_lbl_cc_const_proto=no))
223 AC_MSG_RESULT($ac_cv_lbl_cc_const_proto)
224 if test $ac_cv_lbl_cc_const_proto = no ; then
JP Abgrall511eca32014-02-12 13:46:45 -0800225 AC_DEFINE(const,[],
226 [to handle Ultrix compilers that don't support const in prototypes])
The Android Open Source Project478ab6c2009-03-03 19:30:05 -0800227 fi
228 ;;
229 esac
JP Abgrall511eca32014-02-12 13:46:45 -0800230 $1="$$1 -O"
231 fi
232])
233
234dnl
235dnl Check whether, if you pass an unknown warning option to the
236dnl compiler, it fails or just prints a warning message and succeeds.
237dnl Set ac_lbl_unknown_warning_option_error to the appropriate flag
238dnl to force an error if it would otherwise just print a warning message
239dnl and succeed.
240dnl
241AC_DEFUN(AC_LBL_CHECK_UNKNOWN_WARNING_OPTION_ERROR,
242 [
243 AC_MSG_CHECKING([whether the compiler fails when given an unknown warning option])
244 save_CFLAGS="$CFLAGS"
245 CFLAGS="$CFLAGS -Wxyzzy-this-will-never-succeed-xyzzy"
246 AC_TRY_COMPILE(
247 [],
248 [return 0],
249 [
250 AC_MSG_RESULT([no])
251 #
252 # We're assuming this is clang, where
253 # -Werror=unknown-warning-option is the appropriate
254 # option to force the compiler to fail.
Elliott Hughesd8845d72015-10-19 18:07:04 -0700255 #
JP Abgrall511eca32014-02-12 13:46:45 -0800256 ac_lbl_unknown_warning_option_error="-Werror=unknown-warning-option"
257 ],
258 [
259 AC_MSG_RESULT([yes])
260 ])
261 CFLAGS="$save_CFLAGS"
262 ])
263
264dnl
265dnl Check whether the compiler option specified as the second argument
266dnl is supported by the compiler and, if so, add it to the macro
267dnl specified as the first argument
268dnl
Haibo Huang165065a2018-07-23 17:26:52 -0700269dnl If a third argument is supplied, treat it as C code to be compiled
270dnl with the flag in question, and the "treat warnings as errors" flag
271dnl set, and don't add the flag to the first argument if the compile
272dnl fails; this is for warning options cause problems that can't be
273dnl worked around. If a third argument is supplied, a fourth argument
Haibo Huangee759ce2021-01-05 21:34:29 -0800274dnl should also be supplied; it's a message describing what the test
Haibo Huang165065a2018-07-23 17:26:52 -0700275dnl program is checking.
276dnl
JP Abgrall511eca32014-02-12 13:46:45 -0800277AC_DEFUN(AC_LBL_CHECK_COMPILER_OPT,
278 [
279 AC_MSG_CHECKING([whether the compiler supports the $2 option])
280 save_CFLAGS="$CFLAGS"
Elliott Hughes965a4b52017-05-15 10:37:39 -0700281 if expr "x$2" : "x-W.*" >/dev/null
282 then
283 CFLAGS="$CFLAGS $ac_lbl_unknown_warning_option_error $2"
284 elif expr "x$2" : "x-f.*" >/dev/null
285 then
286 CFLAGS="$CFLAGS -Werror $2"
287 elif expr "x$2" : "x-m.*" >/dev/null
288 then
289 CFLAGS="$CFLAGS -Werror $2"
290 else
291 CFLAGS="$CFLAGS $2"
292 fi
JP Abgrall511eca32014-02-12 13:46:45 -0800293 AC_TRY_COMPILE(
294 [],
295 [return 0],
296 [
297 AC_MSG_RESULT([yes])
Haibo Huang165065a2018-07-23 17:26:52 -0700298 can_add_to_cflags=yes
299 #
300 # The compile supports this; do we have some C code for
301 # which the warning should *not* appear?
302 # We test the fourth argument because the third argument
303 # could contain quotes, breaking the test.
304 #
305 if test "x$4" != "x"
306 then
307 CFLAGS="$CFLAGS $ac_lbl_cc_force_warning_errors"
308 AC_MSG_CHECKING(whether $2 $4)
309 AC_COMPILE_IFELSE(
310 [AC_LANG_SOURCE($3)],
311 [
312 #
313 # Not a problem.
314 #
315 AC_MSG_RESULT(no)
316 ],
317 [
318 #
319 # A problem.
320 #
321 AC_MSG_RESULT(yes)
322 can_add_to_cflags=no
323 ])
324 fi
JP Abgrall511eca32014-02-12 13:46:45 -0800325 CFLAGS="$save_CFLAGS"
Haibo Huang165065a2018-07-23 17:26:52 -0700326 if test x"$can_add_to_cflags" = "xyes"
327 then
328 $1="$$1 $2"
329 fi
JP Abgrall511eca32014-02-12 13:46:45 -0800330 ],
331 [
332 AC_MSG_RESULT([no])
333 CFLAGS="$save_CFLAGS"
334 ])
335 ])
336
337dnl
338dnl Check whether the compiler supports an option to generate
339dnl Makefile-style dependency lines
340dnl
341dnl GCC uses -M for this. Non-GCC compilers that support this
342dnl use a variety of flags, including but not limited to -M.
343dnl
344dnl We test whether the flag in question is supported, as older
345dnl versions of compilers might not support it.
346dnl
347dnl We don't try all the possible flags, just in case some flag means
348dnl "generate dependencies" on one compiler but means something else
349dnl on another compiler.
350dnl
351dnl Most compilers that support this send the output to the standard
352dnl output by default. IBM's XLC, however, supports -M but sends
353dnl the output to {sourcefile-basename}.u, and AIX has no /dev/stdout
354dnl to work around that, so we don't bother with XLC.
355dnl
356AC_DEFUN(AC_LBL_CHECK_DEPENDENCY_GENERATION_OPT,
357 [
358 AC_MSG_CHECKING([whether the compiler supports generating dependencies])
359 if test "$GCC" = yes ; then
360 #
361 # GCC, or a compiler deemed to be GCC by AC_PROG_CC (even
362 # though it's not); we assume that, in this case, the flag
363 # would be -M.
364 #
365 ac_lbl_dependency_flag="-M"
366 else
367 #
368 # Not GCC or a compiler deemed to be GCC; what platform is
369 # this? (We're assuming that if the compiler isn't GCC
370 # it's the compiler from the vendor of the OS; that won't
371 # necessarily be true for x86 platforms, where it might be
372 # the Intel C compiler.)
373 #
374 case "$host_os" in
375
376 irix*|osf*|darwin*)
377 #
378 # MIPS C for IRIX, DEC C, and clang all use -M.
379 #
380 ac_lbl_dependency_flag="-M"
381 ;;
382
383 solaris*)
384 #
385 # Sun C uses -xM.
386 #
387 ac_lbl_dependency_flag="-xM"
388 ;;
389
390 hpux*)
391 #
392 # HP's older C compilers don't support this.
393 # HP's newer C compilers support this with
394 # either +M or +Make; the older compilers
395 # interpret +M as something completely
396 # different, so we use +Make so we don't
397 # think it works with the older compilers.
398 #
399 ac_lbl_dependency_flag="+Make"
400 ;;
401
402 *)
403 #
404 # Not one of the above; assume no support for
405 # generating dependencies.
406 #
407 ac_lbl_dependency_flag=""
408 ;;
409 esac
410 fi
411
412 #
413 # Is ac_lbl_dependency_flag defined and, if so, does the compiler
414 # complain about it?
415 #
416 # Note: clang doesn't seem to exit with an error status when handed
417 # an unknown non-warning error, even if you pass it
418 # -Werror=unknown-warning-option. However, it always supports
419 # -M, so the fact that this test always succeeds with clang
420 # isn't an issue.
421 #
422 if test ! -z "$ac_lbl_dependency_flag"; then
423 AC_LANG_CONFTEST(
424 [AC_LANG_SOURCE([[int main(void) { return 0; }]])])
Haibo Huang165065a2018-07-23 17:26:52 -0700425 if AC_RUN_LOG([eval "$CC $ac_lbl_dependency_flag conftest.c >/dev/null 2>&1"]); then
JP Abgrall511eca32014-02-12 13:46:45 -0800426 AC_MSG_RESULT([yes, with $ac_lbl_dependency_flag])
427 DEPENDENCY_CFLAG="$ac_lbl_dependency_flag"
Haibo Huangee759ce2021-01-05 21:34:29 -0800428 MKDEP='${top_srcdir}/mkdep'
JP Abgrall511eca32014-02-12 13:46:45 -0800429 else
430 AC_MSG_RESULT([no])
431 #
432 # We can't run mkdep, so have "make depend" do
433 # nothing.
434 #
Haibo Huangee759ce2021-01-05 21:34:29 -0800435 MKDEP='${top_srcdir}/nomkdep'
JP Abgrall511eca32014-02-12 13:46:45 -0800436 fi
437 rm -rf conftest*
438 else
439 AC_MSG_RESULT([no])
440 #
441 # We can't run mkdep, so have "make depend" do
442 # nothing.
443 #
Haibo Huangee759ce2021-01-05 21:34:29 -0800444 MKDEP='${top_srcdir}/nomkdep'
JP Abgrall511eca32014-02-12 13:46:45 -0800445 fi
446 AC_SUBST(DEPENDENCY_CFLAG)
447 AC_SUBST(MKDEP)
448 ])
449
450dnl
451dnl Determine what options are needed to build a shared library
452dnl
453dnl usage:
454dnl
455dnl AC_LBL_SHLIBS_INIT
456dnl
457dnl results:
458dnl
Haibo Huang165065a2018-07-23 17:26:52 -0700459dnl V_SHLIB_CCOPT (modified to build position-independent code)
JP Abgrall511eca32014-02-12 13:46:45 -0800460dnl V_SHLIB_CMD
461dnl V_SHLIB_OPT
462dnl V_SONAME_OPT
463dnl V_RPATH_OPT
464dnl
465AC_DEFUN(AC_LBL_SHLIBS_INIT,
466 [AC_PREREQ(2.50)
467 if test "$GCC" = yes ; then
468 #
469 # On platforms where we build a shared library:
470 #
471 # add options to generate position-independent code,
Haibo Huang165065a2018-07-23 17:26:52 -0700472 # if necessary (it's the default in AIX and Darwin/macOS);
JP Abgrall511eca32014-02-12 13:46:45 -0800473 #
474 # define option to set the soname of the shared library,
475 # if the OS supports that;
476 #
477 # add options to specify, at link time, a directory to
478 # add to the run-time search path, if that's necessary.
479 #
480 V_SHLIB_CMD="\$(CC)"
481 V_SHLIB_OPT="-shared"
482 case "$host_os" in
483
484 aix*)
485 ;;
486
Haibo Huangee759ce2021-01-05 21:34:29 -0800487 freebsd*|netbsd*|openbsd*|dragonfly*|linux*|osf*|haiku*|midipix*)
488 #
JP Abgrall511eca32014-02-12 13:46:45 -0800489 # Platforms where the linker is the GNU linker
490 # or accepts command-line arguments like
491 # those the GNU linker accepts.
492 #
493 # Some instruction sets require -fPIC on some
494 # operating systems. Check for them. If you
495 # have a combination that requires it, add it
496 # here.
497 #
498 PIC_OPT=-fpic
499 case "$host_cpu" in
500
501 sparc64*)
502 case "$host_os" in
503
Haibo Huang4ccd6832020-04-23 18:03:48 -0700504 freebsd*|openbsd*|linux*)
JP Abgrall511eca32014-02-12 13:46:45 -0800505 PIC_OPT=-fPIC
506 ;;
507 esac
508 ;;
509 esac
Haibo Huang165065a2018-07-23 17:26:52 -0700510 V_SHLIB_CCOPT="$V_SHLIB_CCOPT $PIC_OPT"
JP Abgrall511eca32014-02-12 13:46:45 -0800511 V_SONAME_OPT="-Wl,-soname,"
512 V_RPATH_OPT="-Wl,-rpath,"
513 ;;
514
515 hpux*)
Haibo Huang165065a2018-07-23 17:26:52 -0700516 V_SHLIB_CCOPT="$V_SHLIB_CCOPT -fpic"
Haibo Huangee759ce2021-01-05 21:34:29 -0800517 #
JP Abgrall511eca32014-02-12 13:46:45 -0800518 # XXX - this assumes GCC is using the HP linker,
519 # rather than the GNU linker, and that the "+h"
520 # option is used on all HP-UX platforms, both .sl
521 # and .so.
522 #
523 V_SONAME_OPT="-Wl,+h,"
524 #
Haibo Huangee759ce2021-01-05 21:34:29 -0800525 # By default, directories specified with -L
JP Abgrall511eca32014-02-12 13:46:45 -0800526 # are added to the run-time search path, so
527 # we don't add them in pcap-config.
528 #
529 ;;
530
531 solaris*)
Haibo Huang165065a2018-07-23 17:26:52 -0700532 V_SHLIB_CCOPT="$V_SHLIB_CCOPT -fpic"
JP Abgrall511eca32014-02-12 13:46:45 -0800533 #
534 # XXX - this assumes GCC is using the Sun linker,
535 # rather than the GNU linker.
536 #
537 V_SONAME_OPT="-Wl,-h,"
538 V_RPATH_OPT="-Wl,-R,"
539 ;;
540 esac
541 else
542 #
543 # Set the appropriate compiler flags and, on platforms
544 # where we build a shared library:
545 #
546 # add options to generate position-independent code,
Haibo Huang165065a2018-07-23 17:26:52 -0700547 # if necessary (it's the default in Darwin/macOS);
JP Abgrall511eca32014-02-12 13:46:45 -0800548 #
549 # if we generate ".so" shared libraries, define the
550 # appropriate options for building the shared library;
551 #
552 # add options to specify, at link time, a directory to
553 # add to the run-time search path, if that's necessary.
554 #
555 # Note: spaces after V_SONAME_OPT are significant; on
556 # some platforms the soname is passed with a GCC-like
557 # "-Wl,-soname,{soname}" option, with the soname part
558 # of the option, while on other platforms the C compiler
559 # driver takes it as a regular option with the soname
560 # following the option. The same applies to V_RPATH_OPT.
561 #
562 case "$host_os" in
563
564 aix*)
565 V_SHLIB_CMD="\$(CC)"
566 V_SHLIB_OPT="-G -bnoentry -bexpall"
567 ;;
568
569 freebsd*|netbsd*|openbsd*|dragonfly*|linux*)
570 #
571 # "cc" is GCC.
572 #
Haibo Huang165065a2018-07-23 17:26:52 -0700573 V_SHLIB_CCOPT="$V_SHLIB_CCOPT -fpic"
JP Abgrall511eca32014-02-12 13:46:45 -0800574 V_SHLIB_CMD="\$(CC)"
575 V_SHLIB_OPT="-shared"
576 V_SONAME_OPT="-Wl,-soname,"
577 V_RPATH_OPT="-Wl,-rpath,"
578 ;;
579
580 hpux*)
Haibo Huang165065a2018-07-23 17:26:52 -0700581 V_SHLIB_CCOPT="$V_SHLIB_CCOPT +z"
JP Abgrall511eca32014-02-12 13:46:45 -0800582 V_SHLIB_CMD="\$(LD)"
583 V_SHLIB_OPT="-b"
584 V_SONAME_OPT="+h "
585 #
Haibo Huangee759ce2021-01-05 21:34:29 -0800586 # By default, directories specified with -L
JP Abgrall511eca32014-02-12 13:46:45 -0800587 # are added to the run-time search path, so
588 # we don't add them in pcap-config.
589 #
590 ;;
591
592 osf*)
Haibo Huangee759ce2021-01-05 21:34:29 -0800593 #
JP Abgrall511eca32014-02-12 13:46:45 -0800594 # Presumed to be DEC OSF/1, Digital UNIX, or
595 # Tru64 UNIX.
596 #
597 V_SHLIB_CMD="\$(CC)"
598 V_SHLIB_OPT="-shared"
599 V_SONAME_OPT="-soname "
600 V_RPATH_OPT="-rpath "
601 ;;
602
603 solaris*)
Haibo Huang165065a2018-07-23 17:26:52 -0700604 V_SHLIB_CCOPT="$V_SHLIB_CCOPT -Kpic"
JP Abgrall511eca32014-02-12 13:46:45 -0800605 V_SHLIB_CMD="\$(CC)"
606 V_SHLIB_OPT="-G"
607 V_SONAME_OPT="-h "
608 V_RPATH_OPT="-R"
609 ;;
610 esac
The Android Open Source Project478ab6c2009-03-03 19:30:05 -0800611 fi
612])
613
614#
615# Try compiling a sample of the type of code that appears in
616# gencode.c with "inline", "__inline__", and "__inline".
617#
618# Autoconf's AC_C_INLINE, at least in autoconf 2.13, isn't good enough,
619# as it just tests whether a function returning "int" can be inlined;
620# at least some versions of HP's C compiler can inline that, but can't
621# inline a function that returns a struct pointer.
622#
623# Make sure we use the V_CCOPT flags, because some of those might
624# disable inlining.
625#
626AC_DEFUN(AC_LBL_C_INLINE,
627 [AC_MSG_CHECKING(for inline)
628 save_CFLAGS="$CFLAGS"
629 CFLAGS="$V_CCOPT"
630 AC_CACHE_VAL(ac_cv_lbl_inline, [
631 ac_cv_lbl_inline=""
632 ac_lbl_cc_inline=no
633 for ac_lbl_inline in inline __inline__ __inline
634 do
635 AC_TRY_COMPILE(
636 [#define inline $ac_lbl_inline
637 static inline struct iltest *foo(void);
638 struct iltest {
639 int iltest1;
640 int iltest2;
641 };
642
643 static inline struct iltest *
644 foo()
645 {
646 static struct iltest xxx;
647
648 return &xxx;
649 }],,ac_lbl_cc_inline=yes,)
650 if test "$ac_lbl_cc_inline" = yes ; then
651 break;
652 fi
653 done
654 if test "$ac_lbl_cc_inline" = yes ; then
655 ac_cv_lbl_inline=$ac_lbl_inline
656 fi])
657 CFLAGS="$save_CFLAGS"
658 if test ! -z "$ac_cv_lbl_inline" ; then
659 AC_MSG_RESULT($ac_cv_lbl_inline)
660 else
661 AC_MSG_RESULT(no)
662 fi
663 AC_DEFINE_UNQUOTED(inline, $ac_cv_lbl_inline, [Define as token for inline if inlining supported])])
664
665dnl
The Android Open Source Project478ab6c2009-03-03 19:30:05 -0800666dnl If using gcc, make sure we have ANSI ioctl definitions
667dnl
668dnl usage:
669dnl
670dnl AC_LBL_FIXINCLUDES
671dnl
672AC_DEFUN(AC_LBL_FIXINCLUDES,
673 [if test "$GCC" = yes ; then
674 AC_MSG_CHECKING(for ANSI ioctl definitions)
675 AC_CACHE_VAL(ac_cv_lbl_gcc_fixincludes,
676 AC_TRY_COMPILE(
677 [/*
678 * This generates a "duplicate case value" when fixincludes
679 * has not be run.
680 */
681# include <sys/types.h>
682# include <sys/time.h>
683# include <sys/ioctl.h>
684# ifdef HAVE_SYS_IOCCOM_H
685# include <sys/ioccom.h>
686# endif],
687 [switch (0) {
688 case _IO('A', 1):;
689 case _IO('B', 1):;
690 }],
691 ac_cv_lbl_gcc_fixincludes=yes,
692 ac_cv_lbl_gcc_fixincludes=no))
693 AC_MSG_RESULT($ac_cv_lbl_gcc_fixincludes)
694 if test $ac_cv_lbl_gcc_fixincludes = no ; then
695 # Don't cache failure
696 unset ac_cv_lbl_gcc_fixincludes
697 AC_MSG_ERROR(see the INSTALL for more info)
698 fi
699 fi])
700
701dnl
The Android Open Source Project478ab6c2009-03-03 19:30:05 -0800702dnl Checks to see if union wait is used with WEXITSTATUS()
703dnl
704dnl usage:
705dnl
706dnl AC_LBL_UNION_WAIT
707dnl
708dnl results:
709dnl
710dnl DECLWAITSTATUS (defined)
711dnl
712AC_DEFUN(AC_LBL_UNION_WAIT,
713 [AC_MSG_CHECKING(if union wait is used)
714 AC_CACHE_VAL(ac_cv_lbl_union_wait,
715 AC_TRY_COMPILE([
716# include <sys/types.h>
717# include <sys/wait.h>],
718 [int status;
719 u_int i = WEXITSTATUS(status);
720 u_int j = waitpid(0, &status, 0);],
721 ac_cv_lbl_union_wait=no,
722 ac_cv_lbl_union_wait=yes))
723 AC_MSG_RESULT($ac_cv_lbl_union_wait)
724 if test $ac_cv_lbl_union_wait = yes ; then
725 AC_DEFINE(DECLWAITSTATUS,union wait,[type for wait])
726 else
727 AC_DEFINE(DECLWAITSTATUS,int,[type for wait])
728 fi])
729
730dnl
The Android Open Source Project478ab6c2009-03-03 19:30:05 -0800731dnl Checks to see if -R is used
732dnl
733dnl usage:
734dnl
735dnl AC_LBL_HAVE_RUN_PATH
736dnl
737dnl results:
738dnl
739dnl ac_cv_lbl_have_run_path (yes or no)
740dnl
741AC_DEFUN(AC_LBL_HAVE_RUN_PATH,
742 [AC_MSG_CHECKING(for ${CC-cc} -R)
743 AC_CACHE_VAL(ac_cv_lbl_have_run_path,
744 [echo 'main(){}' > conftest.c
745 ${CC-cc} -o conftest conftest.c -R/a1/b2/c3 >conftest.out 2>&1
746 if test ! -s conftest.out ; then
747 ac_cv_lbl_have_run_path=yes
748 else
749 ac_cv_lbl_have_run_path=no
750 fi
JP Abgrall511eca32014-02-12 13:46:45 -0800751 rm -f -r conftest*])
The Android Open Source Project478ab6c2009-03-03 19:30:05 -0800752 AC_MSG_RESULT($ac_cv_lbl_have_run_path)
753 ])
754
755dnl
JP Abgrall511eca32014-02-12 13:46:45 -0800756dnl If the file .devel exists:
757dnl Add some warning flags if the compiler supports them
The Android Open Source Project478ab6c2009-03-03 19:30:05 -0800758dnl If an os prototype include exists, symlink os-proto.h to it
759dnl
760dnl usage:
761dnl
762dnl AC_LBL_DEVEL(copt)
763dnl
764dnl results:
765dnl
766dnl $1 (copt appended)
767dnl HAVE_OS_PROTO_H (defined)
768dnl os-proto.h (symlinked)
769dnl
770AC_DEFUN(AC_LBL_DEVEL,
771 [rm -f os-proto.h
772 if test "${LBL_CFLAGS+set}" = set; then
773 $1="$$1 ${LBL_CFLAGS}"
774 fi
775 if test -f .devel ; then
JP Abgrall511eca32014-02-12 13:46:45 -0800776 #
777 # Skip all the warning option stuff on some compilers.
778 #
779 if test "$ac_lbl_cc_dont_try_gcc_dashW" != yes; then
780 AC_LBL_CHECK_UNKNOWN_WARNING_OPTION_ERROR()
Haibo Huang4ccd6832020-04-23 18:03:48 -0700781 AC_LBL_CHECK_COMPILER_OPT($1, -W)
JP Abgrall511eca32014-02-12 13:46:45 -0800782 AC_LBL_CHECK_COMPILER_OPT($1, -Wall)
Haibo Huang165065a2018-07-23 17:26:52 -0700783 AC_LBL_CHECK_COMPILER_OPT($1, -Wcomma)
Haibo Huang4ccd6832020-04-23 18:03:48 -0700784 AC_LBL_CHECK_COMPILER_OPT($1, -Wdocumentation)
785 AC_LBL_CHECK_COMPILER_OPT($1, -Wformat-nonliteral)
Haibo Huang165065a2018-07-23 17:26:52 -0700786 AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-noreturn)
Haibo Huang4ccd6832020-04-23 18:03:48 -0700787 AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-prototypes)
788 AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-variable-declarations)
Haibo Huangee759ce2021-01-05 21:34:29 -0800789 AC_LBL_CHECK_COMPILER_OPT($1, -Wpointer-arith)
790 AC_LBL_CHECK_COMPILER_OPT($1, -Wpointer-sign)
Haibo Huang4ccd6832020-04-23 18:03:48 -0700791 AC_LBL_CHECK_COMPILER_OPT($1, -Wshadow)
792 AC_LBL_CHECK_COMPILER_OPT($1, -Wsign-compare)
793 AC_LBL_CHECK_COMPILER_OPT($1, -Wstrict-prototypes)
794 AC_LBL_CHECK_COMPILER_OPT($1, -Wunused-parameter)
795 AC_LBL_CHECK_COMPILER_OPT($1, -Wused-but-marked-unused)
Haibo Huang165065a2018-07-23 17:26:52 -0700796 # Warns about safeguards added in case the enums are
797 # extended
798 # AC_LBL_CHECK_COMPILER_OPT($1, -Wcovered-switch-default)
Haibo Huang165065a2018-07-23 17:26:52 -0700799 #
800 # This can cause problems with ntohs(), ntohl(),
801 # htons(), and htonl() on some platforms, such
802 # as OpenBSD 6.3 with Clang 5.0.1. I guess the
803 # problem is that the macro that ultimately does
804 # the byte-swapping involves a conditional
805 # expression that tests whether the value being
806 # swapped is a compile-time constant or not,
807 # using __builtin_constant_p(), and, depending
808 # on whether it is, does a compile-time swap or
809 # a run-time swap; perhaps the compiler always
810 # considers one of the two results of the
811 # conditional expressin is never evaluated,
812 # because the conditional check is done at
813 # compile time, and thus always says "that
814 # expression is never executed".
815 #
816 # (Perhaps there should be a way of flagging
817 # an expression that you *want* evaluated at
818 # compile time, so that the compiler 1) warns
819 # if it *can't* be evaluated at compile time
820 # and 2) *doesn't* warn that the true or false
821 # branch will never be reached.)
822 #
823 AC_LBL_CHECK_COMPILER_OPT($1, -Wunreachable-code,
824 [
825#include <arpa/inet.h>
826
827unsigned short
828testme(unsigned short a)
829{
830 return ntohs(a);
831}
832 ],
833 [generates warnings from ntohs()])
Haibo Huangee759ce2021-01-05 21:34:29 -0800834 AC_LBL_CHECK_COMPILER_OPT($1, -Wshorten-64-to-32)
The Android Open Source Project478ab6c2009-03-03 19:30:05 -0800835 fi
JP Abgrall511eca32014-02-12 13:46:45 -0800836 AC_LBL_CHECK_DEPENDENCY_GENERATION_OPT()
837 #
838 # We used to set -n32 for IRIX 6 when not using GCC (presumed
839 # to mean that we're using MIPS C or MIPSpro C); it specified
840 # the "new" faster 32-bit ABI, introduced in IRIX 6.2. I'm
841 # not sure why that would be something to do *only* with a
842 # .devel file; why should the ABI for which we produce code
843 # depend on .devel?
844 #
845 os=`echo $host_os | sed -e 's/\([[0-9]][[0-9]]*\)[[^0-9]].*$/\1/'`
The Android Open Source Project478ab6c2009-03-03 19:30:05 -0800846 name="lbl/os-$os.h"
847 if test -f $name ; then
848 ln -s $name os-proto.h
JP Abgrall511eca32014-02-12 13:46:45 -0800849 AC_DEFINE(HAVE_OS_PROTO_H, 1,
850 [if there's an os_proto.h for this platform, to use additional prototypes])
The Android Open Source Project478ab6c2009-03-03 19:30:05 -0800851 else
852 AC_MSG_WARN(can't find $name)
853 fi
854 fi])
855
856dnl
857dnl Improved version of AC_CHECK_LIB
858dnl
859dnl Thanks to John Hawkinson (jhawk@mit.edu)
860dnl
861dnl usage:
862dnl
863dnl AC_LBL_CHECK_LIB(LIBRARY, FUNCTION [, ACTION-IF-FOUND [,
864dnl ACTION-IF-NOT-FOUND [, OTHER-LIBRARIES]]])
865dnl
866dnl results:
867dnl
868dnl LIBS
869dnl
JP Abgrall511eca32014-02-12 13:46:45 -0800870dnl XXX - "AC_LBL_LIBRARY_NET" was redone to use "AC_SEARCH_LIBS"
871dnl rather than "AC_LBL_CHECK_LIB", so this isn't used any more.
872dnl We keep it around for reference purposes in case it's ever
873dnl useful in the future.
874dnl
The Android Open Source Project478ab6c2009-03-03 19:30:05 -0800875
876define(AC_LBL_CHECK_LIB,
877[AC_MSG_CHECKING([for $2 in -l$1])
JP Abgrall511eca32014-02-12 13:46:45 -0800878dnl Use a cache variable name containing the library, function
879dnl name, and extra libraries to link with, because the test really is
880dnl for library $1 defining function $2, when linked with potinal
881dnl library $5, not just for library $1. Separate tests with the same
882dnl $1 and different $2's or $5's may have different results.
The Android Open Source Project478ab6c2009-03-03 19:30:05 -0800883ac_lib_var=`echo $1['_']$2['_']$5 | sed 'y%./+- %__p__%'`
884AC_CACHE_VAL(ac_cv_lbl_lib_$ac_lib_var,
885[ac_save_LIBS="$LIBS"
886LIBS="-l$1 $5 $LIBS"
887AC_TRY_LINK(dnl
888ifelse([$2], [main], , dnl Avoid conflicting decl of main.
889[/* Override any gcc2 internal prototype to avoid an error. */
890]ifelse(AC_LANG, CPLUSPLUS, [#ifdef __cplusplus
891extern "C"
892#endif
893])dnl
894[/* We use char because int might match the return type of a gcc2
895 builtin and then its argument prototype would still apply. */
896char $2();
897]),
898 [$2()],
899 eval "ac_cv_lbl_lib_$ac_lib_var=yes",
900 eval "ac_cv_lbl_lib_$ac_lib_var=no")
901LIBS="$ac_save_LIBS"
902])dnl
903if eval "test \"`echo '$ac_cv_lbl_lib_'$ac_lib_var`\" = yes"; then
904 AC_MSG_RESULT(yes)
905 ifelse([$3], ,
906[changequote(, )dnl
907 ac_tr_lib=HAVE_LIB`echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g' \
908 -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
909changequote([, ])dnl
910 AC_DEFINE_UNQUOTED($ac_tr_lib)
911 LIBS="-l$1 $LIBS"
912], [$3])
913else
914 AC_MSG_RESULT(no)
915ifelse([$4], , , [$4
916])dnl
917fi
918])
919
920dnl
921dnl AC_LBL_LIBRARY_NET
922dnl
Haibo Huang165065a2018-07-23 17:26:52 -0700923dnl This test is for network applications that need socket functions and
924dnl getaddrinfo()/getnameinfo()-ish functions. We now require
925dnl getaddrinfo() and getnameinfo(). We also prefer versions of
926dnl recvmsg() that conform to the Single UNIX Specification, so that we
927dnl can check whether a datagram received with recvmsg() was truncated
928dnl when received due to the buffer being too small.
The Android Open Source Project478ab6c2009-03-03 19:30:05 -0800929dnl
Haibo Huang165065a2018-07-23 17:26:52 -0700930dnl On most operating systems, they're available in the system library.
The Android Open Source Project478ab6c2009-03-03 19:30:05 -0800931dnl
Haibo Huang165065a2018-07-23 17:26:52 -0700932dnl Under Solaris, we need to link with libsocket and libnsl to get
933dnl getaddrinfo() and getnameinfo() and, if we have libxnet, we need to
934dnl link with libxnet before libsocket to get a version of recvmsg()
935dnl that conforms to the Single UNIX Specification.
The Android Open Source Project478ab6c2009-03-03 19:30:05 -0800936dnl
Haibo Huang165065a2018-07-23 17:26:52 -0700937dnl We use getaddrinfo() because we want a portable thread-safe way
938dnl of getting information for a host name or port; there exist _r
939dnl versions of gethostbyname() and getservbyname() on some platforms,
940dnl but not on all platforms.
The Android Open Source Project478ab6c2009-03-03 19:30:05 -0800941dnl
942AC_DEFUN(AC_LBL_LIBRARY_NET, [
Haibo Huang165065a2018-07-23 17:26:52 -0700943 #
944 # Most operating systems have getaddrinfo() in the default searched
945 # libraries (i.e. libc). Check there first.
946 #
947 AC_CHECK_FUNC(getaddrinfo,,
948 [
949 #
950 # Not found in the standard system libraries.
951 # Try libsocket, which requires libnsl.
952 #
953 AC_CHECK_LIB(socket, getaddrinfo,
954 [
955 #
956 # OK, we found it in libsocket.
957 #
958 LIBS="-lsocket -lnsl $LIBS"
959 ],
960 [
Haibo Huangee759ce2021-01-05 21:34:29 -0800961 AC_CHECK_LIB(network, getaddrinfo,
962 [
963 #
964 # OK, we found it in libnetwork on Haiku.
965 #
966 LIBS="-lnetwork $LIBS"
967 ],
968 [
969 #
970 # We didn't find it.
971 #
972 AC_MSG_ERROR([getaddrinfo is required, but wasn't found])
973 ])
Haibo Huang165065a2018-07-23 17:26:52 -0700974 ], -lnsl)
975
976 #
977 # OK, do we have recvmsg() in libxnet?
978 # We also link with libsocket and libnsl.
979 #
980 AC_CHECK_LIB(xnet, recvmsg,
981 [
982 #
983 # Yes - link with it as well.
984 #
985 LIBS="-lxnet $LIBS"
986 ], , -lsocket -lnsl)
987 ])
The Android Open Source Project478ab6c2009-03-03 19:30:05 -0800988 # DLPI needs putmsg under HPUX so test for -lstr while we're at it
989 AC_SEARCH_LIBS(putmsg, str)
JP Abgrall511eca32014-02-12 13:46:45 -0800990])
Haibo Huangee759ce2021-01-05 21:34:29 -0800991
992m4_ifndef([AC_CONFIG_MACRO_DIRS], [m4_defun([_AM_CONFIG_MACRO_DIRS], [])m4_defun([AC_CONFIG_MACRO_DIRS], [_AM_CONFIG_MACRO_DIRS($@)])])
993dnl pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*-
994dnl serial 11 (pkg-config-0.29)
995dnl
996dnl Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
997dnl Copyright © 2012-2015 Dan Nicholson <dbn.lists@gmail.com>
998dnl
999dnl This program is free software; you can redistribute it and/or modify
1000dnl it under the terms of the GNU General Public License as published by
1001dnl the Free Software Foundation; either version 2 of the License, or
1002dnl (at your option) any later version.
1003dnl
1004dnl This program is distributed in the hope that it will be useful, but
1005dnl WITHOUT ANY WARRANTY; without even the implied warranty of
1006dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1007dnl General Public License for more details.
1008dnl
1009dnl You should have received a copy of the GNU General Public License
1010dnl along with this program; if not, write to the Free Software
1011dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1012dnl 02111-1307, USA.
1013dnl
1014dnl As a special exception to the GNU General Public License, if you
1015dnl distribute this file as part of a program that contains a
1016dnl configuration script generated by Autoconf, you may include it under
1017dnl the same distribution terms that you use for the rest of that
1018dnl program.
1019
1020dnl PKG_PREREQ(MIN-VERSION)
1021dnl -----------------------
1022dnl Since: 0.29
1023dnl
1024dnl Verify that the version of the pkg-config macros are at least
1025dnl MIN-VERSION. Unlike PKG_PROG_PKG_CONFIG, which checks the user's
1026dnl installed version of pkg-config, this checks the developer's version
1027dnl of pkg.m4 when generating configure.
1028dnl
1029dnl To ensure that this macro is defined, also add:
1030dnl m4_ifndef([PKG_PREREQ],
1031dnl [m4_fatal([must install pkg-config 0.29 or later before running autoconf/autogen])])
1032dnl
1033dnl See the "Since" comment for each macro you use to see what version
1034dnl of the macros you require.
1035m4_defun([PKG_PREREQ],
1036[m4_define([PKG_MACROS_VERSION], [0.29])
1037m4_if(m4_version_compare(PKG_MACROS_VERSION, [$1]), -1,
1038 [m4_fatal([pkg.m4 version $1 or higher is required but ]PKG_MACROS_VERSION[ found])])
1039])dnl PKG_PREREQ
1040
1041dnl PKG_PROG_PKG_CONFIG([MIN-VERSION])
1042dnl ----------------------------------
1043dnl Since: 0.16
1044dnl
1045dnl Search for the pkg-config tool and set the PKG_CONFIG variable to
1046dnl first found in the path. Checks that the version of pkg-config found
1047dnl is at least MIN-VERSION. If MIN-VERSION is not specified, 0.9.0 is
1048dnl used since that's the first version where most current features of
1049dnl pkg-config existed.
1050AC_DEFUN([PKG_PROG_PKG_CONFIG],
1051[m4_pattern_forbid([^_?PKG_[A-Z_]+$])
1052m4_pattern_allow([^PKG_CONFIG(_(PATH|LIBDIR|SYSROOT_DIR|ALLOW_SYSTEM_(CFLAGS|LIBS)))?$])
1053m4_pattern_allow([^PKG_CONFIG_(DISABLE_UNINSTALLED|TOP_BUILD_DIR|DEBUG_SPEW)$])
1054AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])
1055AC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path])
1056AC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path])
1057
1058if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
1059 AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
1060fi
1061if test -n "$PKG_CONFIG"; then
1062 _pkg_min_version=m4_default([$1], [0.9.0])
1063 AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version])
1064 if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
1065 AC_MSG_RESULT([yes])
1066 else
1067 AC_MSG_RESULT([no])
1068 PKG_CONFIG=""
1069 fi
1070fi[]dnl
1071])dnl PKG_PROG_PKG_CONFIG
1072
1073dnl PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
1074dnl -------------------------------------------------------------------
1075dnl Since: 0.18
1076dnl
1077dnl Check to see whether a particular set of modules exists. Similar to
1078dnl PKG_CHECK_MODULES(), but does not set variables or print errors.
1079dnl
1080dnl Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG])
1081dnl only at the first occurrence in configure.ac, so if the first place
1082dnl it's called might be skipped (such as if it is within an "if", you
1083dnl have to call PKG_CHECK_EXISTS manually
1084AC_DEFUN([PKG_CHECK_EXISTS],
1085[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
1086if test -n "$PKG_CONFIG" && \
1087 AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then
1088 m4_default([$2], [:])
1089m4_ifvaln([$3], [else
1090 $3])dnl
1091fi])
1092
1093dnl _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES])
1094dnl ---------------------------------------------
1095dnl Internal wrapper calling pkg-config via PKG_CONFIG and setting
1096dnl pkg_failed based on the result.
1097m4_define([_PKG_CONFIG],
1098[if test -n "$$1"; then
1099 pkg_cv_[]$1="$$1"
1100 elif test -n "$PKG_CONFIG"; then
1101 PKG_CHECK_EXISTS([$3],
1102 [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`
1103 test "x$?" != "x0" && pkg_failed=yes ],
1104 [pkg_failed=yes])
1105 else
1106 pkg_failed=untried
1107fi[]dnl
1108])dnl _PKG_CONFIG
1109
1110dnl _PKG_SHORT_ERRORS_SUPPORTED
1111dnl ---------------------------
1112dnl Internal check to see if pkg-config supports short errors.
1113AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED],
1114[AC_REQUIRE([PKG_PROG_PKG_CONFIG])
1115if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
1116 _pkg_short_errors_supported=yes
1117else
1118 _pkg_short_errors_supported=no
1119fi[]dnl
1120])dnl _PKG_SHORT_ERRORS_SUPPORTED
1121
1122
1123dnl PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
1124dnl [ACTION-IF-NOT-FOUND])
1125dnl --------------------------------------------------------------
1126dnl Since: 0.4.0
1127dnl
1128dnl Note that if there is a possibility the first call to
1129dnl PKG_CHECK_MODULES might not happen, you should be sure to include an
1130dnl explicit call to PKG_PROG_PKG_CONFIG in your configure.ac
1131AC_DEFUN([PKG_CHECK_MODULES],
1132[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
1133AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl
1134AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl
1135
1136pkg_failed=no
1137AC_MSG_CHECKING([for $1])
1138
1139_PKG_CONFIG([$1][_CFLAGS], [cflags], [$2])
1140_PKG_CONFIG([$1][_LIBS], [libs], [$2])
1141
1142m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS
1143and $1[]_LIBS to avoid the need to call pkg-config.
1144See the pkg-config man page for more details.])
1145
1146if test $pkg_failed = yes; then
1147 AC_MSG_RESULT([no])
1148 _PKG_SHORT_ERRORS_SUPPORTED
1149 if test $_pkg_short_errors_supported = yes; then
1150 $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "$2" 2>&1`
1151 else
1152 $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "$2" 2>&1`
1153 fi
1154 # Put the nasty error message in config.log where it belongs
1155 echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD
1156
1157 m4_default([$4], [AC_MSG_ERROR(
1158[Package requirements ($2) were not met:
1159
1160$$1_PKG_ERRORS
1161
1162Consider adjusting the PKG_CONFIG_PATH environment variable if you
1163installed software in a non-standard prefix.
1164
1165_PKG_TEXT])[]dnl
1166 ])
1167elif test $pkg_failed = untried; then
1168 AC_MSG_RESULT([no])
1169 m4_default([$4], [AC_MSG_FAILURE(
1170[The pkg-config script could not be found or is too old. Make sure it
1171is in your PATH or set the PKG_CONFIG environment variable to the full
1172path to pkg-config.
1173
1174_PKG_TEXT
1175
1176To get pkg-config, see <https://pkg-config.freedesktop.org/>.])[]dnl
1177 ])
1178else
1179 $1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS
1180 $1[]_LIBS=$pkg_cv_[]$1[]_LIBS
1181 AC_MSG_RESULT([yes])
1182 $3
1183fi[]dnl
1184])dnl PKG_CHECK_MODULES
1185
1186
1187dnl PKG_CHECK_MODULES_STATIC(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
1188dnl [ACTION-IF-NOT-FOUND])
1189dnl ---------------------------------------------------------------------
1190dnl Since: 0.29
1191dnl
1192dnl Checks for existence of MODULES and gathers its build flags with
1193dnl static libraries enabled. Sets VARIABLE-PREFIX_CFLAGS from --cflags
1194dnl and VARIABLE-PREFIX_LIBS from --libs.
1195dnl
1196dnl Note that if there is a possibility the first call to
1197dnl PKG_CHECK_MODULES_STATIC might not happen, you should be sure to
1198dnl include an explicit call to PKG_PROG_PKG_CONFIG in your
1199dnl configure.ac.
1200AC_DEFUN([PKG_CHECK_MODULES_STATIC],
1201[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
1202_save_PKG_CONFIG=$PKG_CONFIG
1203PKG_CONFIG="$PKG_CONFIG --static"
1204PKG_CHECK_MODULES($@)
1205PKG_CONFIG=$_save_PKG_CONFIG[]dnl
1206])dnl PKG_CHECK_MODULES_STATIC
1207
1208
1209dnl PKG_INSTALLDIR([DIRECTORY])
1210dnl -------------------------
1211dnl Since: 0.27
1212dnl
1213dnl Substitutes the variable pkgconfigdir as the location where a module
1214dnl should install pkg-config .pc files. By default the directory is
1215dnl $libdir/pkgconfig, but the default can be changed by passing
1216dnl DIRECTORY. The user can override through the --with-pkgconfigdir
1217dnl parameter.
1218AC_DEFUN([PKG_INSTALLDIR],
1219[m4_pushdef([pkg_default], [m4_default([$1], ['${libdir}/pkgconfig'])])
1220m4_pushdef([pkg_description],
1221 [pkg-config installation directory @<:@]pkg_default[@:>@])
1222AC_ARG_WITH([pkgconfigdir],
1223 [AS_HELP_STRING([--with-pkgconfigdir], pkg_description)],,
1224 [with_pkgconfigdir=]pkg_default)
1225AC_SUBST([pkgconfigdir], [$with_pkgconfigdir])
1226m4_popdef([pkg_default])
1227m4_popdef([pkg_description])
1228])dnl PKG_INSTALLDIR
1229
1230
1231dnl PKG_NOARCH_INSTALLDIR([DIRECTORY])
1232dnl --------------------------------
1233dnl Since: 0.27
1234dnl
1235dnl Substitutes the variable noarch_pkgconfigdir as the location where a
1236dnl module should install arch-independent pkg-config .pc files. By
1237dnl default the directory is $datadir/pkgconfig, but the default can be
1238dnl changed by passing DIRECTORY. The user can override through the
1239dnl --with-noarch-pkgconfigdir parameter.
1240AC_DEFUN([PKG_NOARCH_INSTALLDIR],
1241[m4_pushdef([pkg_default], [m4_default([$1], ['${datadir}/pkgconfig'])])
1242m4_pushdef([pkg_description],
1243 [pkg-config arch-independent installation directory @<:@]pkg_default[@:>@])
1244AC_ARG_WITH([noarch-pkgconfigdir],
1245 [AS_HELP_STRING([--with-noarch-pkgconfigdir], pkg_description)],,
1246 [with_noarch_pkgconfigdir=]pkg_default)
1247AC_SUBST([noarch_pkgconfigdir], [$with_noarch_pkgconfigdir])
1248m4_popdef([pkg_default])
1249m4_popdef([pkg_description])
1250])dnl PKG_NOARCH_INSTALLDIR
1251
1252
1253dnl PKG_CHECK_VAR(VARIABLE, MODULE, CONFIG-VARIABLE,
1254dnl [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
1255dnl -------------------------------------------
1256dnl Since: 0.28
1257dnl
1258dnl Retrieves the value of the pkg-config variable for the given module.
1259AC_DEFUN([PKG_CHECK_VAR],
1260[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
1261AC_ARG_VAR([$1], [value of $3 for $2, overriding pkg-config])dnl
1262
1263_PKG_CONFIG([$1], [variable="][$3]["], [$2])
1264AS_VAR_COPY([$1], [pkg_cv_][$1])
1265
1266AS_VAR_IF([$1], [""], [$5], [$4])dnl
1267])dnl PKG_CHECK_VAR
1268