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