xref: /freebsd/contrib/byacc/aclocal.m4 (revision 38f0b757fd84d17d0fc24739a7cda160c4516d81)
1dnl $Id: aclocal.m4,v 1.33 2014/01/01 14:08:07 tom Exp $
2dnl Macros for byacc configure script (Thomas E. Dickey)
3dnl ---------------------------------------------------------------------------
4dnl Copyright 2004-2013,2014 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: 4 updated: 2013/03/04 19:52:56
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], ,[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: 10 updated: 2010/05/26 05:38:42
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
75no)
76	case $cf_add_cflags in #(vi
77	-undef|-nostdinc*|-I*|-D*|-U*|-E|-P|-C) #(vi
78		case $cf_add_cflags in
79		-D*)
80			cf_tst_cflags=`echo ${cf_add_cflags} |sed -e 's/^-D[[^=]]*='\''\"[[^"]]*//'`
81
82			test "${cf_add_cflags}" != "${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) #(vi
97			;;
98		*) #(vi
99			case $cf_add_cflags in #(vi
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	;;
114yes)
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 "${cf_add_cflags}" != "${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	CFLAGS="$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	CPPFLAGS="$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	EXTRA_CPPFLAGS="$cf_new_extra_cppflags $EXTRA_CPPFLAGS"
139fi
140
141AC_SUBST(EXTRA_CPPFLAGS)
142
143])dnl
144dnl ---------------------------------------------------------------------------
145dnl CF_ARG_DISABLE version: 3 updated: 1999/03/30 17:24:31
146dnl --------------
147dnl Allow user to disable a normally-on option.
148AC_DEFUN([CF_ARG_DISABLE],
149[CF_ARG_OPTION($1,[$2],[$3],[$4],yes)])dnl
150dnl ---------------------------------------------------------------------------
151dnl CF_ARG_OPTION version: 4 updated: 2010/05/26 05:38:42
152dnl -------------
153dnl Restricted form of AC_ARG_ENABLE that ensures user doesn't give bogus
154dnl values.
155dnl
156dnl Parameters:
157dnl $1 = option name
158dnl $2 = help-string
159dnl $3 = action to perform if option is not default
160dnl $4 = action if perform if option is default
161dnl $5 = default option value (either 'yes' or 'no')
162AC_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
165ifelse([$3],,[    :]dnl
166,[    $3]) ifelse([$4],,,[
167  else
168    $4])
169  fi],[enableval=$5 ifelse([$4],,,[
170  $4
171])dnl
172  ])])dnl
173dnl ---------------------------------------------------------------------------
174dnl CF_CC_ENV_FLAGS version: 1 updated: 2012/10/03 05:25:49
175dnl ---------------
176dnl Check for user's environment-breakage by stuffing CFLAGS/CPPFLAGS content
177dnl into CC.  This will not help with broken scripts that wrap the compiler with
178dnl options, but eliminates a more common category of user confusion.
179AC_DEFUN([CF_CC_ENV_FLAGS],
180[
181# This should have been defined by AC_PROG_CC
182: ${CC:=cc}
183
184AC_MSG_CHECKING(\$CC variable)
185case "$CC" in #(vi
186*[[\ \	]]-[[IUD]]*)
187	AC_MSG_RESULT(broken)
188	AC_MSG_WARN(your environment misuses the CC variable to hold CFLAGS/CPPFLAGS options)
189	# humor him...
190	cf_flags=`echo "$CC" | sed -e 's/^[[^ 	]]*[[ 	]]//'`
191	CC=`echo "$CC" | sed -e 's/[[ 	]].*//'`
192	CF_ADD_CFLAGS($cf_flags)
193	;;
194*)
195	AC_MSG_RESULT(ok)
196	;;
197esac
198])dnl
199dnl ---------------------------------------------------------------------------
200dnl CF_CHECK_CACHE version: 12 updated: 2012/10/02 20:55:03
201dnl --------------
202dnl Check if we're accidentally using a cache from a different machine.
203dnl Derive the system name, as a check for reusing the autoconf cache.
204dnl
205dnl If we've packaged config.guess and config.sub, run that (since it does a
206dnl better job than uname).  Normally we'll use AC_CANONICAL_HOST, but allow
207dnl an extra parameter that we may override, e.g., for AC_CANONICAL_SYSTEM
208dnl which is useful in cross-compiles.
209dnl
210dnl Note: we would use $ac_config_sub, but that is one of the places where
211dnl autoconf 2.5x broke compatibility with autoconf 2.13
212AC_DEFUN([CF_CHECK_CACHE],
213[
214if test -f $srcdir/config.guess || test -f $ac_aux_dir/config.guess ; then
215	ifelse([$1],,[AC_CANONICAL_HOST],[$1])
216	system_name="$host_os"
217else
218	system_name="`(uname -s -r) 2>/dev/null`"
219	if test -z "$system_name" ; then
220		system_name="`(hostname) 2>/dev/null`"
221	fi
222fi
223test -n "$system_name" && AC_DEFINE_UNQUOTED(SYSTEM_NAME,"$system_name",[Define to the system name.])
224AC_CACHE_VAL(cf_cv_system_name,[cf_cv_system_name="$system_name"])
225
226test -z "$system_name" && system_name="$cf_cv_system_name"
227test -n "$cf_cv_system_name" && AC_MSG_RESULT(Configuring for $cf_cv_system_name)
228
229if test ".$system_name" != ".$cf_cv_system_name" ; then
230	AC_MSG_RESULT(Cached system name ($system_name) does not agree with actual ($cf_cv_system_name))
231	AC_MSG_ERROR("Please remove config.cache and try again.")
232fi
233])dnl
234dnl ---------------------------------------------------------------------------
235dnl CF_CLANG_COMPILER version: 2 updated: 2013/11/19 19:23:35
236dnl -----------------
237dnl Check if the given compiler is really clang.  clang's C driver defines
238dnl __GNUC__ (fooling the configure script into setting $GCC to yes) but does
239dnl not ignore some gcc options.
240dnl
241dnl This macro should be run "soon" after AC_PROG_CC or AC_PROG_CPLUSPLUS, to
242dnl ensure that it is not mistaken for gcc/g++.  It is normally invoked from
243dnl the wrappers for gcc and g++ warnings.
244dnl
245dnl $1 = GCC (default) or GXX
246dnl $2 = CLANG_COMPILER (default)
247dnl $3 = CFLAGS (default) or CXXFLAGS
248AC_DEFUN([CF_CLANG_COMPILER],[
249ifelse([$2],,CLANG_COMPILER,[$2])=no
250
251if test "$ifelse([$1],,[$1],GCC)" = yes ; then
252	AC_MSG_CHECKING(if this is really Clang ifelse([$1],GXX,C++,C) compiler)
253	cf_save_CFLAGS="$ifelse([$3],,CFLAGS,[$3])"
254	ifelse([$3],,CFLAGS,[$3])="$ifelse([$3],,CFLAGS,[$3]) -Qunused-arguments"
255	AC_TRY_COMPILE([],[
256#ifdef __clang__
257#else
258make an error
259#endif
260],[ifelse([$2],,CLANG_COMPILER,[$2])=yes
261cf_save_CFLAGS="$cf_save_CFLAGS -Qunused-arguments"
262],[])
263	ifelse([$3],,CFLAGS,[$3])="$cf_save_CFLAGS"
264	AC_MSG_RESULT($ifelse([$2],,CLANG_COMPILER,[$2]))
265fi
266])
267dnl ---------------------------------------------------------------------------
268dnl CF_DISABLE_ECHO version: 12 updated: 2012/10/06 16:30:28
269dnl ---------------
270dnl You can always use "make -n" to see the actual options, but it's hard to
271dnl pick out/analyze warning messages when the compile-line is long.
272dnl
273dnl Sets:
274dnl	ECHO_LT - symbol to control if libtool is verbose
275dnl	ECHO_LD - symbol to prefix "cc -o" lines
276dnl	RULE_CC - symbol to put before implicit "cc -c" lines (e.g., .c.o)
277dnl	SHOW_CC - symbol to put before explicit "cc -c" lines
278dnl	ECHO_CC - symbol to put before any "cc" line
279dnl
280AC_DEFUN([CF_DISABLE_ECHO],[
281AC_MSG_CHECKING(if you want to see long compiling messages)
282CF_ARG_DISABLE(echo,
283	[  --disable-echo          do not display "compiling" commands],
284	[
285    ECHO_LT='--silent'
286    ECHO_LD='@echo linking [$]@;'
287    RULE_CC='@echo compiling [$]<'
288    SHOW_CC='@echo compiling [$]@'
289    ECHO_CC='@'
290],[
291    ECHO_LT=''
292    ECHO_LD=''
293    RULE_CC=''
294    SHOW_CC=''
295    ECHO_CC=''
296])
297AC_MSG_RESULT($enableval)
298AC_SUBST(ECHO_LT)
299AC_SUBST(ECHO_LD)
300AC_SUBST(RULE_CC)
301AC_SUBST(SHOW_CC)
302AC_SUBST(ECHO_CC)
303])dnl
304dnl ---------------------------------------------------------------------------
305dnl CF_DISABLE_LEAKS version: 7 updated: 2012/10/02 20:55:03
306dnl ----------------
307dnl Combine no-leak checks with the libraries or tools that are used for the
308dnl checks.
309AC_DEFUN([CF_DISABLE_LEAKS],[
310
311AC_REQUIRE([CF_WITH_DMALLOC])
312AC_REQUIRE([CF_WITH_DBMALLOC])
313AC_REQUIRE([CF_WITH_VALGRIND])
314
315AC_MSG_CHECKING(if you want to perform memory-leak testing)
316AC_ARG_ENABLE(leaks,
317	[  --disable-leaks         test: free permanent memory, analyze leaks],
318	[if test "x$enableval" = xno; then with_no_leaks=yes; else with_no_leaks=no; fi],
319	: ${with_no_leaks:=no})
320AC_MSG_RESULT($with_no_leaks)
321
322if test "$with_no_leaks" = yes ; then
323	AC_DEFINE(NO_LEAKS,1,[Define to 1 if you want to perform memory-leak testing.])
324	AC_DEFINE(YY_NO_LEAKS,1,[Define to 1 if you want to perform memory-leak testing.])
325fi
326])dnl
327dnl ---------------------------------------------------------------------------
328dnl CF_GCC_ATTRIBUTES version: 16 updated: 2012/10/02 20:55:03
329dnl -----------------
330dnl Test for availability of useful gcc __attribute__ directives to quiet
331dnl compiler warnings.  Though useful, not all are supported -- and contrary
332dnl to documentation, unrecognized directives cause older compilers to barf.
333AC_DEFUN([CF_GCC_ATTRIBUTES],
334[
335if test "$GCC" = yes
336then
337cat > conftest.i <<EOF
338#ifndef GCC_PRINTF
339#define GCC_PRINTF 0
340#endif
341#ifndef GCC_SCANF
342#define GCC_SCANF 0
343#endif
344#ifndef GCC_NORETURN
345#define GCC_NORETURN /* nothing */
346#endif
347#ifndef GCC_UNUSED
348#define GCC_UNUSED /* nothing */
349#endif
350EOF
351if test "$GCC" = yes
352then
353	AC_CHECKING([for $CC __attribute__ directives])
354cat > conftest.$ac_ext <<EOF
355#line __oline__ "${as_me:-configure}"
356#include "confdefs.h"
357#include "conftest.h"
358#include "conftest.i"
359#if	GCC_PRINTF
360#define GCC_PRINTFLIKE(fmt,var) __attribute__((format(printf,fmt,var)))
361#else
362#define GCC_PRINTFLIKE(fmt,var) /*nothing*/
363#endif
364#if	GCC_SCANF
365#define GCC_SCANFLIKE(fmt,var)  __attribute__((format(scanf,fmt,var)))
366#else
367#define GCC_SCANFLIKE(fmt,var)  /*nothing*/
368#endif
369extern void wow(char *,...) GCC_SCANFLIKE(1,2);
370extern void oops(char *,...) GCC_PRINTFLIKE(1,2) GCC_NORETURN;
371extern void foo(void) GCC_NORETURN;
372int main(int argc GCC_UNUSED, char *argv[[]] GCC_UNUSED) { return 0; }
373EOF
374	cf_printf_attribute=no
375	cf_scanf_attribute=no
376	for cf_attribute in scanf printf unused noreturn
377	do
378		CF_UPPER(cf_ATTRIBUTE,$cf_attribute)
379		cf_directive="__attribute__(($cf_attribute))"
380		echo "checking for $CC $cf_directive" 1>&AC_FD_CC
381
382		case $cf_attribute in #(vi
383		printf) #(vi
384			cf_printf_attribute=yes
385			cat >conftest.h <<EOF
386#define GCC_$cf_ATTRIBUTE 1
387EOF
388			;;
389		scanf) #(vi
390			cf_scanf_attribute=yes
391			cat >conftest.h <<EOF
392#define GCC_$cf_ATTRIBUTE 1
393EOF
394			;;
395		*) #(vi
396			cat >conftest.h <<EOF
397#define GCC_$cf_ATTRIBUTE $cf_directive
398EOF
399			;;
400		esac
401
402		if AC_TRY_EVAL(ac_compile); then
403			test -n "$verbose" && AC_MSG_RESULT(... $cf_attribute)
404			cat conftest.h >>confdefs.h
405			case $cf_attribute in #(vi
406			noreturn) #(vi
407				AC_DEFINE_UNQUOTED(GCC_NORETURN,$cf_directive,[Define to noreturn-attribute for gcc])
408				;;
409			printf) #(vi
410				cf_value='/* nothing */'
411				if test "$cf_printf_attribute" != no ; then
412					cf_value='__attribute__((format(printf,fmt,var)))'
413					AC_DEFINE(GCC_PRINTF,1,[Define to 1 if the compiler supports gcc-like printf attribute.])
414				fi
415				AC_DEFINE_UNQUOTED(GCC_PRINTFLIKE(fmt,var),$cf_value,[Define to printf-attribute for gcc])
416				;;
417			scanf) #(vi
418				cf_value='/* nothing */'
419				if test "$cf_scanf_attribute" != no ; then
420					cf_value='__attribute__((format(scanf,fmt,var)))'
421					AC_DEFINE(GCC_SCANF,1,[Define to 1 if the compiler supports gcc-like scanf attribute.])
422				fi
423				AC_DEFINE_UNQUOTED(GCC_SCANFLIKE(fmt,var),$cf_value,[Define to sscanf-attribute for gcc])
424				;;
425			unused) #(vi
426				AC_DEFINE_UNQUOTED(GCC_UNUSED,$cf_directive,[Define to unused-attribute for gcc])
427				;;
428			esac
429		fi
430	done
431else
432	fgrep define conftest.i >>confdefs.h
433fi
434rm -rf conftest*
435fi
436])dnl
437dnl ---------------------------------------------------------------------------
438dnl CF_GCC_VERSION version: 7 updated: 2012/10/18 06:46:33
439dnl --------------
440dnl Find version of gcc
441AC_DEFUN([CF_GCC_VERSION],[
442AC_REQUIRE([AC_PROG_CC])
443GCC_VERSION=none
444if test "$GCC" = yes ; then
445	AC_MSG_CHECKING(version of $CC)
446	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.]].*//'`"
447	test -z "$GCC_VERSION" && GCC_VERSION=unknown
448	AC_MSG_RESULT($GCC_VERSION)
449fi
450])dnl
451dnl ---------------------------------------------------------------------------
452dnl CF_GCC_WARNINGS version: 31 updated: 2013/11/19 19:23:35
453dnl ---------------
454dnl Check if the compiler supports useful warning options.  There's a few that
455dnl we don't use, simply because they're too noisy:
456dnl
457dnl	-Wconversion (useful in older versions of gcc, but not in gcc 2.7.x)
458dnl	-Wredundant-decls (system headers make this too noisy)
459dnl	-Wtraditional (combines too many unrelated messages, only a few useful)
460dnl	-Wwrite-strings (too noisy, but should review occasionally).  This
461dnl		is enabled for ncurses using "--enable-const".
462dnl	-pedantic
463dnl
464dnl Parameter:
465dnl	$1 is an optional list of gcc warning flags that a particular
466dnl		application might want to use, e.g., "no-unused" for
467dnl		-Wno-unused
468dnl Special:
469dnl	If $with_ext_const is "yes", add a check for -Wwrite-strings
470dnl
471AC_DEFUN([CF_GCC_WARNINGS],
472[
473AC_REQUIRE([CF_GCC_VERSION])
474CF_INTEL_COMPILER(GCC,INTEL_COMPILER,CFLAGS)
475CF_CLANG_COMPILER(GCC,CLANG_COMPILER,CFLAGS)
476
477cat > conftest.$ac_ext <<EOF
478#line __oline__ "${as_me:-configure}"
479int main(int argc, char *argv[[]]) { return (argv[[argc-1]] == 0) ; }
480EOF
481
482if test "$INTEL_COMPILER" = yes
483then
484# The "-wdXXX" options suppress warnings:
485# remark #1419: external declaration in primary source file
486# remark #1683: explicit conversion of a 64-bit integral type to a smaller integral type (potential portability problem)
487# remark #1684: conversion from pointer to same-sized integral type (potential portability problem)
488# remark #193: zero used for undefined preprocessing identifier
489# remark #593: variable "curs_sb_left_arrow" was set but never used
490# remark #810: conversion from "int" to "Dimension={unsigned short}" may lose significant bits
491# remark #869: parameter "tw" was never referenced
492# remark #981: operands are evaluated in unspecified order
493# warning #279: controlling expression is constant
494
495	AC_CHECKING([for $CC warning options])
496	cf_save_CFLAGS="$CFLAGS"
497	EXTRA_CFLAGS="-Wall"
498	for cf_opt in \
499		wd1419 \
500		wd1683 \
501		wd1684 \
502		wd193 \
503		wd593 \
504		wd279 \
505		wd810 \
506		wd869 \
507		wd981
508	do
509		CFLAGS="$cf_save_CFLAGS $EXTRA_CFLAGS -$cf_opt"
510		if AC_TRY_EVAL(ac_compile); then
511			test -n "$verbose" && AC_MSG_RESULT(... -$cf_opt)
512			EXTRA_CFLAGS="$EXTRA_CFLAGS -$cf_opt"
513		fi
514	done
515	CFLAGS="$cf_save_CFLAGS"
516
517elif test "$GCC" = yes
518then
519	AC_CHECKING([for $CC warning options])
520	cf_save_CFLAGS="$CFLAGS"
521	EXTRA_CFLAGS=
522	cf_warn_CONST=""
523	test "$with_ext_const" = yes && cf_warn_CONST="Wwrite-strings"
524	cf_gcc_warnings="Wignored-qualifiers Wlogical-op Wvarargs"
525	test "x$CLANG_COMPILER" = xyes && cf_gcc_warnings=
526	for cf_opt in W Wall \
527		Wbad-function-cast \
528		Wcast-align \
529		Wcast-qual \
530		Wdeclaration-after-statement \
531		Wextra \
532		Winline \
533		Wmissing-declarations \
534		Wmissing-prototypes \
535		Wnested-externs \
536		Wpointer-arith \
537		Wshadow \
538		Wstrict-prototypes \
539		Wundef $cf_gcc_warnings $cf_warn_CONST $1
540	do
541		CFLAGS="$cf_save_CFLAGS $EXTRA_CFLAGS -$cf_opt"
542		if AC_TRY_EVAL(ac_compile); then
543			test -n "$verbose" && AC_MSG_RESULT(... -$cf_opt)
544			case $cf_opt in #(vi
545			Wcast-qual) #(vi
546				CPPFLAGS="$CPPFLAGS -DXTSTRINGDEFINES"
547				;;
548			Winline) #(vi
549				case $GCC_VERSION in
550				[[34]].*)
551					CF_VERBOSE(feature is broken in gcc $GCC_VERSION)
552					continue;;
553				esac
554				;;
555			Wpointer-arith) #(vi
556				case $GCC_VERSION in
557				[[12]].*)
558					CF_VERBOSE(feature is broken in gcc $GCC_VERSION)
559					continue;;
560				esac
561				;;
562			esac
563			EXTRA_CFLAGS="$EXTRA_CFLAGS -$cf_opt"
564		fi
565	done
566	CFLAGS="$cf_save_CFLAGS"
567fi
568rm -rf conftest*
569
570AC_SUBST(EXTRA_CFLAGS)
571])dnl
572dnl ---------------------------------------------------------------------------
573dnl CF_GNU_SOURCE version: 6 updated: 2005/07/09 13:23:07
574dnl -------------
575dnl Check if we must define _GNU_SOURCE to get a reasonable value for
576dnl _XOPEN_SOURCE, upon which many POSIX definitions depend.  This is a defect
577dnl (or misfeature) of glibc2, which breaks portability of many applications,
578dnl since it is interwoven with GNU extensions.
579dnl
580dnl Well, yes we could work around it...
581AC_DEFUN([CF_GNU_SOURCE],
582[
583AC_CACHE_CHECK(if we must define _GNU_SOURCE,cf_cv_gnu_source,[
584AC_TRY_COMPILE([#include <sys/types.h>],[
585#ifndef _XOPEN_SOURCE
586make an error
587#endif],
588	[cf_cv_gnu_source=no],
589	[cf_save="$CPPFLAGS"
590	 CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
591	 AC_TRY_COMPILE([#include <sys/types.h>],[
592#ifdef _XOPEN_SOURCE
593make an error
594#endif],
595	[cf_cv_gnu_source=no],
596	[cf_cv_gnu_source=yes])
597	CPPFLAGS="$cf_save"
598	])
599])
600test "$cf_cv_gnu_source" = yes && CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
601])dnl
602dnl ---------------------------------------------------------------------------
603dnl CF_INTEL_COMPILER version: 5 updated: 2013/02/10 10:41:05
604dnl -----------------
605dnl Check if the given compiler is really the Intel compiler for Linux.  It
606dnl tries to imitate gcc, but does not return an error when it finds a mismatch
607dnl between prototypes, e.g., as exercised by CF_MISSING_CHECK.
608dnl
609dnl This macro should be run "soon" after AC_PROG_CC or AC_PROG_CPLUSPLUS, to
610dnl ensure that it is not mistaken for gcc/g++.  It is normally invoked from
611dnl the wrappers for gcc and g++ warnings.
612dnl
613dnl $1 = GCC (default) or GXX
614dnl $2 = INTEL_COMPILER (default) or INTEL_CPLUSPLUS
615dnl $3 = CFLAGS (default) or CXXFLAGS
616AC_DEFUN([CF_INTEL_COMPILER],[
617AC_REQUIRE([AC_CANONICAL_HOST])
618ifelse([$2],,INTEL_COMPILER,[$2])=no
619
620if test "$ifelse([$1],,[$1],GCC)" = yes ; then
621	case $host_os in
622	linux*|gnu*)
623		AC_MSG_CHECKING(if this is really Intel ifelse([$1],GXX,C++,C) compiler)
624		cf_save_CFLAGS="$ifelse([$3],,CFLAGS,[$3])"
625		ifelse([$3],,CFLAGS,[$3])="$ifelse([$3],,CFLAGS,[$3]) -no-gcc"
626		AC_TRY_COMPILE([],[
627#ifdef __INTEL_COMPILER
628#else
629make an error
630#endif
631],[ifelse([$2],,INTEL_COMPILER,[$2])=yes
632cf_save_CFLAGS="$cf_save_CFLAGS -we147 -no-gcc"
633],[])
634		ifelse([$3],,CFLAGS,[$3])="$cf_save_CFLAGS"
635		AC_MSG_RESULT($ifelse([$2],,INTEL_COMPILER,[$2]))
636		;;
637	esac
638fi
639])dnl
640dnl ---------------------------------------------------------------------------
641dnl CF_MAKE_DOCS version: 2 updated: 2013/01/02 20:04:08
642dnl ------------
643dnl $1 = name(s) to generate rules for
644dnl $2 = suffix of corresponding manpages used as input.
645define([CF_MAKE_DOCS],[
646test -z "$cf_make_docs" && cf_make_docs=0
647
648cf_output=makefile
649test -f "$cf_output" || cf_output=Makefile
650
651if test "$cf_make_docs" = 0
652then
653cat >>$cf_output <<"CF_EOF"
654################################################################################
655.SUFFIXES : .html .$2 .man .ps .pdf .txt
656
657.$2.html :
658	GROFF_NO_SGR=stupid [$](SHELL) -c "tbl [$]*.$2 | groff -P -o0 -I$*_ -Thtml -man" >[$]@
659
660.$2.ps :
661	[$](SHELL) -c "tbl [$]*.$2 | groff -man" >[$]@
662
663.$2.txt :
664	GROFF_NO_SGR=stupid [$](SHELL) -c "tbl [$]*.$2 | nroff -Tascii -man | col -bx" >[$]@
665
666.ps.pdf :
667	ps2pdf [$]*.ps
668
669CF_EOF
670	cf_make_docs=1
671fi
672
673for cf_name in $1
674do
675cat >>$cf_output <<CF_EOF
676################################################################################
677docs-$cf_name \\
678docs :: $cf_name.html \\
679	$cf_name.pdf \\
680	$cf_name.ps \\
681	$cf_name.txt
682
683clean \\
684docs-clean ::
685	rm -f $cf_name.html $cf_name.pdf $cf_name.ps $cf_name.txt
686
687$cf_name.html : $cf_name.$2
688$cf_name.pdf : $cf_name.ps
689$cf_name.ps : $cf_name.$2
690$cf_name.txt : $cf_name.$2
691CF_EOF
692done
693])dnl
694dnl ---------------------------------------------------------------------------
695dnl CF_MAKE_TAGS version: 6 updated: 2010/10/23 15:52:32
696dnl ------------
697dnl Generate tags/TAGS targets for makefiles.  Do not generate TAGS if we have
698dnl a monocase filesystem.
699AC_DEFUN([CF_MAKE_TAGS],[
700AC_REQUIRE([CF_MIXEDCASE_FILENAMES])
701
702AC_CHECK_PROGS(CTAGS, exctags ctags)
703AC_CHECK_PROGS(ETAGS, exetags etags)
704
705AC_CHECK_PROG(MAKE_LOWER_TAGS, ${CTAGS:-ctags}, yes, no)
706
707if test "$cf_cv_mixedcase" = yes ; then
708	AC_CHECK_PROG(MAKE_UPPER_TAGS, ${ETAGS:-etags}, yes, no)
709else
710	MAKE_UPPER_TAGS=no
711fi
712
713if test "$MAKE_UPPER_TAGS" = yes ; then
714	MAKE_UPPER_TAGS=
715else
716	MAKE_UPPER_TAGS="#"
717fi
718
719if test "$MAKE_LOWER_TAGS" = yes ; then
720	MAKE_LOWER_TAGS=
721else
722	MAKE_LOWER_TAGS="#"
723fi
724
725AC_SUBST(CTAGS)
726AC_SUBST(ETAGS)
727
728AC_SUBST(MAKE_UPPER_TAGS)
729AC_SUBST(MAKE_LOWER_TAGS)
730])dnl
731dnl ---------------------------------------------------------------------------
732dnl CF_MIXEDCASE_FILENAMES version: 6 updated: 2013/10/08 17:47:05
733dnl ----------------------
734dnl Check if the file-system supports mixed-case filenames.  If we're able to
735dnl create a lowercase name and see it as uppercase, it doesn't support that.
736AC_DEFUN([CF_MIXEDCASE_FILENAMES],
737[
738AC_CACHE_CHECK(if filesystem supports mixed-case filenames,cf_cv_mixedcase,[
739if test "$cross_compiling" = yes ; then
740	case $target_alias in #(vi
741	*-os2-emx*|*-msdosdjgpp*|*-cygwin*|*-msys*|*-mingw*|*-uwin*) #(vi
742		cf_cv_mixedcase=no
743		;;
744	*)
745		cf_cv_mixedcase=yes
746		;;
747	esac
748else
749	rm -f conftest CONFTEST
750	echo test >conftest
751	if test -f CONFTEST ; then
752		cf_cv_mixedcase=no
753	else
754		cf_cv_mixedcase=yes
755	fi
756	rm -f conftest CONFTEST
757fi
758])
759test "$cf_cv_mixedcase" = yes && AC_DEFINE(MIXEDCASE_FILENAMES,1,[Define to 1 if filesystem supports mixed-case filenames.])
760])dnl
761dnl ---------------------------------------------------------------------------
762dnl CF_MKSTEMP version: 9 updated: 2012/10/03 04:34:49
763dnl ----------
764dnl Check for a working mkstemp.  This creates two files, checks that they are
765dnl successfully created and distinct (AmigaOS apparently fails on the last).
766AC_DEFUN([CF_MKSTEMP],[
767AC_CACHE_CHECK(for working mkstemp, cf_cv_func_mkstemp,[
768rm -rf conftest*
769AC_TRY_RUN([
770#include <sys/types.h>
771#include <stdlib.h>
772#include <stdio.h>
773#include <string.h>
774#include <sys/stat.h>
775int main()
776{
777	char *tmpl = "conftestXXXXXX";
778	char name[2][80];
779	int n;
780	int result = 0;
781	int fd;
782	struct stat sb;
783
784	umask(077);
785	for (n = 0; n < 2; ++n) {
786		strcpy(name[n], tmpl);
787		if ((fd = mkstemp(name[n])) >= 0) {
788			if (!strcmp(name[n], tmpl)
789			 || stat(name[n], &sb) != 0
790			 || (sb.st_mode & S_IFMT) != S_IFREG
791			 || (sb.st_mode & 077) != 0) {
792				result = 1;
793			}
794			close(fd);
795		}
796	}
797	if (result == 0
798	 && !strcmp(name[0], name[1]))
799		result = 1;
800	${cf_cv_main_return:-return}(result);
801}
802],[cf_cv_func_mkstemp=yes
803],[cf_cv_func_mkstemp=no
804],[cf_cv_func_mkstemp=maybe])
805])
806if test "x$cf_cv_func_mkstemp" = xmaybe ; then
807	AC_CHECK_FUNC(mkstemp)
808fi
809if test "x$cf_cv_func_mkstemp" = xyes || test "x$ac_cv_func_mkstemp" = xyes ; then
810	AC_DEFINE(HAVE_MKSTEMP,1,[Define to 1 if mkstemp() is available and working.])
811fi
812])dnl
813dnl ---------------------------------------------------------------------------
814dnl CF_MSG_LOG version: 5 updated: 2010/10/23 15:52:32
815dnl ----------
816dnl Write a debug message to config.log, along with the line number in the
817dnl configure script.
818AC_DEFUN([CF_MSG_LOG],[
819echo "${as_me:-configure}:__oline__: testing $* ..." 1>&AC_FD_CC
820])dnl
821dnl ---------------------------------------------------------------------------
822dnl CF_NO_LEAKS_OPTION version: 5 updated: 2012/10/02 20:55:03
823dnl ------------------
824dnl see CF_WITH_NO_LEAKS
825AC_DEFUN([CF_NO_LEAKS_OPTION],[
826AC_MSG_CHECKING(if you want to use $1 for testing)
827AC_ARG_WITH($1,
828	[$2],
829	[AC_DEFINE_UNQUOTED($3,1,"Define to 1 if you want to use $1 for testing.")ifelse([$4],,[
830	 $4
831])
832	: ${with_cflags:=-g}
833	: ${with_no_leaks:=yes}
834	 with_$1=yes],
835	[with_$1=])
836AC_MSG_RESULT(${with_$1:-no})
837
838case .$with_cflags in #(vi
839.*-g*)
840	case .$CFLAGS in #(vi
841	.*-g*) #(vi
842		;;
843	*)
844		CF_ADD_CFLAGS([-g])
845		;;
846	esac
847	;;
848esac
849])dnl
850dnl ---------------------------------------------------------------------------
851dnl CF_POSIX_C_SOURCE version: 8 updated: 2010/05/26 05:38:42
852dnl -----------------
853dnl Define _POSIX_C_SOURCE to the given level, and _POSIX_SOURCE if needed.
854dnl
855dnl	POSIX.1-1990				_POSIX_SOURCE
856dnl	POSIX.1-1990 and			_POSIX_SOURCE and
857dnl		POSIX.2-1992 C-Language			_POSIX_C_SOURCE=2
858dnl		Bindings Option
859dnl	POSIX.1b-1993				_POSIX_C_SOURCE=199309L
860dnl	POSIX.1c-1996				_POSIX_C_SOURCE=199506L
861dnl	X/Open 2000				_POSIX_C_SOURCE=200112L
862dnl
863dnl Parameters:
864dnl	$1 is the nominal value for _POSIX_C_SOURCE
865AC_DEFUN([CF_POSIX_C_SOURCE],
866[
867cf_POSIX_C_SOURCE=ifelse([$1],,199506L,[$1])
868
869cf_save_CFLAGS="$CFLAGS"
870cf_save_CPPFLAGS="$CPPFLAGS"
871
872CF_REMOVE_DEFINE(cf_trim_CFLAGS,$cf_save_CFLAGS,_POSIX_C_SOURCE)
873CF_REMOVE_DEFINE(cf_trim_CPPFLAGS,$cf_save_CPPFLAGS,_POSIX_C_SOURCE)
874
875AC_CACHE_CHECK(if we should define _POSIX_C_SOURCE,cf_cv_posix_c_source,[
876	CF_MSG_LOG(if the symbol is already defined go no further)
877	AC_TRY_COMPILE([#include <sys/types.h>],[
878#ifndef _POSIX_C_SOURCE
879make an error
880#endif],
881	[cf_cv_posix_c_source=no],
882	[cf_want_posix_source=no
883	 case .$cf_POSIX_C_SOURCE in #(vi
884	 .[[12]]??*) #(vi
885		cf_cv_posix_c_source="-D_POSIX_C_SOURCE=$cf_POSIX_C_SOURCE"
886		;;
887	 .2) #(vi
888		cf_cv_posix_c_source="-D_POSIX_C_SOURCE=$cf_POSIX_C_SOURCE"
889		cf_want_posix_source=yes
890		;;
891	 .*)
892		cf_want_posix_source=yes
893		;;
894	 esac
895	 if test "$cf_want_posix_source" = yes ; then
896		AC_TRY_COMPILE([#include <sys/types.h>],[
897#ifdef _POSIX_SOURCE
898make an error
899#endif],[],
900		cf_cv_posix_c_source="$cf_cv_posix_c_source -D_POSIX_SOURCE")
901	 fi
902	 CF_MSG_LOG(ifdef from value $cf_POSIX_C_SOURCE)
903	 CFLAGS="$cf_trim_CFLAGS"
904	 CPPFLAGS="$cf_trim_CPPFLAGS $cf_cv_posix_c_source"
905	 CF_MSG_LOG(if the second compile does not leave our definition intact error)
906	 AC_TRY_COMPILE([#include <sys/types.h>],[
907#ifndef _POSIX_C_SOURCE
908make an error
909#endif],,
910	 [cf_cv_posix_c_source=no])
911	 CFLAGS="$cf_save_CFLAGS"
912	 CPPFLAGS="$cf_save_CPPFLAGS"
913	])
914])
915
916if test "$cf_cv_posix_c_source" != no ; then
917	CFLAGS="$cf_trim_CFLAGS"
918	CPPFLAGS="$cf_trim_CPPFLAGS"
919	CF_ADD_CFLAGS($cf_cv_posix_c_source)
920fi
921
922])dnl
923dnl ---------------------------------------------------------------------------
924dnl CF_PROG_CC version: 3 updated: 2012/10/06 15:31:55
925dnl ----------
926dnl standard check for CC, plus followup sanity checks
927dnl $1 = optional parameter to pass to AC_PROG_CC to specify compiler name
928AC_DEFUN([CF_PROG_CC],[
929ifelse($1,,[AC_PROG_CC],[AC_PROG_CC($1)])
930CF_GCC_VERSION
931CF_ACVERSION_CHECK(2.52,
932	[AC_PROG_CC_STDC],
933	[CF_ANSI_CC_REQD])
934CF_CC_ENV_FLAGS
935])dnl
936dnl ---------------------------------------------------------------------------
937dnl CF_PROG_LINT version: 2 updated: 2009/08/12 04:43:14
938dnl ------------
939AC_DEFUN([CF_PROG_LINT],
940[
941AC_CHECK_PROGS(LINT, tdlint lint alint splint lclint)
942AC_SUBST(LINT_OPTS)
943])dnl
944dnl ---------------------------------------------------------------------------
945dnl CF_REMOVE_DEFINE version: 3 updated: 2010/01/09 11:05:50
946dnl ----------------
947dnl Remove all -U and -D options that refer to the given symbol from a list
948dnl of C compiler options.  This works around the problem that not all
949dnl compilers process -U and -D options from left-to-right, so a -U option
950dnl cannot be used to cancel the effect of a preceding -D option.
951dnl
952dnl $1 = target (which could be the same as the source variable)
953dnl $2 = source (including '$')
954dnl $3 = symbol to remove
955define([CF_REMOVE_DEFINE],
956[
957$1=`echo "$2" | \
958	sed	-e 's/-[[UD]]'"$3"'\(=[[^ 	]]*\)\?[[ 	]]/ /g' \
959		-e 's/-[[UD]]'"$3"'\(=[[^ 	]]*\)\?[$]//g'`
960])dnl
961dnl ---------------------------------------------------------------------------
962dnl CF_TRY_XOPEN_SOURCE version: 1 updated: 2011/10/30 17:09:50
963dnl -------------------
964dnl If _XOPEN_SOURCE is not defined in the compile environment, check if we
965dnl can define it successfully.
966AC_DEFUN([CF_TRY_XOPEN_SOURCE],[
967AC_CACHE_CHECK(if we should define _XOPEN_SOURCE,cf_cv_xopen_source,[
968	AC_TRY_COMPILE([
969#include <stdlib.h>
970#include <string.h>
971#include <sys/types.h>
972],[
973#ifndef _XOPEN_SOURCE
974make an error
975#endif],
976	[cf_cv_xopen_source=no],
977	[cf_save="$CPPFLAGS"
978	 CPPFLAGS="$CPPFLAGS -D_XOPEN_SOURCE=$cf_XOPEN_SOURCE"
979	 AC_TRY_COMPILE([
980#include <stdlib.h>
981#include <string.h>
982#include <sys/types.h>
983],[
984#ifdef _XOPEN_SOURCE
985make an error
986#endif],
987	[cf_cv_xopen_source=no],
988	[cf_cv_xopen_source=$cf_XOPEN_SOURCE])
989	CPPFLAGS="$cf_save"
990	])
991])
992
993if test "$cf_cv_xopen_source" != no ; then
994	CF_REMOVE_DEFINE(CFLAGS,$CFLAGS,_XOPEN_SOURCE)
995	CF_REMOVE_DEFINE(CPPFLAGS,$CPPFLAGS,_XOPEN_SOURCE)
996	cf_temp_xopen_source="-D_XOPEN_SOURCE=$cf_cv_xopen_source"
997	CF_ADD_CFLAGS($cf_temp_xopen_source)
998fi
999])
1000dnl ---------------------------------------------------------------------------
1001dnl CF_UPPER version: 5 updated: 2001/01/29 23:40:59
1002dnl --------
1003dnl Make an uppercase version of a variable
1004dnl $1=uppercase($2)
1005AC_DEFUN([CF_UPPER],
1006[
1007$1=`echo "$2" | sed y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%`
1008])dnl
1009dnl ---------------------------------------------------------------------------
1010dnl CF_VERBOSE version: 3 updated: 2007/07/29 09:55:12
1011dnl ----------
1012dnl Use AC_VERBOSE w/o the warnings
1013AC_DEFUN([CF_VERBOSE],
1014[test -n "$verbose" && echo "	$1" 1>&AC_FD_MSG
1015CF_MSG_LOG([$1])
1016])dnl
1017dnl ---------------------------------------------------------------------------
1018dnl CF_WITH_DBMALLOC version: 7 updated: 2010/06/21 17:26:47
1019dnl ----------------
1020dnl Configure-option for dbmalloc.  The optional parameter is used to override
1021dnl the updating of $LIBS, e.g., to avoid conflict with subsequent tests.
1022AC_DEFUN([CF_WITH_DBMALLOC],[
1023CF_NO_LEAKS_OPTION(dbmalloc,
1024	[  --with-dbmalloc         test: use Conor Cahill's dbmalloc library],
1025	[USE_DBMALLOC])
1026
1027if test "$with_dbmalloc" = yes ; then
1028	AC_CHECK_HEADER(dbmalloc.h,
1029		[AC_CHECK_LIB(dbmalloc,[debug_malloc]ifelse([$1],,[],[,$1]))])
1030fi
1031])dnl
1032dnl ---------------------------------------------------------------------------
1033dnl CF_WITH_DMALLOC version: 7 updated: 2010/06/21 17:26:47
1034dnl ---------------
1035dnl Configure-option for dmalloc.  The optional parameter is used to override
1036dnl the updating of $LIBS, e.g., to avoid conflict with subsequent tests.
1037AC_DEFUN([CF_WITH_DMALLOC],[
1038CF_NO_LEAKS_OPTION(dmalloc,
1039	[  --with-dmalloc          test: use Gray Watson's dmalloc library],
1040	[USE_DMALLOC])
1041
1042if test "$with_dmalloc" = yes ; then
1043	AC_CHECK_HEADER(dmalloc.h,
1044		[AC_CHECK_LIB(dmalloc,[dmalloc_debug]ifelse([$1],,[],[,$1]))])
1045fi
1046])dnl
1047dnl ---------------------------------------------------------------------------
1048dnl CF_WITH_VALGRIND version: 1 updated: 2006/12/14 18:00:21
1049dnl ----------------
1050AC_DEFUN([CF_WITH_VALGRIND],[
1051CF_NO_LEAKS_OPTION(valgrind,
1052	[  --with-valgrind         test: use valgrind],
1053	[USE_VALGRIND])
1054])dnl
1055dnl ---------------------------------------------------------------------------
1056dnl CF_WITH_WARNINGS version: 5 updated: 2004/07/23 14:40:34
1057dnl ----------------
1058dnl Combine the checks for gcc features into a configure-script option
1059dnl
1060dnl Parameters:
1061dnl	$1 - see CF_GCC_WARNINGS
1062AC_DEFUN([CF_WITH_WARNINGS],
1063[
1064if ( test "$GCC" = yes || test "$GXX" = yes )
1065then
1066AC_MSG_CHECKING(if you want to check for gcc warnings)
1067AC_ARG_WITH(warnings,
1068	[  --with-warnings         test: turn on gcc warnings],
1069	[cf_opt_with_warnings=$withval],
1070	[cf_opt_with_warnings=no])
1071AC_MSG_RESULT($cf_opt_with_warnings)
1072if test "$cf_opt_with_warnings" != no ; then
1073	CF_GCC_ATTRIBUTES
1074	CF_GCC_WARNINGS([$1])
1075fi
1076fi
1077])dnl
1078dnl ---------------------------------------------------------------------------
1079dnl CF_XOPEN_SOURCE version: 45 updated: 2013/09/07 14:06:25
1080dnl ---------------
1081dnl Try to get _XOPEN_SOURCE defined properly that we can use POSIX functions,
1082dnl or adapt to the vendor's definitions to get equivalent functionality,
1083dnl without losing the common non-POSIX features.
1084dnl
1085dnl Parameters:
1086dnl	$1 is the nominal value for _XOPEN_SOURCE
1087dnl	$2 is the nominal value for _POSIX_C_SOURCE
1088AC_DEFUN([CF_XOPEN_SOURCE],[
1089AC_REQUIRE([AC_CANONICAL_HOST])
1090
1091cf_XOPEN_SOURCE=ifelse([$1],,500,[$1])
1092cf_POSIX_C_SOURCE=ifelse([$2],,199506L,[$2])
1093cf_xopen_source=
1094
1095case $host_os in #(vi
1096aix[[4-7]]*) #(vi
1097	cf_xopen_source="-D_ALL_SOURCE"
1098	;;
1099cygwin|msys) #(vi
1100	cf_XOPEN_SOURCE=600
1101	;;
1102darwin[[0-8]].*) #(vi
1103	cf_xopen_source="-D_APPLE_C_SOURCE"
1104	;;
1105darwin*) #(vi
1106	cf_xopen_source="-D_DARWIN_C_SOURCE"
1107	cf_XOPEN_SOURCE=
1108	;;
1109freebsd*|dragonfly*) #(vi
1110	# 5.x headers associate
1111	#	_XOPEN_SOURCE=600 with _POSIX_C_SOURCE=200112L
1112	#	_XOPEN_SOURCE=500 with _POSIX_C_SOURCE=199506L
1113	cf_POSIX_C_SOURCE=200112L
1114	cf_XOPEN_SOURCE=600
1115	cf_xopen_source="-D_BSD_TYPES -D__BSD_VISIBLE -D_POSIX_C_SOURCE=$cf_POSIX_C_SOURCE -D_XOPEN_SOURCE=$cf_XOPEN_SOURCE"
1116	;;
1117hpux11*) #(vi
1118	cf_xopen_source="-D_HPUX_SOURCE -D_XOPEN_SOURCE=500"
1119	;;
1120hpux*) #(vi
1121	cf_xopen_source="-D_HPUX_SOURCE"
1122	;;
1123irix[[56]].*) #(vi
1124	cf_xopen_source="-D_SGI_SOURCE"
1125	cf_XOPEN_SOURCE=
1126	;;
1127linux*|gnu*|mint*|k*bsd*-gnu) #(vi
1128	CF_GNU_SOURCE
1129	;;
1130mirbsd*) #(vi
1131	# setting _XOPEN_SOURCE or _POSIX_SOURCE breaks <sys/select.h> and other headers which use u_int / u_short types
1132	cf_XOPEN_SOURCE=
1133	CF_POSIX_C_SOURCE($cf_POSIX_C_SOURCE)
1134	;;
1135netbsd*) #(vi
1136	cf_xopen_source="-D_NETBSD_SOURCE" # setting _XOPEN_SOURCE breaks IPv6 for lynx on NetBSD 1.6, breaks xterm, is not needed for ncursesw
1137	;;
1138openbsd[[4-9]]*) #(vi
1139	# setting _XOPEN_SOURCE lower than 500 breaks g++ compile with wchar.h, needed for ncursesw
1140	cf_xopen_source="-D_BSD_SOURCE"
1141	cf_XOPEN_SOURCE=600
1142	;;
1143openbsd*) #(vi
1144	# setting _XOPEN_SOURCE breaks xterm on OpenBSD 2.8, is not needed for ncursesw
1145	;;
1146osf[[45]]*) #(vi
1147	cf_xopen_source="-D_OSF_SOURCE"
1148	;;
1149nto-qnx*) #(vi
1150	cf_xopen_source="-D_QNX_SOURCE"
1151	;;
1152sco*) #(vi
1153	# setting _XOPEN_SOURCE breaks Lynx on SCO Unix / OpenServer
1154	;;
1155solaris2.*) #(vi
1156	cf_xopen_source="-D__EXTENSIONS__"
1157	;;
1158*)
1159	CF_TRY_XOPEN_SOURCE
1160	CF_POSIX_C_SOURCE($cf_POSIX_C_SOURCE)
1161	;;
1162esac
1163
1164if test -n "$cf_xopen_source" ; then
1165	CF_ADD_CFLAGS($cf_xopen_source)
1166fi
1167
1168dnl In anything but the default case, we may have system-specific setting
1169dnl which is still not guaranteed to provide all of the entrypoints that
1170dnl _XOPEN_SOURCE would yield.
1171if test -n "$cf_XOPEN_SOURCE" && test -z "$cf_cv_xopen_source" ; then
1172	AC_MSG_CHECKING(if _XOPEN_SOURCE really is set)
1173	AC_TRY_COMPILE([#include <stdlib.h>],[
1174#ifndef _XOPEN_SOURCE
1175make an error
1176#endif],
1177	[cf_XOPEN_SOURCE_set=yes],
1178	[cf_XOPEN_SOURCE_set=no])
1179	AC_MSG_RESULT($cf_XOPEN_SOURCE_set)
1180	if test $cf_XOPEN_SOURCE_set = yes
1181	then
1182		AC_TRY_COMPILE([#include <stdlib.h>],[
1183#if (_XOPEN_SOURCE - 0) < $cf_XOPEN_SOURCE
1184make an error
1185#endif],
1186		[cf_XOPEN_SOURCE_set_ok=yes],
1187		[cf_XOPEN_SOURCE_set_ok=no])
1188		if test $cf_XOPEN_SOURCE_set_ok = no
1189		then
1190			AC_MSG_WARN(_XOPEN_SOURCE is lower than requested)
1191		fi
1192	else
1193		CF_TRY_XOPEN_SOURCE
1194	fi
1195fi
1196])
1197