aclocal.m4 revision 69626
1dnl Autoconf macros for groff.
2dnl Copyright (C) 1989, 1990, 1991, 1992, 1995 Free Software Foundation, Inc.
3dnl 
4dnl This file is part of groff.
5dnl 
6dnl groff is free software; you can redistribute it and/or modify it under
7dnl the terms of the GNU General Public License as published by the Free
8dnl Software Foundation; either version 2, or (at your option) any later
9dnl version.
10dnl 
11dnl groff is distributed in the hope that it will be useful, but WITHOUT ANY
12dnl WARRANTY; without even the implied warranty of MERCHANTABILITY or
13dnl FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14dnl for more details.
15dnl 
16dnl You should have received a copy of the GNU General Public License along
17dnl with groff; see the file COPYING.  If not, write to the Free Software
18dnl Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19dnl
20dnl
21AC_DEFUN(GROFF_PRINT,
22[if test -z "$PSPRINT"; then
23	AC_CHECK_PROGS(LPR,lpr)
24	AC_CHECK_PROGS(LP,lp)
25	if test -n "$LPR" && test -n "$LP"; then
26		# HP-UX provides an lpr command that emulates lpr using lp,
27		# but it doesn't have lpq; in this case we want to use lp
28		# rather than lpr.
29		AC_CHECK_PROGS(LPQ,lpq)
30		test -n "$LPQ" || LPR=
31	fi
32	if test -n "$LPR"; then
33		PSPRINT="$LPR"
34	elif test -n "$LP"; then
35		PSPRINT="$LP"
36	fi
37fi
38AC_SUBST(PSPRINT)
39AC_MSG_CHECKING([for command to use for printing PostScript files])
40AC_MSG_RESULT($PSPRINT)
41# Figure out DVIPRINT from PSPRINT.
42AC_MSG_CHECKING([for command to use for printing dvi files])
43if test -n "$PSPRINT" && test -z "$DVIPRINT"; then
44	if test "X$PSPRINT" = "Xlpr"; then
45		DVIPRINT="lpr -d"
46	else
47		DVIPRINT="$PSPRINT"
48	fi
49fi
50AC_SUBST(DVIPRINT)
51AC_MSG_RESULT($DVIPRINT)])dnl
52dnl
53dnl
54dnl Bison generated parsers have problems with C++ compilers other than g++.
55dnl So byacc is preferred over bison.
56dnl
57AC_DEFUN(GROFF_PROG_YACC,
58[AC_CHECK_PROGS(YACC, byacc 'bison -y', yacc)])dnl
59dnl
60dnl
61dnl GROFF_CSH_HACK(if hack present, if not present)
62dnl
63AC_DEFUN(GROFF_CSH_HACK,
64[AC_MSG_CHECKING([for csh hash hack])
65cat <<EOF >conftest.sh
66#!/bin/sh
67true || exit 0
68export PATH || exit 0
69exit 1
70EOF
71chmod +x conftest.sh
72if echo ./conftest.sh | (csh >/dev/null 2>&1) >/dev/null 2>&1; then
73	AC_MSG_RESULT(yes); $1
74else
75	AC_MSG_RESULT(no); $2
76fi
77rm -f conftest.sh])dnl
78dnl
79dnl
80dnl From udodo!hans@relay.NL.net (Hans Zuidam)
81dnl
82AC_DEFUN(GROFF_ISC_SYSV3,
83[AC_MSG_CHECKING([for ISC 3.x or 4.x])
84changequote(,)dnl
85if grep '[34]\.' /usr/options/cb.name >/dev/null 2>&1
86changequote([,])dnl
87then
88	AC_MSG_RESULT(yes)
89	AC_DEFINE(_SYSV3)
90else
91	AC_MSG_RESULT(no)
92fi])dnl
93dnl
94dnl
95AC_DEFUN(GROFF_POSIX,
96[AC_MSG_CHECKING([whether -D_POSIX_SOURCE is necessary])
97AC_LANG_SAVE
98AC_LANG_CPLUSPLUS
99AC_TRY_COMPILE([#include <stdio.h>
100extern "C" { void fileno(int); }],,
101AC_MSG_RESULT(yes);AC_DEFINE(_POSIX_SOURCE),
102AC_MSG_RESULT(no))
103AC_LANG_RESTORE])dnl
104dnl
105dnl
106dnl srand() of SunOS 4.1.3 has return type int instead of void
107dnl
108AC_DEFUN(GROFF_SRAND,
109[AC_LANG_SAVE
110AC_LANG_CPLUSPLUS
111AC_MSG_CHECKING([for return type of srand])
112AC_TRY_COMPILE([#include <stdlib.h>
113extern "C" { void srand(unsigned int); }],,
114AC_MSG_RESULT(void);AC_DEFINE(RET_TYPE_SRAND_IS_VOID),
115AC_MSG_RESULT(int))
116AC_LANG_RESTORE])dnl
117dnl
118dnl
119AC_DEFUN(GROFF_SYS_NERR,
120[AC_LANG_SAVE
121AC_LANG_CPLUSPLUS
122AC_MSG_CHECKING([for sys_nerr in <errno.h> or <stdio.h>])
123AC_TRY_COMPILE([#include <errno.h>
124#include <stdio.h>],
125[int k; k = sys_nerr;],
126AC_MSG_RESULT(yes);AC_DEFINE(HAVE_SYS_NERR),
127AC_MSG_RESULT(no))
128AC_LANG_RESTORE])dnl
129dnl
130dnl
131AC_DEFUN(GROFF_SYS_ERRLIST,
132[AC_LANG_SAVE
133AC_LANG_CPLUSPLUS
134AC_MSG_CHECKING([for sys_errlist[] in <errno.h> or <stdio.h>])
135AC_TRY_COMPILE([#include <errno.h>
136#include <stdio.h>],
137[int k; k = (int)sys_errlist[0];],
138AC_MSG_RESULT(yes);AC_DEFINE(HAVE_SYS_ERRLIST),
139AC_MSG_RESULT(no))
140AC_LANG_RESTORE])dnl
141dnl
142dnl
143AC_DEFUN(GROFF_OSFCN_H,
144[AC_LANG_SAVE
145AC_LANG_CPLUSPLUS
146AC_MSG_CHECKING([C++ <osfcn.h>])
147AC_TRY_COMPILE([#include <osfcn.h>],
148[read(0, 0, 0); open(0, 0);],
149AC_MSG_RESULT(yes);AC_DEFINE(HAVE_CC_OSFCN_H),
150AC_MSG_RESULT(no))
151AC_LANG_RESTORE])dnl
152dnl
153dnl
154AC_DEFUN(GROFF_LIMITS_H,
155[AC_LANG_SAVE
156AC_LANG_CPLUSPLUS
157AC_MSG_CHECKING([C++ <limits.h>])
158AC_TRY_COMPILE([#include <limits.h>],
159[int x = INT_MIN; int y = INT_MAX; int z = UCHAR_MAX;],
160AC_MSG_RESULT(yes);AC_DEFINE(HAVE_CC_LIMITS_H),
161AC_MSG_RESULT(no))
162AC_LANG_RESTORE])dnl
163dnl
164dnl
165AC_DEFUN(GROFF_TIME_T,
166[AC_LANG_SAVE
167AC_LANG_CPLUSPLUS
168AC_MSG_CHECKING([for declaration of time_t])
169AC_TRY_COMPILE([#include <time.h>],
170[time_t t = time(0); struct tm *p = localtime(&t);],
171AC_MSG_RESULT(yes),
172AC_MSG_RESULT(no);AC_DEFINE(LONG_FOR_TIME_T))
173AC_LANG_RESTORE])dnl
174dnl
175dnl
176AC_DEFUN(GROFF_STRUCT_EXCEPTION,
177[AC_MSG_CHECKING([struct exception])
178AC_TRY_COMPILE([#include <math.h>],
179[struct exception e;],
180AC_MSG_RESULT(yes);AC_DEFINE(HAVE_STRUCT_EXCEPTION),
181AC_MSG_RESULT(no))])dnl
182dnl
183dnl
184AC_DEFUN(GROFF_ARRAY_DELETE,
185[AC_LANG_SAVE
186AC_LANG_CPLUSPLUS
187AC_MSG_CHECKING([whether ANSI array delete syntax supported])
188AC_TRY_COMPILE(,
189changequote(,)dnl
190char *p = new char[5]; delete [] p;changequote([,]),
191AC_MSG_RESULT(yes),
192AC_MSG_RESULT(no);AC_DEFINE(ARRAY_DELETE_NEEDS_SIZE))
193AC_LANG_RESTORE])dnl
194dnl
195dnl
196dnl
197AC_DEFUN(GROFF_TRADITIONAL_CPP,
198[AC_LANG_SAVE
199AC_LANG_CPLUSPLUS
200AC_MSG_CHECKING([traditional preprocessor])
201AC_TRY_COMPILE([#define name2(a,b) a/**/b],[int name2(foo,bar);],
202AC_MSG_RESULT(yes);AC_DEFINE(TRADITIONAL_CPP),
203AC_MSG_RESULT(no))
204AC_LANG_RESTORE])dnl
205dnl
206dnl
207AC_DEFUN(GROFF_WCOREFLAG,
208[AC_MSG_CHECKING([w_coredump])
209AC_TRY_RUN([#include <sys/types.h>
210#include <sys/wait.h>
211main()
212{
213#ifdef WCOREFLAG
214  exit(1);
215#else
216  int i = 0;
217  ((union wait *)&i)->w_coredump = 1;
218  exit(i != 0200);
219#endif
220}],
221AC_MSG_RESULT(yes);AC_DEFINE(WCOREFLAG,0200),
222AC_MSG_RESULT(no),
223AC_MSG_RESULT(no))])dnl
224dnl
225dnl
226AC_DEFUN(GROFF_BROKEN_SPOOLER_FLAGS,
227[AC_MSG_CHECKING([default value for grops -b option])
228test -n "${BROKEN_SPOOLER_FLAGS}" || BROKEN_SPOOLER_FLAGS=7
229AC_MSG_RESULT($BROKEN_SPOOLER_FLAGS)
230AC_SUBST(BROKEN_SPOOLER_FLAGS)])dnl
231dnl
232dnl
233AC_DEFUN(GROFF_PAGE,
234[AC_MSG_CHECKING([default paper size])
235if test -z "$PAGE"; then
236	descfile=
237	if test -r $prefix/share/groff/font/devps/DESC; then
238		descfile=$prefix/share/groff/font/devps/DESC
239	elif test -r $prefix/lib/groff/font/devps/DESC; then
240		descfile=$prefix/lib/groff/font/devps/DESC
241	fi
242	if test -n "$descfile" \
243	  && grep "^paperlength 841890" $descfile >/dev/null 2>&1; then
244		PAGE=A4
245	else
246		PAGE=letter
247	fi
248fi
249if test -z "$PAGE"; then
250	dom=`awk '([$]1 == "dom" || [$]1 == "search") { print [$]2; exit}' \
251	    /etc/resolv.conf 2>/dev/null`
252	if test -z "$dom"; then
253		dom=`(domainname) 2>/dev/null | tr -d '+'`
254		if test -z "$dom"; then
255			dom=`(hostname) 2>/dev/null | grep '\.'`
256		fi
257	fi
258changequote(,)dnl
259	# If the top-level domain is two letters and it's not `us' or `ca'
260	# then they probably use A4 paper.
261	case "$dom" in
262	*.[Uu][Ss]|*.[Cc][Aa]) ;;
263	*.[A-Za-z][A-Za-z]) PAGE=A4 ;;
264	esac
265changequote([,])dnl
266fi
267test -n "$PAGE" || PAGE=letter
268AC_MSG_RESULT($PAGE)
269AC_SUBST(PAGE)])dnl
270dnl
271dnl
272AC_DEFUN(GROFF_CXX_CHECK,
273[AC_REQUIRE([AC_PROG_CXX])
274AC_LANG_SAVE
275AC_LANG_CPLUSPLUS
276if test "$cross_compiling" = no; then
277	AC_MSG_CHECKING([that C++ compiler can compile simple program])
278fi
279AC_TRY_RUN([int main() { return 0; }],
280AC_MSG_RESULT(yes),
281AC_MSG_RESULT(no);AC_MSG_ERROR([a working C++ compiler is required]),
282:)
283if test "$cross_compiling" = no; then
284	AC_MSG_CHECKING([that C++ static constructors and destructors are called])
285fi
286AC_TRY_RUN([
287extern "C" {
288  void _exit(int);
289}
290int i;
291struct A {
292  char dummy;
293  A() { i = 1; }
294  ~A() { if (i == 1) _exit(0); }
295};
296A a;
297int main() { return 1; }
298],
299AC_MSG_RESULT(yes),
300AC_MSG_RESULT(no);AC_MSG_ERROR([a working C++ compiler is required]),
301:)
302AC_MSG_CHECKING([that header files support C++])
303AC_TRY_LINK([#include <stdio.h>],
304[fopen(0, 0);],
305AC_MSG_RESULT(yes),
306AC_MSG_RESULT(no);AC_MSG_ERROR([header files do not support C++ (if you are using a version of gcc/g++ earlier than 2.5, you should install libg++)]))
307AC_LANG_RESTORE])dnl
308dnl
309dnl
310AC_DEFUN(GROFF_TMAC,
311[AC_MSG_CHECKING([for prefix of system macro packages])
312sys_tmac_prefix=
313sys_tmac_file_prefix=
314for d in /usr/share/lib/tmac /usr/lib/tmac; do
315	for t in "" tmac.; do
316		for m in an s m; do
317			f=$d/$t$m
318			if test -z "$sys_tmac_prefix" \
319			  && test -f $f \
320			  && grep '^\.if' $f >/dev/null 2>&1; then
321				sys_tmac_prefix=$d/$t
322				sys_tmac_file_prefix=$t
323			fi
324		done
325	done
326done
327AC_MSG_RESULT($sys_tmac_prefix)
328AC_SUBST(sys_tmac_prefix)
329tmac_wrap=
330AC_MSG_CHECKING([which system macro packages should be made available])
331if test "x$sys_tmac_file_prefix" = "xtmac."; then
332	for f in $sys_tmac_prefix*; do
333		suff=`echo $f | sed -e "s;$sys_tmac_prefix;;"`
334		case "$suff" in
335		e) ;;
336		*)
337			grep "Copyright.*Free Software Foundation" $f >/dev/null \
338			  || tmac_wrap="$tmac_wrap $suff" ;;
339		esac 
340	done
341elif test -n "$sys_tmac_prefix"; then
342	files=`echo $sys_tmac_prefix*`
343	grep "\\.so" $files >conftest.sol
344	for f in $files; do
345		case "$f" in
346 		${sys_tmac_prefix}e) ;;
347		*.me) ;;
348		*/ms.*) ;;
349		*)
350			b=`basename $f`
351			if grep "\\.so.*/$b\$" conftest.sol >/dev/null \
352			  || grep -l "Copyright.*Free Software Foundation" $f >/dev/null; then
353				:
354			else
355				suff=`echo $f | sed -e "s;$sys_tmac_prefix;;"`
356				case "$suff" in
357				tmac.*) ;;
358				*) tmac_wrap="$tmac_wrap $suff" ;;
359				esac
360			fi
361		esac
362	done
363	rm -f conftest.sol
364fi
365AC_MSG_RESULT([$tmac_wrap])
366AC_SUBST(tmac_wrap)])dnl
367dnl
368dnl
369AC_DEFUN(GROFF_G,
370[AC_MSG_CHECKING([for existing troff installation])
371if test "x`(echo .tm '|n(.g' | tr '|' '\\\\' | troff -z -i 2>&1) 2>/dev/null`" = x0; then
372	AC_MSG_RESULT(yes)
373	g=g
374else
375	AC_MSG_RESULT(no)
376	g=
377fi
378AC_SUBST(g)])dnl
379dnl
380dnl
381dnl We need the path to install-sh to be absolute.
382dnl
383AC_DEFUN(GROFF_INSTALL_SH,
384[AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT])dnl
385ac_dir=`cd $ac_aux_dir; pwd`
386ac_install_sh="$ac_dir/install-sh -c"])dnl
387dnl
388dnl
389dnl At least one UNIX system, Apple Macintosh Rhapsody 5.5,
390dnl does not have -lm.
391dnl
392AC_DEFUN(GROFF_LIBM,
393[AC_CHECK_LIB(m,sin,LIBM=-lm)
394AC_SUBST(LIBM)])dnl
395dnl
396dnl
397dnl We need top_srcdir to be absolute.
398dnl
399AC_DEFUN(GROFF_SRCDIR,
400[ac_srcdir_defaulted=no
401srcdir=`cd $srcdir; pwd`])dnl
402dnl
403dnl
404dnl This simplifies Makefile rules.
405dnl
406AC_DEFUN(GROFF_BUILDDIR,
407[top_builddir=`pwd`
408AC_SUBST(top_builddir)])dnl
409dnl
410dnl
411dnl Check for EBCDIC - stolen from the OS390 Unix LYNX port
412dnl
413AC_DEFUN(GROFF_EBCDIC,
414[AC_MSG_CHECKING([whether character set is EBCDIC])
415AC_TRY_COMPILE(,
416[/* Treat any failure as ASCII for compatibility with existing art.
417    Use compile-time rather than run-time tests for cross-compiler
418    tolerance. */
419#if '0' != 240
420make an error "Character set is not EBCDIC"
421#endif],
422groff_cv_ebcdic="yes"
423 TTYDEVDIRS="font/devcp1047"
424 AC_MSG_RESULT(yes)
425 AC_DEFINE(IS_EBCDIC_HOST),
426groff_cv_ebcdic="no"
427 TTYDEVDIRS="font/devascii font/devlatin1 font/devutf8"
428 AC_MSG_RESULT(no))
429AC_SUBST(TTYDEVDIRS)])dnl
430dnl
431dnl
432dnl Check for OS/390 Unix.  We test for EBCDIC also -- the Linux port (with
433dnl gcc) to OS/390 uses ASCII internally.
434dnl
435AC_DEFUN(GROFF_OS390,
436[groff_cv_os390="no"
437if test "$groff_cv_ebcdic" = "yes"; then
438	AC_MSG_CHECKING([for OS/390 Unix])
439	case `uname` in
440	OS/390)
441		CFLAGS="$CFLAGS -D_ALL_SOURCE"
442		groff_cv_os390="yes"
443		AC_MSG_RESULT(yes) ;;
444	*)
445		AC_MSG_RESULT(no) ;;
446	esac
447fi])dnl
448dnl
449dnl
450dnl Finally, we must modify a base function of autoconf to replace the
451dnl ASCII char `012' with its generic equivalent `\n' if we run under
452dnl OS/390 Unix -- unfortunately, not all `tr' variants understand `\n',
453dnl so this hack is necessary.
454dnl
455define([AC_OUTPUT_MAKE_DEFS],
456[# Transform confdefs.h into DEFS.
457dnl Using a here document instead of a string reduces the quoting nightmare.
458# Protect against shell expansion while executing Makefile rules.
459# Protect against Makefile macro expansion.
460cat > conftest.defs <<\EOF
461changequote(<<, >>)dnl
462s%<<#define>> \([A-Za-z_][A-Za-z0-9_]*\) *\(.*\)%-D\1=\2%g
463s%[ 	`~<<#>>$^&*(){}\\|;'"<>?]%\\&%g
464s%\[%\\&%g
465s%\]%\\&%g
466s%\$%$$%g
467changequote([, ])dnl
468EOF
469if test "$groff_cv_os390" = "yes"; then
470	DEFS=`sed -f conftest.defs confdefs.h | tr '\n' ' '`
471else
472	DEFS=`sed -f conftest.defs confdefs.h | tr '\012' ' '`
473fi
474rm -f conftest.defs
475])dnl
476dnl
477dnl
478dnl Check whether we need a declaration for a function.
479dnl
480dnl Stolen from GNU bfd.
481dnl
482AC_DEFUN(GROFF_NEED_DECLARATION,
483[AC_MSG_CHECKING([whether $1 must be declared])
484AC_LANG_SAVE
485AC_LANG_CPLUSPLUS
486AC_CACHE_VAL(groff_cv_decl_needed_$1,
487[AC_TRY_COMPILE([
488#include <stdio.h>
489#ifdef HAVE_STRING_H
490#include <string.h>
491#else
492#ifdef HAVE_STRINGS_H
493#include <strings.h>
494#endif
495#endif
496#ifdef HAVE_STDLIB_H
497#include <stdlib.h>
498#endif
499#ifdef HAVE_UNISTD_H
500#include <unistd.h>
501#endif
502#ifdef HAVE_MATH_H
503#include <math.h>
504#endif],
505[char *(*pfn) = (char *(*)) $1],
506groff_cv_decl_needed_$1=no,
507groff_cv_decl_needed_$1=yes)])
508AC_MSG_RESULT($groff_cv_decl_needed_$1)
509if test $groff_cv_decl_needed_$1 = yes; then
510	AC_DEFINE([NEED_DECLARATION_]translit($1, [a-z], [A-Z]))
511fi
512AC_LANG_RESTORE])dnl
513