]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/byacc/aclocal.m4
Followup to r347996
[FreeBSD/FreeBSD.git] / contrib / byacc / aclocal.m4
1 dnl $Id: aclocal.m4,v 1.42 2017/02/01 10:12:21 tom Exp $
2 dnl Macros for byacc configure script (Thomas E. Dickey)
3 dnl ---------------------------------------------------------------------------
4 dnl Copyright 2004-2016,2017 Thomas E. Dickey
5 dnl 
6 dnl Permission is hereby granted, free of charge, to any person obtaining a
7 dnl copy of this software and associated documentation files (the
8 dnl "Software"), to deal in the Software without restriction, including
9 dnl without limitation the rights to use, copy, modify, merge, publish,
10 dnl distribute, distribute with modifications, sublicense, and/or sell
11 dnl copies of the Software, and to permit persons to whom the Software is
12 dnl furnished to do so, subject to the following conditions:
13 dnl 
14 dnl The above copyright notice and this permission notice shall be included
15 dnl in all copies or portions of the Software.
16 dnl 
17 dnl THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 dnl OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 dnl MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 dnl IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
21 dnl DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22 dnl OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
23 dnl THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 dnl 
25 dnl Except as contained in this notice, the name(s) of the above copyright
26 dnl holders shall not be used in advertising or otherwise to promote the
27 dnl sale, use or other dealings in this Software without prior written
28 dnl authorization.
29 dnl ---------------------------------------------------------------------------
30 dnl ---------------------------------------------------------------------------
31 dnl CF_ACVERSION_CHECK version: 5 updated: 2014/06/04 19:11:49
32 dnl ------------------
33 dnl Conditionally generate script according to whether we're using a given autoconf.
34 dnl
35 dnl $1 = version to compare against
36 dnl $2 = code to use if AC_ACVERSION is at least as high as $1.
37 dnl $3 = code to use if AC_ACVERSION is older than $1.
38 define([CF_ACVERSION_CHECK],
39 [
40 ifdef([AC_ACVERSION], ,[ifdef([AC_AUTOCONF_VERSION],[m4_copy([AC_AUTOCONF_VERSION],[AC_ACVERSION])],[m4_copy([m4_PACKAGE_VERSION],[AC_ACVERSION])])])dnl
41 ifdef([m4_version_compare],
42 [m4_if(m4_version_compare(m4_defn([AC_ACVERSION]), [$1]), -1, [$3], [$2])],
43 [CF_ACVERSION_COMPARE(
44 AC_PREREQ_CANON(AC_PREREQ_SPLIT([$1])),
45 AC_PREREQ_CANON(AC_PREREQ_SPLIT(AC_ACVERSION)), AC_ACVERSION, [$2], [$3])])])dnl
46 dnl ---------------------------------------------------------------------------
47 dnl CF_ACVERSION_COMPARE version: 3 updated: 2012/10/03 18:39:53
48 dnl --------------------
49 dnl CF_ACVERSION_COMPARE(MAJOR1, MINOR1, TERNARY1,
50 dnl                      MAJOR2, MINOR2, TERNARY2,
51 dnl                      PRINTABLE2, not FOUND, FOUND)
52 define([CF_ACVERSION_COMPARE],
53 [ifelse(builtin([eval], [$2 < $5]), 1,
54 [ifelse([$8], , ,[$8])],
55 [ifelse([$9], , ,[$9])])])dnl
56 dnl ---------------------------------------------------------------------------
57 dnl CF_ADD_CFLAGS version: 12 updated: 2015/04/12 15:39:00
58 dnl -------------
59 dnl Copy non-preprocessor flags to $CFLAGS, preprocessor flags to $CPPFLAGS
60 dnl The second parameter if given makes this macro verbose.
61 dnl
62 dnl Put any preprocessor definitions that use quoted strings in $EXTRA_CPPFLAGS,
63 dnl to simplify use of $CPPFLAGS in compiler checks, etc., that are easily
64 dnl confused by the quotes (which require backslashes to keep them usable).
65 AC_DEFUN([CF_ADD_CFLAGS],
66 [
67 cf_fix_cppflags=no
68 cf_new_cflags=
69 cf_new_cppflags=
70 cf_new_extra_cppflags=
71
72 for cf_add_cflags in $1
73 do
74 case $cf_fix_cppflags in
75 (no)
76         case $cf_add_cflags in
77         (-undef|-nostdinc*|-I*|-D*|-U*|-E|-P|-C)
78                 case $cf_add_cflags in
79                 (-D*)
80                         cf_tst_cflags=`echo ${cf_add_cflags} |sed -e 's/^-D[[^=]]*='\''\"[[^"]]*//'`
81
82                         test "x${cf_add_cflags}" != "x${cf_tst_cflags}" \
83                                 && test -z "${cf_tst_cflags}" \
84                                 && cf_fix_cppflags=yes
85
86                         if test $cf_fix_cppflags = yes ; then
87                                 cf_new_extra_cppflags="$cf_new_extra_cppflags $cf_add_cflags"
88                                 continue
89                         elif test "${cf_tst_cflags}" = "\"'" ; then
90                                 cf_new_extra_cppflags="$cf_new_extra_cppflags $cf_add_cflags"
91                                 continue
92                         fi
93                         ;;
94                 esac
95                 case "$CPPFLAGS" in
96                 (*$cf_add_cflags)
97                         ;;
98                 (*)
99                         case $cf_add_cflags in
100                         (-D*)
101                                 cf_tst_cppflags=`echo "x$cf_add_cflags" | sed -e 's/^...//' -e 's/=.*//'`
102                                 CF_REMOVE_DEFINE(CPPFLAGS,$CPPFLAGS,$cf_tst_cppflags)
103                                 ;;
104                         esac
105                         cf_new_cppflags="$cf_new_cppflags $cf_add_cflags"
106                         ;;
107                 esac
108                 ;;
109         (*)
110                 cf_new_cflags="$cf_new_cflags $cf_add_cflags"
111                 ;;
112         esac
113         ;;
114 (yes)
115         cf_new_extra_cppflags="$cf_new_extra_cppflags $cf_add_cflags"
116
117         cf_tst_cflags=`echo ${cf_add_cflags} |sed -e 's/^[[^"]]*"'\''//'`
118
119         test "x${cf_add_cflags}" != "x${cf_tst_cflags}" \
120                 && test -z "${cf_tst_cflags}" \
121                 && cf_fix_cppflags=no
122         ;;
123 esac
124 done
125
126 if test -n "$cf_new_cflags" ; then
127         ifelse([$2],,,[CF_VERBOSE(add to \$CFLAGS $cf_new_cflags)])
128         CFLAGS="$CFLAGS $cf_new_cflags"
129 fi
130
131 if test -n "$cf_new_cppflags" ; then
132         ifelse([$2],,,[CF_VERBOSE(add to \$CPPFLAGS $cf_new_cppflags)])
133         CPPFLAGS="$CPPFLAGS $cf_new_cppflags"
134 fi
135
136 if test -n "$cf_new_extra_cppflags" ; then
137         ifelse([$2],,,[CF_VERBOSE(add to \$EXTRA_CPPFLAGS $cf_new_extra_cppflags)])
138         EXTRA_CPPFLAGS="$cf_new_extra_cppflags $EXTRA_CPPFLAGS"
139 fi
140
141 AC_SUBST(EXTRA_CPPFLAGS)
142
143 ])dnl
144 dnl ---------------------------------------------------------------------------
145 dnl CF_ARG_DISABLE version: 3 updated: 1999/03/30 17:24:31
146 dnl --------------
147 dnl Allow user to disable a normally-on option.
148 AC_DEFUN([CF_ARG_DISABLE],
149 [CF_ARG_OPTION($1,[$2],[$3],[$4],yes)])dnl
150 dnl ---------------------------------------------------------------------------
151 dnl CF_ARG_OPTION version: 5 updated: 2015/05/10 19:52:14
152 dnl -------------
153 dnl Restricted form of AC_ARG_ENABLE that ensures user doesn't give bogus
154 dnl values.
155 dnl
156 dnl Parameters:
157 dnl $1 = option name
158 dnl $2 = help-string
159 dnl $3 = action to perform if option is not default
160 dnl $4 = action if perform if option is default
161 dnl $5 = default option value (either 'yes' or 'no')
162 AC_DEFUN([CF_ARG_OPTION],
163 [AC_ARG_ENABLE([$1],[$2],[test "$enableval" != ifelse([$5],no,yes,no) && enableval=ifelse([$5],no,no,yes)
164         if test "$enableval" != "$5" ; then
165 ifelse([$3],,[    :]dnl
166 ,[    $3]) ifelse([$4],,,[
167         else
168                 $4])
169         fi],[enableval=$5 ifelse([$4],,,[
170         $4
171 ])dnl
172 ])])dnl
173 dnl ---------------------------------------------------------------------------
174 dnl CF_CC_ENV_FLAGS version: 6 updated: 2016/08/29 20:57:00
175 dnl ---------------
176 dnl Check for user's environment-breakage by stuffing CFLAGS/CPPFLAGS content
177 dnl into CC.  This will not help with broken scripts that wrap the compiler
178 dnl with options, but eliminates a more common category of user confusion.
179 dnl
180 dnl In particular, it addresses the problem of being able to run the C
181 dnl preprocessor in a consistent manner.
182 dnl
183 dnl Caveat: this also disallows blanks in the pathname for the compiler, but
184 dnl the nuisance of having inconsistent settings for compiler and preprocessor
185 dnl outweighs that limitation.
186 AC_DEFUN([CF_CC_ENV_FLAGS],
187 [
188 # This should have been defined by AC_PROG_CC
189 : ${CC:=cc}
190
191 AC_MSG_CHECKING(\$CC variable)
192 case "$CC" in
193 (*[[\ \ ]]-*)
194         AC_MSG_RESULT(broken)
195         AC_MSG_WARN(your environment misuses the CC variable to hold CFLAGS/CPPFLAGS options)
196         # humor him...
197         cf_flags=`echo "$CC" | sed -e 's/^.*[[  ]]\(-[[^        ]]\)/\1/'`
198         CC=`echo "$CC " | sed -e 's/[[  ]]-[[^  ]].*$//' -e 's/[[       ]]*$//'`
199         for cf_arg in $cf_flags
200         do
201                 case "x$cf_arg" in
202                 (x-[[IUDfgOW]]*)
203                         CF_ADD_CFLAGS($cf_flags)
204                         ;;
205                 (*)
206                         CC="$CC $cf_arg"
207                         ;;
208                 esac
209         done
210         CF_VERBOSE(resulting CC: '$CC')
211         CF_VERBOSE(resulting CFLAGS: '$CFLAGS')
212         CF_VERBOSE(resulting CPPFLAGS: '$CPPFLAGS')
213         ;;
214 (*)
215         AC_MSG_RESULT(ok)
216         ;;
217 esac
218 ])dnl
219 dnl ---------------------------------------------------------------------------
220 dnl CF_CHECK_CACHE version: 12 updated: 2012/10/02 20:55:03
221 dnl --------------
222 dnl Check if we're accidentally using a cache from a different machine.
223 dnl Derive the system name, as a check for reusing the autoconf cache.
224 dnl
225 dnl If we've packaged config.guess and config.sub, run that (since it does a
226 dnl better job than uname).  Normally we'll use AC_CANONICAL_HOST, but allow
227 dnl an extra parameter that we may override, e.g., for AC_CANONICAL_SYSTEM
228 dnl which is useful in cross-compiles.
229 dnl
230 dnl Note: we would use $ac_config_sub, but that is one of the places where
231 dnl autoconf 2.5x broke compatibility with autoconf 2.13
232 AC_DEFUN([CF_CHECK_CACHE],
233 [
234 if test -f $srcdir/config.guess || test -f $ac_aux_dir/config.guess ; then
235         ifelse([$1],,[AC_CANONICAL_HOST],[$1])
236         system_name="$host_os"
237 else
238         system_name="`(uname -s -r) 2>/dev/null`"
239         if test -z "$system_name" ; then
240                 system_name="`(hostname) 2>/dev/null`"
241         fi
242 fi
243 test -n "$system_name" && AC_DEFINE_UNQUOTED(SYSTEM_NAME,"$system_name",[Define to the system name.])
244 AC_CACHE_VAL(cf_cv_system_name,[cf_cv_system_name="$system_name"])
245
246 test -z "$system_name" && system_name="$cf_cv_system_name"
247 test -n "$cf_cv_system_name" && AC_MSG_RESULT(Configuring for $cf_cv_system_name)
248
249 if test ".$system_name" != ".$cf_cv_system_name" ; then
250         AC_MSG_RESULT(Cached system name ($system_name) does not agree with actual ($cf_cv_system_name))
251         AC_MSG_ERROR("Please remove config.cache and try again.")
252 fi
253 ])dnl
254 dnl ---------------------------------------------------------------------------
255 dnl CF_CLANG_COMPILER version: 2 updated: 2013/11/19 19:23:35
256 dnl -----------------
257 dnl Check if the given compiler is really clang.  clang's C driver defines
258 dnl __GNUC__ (fooling the configure script into setting $GCC to yes) but does
259 dnl not ignore some gcc options.
260 dnl
261 dnl This macro should be run "soon" after AC_PROG_CC or AC_PROG_CPLUSPLUS, to
262 dnl ensure that it is not mistaken for gcc/g++.  It is normally invoked from
263 dnl the wrappers for gcc and g++ warnings.
264 dnl
265 dnl $1 = GCC (default) or GXX
266 dnl $2 = CLANG_COMPILER (default)
267 dnl $3 = CFLAGS (default) or CXXFLAGS
268 AC_DEFUN([CF_CLANG_COMPILER],[
269 ifelse([$2],,CLANG_COMPILER,[$2])=no
270
271 if test "$ifelse([$1],,[$1],GCC)" = yes ; then
272         AC_MSG_CHECKING(if this is really Clang ifelse([$1],GXX,C++,C) compiler)
273         cf_save_CFLAGS="$ifelse([$3],,CFLAGS,[$3])"
274         ifelse([$3],,CFLAGS,[$3])="$ifelse([$3],,CFLAGS,[$3]) -Qunused-arguments"
275         AC_TRY_COMPILE([],[
276 #ifdef __clang__
277 #else
278 make an error
279 #endif
280 ],[ifelse([$2],,CLANG_COMPILER,[$2])=yes
281 cf_save_CFLAGS="$cf_save_CFLAGS -Qunused-arguments"
282 ],[])
283         ifelse([$3],,CFLAGS,[$3])="$cf_save_CFLAGS"
284         AC_MSG_RESULT($ifelse([$2],,CLANG_COMPILER,[$2]))
285 fi
286 ])
287 dnl ---------------------------------------------------------------------------
288 dnl CF_DISABLE_ECHO version: 13 updated: 2015/04/18 08:56:57
289 dnl ---------------
290 dnl You can always use "make -n" to see the actual options, but it's hard to
291 dnl pick out/analyze warning messages when the compile-line is long.
292 dnl
293 dnl Sets:
294 dnl     ECHO_LT - symbol to control if libtool is verbose
295 dnl     ECHO_LD - symbol to prefix "cc -o" lines
296 dnl     RULE_CC - symbol to put before implicit "cc -c" lines (e.g., .c.o)
297 dnl     SHOW_CC - symbol to put before explicit "cc -c" lines
298 dnl     ECHO_CC - symbol to put before any "cc" line
299 dnl
300 AC_DEFUN([CF_DISABLE_ECHO],[
301 AC_MSG_CHECKING(if you want to see long compiling messages)
302 CF_ARG_DISABLE(echo,
303         [  --disable-echo          do not display "compiling" commands],
304         [
305         ECHO_LT='--silent'
306         ECHO_LD='@echo linking [$]@;'
307         RULE_CC='@echo compiling [$]<'
308         SHOW_CC='@echo compiling [$]@'
309         ECHO_CC='@'
310 ],[
311         ECHO_LT=''
312         ECHO_LD=''
313         RULE_CC=''
314         SHOW_CC=''
315         ECHO_CC=''
316 ])
317 AC_MSG_RESULT($enableval)
318 AC_SUBST(ECHO_LT)
319 AC_SUBST(ECHO_LD)
320 AC_SUBST(RULE_CC)
321 AC_SUBST(SHOW_CC)
322 AC_SUBST(ECHO_CC)
323 ])dnl
324 dnl ---------------------------------------------------------------------------
325 dnl CF_DISABLE_LEAKS version: 7 updated: 2012/10/02 20:55:03
326 dnl ----------------
327 dnl Combine no-leak checks with the libraries or tools that are used for the
328 dnl checks.
329 AC_DEFUN([CF_DISABLE_LEAKS],[
330
331 AC_REQUIRE([CF_WITH_DMALLOC])
332 AC_REQUIRE([CF_WITH_DBMALLOC])
333 AC_REQUIRE([CF_WITH_VALGRIND])
334
335 AC_MSG_CHECKING(if you want to perform memory-leak testing)
336 AC_ARG_ENABLE(leaks,
337         [  --disable-leaks         test: free permanent memory, analyze leaks],
338         [if test "x$enableval" = xno; then with_no_leaks=yes; else with_no_leaks=no; fi],
339         : ${with_no_leaks:=no})
340 AC_MSG_RESULT($with_no_leaks)
341
342 if test "$with_no_leaks" = yes ; then
343         AC_DEFINE(NO_LEAKS,1,[Define to 1 if you want to perform memory-leak testing.])
344         AC_DEFINE(YY_NO_LEAKS,1,[Define to 1 if you want to perform memory-leak testing.])
345 fi
346 ])dnl
347 dnl ---------------------------------------------------------------------------
348 dnl CF_GCC_ATTRIBUTES version: 17 updated: 2015/04/12 15:39:00
349 dnl -----------------
350 dnl Test for availability of useful gcc __attribute__ directives to quiet
351 dnl compiler warnings.  Though useful, not all are supported -- and contrary
352 dnl to documentation, unrecognized directives cause older compilers to barf.
353 AC_DEFUN([CF_GCC_ATTRIBUTES],
354 [
355 if test "$GCC" = yes
356 then
357 cat > conftest.i <<EOF
358 #ifndef GCC_PRINTF
359 #define GCC_PRINTF 0
360 #endif
361 #ifndef GCC_SCANF
362 #define GCC_SCANF 0
363 #endif
364 #ifndef GCC_NORETURN
365 #define GCC_NORETURN /* nothing */
366 #endif
367 #ifndef GCC_UNUSED
368 #define GCC_UNUSED /* nothing */
369 #endif
370 EOF
371 if test "$GCC" = yes
372 then
373         AC_CHECKING([for $CC __attribute__ directives])
374 cat > conftest.$ac_ext <<EOF
375 #line __oline__ "${as_me:-configure}"
376 #include "confdefs.h"
377 #include "conftest.h"
378 #include "conftest.i"
379 #if     GCC_PRINTF
380 #define GCC_PRINTFLIKE(fmt,var) __attribute__((format(printf,fmt,var)))
381 #else
382 #define GCC_PRINTFLIKE(fmt,var) /*nothing*/
383 #endif
384 #if     GCC_SCANF
385 #define GCC_SCANFLIKE(fmt,var)  __attribute__((format(scanf,fmt,var)))
386 #else
387 #define GCC_SCANFLIKE(fmt,var)  /*nothing*/
388 #endif
389 extern void wow(char *,...) GCC_SCANFLIKE(1,2);
390 extern void oops(char *,...) GCC_PRINTFLIKE(1,2) GCC_NORETURN;
391 extern void foo(void) GCC_NORETURN;
392 int main(int argc GCC_UNUSED, char *argv[[]] GCC_UNUSED) { return 0; }
393 EOF
394         cf_printf_attribute=no
395         cf_scanf_attribute=no
396         for cf_attribute in scanf printf unused noreturn
397         do
398                 CF_UPPER(cf_ATTRIBUTE,$cf_attribute)
399                 cf_directive="__attribute__(($cf_attribute))"
400                 echo "checking for $CC $cf_directive" 1>&AC_FD_CC
401
402                 case $cf_attribute in
403                 (printf)
404                         cf_printf_attribute=yes
405                         cat >conftest.h <<EOF
406 #define GCC_$cf_ATTRIBUTE 1
407 EOF
408                         ;;
409                 (scanf)
410                         cf_scanf_attribute=yes
411                         cat >conftest.h <<EOF
412 #define GCC_$cf_ATTRIBUTE 1
413 EOF
414                         ;;
415                 (*)
416                         cat >conftest.h <<EOF
417 #define GCC_$cf_ATTRIBUTE $cf_directive
418 EOF
419                         ;;
420                 esac
421
422                 if AC_TRY_EVAL(ac_compile); then
423                         test -n "$verbose" && AC_MSG_RESULT(... $cf_attribute)
424                         cat conftest.h >>confdefs.h
425                         case $cf_attribute in
426                         (noreturn)
427                                 AC_DEFINE_UNQUOTED(GCC_NORETURN,$cf_directive,[Define to noreturn-attribute for gcc])
428                                 ;;
429                         (printf)
430                                 cf_value='/* nothing */'
431                                 if test "$cf_printf_attribute" != no ; then
432                                         cf_value='__attribute__((format(printf,fmt,var)))'
433                                         AC_DEFINE(GCC_PRINTF,1,[Define to 1 if the compiler supports gcc-like printf attribute.])
434                                 fi
435                                 AC_DEFINE_UNQUOTED(GCC_PRINTFLIKE(fmt,var),$cf_value,[Define to printf-attribute for gcc])
436                                 ;;
437                         (scanf)
438                                 cf_value='/* nothing */'
439                                 if test "$cf_scanf_attribute" != no ; then
440                                         cf_value='__attribute__((format(scanf,fmt,var)))'
441                                         AC_DEFINE(GCC_SCANF,1,[Define to 1 if the compiler supports gcc-like scanf attribute.])
442                                 fi
443                                 AC_DEFINE_UNQUOTED(GCC_SCANFLIKE(fmt,var),$cf_value,[Define to sscanf-attribute for gcc])
444                                 ;;
445                         (unused)
446                                 AC_DEFINE_UNQUOTED(GCC_UNUSED,$cf_directive,[Define to unused-attribute for gcc])
447                                 ;;
448                         esac
449                 fi
450         done
451 else
452         fgrep define conftest.i >>confdefs.h
453 fi
454 rm -rf conftest*
455 fi
456 ])dnl
457 dnl ---------------------------------------------------------------------------
458 dnl CF_GCC_VERSION version: 7 updated: 2012/10/18 06:46:33
459 dnl --------------
460 dnl Find version of gcc
461 AC_DEFUN([CF_GCC_VERSION],[
462 AC_REQUIRE([AC_PROG_CC])
463 GCC_VERSION=none
464 if test "$GCC" = yes ; then
465         AC_MSG_CHECKING(version of $CC)
466         GCC_VERSION="`${CC} --version 2>/dev/null | sed -e '2,$d' -e 's/^.*(GCC[[^)]]*) //' -e 's/^.*(Debian[[^)]]*) //' -e 's/^[[^0-9.]]*//' -e 's/[[^0-9.]].*//'`"
467         test -z "$GCC_VERSION" && GCC_VERSION=unknown
468         AC_MSG_RESULT($GCC_VERSION)
469 fi
470 ])dnl
471 dnl ---------------------------------------------------------------------------
472 dnl CF_GCC_WARNINGS version: 32 updated: 2015/04/12 15:39:00
473 dnl ---------------
474 dnl Check if the compiler supports useful warning options.  There's a few that
475 dnl we don't use, simply because they're too noisy:
476 dnl
477 dnl     -Wconversion (useful in older versions of gcc, but not in gcc 2.7.x)
478 dnl     -Wredundant-decls (system headers make this too noisy)
479 dnl     -Wtraditional (combines too many unrelated messages, only a few useful)
480 dnl     -Wwrite-strings (too noisy, but should review occasionally).  This
481 dnl             is enabled for ncurses using "--enable-const".
482 dnl     -pedantic
483 dnl
484 dnl Parameter:
485 dnl     $1 is an optional list of gcc warning flags that a particular
486 dnl             application might want to use, e.g., "no-unused" for
487 dnl             -Wno-unused
488 dnl Special:
489 dnl     If $with_ext_const is "yes", add a check for -Wwrite-strings
490 dnl
491 AC_DEFUN([CF_GCC_WARNINGS],
492 [
493 AC_REQUIRE([CF_GCC_VERSION])
494 CF_INTEL_COMPILER(GCC,INTEL_COMPILER,CFLAGS)
495 CF_CLANG_COMPILER(GCC,CLANG_COMPILER,CFLAGS)
496
497 cat > conftest.$ac_ext <<EOF
498 #line __oline__ "${as_me:-configure}"
499 int main(int argc, char *argv[[]]) { return (argv[[argc-1]] == 0) ; }
500 EOF
501
502 if test "$INTEL_COMPILER" = yes
503 then
504 # The "-wdXXX" options suppress warnings:
505 # remark #1419: external declaration in primary source file
506 # remark #1683: explicit conversion of a 64-bit integral type to a smaller integral type (potential portability problem)
507 # remark #1684: conversion from pointer to same-sized integral type (potential portability problem)
508 # remark #193: zero used for undefined preprocessing identifier
509 # remark #593: variable "curs_sb_left_arrow" was set but never used
510 # remark #810: conversion from "int" to "Dimension={unsigned short}" may lose significant bits
511 # remark #869: parameter "tw" was never referenced
512 # remark #981: operands are evaluated in unspecified order
513 # warning #279: controlling expression is constant
514
515         AC_CHECKING([for $CC warning options])
516         cf_save_CFLAGS="$CFLAGS"
517         EXTRA_CFLAGS="-Wall"
518         for cf_opt in \
519                 wd1419 \
520                 wd1683 \
521                 wd1684 \
522                 wd193 \
523                 wd593 \
524                 wd279 \
525                 wd810 \
526                 wd869 \
527                 wd981
528         do
529                 CFLAGS="$cf_save_CFLAGS $EXTRA_CFLAGS -$cf_opt"
530                 if AC_TRY_EVAL(ac_compile); then
531                         test -n "$verbose" && AC_MSG_RESULT(... -$cf_opt)
532                         EXTRA_CFLAGS="$EXTRA_CFLAGS -$cf_opt"
533                 fi
534         done
535         CFLAGS="$cf_save_CFLAGS"
536
537 elif test "$GCC" = yes
538 then
539         AC_CHECKING([for $CC warning options])
540         cf_save_CFLAGS="$CFLAGS"
541         EXTRA_CFLAGS=
542         cf_warn_CONST=""
543         test "$with_ext_const" = yes && cf_warn_CONST="Wwrite-strings"
544         cf_gcc_warnings="Wignored-qualifiers Wlogical-op Wvarargs"
545         test "x$CLANG_COMPILER" = xyes && cf_gcc_warnings=
546         for cf_opt in W Wall \
547                 Wbad-function-cast \
548                 Wcast-align \
549                 Wcast-qual \
550                 Wdeclaration-after-statement \
551                 Wextra \
552                 Winline \
553                 Wmissing-declarations \
554                 Wmissing-prototypes \
555                 Wnested-externs \
556                 Wpointer-arith \
557                 Wshadow \
558                 Wstrict-prototypes \
559                 Wundef $cf_gcc_warnings $cf_warn_CONST $1
560         do
561                 CFLAGS="$cf_save_CFLAGS $EXTRA_CFLAGS -$cf_opt"
562                 if AC_TRY_EVAL(ac_compile); then
563                         test -n "$verbose" && AC_MSG_RESULT(... -$cf_opt)
564                         case $cf_opt in
565                         (Wcast-qual)
566                                 CPPFLAGS="$CPPFLAGS -DXTSTRINGDEFINES"
567                                 ;;
568                         (Winline)
569                                 case $GCC_VERSION in
570                                 ([[34]].*)
571                                         CF_VERBOSE(feature is broken in gcc $GCC_VERSION)
572                                         continue;;
573                                 esac
574                                 ;;
575                         (Wpointer-arith)
576                                 case $GCC_VERSION in
577                                 ([[12]].*)
578                                         CF_VERBOSE(feature is broken in gcc $GCC_VERSION)
579                                         continue;;
580                                 esac
581                                 ;;
582                         esac
583                         EXTRA_CFLAGS="$EXTRA_CFLAGS -$cf_opt"
584                 fi
585         done
586         CFLAGS="$cf_save_CFLAGS"
587 fi
588 rm -rf conftest*
589
590 AC_SUBST(EXTRA_CFLAGS)
591 ])dnl
592 dnl ---------------------------------------------------------------------------
593 dnl CF_GNU_SOURCE version: 7 updated: 2016/08/05 05:15:37
594 dnl -------------
595 dnl Check if we must define _GNU_SOURCE to get a reasonable value for
596 dnl _XOPEN_SOURCE, upon which many POSIX definitions depend.  This is a defect
597 dnl (or misfeature) of glibc2, which breaks portability of many applications,
598 dnl since it is interwoven with GNU extensions.
599 dnl
600 dnl Well, yes we could work around it...
601 AC_DEFUN([CF_GNU_SOURCE],
602 [
603 AC_CACHE_CHECK(if we must define _GNU_SOURCE,cf_cv_gnu_source,[
604 AC_TRY_COMPILE([#include <sys/types.h>],[
605 #ifndef _XOPEN_SOURCE
606 make an error
607 #endif],
608         [cf_cv_gnu_source=no],
609         [cf_save="$CPPFLAGS"
610          CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
611          AC_TRY_COMPILE([#include <sys/types.h>],[
612 #ifdef _XOPEN_SOURCE
613 make an error
614 #endif],
615         [cf_cv_gnu_source=no],
616         [cf_cv_gnu_source=yes])
617         CPPFLAGS="$cf_save"
618         ])
619 ])
620
621 if test "$cf_cv_gnu_source" = yes
622 then
623 AC_CACHE_CHECK(if we should also define _DEFAULT_SOURCE,cf_cv_default_source,[
624 CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
625         AC_TRY_COMPILE([#include <sys/types.h>],[
626 #ifdef _DEFAULT_SOURCE
627 make an error
628 #endif],
629                 [cf_cv_default_source=no],
630                 [cf_cv_default_source=yes])
631         ])
632 test "$cf_cv_default_source" = yes && CPPFLAGS="$CPPFLAGS -D_DEFAULT_SOURCE"
633 fi
634 ])dnl
635 dnl ---------------------------------------------------------------------------
636 dnl CF_INTEL_COMPILER version: 7 updated: 2015/04/12 15:39:00
637 dnl -----------------
638 dnl Check if the given compiler is really the Intel compiler for Linux.  It
639 dnl tries to imitate gcc, but does not return an error when it finds a mismatch
640 dnl between prototypes, e.g., as exercised by CF_MISSING_CHECK.
641 dnl
642 dnl This macro should be run "soon" after AC_PROG_CC or AC_PROG_CPLUSPLUS, to
643 dnl ensure that it is not mistaken for gcc/g++.  It is normally invoked from
644 dnl the wrappers for gcc and g++ warnings.
645 dnl
646 dnl $1 = GCC (default) or GXX
647 dnl $2 = INTEL_COMPILER (default) or INTEL_CPLUSPLUS
648 dnl $3 = CFLAGS (default) or CXXFLAGS
649 AC_DEFUN([CF_INTEL_COMPILER],[
650 AC_REQUIRE([AC_CANONICAL_HOST])
651 ifelse([$2],,INTEL_COMPILER,[$2])=no
652
653 if test "$ifelse([$1],,[$1],GCC)" = yes ; then
654         case $host_os in
655         (linux*|gnu*)
656                 AC_MSG_CHECKING(if this is really Intel ifelse([$1],GXX,C++,C) compiler)
657                 cf_save_CFLAGS="$ifelse([$3],,CFLAGS,[$3])"
658                 ifelse([$3],,CFLAGS,[$3])="$ifelse([$3],,CFLAGS,[$3]) -no-gcc"
659                 AC_TRY_COMPILE([],[
660 #ifdef __INTEL_COMPILER
661 #else
662 make an error
663 #endif
664 ],[ifelse([$2],,INTEL_COMPILER,[$2])=yes
665 cf_save_CFLAGS="$cf_save_CFLAGS -we147"
666 ],[])
667                 ifelse([$3],,CFLAGS,[$3])="$cf_save_CFLAGS"
668                 AC_MSG_RESULT($ifelse([$2],,INTEL_COMPILER,[$2]))
669                 ;;
670         esac
671 fi
672 ])dnl
673 dnl ---------------------------------------------------------------------------
674 dnl CF_MAKE_DOCS version: 4 updated: 2015/07/04 21:43:03
675 dnl ------------
676 dnl $1 = name(s) to generate rules for
677 dnl $2 = suffix of corresponding manpages used as input.
678 dnl
679 dnl This works best if called at the end of configure.in, following CF_WITH_MAN2HTML
680 define([CF_MAKE_DOCS],[
681 test -z "$cf_make_docs" && cf_make_docs=0
682
683 cf_output=makefile
684 test -f "$cf_output" || cf_output=Makefile
685
686 if test "$cf_make_docs" = 0
687 then
688 cat >>$cf_output <<CF_EOF
689 ################################################################################
690 ## generated by $0
691 .SUFFIXES : .html .$2 .man .ps .pdf .txt
692
693 ${NROFF_NOTE}.$2.txt :
694 ${NROFF_NOTE}   [\$](SHELL) -c "tbl [\$]*.$2 | nroff -man | col -bx" >[\$]@
695
696 ${GROFF_NOTE}.ps.pdf :
697 ${GROFF_NOTE}   ps2pdf [\$]*.ps
698 ${GROFF_NOTE}
699 ${GROFF_NOTE}.$2.ps :
700 ${GROFF_NOTE}   [\$](SHELL) -c "tbl [\$]*.$2 | groff -man" >[\$]@
701 ${GROFF_NOTE}
702 ${GROFF_NOTE}.$2.txt :
703 ${GROFF_NOTE}   GROFF_NO_SGR=stupid [\$](SHELL) -c "tbl [\$]*.$2 | nroff -Tascii -man | col -bx" >[\$]@
704
705 ${MAN2HTML_NOTE}.$2.html :
706 ${MAN2HTML_NOTE}        ./${MAN2HTML_TEMP} [\$]* $2 man >[\$]@
707
708 CF_EOF
709         cf_make_docs=1
710 fi
711
712 for cf_name in $1
713 do
714 cat >>$cf_output <<CF_EOF
715 ################################################################################
716 ${NROFF_NOTE}docs docs-$cf_name :: $cf_name.txt
717 ${MAN2HTML_NOTE}docs docs-$cf_name :: $cf_name.html
718 ${GROFF_NOTE}docs docs-$cf_name :: $cf_name.pdf
719 ${GROFF_NOTE}docs docs-$cf_name :: $cf_name.ps
720 ${GROFF_NOTE}docs docs-$cf_name :: $cf_name.txt
721
722 clean \\
723 docs-clean ::
724 ${NROFF_NOTE}   rm -f $cf_name.txt
725 ${MAN2HTML_NOTE}        rm -f $cf_name.html
726 ${GROFF_NOTE}   rm -f $cf_name.pdf
727 ${GROFF_NOTE}   rm -f $cf_name.ps
728 ${GROFF_NOTE}   rm -f $cf_name.txt
729
730 ${NROFF_NOTE}$cf_name.txt  : $cf_name.$2
731 ${MAN2HTML_NOTE}$cf_name.html : $cf_name.$2
732 ${GROFF_NOTE}$cf_name.pdf  : $cf_name.ps
733 ${GROFF_NOTE}$cf_name.ps   : $cf_name.$2
734 ${GROFF_NOTE}$cf_name.txt  : $cf_name.$2
735 CF_EOF
736 done
737 ])dnl
738 dnl ---------------------------------------------------------------------------
739 dnl CF_MAKE_TAGS version: 6 updated: 2010/10/23 15:52:32
740 dnl ------------
741 dnl Generate tags/TAGS targets for makefiles.  Do not generate TAGS if we have
742 dnl a monocase filesystem.
743 AC_DEFUN([CF_MAKE_TAGS],[
744 AC_REQUIRE([CF_MIXEDCASE_FILENAMES])
745
746 AC_CHECK_PROGS(CTAGS, exctags ctags)
747 AC_CHECK_PROGS(ETAGS, exetags etags)
748
749 AC_CHECK_PROG(MAKE_LOWER_TAGS, ${CTAGS:-ctags}, yes, no)
750
751 if test "$cf_cv_mixedcase" = yes ; then
752         AC_CHECK_PROG(MAKE_UPPER_TAGS, ${ETAGS:-etags}, yes, no)
753 else
754         MAKE_UPPER_TAGS=no
755 fi
756
757 if test "$MAKE_UPPER_TAGS" = yes ; then
758         MAKE_UPPER_TAGS=
759 else
760         MAKE_UPPER_TAGS="#"
761 fi
762
763 if test "$MAKE_LOWER_TAGS" = yes ; then
764         MAKE_LOWER_TAGS=
765 else
766         MAKE_LOWER_TAGS="#"
767 fi
768
769 AC_SUBST(CTAGS)
770 AC_SUBST(ETAGS)
771
772 AC_SUBST(MAKE_UPPER_TAGS)
773 AC_SUBST(MAKE_LOWER_TAGS)
774 ])dnl
775 dnl ---------------------------------------------------------------------------
776 dnl CF_MIXEDCASE_FILENAMES version: 7 updated: 2015/04/12 15:39:00
777 dnl ----------------------
778 dnl Check if the file-system supports mixed-case filenames.  If we're able to
779 dnl create a lowercase name and see it as uppercase, it doesn't support that.
780 AC_DEFUN([CF_MIXEDCASE_FILENAMES],
781 [
782 AC_CACHE_CHECK(if filesystem supports mixed-case filenames,cf_cv_mixedcase,[
783 if test "$cross_compiling" = yes ; then
784         case $target_alias in
785         (*-os2-emx*|*-msdosdjgpp*|*-cygwin*|*-msys*|*-mingw*|*-uwin*)
786                 cf_cv_mixedcase=no
787                 ;;
788         (*)
789                 cf_cv_mixedcase=yes
790                 ;;
791         esac
792 else
793         rm -f conftest CONFTEST
794         echo test >conftest
795         if test -f CONFTEST ; then
796                 cf_cv_mixedcase=no
797         else
798                 cf_cv_mixedcase=yes
799         fi
800         rm -f conftest CONFTEST
801 fi
802 ])
803 test "$cf_cv_mixedcase" = yes && AC_DEFINE(MIXEDCASE_FILENAMES,1,[Define to 1 if filesystem supports mixed-case filenames.])
804 ])dnl
805 dnl ---------------------------------------------------------------------------
806 dnl CF_MKSTEMP version: 10 updated: 2017/01/21 11:12:16
807 dnl ----------
808 dnl Check for a working mkstemp.  This creates two files, checks that they are
809 dnl successfully created and distinct (AmigaOS apparently fails on the last).
810 AC_DEFUN([CF_MKSTEMP],[
811 AC_CHECK_HEADERS( \
812 unistd.h \
813 )
814 AC_CACHE_CHECK(for working mkstemp, cf_cv_func_mkstemp,[
815 rm -rf conftest*
816 AC_TRY_RUN([
817 #include <sys/types.h>
818 #ifdef HAVE_UNISTD_H
819 #include <unistd.h>
820 #endif
821 #include <stdlib.h>
822 #include <stdio.h>
823 #include <string.h>
824 #include <sys/stat.h>
825 int main(void)
826 {
827         char *tmpl = "conftestXXXXXX";
828         char name[2][80];
829         int n;
830         int result = 0;
831         int fd;
832         struct stat sb;
833
834         umask(077);
835         for (n = 0; n < 2; ++n) {
836                 strcpy(name[n], tmpl);
837                 if ((fd = mkstemp(name[n])) >= 0) {
838                         if (!strcmp(name[n], tmpl)
839                          || stat(name[n], &sb) != 0
840                          || (sb.st_mode & S_IFMT) != S_IFREG
841                          || (sb.st_mode & 077) != 0) {
842                                 result = 1;
843                         }
844                         close(fd);
845                 }
846         }
847         if (result == 0
848          && !strcmp(name[0], name[1]))
849                 result = 1;
850         ${cf_cv_main_return:-return}(result);
851 }
852 ],[cf_cv_func_mkstemp=yes
853 ],[cf_cv_func_mkstemp=no
854 ],[cf_cv_func_mkstemp=maybe])
855 ])
856 if test "x$cf_cv_func_mkstemp" = xmaybe ; then
857         AC_CHECK_FUNC(mkstemp)
858 fi
859 if test "x$cf_cv_func_mkstemp" = xyes || test "x$ac_cv_func_mkstemp" = xyes ; then
860         AC_DEFINE(HAVE_MKSTEMP,1,[Define to 1 if mkstemp() is available and working.])
861 fi
862 ])dnl
863 dnl ---------------------------------------------------------------------------
864 dnl CF_MSG_LOG version: 5 updated: 2010/10/23 15:52:32
865 dnl ----------
866 dnl Write a debug message to config.log, along with the line number in the
867 dnl configure script.
868 AC_DEFUN([CF_MSG_LOG],[
869 echo "${as_me:-configure}:__oline__: testing $* ..." 1>&AC_FD_CC
870 ])dnl
871 dnl ---------------------------------------------------------------------------
872 dnl CF_NO_LEAKS_OPTION version: 6 updated: 2015/04/12 15:39:00
873 dnl ------------------
874 dnl see CF_WITH_NO_LEAKS
875 AC_DEFUN([CF_NO_LEAKS_OPTION],[
876 AC_MSG_CHECKING(if you want to use $1 for testing)
877 AC_ARG_WITH($1,
878         [$2],
879         [AC_DEFINE_UNQUOTED($3,1,"Define to 1 if you want to use $1 for testing.")ifelse([$4],,[
880          $4
881 ])
882         : ${with_cflags:=-g}
883         : ${with_no_leaks:=yes}
884          with_$1=yes],
885         [with_$1=])
886 AC_MSG_RESULT(${with_$1:-no})
887
888 case .$with_cflags in
889 (.*-g*)
890         case .$CFLAGS in
891         (.*-g*)
892                 ;;
893         (*)
894                 CF_ADD_CFLAGS([-g])
895                 ;;
896         esac
897         ;;
898 esac
899 ])dnl
900 dnl ---------------------------------------------------------------------------
901 dnl CF_PATH_SYNTAX version: 16 updated: 2015/04/18 08:56:57
902 dnl --------------
903 dnl Check the argument to see that it looks like a pathname.  Rewrite it if it
904 dnl begins with one of the prefix/exec_prefix variables, and then again if the
905 dnl result begins with 'NONE'.  This is necessary to work around autoconf's
906 dnl delayed evaluation of those symbols.
907 AC_DEFUN([CF_PATH_SYNTAX],[
908 if test "x$prefix" != xNONE; then
909         cf_path_syntax="$prefix"
910 else
911         cf_path_syntax="$ac_default_prefix"
912 fi
913
914 case ".[$]$1" in
915 (.\[$]\(*\)*|.\'*\'*)
916         ;;
917 (..|./*|.\\*)
918         ;;
919 (.[[a-zA-Z]]:[[\\/]]*) # OS/2 EMX
920         ;;
921 (.\[$]{*prefix}*|.\[$]{*dir}*)
922         eval $1="[$]$1"
923         case ".[$]$1" in
924         (.NONE/*)
925                 $1=`echo [$]$1 | sed -e s%NONE%$cf_path_syntax%`
926                 ;;
927         esac
928         ;;
929 (.no|.NONE/*)
930         $1=`echo [$]$1 | sed -e s%NONE%$cf_path_syntax%`
931         ;;
932 (*)
933         ifelse([$2],,[AC_MSG_ERROR([expected a pathname, not \"[$]$1\"])],$2)
934         ;;
935 esac
936 ])dnl
937 dnl ---------------------------------------------------------------------------
938 dnl CF_POSIX_C_SOURCE version: 9 updated: 2015/04/12 15:39:00
939 dnl -----------------
940 dnl Define _POSIX_C_SOURCE to the given level, and _POSIX_SOURCE if needed.
941 dnl
942 dnl     POSIX.1-1990                            _POSIX_SOURCE
943 dnl     POSIX.1-1990 and                        _POSIX_SOURCE and
944 dnl             POSIX.2-1992 C-Language                 _POSIX_C_SOURCE=2
945 dnl             Bindings Option
946 dnl     POSIX.1b-1993                           _POSIX_C_SOURCE=199309L
947 dnl     POSIX.1c-1996                           _POSIX_C_SOURCE=199506L
948 dnl     X/Open 2000                             _POSIX_C_SOURCE=200112L
949 dnl
950 dnl Parameters:
951 dnl     $1 is the nominal value for _POSIX_C_SOURCE
952 AC_DEFUN([CF_POSIX_C_SOURCE],
953 [
954 cf_POSIX_C_SOURCE=ifelse([$1],,199506L,[$1])
955
956 cf_save_CFLAGS="$CFLAGS"
957 cf_save_CPPFLAGS="$CPPFLAGS"
958
959 CF_REMOVE_DEFINE(cf_trim_CFLAGS,$cf_save_CFLAGS,_POSIX_C_SOURCE)
960 CF_REMOVE_DEFINE(cf_trim_CPPFLAGS,$cf_save_CPPFLAGS,_POSIX_C_SOURCE)
961
962 AC_CACHE_CHECK(if we should define _POSIX_C_SOURCE,cf_cv_posix_c_source,[
963         CF_MSG_LOG(if the symbol is already defined go no further)
964         AC_TRY_COMPILE([#include <sys/types.h>],[
965 #ifndef _POSIX_C_SOURCE
966 make an error
967 #endif],
968         [cf_cv_posix_c_source=no],
969         [cf_want_posix_source=no
970          case .$cf_POSIX_C_SOURCE in
971          (.[[12]]??*)
972                 cf_cv_posix_c_source="-D_POSIX_C_SOURCE=$cf_POSIX_C_SOURCE"
973                 ;;
974          (.2)
975                 cf_cv_posix_c_source="-D_POSIX_C_SOURCE=$cf_POSIX_C_SOURCE"
976                 cf_want_posix_source=yes
977                 ;;
978          (.*)
979                 cf_want_posix_source=yes
980                 ;;
981          esac
982          if test "$cf_want_posix_source" = yes ; then
983                 AC_TRY_COMPILE([#include <sys/types.h>],[
984 #ifdef _POSIX_SOURCE
985 make an error
986 #endif],[],
987                 cf_cv_posix_c_source="$cf_cv_posix_c_source -D_POSIX_SOURCE")
988          fi
989          CF_MSG_LOG(ifdef from value $cf_POSIX_C_SOURCE)
990          CFLAGS="$cf_trim_CFLAGS"
991          CPPFLAGS="$cf_trim_CPPFLAGS $cf_cv_posix_c_source"
992          CF_MSG_LOG(if the second compile does not leave our definition intact error)
993          AC_TRY_COMPILE([#include <sys/types.h>],[
994 #ifndef _POSIX_C_SOURCE
995 make an error
996 #endif],,
997          [cf_cv_posix_c_source=no])
998          CFLAGS="$cf_save_CFLAGS"
999          CPPFLAGS="$cf_save_CPPFLAGS"
1000         ])
1001 ])
1002
1003 if test "$cf_cv_posix_c_source" != no ; then
1004         CFLAGS="$cf_trim_CFLAGS"
1005         CPPFLAGS="$cf_trim_CPPFLAGS"
1006         CF_ADD_CFLAGS($cf_cv_posix_c_source)
1007 fi
1008
1009 ])dnl
1010 dnl ---------------------------------------------------------------------------
1011 dnl CF_PROG_AWK version: 1 updated: 2006/09/16 11:40:59
1012 dnl -----------
1013 dnl Check for awk, ensure that the check found something.
1014 AC_DEFUN([CF_PROG_AWK],
1015 [
1016 AC_PROG_AWK
1017 test -z "$AWK" && AC_MSG_ERROR(No awk program found)
1018 ])dnl
1019 dnl ---------------------------------------------------------------------------
1020 dnl CF_PROG_CC version: 4 updated: 2014/07/12 18:57:58
1021 dnl ----------
1022 dnl standard check for CC, plus followup sanity checks
1023 dnl $1 = optional parameter to pass to AC_PROG_CC to specify compiler name
1024 AC_DEFUN([CF_PROG_CC],[
1025 ifelse($1,,[AC_PROG_CC],[AC_PROG_CC($1)])
1026 CF_GCC_VERSION
1027 CF_ACVERSION_CHECK(2.52,
1028         [AC_PROG_CC_STDC],
1029         [CF_ANSI_CC_REQD])
1030 CF_CC_ENV_FLAGS
1031 ])dnl
1032 dnl ---------------------------------------------------------------------------
1033 dnl CF_PROG_GROFF version: 2 updated: 2015/07/04 11:16:27
1034 dnl -------------
1035 dnl Check if groff is available, for cases (such as html output) where nroff
1036 dnl is not enough.
1037 AC_DEFUN([CF_PROG_GROFF],[
1038 AC_PATH_PROG(GROFF_PATH,groff,no)
1039 AC_PATH_PROG(NROFF_PATH,nroff,no)
1040 if test "x$GROFF_PATH" = xno
1041 then
1042         NROFF_NOTE=
1043         GROFF_NOTE="#"
1044 else
1045         NROFF_NOTE="#"
1046         GROFF_NOTE=
1047 fi
1048 AC_SUBST(GROFF_NOTE)
1049 AC_SUBST(NROFF_NOTE)
1050 ])dnl
1051 dnl ---------------------------------------------------------------------------
1052 dnl CF_PROG_LINT version: 3 updated: 2016/05/22 15:25:54
1053 dnl ------------
1054 AC_DEFUN([CF_PROG_LINT],
1055 [
1056 AC_CHECK_PROGS(LINT, lint cppcheck splint)
1057 AC_SUBST(LINT_OPTS)
1058 ])dnl
1059 dnl ---------------------------------------------------------------------------
1060 dnl CF_REMOVE_DEFINE version: 3 updated: 2010/01/09 11:05:50
1061 dnl ----------------
1062 dnl Remove all -U and -D options that refer to the given symbol from a list
1063 dnl of C compiler options.  This works around the problem that not all
1064 dnl compilers process -U and -D options from left-to-right, so a -U option
1065 dnl cannot be used to cancel the effect of a preceding -D option.
1066 dnl
1067 dnl $1 = target (which could be the same as the source variable)
1068 dnl $2 = source (including '$')
1069 dnl $3 = symbol to remove
1070 define([CF_REMOVE_DEFINE],
1071 [
1072 $1=`echo "$2" | \
1073         sed     -e 's/-[[UD]]'"$3"'\(=[[^       ]]*\)\?[[       ]]/ /g' \
1074                 -e 's/-[[UD]]'"$3"'\(=[[^       ]]*\)\?[$]//g'`
1075 ])dnl
1076 dnl ---------------------------------------------------------------------------
1077 dnl CF_TRY_XOPEN_SOURCE version: 1 updated: 2011/10/30 17:09:50
1078 dnl -------------------
1079 dnl If _XOPEN_SOURCE is not defined in the compile environment, check if we
1080 dnl can define it successfully.
1081 AC_DEFUN([CF_TRY_XOPEN_SOURCE],[
1082 AC_CACHE_CHECK(if we should define _XOPEN_SOURCE,cf_cv_xopen_source,[
1083         AC_TRY_COMPILE([
1084 #include <stdlib.h>
1085 #include <string.h>
1086 #include <sys/types.h>
1087 ],[
1088 #ifndef _XOPEN_SOURCE
1089 make an error
1090 #endif],
1091         [cf_cv_xopen_source=no],
1092         [cf_save="$CPPFLAGS"
1093          CPPFLAGS="$CPPFLAGS -D_XOPEN_SOURCE=$cf_XOPEN_SOURCE"
1094          AC_TRY_COMPILE([
1095 #include <stdlib.h>
1096 #include <string.h>
1097 #include <sys/types.h>
1098 ],[
1099 #ifdef _XOPEN_SOURCE
1100 make an error
1101 #endif],
1102         [cf_cv_xopen_source=no],
1103         [cf_cv_xopen_source=$cf_XOPEN_SOURCE])
1104         CPPFLAGS="$cf_save"
1105         ])
1106 ])
1107
1108 if test "$cf_cv_xopen_source" != no ; then
1109         CF_REMOVE_DEFINE(CFLAGS,$CFLAGS,_XOPEN_SOURCE)
1110         CF_REMOVE_DEFINE(CPPFLAGS,$CPPFLAGS,_XOPEN_SOURCE)
1111         cf_temp_xopen_source="-D_XOPEN_SOURCE=$cf_cv_xopen_source"
1112         CF_ADD_CFLAGS($cf_temp_xopen_source)
1113 fi
1114 ])
1115 dnl ---------------------------------------------------------------------------
1116 dnl CF_UPPER version: 5 updated: 2001/01/29 23:40:59
1117 dnl --------
1118 dnl Make an uppercase version of a variable
1119 dnl $1=uppercase($2)
1120 AC_DEFUN([CF_UPPER],
1121 [
1122 $1=`echo "$2" | sed y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%`
1123 ])dnl
1124 dnl ---------------------------------------------------------------------------
1125 dnl CF_VERBOSE version: 3 updated: 2007/07/29 09:55:12
1126 dnl ----------
1127 dnl Use AC_VERBOSE w/o the warnings
1128 AC_DEFUN([CF_VERBOSE],
1129 [test -n "$verbose" && echo "   $1" 1>&AC_FD_MSG
1130 CF_MSG_LOG([$1])
1131 ])dnl
1132 dnl ---------------------------------------------------------------------------
1133 dnl CF_WITH_DBMALLOC version: 7 updated: 2010/06/21 17:26:47
1134 dnl ----------------
1135 dnl Configure-option for dbmalloc.  The optional parameter is used to override
1136 dnl the updating of $LIBS, e.g., to avoid conflict with subsequent tests.
1137 AC_DEFUN([CF_WITH_DBMALLOC],[
1138 CF_NO_LEAKS_OPTION(dbmalloc,
1139         [  --with-dbmalloc         test: use Conor Cahill's dbmalloc library],
1140         [USE_DBMALLOC])
1141
1142 if test "$with_dbmalloc" = yes ; then
1143         AC_CHECK_HEADER(dbmalloc.h,
1144                 [AC_CHECK_LIB(dbmalloc,[debug_malloc]ifelse([$1],,[],[,$1]))])
1145 fi
1146 ])dnl
1147 dnl ---------------------------------------------------------------------------
1148 dnl CF_WITH_DMALLOC version: 7 updated: 2010/06/21 17:26:47
1149 dnl ---------------
1150 dnl Configure-option for dmalloc.  The optional parameter is used to override
1151 dnl the updating of $LIBS, e.g., to avoid conflict with subsequent tests.
1152 AC_DEFUN([CF_WITH_DMALLOC],[
1153 CF_NO_LEAKS_OPTION(dmalloc,
1154         [  --with-dmalloc          test: use Gray Watson's dmalloc library],
1155         [USE_DMALLOC])
1156
1157 if test "$with_dmalloc" = yes ; then
1158         AC_CHECK_HEADER(dmalloc.h,
1159                 [AC_CHECK_LIB(dmalloc,[dmalloc_debug]ifelse([$1],,[],[,$1]))])
1160 fi
1161 ])dnl
1162 dnl ---------------------------------------------------------------------------
1163 dnl CF_WITH_MAN2HTML version: 5 updated: 2015/08/20 04:51:36
1164 dnl ----------------
1165 dnl Check for man2html and groff.  Optionally prefer man2html over groff.
1166 dnl Generate a shell script which hides the differences between the two.
1167 dnl
1168 dnl We name that "man2html.tmp".
1169 dnl
1170 dnl The shell script can be removed later, e.g., using "make distclean".
1171 AC_DEFUN([CF_WITH_MAN2HTML],[
1172 AC_REQUIRE([CF_PROG_GROFF])
1173
1174 AC_MSG_CHECKING(for program to convert manpage to html)
1175 AC_ARG_WITH(man2html,
1176         [  --with-man2html=XXX     use XXX rather than groff],
1177         [cf_man2html=$withval],
1178         [cf_man2html=$GROFF_PATH])
1179
1180 cf_with_groff=no
1181
1182 case $cf_man2html in
1183 (yes)
1184         AC_MSG_RESULT(man2html)
1185         AC_PATH_PROG(cf_man2html,man2html,no)
1186         ;;
1187 (no|groff|*/groff*)
1188         cf_with_groff=yes
1189         cf_man2html=$GROFF_PATH
1190         AC_MSG_RESULT($cf_man2html)
1191         ;;
1192 (*)
1193         AC_MSG_RESULT($cf_man2html)
1194         ;;
1195 esac
1196
1197 MAN2HTML_TEMP="man2html.tmp"
1198         cat >$MAN2HTML_TEMP <<CF_EOF
1199 #!$SHELL
1200 # Temporary script generated by CF_WITH_MAN2HTML
1201 # Convert inputs to html, sending result to standard output.
1202 #
1203 # Parameters:
1204 # \${1} = rootname of file to convert
1205 # \${2} = suffix of file to convert, e.g., "1"
1206 # \${3} = macros to use, e.g., "man"
1207 #
1208 ROOT=\[$]1
1209 TYPE=\[$]2
1210 MACS=\[$]3
1211
1212 unset LANG
1213 unset LC_ALL
1214 unset LC_CTYPE
1215 unset LANGUAGE
1216 GROFF_NO_SGR=stupid
1217 export GROFF_NO_SGR
1218
1219 CF_EOF
1220
1221 if test "x$cf_with_groff" = xyes
1222 then
1223         MAN2HTML_NOTE="$GROFF_NOTE"
1224         MAN2HTML_PATH="$GROFF_PATH"
1225         cat >>$MAN2HTML_TEMP <<CF_EOF
1226 $SHELL -c "tbl \${ROOT}.\${TYPE} | $GROFF_PATH -P -o0 -I\${ROOT}_ -Thtml -\${MACS}"
1227 CF_EOF
1228 else
1229         MAN2HTML_NOTE=""
1230         CF_PATH_SYNTAX(cf_man2html)
1231         MAN2HTML_PATH="$cf_man2html"
1232         AC_MSG_CHECKING(for $cf_man2html top/bottom margins)
1233
1234         # for this example, expect 3 lines of content, the remainder is head/foot
1235         cat >conftest.in <<CF_EOF
1236 .TH HEAD1 HEAD2 HEAD3 HEAD4 HEAD5
1237 .SH SECTION
1238 MARKER
1239 CF_EOF
1240
1241         LC_ALL=C LC_CTYPE=C LANG=C LANGUAGE=C nroff -man conftest.in >conftest.out
1242
1243         cf_man2html_1st=`fgrep -n MARKER conftest.out |sed -e 's/^[[^0-9]]*://' -e 's/:.*//'`
1244         cf_man2html_top=`expr $cf_man2html_1st - 2`
1245         cf_man2html_bot=`wc -l conftest.out |sed -e 's/[[^0-9]]//g'`
1246         cf_man2html_bot=`expr $cf_man2html_bot - 2 - $cf_man2html_top`
1247         cf_man2html_top_bot="-topm=$cf_man2html_top -botm=$cf_man2html_bot"
1248
1249         AC_MSG_RESULT($cf_man2html_top_bot)
1250
1251         AC_MSG_CHECKING(for pagesize to use)
1252         for cf_block in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1253         do
1254         cat >>conftest.in <<CF_EOF
1255 .nf
1256 0
1257 1
1258 2
1259 3
1260 4
1261 5
1262 6
1263 7
1264 8
1265 9
1266 CF_EOF
1267         done
1268
1269         LC_ALL=C LC_CTYPE=C LANG=C LANGUAGE=C nroff -man conftest.in >conftest.out
1270         cf_man2html_page=`fgrep -n HEAD1 conftest.out |tail -n 1 |sed -e 's/^[[^0-9]]*://' -e 's/:.*//'`
1271         test -z "$cf_man2html_page" && cf_man2html_page=99999
1272         test "$cf_man2html_page" -gt 100 && cf_man2html_page=99999
1273
1274         rm -rf conftest*
1275         AC_MSG_RESULT($cf_man2html_page)
1276
1277         cat >>$MAN2HTML_TEMP <<CF_EOF
1278 : \${MAN2HTML_PATH=$MAN2HTML_PATH}
1279 MAN2HTML_OPTS="\$MAN2HTML_OPTS -index -title="\$ROOT\(\$TYPE\)" -compress -pgsize $cf_man2html_page"
1280 case \${TYPE} in
1281 (ms)
1282         tbl \${ROOT}.\${TYPE} | nroff -\${MACS} | \$MAN2HTML_PATH -topm=0 -botm=0 \$MAN2HTML_OPTS
1283         ;;
1284 (*)
1285         tbl \${ROOT}.\${TYPE} | nroff -\${MACS} | \$MAN2HTML_PATH $cf_man2html_top_bot \$MAN2HTML_OPTS
1286         ;;
1287 esac
1288 CF_EOF
1289 fi
1290
1291 chmod 700 $MAN2HTML_TEMP
1292
1293 AC_SUBST(MAN2HTML_NOTE)
1294 AC_SUBST(MAN2HTML_PATH)
1295 AC_SUBST(MAN2HTML_TEMP)
1296 ])dnl
1297 dnl ---------------------------------------------------------------------------
1298 dnl CF_WITH_VALGRIND version: 1 updated: 2006/12/14 18:00:21
1299 dnl ----------------
1300 AC_DEFUN([CF_WITH_VALGRIND],[
1301 CF_NO_LEAKS_OPTION(valgrind,
1302         [  --with-valgrind         test: use valgrind],
1303         [USE_VALGRIND])
1304 ])dnl
1305 dnl ---------------------------------------------------------------------------
1306 dnl CF_WITH_WARNINGS version: 5 updated: 2004/07/23 14:40:34
1307 dnl ----------------
1308 dnl Combine the checks for gcc features into a configure-script option
1309 dnl
1310 dnl Parameters:
1311 dnl     $1 - see CF_GCC_WARNINGS
1312 AC_DEFUN([CF_WITH_WARNINGS],
1313 [
1314 if ( test "$GCC" = yes || test "$GXX" = yes )
1315 then
1316 AC_MSG_CHECKING(if you want to check for gcc warnings)
1317 AC_ARG_WITH(warnings,
1318         [  --with-warnings         test: turn on gcc warnings],
1319         [cf_opt_with_warnings=$withval],
1320         [cf_opt_with_warnings=no])
1321 AC_MSG_RESULT($cf_opt_with_warnings)
1322 if test "$cf_opt_with_warnings" != no ; then
1323         CF_GCC_ATTRIBUTES
1324         CF_GCC_WARNINGS([$1])
1325 fi
1326 fi
1327 ])dnl
1328 dnl ---------------------------------------------------------------------------
1329 dnl CF_XOPEN_SOURCE version: 52 updated: 2016/08/27 12:21:42
1330 dnl ---------------
1331 dnl Try to get _XOPEN_SOURCE defined properly that we can use POSIX functions,
1332 dnl or adapt to the vendor's definitions to get equivalent functionality,
1333 dnl without losing the common non-POSIX features.
1334 dnl
1335 dnl Parameters:
1336 dnl     $1 is the nominal value for _XOPEN_SOURCE
1337 dnl     $2 is the nominal value for _POSIX_C_SOURCE
1338 AC_DEFUN([CF_XOPEN_SOURCE],[
1339 AC_REQUIRE([AC_CANONICAL_HOST])
1340
1341 cf_XOPEN_SOURCE=ifelse([$1],,500,[$1])
1342 cf_POSIX_C_SOURCE=ifelse([$2],,199506L,[$2])
1343 cf_xopen_source=
1344
1345 case $host_os in
1346 (aix[[4-7]]*)
1347         cf_xopen_source="-D_ALL_SOURCE"
1348         ;;
1349 (msys)
1350         cf_XOPEN_SOURCE=600
1351         ;;
1352 (darwin[[0-8]].*)
1353         cf_xopen_source="-D_APPLE_C_SOURCE"
1354         ;;
1355 (darwin*)
1356         cf_xopen_source="-D_DARWIN_C_SOURCE"
1357         cf_XOPEN_SOURCE=
1358         ;;
1359 (freebsd*|dragonfly*)
1360         # 5.x headers associate
1361         #       _XOPEN_SOURCE=600 with _POSIX_C_SOURCE=200112L
1362         #       _XOPEN_SOURCE=500 with _POSIX_C_SOURCE=199506L
1363         cf_POSIX_C_SOURCE=200112L
1364         cf_XOPEN_SOURCE=600
1365         cf_xopen_source="-D_BSD_TYPES -D__BSD_VISIBLE -D_POSIX_C_SOURCE=$cf_POSIX_C_SOURCE -D_XOPEN_SOURCE=$cf_XOPEN_SOURCE"
1366         ;;
1367 (hpux11*)
1368         cf_xopen_source="-D_HPUX_SOURCE -D_XOPEN_SOURCE=500"
1369         ;;
1370 (hpux*)
1371         cf_xopen_source="-D_HPUX_SOURCE"
1372         ;;
1373 (irix[[56]].*)
1374         cf_xopen_source="-D_SGI_SOURCE"
1375         cf_XOPEN_SOURCE=
1376         ;;
1377 (linux*|uclinux*|gnu*|mint*|k*bsd*-gnu|cygwin)
1378         CF_GNU_SOURCE
1379         ;;
1380 (minix*)
1381         cf_xopen_source="-D_NETBSD_SOURCE" # POSIX.1-2001 features are ifdef'd with this...
1382         ;;
1383 (mirbsd*)
1384         # setting _XOPEN_SOURCE or _POSIX_SOURCE breaks <sys/select.h> and other headers which use u_int / u_short types
1385         cf_XOPEN_SOURCE=
1386         CF_POSIX_C_SOURCE($cf_POSIX_C_SOURCE)
1387         ;;
1388 (netbsd*)
1389         cf_xopen_source="-D_NETBSD_SOURCE" # setting _XOPEN_SOURCE breaks IPv6 for lynx on NetBSD 1.6, breaks xterm, is not needed for ncursesw
1390         ;;
1391 (openbsd[[4-9]]*)
1392         # setting _XOPEN_SOURCE lower than 500 breaks g++ compile with wchar.h, needed for ncursesw
1393         cf_xopen_source="-D_BSD_SOURCE"
1394         cf_XOPEN_SOURCE=600
1395         ;;
1396 (openbsd*)
1397         # setting _XOPEN_SOURCE breaks xterm on OpenBSD 2.8, is not needed for ncursesw
1398         ;;
1399 (osf[[45]]*)
1400         cf_xopen_source="-D_OSF_SOURCE"
1401         ;;
1402 (nto-qnx*)
1403         cf_xopen_source="-D_QNX_SOURCE"
1404         ;;
1405 (sco*)
1406         # setting _XOPEN_SOURCE breaks Lynx on SCO Unix / OpenServer
1407         ;;
1408 (solaris2.*)
1409         cf_xopen_source="-D__EXTENSIONS__"
1410         cf_cv_xopen_source=broken
1411         ;;
1412 (sysv4.2uw2.*) # Novell/SCO UnixWare 2.x (tested on 2.1.2)
1413         cf_XOPEN_SOURCE=
1414         cf_POSIX_C_SOURCE=
1415         ;;
1416 (*)
1417         CF_TRY_XOPEN_SOURCE
1418         CF_POSIX_C_SOURCE($cf_POSIX_C_SOURCE)
1419         ;;
1420 esac
1421
1422 if test -n "$cf_xopen_source" ; then
1423         CF_ADD_CFLAGS($cf_xopen_source,true)
1424 fi
1425
1426 dnl In anything but the default case, we may have system-specific setting
1427 dnl which is still not guaranteed to provide all of the entrypoints that
1428 dnl _XOPEN_SOURCE would yield.
1429 if test -n "$cf_XOPEN_SOURCE" && test -z "$cf_cv_xopen_source" ; then
1430         AC_MSG_CHECKING(if _XOPEN_SOURCE really is set)
1431         AC_TRY_COMPILE([#include <stdlib.h>],[
1432 #ifndef _XOPEN_SOURCE
1433 make an error
1434 #endif],
1435         [cf_XOPEN_SOURCE_set=yes],
1436         [cf_XOPEN_SOURCE_set=no])
1437         AC_MSG_RESULT($cf_XOPEN_SOURCE_set)
1438         if test $cf_XOPEN_SOURCE_set = yes
1439         then
1440                 AC_TRY_COMPILE([#include <stdlib.h>],[
1441 #if (_XOPEN_SOURCE - 0) < $cf_XOPEN_SOURCE
1442 make an error
1443 #endif],
1444                 [cf_XOPEN_SOURCE_set_ok=yes],
1445                 [cf_XOPEN_SOURCE_set_ok=no])
1446                 if test $cf_XOPEN_SOURCE_set_ok = no
1447                 then
1448                         AC_MSG_WARN(_XOPEN_SOURCE is lower than requested)
1449                 fi
1450         else
1451                 CF_TRY_XOPEN_SOURCE
1452         fi
1453 fi
1454 ])