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