* src/roff/troff/input.cpp (string_iterator::fill): Protect against
[s-roff.git] / aclocal.m4
blobd272bc45d4a9daf7199e2c56399e44630cd60cd4
1 # Autoconf macros for groff.
2 # Copyright (C) 1989-1995, 2001, 2002, 2003, 2004, 2005
3 # Free Software Foundation, Inc.
5 # This file is part of groff.
7 # groff is free software; you can redistribute it and/or modify it under
8 # the terms of the GNU General Public License as published by the Free
9 # Software Foundation; either version 2, or (at your option) any later
10 # version.
12 # groff is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 # for more details.
17 # You should have received a copy of the GNU General Public License along
18 # with groff; see the file COPYING.  If not, write to the Free Software
19 # Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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
37    fi
38    AC_SUBST([PSPRINT])
39    AC_MSG_CHECKING([for command to use for printing PostScript files])
40    AC_MSG_RESULT([$PSPRINT])
42    # Figure out DVIPRINT from PSPRINT.
43    AC_MSG_CHECKING([for command to use for printing dvi files])
44    if test -n "$PSPRINT" && test -z "$DVIPRINT"; then
45      if test "x$PSPRINT" = "xlpr"; then
46        DVIPRINT="lpr -d"
47      else
48        DVIPRINT="$PSPRINT"
49      fi
50    fi
51    AC_SUBST([DVIPRINT])
52    AC_MSG_RESULT([$DVIPRINT])])
54 # Bison generated parsers have problems with C++ compilers other than g++.
55 # So byacc is preferred over bison.
57 AC_DEFUN([GROFF_PROG_YACC],
58   [AC_CHECK_PROGS([YACC], [byacc 'bison -y'], [yacc])])
60 # The following programs are needed for grohtml.
62 AC_DEFUN([GROFF_HTML_PROGRAMS],
63   [AC_REQUIRE([GROFF_GHOSTSCRIPT_PATH])
64    make_html=html
65    make_install_html=install_html
67    missing=
68    AC_FOREACH([groff_prog],
69      [pnmcut pnmcrop pnmtopng psselect pnmtops],
70      [AC_CHECK_PROG(groff_prog, groff_prog, [found], [missing])
71       if test $[]groff_prog = missing; then
72         missing="$missing \`groff_prog'"
73       fi;])
75    test "$GHOSTSCRIPT" = "missing" && missing="$missing \`gs'"
77    if test -n "$missing"; then
78      plural=`set $missing; test $[#] -gt 1 && echo s`
79      missing=`set $missing
80        missing=""
81        while test $[#] -gt 0
82          do
83            case $[#] in
84              1) missing="$missing$[1]" ;;
85              2) missing="$missing$[1] and " ;;
86              *) missing="$missing$[1], " ;;
87            esac
88            shift
89          done
90          echo $missing`
92      make_html=
93      make_install_html=
95      AC_MSG_WARN([missing program$plural:
97   The program$plural
98      $missing
99   cannot be found in the PATH.
100   Consequently, groff's HTML backend (grohtml) will not work properly;
101   therefore, it will neither be possible to prepare, nor to install,
102   documentation in HTML format.
103      ])
104    fi
106    AC_SUBST([make_html])
107    AC_SUBST([make_install_html])])
109 # To produce PDF docs, we need both awk and ghostscript.
111 AC_DEFUN([GROFF_PDFDOC_PROGRAMS],
112   [AC_REQUIRE([GROFF_AWK_PATH])
113    AC_REQUIRE([GROFF_GHOSTSCRIPT_PATH])
115    make_pdfdoc=pdfdoc
116    make_install_pdfdoc=install_pdfdoc
118    missing=""
119    test "$AWK" = missing && missing="\`awk'"
120    test "$GHOSTSCRIPT" = missing && missing="$missing \`gs'"
121    if test -n "$missing"; then
122      plural=`set $missing; test $[#] -eq 2 && echo s`
123      test x$plural = xs \
124        && missing=`set $missing; echo "$[1] and $[2]"` \
125        || missing=`echo $missing`
127      make_pdfdoc=
128      make_install_pdfdoc=
130      AC_MSG_WARN([missing program$plural:
132   The program$plural $missing cannot be found in the PATH.
133   Consequently, groff's PDF formatter (pdfroff) will not work properly;
134   therefore, it will neither be possible to prepare, nor to install,
135   documentation in PDF format.
136      ])
137    fi
139    AC_SUBST([make_pdfdoc])
140    AC_SUBST([make_install_pdfdoc])])
142 # Check whether pnmtops can handle the -nosetpage option.
144 AC_DEFUN([GROFF_PNMTOPS_NOSETPAGE],
145   [AC_MSG_CHECKING([whether pnmtops can handle the -nosetpage option])
146    if echo P2 2 2 255 0 1 2 0 | pnmtops -nosetpage > /dev/null 2>&1 ; then
147      AC_MSG_RESULT([yes])
148      pnmtops_nosetpage="pnmtops -nosetpage"
149    else
150      AC_MSG_RESULT([no])
151      pnmtops_nosetpage="pnmtops"
152    fi
153    AC_SUBST([pnmtops_nosetpage])])
155 # Check location of `gs'; allow `--with-gs=PROG' option to override.
157 AC_DEFUN([GROFF_GHOSTSCRIPT_PATH],
158   [AC_REQUIRE([GROFF_GHOSTSCRIPT_PREFS])
159    AC_ARG_WITH([gs],
160      [AS_HELP_STRING([--with-gs=PROG],
161        [actual [/path/]name of ghostscript executable])],
162      [GHOSTSCRIPT=$withval],
163      [AC_CHECK_TOOLS(GHOSTSCRIPT, [$ALT_GHOSTSCRIPT_PROGS], [missing])])
164    test "$GHOSTSCRIPT" = "no" && GHOSTSCRIPT=missing])
166 # Preferences for choice of `gs' program...
167 # (allow --with-alt-gs="LIST" to override).
169 AC_DEFUN([GROFF_GHOSTSCRIPT_PREFS],
170   [AC_ARG_WITH([alt-gs],
171     [AS_HELP_STRING([--with-alt-gs=LIST],
172       [alternative names for ghostscript executable])],
173     [ALT_GHOSTSCRIPT_PROGS="$withval"],
174     [ALT_GHOSTSCRIPT_PROGS="gs gswin32c gsos2"])
175    AC_SUBST([ALT_GHOSTSCRIPT_PROGS])])
177 # Check location of `awk'; allow `--with-awk=PROG' option to override.
179 AC_DEFUN([GROFF_AWK_PATH],
180   [AC_REQUIRE([GROFF_AWK_PREFS])
181    AC_ARG_WITH([awk],
182      [AS_HELP_STRING([--with-awk=PROG],
183        [actual [/path/]name of awk executable])],
184      [AWK=$withval],
185      [AC_CHECK_TOOLS(AWK, [$ALT_AWK_PROGS], [missing])])
186    test "$AWK" = "no" && AWK=missing])
188 # Preferences for choice of `awk' program; allow --with-alt-awk="LIST"
189 # to override.
191 AC_DEFUN([GROFF_AWK_PREFS],
192   [AC_ARG_WITH([alt-awk],
193     [AS_HELP_STRING([--with-alt-awk=LIST],
194       [alternative names for awk executable])],
195     [ALT_AWK_PROGS="$withval"],
196     [ALT_AWK_PROGS="gawk mawk nawk awk"])
197    AC_SUBST([ALT_AWK_PROGS])])
199 # GROFF_CSH_HACK(if hack present, if not present)
201 AC_DEFUN([GROFF_CSH_HACK],
202   [AC_MSG_CHECKING([for csh hash hack])
204 cat <<EOF >conftest.sh
205 #!/bin/sh
206 true || exit 0
207 export PATH || exit 0
208 exit 1
211    chmod +x conftest.sh
212    if echo ./conftest.sh | (csh >/dev/null 2>&1) >/dev/null 2>&1; then
213      AC_MSG_RESULT([yes])
214      $1
215    else
216      AC_MSG_RESULT([no])
217      $2
218    fi
219    rm -f conftest.sh])
221 # From udodo!hans@relay.NL.net (Hans Zuidam)
223 AC_DEFUN([GROFF_ISC_SYSV3],
224   [AC_MSG_CHECKING([for ISC 3.x or 4.x])
225    if grep ['[34]\.'] /usr/options/cb.name >/dev/null 2>&1
226    then
227      AC_MSG_RESULT([yes])
228      AC_DEFINE([_SYSV3], [1], [Define if you have ISC 3.x or 4.x.])
229    else
230      AC_MSG_RESULT([no])
231    fi])
233 AC_DEFUN([GROFF_POSIX],
234   [AC_MSG_CHECKING([whether -D_POSIX_SOURCE is necessary])
235    AC_LANG_PUSH([C++])
236    AC_COMPILE_IFELSE([
237        AC_LANG_PROGRAM([[
239 #include <stdio.h>
240 extern "C" { void fileno(int); }
242        ]])
243      ],
244      [AC_MSG_RESULT([yes])
245       AC_DEFINE([_POSIX_SOURCE], [1],
246         [Define if -D_POSIX_SOURCE is necessary.])],
247      [AC_MSG_RESULT([no])])
248    AC_LANG_POP([C++])])
250 # srand() of SunOS 4.1.3 has return type int instead of void
252 AC_DEFUN([GROFF_SRAND],
253   [AC_LANG_PUSH([C++])
254    AC_MSG_CHECKING([for return type of srand])
255    AC_COMPILE_IFELSE([
256        AC_LANG_PROGRAM([[
258 #include <stdlib.h>
259 extern "C" { void srand(unsigned int); }
261        ]])
262      ],
263      [AC_MSG_RESULT([void])
264       AC_DEFINE([RET_TYPE_SRAND_IS_VOID], [1],
265         [Define if srand() returns void not int.])],
266      [AC_MSG_RESULT([int])])
267    AC_LANG_POP([C++])])
269 AC_DEFUN([GROFF_SYS_NERR],
270   [AC_LANG_PUSH([C++])
271    AC_MSG_CHECKING([for sys_nerr in <errno.h>, <stdio.h>, or <stdlib.h>])
272    AC_COMPILE_IFELSE([
273        AC_LANG_PROGRAM([[
275 #include <errno.h>
276 #include <stdio.h>
277 #include <stdlib.h>
279        ]],
280        [[
282 int k;
283 k = sys_nerr;
285        ]])
286      ],
287      [AC_MSG_RESULT([yes])
288       AC_DEFINE([HAVE_SYS_NERR], [1],
289         [Define if you have sys_nerr in <errno.h>, <stdio.h>, or <stdio.h>.])],
290      [AC_MSG_RESULT([no])])
291    AC_LANG_POP([C++])])
293 AC_DEFUN([GROFF_SYS_ERRLIST],
294   [AC_MSG_CHECKING([for sys_errlist[] in <errno.h>, <stdio.h>, or <stdlib.h>])
295    AC_COMPILE_IFELSE([
296        AC_LANG_PROGRAM([[
298 #include <errno.h>
299 #include <stdio.h>
300 #include <stdlib.h>
302        ]],
303        [[
305 int k;
306 k = (int)sys_errlist[0];
308        ]])
309      ],
310      [AC_MSG_RESULT([yes])
311       AC_DEFINE([HAVE_SYS_ERRLIST], [1],
312         [Define if you have sys_errlist in <errno.h>, <stdio.h>, or <stdlib.h>.])],
313      [AC_MSG_RESULT([no])])])
315 AC_DEFUN([GROFF_OSFCN_H],
316   [AC_LANG_PUSH([C++])
317    AC_MSG_CHECKING([C++ <osfcn.h>])
318    AC_COMPILE_IFELSE([
319        AC_LANG_PROGRAM([[
321 #include <osfcn.h>
323        ]],
324        [[
326 read(0, 0, 0);
327 open(0, 0);
329        ]])
330      ],
331      [AC_MSG_RESULT([yes])
332       AC_DEFINE([HAVE_CC_OSFCN_H], [1],
333         [Define if you have a C++ <osfcn.h>.])],
334      [AC_MSG_RESULT([no])])
335    AC_LANG_POP([C++])])
337 AC_DEFUN([GROFF_LIMITS_H],
338   [AC_LANG_PUSH([C++])
339    AC_MSG_CHECKING([C++ <limits.h>])
340    AC_COMPILE_IFELSE([
341        AC_LANG_PROGRAM([[
343 #include <limits.h>
345        ]],
346        [[
348 int x = INT_MIN;
349 int y = INT_MAX;
350 int z = UCHAR_MAX;
352        ]])
353      ],
354      [AC_MSG_RESULT([yes])
355       AC_DEFINE([HAVE_CC_LIMITS_H], [1],
356         [Define if you have a C++ <limits.h>.])],
357      [AC_MSG_RESULT([no])])
358    AC_LANG_POP([C++])])
360 AC_DEFUN([GROFF_TIME_T],
361   [AC_LANG_PUSH([C++])
362    AC_MSG_CHECKING([for declaration of time_t])
363    AC_COMPILE_IFELSE([
364        AC_LANG_PROGRAM([[
366 #include <time.h>
368        ]],
369        [[
371 time_t t = time(0);
372 struct tm *p = localtime(&t);
374        ]])
375      ],
376      [AC_MSG_RESULT([yes])],
377      [AC_MSG_RESULT([no])
378       AC_DEFINE([LONG_FOR_TIME_T], [1],
379         [Define if localtime() takes a long * not a time_t *.])])
380    AC_LANG_POP([C++])])
382 AC_DEFUN([GROFF_STRUCT_EXCEPTION],
383   [AC_MSG_CHECKING([struct exception])
384    AC_COMPILE_IFELSE([
385        AC_LANG_PROGRAM([[
387 #include <math.h>
389        ]],
390        [[
392 struct exception e;
394        ]])
395      ],
396      [AC_MSG_RESULT([yes])
397       AC_DEFINE([HAVE_STRUCT_EXCEPTION], [1],
398         [Define if <math.h> defines struct exception.])],
399      [AC_MSG_RESULT([no])])])
401 AC_DEFUN([GROFF_ARRAY_DELETE],
402   [AC_LANG_PUSH([C++])
403    AC_MSG_CHECKING([whether ANSI array delete syntax is supported])
404    AC_COMPILE_IFELSE([
405        AC_LANG_PROGRAM(, [[
407 char *p = new char[5];
408 delete [] p;
410        ]])
411      ],
412      [AC_MSG_RESULT([yes])],
413      [AC_MSG_RESULT([no])
414       AC_DEFINE([ARRAY_DELETE_NEEDS_SIZE], [1],
415         [Define if your C++ doesn't understand `delete []'.])])
416    AC_LANG_POP([C++])])
418 AC_DEFUN([GROFF_TRADITIONAL_CPP],
419   [AC_LANG_PUSH([C++])
420    AC_MSG_CHECKING([traditional preprocessor])
421    AC_COMPILE_IFELSE([
422        AC_LANG_PROGRAM([[
424 #define name2(a, b) a/**/b
426        ]],
427        [[
429 int name2(foo, bar);
431        ]])
432      ],
433      [AC_MSG_RESULT([yes])
434       AC_DEFINE([TRADITIONAL_CPP], [1],
435         [Define if your C++ compiler uses a traditional (Reiser) preprocessor.])],
436      [AC_MSG_RESULT([no])])
437    AC_LANG_POP([C++])])
439 AC_DEFUN([GROFF_WCOREFLAG],
440   [AC_MSG_CHECKING([w_coredump])
441    AC_RUN_IFELSE([
442        AC_LANG_PROGRAM([[
444 #include <sys/types.h>
445 #include <sys/wait.h>
447        ]],
448        [[
450 main()
452 #ifdef WCOREFLAG
453   exit(1);
454 #else
455   int i = 0;
456   ((union wait *)&i)->w_coredump = 1;
457   exit(i != 0200);
458 #endif
461        ]])
462      ],
463      [AC_MSG_RESULT([yes])
464       AC_DEFINE(WCOREFLAG, 0200,
465         [Define if the 0200 bit of the status returned by wait() indicates
466          whether a core image was produced for a process that was terminated
467          by a signal.])],
468      [AC_MSG_RESULT([no])],
469      [AC_MSG_RESULT([no])])])
471 AC_DEFUN([GROFF_BROKEN_SPOOLER_FLAGS],
472   [AC_MSG_CHECKING([default value for grops -b option])
473    test -n "${BROKEN_SPOOLER_FLAGS}" || BROKEN_SPOOLER_FLAGS=0
474    AC_MSG_RESULT([$BROKEN_SPOOLER_FLAGS])
475    AC_SUBST([BROKEN_SPOOLER_FLAGS])])
477 AC_DEFUN([GROFF_PAGE],
478   [AC_MSG_CHECKING([default paper size])
479    groff_prefix=$prefix
480    test "x$prefix" = "xNONE" && groff_prefix=$ac_default_prefix
481    if test -z "$PAGE"; then
482      descfile=
483      if test -r $groff_prefix/share/groff/font/devps/DESC; then
484        descfile=$groff_prefix/share/groff/font/devps/DESC
485      elif test -r $groff_prefix/lib/groff/font/devps/DESC; then
486        descfile=$groff_prefix/lib/groff/font/devps/DESC
487      else
488        for f in $groff_prefix/share/groff/*/font/devps/DESC; do
489          if test -r $f; then
490            descfile=$f
491            break
492          fi
493        done
494      fi
496      if test -n "$descfile"; then
497        if grep ['^paperlength[   ]\+841890'] $descfile >/dev/null 2>&1; then
498          PAGE=A4
499        elif grep ['^papersize[   ]\+[aA]4'] $descfile >/dev/null 2>&1; then
500          PAGE=A4
501        fi
502      fi
503    fi
505    if test -z "$PAGE"; then
506      dom=`awk '([$]1 == "dom" || [$]1 == "search") { print [$]2; exit}' \
507          /etc/resolv.conf 2>/dev/null`
508      if test -z "$dom"; then
509        dom=`(domainname) 2>/dev/null | tr -d '+'`
510        if test -z "$dom" \
511           || test "$dom" = '(none)'; then
512          dom=`(hostname) 2>/dev/null | grep '\.'`
513        fi
514      fi
515      # If the top-level domain is two letters and it's not `us' or `ca'
516      # then they probably use A4 paper.
517      case "$dom" in
518      [*.[Uu][Ss]|*.[Cc][Aa])]
519        ;;
520      [*.[A-Za-z][A-Za-z])]
521        PAGE=A4 ;;
522      esac
523    fi
525    test -n "$PAGE" || PAGE=letter
526    if test "x$PAGE" = "xA4"; then
527      AC_DEFINE([PAGEA4], [1],
528        [Define if the printer's page size is A4.])
529    fi
530    AC_MSG_RESULT([$PAGE])
531    AC_SUBST([PAGE])])
533 AC_DEFUN([GROFF_CXX_CHECK],
534   [AC_REQUIRE([AC_PROG_CXX])
535    AC_LANG_PUSH([C++])
536    if test "$cross_compiling" = no; then
537      AC_MSG_CHECKING([that C++ compiler can compile simple program])
538    fi
539    AC_RUN_IFELSE([
540        AC_LANG_SOURCE([[
542 int main() {
543   return 0;
546        ]])
547      ],
548      [AC_MSG_RESULT([yes])],
549      [AC_MSG_RESULT([no])
550       AC_MSG_ERROR([a working C++ compiler is required])],
551      [:])
553    if test "$cross_compiling" = no; then
554      AC_MSG_CHECKING([that C++ static constructors and destructors are called])
555    fi
556    AC_RUN_IFELSE([
557        AC_LANG_SOURCE([[
559 extern "C" {
560   void _exit(int);
563 int i;
564 struct A {
565   char dummy;
566   A() { i = 1; }
567   ~A() { if (i == 1) _exit(0); }
570 A a;
572 int main()
574   return 1;
577        ]])
578      ],
579      [AC_MSG_RESULT([yes])],
580      [AC_MSG_RESULT([no])
581       AC_MSG_ERROR([a working C++ compiler is required])],
582      [:])
584    AC_MSG_CHECKING([that header files support C++])
585    AC_LINK_IFELSE([
586        AC_LANG_PROGRAM([[
588 #include <stdio.h>
590        ]],
591        [[
593 fopen(0, 0);
595        ]])
596      ],
597      [AC_MSG_RESULT([yes])],
598      [AC_MSG_RESULT([no])
599       AC_MSG_ERROR([header files do not support C++
600                    (if you are using a version of gcc/g++ earlier than 2.5,
601                    you should install libg++)])])
602    AC_LANG_POP([C++])])
604 AC_DEFUN([GROFF_TMAC],
605   [AC_MSG_CHECKING([for prefix of system macro packages])
606    sys_tmac_prefix=
607    sys_tmac_file_prefix=
608    for d in /usr/share/lib/tmac /usr/lib/tmac; do
609      for t in "" tmac.; do
610        for m in an s m; do
611          f=$d/$t$m
612          if test -z "$sys_tmac_prefix" \
613             && test -f $f \
614             && grep '^\.if' $f >/dev/null 2>&1; then
615            sys_tmac_prefix=$d/$t
616            sys_tmac_file_prefix=$t
617          fi
618        done
619      done
620    done
621    AC_MSG_RESULT([$sys_tmac_prefix])
622    AC_SUBST([sys_tmac_prefix])
624    AC_MSG_CHECKING([which system macro packages should be made available])
625    tmac_wrap=
626    if test "x$sys_tmac_file_prefix" = "xtmac."; then
627      for f in $sys_tmac_prefix*; do
628        suff=`echo $f | sed -e "s;$sys_tmac_prefix;;"`
629        case "$suff" in
630        e)
631          ;;
632        *)
633          grep "Copyright.*Free Software Foundation" $f >/dev/null \
634               || tmac_wrap="$tmac_wrap $suff" ;;
635        esac
636      done
637    elif test -n "$sys_tmac_prefix"; then
638      files=`echo $sys_tmac_prefix*`
639      grep "\\.so" $files >conftest.sol
640      for f in $files; do
641        case "$f" in
642        ${sys_tmac_prefix}e)
643          ;;
644        *.me)
645          ;;
646        */ms.*)
647          ;;
648        *)
649          b=`basename $f`
650          if grep "\\.so.*/$b\$" conftest.sol >/dev/null \
651             || grep -l "Copyright.*Free Software Foundation" $f >/dev/null; then
652            :
653          else
654            suff=`echo $f | sed -e "s;$sys_tmac_prefix;;"`
655            case "$suff" in
656            tmac.*)
657              ;;
658            *)
659              tmac_wrap="$tmac_wrap $suff" ;;
660            esac
661          fi
662        esac
663      done
664      rm -f conftest.sol
665    fi
666    AC_MSG_RESULT([$tmac_wrap])
667    AC_SUBST([tmac_wrap])])
669 AC_DEFUN([GROFF_G],
670   [AC_MSG_CHECKING([for existing troff installation])
671    if test "x`(echo .tm '|n(.g' | tr '|' '\\\\' | troff -z -i 2>&1) 2>/dev/null`" = x0; then
672      AC_MSG_RESULT([yes])
673      g=g
674    else
675      AC_MSG_RESULT([no])
676      g=
677    fi
678    AC_SUBST([g])])
680 # We need the path to install-sh to be absolute.
682 AC_DEFUN([GROFF_INSTALL_SH],
683   [AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT])
684    ac_dir=`cd $ac_aux_dir; pwd`
685    ac_install_sh="$ac_dir/install-sh -c"])
687 # Test whether install-info is available.
689 AC_DEFUN([GROFF_INSTALL_INFO],
690   [AC_CHECK_PROGS([INSTALL_INFO], [install-info], [:])])
692 # At least one UNIX system, Apple Macintosh Rhapsody 5.5,
693 # does not have -lm ...
695 AC_DEFUN([GROFF_LIBM],
696   [AC_CHECK_LIB([m], [sin], [LIBM=-lm])
697    AC_SUBST([LIBM])])
699 # ... while the MinGW implementation of GCC for Microsoft Win32
700 # does not seem to have -lc.
702 AC_DEFUN([GROFF_LIBC],
703   [AC_CHECK_LIB([c], [main], [LIBC=-lc])
704    AC_SUBST([LIBC])])
706 # Check for EBCDIC -- stolen from the OS390 Unix LYNX port
708 AC_DEFUN([GROFF_EBCDIC],
709   [AC_MSG_CHECKING([whether character set is EBCDIC])
710    AC_COMPILE_IFELSE([
711        AC_LANG_PROGRAM([[
713 /* Treat any failure as ASCII for compatibility with existing art.
714    Use compile-time rather than run-time tests for cross-compiler
715    tolerance. */
716 #if '0' != 240
717 make an error "Character set is not EBCDIC"
718 #endif
720        ]])
721      ],
722      [groff_cv_ebcdic="yes"
723       TTYDEVDIRS="font/devcp1047"
724       AC_MSG_RESULT([yes])
725       AC_DEFINE(IS_EBCDIC_HOST, 1,
726         [Define if the host's encoding is EBCDIC.])],
727      [groff_cv_ebcdic="no"
728      TTYDEVDIRS="font/devascii font/devlatin1"
729      OTHERDEVDIRS="font/devlj4 font/devlbp"
730      AC_MSG_RESULT([no])])
731    AC_SUBST([TTYDEVDIRS])
732    AC_SUBST([OTHERDEVDIRS])])
734 # Check for OS/390 Unix.  We test for EBCDIC also -- the Linux port (with
735 # gcc) to OS/390 uses ASCII internally.
737 AC_DEFUN([GROFF_OS390],
738   [if test "$groff_cv_ebcdic" = "yes"; then
739      AC_MSG_CHECKING([for OS/390 Unix])
740      case `uname` in
741      OS/390)
742        CFLAGS="$CFLAGS -D_ALL_SOURCE"
743        AC_MSG_RESULT([yes]) ;;
744      *)
745        AC_MSG_RESULT([no]) ;;
746      esac
747    fi])
749 # Check whether we need a declaration for a function.
751 # Stolen from GNU bfd.
753 AC_DEFUN([GROFF_NEED_DECLARATION],
754   [AC_MSG_CHECKING([whether $1 must be declared])
755    AC_LANG_PUSH([C++])
756    AC_CACHE_VAL([groff_cv_decl_needed_$1],
757      [AC_COMPILE_IFELSE([
758           AC_LANG_PROGRAM([[
760 #include <stdio.h>
761 #ifdef HAVE_STRING_H
762 #include <string.h>
763 #endif
764 #ifdef HAVE_STRINGS_H
765 #include <strings.h>
766 #endif
767 #ifdef HAVE_STDLIB_H
768 #include <stdlib.h>
769 #endif
770 #ifdef HAVE_SYS_TIME_H
771 #include <sys/time.h>
772 #endif
773 #ifdef HAVE_UNISTD_H
774 #include <unistd.h>
775 #endif
776 #ifdef HAVE_MATH_H
777 #include <math.h>
778 #endif
780           ]],
781           [[
783 #ifndef $1
784   char *p = (char *) $1;
785 #endif
787           ]])
788       ],
789       [groff_cv_decl_needed_$1=no],
790       [groff_cv_decl_needed_$1=yes])])
791    AC_MSG_RESULT([$groff_cv_decl_needed_$1])
792    if test $groff_cv_decl_needed_$1 = yes; then
793      AC_DEFINE([NEED_DECLARATION_]translit($1, [a-z], [A-Z]), [1],
794        [Define if your C++ doesn't declare ]$1[().])
795    fi
796    AC_LANG_POP([C++])])
798 # If mkstemp() isn't available, use our own mkstemp.cpp file.
800 AC_DEFUN([GROFF_MKSTEMP],
801   [AC_MSG_CHECKING([for mkstemp])
802    AC_LANG_PUSH([C++])
803    AC_LIBSOURCE([mkstemp.cpp])
804    AC_LINK_IFELSE([
805        AC_LANG_PROGRAM([[
807 #include <stdlib.h>
808 #include <unistd.h>
809 int (*f) (char *);
811        ]],
812        [[
814 f = mkstemp;
816        ]])
817      ],
818      [AC_MSG_RESULT([yes])
819       AC_DEFINE([HAVE_MKSTEMP], [1], [Define if you have mkstemp().])],
820      [AC_MSG_RESULT([no])
821       _AC_LIBOBJ([mkstemp])])
822    AC_LANG_POP([C++])])
824 # Test whether <inttypes.h> exists, doesn't clash with <sys/types.h>,
825 # and declares uintmax_t.  Taken from the fileutils package.
827 AC_DEFUN([GROFF_INTTYPES_H],
828   [AC_LANG_PUSH([C++])
829    AC_MSG_CHECKING([C++ <inttypes.h>])
830    AC_COMPILE_IFELSE([
831        AC_LANG_PROGRAM([[
833 #include <sys/types.h>
834 #include <inttypes.h>
836        ]],
837        [[
839 uintmax_t i = (uintmax_t)-1;
841        ]])
842      ],
843      [groff_cv_header_inttypes_h=yes
844       AC_DEFINE([HAVE_CC_INTTYPES_H], [1],
845         [Define if you have a C++ <inttypes.h>.])],
846      [groff_cv_header_inttypes_h=no])
847    AC_MSG_RESULT([$groff_cv_header_inttypes_h])
848    AC_LANG_POP([C++])])
850 # Test for working `unsigned long long'.  Taken from the fileutils package.
852 AC_DEFUN([GROFF_UNSIGNED_LONG_LONG],
853   [AC_LANG_PUSH([C++])
854    AC_MSG_CHECKING([for unsigned long long])
855    AC_LINK_IFELSE([
856        AC_LANG_PROGRAM([[
858 unsigned long long ull = 1;
859 int i = 63;
860 unsigned long long ullmax = (unsigned long long)-1;
862        ]],
863        [[
865 return ull << i | ull >> i | ullmax / ull | ullmax % ull;
867        ]])
868      ],
869      [groff_cv_type_unsigned_long_long=yes],
870      [groff_cv_type_unsigned_long_long=no])
871    AC_MSG_RESULT([$groff_cv_type_unsigned_long_long])
872    AC_LANG_POP([C++])])
874 # Define uintmax_t to `unsigned long' or `unsigned long long'
875 # if <inttypes.h> does not exist.  Taken from the fileutils package.
877 AC_DEFUN([GROFF_UINTMAX_T],
878   [AC_REQUIRE([GROFF_INTTYPES_H])
879    if test $groff_cv_header_inttypes_h = no; then
880      AC_REQUIRE([GROFF_UNSIGNED_LONG_LONG])
881      test $groff_cv_type_unsigned_long_long = yes \
882           && ac_type='unsigned long long' \
883           || ac_type='unsigned long'
884      AC_DEFINE_UNQUOTED([uintmax_t], [$ac_type],
885        [Define uintmax_t to `unsigned long' or `unsigned long long' if
886         <inttypes.h> does not exist.])
887    fi])
889 # Identify PATH_SEPARATOR character to use in GROFF_FONT_PATH and
890 # GROFF_TMAC_PATH which is appropriate for the target system (POSIX=':',
891 # MS-DOS/Win32=';').
893 # The logic to resolve this test is already encapsulated in
894 # `${srcdir}/src/include/nonposix.h'.
896 AC_DEFUN([GROFF_TARGET_PATH_SEPARATOR],
897   [AC_MSG_CHECKING([separator character to use in groff search paths])
898    cp ${srcdir}/src/include/nonposix.h conftest.h
899    AC_COMPILE_IFELSE([
900        AC_LANG_PROGRAM([[
901         
902 #include <ctype.h>
903 #include "conftest.h"
905        ]],
906        [[
908 #if PATH_SEP_CHAR == ';'
909 make an error "Path separator is ';'"
910 #endif
912        ]])
913      ],
914      [GROFF_PATH_SEPARATOR=":"],
915      [GROFF_PATH_SEPARATOR=";"])
916    AC_MSG_RESULT([$GROFF_PATH_SEPARATOR])
917    AC_SUBST(GROFF_PATH_SEPARATOR)])
919 # Check for X11.
921 AC_DEFUN([GROFF_X11],
922   [AC_REQUIRE([AC_PATH_XTRA])
923    groff_no_x=$no_x
924    if test -z "$groff_no_x"; then
925      OLDCFLAGS=$CFLAGS
926      OLDLDFLAGS=$LDFLAGS
927      OLDLIBS=$LIBS
928      CFLAGS="$CFLAGS $X_CFLAGS"
929      LDFLAGS="$LDFLAGS $X_LIBS"
930      LIBS="$LIBS $X_PRE_LIBS -lX11 $X_EXTRA_LIBS"
932      LIBS="$LIBS -lXaw"
933      AC_MSG_CHECKING([for Xaw library and header files])
934      AC_LINK_IFELSE([
935          AC_LANG_PROGRAM([[
937 #include <X11/Intrinsic.h>
938 #include <X11/Xaw/Simple.h>
940          ]],
941          [])
942        ],
943        [AC_MSG_RESULT([yes])],
944        [AC_MSG_RESULT([no])
945         groff_no_x="yes"])
947      LIBS="$LIBS -lXmu"
948      AC_MSG_CHECKING([for Xmu library and header files])
949      AC_LINK_IFELSE([
950          AC_LANG_PROGRAM([[
952 #include <X11/Intrinsic.h>
953 #include <X11/Xmu/Converters.h>
955          ]],
956          [])
957        ],
958        [AC_MSG_RESULT([yes])],
959        [AC_MSG_RESULT([no])
960         groff_no_x="yes"])
962      CFLAGS=$OLDCFLAGS
963      LDFLAGS=$OLDLDFLAGS
964      LIBS=$OLDLIBS
965    fi
967    if test "x$groff_no_x" = "xyes"; then
968      AC_MSG_NOTICE([gxditview and xtotroff won't be built])
969    else
970      XDEVDIRS="font/devX75 font/devX75-12 font/devX100 font/devX100-12"
971      XPROGDIRS="src/devices/xditview src/utils/xtotroff"
972      XLIBDIRS="src/libs/libxutil"
973    fi
975    AC_SUBST([XDEVDIRS])
976    AC_SUBST([XPROGDIRS])
977    AC_SUBST([XLIBDIRS])])
979 # Set up the `--with-appresdir' command line option.
981 AC_DEFUN([GROFF_APPRESDIR_OPTION],
982   [AC_ARG_WITH([appresdir],
983      dnl Don't quote AS_HELP_STRING!
984      AS_HELP_STRING([--with-appresdir=DIR],
985                     [X11 application resource files]))])
987 # Get a default value for the application resource directory.
989 # We ignore the `XAPPLRES' and `XUSERFILESEARCHPATH' environment variables.
991 # The goal is to find the `root' of X11.  Under most systems this is
992 # `/usr/X11/lib'.  Application default files are then in
993 # `/usr/X11/lib/X11/app-defaults'.
995 # Based on autoconf's AC_PATH_X macro.
997 AC_DEFUN([GROFF_APPRESDIR_DEFAULT],
998   [if test -z "$groff_no_x"; then
999      # Create an Imakefile, run `xmkmf', then `make'.
1000      rm -f -r conftest.dir
1001      if mkdir conftest.dir; then
1002        cd conftest.dir
1003        # Make sure to not put `make' in the Imakefile rules,
1004        # since we grep it out.
1005        cat >Imakefile <<'EOF'
1007 xlibdirs:
1008         @echo 'groff_x_usrlibdir="${USRLIBDIR}"; groff_x_libdir="${LIBDIR}"'
1011        if (xmkmf) >/dev/null 2>/dev/null && test -f Makefile; then
1012          # GNU make sometimes prints "make[1]: Entering...",
1013          # which would confuse us.
1014          eval `${MAKE-make} xlibdirs 2>/dev/null | grep -v make`
1016          # Open Windows `xmkmf' reportedly sets LIBDIR instead of USRLIBDIR.
1017          for groff_extension in a so sl; do
1018            if test ! -f $groff_x_usrlibdir/libX11.$groff_extension &&
1019               test -f $groff_x_libdir/libX11.$groff_extension; then
1020              groff_x_usrlibdir=$groff_x_libdir
1021              break
1022            fi
1023          done
1024        fi
1026        cd ..
1027        rm -f -r conftest.dir
1028      fi
1030      # In case the test with `xmkmf' wasn't successful, try a suite of
1031      # standard directories.  Check `X11' before `X11Rn' because it is often
1032      # a symlink to the current release.
1033      groff_x_libdirs='
1034        /usr/X11/lib
1035        /usr/X11R6/lib
1036        /usr/X11R5/lib
1037        /usr/X11R4/lib
1039        /usr/lib/X11
1040        /usr/lib/X11R6
1041        /usr/lib/X11R5
1042        /usr/lib/X11R4
1044        /usr/local/X11/lib
1045        /usr/local/X11R6/lib
1046        /usr/local/X11R5/lib
1047        /usr/local/X11R4/lib
1049        /usr/local/lib/X11
1050        /usr/local/lib/X11R6
1051        /usr/local/lib/X11R5
1052        /usr/local/lib/X11R4
1054        /usr/X386/lib
1055        /usr/x386/lib
1056        /usr/XFree86/lib/X11
1058        /usr/lib
1059        /usr/local/lib
1060        /usr/unsupported/lib
1061        /usr/athena/lib
1062        /usr/local/x11r5/lib
1063        /usr/lpp/Xamples/lib
1065        /usr/openwin/lib
1066        /usr/openwin/share/lib'
1068      if test -z "$groff_x_usrlibdir"; then
1069        # We only test whether libX11 exists.
1070        for groff_dir in $groff_x_libdirs; do
1071          for groff_extension in a so sl; do
1072            if test ! -r $groff_dir/libX11.$groff_extension; then
1073              groff_x_usrlibdir=$groff_dir
1074              break 2
1075            fi
1076          done
1077        done
1078      fi
1080      if test "x$with_appresdir" = "x"; then
1081        appresdir=$groff_x_usrlibdir/X11/app-defaults
1082      else
1083        appresdir=$with_appresdir
1084      fi
1085    fi
1086    AC_SUBST([appresdir])])
1089 # Emit warning if --with-appresdir hasn't been used.
1091 AC_DEFUN([GROFF_APPRESDIR_CHECK],
1092   [if test -z "$groff_no_x"; then
1093      if test "x$with_appresdir" = "x"; then
1094        AC_MSG_NOTICE([
1096   The application resource file for gxditview will be installed as
1098     $appresdir/GXditview
1100   (an existing file will be saved as `GXditview.old').
1101   To install it into a different directory, say, `/etc/gxditview',
1102   add `--with-appresdir=/etc/gxditview' to the configure script
1103   command line options and rerun it.  The environment variable
1104   `APPLRESDIR' must then be set to `/etc/' (note the trailing slash),
1105   omitting the `gxditview' part which is automatically appended by
1106   the X11 searching routines for resource files.  More details can be
1107   found in the X(7) manual page.
1108        ])
1109      fi
1110    fi])