1 dnl Id: aclocal.m4,v 1.8 2009/10/26 23:41:51 tom Exp
3 dnl Macros for byacc configure script (Thomas E. Dickey)
4 dnl ---------------------------------------------------------------------------
5 dnl ---------------------------------------------------------------------------
6 dnl CF_ADD_CFLAGS version: 8 updated: 2009/01/06 19:33:30
8 dnl Copy non-preprocessor flags to $CFLAGS, preprocessor flags to $CPPFLAGS
9 dnl The second parameter if given makes this macro verbose.
11 dnl Put any preprocessor definitions that use quoted strings in $EXTRA_CPPFLAGS,
12 dnl to simplify use of $CPPFLAGS in compiler checks, etc., that are easily
13 dnl confused by the quotes (which require backslashes to keep them usable).
14 AC_DEFUN([CF_ADD_CFLAGS],
19 cf_new_extra_cppflags=
21 for cf_add_cflags in $1
23 case $cf_fix_cppflags in
25 case $cf_add_cflags in #(vi
26 -undef|-nostdinc*|-I*|-D*|-U*|-E|-P|-C) #(vi
27 case $cf_add_cflags in
29 cf_tst_cflags=`echo ${cf_add_cflags} |sed -e 's/^-D[[^=]]*='\''\"[[^"]]*//'`
31 test "${cf_add_cflags}" != "${cf_tst_cflags}" \
32 && test -z "${cf_tst_cflags}" \
33 && cf_fix_cppflags=yes
35 if test $cf_fix_cppflags = yes ; then
36 cf_new_extra_cppflags="$cf_new_extra_cppflags $cf_add_cflags"
38 elif test "${cf_tst_cflags}" = "\"'" ; then
39 cf_new_extra_cppflags="$cf_new_extra_cppflags $cf_add_cflags"
48 cf_new_cppflags="$cf_new_cppflags $cf_add_cflags"
53 cf_new_cflags="$cf_new_cflags $cf_add_cflags"
58 cf_new_extra_cppflags="$cf_new_extra_cppflags $cf_add_cflags"
60 cf_tst_cflags=`echo ${cf_add_cflags} |sed -e 's/^[[^"]]*"'\''//'`
62 test "${cf_add_cflags}" != "${cf_tst_cflags}" \
63 && test -z "${cf_tst_cflags}" \
69 if test -n "$cf_new_cflags" ; then
70 ifelse($2,,,[CF_VERBOSE(add to \$CFLAGS $cf_new_cflags)])
71 CFLAGS="$CFLAGS $cf_new_cflags"
74 if test -n "$cf_new_cppflags" ; then
75 ifelse($2,,,[CF_VERBOSE(add to \$CPPFLAGS $cf_new_cppflags)])
76 CPPFLAGS="$CPPFLAGS $cf_new_cppflags"
79 if test -n "$cf_new_extra_cppflags" ; then
80 ifelse($2,,,[CF_VERBOSE(add to \$EXTRA_CPPFLAGS $cf_new_extra_cppflags)])
81 EXTRA_CPPFLAGS="$cf_new_extra_cppflags $EXTRA_CPPFLAGS"
84 AC_SUBST(EXTRA_CPPFLAGS)
87 dnl ---------------------------------------------------------------------------
88 dnl CF_ANSI_CC_CHECK version: 9 updated: 2001/12/30 17:53:34
90 dnl This is adapted from the macros 'fp_PROG_CC_STDC' and 'fp_C_PROTOTYPES'
91 dnl in the sharutils 4.2 distribution.
92 AC_DEFUN([CF_ANSI_CC_CHECK],
94 AC_CACHE_CHECK(for ${CC-cc} option to accept ANSI C, cf_cv_ansi_cc,[
96 cf_save_CFLAGS="$CFLAGS"
97 cf_save_CPPFLAGS="$CPPFLAGS"
98 # Don't try gcc -ansi; that turns off useful extensions and
99 # breaks some systems' header files.
101 # Ultrix and OSF/1 -std1
102 # HP-UX -Aa -D_HPUX_SOURCE
104 # UnixWare 1.2 (cannot use -Xc, since ANSI/POSIX clashes)
105 for cf_arg in "-DCC_HAS_PROTOS" \
110 "-Aa -D_HPUX_SOURCE" \
113 CF_ADD_CFLAGS($cf_arg)
116 #ifndef CC_HAS_PROTOS
117 #if !defined(__STDC__) || (__STDC__ != 1)
122 int test (int i, double x);
123 struct s1 {int (*f) (int a);};
124 struct s2 {int (*f) (double a);};],
125 [cf_cv_ansi_cc="$cf_arg"; break])
127 CFLAGS="$cf_save_CFLAGS"
128 CPPFLAGS="$cf_save_CPPFLAGS"
131 if test "$cf_cv_ansi_cc" != "no"; then
132 if test ".$cf_cv_ansi_cc" != ".-DCC_HAS_PROTOS"; then
133 CF_ADD_CFLAGS($cf_cv_ansi_cc)
135 AC_DEFINE(CC_HAS_PROTOS)
139 dnl ---------------------------------------------------------------------------
140 dnl CF_ANSI_CC_REQD version: 4 updated: 2008/03/23 14:48:54
142 dnl For programs that must use an ANSI compiler, obtain compiler options that
143 dnl will make it recognize prototypes. We'll do preprocessor checks in other
144 dnl macros, since tools such as unproto can fake prototypes, but only part of
145 dnl the preprocessor.
146 AC_DEFUN([CF_ANSI_CC_REQD],
147 [AC_REQUIRE([CF_ANSI_CC_CHECK])
148 if test "$cf_cv_ansi_cc" = "no"; then
150 [Your compiler does not appear to recognize prototypes.
151 You have the following choices:
152 a. adjust your compiler options
153 b. get an up-to-date compiler
154 c. use a wrapper such as unproto])
157 dnl ---------------------------------------------------------------------------
158 dnl CF_ARG_DISABLE version: 3 updated: 1999/03/30 17:24:31
160 dnl Allow user to disable a normally-on option.
161 AC_DEFUN([CF_ARG_DISABLE],
162 [CF_ARG_OPTION($1,[$2],[$3],[$4],yes)])dnl
163 dnl ---------------------------------------------------------------------------
164 dnl CF_ARG_OPTION version: 3 updated: 1997/10/18 14:42:41
166 dnl Restricted form of AC_ARG_ENABLE that ensures user doesn't give bogus
172 dnl $3 = action to perform if option is not default
173 dnl $4 = action if perform if option is default
174 dnl $5 = default option value (either 'yes' or 'no')
175 AC_DEFUN([CF_ARG_OPTION],
176 [AC_ARG_ENABLE($1,[$2],[test "$enableval" != ifelse($5,no,yes,no) && enableval=ifelse($5,no,no,yes)
177 if test "$enableval" != "$5" ; then
179 ,[ $3]) ifelse($4,,,[
182 fi],[enableval=$5 ifelse($4,,,[
186 dnl ---------------------------------------------------------------------------
187 dnl CF_CHECK_CACHE version: 11 updated: 2008/03/23 14:45:59
189 dnl Check if we're accidentally using a cache from a different machine.
190 dnl Derive the system name, as a check for reusing the autoconf cache.
192 dnl If we've packaged config.guess and config.sub, run that (since it does a
193 dnl better job than uname). Normally we'll use AC_CANONICAL_HOST, but allow
194 dnl an extra parameter that we may override, e.g., for AC_CANONICAL_SYSTEM
195 dnl which is useful in cross-compiles.
197 dnl Note: we would use $ac_config_sub, but that is one of the places where
198 dnl autoconf 2.5x broke compatibility with autoconf 2.13
199 AC_DEFUN([CF_CHECK_CACHE],
201 if test -f $srcdir/config.guess || test -f $ac_aux_dir/config.guess ; then
202 ifelse([$1],,[AC_CANONICAL_HOST],[$1])
203 system_name="$host_os"
205 system_name="`(uname -s -r) 2>/dev/null`"
206 if test -z "$system_name" ; then
207 system_name="`(hostname) 2>/dev/null`"
210 test -n "$system_name" && AC_DEFINE_UNQUOTED(SYSTEM_NAME,"$system_name")
211 AC_CACHE_VAL(cf_cv_system_name,[cf_cv_system_name="$system_name"])
213 test -z "$system_name" && system_name="$cf_cv_system_name"
214 test -n "$cf_cv_system_name" && AC_MSG_RESULT(Configuring for $cf_cv_system_name)
216 if test ".$system_name" != ".$cf_cv_system_name" ; then
217 AC_MSG_RESULT(Cached system name ($system_name) does not agree with actual ($cf_cv_system_name))
218 AC_MSG_ERROR("Please remove config.cache and try again.")
221 dnl ---------------------------------------------------------------------------
222 dnl CF_DISABLE_ECHO version: 10 updated: 2003/04/17 22:27:11
224 dnl You can always use "make -n" to see the actual options, but it's hard to
225 dnl pick out/analyze warning messages when the compile-line is long.
228 dnl ECHO_LT - symbol to control if libtool is verbose
229 dnl ECHO_LD - symbol to prefix "cc -o" lines
230 dnl RULE_CC - symbol to put before implicit "cc -c" lines (e.g., .c.o)
231 dnl SHOW_CC - symbol to put before explicit "cc -c" lines
232 dnl ECHO_CC - symbol to put before any "cc" line
234 AC_DEFUN([CF_DISABLE_ECHO],[
235 AC_MSG_CHECKING(if you want to see long compiling messages)
237 [ --disable-echo display "compiling" commands],
240 ECHO_LD='@echo linking [$]@;'
241 RULE_CC=' @echo compiling [$]<'
242 SHOW_CC=' @echo compiling [$]@'
247 RULE_CC='# compiling'
248 SHOW_CC='# compiling'
251 AC_MSG_RESULT($enableval)
258 dnl ---------------------------------------------------------------------------
259 dnl CF_DISABLE_LEAKS version: 4 updated: 2006/12/16 15:10:42
261 dnl Combine no-leak checks with the libraries or tools that are used for the
263 AC_DEFUN([CF_DISABLE_LEAKS],[
265 AC_REQUIRE([CF_WITH_DMALLOC])
266 AC_REQUIRE([CF_WITH_DBMALLOC])
267 AC_REQUIRE([CF_WITH_VALGRIND])
269 AC_MSG_CHECKING(if you want to perform memory-leak testing)
271 [ --disable-leaks test: free permanent memory, analyze leaks],
273 : ${with_no_leaks:=no})
274 AC_MSG_RESULT($with_no_leaks)
276 if test "$with_no_leaks" = yes ; then
280 dnl ---------------------------------------------------------------------------
281 dnl CF_GCC_ATTRIBUTES version: 13 updated: 2009/08/11 20:19:56
282 dnl -----------------
283 dnl Test for availability of useful gcc __attribute__ directives to quiet
284 dnl compiler warnings. Though useful, not all are supported -- and contrary
285 dnl to documentation, unrecognized directives cause older compilers to barf.
286 AC_DEFUN([CF_GCC_ATTRIBUTES],
290 cat > conftest.i <<EOF
298 #define GCC_NORETURN /* nothing */
301 #define GCC_UNUSED /* nothing */
306 AC_CHECKING([for $CC __attribute__ directives])
307 cat > conftest.$ac_ext <<EOF
308 #line __oline__ "${as_me-configure}"
309 #include "confdefs.h"
310 #include "conftest.h"
311 #include "conftest.i"
313 #define GCC_PRINTFLIKE(fmt,var) __attribute__((format(printf,fmt,var)))
315 #define GCC_PRINTFLIKE(fmt,var) /*nothing*/
318 #define GCC_SCANFLIKE(fmt,var) __attribute__((format(scanf,fmt,var)))
320 #define GCC_SCANFLIKE(fmt,var) /*nothing*/
322 extern void wow(char *,...) GCC_SCANFLIKE(1,2);
323 extern void oops(char *,...) GCC_PRINTFLIKE(1,2) GCC_NORETURN;
324 extern void foo(void) GCC_NORETURN;
325 int main(int argc GCC_UNUSED, char *argv[[]] GCC_UNUSED) { return 0; }
327 cf_printf_attribute=no
328 cf_scanf_attribute=no
329 for cf_attribute in scanf printf unused noreturn
331 CF_UPPER(cf_ATTRIBUTE,$cf_attribute)
332 cf_directive="__attribute__(($cf_attribute))"
333 echo "checking for $CC $cf_directive" 1>&AC_FD_CC
335 case $cf_attribute in #(vi
337 cf_printf_attribute=yes
338 cat >conftest.h <<EOF
339 #define GCC_$cf_ATTRIBUTE 1
343 cf_scanf_attribute=yes
344 cat >conftest.h <<EOF
345 #define GCC_$cf_ATTRIBUTE 1
349 cat >conftest.h <<EOF
350 #define GCC_$cf_ATTRIBUTE $cf_directive
355 if AC_TRY_EVAL(ac_compile); then
356 test -n "$verbose" && AC_MSG_RESULT(... $cf_attribute)
357 cat conftest.h >>confdefs.h
358 case $cf_attribute in #(vi
360 if test "$cf_printf_attribute" = no ; then
361 cat >>confdefs.h <<EOF
362 #define GCC_PRINTFLIKE(fmt,var) /* nothing */
365 cat >>confdefs.h <<EOF
366 #define GCC_PRINTFLIKE(fmt,var) __attribute__((format(printf,fmt,var)))
371 if test "$cf_scanf_attribute" = no ; then
372 cat >>confdefs.h <<EOF
373 #define GCC_SCANFLIKE(fmt,var) /* nothing */
376 cat >>confdefs.h <<EOF
377 #define GCC_SCANFLIKE(fmt,var) __attribute__((format(scanf,fmt,var)))
385 fgrep define conftest.i >>confdefs.h
390 dnl ---------------------------------------------------------------------------
391 dnl CF_GCC_VERSION version: 4 updated: 2005/08/27 09:53:42
393 dnl Find version of gcc
394 AC_DEFUN([CF_GCC_VERSION],[
395 AC_REQUIRE([AC_PROG_CC])
397 if test "$GCC" = yes ; then
398 AC_MSG_CHECKING(version of $CC)
399 GCC_VERSION="`${CC} --version| sed -e '2,$d' -e 's/^.*(GCC) //' -e 's/^[[^0-9.]]*//' -e 's/[[^0-9.]].*//'`"
400 test -z "$GCC_VERSION" && GCC_VERSION=unknown
401 AC_MSG_RESULT($GCC_VERSION)
404 dnl ---------------------------------------------------------------------------
405 dnl CF_GCC_WARNINGS version: 24 updated: 2009/02/01 15:21:00
407 dnl Check if the compiler supports useful warning options. There's a few that
408 dnl we don't use, simply because they're too noisy:
410 dnl -Wconversion (useful in older versions of gcc, but not in gcc 2.7.x)
411 dnl -Wredundant-decls (system headers make this too noisy)
412 dnl -Wtraditional (combines too many unrelated messages, only a few useful)
413 dnl -Wwrite-strings (too noisy, but should review occasionally). This
414 dnl is enabled for ncurses using "--enable-const".
418 dnl $1 is an optional list of gcc warning flags that a particular
419 dnl application might want to use, e.g., "no-unused" for
422 dnl If $with_ext_const is "yes", add a check for -Wwrite-strings
424 AC_DEFUN([CF_GCC_WARNINGS],
426 AC_REQUIRE([CF_GCC_VERSION])
427 CF_INTEL_COMPILER(GCC,INTEL_COMPILER,CFLAGS)
429 cat > conftest.$ac_ext <<EOF
430 #line __oline__ "${as_me-configure}"
431 int main(int argc, char *argv[[]]) { return (argv[[argc-1]] == 0) ; }
434 if test "$INTEL_COMPILER" = yes
436 # The "-wdXXX" options suppress warnings:
437 # remark #1419: external declaration in primary source file
438 # remark #1683: explicit conversion of a 64-bit integral type to a smaller integral type (potential portability problem)
439 # remark #1684: conversion from pointer to same-sized integral type (potential portability problem)
440 # remark #193: zero used for undefined preprocessing identifier
441 # remark #593: variable "curs_sb_left_arrow" was set but never used
442 # remark #810: conversion from "int" to "Dimension={unsigned short}" may lose significant bits
443 # remark #869: parameter "tw" was never referenced
444 # remark #981: operands are evaluated in unspecified order
445 # warning #279: controlling expression is constant
447 AC_CHECKING([for $CC warning options])
448 cf_save_CFLAGS="$CFLAGS"
461 CFLAGS="$cf_save_CFLAGS $EXTRA_CFLAGS -$cf_opt"
462 if AC_TRY_EVAL(ac_compile); then
463 test -n "$verbose" && AC_MSG_RESULT(... -$cf_opt)
464 EXTRA_CFLAGS="$EXTRA_CFLAGS -$cf_opt"
467 CFLAGS="$cf_save_CFLAGS"
469 elif test "$GCC" = yes
471 AC_CHECKING([for $CC warning options])
472 cf_save_CFLAGS="$CFLAGS"
473 EXTRA_CFLAGS="-W -Wall"
475 test "$with_ext_const" = yes && cf_warn_CONST="Wwrite-strings"
481 Wmissing-declarations \
482 Wmissing-prototypes \
487 Wundef $cf_warn_CONST $1
489 CFLAGS="$cf_save_CFLAGS $EXTRA_CFLAGS -$cf_opt"
490 if AC_TRY_EVAL(ac_compile); then
491 test -n "$verbose" && AC_MSG_RESULT(... -$cf_opt)
494 CPPFLAGS="$CPPFLAGS -DXTSTRINGDEFINES"
499 CF_VERBOSE(feature is broken in gcc $GCC_VERSION)
504 EXTRA_CFLAGS="$EXTRA_CFLAGS -$cf_opt"
507 CFLAGS="$cf_save_CFLAGS"
511 AC_SUBST(EXTRA_CFLAGS)
513 dnl ---------------------------------------------------------------------------
514 dnl CF_INTEL_COMPILER version: 3 updated: 2005/08/06 18:37:29
515 dnl -----------------
516 dnl Check if the given compiler is really the Intel compiler for Linux. It
517 dnl tries to imitate gcc, but does not return an error when it finds a mismatch
518 dnl between prototypes, e.g., as exercised by CF_MISSING_CHECK.
520 dnl This macro should be run "soon" after AC_PROG_CC or AC_PROG_CPLUSPLUS, to
521 dnl ensure that it is not mistaken for gcc/g++. It is normally invoked from
522 dnl the wrappers for gcc and g++ warnings.
524 dnl $1 = GCC (default) or GXX
525 dnl $2 = INTEL_COMPILER (default) or INTEL_CPLUSPLUS
526 dnl $3 = CFLAGS (default) or CXXFLAGS
527 AC_DEFUN([CF_INTEL_COMPILER],[
528 ifelse($2,,INTEL_COMPILER,[$2])=no
530 if test "$ifelse($1,,[$1],GCC)" = yes ; then
533 AC_MSG_CHECKING(if this is really Intel ifelse($1,GXX,C++,C) compiler)
534 cf_save_CFLAGS="$ifelse($3,,CFLAGS,[$3])"
535 ifelse($3,,CFLAGS,[$3])="$ifelse($3,,CFLAGS,[$3]) -no-gcc"
537 #ifdef __INTEL_COMPILER
541 ],[ifelse($2,,INTEL_COMPILER,[$2])=yes
542 cf_save_CFLAGS="$cf_save_CFLAGS -we147 -no-gcc"
544 ifelse($3,,CFLAGS,[$3])="$cf_save_CFLAGS"
545 AC_MSG_RESULT($ifelse($2,,INTEL_COMPILER,[$2]))
550 dnl ---------------------------------------------------------------------------
551 dnl CF_MSG_LOG version: 4 updated: 2007/07/29 09:55:12
553 dnl Write a debug message to config.log, along with the line number in the
554 dnl configure script.
555 AC_DEFUN([CF_MSG_LOG],[
556 echo "${as_me-configure}:__oline__: testing $* ..." 1>&AC_FD_CC
558 dnl ---------------------------------------------------------------------------
559 dnl CF_NO_LEAKS_OPTION version: 4 updated: 2006/12/16 14:24:05
560 dnl ------------------
561 dnl see CF_WITH_NO_LEAKS
562 AC_DEFUN([CF_NO_LEAKS_OPTION],[
563 AC_MSG_CHECKING(if you want to use $1 for testing)
566 [AC_DEFINE($3)ifelse([$4],,[
570 : ${with_no_leaks:=yes}
573 AC_MSG_RESULT(${with_$1:-no})
575 case .$with_cflags in #(vi
577 case .$CFLAGS in #(vi
587 dnl ---------------------------------------------------------------------------
588 dnl CF_PROG_EXT version: 10 updated: 2004/01/03 19:28:18
590 dnl Compute $PROG_EXT, used for non-Unix ports, such as OS/2 EMX.
591 AC_DEFUN([CF_PROG_EXT],
593 AC_REQUIRE([CF_CHECK_CACHE])
594 case $cf_cv_system_name in
596 CFLAGS="$CFLAGS -Zmt"
597 CPPFLAGS="$CPPFLAGS -D__ST_MT_ERRNO__"
598 CXXFLAGS="$CXXFLAGS -Zmt"
599 # autoconf's macro sets -Zexe and suffix both, which conflict:w
600 LDFLAGS="$LDFLAGS -Zmt -Zcrtdll"
610 test -n "$PROG_EXT" && AC_DEFINE_UNQUOTED(PROG_EXT,"$PROG_EXT")
612 dnl ---------------------------------------------------------------------------
613 dnl CF_UPPER version: 5 updated: 2001/01/29 23:40:59
615 dnl Make an uppercase version of a variable
619 $1=`echo "$2" | sed y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%`
621 dnl ---------------------------------------------------------------------------
622 dnl CF_VERBOSE version: 3 updated: 2007/07/29 09:55:12
624 dnl Use AC_VERBOSE w/o the warnings
625 AC_DEFUN([CF_VERBOSE],
626 [test -n "$verbose" && echo " $1" 1>&AC_FD_MSG
629 dnl ---------------------------------------------------------------------------
630 dnl CF_WITH_DBMALLOC version: 6 updated: 2006/12/16 14:24:05
632 dnl Configure-option for dbmalloc. The optional parameter is used to override
633 dnl the updating of $LIBS, e.g., to avoid conflict with subsequent tests.
634 AC_DEFUN([CF_WITH_DBMALLOC],[
635 CF_NO_LEAKS_OPTION(dbmalloc,
636 [ --with-dbmalloc test: use Conor Cahill's dbmalloc library],
639 if test "$with_dbmalloc" = yes ; then
640 AC_CHECK_HEADER(dbmalloc.h,
641 [AC_CHECK_LIB(dbmalloc,[debug_malloc]ifelse($1,,[],[,$1]))])
644 dnl ---------------------------------------------------------------------------
645 dnl CF_WITH_DMALLOC version: 6 updated: 2006/12/16 14:24:05
647 dnl Configure-option for dmalloc. The optional parameter is used to override
648 dnl the updating of $LIBS, e.g., to avoid conflict with subsequent tests.
649 AC_DEFUN([CF_WITH_DMALLOC],[
650 CF_NO_LEAKS_OPTION(dmalloc,
651 [ --with-dmalloc test: use Gray Watson's dmalloc library],
654 if test "$with_dmalloc" = yes ; then
655 AC_CHECK_HEADER(dmalloc.h,
656 [AC_CHECK_LIB(dmalloc,[dmalloc_debug]ifelse($1,,[],[,$1]))])
659 dnl ---------------------------------------------------------------------------
660 dnl CF_WITH_VALGRIND version: 1 updated: 2006/12/14 18:00:21
662 AC_DEFUN([CF_WITH_VALGRIND],[
663 CF_NO_LEAKS_OPTION(valgrind,
664 [ --with-valgrind test: use valgrind],
667 dnl ---------------------------------------------------------------------------
668 dnl CF_WITH_WARNINGS version: 5 updated: 2004/07/23 14:40:34
670 dnl Combine the checks for gcc features into a configure-script option
673 dnl $1 - see CF_GCC_WARNINGS
674 AC_DEFUN([CF_WITH_WARNINGS],
676 if ( test "$GCC" = yes || test "$GXX" = yes )
678 AC_MSG_CHECKING(if you want to check for gcc warnings)
679 AC_ARG_WITH(warnings,
680 [ --with-warnings test: turn on gcc warnings],
681 [cf_opt_with_warnings=$withval],
682 [cf_opt_with_warnings=no])
683 AC_MSG_RESULT($cf_opt_with_warnings)
684 if test "$cf_opt_with_warnings" != no ; then
686 CF_GCC_WARNINGS([$1])