aclocal.m4 revision e0a2b6df
1dnl $XTermId: aclocal.m4,v 1.372 2013/11/20 00:24:55 tom Exp $
2dnl
3dnl ---------------------------------------------------------------------------
4dnl
5dnl Copyright 1997-2012,2013 by Thomas E. Dickey
6dnl
7dnl                         All Rights Reserved
8dnl
9dnl Permission is hereby granted, free of charge, to any person obtaining a
10dnl copy of this software and associated documentation files (the
11dnl "Software"), to deal in the Software without restriction, including
12dnl without limitation the rights to use, copy, modify, merge, publish,
13dnl distribute, sublicense, and/or sell copies of the Software, and to
14dnl permit persons to whom the Software is furnished to do so, subject to
15dnl the following conditions:
16dnl
17dnl The above copyright notice and this permission notice shall be included
18dnl in all copies or substantial portions of the Software.
19dnl
20dnl THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21dnl OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22dnl MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23dnl IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
24dnl CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25dnl TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26dnl SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27dnl
28dnl Except as contained in this notice, the name(s) of the above copyright
29dnl holders shall not be used in advertising or otherwise to promote the
30dnl sale, use or other dealings in this Software without prior written
31dnl authorization.
32dnl
33dnl ---------------------------------------------------------------------------
34dnl See
35dnl		http://invisible-island.net/autoconf/autoconf.html
36dnl ---------------------------------------------------------------------------
37dnl ---------------------------------------------------------------------------
38dnl AM_LANGINFO_CODESET version: 3 updated: 2002/10/27 23:21:42
39dnl -------------------
40dnl Inserted as requested by gettext 0.10.40
41dnl File from /usr/share/aclocal
42dnl codeset.m4
43dnl ====================
44dnl serial AM1
45dnl
46dnl From Bruno Haible.
47AC_DEFUN([AM_LANGINFO_CODESET],
48[
49  AC_CACHE_CHECK([for nl_langinfo and CODESET], am_cv_langinfo_codeset,
50    [AC_TRY_LINK([#include <langinfo.h>],
51      [char* cs = nl_langinfo(CODESET);],
52      am_cv_langinfo_codeset=yes,
53      am_cv_langinfo_codeset=no)
54    ])
55  if test $am_cv_langinfo_codeset = yes; then
56    AC_DEFINE(HAVE_LANGINFO_CODESET, 1,
57      [Define if you have <langinfo.h> and nl_langinfo(CODESET).])
58  fi
59])dnl
60dnl ---------------------------------------------------------------------------
61dnl CF_ACVERSION_CHECK version: 4 updated: 2013/03/04 19:52:56
62dnl ------------------
63dnl Conditionally generate script according to whether we're using a given autoconf.
64dnl
65dnl $1 = version to compare against
66dnl $2 = code to use if AC_ACVERSION is at least as high as $1.
67dnl $3 = code to use if AC_ACVERSION is older than $1.
68define([CF_ACVERSION_CHECK],
69[
70ifdef([AC_ACVERSION], ,[m4_copy([m4_PACKAGE_VERSION],[AC_ACVERSION])])dnl
71ifdef([m4_version_compare],
72[m4_if(m4_version_compare(m4_defn([AC_ACVERSION]), [$1]), -1, [$3], [$2])],
73[CF_ACVERSION_COMPARE(
74AC_PREREQ_CANON(AC_PREREQ_SPLIT([$1])),
75AC_PREREQ_CANON(AC_PREREQ_SPLIT(AC_ACVERSION)), AC_ACVERSION, [$2], [$3])])])dnl
76dnl ---------------------------------------------------------------------------
77dnl CF_ACVERSION_COMPARE version: 3 updated: 2012/10/03 18:39:53
78dnl --------------------
79dnl CF_ACVERSION_COMPARE(MAJOR1, MINOR1, TERNARY1,
80dnl                      MAJOR2, MINOR2, TERNARY2,
81dnl                      PRINTABLE2, not FOUND, FOUND)
82define([CF_ACVERSION_COMPARE],
83[ifelse(builtin([eval], [$2 < $5]), 1,
84[ifelse([$8], , ,[$8])],
85[ifelse([$9], , ,[$9])])])dnl
86dnl ---------------------------------------------------------------------------
87dnl CF_ADD_CFLAGS version: 10 updated: 2010/05/26 05:38:42
88dnl -------------
89dnl Copy non-preprocessor flags to $CFLAGS, preprocessor flags to $CPPFLAGS
90dnl The second parameter if given makes this macro verbose.
91dnl
92dnl Put any preprocessor definitions that use quoted strings in $EXTRA_CPPFLAGS,
93dnl to simplify use of $CPPFLAGS in compiler checks, etc., that are easily
94dnl confused by the quotes (which require backslashes to keep them usable).
95AC_DEFUN([CF_ADD_CFLAGS],
96[
97cf_fix_cppflags=no
98cf_new_cflags=
99cf_new_cppflags=
100cf_new_extra_cppflags=
101
102for cf_add_cflags in $1
103do
104case $cf_fix_cppflags in
105no)
106	case $cf_add_cflags in #(vi
107	-undef|-nostdinc*|-I*|-D*|-U*|-E|-P|-C) #(vi
108		case $cf_add_cflags in
109		-D*)
110			cf_tst_cflags=`echo ${cf_add_cflags} |sed -e 's/^-D[[^=]]*='\''\"[[^"]]*//'`
111
112			test "${cf_add_cflags}" != "${cf_tst_cflags}" \
113				&& test -z "${cf_tst_cflags}" \
114				&& cf_fix_cppflags=yes
115
116			if test $cf_fix_cppflags = yes ; then
117				cf_new_extra_cppflags="$cf_new_extra_cppflags $cf_add_cflags"
118				continue
119			elif test "${cf_tst_cflags}" = "\"'" ; then
120				cf_new_extra_cppflags="$cf_new_extra_cppflags $cf_add_cflags"
121				continue
122			fi
123			;;
124		esac
125		case "$CPPFLAGS" in
126		*$cf_add_cflags) #(vi
127			;;
128		*) #(vi
129			case $cf_add_cflags in #(vi
130			-D*)
131				cf_tst_cppflags=`echo "x$cf_add_cflags" | sed -e 's/^...//' -e 's/=.*//'`
132				CF_REMOVE_DEFINE(CPPFLAGS,$CPPFLAGS,$cf_tst_cppflags)
133				;;
134			esac
135			cf_new_cppflags="$cf_new_cppflags $cf_add_cflags"
136			;;
137		esac
138		;;
139	*)
140		cf_new_cflags="$cf_new_cflags $cf_add_cflags"
141		;;
142	esac
143	;;
144yes)
145	cf_new_extra_cppflags="$cf_new_extra_cppflags $cf_add_cflags"
146
147	cf_tst_cflags=`echo ${cf_add_cflags} |sed -e 's/^[[^"]]*"'\''//'`
148
149	test "${cf_add_cflags}" != "${cf_tst_cflags}" \
150		&& test -z "${cf_tst_cflags}" \
151		&& cf_fix_cppflags=no
152	;;
153esac
154done
155
156if test -n "$cf_new_cflags" ; then
157	ifelse([$2],,,[CF_VERBOSE(add to \$CFLAGS $cf_new_cflags)])
158	CFLAGS="$CFLAGS $cf_new_cflags"
159fi
160
161if test -n "$cf_new_cppflags" ; then
162	ifelse([$2],,,[CF_VERBOSE(add to \$CPPFLAGS $cf_new_cppflags)])
163	CPPFLAGS="$CPPFLAGS $cf_new_cppflags"
164fi
165
166if test -n "$cf_new_extra_cppflags" ; then
167	ifelse([$2],,,[CF_VERBOSE(add to \$EXTRA_CPPFLAGS $cf_new_extra_cppflags)])
168	EXTRA_CPPFLAGS="$cf_new_extra_cppflags $EXTRA_CPPFLAGS"
169fi
170
171AC_SUBST(EXTRA_CPPFLAGS)
172
173])dnl
174dnl ---------------------------------------------------------------------------
175dnl CF_ADD_LIB version: 2 updated: 2010/06/02 05:03:05
176dnl ----------
177dnl Add a library, used to enforce consistency.
178dnl
179dnl $1 = library to add, without the "-l"
180dnl $2 = variable to update (default $LIBS)
181AC_DEFUN([CF_ADD_LIB],[CF_ADD_LIBS(-l$1,ifelse($2,,LIBS,[$2]))])dnl
182dnl ---------------------------------------------------------------------------
183dnl CF_ADD_LIBS version: 1 updated: 2010/06/02 05:03:05
184dnl -----------
185dnl Add one or more libraries, used to enforce consistency.
186dnl
187dnl $1 = libraries to add, with the "-l", etc.
188dnl $2 = variable to update (default $LIBS)
189AC_DEFUN([CF_ADD_LIBS],[ifelse($2,,LIBS,[$2])="$1 [$]ifelse($2,,LIBS,[$2])"])dnl
190dnl ---------------------------------------------------------------------------
191dnl CF_ADD_LIB_AFTER version: 3 updated: 2013/07/09 21:27:22
192dnl ----------------
193dnl Add a given library after another, e.g., following the one it satisfies a
194dnl dependency for.
195dnl
196dnl $1 = the first library
197dnl $2 = its dependency
198AC_DEFUN([CF_ADD_LIB_AFTER],[
199CF_VERBOSE(...before $LIBS)
200LIBS=`echo "$LIBS" | sed -e "s/[[ 	]][[ 	]]*/ /g" -e "s%$1 %$1 $2 %" -e 's%  % %g'`
201CF_VERBOSE(...after  $LIBS)
202])dnl
203dnl ---------------------------------------------------------------------------
204dnl CF_ARG_DISABLE version: 3 updated: 1999/03/30 17:24:31
205dnl --------------
206dnl Allow user to disable a normally-on option.
207AC_DEFUN([CF_ARG_DISABLE],
208[CF_ARG_OPTION($1,[$2],[$3],[$4],yes)])dnl
209dnl ---------------------------------------------------------------------------
210dnl CF_ARG_ENABLE version: 3 updated: 1999/03/30 17:24:31
211dnl -------------
212dnl Allow user to enable a normally-off option.
213AC_DEFUN([CF_ARG_ENABLE],
214[CF_ARG_OPTION($1,[$2],[$3],[$4],no)])dnl
215dnl ---------------------------------------------------------------------------
216dnl CF_ARG_OPTION version: 4 updated: 2010/05/26 05:38:42
217dnl -------------
218dnl Restricted form of AC_ARG_ENABLE that ensures user doesn't give bogus
219dnl values.
220dnl
221dnl Parameters:
222dnl $1 = option name
223dnl $2 = help-string
224dnl $3 = action to perform if option is not default
225dnl $4 = action if perform if option is default
226dnl $5 = default option value (either 'yes' or 'no')
227AC_DEFUN([CF_ARG_OPTION],
228[AC_ARG_ENABLE([$1],[$2],[test "$enableval" != ifelse([$5],no,yes,no) && enableval=ifelse([$5],no,no,yes)
229  if test "$enableval" != "$5" ; then
230ifelse([$3],,[    :]dnl
231,[    $3]) ifelse([$4],,,[
232  else
233    $4])
234  fi],[enableval=$5 ifelse([$4],,,[
235  $4
236])dnl
237  ])])dnl
238dnl ---------------------------------------------------------------------------
239dnl CF_CC_ENV_FLAGS version: 1 updated: 2012/10/03 05:25:49
240dnl ---------------
241dnl Check for user's environment-breakage by stuffing CFLAGS/CPPFLAGS content
242dnl into CC.  This will not help with broken scripts that wrap the compiler with
243dnl options, but eliminates a more common category of user confusion.
244AC_DEFUN([CF_CC_ENV_FLAGS],
245[
246# This should have been defined by AC_PROG_CC
247: ${CC:=cc}
248
249AC_MSG_CHECKING(\$CC variable)
250case "$CC" in #(vi
251*[[\ \	]]-[[IUD]]*)
252	AC_MSG_RESULT(broken)
253	AC_MSG_WARN(your environment misuses the CC variable to hold CFLAGS/CPPFLAGS options)
254	# humor him...
255	cf_flags=`echo "$CC" | sed -e 's/^[[^ 	]]*[[ 	]]//'`
256	CC=`echo "$CC" | sed -e 's/[[ 	]].*//'`
257	CF_ADD_CFLAGS($cf_flags)
258	;;
259*)
260	AC_MSG_RESULT(ok)
261	;;
262esac
263])dnl
264dnl ---------------------------------------------------------------------------
265dnl CF_CHECK_CACHE version: 12 updated: 2012/10/02 20:55:03
266dnl --------------
267dnl Check if we're accidentally using a cache from a different machine.
268dnl Derive the system name, as a check for reusing the autoconf cache.
269dnl
270dnl If we've packaged config.guess and config.sub, run that (since it does a
271dnl better job than uname).  Normally we'll use AC_CANONICAL_HOST, but allow
272dnl an extra parameter that we may override, e.g., for AC_CANONICAL_SYSTEM
273dnl which is useful in cross-compiles.
274dnl
275dnl Note: we would use $ac_config_sub, but that is one of the places where
276dnl autoconf 2.5x broke compatibility with autoconf 2.13
277AC_DEFUN([CF_CHECK_CACHE],
278[
279if test -f $srcdir/config.guess || test -f $ac_aux_dir/config.guess ; then
280	ifelse([$1],,[AC_CANONICAL_HOST],[$1])
281	system_name="$host_os"
282else
283	system_name="`(uname -s -r) 2>/dev/null`"
284	if test -z "$system_name" ; then
285		system_name="`(hostname) 2>/dev/null`"
286	fi
287fi
288test -n "$system_name" && AC_DEFINE_UNQUOTED(SYSTEM_NAME,"$system_name",[Define to the system name.])
289AC_CACHE_VAL(cf_cv_system_name,[cf_cv_system_name="$system_name"])
290
291test -z "$system_name" && system_name="$cf_cv_system_name"
292test -n "$cf_cv_system_name" && AC_MSG_RESULT(Configuring for $cf_cv_system_name)
293
294if test ".$system_name" != ".$cf_cv_system_name" ; then
295	AC_MSG_RESULT(Cached system name ($system_name) does not agree with actual ($cf_cv_system_name))
296	AC_MSG_ERROR("Please remove config.cache and try again.")
297fi
298])dnl
299dnl ---------------------------------------------------------------------------
300dnl CF_CHECK_CFLAGS version: 2 updated: 2001/12/30 19:09:58
301dnl ---------------
302dnl Conditionally add to $CFLAGS and $CPPFLAGS values which are derived from
303dnl a build-configuration such as imake.  These have the pitfall that they
304dnl often contain compiler-specific options which we cannot use, mixed with
305dnl preprocessor options that we usually can.
306AC_DEFUN([CF_CHECK_CFLAGS],
307[
308CF_VERBOSE(checking additions to CFLAGS)
309cf_check_cflags="$CFLAGS"
310cf_check_cppflags="$CPPFLAGS"
311CF_ADD_CFLAGS($1,yes)
312if test "$cf_check_cflags" != "$CFLAGS" ; then
313AC_TRY_LINK([#include <stdio.h>],[printf("Hello world");],,
314	[CF_VERBOSE(test-compile failed.  Undoing change to \$CFLAGS)
315	 if test "$cf_check_cppflags" != "$CPPFLAGS" ; then
316		 CF_VERBOSE(but keeping change to \$CPPFLAGS)
317	 fi
318	 CFLAGS="$cf_check_flags"])
319fi
320])dnl
321dnl ---------------------------------------------------------------------------
322dnl CF_CHECK_ERRNO version: 11 updated: 2010/05/26 05:38:42
323dnl --------------
324dnl Check for data that is usually declared in <stdio.h> or <errno.h>, e.g.,
325dnl the 'errno' variable.  Define a DECL_xxx symbol if we must declare it
326dnl ourselves.
327dnl
328dnl $1 = the name to check
329dnl $2 = the assumed type
330AC_DEFUN([CF_CHECK_ERRNO],
331[
332AC_CACHE_CHECK(if external $1 is declared, cf_cv_dcl_$1,[
333    AC_TRY_COMPILE([
334#ifdef HAVE_STDLIB_H
335#include <stdlib.h>
336#endif
337#include <stdio.h>
338#include <sys/types.h>
339#include <errno.h> ],
340    ifelse([$2],,int,[$2]) x = (ifelse([$2],,int,[$2])) $1,
341    [cf_cv_dcl_$1=yes],
342    [cf_cv_dcl_$1=no])
343])
344
345if test "$cf_cv_dcl_$1" = no ; then
346    CF_UPPER(cf_result,decl_$1)
347    AC_DEFINE_UNQUOTED($cf_result)
348fi
349
350# It's possible (for near-UNIX clones) that the data doesn't exist
351CF_CHECK_EXTERN_DATA($1,ifelse([$2],,int,[$2]))
352])dnl
353dnl ---------------------------------------------------------------------------
354dnl CF_CHECK_EXTERN_DATA version: 3 updated: 2001/12/30 18:03:23
355dnl --------------------
356dnl Check for existence of external data in the current set of libraries.  If
357dnl we can modify it, it's real enough.
358dnl $1 = the name to check
359dnl $2 = its type
360AC_DEFUN([CF_CHECK_EXTERN_DATA],
361[
362AC_CACHE_CHECK(if external $1 exists, cf_cv_have_$1,[
363    AC_TRY_LINK([
364#undef $1
365extern $2 $1;
366],
367    [$1 = 2],
368    [cf_cv_have_$1=yes],
369    [cf_cv_have_$1=no])
370])
371
372if test "$cf_cv_have_$1" = yes ; then
373    CF_UPPER(cf_result,have_$1)
374    AC_DEFINE_UNQUOTED($cf_result)
375fi
376
377])dnl
378dnl ---------------------------------------------------------------------------
379dnl CF_CLANG_COMPILER version: 2 updated: 2013/11/19 19:23:35
380dnl -----------------
381dnl Check if the given compiler is really clang.  clang's C driver defines
382dnl __GNUC__ (fooling the configure script into setting $GCC to yes) but does
383dnl not ignore some gcc options.
384dnl
385dnl This macro should be run "soon" after AC_PROG_CC or AC_PROG_CPLUSPLUS, to
386dnl ensure that it is not mistaken for gcc/g++.  It is normally invoked from
387dnl the wrappers for gcc and g++ warnings.
388dnl
389dnl $1 = GCC (default) or GXX
390dnl $2 = CLANG_COMPILER (default)
391dnl $3 = CFLAGS (default) or CXXFLAGS
392AC_DEFUN([CF_CLANG_COMPILER],[
393ifelse([$2],,CLANG_COMPILER,[$2])=no
394
395if test "$ifelse([$1],,[$1],GCC)" = yes ; then
396	AC_MSG_CHECKING(if this is really Clang ifelse([$1],GXX,C++,C) compiler)
397	cf_save_CFLAGS="$ifelse([$3],,CFLAGS,[$3])"
398	ifelse([$3],,CFLAGS,[$3])="$ifelse([$3],,CFLAGS,[$3]) -Qunused-arguments"
399	AC_TRY_COMPILE([],[
400#ifdef __clang__
401#else
402make an error
403#endif
404],[ifelse([$2],,CLANG_COMPILER,[$2])=yes
405cf_save_CFLAGS="$cf_save_CFLAGS -Qunused-arguments"
406],[])
407	ifelse([$3],,CFLAGS,[$3])="$cf_save_CFLAGS"
408	AC_MSG_RESULT($ifelse([$2],,CLANG_COMPILER,[$2]))
409fi
410])
411dnl ---------------------------------------------------------------------------
412dnl CF_DISABLE_DESKTOP version: 2 updated: 2011/04/22 05:17:37
413dnl ------------------
414dnl Handle a configure option "--disable-desktop", which sets a shell
415dnl variable $desktop_utils to a "#" if the feature is not wanted, or to an
416dnl empty string if enabled.  The variable is used to substitute in front of
417dnl corresponding makefile-rules.
418dnl
419dnl It also tells the configure script to substitute the environment variable
420dnl $DESKTOP_FLAGS, which can be used by external scripts to customize the
421dnl invocation of desktop-file-util.
422dnl
423dnl $1 = program name
424AC_DEFUN([CF_DISABLE_DESKTOP],[
425# Comment-out the install-desktop rule if the desktop-utils are not found.
426AC_MSG_CHECKING(if you want to install desktop files)
427CF_ARG_OPTION(desktop,
428	[  --disable-desktop       disable install of $1 desktop files],
429	[enable_desktop=$enableval],
430	[enable_desktop=$enableval],yes)
431AC_MSG_RESULT($enable_desktop)
432
433desktop_utils=
434if test "$enable_desktop" = yes ; then
435AC_CHECK_PROG(desktop_utils,desktop-file-install,yes,no)
436fi
437
438test "$desktop_utils" = yes && desktop_utils= || desktop_utils="#"
439AC_SUBST(DESKTOP_FLAGS)
440])
441dnl ---------------------------------------------------------------------------
442dnl CF_DISABLE_ECHO version: 12 updated: 2012/10/06 16:30:28
443dnl ---------------
444dnl You can always use "make -n" to see the actual options, but it's hard to
445dnl pick out/analyze warning messages when the compile-line is long.
446dnl
447dnl Sets:
448dnl	ECHO_LT - symbol to control if libtool is verbose
449dnl	ECHO_LD - symbol to prefix "cc -o" lines
450dnl	RULE_CC - symbol to put before implicit "cc -c" lines (e.g., .c.o)
451dnl	SHOW_CC - symbol to put before explicit "cc -c" lines
452dnl	ECHO_CC - symbol to put before any "cc" line
453dnl
454AC_DEFUN([CF_DISABLE_ECHO],[
455AC_MSG_CHECKING(if you want to see long compiling messages)
456CF_ARG_DISABLE(echo,
457	[  --disable-echo          do not display "compiling" commands],
458	[
459    ECHO_LT='--silent'
460    ECHO_LD='@echo linking [$]@;'
461    RULE_CC='@echo compiling [$]<'
462    SHOW_CC='@echo compiling [$]@'
463    ECHO_CC='@'
464],[
465    ECHO_LT=''
466    ECHO_LD=''
467    RULE_CC=''
468    SHOW_CC=''
469    ECHO_CC=''
470])
471AC_MSG_RESULT($enableval)
472AC_SUBST(ECHO_LT)
473AC_SUBST(ECHO_LD)
474AC_SUBST(RULE_CC)
475AC_SUBST(SHOW_CC)
476AC_SUBST(ECHO_CC)
477])dnl
478dnl ---------------------------------------------------------------------------
479dnl CF_DISABLE_LEAKS version: 7 updated: 2012/10/02 20:55:03
480dnl ----------------
481dnl Combine no-leak checks with the libraries or tools that are used for the
482dnl checks.
483AC_DEFUN([CF_DISABLE_LEAKS],[
484
485AC_REQUIRE([CF_WITH_DMALLOC])
486AC_REQUIRE([CF_WITH_DBMALLOC])
487AC_REQUIRE([CF_WITH_VALGRIND])
488
489AC_MSG_CHECKING(if you want to perform memory-leak testing)
490AC_ARG_ENABLE(leaks,
491	[  --disable-leaks         test: free permanent memory, analyze leaks],
492	[if test "x$enableval" = xno; then with_no_leaks=yes; else with_no_leaks=no; fi],
493	: ${with_no_leaks:=no})
494AC_MSG_RESULT($with_no_leaks)
495
496if test "$with_no_leaks" = yes ; then
497	AC_DEFINE(NO_LEAKS,1,[Define to 1 if you want to perform memory-leak testing.])
498	AC_DEFINE(YY_NO_LEAKS,1,[Define to 1 if you want to perform memory-leak testing.])
499fi
500])dnl
501dnl ---------------------------------------------------------------------------
502dnl CF_DISABLE_RPATH_HACK version: 2 updated: 2011/02/13 13:31:33
503dnl ---------------------
504dnl The rpath-hack makes it simpler to build programs, particularly with the
505dnl *BSD ports which may have essential libraries in unusual places.  But it
506dnl can interfere with building an executable for the base system.  Use this
507dnl option in that case.
508AC_DEFUN([CF_DISABLE_RPATH_HACK],
509[
510AC_MSG_CHECKING(if rpath-hack should be disabled)
511CF_ARG_DISABLE(rpath-hack,
512	[  --disable-rpath-hack    don't add rpath options for additional libraries],
513	[cf_disable_rpath_hack=yes],
514	[cf_disable_rpath_hack=no])
515AC_MSG_RESULT($cf_disable_rpath_hack)
516if test "$cf_disable_rpath_hack" = no ; then
517	CF_RPATH_HACK
518fi
519])
520dnl ---------------------------------------------------------------------------
521dnl CF_ENABLE_NARROWPROTO version: 3 updated: 2006/02/12 17:46:00
522dnl ---------------------
523dnl If this is not set properly, Xaw's scrollbars will not work.
524dnl The so-called "modular" configuration for X.org omits most of the
525dnl configure checks that would be needed to provide compatibility with
526dnl older X builds.  This one breaks things noticeably.
527AC_DEFUN([CF_ENABLE_NARROWPROTO],
528[
529AC_MSG_CHECKING(if you want narrow prototypes for X libraries)
530
531case `$ac_config_guess` in #(vi
532*cygwin*|*freebsd*|*gnu*|*irix5*|*irix6*|*linux-gnu*|*netbsd*|*openbsd*|*qnx*|*sco*|*sgi*) #(vi
533	cf_default_narrowproto=yes
534	;;
535*)
536	cf_default_narrowproto=no
537	;;
538esac
539
540CF_ARG_OPTION(narrowproto,
541	[  --enable-narrowproto    enable narrow prototypes for X libraries],
542	[enable_narrowproto=$enableval],
543	[enable_narrowproto=$cf_default_narrowproto],
544	[$cf_default_narrowproto])
545AC_MSG_RESULT($enable_narrowproto)
546])
547dnl ---------------------------------------------------------------------------
548dnl CF_ERRNO version: 5 updated: 1997/11/30 12:44:39
549dnl --------
550dnl Check if 'errno' is declared in <errno.h>
551AC_DEFUN([CF_ERRNO],
552[
553CF_CHECK_ERRNO(errno)
554])dnl
555dnl ---------------------------------------------------------------------------
556dnl CF_FUNC_GRANTPT version: 10 updated: 2013/04/17 05:31:24
557dnl ---------------
558dnl Check for grantpt versus openpty, as well as functions that "should" be
559dnl available if grantpt is available.
560AC_DEFUN([CF_FUNC_GRANTPT],[
561
562AC_CHECK_HEADERS( \
563stropts.h \
564)
565
566cf_func_grantpt="grantpt ptsname"
567case $host_os in #(vi
568darwin[[0-9]].*) #(vi
569	;;
570*)
571	cf_func_grantpt="$cf_func_grantpt posix_openpt"
572	;;
573esac
574
575AC_CHECK_FUNCS($cf_func_grantpt)
576
577cf_grantpt_opts=
578if test "x$ac_cv_func_grantpt" = "xyes" ; then
579	AC_MSG_CHECKING(if grantpt really works)
580	AC_TRY_LINK(CF__GRANTPT_HEAD,CF__GRANTPT_BODY,[
581	AC_TRY_RUN(CF__GRANTPT_HEAD
582int main(void)
583{
584CF__GRANTPT_BODY
585}
586,
587,ac_cv_func_grantpt=no
588,ac_cv_func_grantpt=maybe)
589	],ac_cv_func_grantpt=no)
590	AC_MSG_RESULT($ac_cv_func_grantpt)
591
592	if test "x$ac_cv_func_grantpt" != "xno" ; then
593
594		if test "x$ac_cv_func_grantpt" = "xyes" ; then
595			AC_MSG_CHECKING(for pty features)
596dnl if we have no stropts.h, skip the checks for streams modules
597			if test "x$ac_cv_header_stropts_h" = xyes
598			then
599				cf_pty_this=0
600			else
601				cf_pty_this=3
602			fi
603
604			cf_pty_defines=
605			while test $cf_pty_this != 6
606			do
607
608				cf_pty_feature=
609				cf_pty_next=`expr $cf_pty_this + 1`
610				CF_MSG_LOG(pty feature test $cf_pty_next:5)
611				AC_TRY_RUN(#define CONFTEST $cf_pty_this
612$cf_pty_defines
613CF__GRANTPT_HEAD
614int main(void)
615{
616CF__GRANTPT_BODY
617}
618,
619[
620				case $cf_pty_next in #(vi
621				1) #(vi - streams
622					cf_pty_feature=ptem
623					;;
624				2) #(vi - streams
625					cf_pty_feature=ldterm
626					;;
627				3) #(vi - streams
628					cf_pty_feature=ttcompat
629					;;
630				4) #(vi
631					cf_pty_feature=pty_isatty
632					;;
633				5) #(vi
634					cf_pty_feature=pty_tcsetattr
635					;;
636				6) #(vi
637					cf_pty_feature=tty_tcsetattr
638					;;
639				esac
640],[
641				case $cf_pty_next in #(vi
642				1|2|3)
643					CF_MSG_LOG(skipping remaining streams features $cf_pty_this..2)
644					cf_pty_next=3
645					;;
646				esac
647])
648				if test -n "$cf_pty_feature"
649				then
650					cf_pty_defines="$cf_pty_defines
651#define CONFTEST_$cf_pty_feature 1
652"
653					cf_grantpt_opts="$cf_grantpt_opts $cf_pty_feature"
654				fi
655
656				cf_pty_this=$cf_pty_next
657			done
658			AC_MSG_RESULT($cf_grantpt_opts)
659			cf_grantpt_opts=`echo "$cf_grantpt_opts" | sed -e 's/ isatty//'`
660		fi
661	fi
662fi
663
664dnl If we found grantpt, but no features, e.g., for streams or if we are not
665dnl able to use tcsetattr, then give openpty a try.  In particular, Darwin 10.7
666dnl has a more functional openpty than posix_openpt.
667dnl
668dnl There is no configure run-test for openpty, since older implementations do
669dnl not always run properly as a non-root user.  For that reason, we also allow
670dnl the configure script to suppress this check entirely with $disable_openpty.
671if test "x$disable_openpty" != "xyes" || test -z "$cf_grantpt_opts" ; then
672	AC_CHECK_LIB(util, openpty, [cf_have_openpty=yes],[cf_have_openpty=no])
673	if test "$cf_have_openpty" = yes ; then
674		ac_cv_func_grantpt=no
675		LIBS="-lutil $LIBS"
676		AC_DEFINE(HAVE_OPENPTY,1,[Define to 1 if you have the openpty function])
677		AC_CHECK_HEADERS( \
678			util.h \
679			libutil.h \
680			pty.h \
681		)
682	fi
683fi
684
685dnl If we did not settle on using openpty, fill in the definitions for grantpt.
686if test "x$ac_cv_func_grantpt" != xno
687then
688	CF_VERBOSE(will rely upon grantpt)
689	AC_DEFINE(HAVE_WORKING_GRANTPT,1,[Define to 1 if the grantpt function seems to work])
690	for cf_feature in $cf_grantpt_opts
691	do
692		cf_feature=`echo "$cf_feature" | sed -e 's/ //g'`
693		CF_UPPER(cf_FEATURE,$cf_feature)
694		AC_DEFINE_UNQUOTED(HAVE_GRANTPT_$cf_FEATURE)
695	done
696elif test "x$cf_have_openpty" = xno
697then
698	CF_VERBOSE(will rely upon BSD-pseudoterminals)
699else
700	CF_VERBOSE(will rely upon openpty)
701fi
702])dnl
703dnl ---------------------------------------------------------------------------
704dnl CF_FUNC_TGETENT version: 19 updated: 2012/10/04 20:12:20
705dnl ---------------
706dnl Check for tgetent function in termcap library.  If we cannot find this,
707dnl we'll use the $LINES and $COLUMNS environment variables to pass screen
708dnl size information to subprocesses.  (We cannot use terminfo's compatibility
709dnl function, since it cannot provide the termcap-format data).
710dnl
711dnl If the --disable-full-tgetent option is given, we'll settle for the first
712dnl tgetent function we find.  Since the search list in that case does not
713dnl include the termcap library, that allows us to default to terminfo.
714AC_DEFUN([CF_FUNC_TGETENT],
715[
716# compute a reasonable value for $TERM to give tgetent(), since we may be
717# running in 'screen', which sets $TERMCAP to a specific entry that is not
718# necessarily in /etc/termcap - unsetenv is not portable, so we cannot simply
719# discard $TERMCAP.
720cf_TERMVAR=vt100
721if test -n "$TERMCAP"
722then
723	cf_TERMCAP=`echo "$TERMCAP" | tr '\n' ' ' | sed -e 's/^..|//' -e 's/|.*//'`
724	case "$cf_TERMCAP" in #(vi
725	screen*.*) #(vi
726		;;
727	*)
728		cf_TERMVAR="$cf_TERMCAP"
729		;;
730	esac
731fi
732test -z "$cf_TERMVAR" && cf_TERMVAR=vt100
733
734AC_MSG_CHECKING(if we want full tgetent function)
735CF_ARG_DISABLE(full-tgetent,
736	[  --disable-full-tgetent  disable check for full tgetent function],
737	cf_full_tgetent=no,
738	cf_full_tgetent=yes,yes)
739AC_MSG_RESULT($cf_full_tgetent)
740
741if test "$cf_full_tgetent" = yes ; then
742	cf_test_message="full tgetent"
743else
744	cf_test_message="tgetent"
745fi
746
747AC_CACHE_CHECK(for $cf_test_message function,cf_cv_lib_tgetent,[
748cf_save_LIBS="$LIBS"
749cf_cv_lib_tgetent=no
750if test "$cf_full_tgetent" = yes ; then
751	cf_TERMLIB="otermcap termcap termlib ncurses curses"
752	cf_TERMTST="buffer[[0]] == 0"
753else
754	cf_TERMLIB="termlib ncurses curses"
755	cf_TERMTST="0"
756fi
757for cf_termlib in '' $cf_TERMLIB ; do
758	LIBS="$cf_save_LIBS"
759	test -n "$cf_termlib" && CF_ADD_LIB($cf_termlib)
760	AC_TRY_RUN([
761/* terminfo implementations ignore the buffer argument, making it useless for
762 * the xterm application, which uses this information to make a new TERMCAP
763 * environment variable.
764 */
765int main()
766{
767	char buffer[1024];
768	buffer[0] = 0;
769	tgetent(buffer, "$cf_TERMVAR");
770	${cf_cv_main_return:-return} ($cf_TERMTST); }],
771	[echo "yes, there is a termcap/tgetent in $cf_termlib" 1>&AC_FD_CC
772	 if test -n "$cf_termlib" ; then
773	 	cf_cv_lib_tgetent="-l$cf_termlib"
774	 else
775	 	cf_cv_lib_tgetent=yes
776	 fi
777	 break],
778	[echo "no, there is no termcap/tgetent in $cf_termlib" 1>&AC_FD_CC],
779	[echo "cross-compiling, cannot verify if a termcap/tgetent is present in $cf_termlib" 1>&AC_FD_CC])
780done
781LIBS="$cf_save_LIBS"
782])
783
784# If we found a working tgetent(), set LIBS and check for termcap.h.
785# (LIBS cannot be set inside AC_CACHE_CHECK; the commands there should
786# not have side effects other than setting the cache variable, because
787# they are not executed when a cached value exists.)
788if test "x$cf_cv_lib_tgetent" != xno ; then
789	test "x$cf_cv_lib_tgetent" != xyes && CF_ADD_LIBS($cf_cv_lib_tgetent)
790	AC_DEFINE(USE_TERMCAP,1,[Define 1 to indicate that working tgetent is found])
791	if test "$cf_full_tgetent" = no ; then
792		AC_TRY_COMPILE([
793#include <termcap.h>],[
794#ifdef NCURSES_VERSION
795make an error
796#endif],[AC_DEFINE(HAVE_TERMCAP_H)])
797	else
798		AC_CHECK_HEADERS(termcap.h)
799	fi
800else
801        # If we didn't find a tgetent() that supports the buffer
802        # argument, look again to see whether we can find even
803        # a crippled one.  A crippled tgetent() is still useful to
804        # validate values for the TERM environment variable given to
805        # child processes.
806	AC_CACHE_CHECK(for partial tgetent function,cf_cv_lib_part_tgetent,[
807	cf_cv_lib_part_tgetent=no
808	for cf_termlib in $cf_TERMLIB ; do
809		LIBS="$cf_save_LIBS -l$cf_termlib"
810		AC_TRY_LINK([],[tgetent(0, "$cf_TERMVAR")],
811			[echo "there is a terminfo/tgetent in $cf_termlib" 1>&AC_FD_CC
812			 cf_cv_lib_part_tgetent="-l$cf_termlib"
813			 break])
814	done
815	LIBS="$cf_save_LIBS"
816	])
817
818	if test "$cf_cv_lib_part_tgetent" != no ; then
819		CF_ADD_LIBS($cf_cv_lib_part_tgetent)
820		AC_CHECK_HEADERS(termcap.h)
821
822                # If this is linking against ncurses, we'll trigger the
823                # ifdef in resize.c that turns the termcap stuff back off.
824		AC_DEFINE(USE_TERMINFO,1,[Define to 1 to indicate that terminfo provides the tgetent interface])
825	fi
826fi
827])dnl
828dnl ---------------------------------------------------------------------------
829dnl CF_GCC_ATTRIBUTES version: 16 updated: 2012/10/02 20:55:03
830dnl -----------------
831dnl Test for availability of useful gcc __attribute__ directives to quiet
832dnl compiler warnings.  Though useful, not all are supported -- and contrary
833dnl to documentation, unrecognized directives cause older compilers to barf.
834AC_DEFUN([CF_GCC_ATTRIBUTES],
835[
836if test "$GCC" = yes
837then
838cat > conftest.i <<EOF
839#ifndef GCC_PRINTF
840#define GCC_PRINTF 0
841#endif
842#ifndef GCC_SCANF
843#define GCC_SCANF 0
844#endif
845#ifndef GCC_NORETURN
846#define GCC_NORETURN /* nothing */
847#endif
848#ifndef GCC_UNUSED
849#define GCC_UNUSED /* nothing */
850#endif
851EOF
852if test "$GCC" = yes
853then
854	AC_CHECKING([for $CC __attribute__ directives])
855cat > conftest.$ac_ext <<EOF
856#line __oline__ "${as_me:-configure}"
857#include "confdefs.h"
858#include "conftest.h"
859#include "conftest.i"
860#if	GCC_PRINTF
861#define GCC_PRINTFLIKE(fmt,var) __attribute__((format(printf,fmt,var)))
862#else
863#define GCC_PRINTFLIKE(fmt,var) /*nothing*/
864#endif
865#if	GCC_SCANF
866#define GCC_SCANFLIKE(fmt,var)  __attribute__((format(scanf,fmt,var)))
867#else
868#define GCC_SCANFLIKE(fmt,var)  /*nothing*/
869#endif
870extern void wow(char *,...) GCC_SCANFLIKE(1,2);
871extern void oops(char *,...) GCC_PRINTFLIKE(1,2) GCC_NORETURN;
872extern void foo(void) GCC_NORETURN;
873int main(int argc GCC_UNUSED, char *argv[[]] GCC_UNUSED) { return 0; }
874EOF
875	cf_printf_attribute=no
876	cf_scanf_attribute=no
877	for cf_attribute in scanf printf unused noreturn
878	do
879		CF_UPPER(cf_ATTRIBUTE,$cf_attribute)
880		cf_directive="__attribute__(($cf_attribute))"
881		echo "checking for $CC $cf_directive" 1>&AC_FD_CC
882
883		case $cf_attribute in #(vi
884		printf) #(vi
885			cf_printf_attribute=yes
886			cat >conftest.h <<EOF
887#define GCC_$cf_ATTRIBUTE 1
888EOF
889			;;
890		scanf) #(vi
891			cf_scanf_attribute=yes
892			cat >conftest.h <<EOF
893#define GCC_$cf_ATTRIBUTE 1
894EOF
895			;;
896		*) #(vi
897			cat >conftest.h <<EOF
898#define GCC_$cf_ATTRIBUTE $cf_directive
899EOF
900			;;
901		esac
902
903		if AC_TRY_EVAL(ac_compile); then
904			test -n "$verbose" && AC_MSG_RESULT(... $cf_attribute)
905			cat conftest.h >>confdefs.h
906			case $cf_attribute in #(vi
907			noreturn) #(vi
908				AC_DEFINE_UNQUOTED(GCC_NORETURN,$cf_directive,[Define to noreturn-attribute for gcc])
909				;;
910			printf) #(vi
911				cf_value='/* nothing */'
912				if test "$cf_printf_attribute" != no ; then
913					cf_value='__attribute__((format(printf,fmt,var)))'
914					AC_DEFINE(GCC_PRINTF,1,[Define to 1 if the compiler supports gcc-like printf attribute.])
915				fi
916				AC_DEFINE_UNQUOTED(GCC_PRINTFLIKE(fmt,var),$cf_value,[Define to printf-attribute for gcc])
917				;;
918			scanf) #(vi
919				cf_value='/* nothing */'
920				if test "$cf_scanf_attribute" != no ; then
921					cf_value='__attribute__((format(scanf,fmt,var)))'
922					AC_DEFINE(GCC_SCANF,1,[Define to 1 if the compiler supports gcc-like scanf attribute.])
923				fi
924				AC_DEFINE_UNQUOTED(GCC_SCANFLIKE(fmt,var),$cf_value,[Define to sscanf-attribute for gcc])
925				;;
926			unused) #(vi
927				AC_DEFINE_UNQUOTED(GCC_UNUSED,$cf_directive,[Define to unused-attribute for gcc])
928				;;
929			esac
930		fi
931	done
932else
933	fgrep define conftest.i >>confdefs.h
934fi
935rm -rf conftest*
936fi
937])dnl
938dnl ---------------------------------------------------------------------------
939dnl CF_GCC_VERSION version: 7 updated: 2012/10/18 06:46:33
940dnl --------------
941dnl Find version of gcc
942AC_DEFUN([CF_GCC_VERSION],[
943AC_REQUIRE([AC_PROG_CC])
944GCC_VERSION=none
945if test "$GCC" = yes ; then
946	AC_MSG_CHECKING(version of $CC)
947	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.]].*//'`"
948	test -z "$GCC_VERSION" && GCC_VERSION=unknown
949	AC_MSG_RESULT($GCC_VERSION)
950fi
951])dnl
952dnl ---------------------------------------------------------------------------
953dnl CF_GCC_WARNINGS version: 31 updated: 2013/11/19 19:23:35
954dnl ---------------
955dnl Check if the compiler supports useful warning options.  There's a few that
956dnl we don't use, simply because they're too noisy:
957dnl
958dnl	-Wconversion (useful in older versions of gcc, but not in gcc 2.7.x)
959dnl	-Wredundant-decls (system headers make this too noisy)
960dnl	-Wtraditional (combines too many unrelated messages, only a few useful)
961dnl	-Wwrite-strings (too noisy, but should review occasionally).  This
962dnl		is enabled for ncurses using "--enable-const".
963dnl	-pedantic
964dnl
965dnl Parameter:
966dnl	$1 is an optional list of gcc warning flags that a particular
967dnl		application might want to use, e.g., "no-unused" for
968dnl		-Wno-unused
969dnl Special:
970dnl	If $with_ext_const is "yes", add a check for -Wwrite-strings
971dnl
972AC_DEFUN([CF_GCC_WARNINGS],
973[
974AC_REQUIRE([CF_GCC_VERSION])
975CF_INTEL_COMPILER(GCC,INTEL_COMPILER,CFLAGS)
976CF_CLANG_COMPILER(GCC,CLANG_COMPILER,CFLAGS)
977
978cat > conftest.$ac_ext <<EOF
979#line __oline__ "${as_me:-configure}"
980int main(int argc, char *argv[[]]) { return (argv[[argc-1]] == 0) ; }
981EOF
982
983if test "$INTEL_COMPILER" = yes
984then
985# The "-wdXXX" options suppress warnings:
986# remark #1419: external declaration in primary source file
987# remark #1683: explicit conversion of a 64-bit integral type to a smaller integral type (potential portability problem)
988# remark #1684: conversion from pointer to same-sized integral type (potential portability problem)
989# remark #193: zero used for undefined preprocessing identifier
990# remark #593: variable "curs_sb_left_arrow" was set but never used
991# remark #810: conversion from "int" to "Dimension={unsigned short}" may lose significant bits
992# remark #869: parameter "tw" was never referenced
993# remark #981: operands are evaluated in unspecified order
994# warning #279: controlling expression is constant
995
996	AC_CHECKING([for $CC warning options])
997	cf_save_CFLAGS="$CFLAGS"
998	EXTRA_CFLAGS="-Wall"
999	for cf_opt in \
1000		wd1419 \
1001		wd1683 \
1002		wd1684 \
1003		wd193 \
1004		wd593 \
1005		wd279 \
1006		wd810 \
1007		wd869 \
1008		wd981
1009	do
1010		CFLAGS="$cf_save_CFLAGS $EXTRA_CFLAGS -$cf_opt"
1011		if AC_TRY_EVAL(ac_compile); then
1012			test -n "$verbose" && AC_MSG_RESULT(... -$cf_opt)
1013			EXTRA_CFLAGS="$EXTRA_CFLAGS -$cf_opt"
1014		fi
1015	done
1016	CFLAGS="$cf_save_CFLAGS"
1017
1018elif test "$GCC" = yes
1019then
1020	AC_CHECKING([for $CC warning options])
1021	cf_save_CFLAGS="$CFLAGS"
1022	EXTRA_CFLAGS=
1023	cf_warn_CONST=""
1024	test "$with_ext_const" = yes && cf_warn_CONST="Wwrite-strings"
1025	cf_gcc_warnings="Wignored-qualifiers Wlogical-op Wvarargs"
1026	test "x$CLANG_COMPILER" = xyes && cf_gcc_warnings=
1027	for cf_opt in W Wall \
1028		Wbad-function-cast \
1029		Wcast-align \
1030		Wcast-qual \
1031		Wdeclaration-after-statement \
1032		Wextra \
1033		Winline \
1034		Wmissing-declarations \
1035		Wmissing-prototypes \
1036		Wnested-externs \
1037		Wpointer-arith \
1038		Wshadow \
1039		Wstrict-prototypes \
1040		Wundef $cf_gcc_warnings $cf_warn_CONST $1
1041	do
1042		CFLAGS="$cf_save_CFLAGS $EXTRA_CFLAGS -$cf_opt"
1043		if AC_TRY_EVAL(ac_compile); then
1044			test -n "$verbose" && AC_MSG_RESULT(... -$cf_opt)
1045			case $cf_opt in #(vi
1046			Wcast-qual) #(vi
1047				CPPFLAGS="$CPPFLAGS -DXTSTRINGDEFINES"
1048				;;
1049			Winline) #(vi
1050				case $GCC_VERSION in
1051				[[34]].*)
1052					CF_VERBOSE(feature is broken in gcc $GCC_VERSION)
1053					continue;;
1054				esac
1055				;;
1056			Wpointer-arith) #(vi
1057				case $GCC_VERSION in
1058				[[12]].*)
1059					CF_VERBOSE(feature is broken in gcc $GCC_VERSION)
1060					continue;;
1061				esac
1062				;;
1063			esac
1064			EXTRA_CFLAGS="$EXTRA_CFLAGS -$cf_opt"
1065		fi
1066	done
1067	CFLAGS="$cf_save_CFLAGS"
1068fi
1069rm -rf conftest*
1070
1071AC_SUBST(EXTRA_CFLAGS)
1072])dnl
1073dnl ---------------------------------------------------------------------------
1074dnl CF_GNU_SOURCE version: 6 updated: 2005/07/09 13:23:07
1075dnl -------------
1076dnl Check if we must define _GNU_SOURCE to get a reasonable value for
1077dnl _XOPEN_SOURCE, upon which many POSIX definitions depend.  This is a defect
1078dnl (or misfeature) of glibc2, which breaks portability of many applications,
1079dnl since it is interwoven with GNU extensions.
1080dnl
1081dnl Well, yes we could work around it...
1082AC_DEFUN([CF_GNU_SOURCE],
1083[
1084AC_CACHE_CHECK(if we must define _GNU_SOURCE,cf_cv_gnu_source,[
1085AC_TRY_COMPILE([#include <sys/types.h>],[
1086#ifndef _XOPEN_SOURCE
1087make an error
1088#endif],
1089	[cf_cv_gnu_source=no],
1090	[cf_save="$CPPFLAGS"
1091	 CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
1092	 AC_TRY_COMPILE([#include <sys/types.h>],[
1093#ifdef _XOPEN_SOURCE
1094make an error
1095#endif],
1096	[cf_cv_gnu_source=no],
1097	[cf_cv_gnu_source=yes])
1098	CPPFLAGS="$cf_save"
1099	])
1100])
1101test "$cf_cv_gnu_source" = yes && CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
1102])dnl
1103dnl ---------------------------------------------------------------------------
1104dnl CF_HELP_MESSAGE version: 3 updated: 1998/01/14 10:56:23
1105dnl ---------------
1106dnl Insert text into the help-message, for readability, from AC_ARG_WITH.
1107AC_DEFUN([CF_HELP_MESSAGE],
1108[AC_DIVERT_HELP([$1])dnl
1109])dnl
1110dnl ---------------------------------------------------------------------------
1111dnl CF_IMAKE_CFLAGS version: 31 updated: 2010/05/26 05:38:42
1112dnl ---------------
1113dnl Use imake to obtain compiler flags.  We could, in principle, write tests to
1114dnl get these, but if imake is properly configured there is no point in doing
1115dnl this.
1116dnl
1117dnl Parameters (used in constructing a sample Imakefile):
1118dnl	$1 = optional value to append to $IMAKE_CFLAGS
1119dnl	$2 = optional value to append to $IMAKE_LOADFLAGS
1120AC_DEFUN([CF_IMAKE_CFLAGS],
1121[
1122AC_PATH_PROGS(IMAKE,xmkmf imake)
1123
1124if test -n "$IMAKE" ; then
1125
1126case $IMAKE in # (vi
1127*/imake)
1128	cf_imake_opts="-DUseInstalled=YES" # (vi
1129	;;
1130*/util/xmkmf)
1131	# A single parameter tells xmkmf where the config-files are:
1132	cf_imake_opts="`echo $IMAKE|sed -e s,/config/util/xmkmf,,`" # (vi
1133	;;
1134*)
1135	cf_imake_opts=
1136	;;
1137esac
1138
1139# If it's installed properly, imake (or its wrapper, xmkmf) will point to the
1140# config directory.
1141if mkdir conftestdir; then
1142	CDPATH=; export CDPATH
1143	cf_makefile=`cd $srcdir;pwd`/Imakefile
1144	cd conftestdir
1145
1146	cat >fix_cflags.sed <<'CF_EOF'
1147s/\\//g
1148s/[[ 	]][[ 	]]*/ /g
1149s/"//g
1150:pack
1151s/\(=[[^ ]][[^ ]]*\) \([[^-]]\)/\1	\2/g
1152t pack
1153s/\(-D[[a-zA-Z0-9_]][[a-zA-Z0-9_]]*\)=\([[^\'0-9 ]][[^ ]]*\)/\1='\\"\2\\"'/g
1154s/^IMAKE[[ ]]/IMAKE_CFLAGS="/
1155s/	/ /g
1156s/$/"/
1157CF_EOF
1158
1159	cat >fix_lflags.sed <<'CF_EOF'
1160s/^IMAKE[[ 	]]*/IMAKE_LOADFLAGS="/
1161s/$/"/
1162CF_EOF
1163
1164	echo >./Imakefile
1165	test -f $cf_makefile && cat $cf_makefile >>./Imakefile
1166
1167	cat >> ./Imakefile <<'CF_EOF'
1168findstddefs:
1169	@echo IMAKE ${ALLDEFINES}ifelse([$1],,,[ $1])       | sed -f fix_cflags.sed
1170	@echo IMAKE ${EXTRA_LOAD_FLAGS}ifelse([$2],,,[ $2]) | sed -f fix_lflags.sed
1171CF_EOF
1172
1173	if ( $IMAKE $cf_imake_opts 1>/dev/null 2>&AC_FD_CC && test -f Makefile)
1174	then
1175		CF_VERBOSE(Using $IMAKE $cf_imake_opts)
1176	else
1177		# sometimes imake doesn't have the config path compiled in.  Find it.
1178		cf_config=
1179		for cf_libpath in $X_LIBS $LIBS ; do
1180			case $cf_libpath in # (vi
1181			-L*)
1182				cf_libpath=`echo .$cf_libpath | sed -e 's/^...//'`
1183				cf_libpath=$cf_libpath/X11/config
1184				if test -d $cf_libpath ; then
1185					cf_config=$cf_libpath
1186					break
1187				fi
1188				;;
1189			esac
1190		done
1191		if test -z "$cf_config" ; then
1192			AC_MSG_WARN(Could not find imake config-directory)
1193		else
1194			cf_imake_opts="$cf_imake_opts -I$cf_config"
1195			if ( $IMAKE -v $cf_imake_opts 2>&AC_FD_CC)
1196			then
1197				CF_VERBOSE(Using $IMAKE $cf_config)
1198			else
1199				AC_MSG_WARN(Cannot run $IMAKE)
1200			fi
1201		fi
1202	fi
1203
1204	# GNU make sometimes prints "make[1]: Entering...", which
1205	# would confuse us.
1206	eval `make findstddefs 2>/dev/null | grep -v make`
1207
1208	cd ..
1209	rm -rf conftestdir
1210
1211	# We use ${ALLDEFINES} rather than ${STD_DEFINES} because the former
1212	# declares XTFUNCPROTO there.  However, some vendors (e.g., SGI) have
1213	# modified it to support site.cf, adding a kludge for the /usr/include
1214	# directory.  Try to filter that out, otherwise gcc won't find its
1215	# headers.
1216	if test -n "$GCC" ; then
1217	    if test -n "$IMAKE_CFLAGS" ; then
1218		cf_nostdinc=""
1219		cf_std_incl=""
1220		cf_cpp_opts=""
1221		for cf_opt in $IMAKE_CFLAGS
1222		do
1223		    case "$cf_opt" in
1224		    -nostdinc) #(vi
1225			cf_nostdinc="$cf_opt"
1226			;;
1227		    -I/usr/include) #(vi
1228			cf_std_incl="$cf_opt"
1229			;;
1230		    *) #(vi
1231			cf_cpp_opts="$cf_cpp_opts $cf_opt"
1232			;;
1233		    esac
1234		done
1235		if test -z "$cf_nostdinc" ; then
1236		    IMAKE_CFLAGS="$cf_cpp_opts $cf_std_incl"
1237		elif test -z "$cf_std_incl" ; then
1238		    IMAKE_CFLAGS="$cf_cpp_opts $cf_nostdinc"
1239		else
1240		    CF_VERBOSE(suppressed \"$cf_nostdinc\" and \"$cf_std_incl\")
1241		    IMAKE_CFLAGS="$cf_cpp_opts"
1242		fi
1243	    fi
1244	fi
1245fi
1246
1247# Some imake configurations define PROJECTROOT with an empty value.  Remove
1248# the empty definition.
1249case $IMAKE_CFLAGS in
1250*-DPROJECTROOT=/*)
1251	;;
1252*)
1253	IMAKE_CFLAGS=`echo "$IMAKE_CFLAGS" |sed -e "s,-DPROJECTROOT=[[ 	]], ,"`
1254	;;
1255esac
1256
1257fi
1258
1259CF_VERBOSE(IMAKE_CFLAGS $IMAKE_CFLAGS)
1260CF_VERBOSE(IMAKE_LOADFLAGS $IMAKE_LOADFLAGS)
1261
1262AC_SUBST(IMAKE_CFLAGS)
1263AC_SUBST(IMAKE_LOADFLAGS)
1264])dnl
1265dnl ---------------------------------------------------------------------------
1266dnl CF_INPUT_METHOD version: 3 updated: 2000/04/11 23:46:57
1267dnl ---------------
1268dnl Check if the X libraries support input-method
1269AC_DEFUN([CF_INPUT_METHOD],
1270[
1271AC_CACHE_CHECK([if X libraries support input-method],cf_cv_input_method,[
1272AC_TRY_LINK([
1273#include <X11/IntrinsicP.h>
1274#include <X11/Xatom.h>
1275#include <X11/Xutil.h>
1276#include <X11/Xmu/Atoms.h>
1277#include <X11/Xmu/Converters.h>
1278#include <X11/Xaw/XawImP.h>
1279],[
1280{
1281	XIM xim;
1282	XIMStyles *xim_styles = 0;
1283	XIMStyle input_style;
1284	Widget w = 0;
1285
1286	XSetLocaleModifiers("@im=none");
1287	xim = XOpenIM(XtDisplay(w), NULL, NULL, NULL);
1288	XGetIMValues(xim, XNQueryInputStyle, &xim_styles, NULL);
1289	XCloseIM(xim);
1290	input_style = (XIMPreeditNothing | XIMStatusNothing);
1291}
1292],
1293[cf_cv_input_method=yes],
1294[cf_cv_input_method=no])])
1295])dnl
1296dnl ---------------------------------------------------------------------------
1297dnl CF_INTEL_COMPILER version: 5 updated: 2013/02/10 10:41:05
1298dnl -----------------
1299dnl Check if the given compiler is really the Intel compiler for Linux.  It
1300dnl tries to imitate gcc, but does not return an error when it finds a mismatch
1301dnl between prototypes, e.g., as exercised by CF_MISSING_CHECK.
1302dnl
1303dnl This macro should be run "soon" after AC_PROG_CC or AC_PROG_CPLUSPLUS, to
1304dnl ensure that it is not mistaken for gcc/g++.  It is normally invoked from
1305dnl the wrappers for gcc and g++ warnings.
1306dnl
1307dnl $1 = GCC (default) or GXX
1308dnl $2 = INTEL_COMPILER (default) or INTEL_CPLUSPLUS
1309dnl $3 = CFLAGS (default) or CXXFLAGS
1310AC_DEFUN([CF_INTEL_COMPILER],[
1311AC_REQUIRE([AC_CANONICAL_HOST])
1312ifelse([$2],,INTEL_COMPILER,[$2])=no
1313
1314if test "$ifelse([$1],,[$1],GCC)" = yes ; then
1315	case $host_os in
1316	linux*|gnu*)
1317		AC_MSG_CHECKING(if this is really Intel ifelse([$1],GXX,C++,C) compiler)
1318		cf_save_CFLAGS="$ifelse([$3],,CFLAGS,[$3])"
1319		ifelse([$3],,CFLAGS,[$3])="$ifelse([$3],,CFLAGS,[$3]) -no-gcc"
1320		AC_TRY_COMPILE([],[
1321#ifdef __INTEL_COMPILER
1322#else
1323make an error
1324#endif
1325],[ifelse([$2],,INTEL_COMPILER,[$2])=yes
1326cf_save_CFLAGS="$cf_save_CFLAGS -we147 -no-gcc"
1327],[])
1328		ifelse([$3],,CFLAGS,[$3])="$cf_save_CFLAGS"
1329		AC_MSG_RESULT($ifelse([$2],,INTEL_COMPILER,[$2]))
1330		;;
1331	esac
1332fi
1333])dnl
1334dnl ---------------------------------------------------------------------------
1335dnl CF_LASTLOG version: 5 updated: 2012/10/04 20:12:20
1336dnl ----------
1337dnl Check for header defining _PATH_LASTLOG, or failing that, see if the lastlog
1338dnl file exists.
1339AC_DEFUN([CF_LASTLOG],
1340[
1341AC_CHECK_HEADERS(lastlog.h paths.h)
1342AC_CACHE_CHECK(for lastlog path,cf_cv_path_lastlog,[
1343AC_TRY_COMPILE([
1344#include <sys/types.h>
1345#ifdef HAVE_LASTLOG_H
1346#include <lastlog.h>
1347#else
1348#ifdef HAVE_PATHS_H
1349#include <paths.h>
1350#endif
1351#endif],[char *path = _PATH_LASTLOG],
1352	[cf_cv_path_lastlog="_PATH_LASTLOG"],
1353	[if test -f /usr/adm/lastlog ; then
1354	 	cf_cv_path_lastlog=/usr/adm/lastlog
1355	else
1356		cf_cv_path_lastlog=no
1357	fi])
1358])
1359test $cf_cv_path_lastlog != no && AC_DEFINE(USE_LASTLOG,1,[Define to 1 if we can define lastlog pathname])
1360])dnl
1361dnl ---------------------------------------------------------------------------
1362dnl CF_LD_RPATH_OPT version: 5 updated: 2011/07/17 14:48:41
1363dnl ---------------
1364dnl For the given system and compiler, find the compiler flags to pass to the
1365dnl loader to use the "rpath" feature.
1366AC_DEFUN([CF_LD_RPATH_OPT],
1367[
1368AC_REQUIRE([CF_CHECK_CACHE])
1369
1370LD_RPATH_OPT=
1371AC_MSG_CHECKING(for an rpath option)
1372case $cf_cv_system_name in #(vi
1373irix*) #(vi
1374	if test "$GCC" = yes; then
1375		LD_RPATH_OPT="-Wl,-rpath,"
1376	else
1377		LD_RPATH_OPT="-rpath "
1378	fi
1379	;;
1380linux*|gnu*|k*bsd*-gnu) #(vi
1381	LD_RPATH_OPT="-Wl,-rpath,"
1382	;;
1383openbsd[[2-9]].*|mirbsd*) #(vi
1384	LD_RPATH_OPT="-Wl,-rpath,"
1385	;;
1386dragonfly*|freebsd*) #(vi
1387	LD_RPATH_OPT="-rpath "
1388	;;
1389netbsd*) #(vi
1390	LD_RPATH_OPT="-Wl,-rpath,"
1391	;;
1392osf*|mls+*) #(vi
1393	LD_RPATH_OPT="-rpath "
1394	;;
1395solaris2*) #(vi
1396	LD_RPATH_OPT="-R"
1397	;;
1398*)
1399	;;
1400esac
1401AC_MSG_RESULT($LD_RPATH_OPT)
1402
1403case "x$LD_RPATH_OPT" in #(vi
1404x-R*)
1405	AC_MSG_CHECKING(if we need a space after rpath option)
1406	cf_save_LIBS="$LIBS"
1407	CF_ADD_LIBS(${LD_RPATH_OPT}$libdir)
1408	AC_TRY_LINK(, , cf_rpath_space=no, cf_rpath_space=yes)
1409	LIBS="$cf_save_LIBS"
1410	AC_MSG_RESULT($cf_rpath_space)
1411	test "$cf_rpath_space" = yes && LD_RPATH_OPT="$LD_RPATH_OPT "
1412	;;
1413esac
1414])dnl
1415dnl ---------------------------------------------------------------------------
1416dnl CF_MAKE_TAGS version: 6 updated: 2010/10/23 15:52:32
1417dnl ------------
1418dnl Generate tags/TAGS targets for makefiles.  Do not generate TAGS if we have
1419dnl a monocase filesystem.
1420AC_DEFUN([CF_MAKE_TAGS],[
1421AC_REQUIRE([CF_MIXEDCASE_FILENAMES])
1422
1423AC_CHECK_PROGS(CTAGS, exctags ctags)
1424AC_CHECK_PROGS(ETAGS, exetags etags)
1425
1426AC_CHECK_PROG(MAKE_LOWER_TAGS, ${CTAGS:-ctags}, yes, no)
1427
1428if test "$cf_cv_mixedcase" = yes ; then
1429	AC_CHECK_PROG(MAKE_UPPER_TAGS, ${ETAGS:-etags}, yes, no)
1430else
1431	MAKE_UPPER_TAGS=no
1432fi
1433
1434if test "$MAKE_UPPER_TAGS" = yes ; then
1435	MAKE_UPPER_TAGS=
1436else
1437	MAKE_UPPER_TAGS="#"
1438fi
1439
1440if test "$MAKE_LOWER_TAGS" = yes ; then
1441	MAKE_LOWER_TAGS=
1442else
1443	MAKE_LOWER_TAGS="#"
1444fi
1445
1446AC_SUBST(CTAGS)
1447AC_SUBST(ETAGS)
1448
1449AC_SUBST(MAKE_UPPER_TAGS)
1450AC_SUBST(MAKE_LOWER_TAGS)
1451])dnl
1452dnl ---------------------------------------------------------------------------
1453dnl CF_MIXEDCASE_FILENAMES version: 6 updated: 2013/10/08 17:47:05
1454dnl ----------------------
1455dnl Check if the file-system supports mixed-case filenames.  If we're able to
1456dnl create a lowercase name and see it as uppercase, it doesn't support that.
1457AC_DEFUN([CF_MIXEDCASE_FILENAMES],
1458[
1459AC_CACHE_CHECK(if filesystem supports mixed-case filenames,cf_cv_mixedcase,[
1460if test "$cross_compiling" = yes ; then
1461	case $target_alias in #(vi
1462	*-os2-emx*|*-msdosdjgpp*|*-cygwin*|*-msys*|*-mingw*|*-uwin*) #(vi
1463		cf_cv_mixedcase=no
1464		;;
1465	*)
1466		cf_cv_mixedcase=yes
1467		;;
1468	esac
1469else
1470	rm -f conftest CONFTEST
1471	echo test >conftest
1472	if test -f CONFTEST ; then
1473		cf_cv_mixedcase=no
1474	else
1475		cf_cv_mixedcase=yes
1476	fi
1477	rm -f conftest CONFTEST
1478fi
1479])
1480test "$cf_cv_mixedcase" = yes && AC_DEFINE(MIXEDCASE_FILENAMES,1,[Define to 1 if filesystem supports mixed-case filenames.])
1481])dnl
1482dnl ---------------------------------------------------------------------------
1483dnl CF_MSG_LOG version: 5 updated: 2010/10/23 15:52:32
1484dnl ----------
1485dnl Write a debug message to config.log, along with the line number in the
1486dnl configure script.
1487AC_DEFUN([CF_MSG_LOG],[
1488echo "${as_me:-configure}:__oline__: testing $* ..." 1>&AC_FD_CC
1489])dnl
1490dnl ---------------------------------------------------------------------------
1491dnl CF_NO_LEAKS_OPTION version: 5 updated: 2012/10/02 20:55:03
1492dnl ------------------
1493dnl see CF_WITH_NO_LEAKS
1494AC_DEFUN([CF_NO_LEAKS_OPTION],[
1495AC_MSG_CHECKING(if you want to use $1 for testing)
1496AC_ARG_WITH($1,
1497	[$2],
1498	[AC_DEFINE_UNQUOTED($3,1,"Define to 1 if you want to use $1 for testing.")ifelse([$4],,[
1499	 $4
1500])
1501	: ${with_cflags:=-g}
1502	: ${with_no_leaks:=yes}
1503	 with_$1=yes],
1504	[with_$1=])
1505AC_MSG_RESULT(${with_$1:-no})
1506
1507case .$with_cflags in #(vi
1508.*-g*)
1509	case .$CFLAGS in #(vi
1510	.*-g*) #(vi
1511		;;
1512	*)
1513		CF_ADD_CFLAGS([-g])
1514		;;
1515	esac
1516	;;
1517esac
1518])dnl
1519dnl ---------------------------------------------------------------------------
1520dnl CF_PATHSEP version: 6 updated: 2012/09/29 18:38:12
1521dnl ----------
1522dnl Provide a value for the $PATH and similar separator (or amend the value
1523dnl as provided in autoconf 2.5x).
1524AC_DEFUN([CF_PATHSEP],
1525[
1526	AC_MSG_CHECKING(for PATH separator)
1527	case $cf_cv_system_name in
1528	os2*)	PATH_SEPARATOR=';'  ;;
1529	*)	${PATH_SEPARATOR:=':'}  ;;
1530	esac
1531ifelse([$1],,,[$1=$PATH_SEPARATOR])
1532	AC_SUBST(PATH_SEPARATOR)
1533	AC_MSG_RESULT($PATH_SEPARATOR)
1534])dnl
1535dnl ---------------------------------------------------------------------------
1536dnl CF_PATH_PROG version: 9 updated: 2012/10/04 20:12:20
1537dnl ------------
1538dnl Check for a given program, defining corresponding symbol.
1539dnl	$1 = environment variable, which is suffixed by "_PATH" in the #define.
1540dnl	$2 = program name to find.
1541dnl	$3 = optional list of additional program names to test.
1542dnl
1543dnl If there is more than one token in the result, #define the remaining tokens
1544dnl to $1_ARGS.  We need this for 'install' in particular.
1545dnl
1546dnl FIXME: we should allow this to be overridden by environment variables
1547dnl
1548AC_DEFUN([CF_PATH_PROG],[
1549AC_REQUIRE([CF_PATHSEP])
1550test -z "[$]$1" && $1=$2
1551AC_PATH_PROGS($1,[$]$1 $2 $3,[$]$1)
1552
1553cf_path_prog=""
1554cf_path_args=""
1555IFS="${IFS:- 	}"; cf_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR"
1556for cf_temp in $ac_cv_path_$1
1557do
1558	if test -z "$cf_path_prog" ; then
1559		if test "$with_full_paths" = yes ; then
1560			CF_PATH_SYNTAX(cf_temp,break)
1561			cf_path_prog="$cf_temp"
1562		else
1563			cf_path_prog="`basename $cf_temp`"
1564		fi
1565	elif test -z "$cf_path_args" ; then
1566		cf_path_args="$cf_temp"
1567	else
1568		cf_path_args="$cf_path_args $cf_temp"
1569	fi
1570done
1571IFS="$cf_save_ifs"
1572
1573if test -n "$cf_path_prog" ; then
1574	CF_MSG_LOG(defining path for ${cf_path_prog})
1575	AC_DEFINE_UNQUOTED($1_PATH,"$cf_path_prog",Define to pathname $1)
1576	test -n "$cf_path_args" && AC_DEFINE_UNQUOTED($1_ARGS,"$cf_path_args",Define to provide args for $1)
1577fi
1578])dnl
1579dnl ---------------------------------------------------------------------------
1580dnl CF_PATH_SYNTAX version: 14 updated: 2012/06/19 20:58:54
1581dnl --------------
1582dnl Check the argument to see that it looks like a pathname.  Rewrite it if it
1583dnl begins with one of the prefix/exec_prefix variables, and then again if the
1584dnl result begins with 'NONE'.  This is necessary to work around autoconf's
1585dnl delayed evaluation of those symbols.
1586AC_DEFUN([CF_PATH_SYNTAX],[
1587if test "x$prefix" != xNONE; then
1588  cf_path_syntax="$prefix"
1589else
1590  cf_path_syntax="$ac_default_prefix"
1591fi
1592
1593case ".[$]$1" in #(vi
1594.\[$]\(*\)*|.\'*\'*) #(vi
1595  ;;
1596..|./*|.\\*) #(vi
1597  ;;
1598.[[a-zA-Z]]:[[\\/]]*) #(vi OS/2 EMX
1599  ;;
1600.\[$]{*prefix}*|.\[$]{*dir}*) #(vi
1601  eval $1="[$]$1"
1602  case ".[$]$1" in #(vi
1603  .NONE/*)
1604    $1=`echo [$]$1 | sed -e s%NONE%$cf_path_syntax%`
1605    ;;
1606  esac
1607  ;; #(vi
1608.no|.NONE/*)
1609  $1=`echo [$]$1 | sed -e s%NONE%$cf_path_syntax%`
1610  ;;
1611*)
1612  ifelse([$2],,[AC_MSG_ERROR([expected a pathname, not \"[$]$1\"])],$2)
1613  ;;
1614esac
1615])dnl
1616dnl ---------------------------------------------------------------------------
1617dnl CF_PKG_CONFIG version: 7 updated: 2011/04/29 04:53:22
1618dnl -------------
1619dnl Check for the package-config program, unless disabled by command-line.
1620AC_DEFUN([CF_PKG_CONFIG],
1621[
1622AC_MSG_CHECKING(if you want to use pkg-config)
1623AC_ARG_WITH(pkg-config,
1624	[  --with-pkg-config{=path} enable/disable use of pkg-config],
1625	[cf_pkg_config=$withval],
1626	[cf_pkg_config=yes])
1627AC_MSG_RESULT($cf_pkg_config)
1628
1629case $cf_pkg_config in #(vi
1630no) #(vi
1631	PKG_CONFIG=none
1632	;;
1633yes) #(vi
1634	CF_ACVERSION_CHECK(2.52,
1635		[AC_PATH_TOOL(PKG_CONFIG, pkg-config, none)],
1636		[AC_PATH_PROG(PKG_CONFIG, pkg-config, none)])
1637	;;
1638*)
1639	PKG_CONFIG=$withval
1640	;;
1641esac
1642
1643test -z "$PKG_CONFIG" && PKG_CONFIG=none
1644if test "$PKG_CONFIG" != none ; then
1645	CF_PATH_SYNTAX(PKG_CONFIG)
1646fi
1647
1648AC_SUBST(PKG_CONFIG)
1649])dnl
1650dnl ---------------------------------------------------------------------------
1651dnl CF_POSIX_C_SOURCE version: 8 updated: 2010/05/26 05:38:42
1652dnl -----------------
1653dnl Define _POSIX_C_SOURCE to the given level, and _POSIX_SOURCE if needed.
1654dnl
1655dnl	POSIX.1-1990				_POSIX_SOURCE
1656dnl	POSIX.1-1990 and			_POSIX_SOURCE and
1657dnl		POSIX.2-1992 C-Language			_POSIX_C_SOURCE=2
1658dnl		Bindings Option
1659dnl	POSIX.1b-1993				_POSIX_C_SOURCE=199309L
1660dnl	POSIX.1c-1996				_POSIX_C_SOURCE=199506L
1661dnl	X/Open 2000				_POSIX_C_SOURCE=200112L
1662dnl
1663dnl Parameters:
1664dnl	$1 is the nominal value for _POSIX_C_SOURCE
1665AC_DEFUN([CF_POSIX_C_SOURCE],
1666[
1667cf_POSIX_C_SOURCE=ifelse([$1],,199506L,[$1])
1668
1669cf_save_CFLAGS="$CFLAGS"
1670cf_save_CPPFLAGS="$CPPFLAGS"
1671
1672CF_REMOVE_DEFINE(cf_trim_CFLAGS,$cf_save_CFLAGS,_POSIX_C_SOURCE)
1673CF_REMOVE_DEFINE(cf_trim_CPPFLAGS,$cf_save_CPPFLAGS,_POSIX_C_SOURCE)
1674
1675AC_CACHE_CHECK(if we should define _POSIX_C_SOURCE,cf_cv_posix_c_source,[
1676	CF_MSG_LOG(if the symbol is already defined go no further)
1677	AC_TRY_COMPILE([#include <sys/types.h>],[
1678#ifndef _POSIX_C_SOURCE
1679make an error
1680#endif],
1681	[cf_cv_posix_c_source=no],
1682	[cf_want_posix_source=no
1683	 case .$cf_POSIX_C_SOURCE in #(vi
1684	 .[[12]]??*) #(vi
1685		cf_cv_posix_c_source="-D_POSIX_C_SOURCE=$cf_POSIX_C_SOURCE"
1686		;;
1687	 .2) #(vi
1688		cf_cv_posix_c_source="-D_POSIX_C_SOURCE=$cf_POSIX_C_SOURCE"
1689		cf_want_posix_source=yes
1690		;;
1691	 .*)
1692		cf_want_posix_source=yes
1693		;;
1694	 esac
1695	 if test "$cf_want_posix_source" = yes ; then
1696		AC_TRY_COMPILE([#include <sys/types.h>],[
1697#ifdef _POSIX_SOURCE
1698make an error
1699#endif],[],
1700		cf_cv_posix_c_source="$cf_cv_posix_c_source -D_POSIX_SOURCE")
1701	 fi
1702	 CF_MSG_LOG(ifdef from value $cf_POSIX_C_SOURCE)
1703	 CFLAGS="$cf_trim_CFLAGS"
1704	 CPPFLAGS="$cf_trim_CPPFLAGS $cf_cv_posix_c_source"
1705	 CF_MSG_LOG(if the second compile does not leave our definition intact error)
1706	 AC_TRY_COMPILE([#include <sys/types.h>],[
1707#ifndef _POSIX_C_SOURCE
1708make an error
1709#endif],,
1710	 [cf_cv_posix_c_source=no])
1711	 CFLAGS="$cf_save_CFLAGS"
1712	 CPPFLAGS="$cf_save_CPPFLAGS"
1713	])
1714])
1715
1716if test "$cf_cv_posix_c_source" != no ; then
1717	CFLAGS="$cf_trim_CFLAGS"
1718	CPPFLAGS="$cf_trim_CPPFLAGS"
1719	CF_ADD_CFLAGS($cf_cv_posix_c_source)
1720fi
1721
1722])dnl
1723dnl ---------------------------------------------------------------------------
1724dnl CF_POSIX_SAVED_IDS version: 8 updated: 2012/10/04 20:12:20
1725dnl ------------------
1726dnl
1727dnl Check first if saved-ids are always supported.  Some systems
1728dnl may require runtime checks.
1729AC_DEFUN([CF_POSIX_SAVED_IDS],
1730[
1731AC_CHECK_HEADERS( \
1732sys/param.h \
1733)
1734
1735AC_CACHE_CHECK(if POSIX saved-ids are supported,cf_cv_posix_saved_ids,[
1736AC_TRY_LINK(
1737[
1738#include <unistd.h>
1739#ifdef HAVE_SYS_PARAM_H
1740#include <sys/param.h>		/* this may define "BSD" */
1741#endif
1742],[
1743#if defined(_POSIX_SAVED_IDS) && (_POSIX_SAVED_IDS > 0)
1744	void *p = (void *) seteuid;
1745	int x = seteuid(geteuid());
1746#elif defined(BSD) && (BSD >= 199103)
1747/* The BSD's may implement the runtime check - and it fails.
1748 * However, saved-ids work almost like POSIX (close enough for most uses).
1749 */
1750#else
1751make an error
1752#endif
1753],[cf_cv_posix_saved_ids=yes
1754],[
1755AC_TRY_RUN([
1756#ifdef HAVE_STDLIB_H
1757#include <stdlib.h>
1758#endif
1759#include <unistd.h>
1760int main()
1761{
1762	void *p = (void *) seteuid;
1763	long code = sysconf(_SC_SAVED_IDS);
1764	${cf_cv_main_return:-return}  ((code > 0) ? 0 : 1);
1765}],
1766	cf_cv_posix_saved_ids=yes,
1767	cf_cv_posix_saved_ids=no,
1768	cf_cv_posix_saved_ids=unknown)
1769])
1770])
1771
1772test "$cf_cv_posix_saved_ids" = yes && AC_DEFINE(HAVE_POSIX_SAVED_IDS,1,[Define to 1 if POSIX saved-ids are supported])
1773])
1774dnl ---------------------------------------------------------------------------
1775dnl CF_POSIX_WAIT version: 3 updated: 2012/10/04 20:12:20
1776dnl -------------
1777dnl Check for POSIX wait support
1778AC_DEFUN([CF_POSIX_WAIT],
1779[
1780AC_REQUIRE([AC_HEADER_SYS_WAIT])
1781AC_CACHE_CHECK(for POSIX wait functions,cf_cv_posix_wait,[
1782AC_TRY_LINK([
1783#include <stdlib.h>
1784#include <stdio.h>
1785#include <sys/types.h>
1786#ifdef HAVE_SYS_WAIT_H
1787#include <sys/wait.h>
1788#endif
1789],[
1790	int stat_loc;
1791	pid_t pid = waitpid(-1, &stat_loc, WNOHANG|WUNTRACED);
1792	pid_t pid2 = wait(&stat_loc);
1793],
1794[cf_cv_posix_wait=yes],
1795[cf_cv_posix_wait=no])
1796])
1797test "$cf_cv_posix_wait" = yes && AC_DEFINE(USE_POSIX_WAIT,1,[Define to 1 if we have POSIX wait functions])
1798])dnl
1799dnl ---------------------------------------------------------------------------
1800dnl CF_PROCFS_CWD version: 2 updated: 2007/03/12 20:39:04
1801dnl -------------
1802dnl Find /proc tree (may be in a different place) which implements the "cwd"
1803dnl link.
1804AC_DEFUN([CF_PROCFS_CWD],[
1805AC_CACHE_CHECK(for proc tree with cwd-support,cf_cv_procfs_cwd,[
1806cf_cv_procfs_cwd=no
1807for cf_path in /proc /compat/linux/proc /usr/compat/linux/proc
1808do
1809	if test -d $cf_path && \
1810	   test -d $cf_path/$$ && \
1811	   ( test -d $cf_path/$$/cwd || \
1812	     test -L $cf_path/$$/cwd ); then
1813		cf_cv_procfs_cwd=$cf_path
1814		break
1815	fi
1816done
1817])
1818])dnl
1819dnl ---------------------------------------------------------------------------
1820dnl CF_PROG_CC version: 3 updated: 2012/10/06 15:31:55
1821dnl ----------
1822dnl standard check for CC, plus followup sanity checks
1823dnl $1 = optional parameter to pass to AC_PROG_CC to specify compiler name
1824AC_DEFUN([CF_PROG_CC],[
1825ifelse($1,,[AC_PROG_CC],[AC_PROG_CC($1)])
1826CF_GCC_VERSION
1827CF_ACVERSION_CHECK(2.52,
1828	[AC_PROG_CC_STDC],
1829	[CF_ANSI_CC_REQD])
1830CF_CC_ENV_FLAGS 
1831])dnl
1832dnl ---------------------------------------------------------------------------
1833dnl CF_PROG_GROFF version: 1 updated: 2013/01/02 20:37:18
1834dnl -------------
1835dnl Check if groff is available, for cases (such as html output) where nroff
1836dnl is not enough.
1837AC_DEFUN([CF_PROG_GROFF],[
1838AC_PATH_PROG(GROFF_PATH,groff,no)
1839if test "x$GROFF_PATH" = xno
1840then
1841	NROFF_NOTE=
1842	GROFF_NOTE="#"
1843else
1844	NROFF_NOTE="#"
1845	GROFF_NOTE=
1846fi
1847AC_SUBST(GROFF_PATH)
1848AC_SUBST(GROFF_NOTE)
1849AC_SUBST(NROFF_NOTE)
1850])dnl
1851dnl ---------------------------------------------------------------------------
1852dnl CF_REGEX version: 10 updated: 2012/10/04 20:12:20
1853dnl --------
1854dnl Attempt to determine if we've got one of the flavors of regular-expression
1855dnl code that we can support.
1856AC_DEFUN([CF_REGEX],
1857[
1858
1859cf_regex_func=no
1860
1861cf_regex_libs="regex re"
1862case $host_os in #(vi
1863mingw*)
1864	cf_regex_libs="gnurx $cf_regex_libs"
1865	;;
1866esac
1867
1868AC_CHECK_FUNC(regcomp,[cf_regex_func=regcomp],[
1869	for cf_regex_lib in $cf_regex_libs
1870	do
1871		AC_CHECK_LIB($cf_regex_lib,regcomp,[
1872				CF_ADD_LIB($cf_regex_lib)
1873				cf_regex_func=regcomp
1874				break])
1875	done
1876])
1877
1878if test "$cf_regex_func" = no ; then
1879	AC_CHECK_FUNC(compile,[cf_regex_func=compile],[
1880		AC_CHECK_LIB(gen,compile,[
1881				CF_ADD_LIB(gen)
1882				cf_regex_func=compile])])
1883fi
1884
1885if test "$cf_regex_func" = no ; then
1886	AC_MSG_WARN(cannot find regular expression library)
1887fi
1888
1889AC_CACHE_CHECK(for regular-expression headers,cf_cv_regex_hdrs,[
1890
1891cf_cv_regex_hdrs=no
1892case $cf_regex_func in #(vi
1893compile) #(vi
1894	for cf_regex_hdr in regexp.h regexpr.h
1895	do
1896		AC_TRY_LINK([#include <$cf_regex_hdr>],[
1897			char *p = compile("", "", "", 0);
1898			int x = step("", "");
1899		],[
1900			cf_cv_regex_hdrs=$cf_regex_hdr
1901			break
1902		])
1903	done
1904	;;
1905*)
1906	for cf_regex_hdr in regex.h
1907	do
1908		AC_TRY_LINK([#include <sys/types.h>
1909#include <$cf_regex_hdr>],[
1910			regex_t *p;
1911			int x = regcomp(p, "", 0);
1912			int y = regexec(p, "", 0, 0, 0);
1913			regfree(p);
1914		],[
1915			cf_cv_regex_hdrs=$cf_regex_hdr
1916			break
1917		])
1918	done
1919	;;
1920esac
1921
1922])
1923
1924case $cf_cv_regex_hdrs in #(vi
1925    no)	       AC_MSG_WARN(no regular expression header found) ;; #(vi
1926    regex.h)   AC_DEFINE(HAVE_REGEX_H_FUNCS,1,[Define to 1 to include regex.h for regular expressions]) ;; #(vi
1927    regexp.h)  AC_DEFINE(HAVE_REGEXP_H_FUNCS,1,[Define to 1 to include regexp.h for regular expressions]) ;; #(vi
1928    regexpr.h) AC_DEFINE(HAVE_REGEXPR_H_FUNCS,1,[Define to 1 to include regexpr.h for regular expressions]) ;;
1929esac
1930])dnl
1931dnl ---------------------------------------------------------------------------
1932dnl CF_REMOVE_DEFINE version: 3 updated: 2010/01/09 11:05:50
1933dnl ----------------
1934dnl Remove all -U and -D options that refer to the given symbol from a list
1935dnl of C compiler options.  This works around the problem that not all
1936dnl compilers process -U and -D options from left-to-right, so a -U option
1937dnl cannot be used to cancel the effect of a preceding -D option.
1938dnl
1939dnl $1 = target (which could be the same as the source variable)
1940dnl $2 = source (including '$')
1941dnl $3 = symbol to remove
1942define([CF_REMOVE_DEFINE],
1943[
1944$1=`echo "$2" | \
1945	sed	-e 's/-[[UD]]'"$3"'\(=[[^ 	]]*\)\?[[ 	]]/ /g' \
1946		-e 's/-[[UD]]'"$3"'\(=[[^ 	]]*\)\?[$]//g'`
1947])dnl
1948dnl ---------------------------------------------------------------------------
1949dnl CF_RPATH_HACK version: 11 updated: 2013/09/01 13:02:00
1950dnl -------------
1951AC_DEFUN([CF_RPATH_HACK],
1952[
1953AC_REQUIRE([CF_LD_RPATH_OPT])
1954AC_MSG_CHECKING(for updated LDFLAGS)
1955if test -n "$LD_RPATH_OPT" ; then
1956	AC_MSG_RESULT(maybe)
1957
1958	AC_CHECK_PROGS(cf_ldd_prog,ldd,no)
1959	cf_rpath_list="/usr/lib /lib"
1960	if test "$cf_ldd_prog" != no
1961	then
1962		cf_rpath_oops=
1963
1964AC_TRY_LINK([#include <stdio.h>],
1965		[printf("Hello");],
1966		[cf_rpath_oops=`$cf_ldd_prog conftest$ac_exeext | fgrep ' not found' | sed -e 's% =>.*$%%' |sort | uniq`
1967		 cf_rpath_list=`$cf_ldd_prog conftest$ac_exeext | fgrep / | sed -e 's%^.*[[ 	]]/%/%' -e 's%/[[^/]][[^/]]*$%%' |sort | uniq`])
1968
1969		# If we passed the link-test, but get a "not found" on a given library,
1970		# this could be due to inept reconfiguration of gcc to make it only
1971		# partly honor /usr/local/lib (or whatever).  Sometimes this behavior
1972		# is intentional, e.g., installing gcc in /usr/bin and suppressing the
1973		# /usr/local libraries.
1974		if test -n "$cf_rpath_oops"
1975		then
1976			for cf_rpath_src in $cf_rpath_oops
1977			do
1978				for cf_rpath_dir in \
1979					/usr/local \
1980					/usr/pkg \
1981					/opt/sfw
1982				do
1983					if test -f $cf_rpath_dir/lib/$cf_rpath_src
1984					then
1985						CF_VERBOSE(...adding -L$cf_rpath_dir/lib to LDFLAGS for $cf_rpath_src)
1986						LDFLAGS="$LDFLAGS -L$cf_rpath_dir/lib"
1987						break
1988					fi
1989				done
1990			done
1991		fi
1992	fi
1993
1994	CF_VERBOSE(...checking EXTRA_LDFLAGS $EXTRA_LDFLAGS)
1995
1996	CF_RPATH_HACK_2(LDFLAGS)
1997	CF_RPATH_HACK_2(LIBS)
1998
1999	CF_VERBOSE(...checked EXTRA_LDFLAGS $EXTRA_LDFLAGS)
2000else
2001	AC_MSG_RESULT(no)
2002fi
2003AC_SUBST(EXTRA_LDFLAGS)
2004])dnl
2005dnl ---------------------------------------------------------------------------
2006dnl CF_RPATH_HACK_2 version: 6 updated: 2010/04/17 16:31:24
2007dnl ---------------
2008dnl Do one set of substitutions for CF_RPATH_HACK, adding an rpath option to
2009dnl EXTRA_LDFLAGS for each -L option found.
2010dnl
2011dnl $cf_rpath_list contains a list of directories to ignore.
2012dnl
2013dnl $1 = variable name to update.  The LDFLAGS variable should be the only one,
2014dnl      but LIBS often has misplaced -L options.
2015AC_DEFUN([CF_RPATH_HACK_2],
2016[
2017CF_VERBOSE(...checking $1 [$]$1)
2018
2019cf_rpath_dst=
2020for cf_rpath_src in [$]$1
2021do
2022	case $cf_rpath_src in #(vi
2023	-L*) #(vi
2024
2025		# check if this refers to a directory which we will ignore
2026		cf_rpath_skip=no
2027		if test -n "$cf_rpath_list"
2028		then
2029			for cf_rpath_item in $cf_rpath_list
2030			do
2031				if test "x$cf_rpath_src" = "x-L$cf_rpath_item"
2032				then
2033					cf_rpath_skip=yes
2034					break
2035				fi
2036			done
2037		fi
2038
2039		if test "$cf_rpath_skip" = no
2040		then
2041			# transform the option
2042			if test "$LD_RPATH_OPT" = "-R " ; then
2043				cf_rpath_tmp=`echo "$cf_rpath_src" |sed -e "s%-L%-R %"`
2044			else
2045				cf_rpath_tmp=`echo "$cf_rpath_src" |sed -e "s%-L%$LD_RPATH_OPT%"`
2046			fi
2047
2048			# if we have not already added this, add it now
2049			cf_rpath_tst=`echo "$EXTRA_LDFLAGS" | sed -e "s%$cf_rpath_tmp %%"`
2050			if test "x$cf_rpath_tst" = "x$EXTRA_LDFLAGS"
2051			then
2052				CF_VERBOSE(...Filter $cf_rpath_src ->$cf_rpath_tmp)
2053				EXTRA_LDFLAGS="$cf_rpath_tmp $EXTRA_LDFLAGS"
2054			fi
2055		fi
2056		;;
2057	esac
2058	cf_rpath_dst="$cf_rpath_dst $cf_rpath_src"
2059done
2060$1=$cf_rpath_dst
2061
2062CF_VERBOSE(...checked $1 [$]$1)
2063AC_SUBST(EXTRA_LDFLAGS)
2064])dnl
2065dnl ---------------------------------------------------------------------------
2066dnl CF_SIGWINCH version: 1 updated: 2006/04/02 16:41:09
2067dnl -----------
2068dnl Use this macro after CF_XOPEN_SOURCE, but do not require it (not all
2069dnl programs need this test).
2070dnl
2071dnl This is really a MacOS X 10.4.3 workaround.  Defining _POSIX_C_SOURCE
2072dnl forces SIGWINCH to be undefined (breaks xterm, ncurses).  Oddly, the struct
2073dnl winsize declaration is left alone - we may revisit this if Apple choose to
2074dnl break that part of the interface as well.
2075AC_DEFUN([CF_SIGWINCH],
2076[
2077AC_CACHE_CHECK(if SIGWINCH is defined,cf_cv_define_sigwinch,[
2078	AC_TRY_COMPILE([
2079#include <sys/types.h>
2080#include <sys/signal.h>
2081],[int x = SIGWINCH],
2082	[cf_cv_define_sigwinch=yes],
2083	[AC_TRY_COMPILE([
2084#undef _XOPEN_SOURCE
2085#undef _POSIX_SOURCE
2086#undef _POSIX_C_SOURCE
2087#include <sys/types.h>
2088#include <sys/signal.h>
2089],[int x = SIGWINCH],
2090	[cf_cv_define_sigwinch=maybe],
2091	[cf_cv_define_sigwinch=no])
2092])
2093])
2094
2095if test "$cf_cv_define_sigwinch" = maybe ; then
2096AC_CACHE_CHECK(for actual SIGWINCH definition,cf_cv_fixup_sigwinch,[
2097cf_cv_fixup_sigwinch=unknown
2098cf_sigwinch=32
2099while test $cf_sigwinch != 1
2100do
2101	AC_TRY_COMPILE([
2102#undef _XOPEN_SOURCE
2103#undef _POSIX_SOURCE
2104#undef _POSIX_C_SOURCE
2105#include <sys/types.h>
2106#include <sys/signal.h>
2107],[
2108#if SIGWINCH != $cf_sigwinch
2109make an error
2110#endif
2111int x = SIGWINCH],
2112	[cf_cv_fixup_sigwinch=$cf_sigwinch
2113	 break])
2114
2115cf_sigwinch=`expr $cf_sigwinch - 1`
2116done
2117])
2118
2119	if test "$cf_cv_fixup_sigwinch" != unknown ; then
2120		CPPFLAGS="$CPPFLAGS -DSIGWINCH=$cf_cv_fixup_sigwinch"
2121	fi
2122fi
2123])dnl
2124dnl ---------------------------------------------------------------------------
2125dnl CF_SIG_ATOMIC_T version: 3 updated: 2012/10/04 20:12:20
2126dnl ---------------
2127dnl signal handler, but there are some gcc depedencies in that recommendation.
2128dnl Try anyway.
2129AC_DEFUN([CF_SIG_ATOMIC_T],
2130[
2131AC_MSG_CHECKING(for signal global datatype)
2132AC_CACHE_VAL(cf_cv_sig_atomic_t,[
2133	for cf_type in \
2134		"volatile sig_atomic_t" \
2135		"sig_atomic_t" \
2136		"int"
2137	do
2138	AC_TRY_COMPILE([
2139#include <sys/types.h>
2140#include <signal.h>
2141#include <stdio.h>
2142
2143extern $cf_type x;
2144$cf_type x;
2145static void handler(int sig)
2146{
2147	x = 5;
2148}],
2149		[signal(SIGINT, handler);
2150		 x = 1],
2151		[cf_cv_sig_atomic_t=$cf_type],
2152		[cf_cv_sig_atomic_t=no])
2153		test "$cf_cv_sig_atomic_t" != no && break
2154	done
2155	])
2156AC_MSG_RESULT($cf_cv_sig_atomic_t)
2157test "$cf_cv_sig_atomic_t" != no && AC_DEFINE_UNQUOTED(SIG_ATOMIC_T, $cf_cv_sig_atomic_t,[Define to signal global datatype])
2158])dnl
2159dnl ---------------------------------------------------------------------------
2160dnl CF_STRUCT_LASTLOG version: 2 updated: 2012/10/04 20:12:20
2161dnl -----------------
2162dnl Check for header defining struct lastlog, ensure that its .ll_time member
2163dnl is compatible with time().
2164AC_DEFUN([CF_STRUCT_LASTLOG],
2165[
2166AC_CHECK_HEADERS(lastlog.h)
2167AC_CACHE_CHECK(for struct lastlog,cf_cv_struct_lastlog,[
2168AC_TRY_RUN([
2169#include <sys/types.h>
2170#include <time.h>
2171#include <lastlog.h>
2172
2173int main()
2174{
2175	struct lastlog data;
2176	return (sizeof(data.ll_time) != sizeof(time_t));
2177}],[
2178cf_cv_struct_lastlog=yes],[
2179cf_cv_struct_lastlog=no],[
2180cf_cv_struct_lastlog=unknown])])
2181
2182test $cf_cv_struct_lastlog != no && AC_DEFINE(USE_STRUCT_LASTLOG,1,[Define to 1 if we have struct lastlog])
2183])dnl
2184dnl ---------------------------------------------------------------------------
2185dnl CF_SVR4 version: 5 updated: 2012/10/04 05:24:07
2186dnl -------
2187dnl Check if this is an SVR4 system.  We need the definition for xterm
2188AC_DEFUN([CF_SVR4],
2189[
2190AC_CHECK_LIB(elf, elf_begin,[
2191AC_CACHE_CHECK(if this is an SVR4 system, cf_cv_svr4,[
2192AC_TRY_COMPILE([
2193#if defined(__CYGWIN__)
2194make an error
2195#endif
2196#include <elf.h>
2197#include <sys/termio.h>
2198],[
2199static struct termio d_tio;
2200	d_tio.c_cc[VINTR] = 0;
2201	d_tio.c_cc[VQUIT] = 0;
2202	d_tio.c_cc[VERASE] = 0;
2203	d_tio.c_cc[VKILL] = 0;
2204	d_tio.c_cc[VEOF] = 0;
2205	d_tio.c_cc[VEOL] = 0;
2206	d_tio.c_cc[VMIN] = 0;
2207	d_tio.c_cc[VTIME] = 0;
2208	d_tio.c_cc[VLNEXT] = 0;
2209],
2210[cf_cv_svr4=yes],
2211[cf_cv_svr4=no])
2212])
2213])
2214test "$cf_cv_svr4" = yes && AC_DEFINE(SVR4,1,[Define to 1 if this is an SVR4 system])
2215])dnl
2216dnl ---------------------------------------------------------------------------
2217dnl CF_SYSV version: 15 updated: 2012/10/04 05:24:07
2218dnl -------
2219dnl Check if this is a SYSV platform, e.g., as used in <X11/Xos.h>, and whether
2220dnl defining it will be helpful.  The following features are used to check:
2221dnl
2222dnl a) bona-fide SVSV doesn't use const for sys_errlist[].  Since this is a
2223dnl legacy (pre-ANSI) feature, const should not apply.  Modern systems only
2224dnl declare strerror().  Xos.h declares the legacy form of str_errlist[], and
2225dnl a compile-time error will result from trying to assign to a const array.
2226dnl
2227dnl b) compile with headers that exist on SYSV hosts.
2228dnl
2229dnl c) compile with type definitions that differ on SYSV hosts from standard C.
2230AC_DEFUN([CF_SYSV],
2231[
2232AC_CHECK_HEADERS( \
2233termios.h \
2234stdlib.h \
2235X11/Intrinsic.h \
2236)
2237
2238AC_REQUIRE([CF_SYS_ERRLIST])
2239
2240AC_CACHE_CHECK(if we should define SYSV,cf_cv_sysv,[
2241AC_TRY_COMPILE([
2242#undef  SYSV
2243#define SYSV 1			/* get Xos.h to declare sys_errlist[] */
2244#ifdef HAVE_STDLIB_H
2245#include <stdlib.h>		/* look for wchar_t */
2246#endif
2247#ifdef HAVE_X11_INTRINSIC_H
2248#include <X11/Intrinsic.h>	/* Intrinsic.h has other traps... */
2249#endif
2250#ifdef HAVE_TERMIOS_H		/* needed for HPUX 10.20 */
2251#include <termios.h>
2252#define STRUCT_TERMIOS struct termios
2253#else
2254#define STRUCT_TERMIOS struct termio
2255#endif
2256#include <curses.h>
2257#include <term.h>		/* eliminate most BSD hacks */
2258#include <errno.h>		/* declare sys_errlist on older systems */
2259#include <sys/termio.h>		/* eliminate most of the remaining ones */
2260],[
2261static STRUCT_TERMIOS d_tio;
2262	d_tio.c_cc[VINTR] = 0;
2263	d_tio.c_cc[VQUIT] = 0;
2264	d_tio.c_cc[VERASE] = 0;
2265	d_tio.c_cc[VKILL] = 0;
2266	d_tio.c_cc[VEOF] = 0;
2267	d_tio.c_cc[VEOL] = 0;
2268	d_tio.c_cc[VMIN] = 0;
2269	d_tio.c_cc[VTIME] = 0;
2270#if defined(HAVE_SYS_ERRLIST) && !defined(DECL_SYS_ERRLIST)
2271sys_errlist[0] = "";		/* Cygwin mis-declares this */
2272#endif
2273],
2274[cf_cv_sysv=yes],
2275[cf_cv_sysv=no])
2276])
2277test "$cf_cv_sysv" = yes && AC_DEFINE(SYSV,1,[Define to 1 if this is an SYSV system])
2278])dnl
2279dnl ---------------------------------------------------------------------------
2280dnl CF_SYSV_UTMP version: 6 updated: 2012/10/04 20:12:20
2281dnl ------------
2282dnl Check if this is a SYSV flavor of UTMP
2283AC_DEFUN([CF_SYSV_UTMP],
2284[
2285AC_CACHE_CHECK(if $cf_cv_have_utmp is SYSV flavor,cf_cv_sysv_utmp,[
2286test "$cf_cv_have_utmp" = "utmp" && cf_prefix="ut" || cf_prefix="utx"
2287AC_TRY_LINK([
2288#include <sys/types.h>
2289#include <${cf_cv_have_utmp}.h>],[
2290struct $cf_cv_have_utmp x;
2291	set${cf_prefix}ent ();
2292	get${cf_prefix}id(&x);
2293	put${cf_prefix}line(&x);
2294	end${cf_prefix}ent();],
2295	[cf_cv_sysv_utmp=yes],
2296	[cf_cv_sysv_utmp=no])
2297])
2298test $cf_cv_sysv_utmp = yes && AC_DEFINE(USE_SYSV_UTMP,1,[Define to 1 if utmp is SYSV flavor])
2299])dnl
2300dnl ---------------------------------------------------------------------------
2301dnl CF_SYS_ERRLIST version: 6 updated: 2001/12/30 13:03:23
2302dnl --------------
2303dnl Check for declaration of sys_nerr and sys_errlist in one of stdio.h and
2304dnl errno.h.  Declaration of sys_errlist on BSD4.4 interferes with our
2305dnl declaration.  Reported by Keith Bostic.
2306AC_DEFUN([CF_SYS_ERRLIST],
2307[
2308    CF_CHECK_ERRNO(sys_nerr)
2309    CF_CHECK_ERRNO(sys_errlist)
2310])dnl
2311dnl ---------------------------------------------------------------------------
2312dnl CF_TERMIO_C_ISPEED version: 3 updated: 2012/10/04 20:12:20
2313dnl ------------------
2314dnl Check for SGI's broken redefinition of baud rates introduced in IRIX 6.5
2315dnl (there doesn't appear to be a useful predefined symbol).
2316AC_DEFUN([CF_TERMIO_C_ISPEED],
2317[
2318AC_CACHE_CHECK(for IRIX 6.5 baud-rate redefinitions,cf_cv_termio_c_ispeed,[
2319AC_TRY_COMPILE([
2320#include <sys/types.h>
2321#include <sys/termio.h>],[
2322struct termio foo;
2323foo.c_ispeed = B38400;
2324foo.c_ospeed = B9600;
2325],[cf_cv_termio_c_ispeed=yes
2326],[cf_cv_termio_c_ispeed=no])
2327])
2328test "$cf_cv_termio_c_ispeed" = yes && AC_DEFINE(HAVE_TERMIO_C_ISPEED,1,[define 1 if we have IRIX 6.5 baud-rate redefinitions])
2329])dnl
2330dnl ---------------------------------------------------------------------------
2331dnl CF_TRIM_X_LIBS version: 2 updated: 2013/07/09 21:27:22
2332dnl --------------
2333dnl Trim extra base X libraries added as a workaround for inconsistent library
2334dnl dependencies returned by "new" pkg-config files.
2335AC_DEFUN([CF_TRIM_X_LIBS],[
2336	for cf_trim_lib in Xmu Xt X11
2337	do
2338		case "$LIBS" in
2339		*-l$cf_trim_lib\ *-l$cf_trim_lib*)
2340			LIBS=`echo "$LIBS " | sed -e 's/  / /g' -e 's%-l'"$cf_trim_lib"' %%' -e 's/ $//'`
2341			CF_VERBOSE(..trimmed $LIBS)
2342			;;
2343		esac
2344	done
2345])
2346dnl ---------------------------------------------------------------------------
2347dnl CF_TRY_PKG_CONFIG version: 5 updated: 2013/07/06 21:27:06
2348dnl -----------------
2349dnl This is a simple wrapper to use for pkg-config, for libraries which may be
2350dnl available in that form.
2351dnl
2352dnl $1 = package name
2353dnl $2 = extra logic to use, if any, after updating CFLAGS and LIBS
2354dnl $3 = logic to use if pkg-config does not have the package
2355AC_DEFUN([CF_TRY_PKG_CONFIG],[
2356AC_REQUIRE([CF_PKG_CONFIG])
2357
2358if test "$PKG_CONFIG" != none && "$PKG_CONFIG" --exists $1; then
2359	CF_VERBOSE(found package $1)
2360	cf_pkgconfig_incs="`$PKG_CONFIG --cflags $1 2>/dev/null`"
2361	cf_pkgconfig_libs="`$PKG_CONFIG --libs   $1 2>/dev/null`"
2362	CF_VERBOSE(package $1 CFLAGS: $cf_pkgconfig_incs)
2363	CF_VERBOSE(package $1 LIBS: $cf_pkgconfig_libs)
2364	CF_ADD_CFLAGS($cf_pkgconfig_incs)
2365	CF_ADD_LIBS($cf_pkgconfig_libs)
2366	ifelse([$2],,:,[$2])
2367else
2368	cf_pkgconfig_incs=
2369	cf_pkgconfig_libs=
2370	ifelse([$3],,:,[$3])
2371fi
2372])
2373dnl ---------------------------------------------------------------------------
2374dnl CF_TRY_XOPEN_SOURCE version: 1 updated: 2011/10/30 17:09:50
2375dnl -------------------
2376dnl If _XOPEN_SOURCE is not defined in the compile environment, check if we
2377dnl can define it successfully.
2378AC_DEFUN([CF_TRY_XOPEN_SOURCE],[
2379AC_CACHE_CHECK(if we should define _XOPEN_SOURCE,cf_cv_xopen_source,[
2380	AC_TRY_COMPILE([
2381#include <stdlib.h>
2382#include <string.h>
2383#include <sys/types.h>
2384],[
2385#ifndef _XOPEN_SOURCE
2386make an error
2387#endif],
2388	[cf_cv_xopen_source=no],
2389	[cf_save="$CPPFLAGS"
2390	 CPPFLAGS="$CPPFLAGS -D_XOPEN_SOURCE=$cf_XOPEN_SOURCE"
2391	 AC_TRY_COMPILE([
2392#include <stdlib.h>
2393#include <string.h>
2394#include <sys/types.h>
2395],[
2396#ifdef _XOPEN_SOURCE
2397make an error
2398#endif],
2399	[cf_cv_xopen_source=no],
2400	[cf_cv_xopen_source=$cf_XOPEN_SOURCE])
2401	CPPFLAGS="$cf_save"
2402	])
2403])
2404
2405if test "$cf_cv_xopen_source" != no ; then
2406	CF_REMOVE_DEFINE(CFLAGS,$CFLAGS,_XOPEN_SOURCE)
2407	CF_REMOVE_DEFINE(CPPFLAGS,$CPPFLAGS,_XOPEN_SOURCE)
2408	cf_temp_xopen_source="-D_XOPEN_SOURCE=$cf_cv_xopen_source"
2409	CF_ADD_CFLAGS($cf_temp_xopen_source)
2410fi
2411])
2412dnl ---------------------------------------------------------------------------
2413dnl CF_TTY_GROUP version: 8 updated: 2012/10/04 20:12:20
2414dnl ------------
2415dnl Check if the system has a tty-group defined.  This is used in xterm when
2416dnl setting pty ownership.
2417AC_DEFUN([CF_TTY_GROUP],
2418[
2419AC_MSG_CHECKING(for explicit tty group name)
2420AC_ARG_WITH(tty-group,
2421	[  --with-tty-group=XXX    use XXX for the tty-group],
2422	[cf_tty_group=$withval],
2423	[cf_tty_group=auto...])
2424test -z "$cf_tty_group"    && cf_tty_group=auto...
2425test "$cf_tty_group" = yes && cf_tty_group=auto...
2426AC_MSG_RESULT($cf_tty_group)
2427
2428if test "$cf_tty_group" = "auto..." ; then
2429AC_CACHE_CHECK(for tty group name,cf_cv_tty_group_name,[
2430
2431# If we are configuring as root, it is hard to get a clue about the tty group.
2432# But we'll guess based on how our connection is set up - assuming it is done
2433# properly.
2434
2435cf_uid=`id | sed -e 's/^[^=]*=//' -e 's/(.*$//'`
2436# )vi
2437if test "$cf_uid" != 0 ; then
2438cf_cv_tty_group_name=
2439cf_tty_name=`tty`
2440test "$cf_tty_name" = "not a tty" && cf_tty_name=/dev/tty
2441test -z "$cf_tty_name" && cf_tty_name=/dev/tty
2442if test -c "$cf_tty_name"
2443then
2444	cf_option="-l -L"
2445
2446	# Expect listing to have fields like this:
2447	#-rwxrwxrwx   1 user      group       34293 Jul 18 16:29 pathname
2448	ls $cf_option $cf_tty_name >conftest.out
2449	read cf_mode cf_links cf_usr cf_grp cf_size cf_date1 cf_date2 cf_date3 cf_rest <conftest.out
2450	if test -z "$cf_rest" ; then
2451		cf_option="$cf_option -g"
2452		ls $cf_option $cf_tty_name >conftest.out
2453		read cf_mode cf_links cf_usr cf_grp cf_size cf_date1 cf_date2 cf_date3 cf_rest <conftest.out
2454	fi
2455	rm -f conftest.out
2456	cf_cv_tty_group_name=$cf_grp
2457fi
2458fi
2459
2460# If we cannot deduce the tty group, fall back on hardcoded cases
2461
2462if test -z "$cf_cv_tty_group_name"
2463then
2464case $host_os in #(vi
2465osf*) #(vi
2466	cf_cv_tty_group_name="terminal"
2467	;;
2468*)
2469	cf_cv_tty_group_name="unknown"
2470	if ( egrep '^tty:' /etc/group 2>/dev/null 1>/dev/null ) then
2471		cf_cv_tty_group_name="tty"
2472	fi
2473	;;
2474esac
2475fi
2476])
2477cf_tty_group="$cf_cv_tty_group_name"
2478else
2479	# if configure option, always do this
2480	AC_DEFINE(USE_TTY_GROUP,1,[Define to 1 if we have a tty groupname])
2481fi
2482
2483AC_DEFINE_UNQUOTED(TTY_GROUP_NAME,"$cf_tty_group",[Define to the name use for tty group])
2484
2485# This is only a double-check that the group-name we obtained above really
2486# does apply to the device.  We cannot perform this test if we are in batch
2487# mode, or if we are cross-compiling.
2488
2489AC_CACHE_CHECK(if we may use the $cf_tty_group group,cf_cv_tty_group,[
2490cf_tty_name=`tty`
2491if test "$cf_tty_name" != "not a tty"
2492then
2493AC_TRY_RUN([
2494#include <unistd.h>
2495#include <sys/types.h>
2496#include <sys/stat.h>
2497#include <grp.h>
2498int main()
2499{
2500	struct stat sb;
2501	struct group *ttygrp = getgrnam(TTY_GROUP_NAME);
2502	char *name = ttyname(0);
2503
2504	endgrent();
2505	if (ttygrp != 0
2506	 && name != 0
2507	 && stat(name, &sb) == 0
2508	 && sb.st_gid != getgid()
2509	 && sb.st_gid == ttygrp->gr_gid) {
2510		${cf_cv_main_return:-return} (0);
2511	}
2512	${cf_cv_main_return:-return} (1);
2513}
2514	],
2515	[cf_cv_tty_group=yes],
2516	[cf_cv_tty_group=no],
2517	[cf_cv_tty_group=unknown])
2518elif test "$cross_compiling" = yes; then
2519	cf_cv_tty_group=unknown
2520else
2521	cf_cv_tty_group=yes
2522fi
2523])
2524
2525if test $cf_cv_tty_group = no ; then
2526	AC_MSG_WARN(Cannot use $cf_tty_group group)
2527else
2528	AC_DEFINE(USE_TTY_GROUP)
2529fi
2530])dnl
2531dnl ---------------------------------------------------------------------------
2532dnl CF_TYPE_CC_T version: 2 updated: 2012/10/04 20:12:20
2533dnl ------------
2534dnl	Check for cc_t type, used in termio.
2535AC_DEFUN([CF_TYPE_CC_T],
2536[
2537AC_MSG_CHECKING(for cc_t in <termios.h> or <termio.h>)
2538AC_CACHE_VAL(cf_cv_type_cc_t,[
2539	AC_TRY_COMPILE([
2540#include <sys/types.h>
2541#if defined(HAVE_TERMIOS_H)
2542#include <termios.h>
2543#else
2544#include <termio.h>
2545#include <sys/ioctl.h>
2546#endif
2547],
2548		[cc_t x],
2549		[cf_cv_type_cc_t=yes],
2550		[cf_cv_type_cc_t=no])
2551	])
2552AC_MSG_RESULT($cf_cv_type_cc_t)
2553test $cf_cv_type_cc_t = no && AC_DEFINE(cc_t, unsigned char,[Define to cc_t type used in termio])
2554])dnl
2555dnl ---------------------------------------------------------------------------
2556dnl CF_TYPE_FD_MASK version: 3 updated: 2012/10/04 06:57:36
2557dnl ---------------
2558dnl Check for the declaration of fd_mask, which is like fd_set, associated
2559dnl with select().  The check for fd_set should have pulled in this as well,
2560dnl but there is a special case for Mac OS X, possibly other BSD-derived
2561dnl platforms.
2562AC_DEFUN([CF_TYPE_FD_MASK],
2563[
2564AC_REQUIRE([CF_TYPE_FD_SET])
2565
2566AC_CACHE_CHECK(for declaration of fd_mask,cf_cv_type_fd_mask,[
2567    if test x$cf_cv_type_fd_set = xX11/Xpoll.h ; then
2568        AC_TRY_COMPILE([
2569#include <X11/Xpoll.h>],[fd_mask x],,
2570        [CF_MSG_LOG(if we must define CSRG_BASED)
2571# Xosdefs.h on Mac OS X may not define this (but it should).
2572            AC_TRY_COMPILE([
2573#define CSRG_BASED
2574#include <X11/Xpoll.h>],[fd_mask x],
2575        cf_cv_type_fd_mask=CSRG_BASED)])
2576    else
2577        cf_cv_type_fd_mask=$cf_cv_type_fd_set
2578    fi
2579])
2580if test x$cf_cv_type_fd_mask = xCSRG_BASED ; then
2581    AC_DEFINE(CSRG_BASED,1,[Define to 1 if needed for declaring fd_mask()])
2582fi
2583])dnl
2584dnl ---------------------------------------------------------------------------
2585dnl CF_TYPE_FD_SET version: 5 updated: 2012/10/04 20:12:20
2586dnl --------------
2587dnl Check for the declaration of fd_set.  Some platforms declare it in
2588dnl <sys/types.h>, and some in <sys/select.h>, which requires <sys/types.h>.
2589dnl Finally, if we are using this for an X application, Xpoll.h may include
2590dnl <sys/select.h>, so we don't want to do it twice.
2591AC_DEFUN([CF_TYPE_FD_SET],
2592[
2593AC_CHECK_HEADERS(X11/Xpoll.h)
2594
2595AC_CACHE_CHECK(for declaration of fd_set,cf_cv_type_fd_set,
2596	[CF_MSG_LOG(sys/types alone)
2597AC_TRY_COMPILE([
2598#include <sys/types.h>],
2599	[fd_set x],
2600	[cf_cv_type_fd_set=sys/types.h],
2601	[CF_MSG_LOG(X11/Xpoll.h)
2602AC_TRY_COMPILE([
2603#ifdef HAVE_X11_XPOLL_H
2604#include <X11/Xpoll.h>
2605#endif],
2606	[fd_set x],
2607	[cf_cv_type_fd_set=X11/Xpoll.h],
2608	[CF_MSG_LOG(sys/select.h)
2609AC_TRY_COMPILE([
2610#include <sys/types.h>
2611#include <sys/select.h>],
2612	[fd_set x],
2613	[cf_cv_type_fd_set=sys/select.h],
2614	[cf_cv_type_fd_set=unknown])])])])
2615if test $cf_cv_type_fd_set = sys/select.h ; then
2616	AC_DEFINE(USE_SYS_SELECT_H,1,[Define to 1 to include sys/select.h to declare fd_set])
2617fi
2618])
2619dnl ---------------------------------------------------------------------------
2620dnl CF_UNDO_CFLAGS version: 1 updated: 2011/07/02 09:27:51
2621dnl --------------
2622dnl Remove flags from $CFLAGS or similar shell variable using sed.
2623dnl $1 = variable
2624dnl $2 = message
2625dnl $3 = pattern to remove
2626AC_DEFUN([CF_UNDO_CFLAGS],
2627[
2628	CF_VERBOSE(removing $2 flags from $1)
2629	$1=`echo "[$]$1" | sed -e 's/$3//'`
2630	CF_VERBOSE(...result [$]$1)
2631])dnl
2632dnl ---------------------------------------------------------------------------
2633dnl CF_UPPER version: 5 updated: 2001/01/29 23:40:59
2634dnl --------
2635dnl Make an uppercase version of a variable
2636dnl $1=uppercase($2)
2637AC_DEFUN([CF_UPPER],
2638[
2639$1=`echo "$2" | sed y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%`
2640])dnl
2641dnl ---------------------------------------------------------------------------
2642dnl CF_UTEMPTER version: 4 updated: 2012/10/04 20:12:20
2643dnl -----------
2644dnl Try to link with utempter library
2645AC_DEFUN([CF_UTEMPTER],
2646[
2647AC_CACHE_CHECK(if we can link with utempter library,cf_cv_have_utempter,[
2648cf_save_LIBS="$LIBS"
2649CF_ADD_LIB(utempter)
2650AC_TRY_LINK([
2651#include <utempter.h>
2652],[
2653	addToUtmp("/dev/tty", 0, 1);
2654	removeFromUtmp();
2655],[
2656	cf_cv_have_utempter=yes],[
2657	cf_cv_have_utempter=no])
2658LIBS="$cf_save_LIBS"
2659])
2660if test "$cf_cv_have_utempter" = yes ; then
2661	AC_DEFINE(USE_UTEMPTER,1,[Define to 1 if we can/should link with utempter])
2662	CF_ADD_LIB(utempter)
2663fi
2664])dnl
2665dnl ---------------------------------------------------------------------------
2666dnl CF_UTMP version: 10 updated: 2012/10/04 20:12:20
2667dnl -------
2668dnl Check for UTMP/UTMPX headers
2669AC_DEFUN([CF_UTMP],
2670[
2671AC_REQUIRE([CF_LASTLOG])
2672
2673AC_CACHE_CHECK(for utmp implementation,cf_cv_have_utmp,[
2674	cf_cv_have_utmp=no
2675for cf_header in utmpx utmp ; do
2676cf_utmp_includes="
2677#include <sys/types.h>
2678#include <${cf_header}.h>
2679#define getutent getutxent
2680#ifdef USE_LASTLOG
2681#include <lastlog.h>	/* may conflict with utmpx.h on Linux */
2682#endif
2683"
2684	AC_TRY_COMPILE([$cf_utmp_includes],
2685	[struct $cf_header x;
2686	 char *name = x.ut_name; /* utmp.h and compatible definitions */
2687	],
2688	[cf_cv_have_utmp=$cf_header
2689	 break],
2690	[
2691	AC_TRY_COMPILE([$cf_utmp_includes],
2692	[struct $cf_header x;
2693	 char *name = x.ut_user; /* utmpx.h must declare this */
2694	],
2695	[cf_cv_have_utmp=$cf_header
2696	 break
2697	])])
2698done
2699])
2700
2701if test $cf_cv_have_utmp != no ; then
2702	AC_DEFINE(HAVE_UTMP,1,[Define to 1 if the utmp interface is available])
2703	test $cf_cv_have_utmp = utmpx && AC_DEFINE(UTMPX_FOR_UTMP,1,[Define if we have utmpx interface])
2704	CF_UTMP_UT_HOST
2705	CF_UTMP_UT_SYSLEN
2706	CF_UTMP_UT_NAME
2707	CF_UTMP_UT_XSTATUS
2708	CF_UTMP_UT_XTIME
2709	CF_UTMP_UT_SESSION
2710	CF_SYSV_UTMP
2711fi
2712])dnl
2713dnl ---------------------------------------------------------------------------
2714dnl CF_UTMP_GROUP version: 1 updated: 2005/10/06 20:29:29
2715dnl -------------
2716dnl Find the utmp/utmpx file and determine its group to allow setgid programs
2717dnl to manipulate it, e.g., when there is no intermediary.
2718AC_DEFUN([CF_UTMP_GROUP],[
2719AC_REQUIRE([CF_UTMP])
2720if test $cf_cv_have_utmp != no ; then
2721AC_CACHE_CHECK(for utmp/utmpx group,cf_cv_utmp_group,[
2722for cf_utmp_path in /var/adm /var/run
2723do
2724	for cf_utmp_file in utmpx utmp
2725	do
2726		if test -f $cf_utmp_path/$cf_utmp_file
2727		then
2728			cf_cv_utmp_group=root
2729
2730			cf_option="-l -L"
2731
2732			# Expect listing to have fields like this:
2733			#-r--r--r--   1 user      group       34293 Jul 18 16:29 pathname
2734			ls $cf_option $cf_utmp_path/$cf_utmp_file >conftest
2735			read cf_mode cf_links cf_usr cf_grp cf_size cf_date1 cf_date2 cf_date3 cf_rest <conftest
2736			if test -z "$cf_rest" ; then
2737				cf_option="$cf_option -g"
2738				ls $cf_option $cf_utmp_path/$cf_utmp_file >conftest
2739				read cf_mode cf_links cf_usr cf_grp cf_size cf_date1 cf_date2 cf_date3 cf_rest <conftest
2740			fi
2741			rm -f conftest
2742
2743			# If we have a pathname, and the date fields look right, assume we've
2744			# captured the group as well.
2745			if test -n "$cf_rest" ; then
2746				cf_test=`echo "${cf_date2}${cf_date3}" | sed -e 's/[[0-9:]]//g'`
2747				if test -z "$cf_test" ; then
2748					cf_cv_utmp_group=$cf_grp;
2749				fi
2750			fi
2751			break
2752		fi
2753	done
2754	test -n "$cf_cv_utmp_group" && break
2755done
2756])
2757else
2758	AC_MSG_ERROR(cannot find utmp group)
2759fi
2760])dnl
2761dnl ---------------------------------------------------------------------------
2762dnl CF_UTMP_UT_HOST version: 8 updated: 2012/10/04 20:12:20
2763dnl ---------------
2764dnl Check if UTMP/UTMPX struct defines ut_host member
2765AC_DEFUN([CF_UTMP_UT_HOST],
2766[
2767if test $cf_cv_have_utmp != no ; then
2768AC_MSG_CHECKING(if ${cf_cv_have_utmp}.ut_host is declared)
2769AC_CACHE_VAL(cf_cv_have_utmp_ut_host,[
2770	AC_TRY_COMPILE([
2771#include <sys/types.h>
2772#include <${cf_cv_have_utmp}.h>],
2773	[struct $cf_cv_have_utmp x; char *y = &x.ut_host[0]],
2774	[cf_cv_have_utmp_ut_host=yes],
2775	[cf_cv_have_utmp_ut_host=no])
2776	])
2777AC_MSG_RESULT($cf_cv_have_utmp_ut_host)
2778test $cf_cv_have_utmp_ut_host != no && AC_DEFINE(HAVE_UTMP_UT_HOST,1,[Define to 1 if UTMP/UTMPX struct defines ut_host member])
2779fi
2780])dnl
2781dnl ---------------------------------------------------------------------------
2782dnl CF_UTMP_UT_NAME version: 5 updated: 2012/10/04 20:12:20
2783dnl ---------------
2784dnl Check if UTMP/UTMPX struct defines ut_name member
2785AC_DEFUN([CF_UTMP_UT_NAME],
2786[
2787if test $cf_cv_have_utmp != no ; then
2788AC_CACHE_CHECK(if ${cf_cv_have_utmp}.ut_name is declared,cf_cv_have_utmp_ut_name,[
2789	cf_cv_have_utmp_ut_name=no
2790cf_utmp_includes="
2791#include <sys/types.h>
2792#include <${cf_cv_have_utmp}.h>
2793#define getutent getutxent
2794#ifdef USE_LASTLOG
2795#include <lastlog.h>		/* may conflict with utmpx.h on Linux */
2796#endif
2797"
2798for cf_header in ut_name ut_user ; do
2799	AC_TRY_COMPILE([$cf_utmp_includes],
2800	[struct $cf_cv_have_utmp x;
2801	 char *name = x.$cf_header;
2802	],
2803	[cf_cv_have_utmp_ut_name=$cf_header
2804	 break])
2805done
2806])
2807
2808case $cf_cv_have_utmp_ut_name in #(vi
2809no) #(vi
2810	AC_MSG_ERROR(Cannot find declaration for ut.ut_name)
2811	;;
2812ut_user)
2813	AC_DEFINE(ut_name,ut_user,[Define to rename UTMP/UTMPX struct ut_name member])
2814	;;
2815esac
2816fi
2817])dnl
2818dnl ---------------------------------------------------------------------------
2819dnl CF_UTMP_UT_SESSION version: 6 updated: 2012/10/04 20:12:20
2820dnl ------------------
2821dnl Check if UTMP/UTMPX struct defines ut_session member
2822AC_DEFUN([CF_UTMP_UT_SESSION],
2823[
2824if test $cf_cv_have_utmp != no ; then
2825AC_CACHE_CHECK(if ${cf_cv_have_utmp}.ut_session is declared, cf_cv_have_utmp_ut_session,[
2826	AC_TRY_COMPILE([
2827#include <sys/types.h>
2828#include <${cf_cv_have_utmp}.h>],
2829	[struct $cf_cv_have_utmp x; long y = x.ut_session],
2830	[cf_cv_have_utmp_ut_session=yes],
2831	[cf_cv_have_utmp_ut_session=no])
2832])
2833if test $cf_cv_have_utmp_ut_session != no ; then
2834	AC_DEFINE(HAVE_UTMP_UT_SESSION,1,[Define to 1 if UTMP/UTMPX struct defines ut_session member])
2835fi
2836fi
2837])dnl
2838dnl ---------------------------------------------------------------------------
2839dnl CF_UTMP_UT_SYSLEN version: 2 updated: 2012/10/04 20:12:20
2840dnl -----------------
2841dnl Check if UTMP/UTMPX struct defines ut_syslen member
2842AC_DEFUN([CF_UTMP_UT_SYSLEN],
2843[
2844if test $cf_cv_have_utmp != no ; then
2845AC_MSG_CHECKING(if ${cf_cv_have_utmp}.ut_syslen is declared)
2846AC_CACHE_VAL(cf_cv_have_utmp_ut_syslen,[
2847	AC_TRY_COMPILE([
2848#include <sys/types.h>
2849#include <${cf_cv_have_utmp}.h>],
2850	[struct $cf_cv_have_utmp x; int y = x.ut_syslen],
2851	[cf_cv_have_utmp_ut_syslen=yes],
2852	[cf_cv_have_utmp_ut_syslen=no])
2853	])
2854AC_MSG_RESULT($cf_cv_have_utmp_ut_syslen)
2855test $cf_cv_have_utmp_ut_syslen != no && AC_DEFINE(HAVE_UTMP_UT_SYSLEN,1,[Define to 1 if UTMP/UTMPX struct defines ut_syslen member])
2856fi
2857])dnl
2858dnl ---------------------------------------------------------------------------
2859dnl CF_UTMP_UT_XSTATUS version: 4 updated: 2012/10/04 20:12:20
2860dnl ------------------
2861dnl Check for known variants on the UTMP/UTMPX struct's exit-status as reported
2862dnl by various people:
2863dnl
2864dnl	ut_exit.__e_exit (HPUX 11 - David Ellement, also in glibc2)
2865dnl	ut_exit.e_exit (SVR4)
2866dnl	ut_exit.ut_e_exit (os390 - Greg Smith)
2867dnl	ut_exit.ut_exit (Tru64 4.0f - Jeremie Petit, 4.0e - Tomas Vanhala)
2868dnl
2869dnl Note: utmp_xstatus is not a conventional compatibility definition in the
2870dnl system header files.
2871AC_DEFUN([CF_UTMP_UT_XSTATUS],
2872[
2873if test $cf_cv_have_utmp != no ; then
2874AC_CACHE_CHECK(for exit-status in $cf_cv_have_utmp,cf_cv_have_utmp_ut_xstatus,[
2875for cf_result in \
2876	ut_exit.__e_exit \
2877	ut_exit.e_exit \
2878	ut_exit.ut_e_exit \
2879	ut_exit.ut_exit
2880do
2881AC_TRY_COMPILE([
2882#include <sys/types.h>
2883#include <${cf_cv_have_utmp}.h>],
2884	[struct $cf_cv_have_utmp x; long y = x.$cf_result = 0],
2885	[cf_cv_have_utmp_ut_xstatus=$cf_result
2886	 break],
2887	[cf_cv_have_utmp_ut_xstatus=no])
2888done
2889])
2890if test $cf_cv_have_utmp_ut_xstatus != no ; then
2891	AC_DEFINE(HAVE_UTMP_UT_XSTATUS,1,[Define to 1 if UTMP/UTMPX has exit-status member])
2892	AC_DEFINE_UNQUOTED(ut_xstatus,$cf_cv_have_utmp_ut_xstatus,[Define if needed to rename member ut_xstatus of UTMP/UTMPX])
2893fi
2894fi
2895])dnl
2896dnl ---------------------------------------------------------------------------
2897dnl CF_UTMP_UT_XTIME version: 9 updated: 2012/10/04 20:12:20
2898dnl ----------------
2899dnl Check if UTMP/UTMPX struct defines ut_xtime member
2900AC_DEFUN([CF_UTMP_UT_XTIME],
2901[
2902if test $cf_cv_have_utmp != no ; then
2903AC_CACHE_CHECK(if ${cf_cv_have_utmp}.ut_xtime is declared, cf_cv_have_utmp_ut_xtime,[
2904	AC_TRY_COMPILE([
2905#include <sys/types.h>
2906#include <${cf_cv_have_utmp}.h>],
2907	[struct $cf_cv_have_utmp x; long y = x.ut_xtime = 0],
2908	[cf_cv_have_utmp_ut_xtime=yes],
2909	[AC_TRY_COMPILE([
2910#include <sys/types.h>
2911#include <${cf_cv_have_utmp}.h>],
2912	[struct $cf_cv_have_utmp x; long y = x.ut_tv.tv_sec],
2913	[cf_cv_have_utmp_ut_xtime=define],
2914	[cf_cv_have_utmp_ut_xtime=no])
2915	])
2916])
2917if test $cf_cv_have_utmp_ut_xtime != no ; then
2918	AC_DEFINE(HAVE_UTMP_UT_XTIME,1,[Define to 1 if UTMP/UTMPX struct defines ut_xtime member])
2919	if test $cf_cv_have_utmp_ut_xtime = define ; then
2920		AC_DEFINE(ut_xtime,ut_tv.tv_sec,[Define if needed to alternate name for utmpx.ut_xtime member])
2921	fi
2922fi
2923fi
2924])dnl
2925dnl ---------------------------------------------------------------------------
2926dnl CF_VERBOSE version: 3 updated: 2007/07/29 09:55:12
2927dnl ----------
2928dnl Use AC_VERBOSE w/o the warnings
2929AC_DEFUN([CF_VERBOSE],
2930[test -n "$verbose" && echo "	$1" 1>&AC_FD_MSG
2931CF_MSG_LOG([$1])
2932])dnl
2933dnl ---------------------------------------------------------------------------
2934dnl CF_WITH_APP_CLASS version: 2 updated: 2012/10/04 04:29:52
2935dnl -----------------
2936dnl Handle configure option "--with-app-class", setting the $APP_CLASS
2937dnl variable, used for X resources.
2938dnl
2939dnl $1 = default value.
2940AC_DEFUN([CF_WITH_APP_CLASS],[
2941AC_MSG_CHECKING(for X applications class)
2942AC_ARG_WITH(app-class,
2943	[  --with-app-class=XXX    override X applications class (default $1)],
2944	[APP_CLASS=$withval],
2945	[APP_CLASS=$1])
2946
2947case x$APP_CLASS in #(vi
2948*[[/@,%]]*) #(vi
2949	AC_MSG_WARN(X applications class cannot contain punctuation)
2950	APP_CLASS=$1
2951	;;
2952x[[A-Z]]*) #(vi
2953	;;
2954*)
2955	AC_MSG_WARN([X applications class must start with capital, ignoring $APP_CLASS])
2956	APP_CLASS=$1
2957	;;
2958esac
2959
2960AC_MSG_RESULT($APP_CLASS)
2961
2962AC_SUBST(APP_CLASS)
2963])dnl
2964dnl ---------------------------------------------------------------------------
2965dnl CF_WITH_APP_DEFAULTS version: 5 updated: 2012/10/04 04:29:52
2966dnl --------------------
2967dnl Handle configure option "--with-app-defaults", setting these shell
2968dnl variables:
2969dnl
2970dnl $APPSDIR is the option value, used for installing app-defaults files.
2971dnl $no_appsdir is a "#" (comment) if "--without-app-defaults" is given.
2972dnl
2973dnl Most Linux's use this:
2974dnl 	/usr/share/X11/app-defaults
2975dnl Debian uses this:
2976dnl 	/etc/X11/app-defaults
2977dnl DragonFlyBSD ports uses this:
2978dnl 	/usr/pkg/lib/X11/app-defaults
2979dnl FreeBSD ports use these:
2980dnl 	/usr/local/lib/X11/app-defaults
2981dnl 	/usr/local/share/X11/app-defaults
2982dnl Mandriva has these:
2983dnl 	/usr/lib/X11/app-defaults
2984dnl 	/usr/lib64/X11/app-defaults
2985dnl NetBSD has these
2986dnl 	/usr/X11R7/lib/X11/app-defaults
2987dnl OpenSolaris uses
2988dnl 	32-bit:
2989dnl 	/usr/X11/etc/X11/app-defaults
2990dnl 	/usr/X11/share/X11/app-defaults
2991dnl 	/usr/X11/lib/X11/app-defaults
2992dnl	64-bit:
2993dnl 	/usr/X11/etc/X11/app-defaults
2994dnl 	/usr/X11/share/X11/app-defaults (I mkdir'd this)
2995dnl 	/usr/X11/lib/amd64/X11/app-defaults
2996dnl Solaris10 uses (in this order):
2997dnl 	/usr/openwin/lib/X11/app-defaults
2998dnl 	/usr/X11/lib/X11/app-defaults
2999AC_DEFUN([CF_WITH_APP_DEFAULTS],[
3000AC_MSG_CHECKING(for directory to install resource files)
3001AC_ARG_WITH(app-defaults,
3002	[  --with-app-defaults=DIR directory in which to install resource files (EPREFIX/lib/X11/app-defaults)],
3003	[APPSDIR=$withval],
3004	[APPSDIR='${exec_prefix}/lib/X11/app-defaults'])
3005
3006if test "x[$]APPSDIR" = xauto
3007then
3008	APPSDIR='${exec_prefix}/lib/X11/app-defaults'
3009	for cf_path in \
3010		/usr/share/X11/app-defaults \
3011		/usr/X11/share/X11/app-defaults \
3012		/usr/X11/lib/X11/app-defaults \
3013		/usr/lib/X11/app-defaults \
3014		/etc/X11/app-defaults \
3015		/usr/pkg/lib/X11/app-defaults \
3016		/usr/X11R7/lib/X11/app-defaults \
3017		/usr/X11R6/lib/X11/app-defaults \
3018		/usr/X11R5/lib/X11/app-defaults \
3019		/usr/X11R4/lib/X11/app-defaults \
3020		/usr/local/lib/X11/app-defaults \
3021		/usr/local/share/X11/app-defaults \
3022		/usr/lib64/X11/app-defaults
3023	do
3024		if test -d "$cf_path" ; then
3025			APPSDIR="$cf_path"
3026			break
3027		fi
3028	done
3029else
3030	cf_path=$APPSDIR
3031	CF_PATH_SYNTAX(cf_path)
3032fi
3033
3034AC_MSG_RESULT($APPSDIR)
3035AC_SUBST(APPSDIR)
3036
3037no_appsdir=
3038if test "$APPSDIR" = no
3039then
3040	no_appsdir="#"
3041else
3042	EXTRA_INSTALL_DIRS="$EXTRA_INSTALL_DIRS \$(APPSDIR)"
3043fi
3044AC_SUBST(no_appsdir)
3045])dnl
3046dnl ---------------------------------------------------------------------------
3047dnl CF_WITH_DBMALLOC version: 7 updated: 2010/06/21 17:26:47
3048dnl ----------------
3049dnl Configure-option for dbmalloc.  The optional parameter is used to override
3050dnl the updating of $LIBS, e.g., to avoid conflict with subsequent tests.
3051AC_DEFUN([CF_WITH_DBMALLOC],[
3052CF_NO_LEAKS_OPTION(dbmalloc,
3053	[  --with-dbmalloc         test: use Conor Cahill's dbmalloc library],
3054	[USE_DBMALLOC])
3055
3056if test "$with_dbmalloc" = yes ; then
3057	AC_CHECK_HEADER(dbmalloc.h,
3058		[AC_CHECK_LIB(dbmalloc,[debug_malloc]ifelse([$1],,[],[,$1]))])
3059fi
3060])dnl
3061dnl ---------------------------------------------------------------------------
3062dnl CF_WITH_DESKTOP_CATEGORY version: 4 updated: 2013/01/01 10:50:14
3063dnl ------------------------
3064dnl Taking into account the absence of standardization of desktop categories
3065dnl take a look to see whether other applications on the current system are
3066dnl assigned any/all of a set of suggested categories.
3067dnl
3068dnl $1 = program name
3069dnl $2 = case-pattern to match comparable desktop files to obtain category
3070dnl      This pattern may contain wildcards.
3071dnl $3 = suggested categories, also a case-pattern but without wildcards,
3072dnl      since it doubles as a default value for a shell case-statement.
3073dnl $4 = categories to use if no match is found on the build-machine for the
3074dnl      --with-desktop-category "auto" setting.
3075dnl
3076dnl The macro tells the configure script to substitute the $DESKTOP_CATEGORY
3077dnl value.
3078AC_DEFUN([CF_WITH_DESKTOP_CATEGORY],[
3079AC_REQUIRE([CF_DISABLE_DESKTOP])
3080
3081if test -z "$desktop_utils"
3082then
3083	AC_MSG_CHECKING(for requested desktop-category)
3084	AC_ARG_WITH(desktop-category,
3085		[  --with-desktop-category=XXX  one or more desktop catgories or auto],
3086		[cf_desktop_want=$withval],
3087		[cf_desktop_want=auto])
3088	AC_MSG_RESULT($cf_desktop_want)
3089
3090	if test "$cf_desktop_want" = auto
3091	then
3092		rm -rf conftest*
3093		cf_desktop_also=
3094		for cf_desktop_dir in  \
3095			/usr/share/app-install \
3096			/usr/share/applications
3097		do
3098			if test -d $cf_desktop_dir
3099			then
3100				find $cf_desktop_dir -name '*.desktop' | \
3101				while true
3102				do
3103					read cf_desktop_path
3104					test -z "$cf_desktop_path" && break
3105					cf_desktop_name=`basename $cf_desktop_path .desktop`
3106					case $cf_desktop_name in #(vi
3107					$1|*-$1|$2)
3108						CF_VERBOSE(inspect $cf_desktop_path)
3109						egrep '^Categories=' $cf_desktop_path | \
3110							tr ';' '\n' | \
3111							sed -e 's%^.*=%%' -e '/^$/d' >>conftest.1
3112						;;
3113					esac
3114				done
3115			fi
3116		done
3117		if test -s conftest.1
3118		then
3119			cf_desktop_last=
3120			sort conftest.1 | \
3121			while true
3122			do
3123				read cf_desktop_this
3124				test -z "$cf_desktop_this" && break
3125				case $cf_desktop_this in #(vi
3126				Qt*|GTK*|KDE*|GNOME*|*XFCE*|*Xfce*) #(vi
3127					;;
3128				$3)
3129					test "x$cf_desktop_last" != "x$cf_desktop_this" && echo $cf_desktop_this >>conftest.2
3130					;;
3131				esac
3132				cf_desktop_last=$cf_desktop_this
3133			done
3134			cf_desktop_want=`cat conftest.2 | tr '\n' ';'`
3135		fi
3136		if test -n "$cf_desktop_want"
3137		then
3138			if test "$cf_desktop_want" = auto
3139			then
3140				cf_desktop_want=
3141			else
3142				# do a sanity check on the semicolon-separated list, ignore on failure
3143				cf_desktop_test=`echo "$cf_desktop_want" | sed -e 's/[[^;]]//g'`
3144				test -z "$cf_desktop_test" && cf_desktop_want=
3145				cf_desktop_test=`echo "$cf_desktop_want" | sed -e 's/^.*;$/./g'`
3146				test -z "$cf_desktop_test" && cf_desktop_want=
3147			fi
3148		fi
3149		if test -z "$cf_desktop_want"
3150		then
3151			cf_desktop_want="ifelse([$4],,ifelse([$3],,[Application;],[`echo "$3" | sed -e 's/\*//g' -e 's/|/;/g' -e 's/[[;]]*$/;/g'`]),[$4])"
3152			CF_VERBOSE(no usable value found for desktop category, using $cf_desktop_want)
3153		fi
3154	fi
3155	DESKTOP_CATEGORY=`echo "$cf_desktop_want" | sed -e 's/[[ ,]]/;/g'`
3156	CF_VERBOSE(will use Categories=$DESKTOP_CATEGORY)
3157	AC_SUBST(DESKTOP_CATEGORY)
3158fi
3159])
3160dnl ---------------------------------------------------------------------------
3161dnl CF_WITH_DMALLOC version: 7 updated: 2010/06/21 17:26:47
3162dnl ---------------
3163dnl Configure-option for dmalloc.  The optional parameter is used to override
3164dnl the updating of $LIBS, e.g., to avoid conflict with subsequent tests.
3165AC_DEFUN([CF_WITH_DMALLOC],[
3166CF_NO_LEAKS_OPTION(dmalloc,
3167	[  --with-dmalloc          test: use Gray Watson's dmalloc library],
3168	[USE_DMALLOC])
3169
3170if test "$with_dmalloc" = yes ; then
3171	AC_CHECK_HEADER(dmalloc.h,
3172		[AC_CHECK_LIB(dmalloc,[dmalloc_debug]ifelse([$1],,[],[,$1]))])
3173fi
3174])dnl
3175dnl ---------------------------------------------------------------------------
3176dnl CF_WITH_ICONDIR version: 5 updated: 2012/07/22 09:18:02
3177dnl ---------------
3178dnl Handle configure option "--with-icondir", setting these shell variables:
3179dnl
3180dnl $ICONDIR is the option value, used for installing icon files.
3181dnl $no_icondir is a "#" (comment) if "--without-icondir" is given.
3182AC_DEFUN([CF_WITH_ICONDIR],[
3183AC_MSG_CHECKING(for directory to install icons)
3184AC_ARG_WITH(icondir,
3185	[  --with-icondir=DIR      directory in which to install icons for desktop],
3186	[ICONDIR=$withval],
3187	[test -z "$ICONDIR" && ICONDIR=no])
3188
3189if test "x[$]ICONDIR" = xauto
3190then
3191	ICONDIR='${datadir}/icons'
3192	for cf_path in \
3193		/usr/share/icons \
3194		/usr/X11R6/share/icons
3195	do
3196		if test -d "$cf_path" ; then
3197			ICONDIR="$cf_path"
3198			break
3199		fi
3200	done
3201else
3202	cf_path=$ICONDIR
3203	CF_PATH_SYNTAX(cf_path)
3204fi
3205AC_MSG_RESULT($ICONDIR)
3206AC_SUBST(ICONDIR)
3207
3208no_icondir=
3209if test "$ICONDIR" = no
3210then
3211	no_icondir="#"
3212else
3213	EXTRA_INSTALL_DIRS="$EXTRA_INSTALL_DIRS \$(ICONDIR)"
3214fi
3215AC_SUBST(no_icondir)
3216])dnl
3217dnl ---------------------------------------------------------------------------
3218dnl CF_WITH_ICON_NAME version: 2 updated: 2013/05/27 18:34:42
3219dnl -----------------
3220dnl Allow a default icon-name to be overridden.
3221dnl $1 = default icon name
3222AC_DEFUN([CF_WITH_ICON_NAME],[
3223AC_MSG_CHECKING(for the icon name)
3224AC_ARG_WITH(icon-name,
3225	[  --with-icon-name=XXXX   override icon name (default: $1)],
3226	[ICON_NAME="$withval"],
3227	[ICON_NAME=$1])
3228case "x$ICON_NAME" in
3229xyes|xno|x)
3230	ICON_NAME=$1
3231	;;
3232esac
3233AC_SUBST(ICON_NAME)
3234AC_MSG_RESULT($ICON_NAME)
3235])dnl
3236dnl ---------------------------------------------------------------------------
3237dnl CF_WITH_ICON_SYMLINK version: 1 updated: 2013/05/27 18:34:42
3238dnl --------------------
3239dnl Workaround for systems which are (mis)configured to map all icon references
3240dnl for xterm into "xterm" name.  For instance, recent (2013) KDE ignores both
3241dnl the name given in the .desktop file (xterm-color) and the application name
3242dnl (xterm-dev).
3243dnl
3244dnl $1 = default icon name to use if symlink is wanted
3245AC_DEFUN([CF_WITH_ICON_SYMLINK],[
3246AC_MSG_CHECKING(for icon symlink to use)
3247AC_ARG_WITH(icon-symlink,
3248	[  --with-icon-symlink=XXX make symbolic link for icon name (default: $1)],
3249	[ICON_SYMLINK="$withval"],
3250	[ICON_SYMLINK=NONE])
3251case "x$ICON_SYMLINK" in
3252xyes)
3253	ICON_SYMLINK=$1
3254	;;
3255xno|x)
3256	ICON_SYMLINK=NONE
3257	;;
3258esac
3259AC_SUBST(ICON_SYMLINK)
3260AC_MSG_RESULT($ICON_SYMLINK)
3261])dnl
3262dnl ---------------------------------------------------------------------------
3263dnl CF_WITH_ICON_THEME version: 9 updated: 2013/04/17 05:31:24
3264dnl ------------------
3265dnl If asked, check for prerequisites and setup symbols to permit installing
3266dnl one or more application icons in the Red Hat icon-theme directory
3267dnl hierarchy. 
3268dnl
3269dnl If the prerequisites are missing, give a warning and revert to the long-
3270dnl standing pixmaps directory.
3271dnl
3272dnl Parameters:
3273dnl
3274dnl $1 = application icon.  This can be a list, and is not optional.
3275dnl $2 = default theme (defaults to hicolor)
3276dnl $3 = formats (defaults to list [.svg .png .xpm])
3277dnl $4 = alternate icon if no theme is used (defaults to $1).
3278dnl
3279dnl Result:
3280dnl ICON_NAME = basename of first item in $1
3281dnl ICON_LIST = reprocessed $1
3282dnl ICON_THEME = reprocessed $2
3283dnl ICON_FORMAT = reprocessed $3
3284AC_DEFUN([CF_WITH_ICON_THEME],
3285[
3286ifelse([$1],,[
3287	AC_MSG_ERROR([macro [CF_WITH_ICON_THEME] requires application-icon name])
3288],[
3289
3290CF_WITH_PIXMAPDIR
3291CF_WITH_ICONDIR
3292
3293AC_MSG_CHECKING(if icon theme should be used)
3294AC_ARG_WITH(icon-theme,
3295	[  --with-icon-theme=XXX   install icons into desktop theme (hicolor)],
3296	[ICON_THEME=$withval],
3297	[ICON_THEME=no])
3298
3299case "x$ICON_THEME" in #(vi
3300xno) #(vi
3301	;;
3302x|xyes)
3303	ICON_THEME=ifelse([$2],,hicolor,$2)
3304	;;
3305esac
3306AC_MSG_RESULT($ICON_THEME)
3307
3308if test "x$ICON_THEME" = xno
3309then
3310	if test "x$ICONDIR" != xno
3311	then
3312		CF_VERBOSE(ignoring icondir without theme)
3313		no_icondir="#"
3314	fi
3315else
3316	if test "x$ICONDIR" = xno
3317	then
3318		AC_MSG_ERROR(icondir must be set for icon theme)
3319	fi
3320fi
3321
3322: ${ICON_FORMAT:=ifelse([$3],,[".svg .png .xpm"],[$3])}
3323
3324# ICON_NAME=
3325ICON_LIST=
3326
3327ifelse([$4],,[cf_icon_list=$1],[
3328if test "x$ICON_THEME" != xno
3329then
3330	cf_icon_list="$1"
3331else
3332	cf_icon_list="$4"
3333fi
3334])
3335
3336AC_MSG_CHECKING([for icon(s) to install])
3337for cf_name in $cf_icon_list
3338do
3339	CF_VERBOSE(using $ICON_FORMAT)
3340	for cf_suffix in $ICON_FORMAT
3341	do
3342		cf_icon="${cf_name}${cf_suffix}"
3343		cf_left=`echo "$cf_icon" | sed -e 's/:.*//'`
3344		if test ! -f "${cf_left}"
3345		then
3346			if test "x$srcdir" != "x."
3347			then
3348				cf_icon="${srcdir}/${cf_left}"
3349				cf_left=`echo "$cf_icon" | sed -e 's/:.*//'`
3350				if test ! -f "${cf_left}"
3351				then
3352					continue
3353				fi
3354			else
3355				continue
3356			fi
3357		fi
3358		if test "x$ICON_THEME" != xno
3359		then
3360			cf_base=`basename $cf_left`
3361			cf_trim=`echo "$cf_base" | sed -e 's/_[[0-9]][[0-9]]x[[0-9]][[0-9]]\././'`
3362			case "x${cf_base}" in #(vi
3363			*:*) #(vi
3364				cf_next=$cf_base
3365				# user-defined mapping
3366				;;
3367			*.png) #(vi
3368				cf_size=`file "$cf_left"|sed -e 's/^[[^:]]*://' -e 's/^.*[[^0-9]]\([[0-9]][[0-9]]* x [[0-9]][[0-9]]*\)[[^0-9]].*$/\1/' -e 's/ //g'`
3369				if test -z "$cf_size"
3370				then
3371					AC_MSG_WARN(cannot determine size of $cf_left)
3372					continue
3373				fi
3374				cf_next="$cf_size/apps/$cf_trim"
3375				;;
3376			*.svg) #(vi
3377				cf_next="scalable/apps/$cf_trim"
3378				;;
3379			*.xpm)
3380				CF_VERBOSE(ignored XPM file in icon theme)
3381				continue
3382				;;
3383			*_[[0-9]][[0-9]]*x[[0-9]][[0-9]]*.*) #(vi
3384				cf_size=`echo "$cf_left"|sed -e 's/^.*_\([[0-9]][[0-9]]*x[[0-9]][[0-9]]*\)\..*$/\1/'`
3385				cf_left=`echo "$cf_left"|sed -e 's/^\(.*\)_\([[0-9]][[0-9]]*x[[0-9]][[0-9]]*\)\(\..*\)$/\1\3/'`
3386				cf_next="$cf_size/apps/$cf_base"
3387				;;
3388			esac
3389			CF_VERBOSE(adding $cf_next)
3390			cf_icon="${cf_icon}:${cf_next}"
3391		fi
3392		test -n "$ICON_LIST" && ICON_LIST="$ICON_LIST "
3393		ICON_LIST="$ICON_LIST${cf_icon}"
3394		if test -z "$ICON_NAME"
3395		then
3396			ICON_NAME=`basename $cf_icon | sed -e 's/[[.:]].*//'`
3397		fi
3398	done
3399done
3400
3401if test -n "$verbose"
3402then
3403	AC_MSG_CHECKING(result)
3404fi
3405AC_MSG_RESULT($ICON_LIST)
3406
3407if test -z "$ICON_LIST"
3408then
3409	AC_MSG_ERROR(no icons found)
3410fi
3411])
3412
3413AC_MSG_CHECKING(for icon name)
3414AC_MSG_RESULT($ICON_NAME)
3415
3416AC_SUBST(ICON_FORMAT)
3417AC_SUBST(ICON_THEME)
3418AC_SUBST(ICON_LIST)
3419AC_SUBST(ICON_NAME)
3420])dnl
3421dnl ---------------------------------------------------------------------------
3422dnl CF_WITH_IMAKE_CFLAGS version: 9 updated: 2010/05/26 05:38:42
3423dnl --------------------
3424dnl xterm and similar programs build more readily when propped up with imake's
3425dnl hand-tuned definitions.  If we do not use imake, provide fallbacks for the
3426dnl most common definitions that we're not likely to do by autoconf tests.
3427AC_DEFUN([CF_WITH_IMAKE_CFLAGS],[
3428AC_REQUIRE([CF_ENABLE_NARROWPROTO])
3429
3430AC_MSG_CHECKING(if we should use imake to help)
3431CF_ARG_DISABLE(imake,
3432	[  --disable-imake         disable use of imake for definitions],
3433	[enable_imake=no],
3434	[enable_imake=yes])
3435AC_MSG_RESULT($enable_imake)
3436
3437if test "$enable_imake" = yes ; then
3438	CF_IMAKE_CFLAGS(ifelse([$1],,,[$1]))
3439fi
3440
3441if test -n "$IMAKE" && test -n "$IMAKE_CFLAGS" ; then
3442	CF_ADD_CFLAGS($IMAKE_CFLAGS)
3443else
3444	IMAKE_CFLAGS=
3445	IMAKE_LOADFLAGS=
3446	CF_VERBOSE(make fallback definitions)
3447
3448	# We prefer config.guess' values when we can get them, to avoid
3449	# inconsistent results with uname (AIX for instance).  However,
3450	# config.guess is not always consistent either.
3451	case $host_os in
3452	*[[0-9]].[[0-9]]*)
3453		UNAME_RELEASE="$host_os"
3454		;;
3455	*)
3456		UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown
3457		;;
3458	esac
3459
3460	case .$UNAME_RELEASE in
3461	*[[0-9]].[[0-9]]*)
3462		OSMAJORVERSION=`echo "$UNAME_RELEASE" |sed -e 's/^[[^0-9]]*//' -e 's/\..*//'`
3463		OSMINORVERSION=`echo "$UNAME_RELEASE" |sed -e 's/^[[^0-9]]*//' -e 's/^[[^.]]*\.//' -e 's/\..*//' -e 's/[[^0-9]].*//' `
3464		test -z "$OSMAJORVERSION" && OSMAJORVERSION=1
3465		test -z "$OSMINORVERSION" && OSMINORVERSION=0
3466		IMAKE_CFLAGS="-DOSMAJORVERSION=$OSMAJORVERSION -DOSMINORVERSION=$OSMINORVERSION $IMAKE_CFLAGS"
3467		;;
3468	esac
3469
3470	# FUNCPROTO is standard with X11R6, but XFree86 drops it, leaving some
3471	# fallback/fragments for NeedPrototypes, etc.
3472	IMAKE_CFLAGS="-DFUNCPROTO=15 $IMAKE_CFLAGS"
3473
3474	# If this is not set properly, Xaw's scrollbars will not work
3475	if test "$enable_narrowproto" = yes ; then
3476		IMAKE_CFLAGS="-DNARROWPROTO=1 $IMAKE_CFLAGS"
3477	fi
3478
3479	# Other special definitions:
3480	case $host_os in
3481	aix*)
3482		# imake on AIX 5.1 defines AIXV3.  really.
3483		IMAKE_CFLAGS="-DAIXV3 -DAIXV4 $IMAKE_CFLAGS"
3484		;;
3485	irix[[56]].*) #(vi
3486		# these are needed to make SIGWINCH work in xterm
3487		IMAKE_CFLAGS="-DSYSV -DSVR4 $IMAKE_CFLAGS"
3488		;;
3489	esac
3490
3491	CF_ADD_CFLAGS($IMAKE_CFLAGS)
3492
3493	AC_SUBST(IMAKE_CFLAGS)
3494	AC_SUBST(IMAKE_LOADFLAGS)
3495fi
3496])dnl
3497dnl ---------------------------------------------------------------------------
3498dnl CF_WITH_PCRE version: 10 updated: 2012/10/04 20:12:20
3499dnl ------------
3500dnl Add PCRE (Perl-compatible regular expressions) to the build if it is
3501dnl available and the user requests it.  Assume the application will otherwise
3502dnl use the POSIX interface.
3503dnl
3504dnl TODO allow $withval to specify package location
3505AC_DEFUN([CF_WITH_PCRE],
3506[
3507AC_REQUIRE([CF_PKG_CONFIG])
3508
3509AC_MSG_CHECKING(if you want to use PCRE for regular-expressions)
3510AC_ARG_WITH(pcre,
3511	[  --with-pcre             use PCRE for regular-expressions])
3512test -z "$with_pcre" && with_pcre=no
3513AC_MSG_RESULT($with_pcre)
3514
3515if test "$with_pcre" != no ; then
3516	CF_TRY_PKG_CONFIG(libpcre,,[
3517		AC_CHECK_LIB(pcre,pcre_compile,,
3518			AC_MSG_ERROR(Cannot find PCRE library))])
3519
3520		AC_DEFINE(HAVE_LIB_PCRE,1,[Define to 1 if we can/should compile with the PCRE library])
3521
3522		case $LIBS in #(vi
3523		*pcreposix*) #(vi
3524			;;
3525		*)
3526			AC_CHECK_LIB(pcreposix,pcreposix_regcomp,
3527				[AC_DEFINE(HAVE_PCREPOSIX_H,1,[Define to 1 if we should include pcreposix.h])
3528				 CF_ADD_LIB(pcreposix)],
3529				[AC_CHECK_LIB(pcreposix,regcomp,[
3530					AC_DEFINE(HAVE_PCREPOSIX_H,1,[Define to 1 if we should include pcreposix.h])
3531					CF_ADD_LIB(pcreposix)],
3532					AC_MSG_ERROR(Cannot find PCRE POSIX library)]))
3533			;;
3534		esac
3535fi
3536])dnl
3537dnl ---------------------------------------------------------------------------
3538dnl CF_WITH_PIXMAPDIR version: 3 updated: 2012/07/22 09:18:02
3539dnl -----------------
3540dnl Handle configure option "--with-pixmapdir", setting these shell variables:
3541dnl
3542dnl $PIXMAPDIR is the option value, used for installing pixmap files.
3543dnl $no_pixmapdir is a "#" (comment) if "--without-pixmapdir" is given.
3544AC_DEFUN([CF_WITH_PIXMAPDIR],[
3545AC_MSG_CHECKING(for directory to install pixmaps)
3546AC_ARG_WITH(pixmapdir,
3547	[  --with-pixmapdir=DIR    directory in which to install pixmaps (DATADIR/pixmaps)],
3548	[PIXMAPDIR=$withval],
3549	[test -z "$PIXMAPDIR" && PIXMAPDIR='${datadir}/pixmaps'])
3550
3551if test "x[$]PIXMAPDIR" = xauto
3552then
3553	PIXMAPDIR='${datadir}/pixmaps'
3554	for cf_path in \
3555		/usr/share/pixmaps \
3556		/usr/X11R6/share/pixmaps
3557	do
3558		if test -d "$cf_path" ; then
3559			PIXMAPDIR="$cf_path"
3560			break
3561		fi
3562	done
3563else
3564	cf_path=$PIXMAPDIR
3565	CF_PATH_SYNTAX(cf_path)
3566fi
3567AC_MSG_RESULT($PIXMAPDIR)
3568AC_SUBST(PIXMAPDIR)
3569
3570no_pixmapdir=
3571if test "$PIXMAPDIR" = no
3572then
3573	no_pixmapdir="#"
3574else
3575	EXTRA_INSTALL_DIRS="$EXTRA_INSTALL_DIRS \$(PIXMAPDIR)"
3576fi
3577AC_SUBST(no_pixmapdir)
3578])dnl
3579dnl ---------------------------------------------------------------------------
3580dnl CF_WITH_VALGRIND version: 1 updated: 2006/12/14 18:00:21
3581dnl ----------------
3582AC_DEFUN([CF_WITH_VALGRIND],[
3583CF_NO_LEAKS_OPTION(valgrind,
3584	[  --with-valgrind         test: use valgrind],
3585	[USE_VALGRIND])
3586])dnl
3587dnl ---------------------------------------------------------------------------
3588dnl CF_WITH_XPM version: 3 updated: 2012/10/04 06:57:36
3589dnl -----------
3590dnl Test for Xpm library, update compiler/loader flags if it is wanted and
3591dnl found.
3592dnl
3593dnl Also sets ICON_SUFFIX
3594AC_DEFUN([CF_WITH_XPM],
3595[
3596ICON_SUFFIX=.xbm
3597
3598cf_save_cppflags="${CPPFLAGS}"
3599cf_save_ldflags="${LDFLAGS}"
3600
3601AC_MSG_CHECKING(if you want to use the Xpm library for colored icon)
3602AC_ARG_WITH(xpm,
3603[  --with-xpm=DIR          use Xpm library for colored icon, may specify path],
3604	[cf_Xpm_library="$withval"],
3605	[cf_Xpm_library=yes])
3606AC_MSG_RESULT($cf_Xpm_library)
3607
3608if test "$cf_Xpm_library" != no ; then
3609    if test "$cf_Xpm_library" != yes ; then
3610	CPPFLAGS="$CPPFLAGS -I$withval/include"
3611	LDFLAGS="$LDFLAGS -L$withval/lib"
3612    fi
3613    AC_CHECK_HEADER(X11/xpm.h,[
3614	AC_CHECK_LIB(Xpm, XpmCreatePixmapFromData,[
3615	    AC_DEFINE(HAVE_LIBXPM,1,[Define to 1 if we should use Xpm library])
3616	    ICON_SUFFIX=.xpm
3617	    LIBS="-lXpm $LIBS"],
3618	    [CPPFLAGS="${cf_save_cppflags}" LDFLAGS="${cf_save_ldflags}"],
3619	    [-lX11 $X_LIBS])],
3620	[CPPFLAGS="${cf_save_cppflags}" LDFLAGS="${cf_save_ldflags}"])
3621fi
3622
3623AC_SUBST(ICON_SUFFIX)
3624])dnl
3625dnl ---------------------------------------------------------------------------
3626dnl CF_XBOOL_RESULT version: 2 updated: 2012/10/04 06:57:36
3627dnl ---------------
3628dnl Translate an autoconf boolean yes/no into X11's booleans, e.g., True/False.
3629dnl Allow for more than two values, e.g., "maybe", still using the same leading
3630dnl capital convention.
3631dnl
3632dnl $1 = symbol to define
3633dnl $2 = symbol holding value
3634dnl $3 = description
3635define([CF_XBOOL_RESULT],[
3636AC_MSG_RESULT([$]$2)
3637case [$]$2 in #(vi
3638yes) #(vi
3639	$2=true
3640	;;
3641no) #(vi
3642	$2=false
3643	;;
3644esac
3645cf_xbool1=`echo "[$]$2"|sed -e 's/^\(.\).*/\1/'`
3646CF_UPPER(cf_xbool1,$cf_xbool1)
3647cf_xbool2=`echo "[$]$2"|sed -e 's/^.//'`
3648$2=${cf_xbool1}${cf_xbool2}
3649AC_DEFINE_UNQUOTED($1,[$]$2,$3)
3650AC_SUBST($2)
3651])
3652dnl ---------------------------------------------------------------------------
3653dnl CF_XKB_BELL_EXT version: 4 updated: 2012/10/04 20:12:20
3654dnl ---------------
3655dnl Check for XKB bell extension
3656AC_DEFUN([CF_XKB_BELL_EXT],[
3657AC_CACHE_CHECK(for XKB Bell extension, cf_cv_xkb_bell_ext,[
3658AC_TRY_LINK([
3659#include <X11/Intrinsic.h>
3660#include <X11/XKBlib.h>		/* has the prototype */
3661#include <X11/extensions/XKBbells.h>	/* has the XkbBI_xxx definitions */
3662],[
3663	int x = (XkbBI_Info |XkbBI_MinorError |XkbBI_MajorError |XkbBI_TerminalBell |XkbBI_MarginBell);
3664	Atom y;
3665	XkbBell((Display *)0, (Widget)0, 0, y);
3666],[cf_cv_xkb_bell_ext=yes],[cf_cv_xkb_bell_ext=no])
3667])
3668test "$cf_cv_xkb_bell_ext" = yes && AC_DEFINE(HAVE_XKB_BELL_EXT,1,[Define 1 if we have XKB Bell extension])
3669])
3670dnl ---------------------------------------------------------------------------
3671dnl CF_XKB_KEYCODE_TO_KEYSYM version: 2 updated: 2012/09/28 20:23:33
3672dnl ------------------------
3673dnl Some older vendor-unix systems made a practice of delivering fragments of
3674dnl Xkb, requiring test-compiles.
3675AC_DEFUN([CF_XKB_KEYCODE_TO_KEYSYM],[
3676AC_CACHE_CHECK(if we can use XkbKeycodeToKeysym, cf_cv_xkb_keycode_to_keysym,[
3677AC_TRY_COMPILE([
3678#include <X11/Xlib.h>
3679#include <X11/XKBlib.h>
3680],[
3681    KeySym keysym = XkbKeycodeToKeysym((Display *)0, 0, 0, 0);
3682],[
3683cf_cv_xkb_keycode_to_keysym=yes
3684],[
3685cf_cv_xkb_keycode_to_keysym=no
3686])
3687])
3688
3689if test $cf_cv_xkb_keycode_to_keysym = yes
3690then
3691	AC_CHECK_FUNCS(XkbKeycodeToKeysym)
3692fi
3693])
3694dnl ---------------------------------------------------------------------------
3695dnl CF_XKB_QUERY_EXTENSION version: 2 updated: 2012/09/28 20:23:46
3696dnl ----------------------
3697dnl see ifdef in scrollbar.c - iron out here
3698AC_DEFUN([CF_XKB_QUERY_EXTENSION],[
3699AC_CACHE_CHECK(if we can use XkbQueryExtension, cf_cv_xkb_query_extension,[
3700AC_TRY_COMPILE([
3701#include <X11/Xlib.h>
3702#include <X11/extensions/XKB.h>
3703#include <X11/XKBlib.h>
3704],[
3705	int xkbmajor = XkbMajorVersion;
3706	int xkbminor = XkbMinorVersion;
3707	int xkbopcode, xkbevent, xkberror;
3708
3709	if (XkbLibraryVersion(&xkbmajor, &xkbminor)
3710	    && XkbQueryExtension((Display *)0,
3711				 &xkbopcode,
3712				 &xkbevent,
3713				 &xkberror,
3714				 &xkbmajor,
3715				 &xkbminor))
3716		 return 0;
3717],[
3718cf_cv_xkb_query_extension=yes
3719],[
3720cf_cv_xkb_query_extension=no
3721])
3722])
3723
3724if test $cf_cv_xkb_query_extension = yes
3725then
3726	AC_CHECK_FUNCS(XkbQueryExtension)
3727fi
3728])
3729dnl ---------------------------------------------------------------------------
3730dnl CF_XOPEN_SOURCE version: 45 updated: 2013/09/07 14:06:25
3731dnl ---------------
3732dnl Try to get _XOPEN_SOURCE defined properly that we can use POSIX functions,
3733dnl or adapt to the vendor's definitions to get equivalent functionality,
3734dnl without losing the common non-POSIX features.
3735dnl
3736dnl Parameters:
3737dnl	$1 is the nominal value for _XOPEN_SOURCE
3738dnl	$2 is the nominal value for _POSIX_C_SOURCE
3739AC_DEFUN([CF_XOPEN_SOURCE],[
3740AC_REQUIRE([AC_CANONICAL_HOST])
3741
3742cf_XOPEN_SOURCE=ifelse([$1],,500,[$1])
3743cf_POSIX_C_SOURCE=ifelse([$2],,199506L,[$2])
3744cf_xopen_source=
3745
3746case $host_os in #(vi
3747aix[[4-7]]*) #(vi
3748	cf_xopen_source="-D_ALL_SOURCE"
3749	;;
3750cygwin|msys) #(vi
3751	cf_XOPEN_SOURCE=600
3752	;;
3753darwin[[0-8]].*) #(vi
3754	cf_xopen_source="-D_APPLE_C_SOURCE"
3755	;;
3756darwin*) #(vi
3757	cf_xopen_source="-D_DARWIN_C_SOURCE"
3758	cf_XOPEN_SOURCE=
3759	;;
3760freebsd*|dragonfly*) #(vi
3761	# 5.x headers associate
3762	#	_XOPEN_SOURCE=600 with _POSIX_C_SOURCE=200112L
3763	#	_XOPEN_SOURCE=500 with _POSIX_C_SOURCE=199506L
3764	cf_POSIX_C_SOURCE=200112L
3765	cf_XOPEN_SOURCE=600
3766	cf_xopen_source="-D_BSD_TYPES -D__BSD_VISIBLE -D_POSIX_C_SOURCE=$cf_POSIX_C_SOURCE -D_XOPEN_SOURCE=$cf_XOPEN_SOURCE"
3767	;;
3768hpux11*) #(vi
3769	cf_xopen_source="-D_HPUX_SOURCE -D_XOPEN_SOURCE=500"
3770	;;
3771hpux*) #(vi
3772	cf_xopen_source="-D_HPUX_SOURCE"
3773	;;
3774irix[[56]].*) #(vi
3775	cf_xopen_source="-D_SGI_SOURCE"
3776	cf_XOPEN_SOURCE=
3777	;;
3778linux*|gnu*|mint*|k*bsd*-gnu) #(vi
3779	CF_GNU_SOURCE
3780	;;
3781mirbsd*) #(vi
3782	# setting _XOPEN_SOURCE or _POSIX_SOURCE breaks <sys/select.h> and other headers which use u_int / u_short types
3783	cf_XOPEN_SOURCE=
3784	CF_POSIX_C_SOURCE($cf_POSIX_C_SOURCE)
3785	;;
3786netbsd*) #(vi
3787	cf_xopen_source="-D_NETBSD_SOURCE" # setting _XOPEN_SOURCE breaks IPv6 for lynx on NetBSD 1.6, breaks xterm, is not needed for ncursesw
3788	;;
3789openbsd[[4-9]]*) #(vi
3790	# setting _XOPEN_SOURCE lower than 500 breaks g++ compile with wchar.h, needed for ncursesw
3791	cf_xopen_source="-D_BSD_SOURCE"
3792	cf_XOPEN_SOURCE=600
3793	;;
3794openbsd*) #(vi
3795	# setting _XOPEN_SOURCE breaks xterm on OpenBSD 2.8, is not needed for ncursesw
3796	;;
3797osf[[45]]*) #(vi
3798	cf_xopen_source="-D_OSF_SOURCE"
3799	;;
3800nto-qnx*) #(vi
3801	cf_xopen_source="-D_QNX_SOURCE"
3802	;;
3803sco*) #(vi
3804	# setting _XOPEN_SOURCE breaks Lynx on SCO Unix / OpenServer
3805	;;
3806solaris2.*) #(vi
3807	cf_xopen_source="-D__EXTENSIONS__"
3808	;;
3809*)
3810	CF_TRY_XOPEN_SOURCE
3811	CF_POSIX_C_SOURCE($cf_POSIX_C_SOURCE)
3812	;;
3813esac
3814
3815if test -n "$cf_xopen_source" ; then
3816	CF_ADD_CFLAGS($cf_xopen_source)
3817fi
3818
3819dnl In anything but the default case, we may have system-specific setting
3820dnl which is still not guaranteed to provide all of the entrypoints that
3821dnl _XOPEN_SOURCE would yield.
3822if test -n "$cf_XOPEN_SOURCE" && test -z "$cf_cv_xopen_source" ; then
3823	AC_MSG_CHECKING(if _XOPEN_SOURCE really is set)
3824	AC_TRY_COMPILE([#include <stdlib.h>],[
3825#ifndef _XOPEN_SOURCE
3826make an error
3827#endif],
3828	[cf_XOPEN_SOURCE_set=yes],
3829	[cf_XOPEN_SOURCE_set=no])
3830	AC_MSG_RESULT($cf_XOPEN_SOURCE_set)
3831	if test $cf_XOPEN_SOURCE_set = yes
3832	then
3833		AC_TRY_COMPILE([#include <stdlib.h>],[
3834#if (_XOPEN_SOURCE - 0) < $cf_XOPEN_SOURCE
3835make an error
3836#endif],
3837		[cf_XOPEN_SOURCE_set_ok=yes],
3838		[cf_XOPEN_SOURCE_set_ok=no])
3839		if test $cf_XOPEN_SOURCE_set_ok = no
3840		then
3841			AC_MSG_WARN(_XOPEN_SOURCE is lower than requested)
3842		fi
3843	else
3844		CF_TRY_XOPEN_SOURCE
3845	fi
3846fi
3847])
3848dnl ---------------------------------------------------------------------------
3849dnl CF_X_ATHENA version: 21 updated: 2013/07/06 21:27:06
3850dnl -----------
3851dnl Check for Xaw (Athena) libraries
3852dnl
3853dnl Sets $cf_x_athena according to the flavor of Xaw which is used.
3854AC_DEFUN([CF_X_ATHENA],
3855[
3856cf_x_athena=${cf_x_athena:-Xaw}
3857
3858AC_MSG_CHECKING(if you want to link with Xaw 3d library)
3859withval=
3860AC_ARG_WITH(Xaw3d,
3861	[  --with-Xaw3d            link with Xaw 3d library])
3862if test "$withval" = yes ; then
3863	cf_x_athena=Xaw3d
3864	AC_MSG_RESULT(yes)
3865else
3866	AC_MSG_RESULT(no)
3867fi
3868
3869AC_MSG_CHECKING(if you want to link with neXT Athena library)
3870withval=
3871AC_ARG_WITH(neXtaw,
3872	[  --with-neXtaw           link with neXT Athena library])
3873if test "$withval" = yes ; then
3874	cf_x_athena=neXtaw
3875	AC_MSG_RESULT(yes)
3876else
3877	AC_MSG_RESULT(no)
3878fi
3879
3880AC_MSG_CHECKING(if you want to link with Athena-Plus library)
3881withval=
3882AC_ARG_WITH(XawPlus,
3883	[  --with-XawPlus          link with Athena-Plus library])
3884if test "$withval" = yes ; then
3885	cf_x_athena=XawPlus
3886	AC_MSG_RESULT(yes)
3887else
3888	AC_MSG_RESULT(no)
3889fi
3890
3891cf_x_athena_lib=""
3892
3893if test "$PKG_CONFIG" != none ; then
3894	cf_athena_list=
3895	test "$cf_x_athena" = Xaw && cf_athena_list="xaw8 xaw7 xaw6"
3896	for cf_athena_pkg in \
3897		$cf_athena_list \
3898		${cf_x_athena} \
3899		${cf_x_athena}-devel \
3900		lib${cf_x_athena} \
3901		lib${cf_x_athena}-devel
3902	do
3903		CF_TRY_PKG_CONFIG($cf_athena_pkg,[
3904			cf_x_athena_lib="$cf_pkgconfig_libs"
3905			CF_UPPER(cf_x_athena_LIBS,HAVE_LIB_$cf_x_athena)
3906			AC_DEFINE_UNQUOTED($cf_x_athena_LIBS)
3907
3908			CF_TRIM_X_LIBS
3909
3910AC_CACHE_CHECK(for usable $cf_x_athena/Xmu package,cf_cv_xaw_compat,[
3911AC_TRY_LINK([
3912#include <X11/Xmu/CharSet.h>
3913],[
3914int check = XmuCompareISOLatin1("big", "small")
3915],[cf_cv_xaw_compat=yes],[cf_cv_xaw_compat=no])])
3916
3917			if test "$cf_cv_xaw_compat" = no
3918			then
3919				# workaround for broken ".pc" files...
3920				case "$cf_x_athena_lib" in #(vi
3921				*-lXmu*) #(vi
3922					;;
3923				*)
3924					CF_VERBOSE(work around broken package)
3925					cf_save_xmu="$LIBS"
3926					cf_first_lib=`echo "$cf_save_xmu" | sed -e 's/^[ ][ ]*//' -e 's/ .*//'`
3927					CF_TRY_PKG_CONFIG(xmu,[
3928							LIBS="$cf_save_xmu"
3929							CF_ADD_LIB_AFTER($cf_first_lib,$cf_pkgconfig_libs)
3930						],[
3931							CF_ADD_LIB_AFTER($cf_first_lib,-lXmu)
3932						])
3933					CF_TRIM_X_LIBS
3934					;;
3935				esac
3936			fi
3937
3938			break])
3939	done
3940fi
3941
3942if test -z "$cf_x_athena_lib" ; then
3943	CF_X_EXT
3944	CF_X_TOOLKIT
3945	CF_X_ATHENA_CPPFLAGS($cf_x_athena)
3946	CF_X_ATHENA_LIBS($cf_x_athena)
3947fi
3948])dnl
3949dnl ---------------------------------------------------------------------------
3950dnl CF_X_ATHENA_CPPFLAGS version: 5 updated: 2010/05/26 17:35:30
3951dnl --------------------
3952dnl Normally invoked by CF_X_ATHENA, with $1 set to the appropriate flavor of
3953dnl the Athena widgets, e.g., Xaw, Xaw3d, neXtaw.
3954AC_DEFUN([CF_X_ATHENA_CPPFLAGS],
3955[
3956cf_x_athena_root=ifelse([$1],,Xaw,[$1])
3957cf_x_athena_inc=""
3958
3959for cf_path in default \
3960	/usr/contrib/X11R6 \
3961	/usr/contrib/X11R5 \
3962	/usr/lib/X11R5 \
3963	/usr/local
3964do
3965	if test -z "$cf_x_athena_inc" ; then
3966		cf_save="$CPPFLAGS"
3967		cf_test=X11/$cf_x_athena_root/SimpleMenu.h
3968		if test $cf_path != default ; then
3969			CPPFLAGS="$cf_save -I$cf_path/include"
3970			AC_MSG_CHECKING(for $cf_test in $cf_path)
3971		else
3972			AC_MSG_CHECKING(for $cf_test)
3973		fi
3974		AC_TRY_COMPILE([
3975#include <X11/Intrinsic.h>
3976#include <$cf_test>],[],
3977			[cf_result=yes],
3978			[cf_result=no])
3979		AC_MSG_RESULT($cf_result)
3980		if test "$cf_result" = yes ; then
3981			cf_x_athena_inc=$cf_path
3982			break
3983		else
3984			CPPFLAGS="$cf_save"
3985		fi
3986	fi
3987done
3988
3989if test -z "$cf_x_athena_inc" ; then
3990	AC_MSG_WARN(
3991[Unable to successfully find Athena header files with test program])
3992elif test "$cf_x_athena_inc" != default ; then
3993	CPPFLAGS="$CPPFLAGS -I$cf_x_athena_inc"
3994fi
3995])
3996dnl ---------------------------------------------------------------------------
3997dnl CF_X_ATHENA_LIBS version: 12 updated: 2011/07/17 19:55:02
3998dnl ----------------
3999dnl Normally invoked by CF_X_ATHENA, with $1 set to the appropriate flavor of
4000dnl the Athena widgets, e.g., Xaw, Xaw3d, neXtaw.
4001AC_DEFUN([CF_X_ATHENA_LIBS],
4002[AC_REQUIRE([CF_X_TOOLKIT])
4003cf_x_athena_root=ifelse([$1],,Xaw,[$1])
4004cf_x_athena_lib=""
4005
4006for cf_path in default \
4007	/usr/contrib/X11R6 \
4008	/usr/contrib/X11R5 \
4009	/usr/lib/X11R5 \
4010	/usr/local
4011do
4012	for cf_lib in \
4013		${cf_x_athena_root} \
4014		${cf_x_athena_root}7 \
4015		${cf_x_athena_root}6
4016	do
4017	for cf_libs in \
4018		"-l$cf_lib -lXmu" \
4019		"-l$cf_lib -lXpm -lXmu" \
4020		"-l${cf_lib}_s -lXmu_s"
4021	do
4022		if test -z "$cf_x_athena_lib" ; then
4023			cf_save="$LIBS"
4024			cf_test=XawSimpleMenuAddGlobalActions
4025			if test $cf_path != default ; then
4026				CF_ADD_LIBS(-L$cf_path/lib $cf_libs)
4027				AC_MSG_CHECKING(for $cf_libs in $cf_path)
4028			else
4029				CF_ADD_LIBS($cf_libs)
4030				AC_MSG_CHECKING(for $cf_test in $cf_libs)
4031			fi
4032			AC_TRY_LINK([
4033#include <X11/Intrinsic.h>
4034#include <X11/$cf_x_athena_root/SimpleMenu.h>
4035],[
4036$cf_test((XtAppContext) 0)],
4037				[cf_result=yes],
4038				[cf_result=no])
4039			AC_MSG_RESULT($cf_result)
4040			if test "$cf_result" = yes ; then
4041				cf_x_athena_lib="$cf_libs"
4042				break
4043			fi
4044			LIBS="$cf_save"
4045		fi
4046	done # cf_libs
4047		test -n "$cf_x_athena_lib" && break
4048	done # cf_lib
4049done
4050
4051if test -z "$cf_x_athena_lib" ; then
4052	AC_MSG_ERROR(
4053[Unable to successfully link Athena library (-l$cf_x_athena_root) with test program])
4054fi
4055
4056CF_UPPER(cf_x_athena_LIBS,HAVE_LIB_$cf_x_athena)
4057AC_DEFINE_UNQUOTED($cf_x_athena_LIBS)
4058])
4059dnl ---------------------------------------------------------------------------
4060dnl CF_X_EXT version: 3 updated: 2010/06/02 05:03:05
4061dnl --------
4062AC_DEFUN([CF_X_EXT],[
4063CF_TRY_PKG_CONFIG(Xext,,[
4064	AC_CHECK_LIB(Xext,XextCreateExtension,
4065		[CF_ADD_LIB(Xext)])])
4066])dnl
4067dnl ---------------------------------------------------------------------------
4068dnl CF_X_FONTCONFIG version: 5 updated: 2013/07/06 21:27:06
4069dnl ---------------
4070dnl Check for fontconfig library, a dependency of the X FreeType library.
4071AC_DEFUN([CF_X_FONTCONFIG],
4072[
4073AC_REQUIRE([CF_X_FREETYPE])
4074
4075if test "$cf_cv_found_freetype" = yes ; then
4076AC_CACHE_CHECK(for usable Xft/fontconfig package,cf_cv_xft_compat,[
4077AC_TRY_LINK([
4078#include <X11/Xft/Xft.h>
4079],[
4080	XftPattern *pat;
4081	XftPatternBuild(pat,
4082					XFT_FAMILY, XftTypeString, "mono",
4083					(void *) 0);
4084],[cf_cv_xft_compat=yes],[cf_cv_xft_compat=no])
4085])
4086
4087if test "$cf_cv_xft_compat" = no
4088then
4089	# workaround for broken ".pc" files used for Xft.
4090	case "$cf_cv_x_freetype_libs" in #(vi
4091	*-lfontconfig*) #(vi
4092		;;
4093	*)
4094		CF_VERBOSE(work around broken package)
4095		cf_save_fontconfig="$LIBS"
4096		CF_TRY_PKG_CONFIG(fontconfig,[
4097				CF_ADD_CFLAGS($cf_pkgconfig_incs)
4098				LIBS="$cf_save_fontconfig"
4099				CF_ADD_LIB_AFTER(-lXft,$cf_pkgconfig_libs)
4100			],[
4101				CF_ADD_LIB_AFTER(-lXft,-lfontconfig)
4102			])
4103		;;
4104	esac
4105fi
4106fi
4107])dnl
4108dnl ---------------------------------------------------------------------------
4109dnl CF_X_FREETYPE version: 26 updated: 2012/10/04 20:12:20
4110dnl -------------
4111dnl Check for X FreeType headers and libraries (XFree86 4.x, etc).
4112dnl
4113dnl First check for the appropriate config program, since the developers for
4114dnl these libraries change their configuration (and config program) more or
4115dnl less randomly.  If we cannot find the config program, do not bother trying
4116dnl to guess the latest variation of include/lib directories.
4117dnl
4118dnl If either or both of these configure-script options are not given, rely on
4119dnl the output of the config program to provide the cflags/libs options:
4120dnl	--with-freetype-cflags
4121dnl	--with-freetype-libs
4122AC_DEFUN([CF_X_FREETYPE],
4123[
4124AC_REQUIRE([CF_PKG_CONFIG])
4125
4126cf_cv_x_freetype_incs=no
4127cf_cv_x_freetype_libs=no
4128cf_extra_freetype_libs=
4129FREETYPE_CONFIG=none
4130FREETYPE_PARAMS=
4131
4132AC_MSG_CHECKING(for FreeType configuration script)
4133AC_ARG_WITH(freetype-config,
4134	[  --with-freetype-config  configure script to use for FreeType],
4135	[cf_cv_x_freetype_cfgs="$withval"],
4136	[cf_cv_x_freetype_cfgs=auto])
4137test -z $cf_cv_x_freetype_cfgs && cf_cv_x_freetype_cfgs=auto
4138test $cf_cv_x_freetype_cfgs = no && cf_cv_x_freetype_cfgs=none
4139AC_MSG_RESULT($cf_cv_x_freetype_cfgs)
4140
4141case $cf_cv_x_freetype_cfgs in
4142none) #(vi
4143	AC_MSG_CHECKING(if you specified -D/-I options for FreeType)
4144	AC_ARG_WITH(freetype-cflags,
4145		[  --with-freetype-cflags  -D/-I options for compiling with FreeType],
4146		[cf_cv_x_freetype_incs="$with_freetype_cflags"],
4147		[cf_cv_x_freetype_incs=no])
4148	AC_MSG_RESULT($cf_cv_x_freetype_incs)
4149
4150	AC_MSG_CHECKING(if you specified -L/-l options for FreeType)
4151	AC_ARG_WITH(freetype-libs,
4152		[  --with-freetype-libs    -L/-l options to link FreeType],
4153		[cf_cv_x_freetype_libs="$with_freetype_libs"],
4154		[cf_cv_x_freetype_libs=no])
4155	AC_MSG_RESULT($cf_cv_x_freetype_libs)
4156	;;
4157auto) #(vi
4158	if test "$PKG_CONFIG" != none && "$PKG_CONFIG" --exists xft; then
4159		FREETYPE_CONFIG=$PKG_CONFIG
4160		FREETYPE_PARAMS=xft
4161	else
4162		AC_PATH_PROG(FREETYPE_CONFIG, freetype-config, none)
4163		if test "$FREETYPE_CONFIG" != none; then
4164			FREETYPE_CONFIG=$FREETYPE_CONFIG
4165			cf_extra_freetype_libs="-lXft"
4166		else
4167			AC_PATH_PROG(FREETYPE_OLD_CONFIG, xft-config, none)
4168			if test "$FREETYPE_OLD_CONFIG" != none; then
4169				FREETYPE_CONFIG=$FREETYPE_OLD_CONFIG
4170			fi
4171		fi
4172	fi
4173	;;
4174pkg*) #(vi
4175	if test "$PKG_CONFIG" != none && "$PKG_CONFIG" --exists xft; then
4176		FREETYPE_CONFIG=$cf_cv_x_freetype_cfgs
4177		FREETYPE_PARAMS=xft
4178	else
4179		AC_MSG_WARN(cannot find pkg-config for Xft)
4180	fi
4181	;;
4182*) #(vi
4183	AC_PATH_PROG(FREETYPE_XFT_CONFIG, $cf_cv_x_freetype_cfgs, none)
4184	if test "$FREETYPE_XFT_CONFIG" != none; then
4185		FREETYPE_CONFIG=$FREETYPE_XFT_CONFIG
4186	else
4187		AC_MSG_WARN(cannot find config script for Xft)
4188	fi
4189	;;
4190esac
4191
4192if test "$FREETYPE_CONFIG" != none ; then
4193	AC_MSG_CHECKING(for FreeType config)
4194	AC_MSG_RESULT($FREETYPE_CONFIG $FREETYPE_PARAMS)
4195
4196	if test "$cf_cv_x_freetype_incs" = no ; then
4197		AC_MSG_CHECKING(for $FREETYPE_CONFIG cflags)
4198		cf_cv_x_freetype_incs="`$FREETYPE_CONFIG $FREETYPE_PARAMS --cflags 2>/dev/null`"
4199		AC_MSG_RESULT($cf_cv_x_freetype_incs)
4200	fi
4201
4202	if test "$cf_cv_x_freetype_libs" = no ; then
4203		AC_MSG_CHECKING(for $FREETYPE_CONFIG libs)
4204		cf_cv_x_freetype_libs="$cf_extra_freetype_libs `$FREETYPE_CONFIG $FREETYPE_PARAMS --libs 2>/dev/null`"
4205		AC_MSG_RESULT($cf_cv_x_freetype_libs)
4206	fi
4207fi
4208
4209if test "$cf_cv_x_freetype_incs" = no ; then
4210	cf_cv_x_freetype_incs=
4211fi
4212
4213if test "$cf_cv_x_freetype_libs" = no ; then
4214	cf_cv_x_freetype_libs=-lXft
4215fi
4216
4217AC_MSG_CHECKING(if we can link with FreeType libraries)
4218
4219cf_save_LIBS="$LIBS"
4220cf_save_INCS="$CPPFLAGS"
4221
4222CF_ADD_LIBS($cf_cv_x_freetype_libs)
4223CPPFLAGS="$CPPFLAGS $cf_cv_x_freetype_incs"
4224
4225AC_TRY_LINK([
4226#include <X11/Xlib.h>
4227#include <X11/extensions/Xrender.h>
4228#include <X11/Xft/Xft.h>],[
4229	XftPattern  *pat = XftNameParse ("name");],
4230	[cf_cv_found_freetype=yes],
4231	[cf_cv_found_freetype=no])
4232AC_MSG_RESULT($cf_cv_found_freetype)
4233
4234LIBS="$cf_save_LIBS"
4235CPPFLAGS="$cf_save_INCS"
4236
4237if test "$cf_cv_found_freetype" = yes ; then
4238	CF_ADD_LIBS($cf_cv_x_freetype_libs)
4239	CF_ADD_CFLAGS($cf_cv_x_freetype_incs)
4240	AC_DEFINE(XRENDERFONT,1,[Define to 1 if we can/should link with FreeType libraries])
4241
4242AC_CHECK_FUNCS( \
4243	XftDrawCharSpec \
4244	XftDrawSetClip \
4245	XftDrawSetClipRectangles \
4246)
4247
4248else
4249	AC_MSG_WARN(No libraries found for FreeType)
4250	CPPFLAGS=`echo "$CPPFLAGS" | sed -e s/-DXRENDERFONT//`
4251fi
4252
4253# FIXME: revisit this if needed
4254AC_SUBST(HAVE_TYPE_FCCHAR32)
4255AC_SUBST(HAVE_TYPE_XFTCHARSPEC)
4256])
4257dnl ---------------------------------------------------------------------------
4258dnl CF_X_TOOLKIT version: 21 updated: 2012/10/04 06:57:36
4259dnl ------------
4260dnl Check for X Toolkit libraries
4261dnl
4262AC_DEFUN([CF_X_TOOLKIT],
4263[
4264AC_REQUIRE([AC_PATH_XTRA])
4265AC_REQUIRE([CF_CHECK_CACHE])
4266
4267cf_have_X_LIBS=no
4268
4269CF_TRY_PKG_CONFIG(xt,[
4270
4271	case "x$LIBS" in #(vi
4272	*-lX11*) #(vi
4273		;;
4274	*)
4275# we have an "xt" package, but it may omit Xt's dependency on X11
4276AC_CACHE_CHECK(for usable X dependency,cf_cv_xt_x11_compat,[
4277AC_TRY_LINK([
4278#include <X11/Xlib.h>
4279],[
4280	int rc1 = XDrawLine((Display*) 0, (Drawable) 0, (GC) 0, 0, 0, 0, 0);
4281	int rc2 = XClearWindow((Display*) 0, (Window) 0);
4282	int rc3 = XMoveWindow((Display*) 0, (Window) 0, 0, 0);
4283	int rc4 = XMoveResizeWindow((Display*)0, (Window)0, 0, 0, 0, 0);
4284],[cf_cv_xt_x11_compat=yes],[cf_cv_xt_x11_compat=no])])
4285		if test "$cf_cv_xt_x11_compat" = no
4286		then
4287			CF_VERBOSE(work around broken X11 dependency)
4288			# 2010/11/19 - good enough until a working Xt on Xcb is delivered.
4289			CF_TRY_PKG_CONFIG(x11,,[CF_ADD_LIB_AFTER(-lXt,-lX11)])
4290		fi
4291		;;
4292	esac
4293
4294AC_CACHE_CHECK(for usable X Toolkit package,cf_cv_xt_ice_compat,[
4295AC_TRY_LINK([
4296#include <X11/Shell.h>
4297],[int num = IceConnectionNumber(0)
4298],[cf_cv_xt_ice_compat=yes],[cf_cv_xt_ice_compat=no])])
4299
4300	if test "$cf_cv_xt_ice_compat" = no
4301	then
4302		# workaround for broken ".pc" files used for X Toolkit.
4303		case "x$X_PRE_LIBS" in #(vi
4304		*-lICE*)
4305			case "x$LIBS" in #(vi
4306			*-lICE*) #(vi
4307				;;
4308			*)
4309				CF_VERBOSE(work around broken ICE dependency)
4310				CF_TRY_PKG_CONFIG(ice,
4311					[CF_TRY_PKG_CONFIG(sm)],
4312					[CF_ADD_LIB_AFTER(-lXt,$X_PRE_LIBS)])
4313				;;
4314			esac
4315			;;
4316		esac
4317	fi
4318
4319	cf_have_X_LIBS=yes
4320],[
4321
4322	LDFLAGS="$X_LIBS $LDFLAGS"
4323	CF_CHECK_CFLAGS($X_CFLAGS)
4324
4325	AC_CHECK_FUNC(XOpenDisplay,,[
4326	AC_CHECK_LIB(X11,XOpenDisplay,
4327		[CF_ADD_LIB(X11)],,
4328		[$X_PRE_LIBS $LIBS $X_EXTRA_LIBS])])
4329
4330	AC_CHECK_FUNC(XtAppInitialize,,[
4331	AC_CHECK_LIB(Xt, XtAppInitialize,
4332		[AC_DEFINE(HAVE_LIBXT,1,[Define to 1 if we can compile with the Xt library])
4333		 cf_have_X_LIBS=Xt
4334		 LIBS="-lXt $X_PRE_LIBS $LIBS $X_EXTRA_LIBS"],,
4335		[$X_PRE_LIBS $LIBS $X_EXTRA_LIBS])])
4336])
4337
4338if test $cf_have_X_LIBS = no ; then
4339	AC_MSG_WARN(
4340[Unable to successfully link X Toolkit library (-lXt) with
4341test program.  You will have to check and add the proper libraries by hand
4342to makefile.])
4343fi
4344])dnl
4345dnl ---------------------------------------------------------------------------
4346dnl CF__GRANTPT_BODY version: 4 updated: 2012/05/07 19:39:45
4347dnl ----------------
4348dnl Body for workability check of grantpt.
4349define([CF__GRANTPT_BODY],[
4350	int code = 0;
4351	int rc;
4352	int pty;
4353	int tty;
4354	char *slave;
4355	struct termios tio;
4356
4357	signal(SIGALRM, my_timeout);
4358
4359	if (alarm(2) == 9)
4360		failed(9);
4361	else if ((pty = posix_openpt(O_RDWR)) < 0)
4362		failed(1);
4363	else if ((rc = grantpt(pty)) < 0)
4364		failed(2);
4365	else if ((rc = unlockpt(pty)) < 0)
4366		failed(3);
4367	else if ((slave = ptsname(pty)) == 0)
4368		failed(4);
4369#if (CONFTEST == 3) || defined(CONFTEST_isatty)
4370	else if (!isatty(pty))
4371		failed(4);
4372#endif
4373#if CONFTEST >= 4
4374    else if ((rc = tcgetattr(pty, &tio)) < 0)
4375		failed(20);
4376    else if ((rc = tcsetattr(pty, TCSAFLUSH, &tio)) < 0)
4377		failed(21);
4378#endif
4379	/* BSD posix_openpt does not treat pty as a terminal until slave is opened.
4380	 * Linux does treat it that way.
4381	 */
4382	else if ((tty = open(slave, O_RDWR)) < 0)
4383		failed(5);
4384#ifdef CONFTEST
4385#ifdef I_PUSH
4386#if (CONFTEST == 0) || defined(CONFTEST_ptem)
4387    else if ((rc = ioctl(tty, I_PUSH, "ptem")) < 0)
4388		failed(10);
4389#endif
4390#if (CONFTEST == 1) || defined(CONFTEST_ldterm)
4391    else if ((rc = ioctl(tty, I_PUSH, "ldterm")) < 0)
4392		failed(11);
4393#endif
4394#if (CONFTEST == 2) || defined(CONFTEST_ttcompat)
4395    else if ((rc = ioctl(tty, I_PUSH, "ttcompat")) < 0)
4396		failed(12);
4397#endif
4398#endif /* I_PUSH */
4399#if CONFTEST >= 5
4400    else if ((rc = tcgetattr(tty, &tio)) < 0)
4401		failed(30);
4402    else if ((rc = tcsetattr(tty, TCSAFLUSH, &tio)) < 0)
4403		failed(31);
4404#endif
4405#endif /* CONFTEST */
4406
4407	${cf_cv_main_return:-return}(code);
4408])
4409dnl ---------------------------------------------------------------------------
4410dnl CF__GRANTPT_HEAD version: 3 updated: 2012/01/29 17:13:14
4411dnl ----------------
4412dnl Headers for workability check of grantpt.
4413define([CF__GRANTPT_HEAD],[
4414#include <stdlib.h>
4415#include <termios.h>
4416#include <unistd.h>
4417#include <signal.h>
4418#include <fcntl.h>
4419#include <errno.h>
4420
4421#ifndef HAVE_POSIX_OPENPT
4422#undef posix_openpt
4423#define posix_openpt(mode) open("/dev/ptmx", mode)
4424#endif
4425
4426#ifdef HAVE_STROPTS_H
4427#include <stropts.h>
4428#endif
4429
4430static void failed(int code)
4431{
4432	perror("conftest");
4433	exit(code);
4434}
4435
4436static void my_timeout(int sig)
4437{
4438	exit(99);
4439}
4440])
4441