* src/roff/troff/input.cpp: s/safer_flag/unsafe_flag/.
[s-roff.git] / m4 / groff.m4
blob542b0b17e6d611bd663aa2d4c6b25a702ed714d9
1 # Autoconf macros for groff.
2 # Copyright (C) 1989-1995, 2001, 2002, 2003, 2004, 2005, 2006, 2007
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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, 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 # We need makeinfo 4.8 or newer.
62 AC_DEFUN([GROFF_MAKEINFO],
63   [missing=
64    AC_CHECK_PROG([MAKEINFO], [makeinfo], [makeinfo])
65    if test -z "$MAKEINFO"; then
66      missing="\`makeinfo' is missing."
67    else
68      AC_MSG_CHECKING([for makeinfo version])
69      # We need an additional level of quoting to make sed's regexps work.
70      [makeinfo_version=`$MAKEINFO --version 2>&1 \
71        | sed -e 's/^.* \([^ ][^ ]*\)$/\1/' -e '1q'`]
72      AC_MSG_RESULT([$makeinfo_version])
73      # Consider only the first two numbers in version number string.
74      makeinfo_version_major=`IFS=.; set x $makeinfo_version; echo 0${2}`
75      makeinfo_version_minor=`IFS=.; set x $makeinfo_version; echo 0${3}`
76      makeinfo_version_numeric=`
77        expr ${makeinfo_version_major}000 \+ ${makeinfo_version_minor}`
78      if test $makeinfo_version_numeric -lt 4008; then
79        missing="\`makeinfo' is too old."
80      fi
81    fi
83    if test -n "$missing"; then
84      infofile=doc/groff.info
85      test -f ${infofile} || infofile=${srcdir}/${infofile}
86      if test ! -f ${infofile} \
87         || test ${srcdir}/doc/groff.texinfo -nt ${infofile}; then
88        AC_MSG_ERROR($missing
89 [Get the `texinfo' package version 4.8 or newer.])
90      else
91        AC_MSG_WARN($missing
92 [Get the `texinfo' package version 4.8 or newer if you want to convert
93 `groff.texinfo' into a PDF or HTML document.])
94      fi
95    fi
96    AC_SUBST([MAKEINFO])])
98 # The following programs are needed for grohtml.
100 AC_DEFUN([GROFF_HTML_PROGRAMS],
101   [AC_REQUIRE([GROFF_GHOSTSCRIPT_PATH])
102    make_html=html
103    make_install_html=install_html
105    missing=
106    AC_FOREACH([groff_prog],
107      [pnmcut pnmcrop pnmtopng psselect pnmtops],
108      [AC_CHECK_PROG(groff_prog, groff_prog, [found], [missing])
109       if test $[]groff_prog = missing; then
110         missing="$missing \`groff_prog'"
111       fi;])
113    test "$GHOSTSCRIPT" = "missing" && missing="$missing \`gs'"
115    if test -n "$missing"; then
116      plural=`set $missing; test $[#] -gt 1 && echo s`
117      missing=`set $missing
118        missing=""
119        while test $[#] -gt 0
120          do
121            case $[#] in
122              1) missing="$missing$[1]" ;;
123              2) missing="$missing$[1] and " ;;
124              *) missing="$missing$[1], " ;;
125            esac
126            shift
127          done
128          echo $missing`
130      make_html=
131      make_install_html=
133      AC_MSG_WARN([missing program$plural:
135   The program$plural
136      $missing
137   cannot be found in the PATH.
138   Consequently, groff's HTML backend (grohtml) will not work properly;
139   therefore, it will neither be possible to prepare, nor to install,
140   documentation in HTML format.
141      ])
142    fi
144    AC_SUBST([make_html])
145    AC_SUBST([make_install_html])])
147 # To produce PDF docs, we need both awk and ghostscript.
149 AC_DEFUN([GROFF_PDFDOC_PROGRAMS],
150   [AC_REQUIRE([GROFF_AWK_PATH])
151    AC_REQUIRE([GROFF_GHOSTSCRIPT_PATH])
153    make_pdfdoc=pdfdoc
154    make_install_pdfdoc=install_pdfdoc
156    missing=""
157    test "$AWK" = missing && missing="\`awk'"
158    test "$GHOSTSCRIPT" = missing && missing="$missing \`gs'"
159    if test -n "$missing"; then
160      plural=`set $missing; test $[#] -eq 2 && echo s`
161      test x$plural = xs \
162        && missing=`set $missing; echo "$[1] and $[2]"` \
163        || missing=`echo $missing`
165      make_pdfdoc=
166      make_install_pdfdoc=
168      AC_MSG_WARN([missing program$plural:
170   The program$plural $missing cannot be found in the PATH.
171   Consequently, groff's PDF formatter (pdfroff) will not work properly;
172   therefore, it will neither be possible to prepare, nor to install,
173   documentation in PDF format.
174      ])
175    fi
177    AC_SUBST([make_pdfdoc])
178    AC_SUBST([make_install_pdfdoc])])
180 # Check whether pnmtops can handle the -nosetpage option.
182 AC_DEFUN([GROFF_PNMTOPS_NOSETPAGE],
183   [AC_MSG_CHECKING([whether pnmtops can handle the -nosetpage option])
184    if echo P2 2 2 255 0 1 2 0 | pnmtops -nosetpage > /dev/null 2>&1 ; then
185      AC_MSG_RESULT([yes])
186      pnmtops_nosetpage="pnmtops -nosetpage"
187    else
188      AC_MSG_RESULT([no])
189      pnmtops_nosetpage="pnmtops"
190    fi
191    AC_SUBST([pnmtops_nosetpage])])
193 # Check location of `gs'; allow `--with-gs=PROG' option to override.
195 AC_DEFUN([GROFF_GHOSTSCRIPT_PATH],
196   [AC_REQUIRE([GROFF_GHOSTSCRIPT_PREFS])
197    AC_ARG_WITH([gs],
198      [AS_HELP_STRING([--with-gs=PROG],
199        [actual [/path/]name of ghostscript executable])],
200      [GHOSTSCRIPT=$withval],
201      [AC_CHECK_TOOLS(GHOSTSCRIPT, [$ALT_GHOSTSCRIPT_PROGS], [missing])])
202    test "$GHOSTSCRIPT" = "no" && GHOSTSCRIPT=missing])
204 # Preferences for choice of `gs' program...
205 # (allow --with-alt-gs="LIST" to override).
207 AC_DEFUN([GROFF_GHOSTSCRIPT_PREFS],
208   [AC_ARG_WITH([alt-gs],
209     [AS_HELP_STRING([--with-alt-gs=LIST],
210       [alternative names for ghostscript executable])],
211     [ALT_GHOSTSCRIPT_PROGS="$withval"],
212     [ALT_GHOSTSCRIPT_PROGS="gs gswin32c gsos2"])
213    AC_SUBST([ALT_GHOSTSCRIPT_PROGS])])
215 # Check location of `awk'; allow `--with-awk=PROG' option to override.
217 AC_DEFUN([GROFF_AWK_PATH],
218   [AC_REQUIRE([GROFF_AWK_PREFS])
219    AC_ARG_WITH([awk],
220      [AS_HELP_STRING([--with-awk=PROG],
221        [actual [/path/]name of awk executable])],
222      [AWK=$withval],
223      [AC_CHECK_TOOLS(AWK, [$ALT_AWK_PROGS], [missing])])
224    test "$AWK" = "no" && AWK=missing])
226 # Preferences for choice of `awk' program; allow --with-alt-awk="LIST"
227 # to override.
229 AC_DEFUN([GROFF_AWK_PREFS],
230   [AC_ARG_WITH([alt-awk],
231     [AS_HELP_STRING([--with-alt-awk=LIST],
232       [alternative names for awk executable])],
233     [ALT_AWK_PROGS="$withval"],
234     [ALT_AWK_PROGS="gawk mawk nawk awk"])
235    AC_SUBST([ALT_AWK_PROGS])])
237 # GROFF_CSH_HACK(if hack present, if not present)
239 AC_DEFUN([GROFF_CSH_HACK],
240   [AC_MSG_CHECKING([for csh hash hack])
242 cat <<EOF >conftest.sh
243 #! /bin/sh
244 true || exit 0
245 export PATH || exit 0
246 exit 1
249    chmod +x conftest.sh
250    if echo ./conftest.sh | (csh >/dev/null 2>&1) >/dev/null 2>&1; then
251      AC_MSG_RESULT([yes])
252      $1
253    else
254      AC_MSG_RESULT([no])
255      $2
256    fi
257    rm -f conftest.sh])
259 # From udodo!hans@relay.NL.net (Hans Zuidam)
261 AC_DEFUN([GROFF_ISC_SYSV3],
262   [AC_MSG_CHECKING([for ISC 3.x or 4.x])
263    if grep ['[34]\.'] /usr/options/cb.name >/dev/null 2>&1
264    then
265      AC_MSG_RESULT([yes])
266      AC_DEFINE([_SYSV3], [1], [Define if you have ISC 3.x or 4.x.])
267    else
268      AC_MSG_RESULT([no])
269    fi])
271 AC_DEFUN([GROFF_POSIX],
272   [AC_MSG_CHECKING([whether -D_POSIX_SOURCE is necessary])
273    AC_LANG_PUSH([C++])
274    AC_COMPILE_IFELSE([
275        AC_LANG_PROGRAM([[
277 #include <stdio.h>
278 extern "C" { void fileno(int); }
280        ]])
281      ],
282      [AC_MSG_RESULT([yes])
283       AC_DEFINE([_POSIX_SOURCE], [1],
284         [Define if -D_POSIX_SOURCE is necessary.])],
285      [AC_MSG_RESULT([no])])
286    AC_LANG_POP([C++])])
288 # srand() of SunOS 4.1.3 has return type int instead of void
290 AC_DEFUN([GROFF_SRAND],
291   [AC_LANG_PUSH([C++])
292    AC_MSG_CHECKING([for return type of srand])
293    AC_COMPILE_IFELSE([
294        AC_LANG_PROGRAM([[
296 #include <stdlib.h>
297 extern "C" { void srand(unsigned int); }
299        ]])
300      ],
301      [AC_MSG_RESULT([void])
302       AC_DEFINE([RET_TYPE_SRAND_IS_VOID], [1],
303         [Define if srand() returns void not int.])],
304      [AC_MSG_RESULT([int])])
305    AC_LANG_POP([C++])])
307 # In April 2005, autoconf's AC_TYPE_SIGNAL is still broken.
309 AC_DEFUN([GROFF_TYPE_SIGNAL],
310   [AC_MSG_CHECKING([for return type of signal handlers])
311    for groff_declaration in \
312      'extern "C" void (*signal (int, void (*)(int)))(int);' \
313      'extern "C" void (*signal (int, void (*)(int)) throw ())(int);' \
314      'void (*signal ()) ();' 
315    do
316      AC_COMPILE_IFELSE([
317          AC_LANG_PROGRAM([[
319 #include <sys/types.h>
320 #include <signal.h>
321 #ifdef signal
322 # undef signal
323 #endif
324 $groff_declaration
326          ]],
327          [[
329 int i;
331          ]])
332        ],
333        [break],
334        [continue])
335    done
337    if test -n "$groff_declaration"; then
338      AC_MSG_RESULT([void])
339      AC_DEFINE([RETSIGTYPE], [void],
340        [Define as the return type of signal handlers
341         (`int' or `void').])
342    else
343      AC_MSG_RESULT([int])
344      AC_DEFINE([RETSIGTYPE], [int],
345        [Define as the return type of signal handlers
346         (`int' or `void').])
347    fi])
349 AC_DEFUN([GROFF_SYS_NERR],
350   [AC_LANG_PUSH([C++])
351    AC_MSG_CHECKING([for sys_nerr in <errno.h>, <stdio.h>, or <stdlib.h>])
352    AC_COMPILE_IFELSE([
353        AC_LANG_PROGRAM([[
355 #include <errno.h>
356 #include <stdio.h>
357 #include <stdlib.h>
359        ]],
360        [[
362 int k;
363 k = sys_nerr;
365        ]])
366      ],
367      [AC_MSG_RESULT([yes])
368       AC_DEFINE([HAVE_SYS_NERR], [1],
369         [Define if you have sys_nerr in <errno.h>, <stdio.h>, or <stdio.h>.])],
370      [AC_MSG_RESULT([no])])
371    AC_LANG_POP([C++])])
373 AC_DEFUN([GROFF_SYS_ERRLIST],
374   [AC_MSG_CHECKING([for sys_errlist[] in <errno.h>, <stdio.h>, or <stdlib.h>])
375    AC_COMPILE_IFELSE([
376        AC_LANG_PROGRAM([[
378 #include <errno.h>
379 #include <stdio.h>
380 #include <stdlib.h>
382        ]],
383        [[
385 int k;
386 k = (int)sys_errlist[0];
388        ]])
389      ],
390      [AC_MSG_RESULT([yes])
391       AC_DEFINE([HAVE_SYS_ERRLIST], [1],
392         [Define if you have sys_errlist in <errno.h>, <stdio.h>, or <stdlib.h>.])],
393      [AC_MSG_RESULT([no])])])
395 AC_DEFUN([GROFF_OSFCN_H],
396   [AC_LANG_PUSH([C++])
397    AC_MSG_CHECKING([C++ <osfcn.h>])
398    AC_COMPILE_IFELSE([
399        AC_LANG_PROGRAM([[
401 #include <osfcn.h>
403        ]],
404        [[
406 read(0, 0, 0);
407 open(0, 0);
409        ]])
410      ],
411      [AC_MSG_RESULT([yes])
412       AC_DEFINE([HAVE_CC_OSFCN_H], [1],
413         [Define if you have a C++ <osfcn.h>.])],
414      [AC_MSG_RESULT([no])])
415    AC_LANG_POP([C++])])
417 AC_DEFUN([GROFF_LIMITS_H],
418   [AC_LANG_PUSH([C++])
419    AC_MSG_CHECKING([C++ <limits.h>])
420    AC_COMPILE_IFELSE([
421        AC_LANG_PROGRAM([[
423 #include <limits.h>
425        ]],
426        [[
428 int x = INT_MIN;
429 int y = INT_MAX;
430 int z = UCHAR_MAX;
432        ]])
433      ],
434      [AC_MSG_RESULT([yes])
435       AC_DEFINE([HAVE_CC_LIMITS_H], [1],
436         [Define if you have a C++ <limits.h>.])],
437      [AC_MSG_RESULT([no])])
438    AC_LANG_POP([C++])])
440 AC_DEFUN([GROFF_TIME_T],
441   [AC_LANG_PUSH([C++])
442    AC_MSG_CHECKING([for declaration of time_t])
443    AC_COMPILE_IFELSE([
444        AC_LANG_PROGRAM([[
446 #include <time.h>
448        ]],
449        [[
451 time_t t = time(0);
452 struct tm *p = localtime(&t);
454        ]])
455      ],
456      [AC_MSG_RESULT([yes])],
457      [AC_MSG_RESULT([no])
458       AC_DEFINE([LONG_FOR_TIME_T], [1],
459         [Define if localtime() takes a long * not a time_t *.])])
460    AC_LANG_POP([C++])])
462 AC_DEFUN([GROFF_STRUCT_EXCEPTION],
463   [AC_MSG_CHECKING([struct exception])
464    AC_COMPILE_IFELSE([
465        AC_LANG_PROGRAM([[
467 #include <math.h>
469        ]],
470        [[
472 struct exception e;
474        ]])
475      ],
476      [AC_MSG_RESULT([yes])
477       AC_DEFINE([HAVE_STRUCT_EXCEPTION], [1],
478         [Define if <math.h> defines struct exception.])],
479      [AC_MSG_RESULT([no])])])
481 AC_DEFUN([GROFF_ARRAY_DELETE],
482   [AC_LANG_PUSH([C++])
483    AC_MSG_CHECKING([whether ANSI array delete syntax is supported])
484    AC_COMPILE_IFELSE([
485        AC_LANG_PROGRAM(, [[
487 char *p = new char[5];
488 delete [] p;
490        ]])
491      ],
492      [AC_MSG_RESULT([yes])],
493      [AC_MSG_RESULT([no])
494       AC_DEFINE([ARRAY_DELETE_NEEDS_SIZE], [1],
495         [Define if your C++ doesn't understand `delete []'.])])
496    AC_LANG_POP([C++])])
498 AC_DEFUN([GROFF_TRADITIONAL_CPP],
499   [AC_LANG_PUSH([C++])
500    AC_MSG_CHECKING([traditional preprocessor])
501    AC_COMPILE_IFELSE([
502        AC_LANG_PROGRAM([[
504 #define name2(a, b) a/**/b
506        ]],
507        [[
509 int name2(foo, bar);
511        ]])
512      ],
513      [AC_MSG_RESULT([yes])
514       AC_DEFINE([TRADITIONAL_CPP], [1],
515         [Define if your C++ compiler uses a traditional (Reiser) preprocessor.])],
516      [AC_MSG_RESULT([no])])
517    AC_LANG_POP([C++])])
519 AC_DEFUN([GROFF_WCOREFLAG],
520   [AC_MSG_CHECKING([w_coredump])
521    AC_RUN_IFELSE([
522        AC_LANG_PROGRAM([[
524 #include <sys/types.h>
525 #include <sys/wait.h>
527        ]],
528        [[
530 main()
532 #ifdef WCOREFLAG
533   exit(1);
534 #else
535   int i = 0;
536   ((union wait *)&i)->w_coredump = 1;
537   exit(i != 0200);
538 #endif
541        ]])
542      ],
543      [AC_MSG_RESULT([yes])
544       AC_DEFINE(WCOREFLAG, 0200,
545         [Define if the 0200 bit of the status returned by wait() indicates
546          whether a core image was produced for a process that was terminated
547          by a signal.])],
548      [AC_MSG_RESULT([no])],
549      [AC_MSG_RESULT([no])])])
551 AC_DEFUN([GROFF_BROKEN_SPOOLER_FLAGS],
552   [AC_MSG_CHECKING([default value for grops -b option])
553    test -n "${BROKEN_SPOOLER_FLAGS}" || BROKEN_SPOOLER_FLAGS=0
554    AC_MSG_RESULT([$BROKEN_SPOOLER_FLAGS])
555    AC_SUBST([BROKEN_SPOOLER_FLAGS])])
557 AC_DEFUN([GROFF_PAGE],
558   [AC_MSG_CHECKING([default paper size])
559    groff_prefix=$prefix
560    test "x$prefix" = "xNONE" && groff_prefix=$ac_default_prefix
561    if test -z "$PAGE"; then
562      descfile=
563      if test -r $groff_prefix/share/groff/font/devps/DESC; then
564        descfile=$groff_prefix/share/groff/font/devps/DESC
565      elif test -r $groff_prefix/lib/groff/font/devps/DESC; then
566        descfile=$groff_prefix/lib/groff/font/devps/DESC
567      else
568        for f in $groff_prefix/share/groff/*/font/devps/DESC; do
569          if test -r $f; then
570            descfile=$f
571            break
572          fi
573        done
574      fi
576      if test -n "$descfile"; then
577        if grep ['^paperlength[   ]\+841890'] $descfile >/dev/null 2>&1; then
578          PAGE=A4
579        elif grep ['^papersize[   ]\+[aA]4'] $descfile >/dev/null 2>&1; then
580          PAGE=A4
581        fi
582      fi
583    fi
585    if test -z "$PAGE"; then
586      dom=`awk '([$]1 == "dom" || [$]1 == "search") { print [$]2; exit}' \
587          /etc/resolv.conf 2>/dev/null`
588      if test -z "$dom"; then
589        dom=`(domainname) 2>/dev/null | tr -d '+'`
590        if test -z "$dom" \
591           || test "$dom" = '(none)'; then
592          dom=`(hostname) 2>/dev/null | grep '\.'`
593        fi
594      fi
595      # If the top-level domain is two letters and it's not `us' or `ca'
596      # then they probably use A4 paper.
597      case "$dom" in
598      [*.[Uu][Ss]|*.[Cc][Aa])]
599        ;;
600      [*.[A-Za-z][A-Za-z])]
601        PAGE=A4 ;;
602      esac
603    fi
605    test -n "$PAGE" || PAGE=letter
606    if test "x$PAGE" = "xA4"; then
607      AC_DEFINE([PAGEA4], [1],
608        [Define if the printer's page size is A4.])
609    fi
610    AC_MSG_RESULT([$PAGE])
611    AC_SUBST([PAGE])])
613 AC_DEFUN([GROFF_CXX_CHECK],
614   [AC_REQUIRE([AC_PROG_CXX])
615    AC_LANG_PUSH([C++])
616    if test "$cross_compiling" = no; then
617      AC_MSG_CHECKING([that C++ compiler can compile simple program])
618    fi
619    AC_RUN_IFELSE([
620        AC_LANG_SOURCE([[
622 int main() {
623   return 0;
626        ]])
627      ],
628      [AC_MSG_RESULT([yes])],
629      [AC_MSG_RESULT([no])
630       AC_MSG_ERROR([a working C++ compiler is required])],
631      [:])
633    if test "$cross_compiling" = no; then
634      AC_MSG_CHECKING([that C++ static constructors and destructors are called])
635    fi
636    AC_RUN_IFELSE([
637        AC_LANG_SOURCE([[
639 extern "C" {
640   void _exit(int);
643 int i;
644 struct A {
645   char dummy;
646   A() { i = 1; }
647   ~A() { if (i == 1) _exit(0); }
650 A a;
652 int main()
654   return 1;
657        ]])
658      ],
659      [AC_MSG_RESULT([yes])],
660      [AC_MSG_RESULT([no])
661       AC_MSG_ERROR([a working C++ compiler is required])],
662      [:])
664    AC_MSG_CHECKING([that header files support C++])
665    AC_LINK_IFELSE([
666        AC_LANG_PROGRAM([[
668 #include <stdio.h>
670        ]],
671        [[
673 fopen(0, 0);
675        ]])
676      ],
677      [AC_MSG_RESULT([yes])],
678      [AC_MSG_RESULT([no])
679       AC_MSG_ERROR([header files do not support C++
680                    (if you are using a version of gcc/g++ earlier than 2.5,
681                    you should install libg++)])])
682    AC_LANG_POP([C++])])
684 AC_DEFUN([GROFF_TMAC],
685   [AC_MSG_CHECKING([for prefix of system macro packages])
686    sys_tmac_prefix=
687    sys_tmac_file_prefix=
688    for d in /usr/share/lib/tmac /usr/lib/tmac; do
689      for t in "" tmac.; do
690        for m in an s m; do
691          f=$d/$t$m
692          if test -z "$sys_tmac_prefix" \
693             && test -f $f \
694             && grep '^\.if' $f >/dev/null 2>&1; then
695            sys_tmac_prefix=$d/$t
696            sys_tmac_file_prefix=$t
697          fi
698        done
699      done
700    done
701    AC_MSG_RESULT([$sys_tmac_prefix])
702    AC_SUBST([sys_tmac_prefix])
704    AC_MSG_CHECKING([which system macro packages should be made available])
705    tmac_wrap=
706    if test "x$sys_tmac_file_prefix" = "xtmac."; then
707      for f in $sys_tmac_prefix*; do
708        suff=`echo $f | sed -e "s;$sys_tmac_prefix;;"`
709        case "$suff" in
710        e)
711          ;;
712        *)
713          grep "Copyright.*Free Software Foundation" $f >/dev/null \
714               || tmac_wrap="$tmac_wrap $suff" ;;
715        esac
716      done
717    elif test -n "$sys_tmac_prefix"; then
718      files=`echo $sys_tmac_prefix*`
719      grep "\\.so" $files >conftest.sol
720      for f in $files; do
721        case "$f" in
722        ${sys_tmac_prefix}e)
723          ;;
724        *.me)
725          ;;
726        */ms.*)
727          ;;
728        *)
729          b=`basename $f`
730          if grep "\\.so.*/$b\$" conftest.sol >/dev/null \
731             || grep -l "Copyright.*Free Software Foundation" $f >/dev/null; then
732            :
733          else
734            suff=`echo $f | sed -e "s;$sys_tmac_prefix;;"`
735            case "$suff" in
736            tmac.*)
737              ;;
738            *)
739              tmac_wrap="$tmac_wrap $suff" ;;
740            esac
741          fi
742        esac
743      done
744      rm -f conftest.sol
745    fi
746    AC_MSG_RESULT([$tmac_wrap])
747    AC_SUBST([tmac_wrap])])
749 AC_DEFUN([GROFF_G],
750   [AC_MSG_CHECKING([for existing troff installation])
751    if test "x`(echo .tm '|n(.g' | tr '|' '\\\\' | troff -z -i 2>&1) 2>/dev/null`" = x0; then
752      AC_MSG_RESULT([yes])
753      g=g
754    else
755      AC_MSG_RESULT([no])
756      g=
757    fi
758    AC_SUBST([g])])
760 # We need the path to install-sh to be absolute.
762 AC_DEFUN([GROFF_INSTALL_SH],
763   [AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT])
764    ac_dir=`cd $ac_aux_dir; pwd`
765    ac_install_sh="$ac_dir/install-sh -c"])
767 # Test whether install-info is available.
769 AC_DEFUN([GROFF_INSTALL_INFO],
770   [AC_CHECK_PROGS([INSTALL_INFO], [install-info], [:])])
772 # At least one UNIX system, Apple Macintosh Rhapsody 5.5,
773 # does not have -lm ...
775 AC_DEFUN([GROFF_LIBM],
776   [AC_CHECK_LIB([m], [sin], [LIBM=-lm])
777    AC_SUBST([LIBM])])
779 # ... while the MinGW implementation of GCC for Microsoft Win32
780 # does not seem to have -lc.
782 AC_DEFUN([GROFF_LIBC],
783   [AC_CHECK_LIB([c], [main], [LIBC=-lc])
784    AC_SUBST([LIBC])])
786 # Check for EBCDIC -- stolen from the OS390 Unix LYNX port
788 AC_DEFUN([GROFF_EBCDIC],
789   [AC_MSG_CHECKING([whether character set is EBCDIC])
790    AC_COMPILE_IFELSE([
791        AC_LANG_PROGRAM([[
793 /* Treat any failure as ASCII for compatibility with existing art.
794    Use compile-time rather than run-time tests for cross-compiler
795    tolerance. */
796 #if '0' != 240
797 make an error "Character set is not EBCDIC"
798 #endif
800        ]])
801      ],
802      [groff_cv_ebcdic="yes"
803       TTYDEVDIRS="font/devcp1047"
804       AC_MSG_RESULT([yes])
805       AC_DEFINE(IS_EBCDIC_HOST, 1,
806         [Define if the host's encoding is EBCDIC.])],
807      [groff_cv_ebcdic="no"
808      TTYDEVDIRS="font/devascii font/devlatin1"
809      OTHERDEVDIRS="font/devlj4 font/devlbp"
810      AC_MSG_RESULT([no])])
811    AC_SUBST([TTYDEVDIRS])
812    AC_SUBST([OTHERDEVDIRS])])
814 # Check for OS/390 Unix.  We test for EBCDIC also -- the Linux port (with
815 # gcc) to OS/390 uses ASCII internally.
817 AC_DEFUN([GROFF_OS390],
818   [if test "$groff_cv_ebcdic" = "yes"; then
819      AC_MSG_CHECKING([for OS/390 Unix])
820      case `uname` in
821      OS/390)
822        CFLAGS="$CFLAGS -D_ALL_SOURCE"
823        AC_MSG_RESULT([yes]) ;;
824      *)
825        AC_MSG_RESULT([no]) ;;
826      esac
827    fi])
829 # Check whether we need a declaration for a function.
831 # Stolen from GNU bfd.
833 AC_DEFUN([GROFF_NEED_DECLARATION],
834   [AC_MSG_CHECKING([whether $1 must be declared])
835    AC_LANG_PUSH([C++])
836    AC_CACHE_VAL([groff_cv_decl_needed_$1],
837      [AC_COMPILE_IFELSE([
838           AC_LANG_PROGRAM([[
840 #include <stdio.h>
841 #ifdef HAVE_STRING_H
842 #include <string.h>
843 #endif
844 #ifdef HAVE_STRINGS_H
845 #include <strings.h>
846 #endif
847 #ifdef HAVE_STDLIB_H
848 #include <stdlib.h>
849 #endif
850 #ifdef HAVE_SYS_TIME_H
851 #include <sys/time.h>
852 #endif
853 #ifdef HAVE_UNISTD_H
854 #include <unistd.h>
855 #endif
856 #ifdef HAVE_MATH_H
857 #include <math.h>
858 #endif
860           ]],
861           [[
863 #ifndef $1
864   char *p = (char *) $1;
865 #endif
867           ]])
868       ],
869       [groff_cv_decl_needed_$1=no],
870       [groff_cv_decl_needed_$1=yes])])
871    AC_MSG_RESULT([$groff_cv_decl_needed_$1])
872    if test $groff_cv_decl_needed_$1 = yes; then
873      AC_DEFINE([NEED_DECLARATION_]translit($1, [a-z], [A-Z]), [1],
874        [Define if your C++ doesn't declare ]$1[().])
875    fi
876    AC_LANG_POP([C++])])
878 # If mkstemp() isn't available, use our own mkstemp.cpp file.
880 AC_DEFUN([GROFF_MKSTEMP],
881   [AC_MSG_CHECKING([for mkstemp])
882    AC_LANG_PUSH([C++])
883    AC_LIBSOURCE([mkstemp.cpp])
884    AC_LINK_IFELSE([
885        AC_LANG_PROGRAM([[
887 #include <stdlib.h>
888 #include <unistd.h>
889 int (*f) (char *);
891        ]],
892        [[
894 f = mkstemp;
896        ]])
897      ],
898      [AC_MSG_RESULT([yes])
899       AC_DEFINE([HAVE_MKSTEMP], [1], [Define if you have mkstemp().])],
900      [AC_MSG_RESULT([no])
901       _AC_LIBOBJ([mkstemp])])
902    AC_LANG_POP([C++])])
904 # Test whether <inttypes.h> exists, doesn't clash with <sys/types.h>,
905 # and declares uintmax_t.  Taken from the fileutils package.
907 AC_DEFUN([GROFF_INTTYPES_H],
908   [AC_LANG_PUSH([C++])
909    AC_MSG_CHECKING([C++ <inttypes.h>])
910    AC_COMPILE_IFELSE([
911        AC_LANG_PROGRAM([[
913 #include <sys/types.h>
914 #include <inttypes.h>
916        ]],
917        [[
919 uintmax_t i = (uintmax_t)-1;
921        ]])
922      ],
923      [groff_cv_header_inttypes_h=yes
924       AC_DEFINE([HAVE_CC_INTTYPES_H], [1],
925         [Define if you have a C++ <inttypes.h>.])],
926      [groff_cv_header_inttypes_h=no])
927    AC_MSG_RESULT([$groff_cv_header_inttypes_h])
928    AC_LANG_POP([C++])])
930 # Test for working `unsigned long long'.  Taken from the fileutils package.
932 AC_DEFUN([GROFF_UNSIGNED_LONG_LONG],
933   [AC_LANG_PUSH([C++])
934    AC_MSG_CHECKING([for unsigned long long])
935    AC_LINK_IFELSE([
936        AC_LANG_PROGRAM([[
938 unsigned long long ull = 1;
939 int i = 63;
940 unsigned long long ullmax = (unsigned long long)-1;
942        ]],
943        [[
945 return ull << i | ull >> i | ullmax / ull | ullmax % ull;
947        ]])
948      ],
949      [groff_cv_type_unsigned_long_long=yes],
950      [groff_cv_type_unsigned_long_long=no])
951    AC_MSG_RESULT([$groff_cv_type_unsigned_long_long])
952    AC_LANG_POP([C++])])
954 # Define uintmax_t to `unsigned long' or `unsigned long long'
955 # if <inttypes.h> does not exist.  Taken from the fileutils package.
957 AC_DEFUN([GROFF_UINTMAX_T],
958   [AC_REQUIRE([GROFF_INTTYPES_H])
959    if test $groff_cv_header_inttypes_h = no; then
960      AC_REQUIRE([GROFF_UNSIGNED_LONG_LONG])
961      test $groff_cv_type_unsigned_long_long = yes \
962           && ac_type='unsigned long long' \
963           || ac_type='unsigned long'
964      AC_DEFINE_UNQUOTED([uintmax_t], [$ac_type],
965        [Define uintmax_t to `unsigned long' or `unsigned long long' if
966         <inttypes.h> does not exist.])
967    fi])
969 # Identify PATH_SEPARATOR character to use in GROFF_FONT_PATH and
970 # GROFF_TMAC_PATH which is appropriate for the target system (POSIX=':',
971 # MS-DOS/Win32=';').
973 # The logic to resolve this test is already encapsulated in
974 # `${srcdir}/src/include/nonposix.h'.
976 AC_DEFUN([GROFF_TARGET_PATH_SEPARATOR],
977   [AC_MSG_CHECKING([separator character to use in groff search paths])
978    cp ${srcdir}/src/include/nonposix.h conftest.h
979    AC_COMPILE_IFELSE([
980        AC_LANG_PROGRAM([[
981         
982 #include <ctype.h>
983 #include "conftest.h"
985        ]],
986        [[
988 #if PATH_SEP_CHAR == ';'
989 make an error "Path separator is ';'"
990 #endif
992        ]])
993      ],
994      [GROFF_PATH_SEPARATOR=":"],
995      [GROFF_PATH_SEPARATOR=";"])
996    AC_MSG_RESULT([$GROFF_PATH_SEPARATOR])
997    AC_SUBST(GROFF_PATH_SEPARATOR)])
999 # Check for X11.
1001 AC_DEFUN([GROFF_X11],
1002   [AC_REQUIRE([AC_PATH_XTRA])
1003    groff_no_x=$no_x
1004    if test -z "$groff_no_x"; then
1005      OLDCFLAGS=$CFLAGS
1006      OLDLDFLAGS=$LDFLAGS
1007      OLDLIBS=$LIBS
1008      CFLAGS="$CFLAGS $X_CFLAGS"
1009      LDFLAGS="$LDFLAGS $X_LIBS"
1010      LIBS="$LIBS $X_PRE_LIBS -lX11 $X_EXTRA_LIBS"
1012      LIBS="$LIBS -lXaw"
1013      AC_MSG_CHECKING([for Xaw library and header files])
1014      AC_LINK_IFELSE([
1015          AC_LANG_PROGRAM([[
1017 #include <X11/Intrinsic.h>
1018 #include <X11/Xaw/Simple.h>
1020          ]],
1021          [])
1022        ],
1023        [AC_MSG_RESULT([yes])],
1024        [AC_MSG_RESULT([no])
1025         groff_no_x="yes"])
1027      LIBS="$LIBS -lXmu"
1028      AC_MSG_CHECKING([for Xmu library and header files])
1029      AC_LINK_IFELSE([
1030          AC_LANG_PROGRAM([[
1032 #include <X11/Intrinsic.h>
1033 #include <X11/Xmu/Converters.h>
1035          ]],
1036          [])
1037        ],
1038        [AC_MSG_RESULT([yes])],
1039        [AC_MSG_RESULT([no])
1040         groff_no_x="yes"])
1042      CFLAGS=$OLDCFLAGS
1043      LDFLAGS=$OLDLDFLAGS
1044      LIBS=$OLDLIBS
1045    fi
1047    if test "x$groff_no_x" = "xyes"; then
1048      AC_MSG_NOTICE([gxditview and xtotroff won't be built])
1049    else
1050      XDEVDIRS="font/devX75 font/devX75-12 font/devX100 font/devX100-12"
1051      XPROGDIRS="src/devices/xditview src/utils/xtotroff"
1052      XLIBDIRS="src/libs/libxutil"
1053    fi
1055    AC_SUBST([XDEVDIRS])
1056    AC_SUBST([XPROGDIRS])
1057    AC_SUBST([XLIBDIRS])])
1059 # Set up the `--with-appresdir' command line option.
1061 # Don't quote AS_HELP_STRING!
1062 AC_DEFUN([GROFF_APPRESDIR_OPTION],
1063   [AC_ARG_WITH([appresdir],
1064      AS_HELP_STRING([--with-appresdir=DIR],
1065                     [X11 application resource files]))])
1067 # Get a default value for the application resource directory.
1069 # We ignore the `XAPPLRES' and `XUSERFILESEARCHPATH' environment variables.
1071 # The goal is to find the `root' of X11.  Under most systems this is
1072 # `/usr/X11/lib'.  Application default files are then in
1073 # `/usr/X11/lib/X11/app-defaults'.
1075 # Based on autoconf's AC_PATH_X macro.
1077 AC_DEFUN([GROFF_APPRESDIR_DEFAULT],
1078   [if test -z "$groff_no_x"; then
1079      # Create an Imakefile, run `xmkmf', then `make'.
1080      rm -f -r conftest.dir
1081      if mkdir conftest.dir; then
1082        cd conftest.dir
1083        # Make sure to not put `make' in the Imakefile rules,
1084        # since we grep it out.
1085        cat >Imakefile <<'EOF'
1087 xlibdirs:
1088         @echo 'groff_x_usrlibdir="${USRLIBDIR}"; groff_x_libdir="${LIBDIR}"'
1091        if (xmkmf) >/dev/null 2>/dev/null && test -f Makefile; then
1092          # GNU make sometimes prints "make[1]: Entering...",
1093          # which would confuse us.
1094          eval `${MAKE-make} xlibdirs 2>/dev/null | grep -v make`
1096          # Open Windows `xmkmf' reportedly sets LIBDIR instead of USRLIBDIR.
1097          for groff_extension in a so sl; do
1098            if test ! -f $groff_x_usrlibdir/libX11.$groff_extension &&
1099               test -f $groff_x_libdir/libX11.$groff_extension; then
1100              groff_x_usrlibdir=$groff_x_libdir
1101              break
1102            fi
1103          done
1104        fi
1106        cd ..
1107        rm -f -r conftest.dir
1108      fi
1110      # In case the test with `xmkmf' wasn't successful, try a suite of
1111      # standard directories.  Check `X11' before `X11Rn' because it is often
1112      # a symlink to the current release.
1113      groff_x_libdirs='
1114        /usr/X11/lib
1115        /usr/X11R6/lib
1116        /usr/X11R5/lib
1117        /usr/X11R4/lib
1119        /usr/lib/X11
1120        /usr/lib/X11R6
1121        /usr/lib/X11R5
1122        /usr/lib/X11R4
1124        /usr/local/X11/lib
1125        /usr/local/X11R6/lib
1126        /usr/local/X11R5/lib
1127        /usr/local/X11R4/lib
1129        /usr/local/lib/X11
1130        /usr/local/lib/X11R6
1131        /usr/local/lib/X11R5
1132        /usr/local/lib/X11R4
1134        /usr/X386/lib
1135        /usr/x386/lib
1136        /usr/XFree86/lib/X11
1138        /usr/lib
1139        /usr/local/lib
1140        /usr/unsupported/lib
1141        /usr/athena/lib
1142        /usr/local/x11r5/lib
1143        /usr/lpp/Xamples/lib
1145        /usr/openwin/lib
1146        /usr/openwin/share/lib'
1148      if test -z "$groff_x_usrlibdir"; then
1149        # We only test whether libX11 exists.
1150        for groff_dir in $groff_x_libdirs; do
1151          for groff_extension in a so sl; do
1152            if test ! -r $groff_dir/libX11.$groff_extension; then
1153              groff_x_usrlibdir=$groff_dir
1154              break 2
1155            fi
1156          done
1157        done
1158      fi
1160      if test "x$with_appresdir" = "x"; then
1161        appresdir=$groff_x_usrlibdir/X11/app-defaults
1162      else
1163        appresdir=$with_appresdir
1164      fi
1165    fi
1166    AC_SUBST([appresdir])])
1169 # Emit warning if --with-appresdir hasn't been used.
1171 AC_DEFUN([GROFF_APPRESDIR_CHECK],
1172   [if test -z "$groff_no_x"; then
1173      if test "x$with_appresdir" = "x"; then
1174        AC_MSG_NOTICE([
1176   The application resource files for gxditview will be installed as
1178     $appresdir/GXditview
1180   and
1182     $appresdir/GXditview-color
1184   (existing files will be saved by appending `.old' to the file
1185   name).
1187   To install them into a different directory, say, `/etc/gxditview',
1188   add `--with-appresdir=/etc/gxditview' to the configure script
1189   command line options and rerun it.  The environment variable
1190   `APPLRESDIR' must then be set to `/etc/' (note the trailing slash),
1191   omitting the `gxditview' part which is automatically appended by
1192   the X11 searching routines for resource files.  More details can be
1193   found in the X(7) manual page.
1194        ])
1195      fi
1196    fi])