1251143Sbaptdnl $Id: aclocal.m4,v 1.30 2013/03/05 01:13:39 tom Exp $
2234949Sbaptdnl Macros for byacc configure script (Thomas E. Dickey)
3234949Sbaptdnl ---------------------------------------------------------------------------
4251143Sbaptdnl Copyright 2004-2012,2013 Thomas E. Dickey
5234949Sbaptdnl 
6234949Sbaptdnl Permission is hereby granted, free of charge, to any person obtaining a
7234949Sbaptdnl copy of this software and associated documentation files (the
8234949Sbaptdnl "Software"), to deal in the Software without restriction, including
9234949Sbaptdnl without limitation the rights to use, copy, modify, merge, publish,
10234949Sbaptdnl distribute, distribute with modifications, sublicense, and/or sell
11234949Sbaptdnl copies of the Software, and to permit persons to whom the Software is
12234949Sbaptdnl furnished to do so, subject to the following conditions:
13234949Sbaptdnl 
14234949Sbaptdnl The above copyright notice and this permission notice shall be included
15234949Sbaptdnl in all copies or portions of the Software.
16234949Sbaptdnl 
17234949Sbaptdnl THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18234949Sbaptdnl OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19234949Sbaptdnl MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20234949Sbaptdnl IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
21234949Sbaptdnl DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22234949Sbaptdnl OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
23234949Sbaptdnl THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24234949Sbaptdnl 
25234949Sbaptdnl Except as contained in this notice, the name(s) of the above copyright
26234949Sbaptdnl holders shall not be used in advertising or otherwise to promote the
27234949Sbaptdnl sale, use or other dealings in this Software without prior written
28234949Sbaptdnl authorization.
29234949Sbaptdnl ---------------------------------------------------------------------------
30234949Sbaptdnl ---------------------------------------------------------------------------
31251143Sbaptdnl CF_ACVERSION_CHECK version: 4 updated: 2013/03/04 19:52:56
32251143Sbaptdnl ------------------
33251143Sbaptdnl Conditionally generate script according to whether we're using a given autoconf.
34251143Sbaptdnl
35251143Sbaptdnl $1 = version to compare against
36251143Sbaptdnl $2 = code to use if AC_ACVERSION is at least as high as $1.
37251143Sbaptdnl $3 = code to use if AC_ACVERSION is older than $1.
38251143Sbaptdefine([CF_ACVERSION_CHECK],
39251143Sbapt[
40251143Sbaptifdef([AC_ACVERSION], ,[m4_copy([m4_PACKAGE_VERSION],[AC_ACVERSION])])dnl
41251143Sbaptifdef([m4_version_compare],
42251143Sbapt[m4_if(m4_version_compare(m4_defn([AC_ACVERSION]), [$1]), -1, [$3], [$2])],
43251143Sbapt[CF_ACVERSION_COMPARE(
44251143SbaptAC_PREREQ_CANON(AC_PREREQ_SPLIT([$1])),
45251143SbaptAC_PREREQ_CANON(AC_PREREQ_SPLIT(AC_ACVERSION)), AC_ACVERSION, [$2], [$3])])])dnl
46251143Sbaptdnl ---------------------------------------------------------------------------
47251143Sbaptdnl CF_ACVERSION_COMPARE version: 3 updated: 2012/10/03 18:39:53
48251143Sbaptdnl --------------------
49251143Sbaptdnl CF_ACVERSION_COMPARE(MAJOR1, MINOR1, TERNARY1,
50251143Sbaptdnl                      MAJOR2, MINOR2, TERNARY2,
51251143Sbaptdnl                      PRINTABLE2, not FOUND, FOUND)
52251143Sbaptdefine([CF_ACVERSION_COMPARE],
53251143Sbapt[ifelse(builtin([eval], [$2 < $5]), 1,
54251143Sbapt[ifelse([$8], , ,[$8])],
55251143Sbapt[ifelse([$9], , ,[$9])])])dnl
56251143Sbaptdnl ---------------------------------------------------------------------------
57234949Sbaptdnl CF_ADD_CFLAGS version: 10 updated: 2010/05/26 05:38:42
58234949Sbaptdnl -------------
59234949Sbaptdnl Copy non-preprocessor flags to $CFLAGS, preprocessor flags to $CPPFLAGS
60234949Sbaptdnl The second parameter if given makes this macro verbose.
61234949Sbaptdnl
62234949Sbaptdnl Put any preprocessor definitions that use quoted strings in $EXTRA_CPPFLAGS,
63234949Sbaptdnl to simplify use of $CPPFLAGS in compiler checks, etc., that are easily
64234949Sbaptdnl confused by the quotes (which require backslashes to keep them usable).
65234949SbaptAC_DEFUN([CF_ADD_CFLAGS],
66234949Sbapt[
67234949Sbaptcf_fix_cppflags=no
68234949Sbaptcf_new_cflags=
69234949Sbaptcf_new_cppflags=
70234949Sbaptcf_new_extra_cppflags=
71234949Sbapt
72234949Sbaptfor cf_add_cflags in $1
73234949Sbaptdo
74234949Sbaptcase $cf_fix_cppflags in
75234949Sbaptno)
76234949Sbapt	case $cf_add_cflags in #(vi
77234949Sbapt	-undef|-nostdinc*|-I*|-D*|-U*|-E|-P|-C) #(vi
78234949Sbapt		case $cf_add_cflags in
79234949Sbapt		-D*)
80234949Sbapt			cf_tst_cflags=`echo ${cf_add_cflags} |sed -e 's/^-D[[^=]]*='\''\"[[^"]]*//'`
81234949Sbapt
82234949Sbapt			test "${cf_add_cflags}" != "${cf_tst_cflags}" \
83234949Sbapt				&& test -z "${cf_tst_cflags}" \
84234949Sbapt				&& cf_fix_cppflags=yes
85234949Sbapt
86234949Sbapt			if test $cf_fix_cppflags = yes ; then
87234949Sbapt				cf_new_extra_cppflags="$cf_new_extra_cppflags $cf_add_cflags"
88234949Sbapt				continue
89234949Sbapt			elif test "${cf_tst_cflags}" = "\"'" ; then
90234949Sbapt				cf_new_extra_cppflags="$cf_new_extra_cppflags $cf_add_cflags"
91234949Sbapt				continue
92234949Sbapt			fi
93234949Sbapt			;;
94234949Sbapt		esac
95234949Sbapt		case "$CPPFLAGS" in
96234949Sbapt		*$cf_add_cflags) #(vi
97234949Sbapt			;;
98234949Sbapt		*) #(vi
99234949Sbapt			case $cf_add_cflags in #(vi
100234949Sbapt			-D*)
101234949Sbapt				cf_tst_cppflags=`echo "x$cf_add_cflags" | sed -e 's/^...//' -e 's/=.*//'`
102234949Sbapt				CF_REMOVE_DEFINE(CPPFLAGS,$CPPFLAGS,$cf_tst_cppflags)
103234949Sbapt				;;
104234949Sbapt			esac
105234949Sbapt			cf_new_cppflags="$cf_new_cppflags $cf_add_cflags"
106234949Sbapt			;;
107234949Sbapt		esac
108234949Sbapt		;;
109234949Sbapt	*)
110234949Sbapt		cf_new_cflags="$cf_new_cflags $cf_add_cflags"
111234949Sbapt		;;
112234949Sbapt	esac
113234949Sbapt	;;
114234949Sbaptyes)
115234949Sbapt	cf_new_extra_cppflags="$cf_new_extra_cppflags $cf_add_cflags"
116234949Sbapt
117234949Sbapt	cf_tst_cflags=`echo ${cf_add_cflags} |sed -e 's/^[[^"]]*"'\''//'`
118234949Sbapt
119234949Sbapt	test "${cf_add_cflags}" != "${cf_tst_cflags}" \
120234949Sbapt		&& test -z "${cf_tst_cflags}" \
121234949Sbapt		&& cf_fix_cppflags=no
122234949Sbapt	;;
123234949Sbaptesac
124234949Sbaptdone
125234949Sbapt
126234949Sbaptif test -n "$cf_new_cflags" ; then
127234949Sbapt	ifelse([$2],,,[CF_VERBOSE(add to \$CFLAGS $cf_new_cflags)])
128234949Sbapt	CFLAGS="$CFLAGS $cf_new_cflags"
129234949Sbaptfi
130234949Sbapt
131234949Sbaptif test -n "$cf_new_cppflags" ; then
132234949Sbapt	ifelse([$2],,,[CF_VERBOSE(add to \$CPPFLAGS $cf_new_cppflags)])
133234949Sbapt	CPPFLAGS="$CPPFLAGS $cf_new_cppflags"
134234949Sbaptfi
135234949Sbapt
136234949Sbaptif test -n "$cf_new_extra_cppflags" ; then
137234949Sbapt	ifelse([$2],,,[CF_VERBOSE(add to \$EXTRA_CPPFLAGS $cf_new_extra_cppflags)])
138234949Sbapt	EXTRA_CPPFLAGS="$cf_new_extra_cppflags $EXTRA_CPPFLAGS"
139234949Sbaptfi
140234949Sbapt
141234949SbaptAC_SUBST(EXTRA_CPPFLAGS)
142234949Sbapt
143234949Sbapt])dnl
144234949Sbaptdnl ---------------------------------------------------------------------------
145234949Sbaptdnl CF_ARG_DISABLE version: 3 updated: 1999/03/30 17:24:31
146234949Sbaptdnl --------------
147234949Sbaptdnl Allow user to disable a normally-on option.
148234949SbaptAC_DEFUN([CF_ARG_DISABLE],
149234949Sbapt[CF_ARG_OPTION($1,[$2],[$3],[$4],yes)])dnl
150234949Sbaptdnl ---------------------------------------------------------------------------
151234949Sbaptdnl CF_ARG_OPTION version: 4 updated: 2010/05/26 05:38:42
152234949Sbaptdnl -------------
153234949Sbaptdnl Restricted form of AC_ARG_ENABLE that ensures user doesn't give bogus
154234949Sbaptdnl values.
155234949Sbaptdnl
156234949Sbaptdnl Parameters:
157234949Sbaptdnl $1 = option name
158234949Sbaptdnl $2 = help-string
159234949Sbaptdnl $3 = action to perform if option is not default
160234949Sbaptdnl $4 = action if perform if option is default
161234949Sbaptdnl $5 = default option value (either 'yes' or 'no')
162234949SbaptAC_DEFUN([CF_ARG_OPTION],
163234949Sbapt[AC_ARG_ENABLE([$1],[$2],[test "$enableval" != ifelse([$5],no,yes,no) && enableval=ifelse([$5],no,no,yes)
164234949Sbapt  if test "$enableval" != "$5" ; then
165234949Sbaptifelse([$3],,[    :]dnl
166234949Sbapt,[    $3]) ifelse([$4],,,[
167234949Sbapt  else
168234949Sbapt    $4])
169234949Sbapt  fi],[enableval=$5 ifelse([$4],,,[
170234949Sbapt  $4
171234949Sbapt])dnl
172234949Sbapt  ])])dnl
173234949Sbaptdnl ---------------------------------------------------------------------------
174251143Sbaptdnl CF_CC_ENV_FLAGS version: 1 updated: 2012/10/03 05:25:49
175251143Sbaptdnl ---------------
176251143Sbaptdnl Check for user's environment-breakage by stuffing CFLAGS/CPPFLAGS content
177251143Sbaptdnl into CC.  This will not help with broken scripts that wrap the compiler with
178251143Sbaptdnl options, but eliminates a more common category of user confusion.
179251143SbaptAC_DEFUN([CF_CC_ENV_FLAGS],
180251143Sbapt[
181251143Sbapt# This should have been defined by AC_PROG_CC
182251143Sbapt: ${CC:=cc}
183251143Sbapt
184251143SbaptAC_MSG_CHECKING(\$CC variable)
185251143Sbaptcase "$CC" in #(vi
186251143Sbapt*[[\ \	]]-[[IUD]]*)
187251143Sbapt	AC_MSG_RESULT(broken)
188251143Sbapt	AC_MSG_WARN(your environment misuses the CC variable to hold CFLAGS/CPPFLAGS options)
189251143Sbapt	# humor him...
190251143Sbapt	cf_flags=`echo "$CC" | sed -e 's/^[[^ 	]]*[[ 	]]//'`
191251143Sbapt	CC=`echo "$CC" | sed -e 's/[[ 	]].*//'`
192251143Sbapt	CF_ADD_CFLAGS($cf_flags)
193251143Sbapt	;;
194251143Sbapt*)
195251143Sbapt	AC_MSG_RESULT(ok)
196251143Sbapt	;;
197251143Sbaptesac
198251143Sbapt])dnl
199251143Sbaptdnl ---------------------------------------------------------------------------
200251143Sbaptdnl CF_CHECK_CACHE version: 12 updated: 2012/10/02 20:55:03
201234949Sbaptdnl --------------
202234949Sbaptdnl Check if we're accidentally using a cache from a different machine.
203234949Sbaptdnl Derive the system name, as a check for reusing the autoconf cache.
204234949Sbaptdnl
205234949Sbaptdnl If we've packaged config.guess and config.sub, run that (since it does a
206234949Sbaptdnl better job than uname).  Normally we'll use AC_CANONICAL_HOST, but allow
207234949Sbaptdnl an extra parameter that we may override, e.g., for AC_CANONICAL_SYSTEM
208234949Sbaptdnl which is useful in cross-compiles.
209234949Sbaptdnl
210234949Sbaptdnl Note: we would use $ac_config_sub, but that is one of the places where
211234949Sbaptdnl autoconf 2.5x broke compatibility with autoconf 2.13
212234949SbaptAC_DEFUN([CF_CHECK_CACHE],
213234949Sbapt[
214234949Sbaptif test -f $srcdir/config.guess || test -f $ac_aux_dir/config.guess ; then
215234949Sbapt	ifelse([$1],,[AC_CANONICAL_HOST],[$1])
216234949Sbapt	system_name="$host_os"
217234949Sbaptelse
218234949Sbapt	system_name="`(uname -s -r) 2>/dev/null`"
219234949Sbapt	if test -z "$system_name" ; then
220234949Sbapt		system_name="`(hostname) 2>/dev/null`"
221234949Sbapt	fi
222234949Sbaptfi
223251143Sbapttest -n "$system_name" && AC_DEFINE_UNQUOTED(SYSTEM_NAME,"$system_name",[Define to the system name.])
224234949SbaptAC_CACHE_VAL(cf_cv_system_name,[cf_cv_system_name="$system_name"])
225234949Sbapt
226234949Sbapttest -z "$system_name" && system_name="$cf_cv_system_name"
227234949Sbapttest -n "$cf_cv_system_name" && AC_MSG_RESULT(Configuring for $cf_cv_system_name)
228234949Sbapt
229234949Sbaptif test ".$system_name" != ".$cf_cv_system_name" ; then
230234949Sbapt	AC_MSG_RESULT(Cached system name ($system_name) does not agree with actual ($cf_cv_system_name))
231234949Sbapt	AC_MSG_ERROR("Please remove config.cache and try again.")
232234949Sbaptfi
233234949Sbapt])dnl
234234949Sbaptdnl ---------------------------------------------------------------------------
235251143Sbaptdnl CF_CLANG_COMPILER version: 1 updated: 2012/06/16 14:55:39
236251143Sbaptdnl -----------------
237251143Sbaptdnl Check if the given compiler is really clang.  clang's C driver defines
238251143Sbaptdnl __GNUC__ (fooling the configure script into setting $GCC to yes) but does
239251143Sbaptdnl not ignore some gcc options.
240251143Sbaptdnl
241251143Sbaptdnl This macro should be run "soon" after AC_PROG_CC or AC_PROG_CPLUSPLUS, to
242251143Sbaptdnl ensure that it is not mistaken for gcc/g++.  It is normally invoked from
243251143Sbaptdnl the wrappers for gcc and g++ warnings.
244251143Sbaptdnl
245251143Sbaptdnl $1 = GCC (default) or GXX
246251143Sbaptdnl $2 = INTEL_COMPILER (default) or INTEL_CPLUSPLUS
247251143Sbaptdnl $3 = CFLAGS (default) or CXXFLAGS
248251143SbaptAC_DEFUN([CF_CLANG_COMPILER],[
249251143Sbaptifelse([$2],,CLANG_COMPILER,[$2])=no
250251143Sbapt
251251143Sbaptif test "$ifelse([$1],,[$1],GCC)" = yes ; then
252251143Sbapt	AC_MSG_CHECKING(if this is really Clang ifelse([$1],GXX,C++,C) compiler)
253251143Sbapt	cf_save_CFLAGS="$ifelse([$3],,CFLAGS,[$3])"
254251143Sbapt	ifelse([$3],,CFLAGS,[$3])="$ifelse([$3],,CFLAGS,[$3]) -Qunused-arguments"
255251143Sbapt	AC_TRY_COMPILE([],[
256251143Sbapt#ifdef __clang__
257251143Sbapt#else
258251143Sbaptmake an error
259251143Sbapt#endif
260251143Sbapt],[ifelse([$2],,CLANG_COMPILER,[$2])=yes
261251143Sbaptcf_save_CFLAGS="$cf_save_CFLAGS -Qunused-arguments"
262251143Sbapt],[])
263251143Sbapt	ifelse([$3],,CFLAGS,[$3])="$cf_save_CFLAGS"
264251143Sbapt	AC_MSG_RESULT($ifelse([$2],,CLANG_COMPILER,[$2]))
265251143Sbaptfi
266251143Sbapt])
267251143Sbaptdnl ---------------------------------------------------------------------------
268251143Sbaptdnl CF_DISABLE_ECHO version: 12 updated: 2012/10/06 16:30:28
269234949Sbaptdnl ---------------
270234949Sbaptdnl You can always use "make -n" to see the actual options, but it's hard to
271234949Sbaptdnl pick out/analyze warning messages when the compile-line is long.
272234949Sbaptdnl
273234949Sbaptdnl Sets:
274234949Sbaptdnl	ECHO_LT - symbol to control if libtool is verbose
275234949Sbaptdnl	ECHO_LD - symbol to prefix "cc -o" lines
276234949Sbaptdnl	RULE_CC - symbol to put before implicit "cc -c" lines (e.g., .c.o)
277234949Sbaptdnl	SHOW_CC - symbol to put before explicit "cc -c" lines
278234949Sbaptdnl	ECHO_CC - symbol to put before any "cc" line
279234949Sbaptdnl
280234949SbaptAC_DEFUN([CF_DISABLE_ECHO],[
281234949SbaptAC_MSG_CHECKING(if you want to see long compiling messages)
282234949SbaptCF_ARG_DISABLE(echo,
283251143Sbapt	[  --disable-echo          do not display "compiling" commands],
284234949Sbapt	[
285234949Sbapt    ECHO_LT='--silent'
286234949Sbapt    ECHO_LD='@echo linking [$]@;'
287234949Sbapt    RULE_CC='@echo compiling [$]<'
288234949Sbapt    SHOW_CC='@echo compiling [$]@'
289234949Sbapt    ECHO_CC='@'
290234949Sbapt],[
291234949Sbapt    ECHO_LT=''
292234949Sbapt    ECHO_LD=''
293234949Sbapt    RULE_CC=''
294234949Sbapt    SHOW_CC=''
295234949Sbapt    ECHO_CC=''
296234949Sbapt])
297234949SbaptAC_MSG_RESULT($enableval)
298234949SbaptAC_SUBST(ECHO_LT)
299234949SbaptAC_SUBST(ECHO_LD)
300234949SbaptAC_SUBST(RULE_CC)
301234949SbaptAC_SUBST(SHOW_CC)
302234949SbaptAC_SUBST(ECHO_CC)
303234949Sbapt])dnl
304234949Sbaptdnl ---------------------------------------------------------------------------
305251143Sbaptdnl CF_DISABLE_LEAKS version: 7 updated: 2012/10/02 20:55:03
306234949Sbaptdnl ----------------
307234949Sbaptdnl Combine no-leak checks with the libraries or tools that are used for the
308234949Sbaptdnl checks.
309234949SbaptAC_DEFUN([CF_DISABLE_LEAKS],[
310234949Sbapt
311234949SbaptAC_REQUIRE([CF_WITH_DMALLOC])
312234949SbaptAC_REQUIRE([CF_WITH_DBMALLOC])
313234949SbaptAC_REQUIRE([CF_WITH_VALGRIND])
314234949Sbapt
315234949SbaptAC_MSG_CHECKING(if you want to perform memory-leak testing)
316234949SbaptAC_ARG_ENABLE(leaks,
317234949Sbapt	[  --disable-leaks         test: free permanent memory, analyze leaks],
318234949Sbapt	[if test "x$enableval" = xno; then with_no_leaks=yes; else with_no_leaks=no; fi],
319234949Sbapt	: ${with_no_leaks:=no})
320234949SbaptAC_MSG_RESULT($with_no_leaks)
321234949Sbapt
322234949Sbaptif test "$with_no_leaks" = yes ; then
323251143Sbapt	AC_DEFINE(NO_LEAKS,1,[Define to 1 if you want to perform memory-leak testing.])
324251143Sbapt	AC_DEFINE(YY_NO_LEAKS,1,[Define to 1 if you want to perform memory-leak testing.])
325234949Sbaptfi
326234949Sbapt])dnl
327234949Sbaptdnl ---------------------------------------------------------------------------
328251143Sbaptdnl CF_GCC_ATTRIBUTES version: 16 updated: 2012/10/02 20:55:03
329234949Sbaptdnl -----------------
330234949Sbaptdnl Test for availability of useful gcc __attribute__ directives to quiet
331234949Sbaptdnl compiler warnings.  Though useful, not all are supported -- and contrary
332234949Sbaptdnl to documentation, unrecognized directives cause older compilers to barf.
333234949SbaptAC_DEFUN([CF_GCC_ATTRIBUTES],
334234949Sbapt[
335234949Sbaptif test "$GCC" = yes
336234949Sbaptthen
337234949Sbaptcat > conftest.i <<EOF
338234949Sbapt#ifndef GCC_PRINTF
339234949Sbapt#define GCC_PRINTF 0
340234949Sbapt#endif
341234949Sbapt#ifndef GCC_SCANF
342234949Sbapt#define GCC_SCANF 0
343234949Sbapt#endif
344234949Sbapt#ifndef GCC_NORETURN
345234949Sbapt#define GCC_NORETURN /* nothing */
346234949Sbapt#endif
347234949Sbapt#ifndef GCC_UNUSED
348234949Sbapt#define GCC_UNUSED /* nothing */
349234949Sbapt#endif
350234949SbaptEOF
351234949Sbaptif test "$GCC" = yes
352234949Sbaptthen
353234949Sbapt	AC_CHECKING([for $CC __attribute__ directives])
354234949Sbaptcat > conftest.$ac_ext <<EOF
355234949Sbapt#line __oline__ "${as_me:-configure}"
356234949Sbapt#include "confdefs.h"
357234949Sbapt#include "conftest.h"
358234949Sbapt#include "conftest.i"
359234949Sbapt#if	GCC_PRINTF
360234949Sbapt#define GCC_PRINTFLIKE(fmt,var) __attribute__((format(printf,fmt,var)))
361234949Sbapt#else
362234949Sbapt#define GCC_PRINTFLIKE(fmt,var) /*nothing*/
363234949Sbapt#endif
364234949Sbapt#if	GCC_SCANF
365234949Sbapt#define GCC_SCANFLIKE(fmt,var)  __attribute__((format(scanf,fmt,var)))
366234949Sbapt#else
367234949Sbapt#define GCC_SCANFLIKE(fmt,var)  /*nothing*/
368234949Sbapt#endif
369234949Sbaptextern void wow(char *,...) GCC_SCANFLIKE(1,2);
370234949Sbaptextern void oops(char *,...) GCC_PRINTFLIKE(1,2) GCC_NORETURN;
371234949Sbaptextern void foo(void) GCC_NORETURN;
372234949Sbaptint main(int argc GCC_UNUSED, char *argv[[]] GCC_UNUSED) { return 0; }
373234949SbaptEOF
374234949Sbapt	cf_printf_attribute=no
375234949Sbapt	cf_scanf_attribute=no
376234949Sbapt	for cf_attribute in scanf printf unused noreturn
377234949Sbapt	do
378234949Sbapt		CF_UPPER(cf_ATTRIBUTE,$cf_attribute)
379234949Sbapt		cf_directive="__attribute__(($cf_attribute))"
380234949Sbapt		echo "checking for $CC $cf_directive" 1>&AC_FD_CC
381234949Sbapt
382234949Sbapt		case $cf_attribute in #(vi
383234949Sbapt		printf) #(vi
384234949Sbapt			cf_printf_attribute=yes
385234949Sbapt			cat >conftest.h <<EOF
386234949Sbapt#define GCC_$cf_ATTRIBUTE 1
387234949SbaptEOF
388234949Sbapt			;;
389234949Sbapt		scanf) #(vi
390234949Sbapt			cf_scanf_attribute=yes
391234949Sbapt			cat >conftest.h <<EOF
392234949Sbapt#define GCC_$cf_ATTRIBUTE 1
393234949SbaptEOF
394234949Sbapt			;;
395234949Sbapt		*) #(vi
396234949Sbapt			cat >conftest.h <<EOF
397234949Sbapt#define GCC_$cf_ATTRIBUTE $cf_directive
398234949SbaptEOF
399234949Sbapt			;;
400234949Sbapt		esac
401234949Sbapt
402234949Sbapt		if AC_TRY_EVAL(ac_compile); then
403234949Sbapt			test -n "$verbose" && AC_MSG_RESULT(... $cf_attribute)
404234949Sbapt			cat conftest.h >>confdefs.h
405234949Sbapt			case $cf_attribute in #(vi
406251143Sbapt			noreturn) #(vi
407251143Sbapt				AC_DEFINE_UNQUOTED(GCC_NORETURN,$cf_directive,[Define to noreturn-attribute for gcc])
408251143Sbapt				;;
409234949Sbapt			printf) #(vi
410251143Sbapt				cf_value='/* nothing */'
411251143Sbapt				if test "$cf_printf_attribute" != no ; then
412251143Sbapt					cf_value='__attribute__((format(printf,fmt,var)))'
413251143Sbapt					AC_DEFINE(GCC_PRINTF,1,[Define to 1 if the compiler supports gcc-like printf attribute.])
414234949Sbapt				fi
415251143Sbapt				AC_DEFINE_UNQUOTED(GCC_PRINTFLIKE(fmt,var),$cf_value,[Define to printf-attribute for gcc])
416234949Sbapt				;;
417234949Sbapt			scanf) #(vi
418251143Sbapt				cf_value='/* nothing */'
419251143Sbapt				if test "$cf_scanf_attribute" != no ; then
420251143Sbapt					cf_value='__attribute__((format(scanf,fmt,var)))'
421251143Sbapt					AC_DEFINE(GCC_SCANF,1,[Define to 1 if the compiler supports gcc-like scanf attribute.])
422234949Sbapt				fi
423251143Sbapt				AC_DEFINE_UNQUOTED(GCC_SCANFLIKE(fmt,var),$cf_value,[Define to sscanf-attribute for gcc])
424234949Sbapt				;;
425251143Sbapt			unused) #(vi
426251143Sbapt				AC_DEFINE_UNQUOTED(GCC_UNUSED,$cf_directive,[Define to unused-attribute for gcc])
427251143Sbapt				;;
428234949Sbapt			esac
429234949Sbapt		fi
430234949Sbapt	done
431234949Sbaptelse
432234949Sbapt	fgrep define conftest.i >>confdefs.h
433234949Sbaptfi
434234949Sbaptrm -rf conftest*
435234949Sbaptfi
436234949Sbapt])dnl
437234949Sbaptdnl ---------------------------------------------------------------------------
438251143Sbaptdnl CF_GCC_VERSION version: 7 updated: 2012/10/18 06:46:33
439234949Sbaptdnl --------------
440234949Sbaptdnl Find version of gcc
441234949SbaptAC_DEFUN([CF_GCC_VERSION],[
442234949SbaptAC_REQUIRE([AC_PROG_CC])
443234949SbaptGCC_VERSION=none
444234949Sbaptif test "$GCC" = yes ; then
445234949Sbapt	AC_MSG_CHECKING(version of $CC)
446251143Sbapt	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.]].*//'`"
447234949Sbapt	test -z "$GCC_VERSION" && GCC_VERSION=unknown
448234949Sbapt	AC_MSG_RESULT($GCC_VERSION)
449234949Sbaptfi
450234949Sbapt])dnl
451234949Sbaptdnl ---------------------------------------------------------------------------
452251143Sbaptdnl CF_GCC_WARNINGS version: 29 updated: 2012/06/16 14:55:39
453234949Sbaptdnl ---------------
454234949Sbaptdnl Check if the compiler supports useful warning options.  There's a few that
455234949Sbaptdnl we don't use, simply because they're too noisy:
456234949Sbaptdnl
457234949Sbaptdnl	-Wconversion (useful in older versions of gcc, but not in gcc 2.7.x)
458234949Sbaptdnl	-Wredundant-decls (system headers make this too noisy)
459234949Sbaptdnl	-Wtraditional (combines too many unrelated messages, only a few useful)
460234949Sbaptdnl	-Wwrite-strings (too noisy, but should review occasionally).  This
461234949Sbaptdnl		is enabled for ncurses using "--enable-const".
462234949Sbaptdnl	-pedantic
463234949Sbaptdnl
464234949Sbaptdnl Parameter:
465234949Sbaptdnl	$1 is an optional list of gcc warning flags that a particular
466234949Sbaptdnl		application might want to use, e.g., "no-unused" for
467234949Sbaptdnl		-Wno-unused
468234949Sbaptdnl Special:
469234949Sbaptdnl	If $with_ext_const is "yes", add a check for -Wwrite-strings
470234949Sbaptdnl
471234949SbaptAC_DEFUN([CF_GCC_WARNINGS],
472234949Sbapt[
473234949SbaptAC_REQUIRE([CF_GCC_VERSION])
474234949SbaptCF_INTEL_COMPILER(GCC,INTEL_COMPILER,CFLAGS)
475251143SbaptCF_CLANG_COMPILER(GCC,CLANG_COMPILER,CFLAGS)
476234949Sbapt
477234949Sbaptcat > conftest.$ac_ext <<EOF
478234949Sbapt#line __oline__ "${as_me:-configure}"
479234949Sbaptint main(int argc, char *argv[[]]) { return (argv[[argc-1]] == 0) ; }
480234949SbaptEOF
481234949Sbapt
482234949Sbaptif test "$INTEL_COMPILER" = yes
483234949Sbaptthen
484234949Sbapt# The "-wdXXX" options suppress warnings:
485234949Sbapt# remark #1419: external declaration in primary source file
486234949Sbapt# remark #1683: explicit conversion of a 64-bit integral type to a smaller integral type (potential portability problem)
487234949Sbapt# remark #1684: conversion from pointer to same-sized integral type (potential portability problem)
488234949Sbapt# remark #193: zero used for undefined preprocessing identifier
489234949Sbapt# remark #593: variable "curs_sb_left_arrow" was set but never used
490234949Sbapt# remark #810: conversion from "int" to "Dimension={unsigned short}" may lose significant bits
491234949Sbapt# remark #869: parameter "tw" was never referenced
492234949Sbapt# remark #981: operands are evaluated in unspecified order
493234949Sbapt# warning #279: controlling expression is constant
494234949Sbapt
495234949Sbapt	AC_CHECKING([for $CC warning options])
496234949Sbapt	cf_save_CFLAGS="$CFLAGS"
497234949Sbapt	EXTRA_CFLAGS="-Wall"
498234949Sbapt	for cf_opt in \
499234949Sbapt		wd1419 \
500234949Sbapt		wd1683 \
501234949Sbapt		wd1684 \
502234949Sbapt		wd193 \
503234949Sbapt		wd593 \
504234949Sbapt		wd279 \
505234949Sbapt		wd810 \
506234949Sbapt		wd869 \
507234949Sbapt		wd981
508234949Sbapt	do
509234949Sbapt		CFLAGS="$cf_save_CFLAGS $EXTRA_CFLAGS -$cf_opt"
510234949Sbapt		if AC_TRY_EVAL(ac_compile); then
511234949Sbapt			test -n "$verbose" && AC_MSG_RESULT(... -$cf_opt)
512234949Sbapt			EXTRA_CFLAGS="$EXTRA_CFLAGS -$cf_opt"
513234949Sbapt		fi
514234949Sbapt	done
515234949Sbapt	CFLAGS="$cf_save_CFLAGS"
516234949Sbapt
517234949Sbaptelif test "$GCC" = yes
518234949Sbaptthen
519234949Sbapt	AC_CHECKING([for $CC warning options])
520234949Sbapt	cf_save_CFLAGS="$CFLAGS"
521234949Sbapt	EXTRA_CFLAGS=
522234949Sbapt	cf_warn_CONST=""
523234949Sbapt	test "$with_ext_const" = yes && cf_warn_CONST="Wwrite-strings"
524234949Sbapt	for cf_opt in W Wall \
525234949Sbapt		Wbad-function-cast \
526234949Sbapt		Wcast-align \
527234949Sbapt		Wcast-qual \
528234949Sbapt		Winline \
529234949Sbapt		Wmissing-declarations \
530234949Sbapt		Wmissing-prototypes \
531234949Sbapt		Wnested-externs \
532234949Sbapt		Wpointer-arith \
533234949Sbapt		Wshadow \
534234949Sbapt		Wstrict-prototypes \
535234949Sbapt		Wundef $cf_warn_CONST $1
536234949Sbapt	do
537234949Sbapt		CFLAGS="$cf_save_CFLAGS $EXTRA_CFLAGS -$cf_opt"
538234949Sbapt		if AC_TRY_EVAL(ac_compile); then
539234949Sbapt			test -n "$verbose" && AC_MSG_RESULT(... -$cf_opt)
540234949Sbapt			case $cf_opt in #(vi
541234949Sbapt			Wcast-qual) #(vi
542234949Sbapt				CPPFLAGS="$CPPFLAGS -DXTSTRINGDEFINES"
543234949Sbapt				;;
544234949Sbapt			Winline) #(vi
545234949Sbapt				case $GCC_VERSION in
546234949Sbapt				[[34]].*)
547234949Sbapt					CF_VERBOSE(feature is broken in gcc $GCC_VERSION)
548234949Sbapt					continue;;
549234949Sbapt				esac
550234949Sbapt				;;
551251143Sbapt			Wpointer-arith) #(vi
552251143Sbapt				case $GCC_VERSION in
553251143Sbapt				[[12]].*)
554251143Sbapt					CF_VERBOSE(feature is broken in gcc $GCC_VERSION)
555251143Sbapt					continue;;
556251143Sbapt				esac
557251143Sbapt				;;
558234949Sbapt			esac
559234949Sbapt			EXTRA_CFLAGS="$EXTRA_CFLAGS -$cf_opt"
560234949Sbapt		fi
561234949Sbapt	done
562234949Sbapt	CFLAGS="$cf_save_CFLAGS"
563234949Sbaptfi
564234949Sbaptrm -rf conftest*
565234949Sbapt
566234949SbaptAC_SUBST(EXTRA_CFLAGS)
567234949Sbapt])dnl
568234949Sbaptdnl ---------------------------------------------------------------------------
569234949Sbaptdnl CF_GNU_SOURCE version: 6 updated: 2005/07/09 13:23:07
570234949Sbaptdnl -------------
571234949Sbaptdnl Check if we must define _GNU_SOURCE to get a reasonable value for
572234949Sbaptdnl _XOPEN_SOURCE, upon which many POSIX definitions depend.  This is a defect
573234949Sbaptdnl (or misfeature) of glibc2, which breaks portability of many applications,
574234949Sbaptdnl since it is interwoven with GNU extensions.
575234949Sbaptdnl
576234949Sbaptdnl Well, yes we could work around it...
577234949SbaptAC_DEFUN([CF_GNU_SOURCE],
578234949Sbapt[
579234949SbaptAC_CACHE_CHECK(if we must define _GNU_SOURCE,cf_cv_gnu_source,[
580234949SbaptAC_TRY_COMPILE([#include <sys/types.h>],[
581234949Sbapt#ifndef _XOPEN_SOURCE
582234949Sbaptmake an error
583234949Sbapt#endif],
584234949Sbapt	[cf_cv_gnu_source=no],
585234949Sbapt	[cf_save="$CPPFLAGS"
586234949Sbapt	 CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
587234949Sbapt	 AC_TRY_COMPILE([#include <sys/types.h>],[
588234949Sbapt#ifdef _XOPEN_SOURCE
589234949Sbaptmake an error
590234949Sbapt#endif],
591234949Sbapt	[cf_cv_gnu_source=no],
592234949Sbapt	[cf_cv_gnu_source=yes])
593234949Sbapt	CPPFLAGS="$cf_save"
594234949Sbapt	])
595234949Sbapt])
596234949Sbapttest "$cf_cv_gnu_source" = yes && CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
597234949Sbapt])dnl
598234949Sbaptdnl ---------------------------------------------------------------------------
599251143Sbaptdnl CF_INTEL_COMPILER version: 5 updated: 2013/02/10 10:41:05
600234949Sbaptdnl -----------------
601234949Sbaptdnl Check if the given compiler is really the Intel compiler for Linux.  It
602234949Sbaptdnl tries to imitate gcc, but does not return an error when it finds a mismatch
603234949Sbaptdnl between prototypes, e.g., as exercised by CF_MISSING_CHECK.
604234949Sbaptdnl
605234949Sbaptdnl This macro should be run "soon" after AC_PROG_CC or AC_PROG_CPLUSPLUS, to
606234949Sbaptdnl ensure that it is not mistaken for gcc/g++.  It is normally invoked from
607234949Sbaptdnl the wrappers for gcc and g++ warnings.
608234949Sbaptdnl
609234949Sbaptdnl $1 = GCC (default) or GXX
610234949Sbaptdnl $2 = INTEL_COMPILER (default) or INTEL_CPLUSPLUS
611234949Sbaptdnl $3 = CFLAGS (default) or CXXFLAGS
612234949SbaptAC_DEFUN([CF_INTEL_COMPILER],[
613251143SbaptAC_REQUIRE([AC_CANONICAL_HOST])
614234949Sbaptifelse([$2],,INTEL_COMPILER,[$2])=no
615234949Sbapt
616234949Sbaptif test "$ifelse([$1],,[$1],GCC)" = yes ; then
617234949Sbapt	case $host_os in
618234949Sbapt	linux*|gnu*)
619234949Sbapt		AC_MSG_CHECKING(if this is really Intel ifelse([$1],GXX,C++,C) compiler)
620234949Sbapt		cf_save_CFLAGS="$ifelse([$3],,CFLAGS,[$3])"
621234949Sbapt		ifelse([$3],,CFLAGS,[$3])="$ifelse([$3],,CFLAGS,[$3]) -no-gcc"
622234949Sbapt		AC_TRY_COMPILE([],[
623234949Sbapt#ifdef __INTEL_COMPILER
624234949Sbapt#else
625234949Sbaptmake an error
626234949Sbapt#endif
627234949Sbapt],[ifelse([$2],,INTEL_COMPILER,[$2])=yes
628234949Sbaptcf_save_CFLAGS="$cf_save_CFLAGS -we147 -no-gcc"
629234949Sbapt],[])
630234949Sbapt		ifelse([$3],,CFLAGS,[$3])="$cf_save_CFLAGS"
631234949Sbapt		AC_MSG_RESULT($ifelse([$2],,INTEL_COMPILER,[$2]))
632234949Sbapt		;;
633234949Sbapt	esac
634234949Sbaptfi
635234949Sbapt])dnl
636234949Sbaptdnl ---------------------------------------------------------------------------
637234949Sbaptdnl CF_MAKE_TAGS version: 6 updated: 2010/10/23 15:52:32
638234949Sbaptdnl ------------
639234949Sbaptdnl Generate tags/TAGS targets for makefiles.  Do not generate TAGS if we have
640234949Sbaptdnl a monocase filesystem.
641234949SbaptAC_DEFUN([CF_MAKE_TAGS],[
642234949SbaptAC_REQUIRE([CF_MIXEDCASE_FILENAMES])
643234949Sbapt
644234949SbaptAC_CHECK_PROGS(CTAGS, exctags ctags)
645234949SbaptAC_CHECK_PROGS(ETAGS, exetags etags)
646234949Sbapt
647234949SbaptAC_CHECK_PROG(MAKE_LOWER_TAGS, ${CTAGS:-ctags}, yes, no)
648234949Sbapt
649234949Sbaptif test "$cf_cv_mixedcase" = yes ; then
650234949Sbapt	AC_CHECK_PROG(MAKE_UPPER_TAGS, ${ETAGS:-etags}, yes, no)
651234949Sbaptelse
652234949Sbapt	MAKE_UPPER_TAGS=no
653234949Sbaptfi
654234949Sbapt
655234949Sbaptif test "$MAKE_UPPER_TAGS" = yes ; then
656234949Sbapt	MAKE_UPPER_TAGS=
657234949Sbaptelse
658234949Sbapt	MAKE_UPPER_TAGS="#"
659234949Sbaptfi
660234949Sbapt
661234949Sbaptif test "$MAKE_LOWER_TAGS" = yes ; then
662234949Sbapt	MAKE_LOWER_TAGS=
663234949Sbaptelse
664234949Sbapt	MAKE_LOWER_TAGS="#"
665234949Sbaptfi
666234949Sbapt
667234949SbaptAC_SUBST(CTAGS)
668234949SbaptAC_SUBST(ETAGS)
669234949Sbapt
670234949SbaptAC_SUBST(MAKE_UPPER_TAGS)
671234949SbaptAC_SUBST(MAKE_LOWER_TAGS)
672234949Sbapt])dnl
673234949Sbaptdnl ---------------------------------------------------------------------------
674251143Sbaptdnl CF_MIXEDCASE_FILENAMES version: 4 updated: 2012/10/02 20:55:03
675234949Sbaptdnl ----------------------
676234949Sbaptdnl Check if the file-system supports mixed-case filenames.  If we're able to
677234949Sbaptdnl create a lowercase name and see it as uppercase, it doesn't support that.
678234949SbaptAC_DEFUN([CF_MIXEDCASE_FILENAMES],
679234949Sbapt[
680234949SbaptAC_CACHE_CHECK(if filesystem supports mixed-case filenames,cf_cv_mixedcase,[
681234949Sbaptif test "$cross_compiling" = yes ; then
682234949Sbapt	case $target_alias in #(vi
683234949Sbapt	*-os2-emx*|*-msdosdjgpp*|*-cygwin*|*-mingw32*|*-uwin*) #(vi
684234949Sbapt		cf_cv_mixedcase=no
685234949Sbapt		;;
686234949Sbapt	*)
687234949Sbapt		cf_cv_mixedcase=yes
688234949Sbapt		;;
689234949Sbapt	esac
690234949Sbaptelse
691234949Sbapt	rm -f conftest CONFTEST
692234949Sbapt	echo test >conftest
693234949Sbapt	if test -f CONFTEST ; then
694234949Sbapt		cf_cv_mixedcase=no
695234949Sbapt	else
696234949Sbapt		cf_cv_mixedcase=yes
697234949Sbapt	fi
698234949Sbapt	rm -f conftest CONFTEST
699234949Sbaptfi
700234949Sbapt])
701251143Sbapttest "$cf_cv_mixedcase" = yes && AC_DEFINE(MIXEDCASE_FILENAMES,1,[Define to 1 if filesystem supports mixed-case filenames.])
702234949Sbapt])dnl
703234949Sbaptdnl ---------------------------------------------------------------------------
704251143Sbaptdnl CF_MKSTEMP version: 9 updated: 2012/10/03 04:34:49
705234949Sbaptdnl ----------
706234949Sbaptdnl Check for a working mkstemp.  This creates two files, checks that they are
707234949Sbaptdnl successfully created and distinct (AmigaOS apparently fails on the last).
708234949SbaptAC_DEFUN([CF_MKSTEMP],[
709234949SbaptAC_CACHE_CHECK(for working mkstemp, cf_cv_func_mkstemp,[
710234949Sbaptrm -rf conftest*
711234949SbaptAC_TRY_RUN([
712234949Sbapt#include <sys/types.h>
713234949Sbapt#include <stdlib.h>
714234949Sbapt#include <stdio.h>
715234949Sbapt#include <string.h>
716234949Sbapt#include <sys/stat.h>
717234949Sbaptint main()
718234949Sbapt{
719234949Sbapt	char *tmpl = "conftestXXXXXX";
720234949Sbapt	char name[2][80];
721234949Sbapt	int n;
722234949Sbapt	int result = 0;
723234949Sbapt	int fd;
724234949Sbapt	struct stat sb;
725234949Sbapt
726234949Sbapt	umask(077);
727234949Sbapt	for (n = 0; n < 2; ++n) {
728234949Sbapt		strcpy(name[n], tmpl);
729234949Sbapt		if ((fd = mkstemp(name[n])) >= 0) {
730234949Sbapt			if (!strcmp(name[n], tmpl)
731234949Sbapt			 || stat(name[n], &sb) != 0
732234949Sbapt			 || (sb.st_mode & S_IFMT) != S_IFREG
733234949Sbapt			 || (sb.st_mode & 077) != 0) {
734234949Sbapt				result = 1;
735234949Sbapt			}
736234949Sbapt			close(fd);
737234949Sbapt		}
738234949Sbapt	}
739234949Sbapt	if (result == 0
740234949Sbapt	 && !strcmp(name[0], name[1]))
741234949Sbapt		result = 1;
742234949Sbapt	${cf_cv_main_return:-return}(result);
743234949Sbapt}
744234949Sbapt],[cf_cv_func_mkstemp=yes
745234949Sbapt],[cf_cv_func_mkstemp=no
746251143Sbapt],[cf_cv_func_mkstemp=maybe])
747234949Sbapt])
748251143Sbaptif test "x$cf_cv_func_mkstemp" = xmaybe ; then
749251143Sbapt	AC_CHECK_FUNC(mkstemp)
750251143Sbaptfi
751234949Sbaptif test "x$cf_cv_func_mkstemp" = xyes || test "x$ac_cv_func_mkstemp" = xyes ; then
752251143Sbapt	AC_DEFINE(HAVE_MKSTEMP,1,[Define to 1 if mkstemp() is available and working.])
753234949Sbaptfi
754234949Sbapt])dnl
755234949Sbaptdnl ---------------------------------------------------------------------------
756234949Sbaptdnl CF_MSG_LOG version: 5 updated: 2010/10/23 15:52:32
757234949Sbaptdnl ----------
758234949Sbaptdnl Write a debug message to config.log, along with the line number in the
759234949Sbaptdnl configure script.
760234949SbaptAC_DEFUN([CF_MSG_LOG],[
761234949Sbaptecho "${as_me:-configure}:__oline__: testing $* ..." 1>&AC_FD_CC
762234949Sbapt])dnl
763234949Sbaptdnl ---------------------------------------------------------------------------
764251143Sbaptdnl CF_NO_LEAKS_OPTION version: 5 updated: 2012/10/02 20:55:03
765234949Sbaptdnl ------------------
766234949Sbaptdnl see CF_WITH_NO_LEAKS
767234949SbaptAC_DEFUN([CF_NO_LEAKS_OPTION],[
768234949SbaptAC_MSG_CHECKING(if you want to use $1 for testing)
769234949SbaptAC_ARG_WITH($1,
770234949Sbapt	[$2],
771251143Sbapt	[AC_DEFINE_UNQUOTED($3,1,"Define to 1 if you want to use $1 for testing.")ifelse([$4],,[
772234949Sbapt	 $4
773234949Sbapt])
774234949Sbapt	: ${with_cflags:=-g}
775234949Sbapt	: ${with_no_leaks:=yes}
776234949Sbapt	 with_$1=yes],
777234949Sbapt	[with_$1=])
778234949SbaptAC_MSG_RESULT(${with_$1:-no})
779234949Sbapt
780234949Sbaptcase .$with_cflags in #(vi
781234949Sbapt.*-g*)
782234949Sbapt	case .$CFLAGS in #(vi
783234949Sbapt	.*-g*) #(vi
784234949Sbapt		;;
785234949Sbapt	*)
786234949Sbapt		CF_ADD_CFLAGS([-g])
787234949Sbapt		;;
788234949Sbapt	esac
789234949Sbapt	;;
790234949Sbaptesac
791234949Sbapt])dnl
792234949Sbaptdnl ---------------------------------------------------------------------------
793234949Sbaptdnl CF_POSIX_C_SOURCE version: 8 updated: 2010/05/26 05:38:42
794234949Sbaptdnl -----------------
795234949Sbaptdnl Define _POSIX_C_SOURCE to the given level, and _POSIX_SOURCE if needed.
796234949Sbaptdnl
797234949Sbaptdnl	POSIX.1-1990				_POSIX_SOURCE
798234949Sbaptdnl	POSIX.1-1990 and			_POSIX_SOURCE and
799234949Sbaptdnl		POSIX.2-1992 C-Language			_POSIX_C_SOURCE=2
800234949Sbaptdnl		Bindings Option
801234949Sbaptdnl	POSIX.1b-1993				_POSIX_C_SOURCE=199309L
802234949Sbaptdnl	POSIX.1c-1996				_POSIX_C_SOURCE=199506L
803234949Sbaptdnl	X/Open 2000				_POSIX_C_SOURCE=200112L
804234949Sbaptdnl
805234949Sbaptdnl Parameters:
806234949Sbaptdnl	$1 is the nominal value for _POSIX_C_SOURCE
807234949SbaptAC_DEFUN([CF_POSIX_C_SOURCE],
808234949Sbapt[
809234949Sbaptcf_POSIX_C_SOURCE=ifelse([$1],,199506L,[$1])
810234949Sbapt
811234949Sbaptcf_save_CFLAGS="$CFLAGS"
812234949Sbaptcf_save_CPPFLAGS="$CPPFLAGS"
813234949Sbapt
814234949SbaptCF_REMOVE_DEFINE(cf_trim_CFLAGS,$cf_save_CFLAGS,_POSIX_C_SOURCE)
815234949SbaptCF_REMOVE_DEFINE(cf_trim_CPPFLAGS,$cf_save_CPPFLAGS,_POSIX_C_SOURCE)
816234949Sbapt
817234949SbaptAC_CACHE_CHECK(if we should define _POSIX_C_SOURCE,cf_cv_posix_c_source,[
818234949Sbapt	CF_MSG_LOG(if the symbol is already defined go no further)
819234949Sbapt	AC_TRY_COMPILE([#include <sys/types.h>],[
820234949Sbapt#ifndef _POSIX_C_SOURCE
821234949Sbaptmake an error
822234949Sbapt#endif],
823234949Sbapt	[cf_cv_posix_c_source=no],
824234949Sbapt	[cf_want_posix_source=no
825234949Sbapt	 case .$cf_POSIX_C_SOURCE in #(vi
826234949Sbapt	 .[[12]]??*) #(vi
827234949Sbapt		cf_cv_posix_c_source="-D_POSIX_C_SOURCE=$cf_POSIX_C_SOURCE"
828234949Sbapt		;;
829234949Sbapt	 .2) #(vi
830234949Sbapt		cf_cv_posix_c_source="-D_POSIX_C_SOURCE=$cf_POSIX_C_SOURCE"
831234949Sbapt		cf_want_posix_source=yes
832234949Sbapt		;;
833234949Sbapt	 .*)
834234949Sbapt		cf_want_posix_source=yes
835234949Sbapt		;;
836234949Sbapt	 esac
837234949Sbapt	 if test "$cf_want_posix_source" = yes ; then
838234949Sbapt		AC_TRY_COMPILE([#include <sys/types.h>],[
839234949Sbapt#ifdef _POSIX_SOURCE
840234949Sbaptmake an error
841234949Sbapt#endif],[],
842234949Sbapt		cf_cv_posix_c_source="$cf_cv_posix_c_source -D_POSIX_SOURCE")
843234949Sbapt	 fi
844234949Sbapt	 CF_MSG_LOG(ifdef from value $cf_POSIX_C_SOURCE)
845234949Sbapt	 CFLAGS="$cf_trim_CFLAGS"
846234949Sbapt	 CPPFLAGS="$cf_trim_CPPFLAGS $cf_cv_posix_c_source"
847234949Sbapt	 CF_MSG_LOG(if the second compile does not leave our definition intact error)
848234949Sbapt	 AC_TRY_COMPILE([#include <sys/types.h>],[
849234949Sbapt#ifndef _POSIX_C_SOURCE
850234949Sbaptmake an error
851234949Sbapt#endif],,
852234949Sbapt	 [cf_cv_posix_c_source=no])
853234949Sbapt	 CFLAGS="$cf_save_CFLAGS"
854234949Sbapt	 CPPFLAGS="$cf_save_CPPFLAGS"
855234949Sbapt	])
856234949Sbapt])
857234949Sbapt
858234949Sbaptif test "$cf_cv_posix_c_source" != no ; then
859234949Sbapt	CFLAGS="$cf_trim_CFLAGS"
860234949Sbapt	CPPFLAGS="$cf_trim_CPPFLAGS"
861234949Sbapt	CF_ADD_CFLAGS($cf_cv_posix_c_source)
862234949Sbaptfi
863234949Sbapt
864234949Sbapt])dnl
865234949Sbaptdnl ---------------------------------------------------------------------------
866251143Sbaptdnl CF_PROG_CC version: 3 updated: 2012/10/06 15:31:55
867251143Sbaptdnl ----------
868251143Sbaptdnl standard check for CC, plus followup sanity checks
869251143Sbaptdnl $1 = optional parameter to pass to AC_PROG_CC to specify compiler name
870251143SbaptAC_DEFUN([CF_PROG_CC],[
871251143Sbaptifelse($1,,[AC_PROG_CC],[AC_PROG_CC($1)])
872251143SbaptCF_GCC_VERSION
873251143SbaptCF_ACVERSION_CHECK(2.52,
874251143Sbapt	[AC_PROG_CC_STDC],
875251143Sbapt	[CF_ANSI_CC_REQD])
876251143SbaptCF_CC_ENV_FLAGS 
877234949Sbapt])dnl
878234949Sbaptdnl ---------------------------------------------------------------------------
879234949Sbaptdnl CF_PROG_LINT version: 2 updated: 2009/08/12 04:43:14
880234949Sbaptdnl ------------
881234949SbaptAC_DEFUN([CF_PROG_LINT],
882234949Sbapt[
883234949SbaptAC_CHECK_PROGS(LINT, tdlint lint alint splint lclint)
884234949SbaptAC_SUBST(LINT_OPTS)
885234949Sbapt])dnl
886234949Sbaptdnl ---------------------------------------------------------------------------
887234949Sbaptdnl CF_REMOVE_DEFINE version: 3 updated: 2010/01/09 11:05:50
888234949Sbaptdnl ----------------
889234949Sbaptdnl Remove all -U and -D options that refer to the given symbol from a list
890234949Sbaptdnl of C compiler options.  This works around the problem that not all
891234949Sbaptdnl compilers process -U and -D options from left-to-right, so a -U option
892234949Sbaptdnl cannot be used to cancel the effect of a preceding -D option.
893234949Sbaptdnl
894234949Sbaptdnl $1 = target (which could be the same as the source variable)
895234949Sbaptdnl $2 = source (including '$')
896234949Sbaptdnl $3 = symbol to remove
897234949Sbaptdefine([CF_REMOVE_DEFINE],
898234949Sbapt[
899234949Sbapt$1=`echo "$2" | \
900234949Sbapt	sed	-e 's/-[[UD]]'"$3"'\(=[[^ 	]]*\)\?[[ 	]]/ /g' \
901234949Sbapt		-e 's/-[[UD]]'"$3"'\(=[[^ 	]]*\)\?[$]//g'`
902234949Sbapt])dnl
903234949Sbaptdnl ---------------------------------------------------------------------------
904234949Sbaptdnl CF_TRY_XOPEN_SOURCE version: 1 updated: 2011/10/30 17:09:50
905234949Sbaptdnl -------------------
906234949Sbaptdnl If _XOPEN_SOURCE is not defined in the compile environment, check if we
907234949Sbaptdnl can define it successfully.
908234949SbaptAC_DEFUN([CF_TRY_XOPEN_SOURCE],[
909234949SbaptAC_CACHE_CHECK(if we should define _XOPEN_SOURCE,cf_cv_xopen_source,[
910234949Sbapt	AC_TRY_COMPILE([
911234949Sbapt#include <stdlib.h>
912234949Sbapt#include <string.h>
913234949Sbapt#include <sys/types.h>
914234949Sbapt],[
915234949Sbapt#ifndef _XOPEN_SOURCE
916234949Sbaptmake an error
917234949Sbapt#endif],
918234949Sbapt	[cf_cv_xopen_source=no],
919234949Sbapt	[cf_save="$CPPFLAGS"
920234949Sbapt	 CPPFLAGS="$CPPFLAGS -D_XOPEN_SOURCE=$cf_XOPEN_SOURCE"
921234949Sbapt	 AC_TRY_COMPILE([
922234949Sbapt#include <stdlib.h>
923234949Sbapt#include <string.h>
924234949Sbapt#include <sys/types.h>
925234949Sbapt],[
926234949Sbapt#ifdef _XOPEN_SOURCE
927234949Sbaptmake an error
928234949Sbapt#endif],
929234949Sbapt	[cf_cv_xopen_source=no],
930234949Sbapt	[cf_cv_xopen_source=$cf_XOPEN_SOURCE])
931234949Sbapt	CPPFLAGS="$cf_save"
932234949Sbapt	])
933234949Sbapt])
934234949Sbapt
935234949Sbaptif test "$cf_cv_xopen_source" != no ; then
936234949Sbapt	CF_REMOVE_DEFINE(CFLAGS,$CFLAGS,_XOPEN_SOURCE)
937234949Sbapt	CF_REMOVE_DEFINE(CPPFLAGS,$CPPFLAGS,_XOPEN_SOURCE)
938234949Sbapt	cf_temp_xopen_source="-D_XOPEN_SOURCE=$cf_cv_xopen_source"
939234949Sbapt	CF_ADD_CFLAGS($cf_temp_xopen_source)
940234949Sbaptfi
941234949Sbapt])
942234949Sbaptdnl ---------------------------------------------------------------------------
943234949Sbaptdnl CF_UPPER version: 5 updated: 2001/01/29 23:40:59
944234949Sbaptdnl --------
945234949Sbaptdnl Make an uppercase version of a variable
946234949Sbaptdnl $1=uppercase($2)
947234949SbaptAC_DEFUN([CF_UPPER],
948234949Sbapt[
949234949Sbapt$1=`echo "$2" | sed y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%`
950234949Sbapt])dnl
951234949Sbaptdnl ---------------------------------------------------------------------------
952234949Sbaptdnl CF_VERBOSE version: 3 updated: 2007/07/29 09:55:12
953234949Sbaptdnl ----------
954234949Sbaptdnl Use AC_VERBOSE w/o the warnings
955234949SbaptAC_DEFUN([CF_VERBOSE],
956234949Sbapt[test -n "$verbose" && echo "	$1" 1>&AC_FD_MSG
957234949SbaptCF_MSG_LOG([$1])
958234949Sbapt])dnl
959234949Sbaptdnl ---------------------------------------------------------------------------
960234949Sbaptdnl CF_WITH_DBMALLOC version: 7 updated: 2010/06/21 17:26:47
961234949Sbaptdnl ----------------
962234949Sbaptdnl Configure-option for dbmalloc.  The optional parameter is used to override
963234949Sbaptdnl the updating of $LIBS, e.g., to avoid conflict with subsequent tests.
964234949SbaptAC_DEFUN([CF_WITH_DBMALLOC],[
965234949SbaptCF_NO_LEAKS_OPTION(dbmalloc,
966234949Sbapt	[  --with-dbmalloc         test: use Conor Cahill's dbmalloc library],
967234949Sbapt	[USE_DBMALLOC])
968234949Sbapt
969234949Sbaptif test "$with_dbmalloc" = yes ; then
970234949Sbapt	AC_CHECK_HEADER(dbmalloc.h,
971234949Sbapt		[AC_CHECK_LIB(dbmalloc,[debug_malloc]ifelse([$1],,[],[,$1]))])
972234949Sbaptfi
973234949Sbapt])dnl
974234949Sbaptdnl ---------------------------------------------------------------------------
975234949Sbaptdnl CF_WITH_DMALLOC version: 7 updated: 2010/06/21 17:26:47
976234949Sbaptdnl ---------------
977234949Sbaptdnl Configure-option for dmalloc.  The optional parameter is used to override
978234949Sbaptdnl the updating of $LIBS, e.g., to avoid conflict with subsequent tests.
979234949SbaptAC_DEFUN([CF_WITH_DMALLOC],[
980234949SbaptCF_NO_LEAKS_OPTION(dmalloc,
981234949Sbapt	[  --with-dmalloc          test: use Gray Watson's dmalloc library],
982234949Sbapt	[USE_DMALLOC])
983234949Sbapt
984234949Sbaptif test "$with_dmalloc" = yes ; then
985234949Sbapt	AC_CHECK_HEADER(dmalloc.h,
986234949Sbapt		[AC_CHECK_LIB(dmalloc,[dmalloc_debug]ifelse([$1],,[],[,$1]))])
987234949Sbaptfi
988234949Sbapt])dnl
989234949Sbaptdnl ---------------------------------------------------------------------------
990234949Sbaptdnl CF_WITH_VALGRIND version: 1 updated: 2006/12/14 18:00:21
991234949Sbaptdnl ----------------
992234949SbaptAC_DEFUN([CF_WITH_VALGRIND],[
993234949SbaptCF_NO_LEAKS_OPTION(valgrind,
994234949Sbapt	[  --with-valgrind         test: use valgrind],
995234949Sbapt	[USE_VALGRIND])
996234949Sbapt])dnl
997234949Sbaptdnl ---------------------------------------------------------------------------
998234949Sbaptdnl CF_WITH_WARNINGS version: 5 updated: 2004/07/23 14:40:34
999234949Sbaptdnl ----------------
1000234949Sbaptdnl Combine the checks for gcc features into a configure-script option
1001234949Sbaptdnl
1002234949Sbaptdnl Parameters:
1003234949Sbaptdnl	$1 - see CF_GCC_WARNINGS
1004234949SbaptAC_DEFUN([CF_WITH_WARNINGS],
1005234949Sbapt[
1006234949Sbaptif ( test "$GCC" = yes || test "$GXX" = yes )
1007234949Sbaptthen
1008234949SbaptAC_MSG_CHECKING(if you want to check for gcc warnings)
1009234949SbaptAC_ARG_WITH(warnings,
1010234949Sbapt	[  --with-warnings         test: turn on gcc warnings],
1011234949Sbapt	[cf_opt_with_warnings=$withval],
1012234949Sbapt	[cf_opt_with_warnings=no])
1013234949SbaptAC_MSG_RESULT($cf_opt_with_warnings)
1014234949Sbaptif test "$cf_opt_with_warnings" != no ; then
1015234949Sbapt	CF_GCC_ATTRIBUTES
1016234949Sbapt	CF_GCC_WARNINGS([$1])
1017234949Sbaptfi
1018234949Sbaptfi
1019234949Sbapt])dnl
1020234949Sbaptdnl ---------------------------------------------------------------------------
1021251143Sbaptdnl CF_XOPEN_SOURCE version: 43 updated: 2013/02/10 10:41:05
1022234949Sbaptdnl ---------------
1023234949Sbaptdnl Try to get _XOPEN_SOURCE defined properly that we can use POSIX functions,
1024234949Sbaptdnl or adapt to the vendor's definitions to get equivalent functionality,
1025234949Sbaptdnl without losing the common non-POSIX features.
1026234949Sbaptdnl
1027234949Sbaptdnl Parameters:
1028234949Sbaptdnl	$1 is the nominal value for _XOPEN_SOURCE
1029234949Sbaptdnl	$2 is the nominal value for _POSIX_C_SOURCE
1030234949SbaptAC_DEFUN([CF_XOPEN_SOURCE],[
1031251143SbaptAC_REQUIRE([AC_CANONICAL_HOST])
1032234949Sbapt
1033234949Sbaptcf_XOPEN_SOURCE=ifelse([$1],,500,[$1])
1034234949Sbaptcf_POSIX_C_SOURCE=ifelse([$2],,199506L,[$2])
1035234949Sbaptcf_xopen_source=
1036234949Sbapt
1037234949Sbaptcase $host_os in #(vi
1038234949Sbaptaix[[4-7]]*) #(vi
1039234949Sbapt	cf_xopen_source="-D_ALL_SOURCE"
1040234949Sbapt	;;
1041234949Sbaptcygwin) #(vi
1042234949Sbapt	cf_XOPEN_SOURCE=600
1043234949Sbapt	;;
1044234949Sbaptdarwin[[0-8]].*) #(vi
1045234949Sbapt	cf_xopen_source="-D_APPLE_C_SOURCE"
1046234949Sbapt	;;
1047234949Sbaptdarwin*) #(vi
1048234949Sbapt	cf_xopen_source="-D_DARWIN_C_SOURCE"
1049234949Sbapt	cf_XOPEN_SOURCE=
1050234949Sbapt	;;
1051234949Sbaptfreebsd*|dragonfly*) #(vi
1052234949Sbapt	# 5.x headers associate
1053234949Sbapt	#	_XOPEN_SOURCE=600 with _POSIX_C_SOURCE=200112L
1054234949Sbapt	#	_XOPEN_SOURCE=500 with _POSIX_C_SOURCE=199506L
1055234949Sbapt	cf_POSIX_C_SOURCE=200112L
1056234949Sbapt	cf_XOPEN_SOURCE=600
1057234949Sbapt	cf_xopen_source="-D_BSD_TYPES -D__BSD_VISIBLE -D_POSIX_C_SOURCE=$cf_POSIX_C_SOURCE -D_XOPEN_SOURCE=$cf_XOPEN_SOURCE"
1058234949Sbapt	;;
1059234949Sbapthpux11*) #(vi
1060234949Sbapt	cf_xopen_source="-D_HPUX_SOURCE -D_XOPEN_SOURCE=500"
1061234949Sbapt	;;
1062234949Sbapthpux*) #(vi
1063234949Sbapt	cf_xopen_source="-D_HPUX_SOURCE"
1064234949Sbapt	;;
1065234949Sbaptirix[[56]].*) #(vi
1066234949Sbapt	cf_xopen_source="-D_SGI_SOURCE"
1067234949Sbapt	cf_XOPEN_SOURCE=
1068234949Sbapt	;;
1069234949Sbaptlinux*|gnu*|mint*|k*bsd*-gnu) #(vi
1070234949Sbapt	CF_GNU_SOURCE
1071234949Sbapt	;;
1072234949Sbaptmirbsd*) #(vi
1073234949Sbapt	# setting _XOPEN_SOURCE or _POSIX_SOURCE breaks <sys/select.h> and other headers which use u_int / u_short types
1074234949Sbapt	cf_XOPEN_SOURCE=
1075234949Sbapt	CF_POSIX_C_SOURCE($cf_POSIX_C_SOURCE)
1076234949Sbapt	;;
1077234949Sbaptnetbsd*) #(vi
1078234949Sbapt	cf_xopen_source="-D_NETBSD_SOURCE" # setting _XOPEN_SOURCE breaks IPv6 for lynx on NetBSD 1.6, breaks xterm, is not needed for ncursesw
1079234949Sbapt	;;
1080234949Sbaptopenbsd[[4-9]]*) #(vi
1081234949Sbapt	# setting _XOPEN_SOURCE lower than 500 breaks g++ compile with wchar.h, needed for ncursesw
1082234949Sbapt	cf_xopen_source="-D_BSD_SOURCE"
1083234949Sbapt	cf_XOPEN_SOURCE=600
1084234949Sbapt	;;
1085234949Sbaptopenbsd*) #(vi
1086234949Sbapt	# setting _XOPEN_SOURCE breaks xterm on OpenBSD 2.8, is not needed for ncursesw
1087234949Sbapt	;;
1088234949Sbaptosf[[45]]*) #(vi
1089234949Sbapt	cf_xopen_source="-D_OSF_SOURCE"
1090234949Sbapt	;;
1091234949Sbaptnto-qnx*) #(vi
1092234949Sbapt	cf_xopen_source="-D_QNX_SOURCE"
1093234949Sbapt	;;
1094234949Sbaptsco*) #(vi
1095234949Sbapt	# setting _XOPEN_SOURCE breaks Lynx on SCO Unix / OpenServer
1096234949Sbapt	;;
1097234949Sbaptsolaris2.*) #(vi
1098234949Sbapt	cf_xopen_source="-D__EXTENSIONS__"
1099234949Sbapt	;;
1100234949Sbapt*)
1101234949Sbapt	CF_TRY_XOPEN_SOURCE
1102234949Sbapt	CF_POSIX_C_SOURCE($cf_POSIX_C_SOURCE)
1103234949Sbapt	;;
1104234949Sbaptesac
1105234949Sbapt
1106234949Sbaptif test -n "$cf_xopen_source" ; then
1107234949Sbapt	CF_ADD_CFLAGS($cf_xopen_source)
1108234949Sbaptfi
1109234949Sbapt
1110234949Sbaptdnl In anything but the default case, we may have system-specific setting
1111234949Sbaptdnl which is still not guaranteed to provide all of the entrypoints that
1112234949Sbaptdnl _XOPEN_SOURCE would yield.
1113234949Sbaptif test -n "$cf_XOPEN_SOURCE" && test -z "$cf_cv_xopen_source" ; then
1114234949Sbapt	AC_MSG_CHECKING(if _XOPEN_SOURCE really is set)
1115234949Sbapt	AC_TRY_COMPILE([#include <stdlib.h>],[
1116234949Sbapt#ifndef _XOPEN_SOURCE
1117234949Sbaptmake an error
1118234949Sbapt#endif],
1119234949Sbapt	[cf_XOPEN_SOURCE_set=yes],
1120234949Sbapt	[cf_XOPEN_SOURCE_set=no])
1121234949Sbapt	AC_MSG_RESULT($cf_XOPEN_SOURCE_set)
1122234949Sbapt	if test $cf_XOPEN_SOURCE_set = yes
1123234949Sbapt	then
1124234949Sbapt		AC_TRY_COMPILE([#include <stdlib.h>],[
1125234949Sbapt#if (_XOPEN_SOURCE - 0) < $cf_XOPEN_SOURCE
1126234949Sbaptmake an error
1127234949Sbapt#endif],
1128234949Sbapt		[cf_XOPEN_SOURCE_set_ok=yes],
1129234949Sbapt		[cf_XOPEN_SOURCE_set_ok=no])
1130234949Sbapt		if test $cf_XOPEN_SOURCE_set_ok = no
1131234949Sbapt		then
1132234949Sbapt			AC_MSG_WARN(_XOPEN_SOURCE is lower than requested)
1133234949Sbapt		fi
1134234949Sbapt	else
1135234949Sbapt		CF_TRY_XOPEN_SOURCE
1136234949Sbapt	fi
1137234949Sbaptfi
1138234949Sbapt])
1139