Replaced specific checks for function declarations with a generic
[s-roff.git] / aclocal.m4
blob1cd92ce2e7cf266589de8c7fdf3160f08f31679f
1 dnl Autoconf macros for groff.
2 dnl Copyright (C) 1989, 1990, 1991, 1992, 1995 Free Software Foundation, Inc.
3 dnl 
4 dnl This file is part of groff.
5 dnl 
6 dnl groff is free software; you can redistribute it and/or modify it under
7 dnl the terms of the GNU General Public License as published by the Free
8 dnl Software Foundation; either version 2, or (at your option) any later
9 dnl version.
10 dnl 
11 dnl groff is distributed in the hope that it will be useful, but WITHOUT ANY
12 dnl WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 dnl FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 dnl for more details.
15 dnl 
16 dnl You should have received a copy of the GNU General Public License along
17 dnl with groff; see the file COPYING.  If not, write to the Free Software
18 dnl Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 dnl
20 dnl
21 AC_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
38 AC_SUBST(PSPRINT)
39 AC_MSG_CHECKING([for command to use for printing PostScript files])
40 AC_MSG_RESULT($PSPRINT)
41 # Figure out DVIPRINT from PSPRINT.
42 AC_MSG_CHECKING([for command to use for printing dvi files])
43 if 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
50 AC_SUBST(DVIPRINT)
51 AC_MSG_RESULT($DVIPRINT)])dnl
52 dnl
53 dnl
54 dnl Bison generated parsers have problems with C++ compilers other than g++.
55 dnl So byacc is preferred over bison.
56 dnl
57 AC_DEFUN(GROFF_PROG_YACC,
58 [AC_CHECK_PROGS(YACC, byacc 'bison -y', yacc)])dnl
59 dnl
60 dnl
61 dnl GROFF_CSH_HACK(if hack present, if not present)
62 dnl
63 AC_DEFUN(GROFF_CSH_HACK,
64 [AC_MSG_CHECKING([for csh hash hack])
65 cat <<EOF >conftest.sh
66 #!/bin/sh
67 true || exit 0
68 export PATH || exit 0
69 exit 1
70 EOF
71 chmod +x conftest.sh
72 if echo ./conftest.sh | (csh >/dev/null 2>&1) >/dev/null 2>&1; then
73         AC_MSG_RESULT(yes); $1
74 else
75         AC_MSG_RESULT(no); $2
77 rm -f conftest.sh])dnl
78 dnl
79 dnl
80 dnl From udodo!hans@relay.NL.net (Hans Zuidam)
81 dnl
82 AC_DEFUN(GROFF_ISC_SYSV3,
83 [AC_MSG_CHECKING([for ISC 3.x or 4.x])
84 changequote(,)dnl
85 if grep '[34]\.' /usr/options/cb.name >/dev/null 2>&1
86 changequote([,])dnl
87 then
88         AC_MSG_RESULT(yes)
89         AC_DEFINE(_SYSV3)
90 else
91         AC_MSG_RESULT(no)
92 fi])dnl
93 dnl
94 dnl
95 AC_DEFUN(GROFF_POSIX,
96 [AC_MSG_CHECKING([whether -D_POSIX_SOURCE is necessary])
97 AC_LANG_SAVE
98 AC_LANG_CPLUSPLUS
99 AC_TRY_COMPILE([#include <stdio.h>
100 extern "C" { void fileno(int); }],,
101 AC_MSG_RESULT(yes);AC_DEFINE(_POSIX_SOURCE),
102 AC_MSG_RESULT(no))
103 AC_LANG_RESTORE])dnl
106 dnl srand() of SunOS 4.1.3 has return type int instead of void
108 AC_DEFUN(GROFF_SRAND,
109 [AC_LANG_SAVE
110 AC_LANG_CPLUSPLUS
111 AC_MSG_CHECKING([for return type of srand])
112 AC_TRY_COMPILE([#include <stdlib.h>
113 extern "C" { void srand(unsigned int); }],,
114 AC_MSG_RESULT(void);AC_DEFINE(RET_TYPE_SRAND_IS_VOID),
115 AC_MSG_RESULT(int))
116 AC_LANG_RESTORE])dnl
119 AC_DEFUN(GROFF_SYS_NERR,
120 [AC_LANG_SAVE
121 AC_LANG_CPLUSPLUS
122 AC_MSG_CHECKING([for sys_nerr in <errno.h> or <stdio.h>])
123 AC_TRY_COMPILE([#include <errno.h>
124 #include <stdio.h>],
125 [int k; k = sys_nerr;],
126 AC_MSG_RESULT(yes);AC_DEFINE(HAVE_SYS_NERR),
127 AC_MSG_RESULT(no))
128 AC_LANG_RESTORE])dnl
131 AC_DEFUN(GROFF_SYS_ERRLIST,
132 [AC_LANG_SAVE
133 AC_LANG_CPLUSPLUS
134 AC_MSG_CHECKING([for sys_errlist[] in <errno.h> or <stdio.h>])
135 AC_TRY_COMPILE([#include <errno.h>
136 #include <stdio.h>],
137 [int k; k = (int)sys_errlist[0];],
138 AC_MSG_RESULT(yes);AC_DEFINE(HAVE_SYS_ERRLIST),
139 AC_MSG_RESULT(no))
140 AC_LANG_RESTORE])dnl
143 AC_DEFUN(GROFF_OSFCN_H,
144 [AC_LANG_SAVE
145 AC_LANG_CPLUSPLUS
146 AC_MSG_CHECKING([C++ <osfcn.h>])
147 AC_TRY_COMPILE([#include <osfcn.h>],
148 [read(0, 0, 0); open(0, 0);],
149 AC_MSG_RESULT(yes);AC_DEFINE(HAVE_CC_OSFCN_H),
150 AC_MSG_RESULT(no))
151 AC_LANG_RESTORE])dnl
154 AC_DEFUN(GROFF_LIMITS_H,
155 [AC_LANG_SAVE
156 AC_LANG_CPLUSPLUS
157 AC_MSG_CHECKING([C++ <limits.h>])
158 AC_TRY_COMPILE([#include <limits.h>],
159 [int x = INT_MIN; int y = INT_MAX; int z = UCHAR_MAX;],
160 AC_MSG_RESULT(yes);AC_DEFINE(HAVE_CC_LIMITS_H),
161 AC_MSG_RESULT(no))
162 AC_LANG_RESTORE])dnl
165 AC_DEFUN(GROFF_TIME_T,
166 [AC_LANG_SAVE
167 AC_LANG_CPLUSPLUS
168 AC_MSG_CHECKING([for declaration of time_t])
169 AC_TRY_COMPILE([#include <time.h>],
170 [time_t t = time(0); struct tm *p = localtime(&t);],
171 AC_MSG_RESULT(yes),
172 AC_MSG_RESULT(no);AC_DEFINE(LONG_FOR_TIME_T))
173 AC_LANG_RESTORE])dnl
176 AC_DEFUN(GROFF_STRUCT_EXCEPTION,
177 [AC_MSG_CHECKING([struct exception])
178 AC_TRY_COMPILE([#include <math.h>],
179 [struct exception e;],
180 AC_MSG_RESULT(yes);AC_DEFINE(HAVE_STRUCT_EXCEPTION),
181 AC_MSG_RESULT(no))])dnl
184 AC_DEFUN(GROFF_ARRAY_DELETE,
185 [AC_LANG_SAVE
186 AC_LANG_CPLUSPLUS
187 AC_MSG_CHECKING([whether ANSI array delete syntax supported])
188 AC_TRY_COMPILE(,
189 changequote(,)dnl
190 char *p = new char[5]; delete [] p;changequote([,]),
191 AC_MSG_RESULT(yes),
192 AC_MSG_RESULT(no);AC_DEFINE(ARRAY_DELETE_NEEDS_SIZE))
193 AC_LANG_RESTORE])dnl
197 AC_DEFUN(GROFF_TRADITIONAL_CPP,
198 [AC_LANG_SAVE
199 AC_LANG_CPLUSPLUS
200 AC_MSG_CHECKING([traditional preprocessor])
201 AC_TRY_COMPILE([#define name2(a,b) a/**/b],[int name2(foo,bar);],
202 AC_MSG_RESULT(yes);AC_DEFINE(TRADITIONAL_CPP),
203 AC_MSG_RESULT(no))
204 AC_LANG_RESTORE])dnl
207 AC_DEFUN(GROFF_WCOREFLAG,
208 [AC_MSG_CHECKING([w_coredump])
209 AC_TRY_RUN([#include <sys/types.h>
210 #include <sys/wait.h>
211 main()
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
221 AC_MSG_RESULT(yes);AC_DEFINE(WCOREFLAG,0200),
222 AC_MSG_RESULT(no),
223 AC_MSG_RESULT(no))])dnl
226 AC_DEFUN(GROFF_BROKEN_SPOOLER_FLAGS,
227 [AC_MSG_CHECKING([default value for grops -b option])
228 test -n "${BROKEN_SPOOLER_FLAGS}" || BROKEN_SPOOLER_FLAGS=7
229 AC_MSG_RESULT($BROKEN_SPOOLER_FLAGS)
230 AC_SUBST(BROKEN_SPOOLER_FLAGS)])dnl
233 AC_DEFUN(GROFF_PAGE,
234 [AC_MSG_CHECKING([default paper size])
235 if 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
249 if 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
258 changequote(,)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
265 changequote([,])dnl
267 test -n "$PAGE" || PAGE=letter
268 AC_MSG_RESULT($PAGE)
269 AC_SUBST(PAGE)])dnl
272 AC_DEFUN(GROFF_CXX_CHECK,
273 [AC_REQUIRE([AC_PROG_CXX])
274 AC_LANG_SAVE
275 AC_LANG_CPLUSPLUS
276 if test "$cross_compiling" = no; then
277         AC_MSG_CHECKING([that C++ compiler can compile simple program])
279 AC_TRY_RUN([int main() { return 0; }],
280 AC_MSG_RESULT(yes),
281 AC_MSG_RESULT(no);AC_MSG_ERROR([a working C++ compiler is required]),
283 if test "$cross_compiling" = no; then
284         AC_MSG_CHECKING([that C++ static constructors and destructors are called])
286 AC_TRY_RUN([
287 extern "C" {
288   void _exit(int);
290 int i;
291 struct A {
292   char dummy;
293   A() { i = 1; }
294   ~A() { if (i == 1) _exit(0); }
296 A a;
297 int main() { return 1; }
299 AC_MSG_RESULT(yes),
300 AC_MSG_RESULT(no);AC_MSG_ERROR([a working C++ compiler is required]),
302 AC_MSG_CHECKING([that header files support C++])
303 AC_TRY_LINK([#include <stdio.h>],
304 [fopen(0, 0);],
305 AC_MSG_RESULT(yes),
306 AC_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++)]))
307 AC_LANG_RESTORE])dnl
310 AC_DEFUN(GROFF_TMAC,
311 [AC_MSG_CHECKING([for prefix of system macro packages])
312 sys_tmac_prefix=
313 sys_tmac_file_prefix=
314 for 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
326 done
327 AC_MSG_RESULT($sys_tmac_prefix)
328 AC_SUBST(sys_tmac_prefix)
329 tmac_wrap=
330 AC_MSG_CHECKING([which system macro packages should be made available])
331 if 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
341 elif 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
365 AC_MSG_RESULT([$tmac_wrap])
366 AC_SUBST(tmac_wrap)])dnl
369 AC_DEFUN(GROFF_G,
370 [AC_MSG_CHECKING([for existing troff installation])
371 if 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
374 else
375         AC_MSG_RESULT(no)
376         g=
378 AC_SUBST(g)])dnl
381 dnl We need the path to install-sh to be absolute.
383 AC_DEFUN(GROFF_INSTALL_SH,
384 [AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT])dnl
385 ac_dir=`cd $ac_aux_dir; pwd`
386 ac_install_sh="$ac_dir/install-sh -c"])dnl
389 dnl At least one UNIX system, Apple Macintosh Rhapsody 5.5,
390 dnl does not have -lm.
392 AC_DEFUN(GROFF_LIBM,
393 [AC_CHECK_LIB(m,sin,LIBM=-lm)
394 AC_SUBST(LIBM)])dnl
397 dnl We need top_srcdir to be absolute.
399 AC_DEFUN(GROFF_SRCDIR,
400 [ac_srcdir_defaulted=no
401 srcdir=`cd $srcdir; pwd`])dnl
404 dnl This simplifies Makefile rules.
406 AC_DEFUN(GROFF_BUILDDIR,
407 [top_builddir=`pwd`
408 AC_SUBST(top_builddir)])dnl
411 dnl Check for EBCDIC - stolen from the OS390 Unix LYNX port
413 AC_DEFUN(GROFF_EBCDIC,
414 [AC_MSG_CHECKING([whether character set is EBCDIC])
415 AC_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
420 make an error "Character set is not EBCDIC"
421 #endif],
422 groff_cv_ebcdic="yes"
423  TTYDEVDIRS="font/devcp1047"
424  AC_MSG_RESULT(yes)
425  AC_DEFINE(IS_EBCDIC_HOST),
426 groff_cv_ebcdic="no"
427  TTYDEVDIRS="font/devascii font/devlatin1 font/devutf8"
428  AC_MSG_RESULT(no))
429 AC_SUBST(TTYDEVDIRS)])dnl
432 dnl Check for OS/390 Unix.  We test for EBCDIC also -- the Linux port (with
433 dnl gcc) to OS/390 uses ASCII internally.
435 AC_DEFUN(GROFF_OS390,
436 [groff_cv_os390="no"
437 if 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
447 fi])dnl
450 dnl Finally, we must modify a base function of autoconf to replace the
451 dnl ASCII char `012' with its generic equivalent `\n' if we run under
452 dnl OS/390 Unix -- unfortunately, not all `tr' variants understand `\n',
453 dnl so this hack is necessary.
455 define([AC_OUTPUT_MAKE_DEFS],
456 [# Transform confdefs.h into DEFS.
457 dnl 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.
460 cat > conftest.defs <<\EOF
461 changequote(<<, >>)dnl
462 s%<<#define>> \([A-Za-z_][A-Za-z0-9_]*\) *\(.*\)%-D\1=\2%g
463 s%[     `~<<#>>$^&*(){}\\|;'"<>?]%\\&%g
464 s%\[%\\&%g
465 s%\]%\\&%g
466 s%\$%$$%g
467 changequote([, ])dnl
469 if test "$groff_cv_os390" = "yes"; then
470         DEFS=`sed -f conftest.defs confdefs.h | tr '\n' ' '`
471 else
472         DEFS=`sed -f conftest.defs confdefs.h | tr '\012' ' '`
474 rm -f conftest.defs
475 ])dnl
478 dnl Check whether we need a declaration for a function.
480 dnl Stolen from GNU bfd.
482 AC_DEFUN(GROFF_NEED_DECLARATION,
483 [AC_MSG_CHECKING([whether $1 must be declared])
484 AC_LANG_SAVE
485 AC_LANG_CPLUSPLUS
486 AC_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],
506 groff_cv_decl_needed_$1=no,
507 groff_cv_decl_needed_$1=yes)])
508 AC_MSG_RESULT($groff_cv_decl_needed_$1)
509 if test $groff_cv_decl_needed_$1 = yes; then
510         AC_DEFINE([NEED_DECLARATION_]translit($1, [a-z], [A-Z]))
512 AC_LANG_RESTORE])dnl