Fixed typo. From Michail.
[s-roff.git] / aclocal.m4
blobce88f5507d95d8cbdbe8b09b082ef755f90bdb68
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, 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=`echo $makeinfo_version \
75        | sed 's/^\([0-9]*\).*$/\1/'`]
76      if test -z "$makeinfo_version_major"; then
77        makeinfo_version_major=0
78        makeinfo_version_minor=0
79      else
80        [makeinfo_version_minor=`echo $makeinfo_version \
81          | sed 's/^[^.][^.]*\(.*\)$/\1/'`]
82        # No minor version number at all?
83        if test -z "$makeinfo_version_minor"; then
84          makeinfo_version_minor=0
85        else
86          [makeinfo_version_minor=`echo $makeinfo_version_minor \
87            | sed 's/\.\([0-9]*\).*$/\1/'`]
88          if test -z "$makeinfo_version_minor"; then
89            makeinfo_version_minor=0
90          fi
91        fi
92      fi
93    fi
94    makeinfo_version_numeric=`expr $makeinfo_version_major '*' 1000 \
95                                   '+' $makeinfo_version_minor`
96    if test $makeinfo_version_numeric -lt 4008; then
97      missing="\`makeinfo' is too old."
98    fi
100    if test -n "$missing"; then
101      if test ! -f doc/groff.info \
102         || test ${srcdir}/doc/groff.texinfo -nt doc/groff.info; then
103        AC_MSG_ERROR($missing
104 [Get the `texinfo' package version 4.8 or newer.])
105      else
106        AC_MSG_WARN($missing
107 [Get the `texinfo' package version 4.8 or newer if you want to convert
108 `groff.texinfo' into a PDF or HTML document.])
109      fi
110    fi
111    AC_SUBST([MAKEINFO])])
113 # The following programs are needed for grohtml.
115 AC_DEFUN([GROFF_HTML_PROGRAMS],
116   [AC_REQUIRE([GROFF_GHOSTSCRIPT_PATH])
117    make_html=html
118    make_install_html=install_html
120    missing=
121    AC_FOREACH([groff_prog],
122      [pnmcut pnmcrop pnmtopng psselect pnmtops],
123      [AC_CHECK_PROG(groff_prog, groff_prog, [found], [missing])
124       if test $[]groff_prog = missing; then
125         missing="$missing \`groff_prog'"
126       fi;])
128    test "$GHOSTSCRIPT" = "missing" && missing="$missing \`gs'"
130    if test -n "$missing"; then
131      plural=`set $missing; test $[#] -gt 1 && echo s`
132      missing=`set $missing
133        missing=""
134        while test $[#] -gt 0
135          do
136            case $[#] in
137              1) missing="$missing$[1]" ;;
138              2) missing="$missing$[1] and " ;;
139              *) missing="$missing$[1], " ;;
140            esac
141            shift
142          done
143          echo $missing`
145      make_html=
146      make_install_html=
148      AC_MSG_WARN([missing program$plural:
150   The program$plural
151      $missing
152   cannot be found in the PATH.
153   Consequently, groff's HTML backend (grohtml) will not work properly;
154   therefore, it will neither be possible to prepare, nor to install,
155   documentation in HTML format.
156      ])
157    fi
159    AC_SUBST([make_html])
160    AC_SUBST([make_install_html])])
162 # To produce PDF docs, we need both awk and ghostscript.
164 AC_DEFUN([GROFF_PDFDOC_PROGRAMS],
165   [AC_REQUIRE([GROFF_AWK_PATH])
166    AC_REQUIRE([GROFF_GHOSTSCRIPT_PATH])
168    make_pdfdoc=pdfdoc
169    make_install_pdfdoc=install_pdfdoc
171    missing=""
172    test "$AWK" = missing && missing="\`awk'"
173    test "$GHOSTSCRIPT" = missing && missing="$missing \`gs'"
174    if test -n "$missing"; then
175      plural=`set $missing; test $[#] -eq 2 && echo s`
176      test x$plural = xs \
177        && missing=`set $missing; echo "$[1] and $[2]"` \
178        || missing=`echo $missing`
180      make_pdfdoc=
181      make_install_pdfdoc=
183      AC_MSG_WARN([missing program$plural:
185   The program$plural $missing cannot be found in the PATH.
186   Consequently, groff's PDF formatter (pdfroff) will not work properly;
187   therefore, it will neither be possible to prepare, nor to install,
188   documentation in PDF format.
189      ])
190    fi
192    AC_SUBST([make_pdfdoc])
193    AC_SUBST([make_install_pdfdoc])])
195 # Check whether pnmtops can handle the -nosetpage option.
197 AC_DEFUN([GROFF_PNMTOPS_NOSETPAGE],
198   [AC_MSG_CHECKING([whether pnmtops can handle the -nosetpage option])
199    if echo P2 2 2 255 0 1 2 0 | pnmtops -nosetpage > /dev/null 2>&1 ; then
200      AC_MSG_RESULT([yes])
201      pnmtops_nosetpage="pnmtops -nosetpage"
202    else
203      AC_MSG_RESULT([no])
204      pnmtops_nosetpage="pnmtops"
205    fi
206    AC_SUBST([pnmtops_nosetpage])])
208 # Check location of `gs'; allow `--with-gs=PROG' option to override.
210 AC_DEFUN([GROFF_GHOSTSCRIPT_PATH],
211   [AC_REQUIRE([GROFF_GHOSTSCRIPT_PREFS])
212    AC_ARG_WITH([gs],
213      [AS_HELP_STRING([--with-gs=PROG],
214        [actual [/path/]name of ghostscript executable])],
215      [GHOSTSCRIPT=$withval],
216      [AC_CHECK_TOOLS(GHOSTSCRIPT, [$ALT_GHOSTSCRIPT_PROGS], [missing])])
217    test "$GHOSTSCRIPT" = "no" && GHOSTSCRIPT=missing])
219 # Preferences for choice of `gs' program...
220 # (allow --with-alt-gs="LIST" to override).
222 AC_DEFUN([GROFF_GHOSTSCRIPT_PREFS],
223   [AC_ARG_WITH([alt-gs],
224     [AS_HELP_STRING([--with-alt-gs=LIST],
225       [alternative names for ghostscript executable])],
226     [ALT_GHOSTSCRIPT_PROGS="$withval"],
227     [ALT_GHOSTSCRIPT_PROGS="gs gswin32c gsos2"])
228    AC_SUBST([ALT_GHOSTSCRIPT_PROGS])])
230 # Check location of `awk'; allow `--with-awk=PROG' option to override.
232 AC_DEFUN([GROFF_AWK_PATH],
233   [AC_REQUIRE([GROFF_AWK_PREFS])
234    AC_ARG_WITH([awk],
235      [AS_HELP_STRING([--with-awk=PROG],
236        [actual [/path/]name of awk executable])],
237      [AWK=$withval],
238      [AC_CHECK_TOOLS(AWK, [$ALT_AWK_PROGS], [missing])])
239    test "$AWK" = "no" && AWK=missing])
241 # Preferences for choice of `awk' program; allow --with-alt-awk="LIST"
242 # to override.
244 AC_DEFUN([GROFF_AWK_PREFS],
245   [AC_ARG_WITH([alt-awk],
246     [AS_HELP_STRING([--with-alt-awk=LIST],
247       [alternative names for awk executable])],
248     [ALT_AWK_PROGS="$withval"],
249     [ALT_AWK_PROGS="gawk mawk nawk awk"])
250    AC_SUBST([ALT_AWK_PROGS])])
252 # GROFF_CSH_HACK(if hack present, if not present)
254 AC_DEFUN([GROFF_CSH_HACK],
255   [AC_MSG_CHECKING([for csh hash hack])
257 cat <<EOF >conftest.sh
258 #! /bin/sh
259 true || exit 0
260 export PATH || exit 0
261 exit 1
264    chmod +x conftest.sh
265    if echo ./conftest.sh | (csh >/dev/null 2>&1) >/dev/null 2>&1; then
266      AC_MSG_RESULT([yes])
267      $1
268    else
269      AC_MSG_RESULT([no])
270      $2
271    fi
272    rm -f conftest.sh])
274 # From udodo!hans@relay.NL.net (Hans Zuidam)
276 AC_DEFUN([GROFF_ISC_SYSV3],
277   [AC_MSG_CHECKING([for ISC 3.x or 4.x])
278    if grep ['[34]\.'] /usr/options/cb.name >/dev/null 2>&1
279    then
280      AC_MSG_RESULT([yes])
281      AC_DEFINE([_SYSV3], [1], [Define if you have ISC 3.x or 4.x.])
282    else
283      AC_MSG_RESULT([no])
284    fi])
286 AC_DEFUN([GROFF_POSIX],
287   [AC_MSG_CHECKING([whether -D_POSIX_SOURCE is necessary])
288    AC_LANG_PUSH([C++])
289    AC_COMPILE_IFELSE([
290        AC_LANG_PROGRAM([[
292 #include <stdio.h>
293 extern "C" { void fileno(int); }
295        ]])
296      ],
297      [AC_MSG_RESULT([yes])
298       AC_DEFINE([_POSIX_SOURCE], [1],
299         [Define if -D_POSIX_SOURCE is necessary.])],
300      [AC_MSG_RESULT([no])])
301    AC_LANG_POP([C++])])
303 # srand() of SunOS 4.1.3 has return type int instead of void
305 AC_DEFUN([GROFF_SRAND],
306   [AC_LANG_PUSH([C++])
307    AC_MSG_CHECKING([for return type of srand])
308    AC_COMPILE_IFELSE([
309        AC_LANG_PROGRAM([[
311 #include <stdlib.h>
312 extern "C" { void srand(unsigned int); }
314        ]])
315      ],
316      [AC_MSG_RESULT([void])
317       AC_DEFINE([RET_TYPE_SRAND_IS_VOID], [1],
318         [Define if srand() returns void not int.])],
319      [AC_MSG_RESULT([int])])
320    AC_LANG_POP([C++])])
322 # In April 2005, autoconf's AC_TYPE_SIGNAL is still broken.
324 AC_DEFUN([GROFF_TYPE_SIGNAL],
325   [AC_MSG_CHECKING([for return type of signal handlers])
326    for groff_declaration in \
327      'extern "C" void (*signal (int, void (*)(int)))(int);' \
328      'extern "C" void (*signal (int, void (*)(int)) throw ())(int);' \
329      'void (*signal ()) ();' 
330    do
331      AC_COMPILE_IFELSE([
332          AC_LANG_PROGRAM([[
334 #include <sys/types.h>
335 #include <signal.h>
336 #ifdef signal
337 # undef signal
338 #endif
339 $groff_declaration
341          ]],
342          [[
344 int i;
346          ]])
347        ],
348        [break],
349        [continue])
350    done
352    if test -n "$groff_declaration"; then
353      AC_MSG_RESULT([void])
354      AC_DEFINE([RETSIGTYPE], [void],
355        [Define as the return type of signal handlers
356         (`int' or `void').])
357    else
358      AC_MSG_RESULT([int])
359      AC_DEFINE([RETSIGTYPE], [int],
360        [Define as the return type of signal handlers
361         (`int' or `void').])
362    fi])
364 AC_DEFUN([GROFF_SYS_NERR],
365   [AC_LANG_PUSH([C++])
366    AC_MSG_CHECKING([for sys_nerr in <errno.h>, <stdio.h>, or <stdlib.h>])
367    AC_COMPILE_IFELSE([
368        AC_LANG_PROGRAM([[
370 #include <errno.h>
371 #include <stdio.h>
372 #include <stdlib.h>
374        ]],
375        [[
377 int k;
378 k = sys_nerr;
380        ]])
381      ],
382      [AC_MSG_RESULT([yes])
383       AC_DEFINE([HAVE_SYS_NERR], [1],
384         [Define if you have sys_nerr in <errno.h>, <stdio.h>, or <stdio.h>.])],
385      [AC_MSG_RESULT([no])])
386    AC_LANG_POP([C++])])
388 AC_DEFUN([GROFF_SYS_ERRLIST],
389   [AC_MSG_CHECKING([for sys_errlist[] in <errno.h>, <stdio.h>, or <stdlib.h>])
390    AC_COMPILE_IFELSE([
391        AC_LANG_PROGRAM([[
393 #include <errno.h>
394 #include <stdio.h>
395 #include <stdlib.h>
397        ]],
398        [[
400 int k;
401 k = (int)sys_errlist[0];
403        ]])
404      ],
405      [AC_MSG_RESULT([yes])
406       AC_DEFINE([HAVE_SYS_ERRLIST], [1],
407         [Define if you have sys_errlist in <errno.h>, <stdio.h>, or <stdlib.h>.])],
408      [AC_MSG_RESULT([no])])])
410 AC_DEFUN([GROFF_OSFCN_H],
411   [AC_LANG_PUSH([C++])
412    AC_MSG_CHECKING([C++ <osfcn.h>])
413    AC_COMPILE_IFELSE([
414        AC_LANG_PROGRAM([[
416 #include <osfcn.h>
418        ]],
419        [[
421 read(0, 0, 0);
422 open(0, 0);
424        ]])
425      ],
426      [AC_MSG_RESULT([yes])
427       AC_DEFINE([HAVE_CC_OSFCN_H], [1],
428         [Define if you have a C++ <osfcn.h>.])],
429      [AC_MSG_RESULT([no])])
430    AC_LANG_POP([C++])])
432 AC_DEFUN([GROFF_LIMITS_H],
433   [AC_LANG_PUSH([C++])
434    AC_MSG_CHECKING([C++ <limits.h>])
435    AC_COMPILE_IFELSE([
436        AC_LANG_PROGRAM([[
438 #include <limits.h>
440        ]],
441        [[
443 int x = INT_MIN;
444 int y = INT_MAX;
445 int z = UCHAR_MAX;
447        ]])
448      ],
449      [AC_MSG_RESULT([yes])
450       AC_DEFINE([HAVE_CC_LIMITS_H], [1],
451         [Define if you have a C++ <limits.h>.])],
452      [AC_MSG_RESULT([no])])
453    AC_LANG_POP([C++])])
455 AC_DEFUN([GROFF_TIME_T],
456   [AC_LANG_PUSH([C++])
457    AC_MSG_CHECKING([for declaration of time_t])
458    AC_COMPILE_IFELSE([
459        AC_LANG_PROGRAM([[
461 #include <time.h>
463        ]],
464        [[
466 time_t t = time(0);
467 struct tm *p = localtime(&t);
469        ]])
470      ],
471      [AC_MSG_RESULT([yes])],
472      [AC_MSG_RESULT([no])
473       AC_DEFINE([LONG_FOR_TIME_T], [1],
474         [Define if localtime() takes a long * not a time_t *.])])
475    AC_LANG_POP([C++])])
477 AC_DEFUN([GROFF_STRUCT_EXCEPTION],
478   [AC_MSG_CHECKING([struct exception])
479    AC_COMPILE_IFELSE([
480        AC_LANG_PROGRAM([[
482 #include <math.h>
484        ]],
485        [[
487 struct exception e;
489        ]])
490      ],
491      [AC_MSG_RESULT([yes])
492       AC_DEFINE([HAVE_STRUCT_EXCEPTION], [1],
493         [Define if <math.h> defines struct exception.])],
494      [AC_MSG_RESULT([no])])])
496 AC_DEFUN([GROFF_ARRAY_DELETE],
497   [AC_LANG_PUSH([C++])
498    AC_MSG_CHECKING([whether ANSI array delete syntax is supported])
499    AC_COMPILE_IFELSE([
500        AC_LANG_PROGRAM(, [[
502 char *p = new char[5];
503 delete [] p;
505        ]])
506      ],
507      [AC_MSG_RESULT([yes])],
508      [AC_MSG_RESULT([no])
509       AC_DEFINE([ARRAY_DELETE_NEEDS_SIZE], [1],
510         [Define if your C++ doesn't understand `delete []'.])])
511    AC_LANG_POP([C++])])
513 AC_DEFUN([GROFF_TRADITIONAL_CPP],
514   [AC_LANG_PUSH([C++])
515    AC_MSG_CHECKING([traditional preprocessor])
516    AC_COMPILE_IFELSE([
517        AC_LANG_PROGRAM([[
519 #define name2(a, b) a/**/b
521        ]],
522        [[
524 int name2(foo, bar);
526        ]])
527      ],
528      [AC_MSG_RESULT([yes])
529       AC_DEFINE([TRADITIONAL_CPP], [1],
530         [Define if your C++ compiler uses a traditional (Reiser) preprocessor.])],
531      [AC_MSG_RESULT([no])])
532    AC_LANG_POP([C++])])
534 AC_DEFUN([GROFF_WCOREFLAG],
535   [AC_MSG_CHECKING([w_coredump])
536    AC_RUN_IFELSE([
537        AC_LANG_PROGRAM([[
539 #include <sys/types.h>
540 #include <sys/wait.h>
542        ]],
543        [[
545 main()
547 #ifdef WCOREFLAG
548   exit(1);
549 #else
550   int i = 0;
551   ((union wait *)&i)->w_coredump = 1;
552   exit(i != 0200);
553 #endif
556        ]])
557      ],
558      [AC_MSG_RESULT([yes])
559       AC_DEFINE(WCOREFLAG, 0200,
560         [Define if the 0200 bit of the status returned by wait() indicates
561          whether a core image was produced for a process that was terminated
562          by a signal.])],
563      [AC_MSG_RESULT([no])],
564      [AC_MSG_RESULT([no])])])
566 AC_DEFUN([GROFF_BROKEN_SPOOLER_FLAGS],
567   [AC_MSG_CHECKING([default value for grops -b option])
568    test -n "${BROKEN_SPOOLER_FLAGS}" || BROKEN_SPOOLER_FLAGS=0
569    AC_MSG_RESULT([$BROKEN_SPOOLER_FLAGS])
570    AC_SUBST([BROKEN_SPOOLER_FLAGS])])
572 AC_DEFUN([GROFF_PAGE],
573   [AC_MSG_CHECKING([default paper size])
574    groff_prefix=$prefix
575    test "x$prefix" = "xNONE" && groff_prefix=$ac_default_prefix
576    if test -z "$PAGE"; then
577      descfile=
578      if test -r $groff_prefix/share/groff/font/devps/DESC; then
579        descfile=$groff_prefix/share/groff/font/devps/DESC
580      elif test -r $groff_prefix/lib/groff/font/devps/DESC; then
581        descfile=$groff_prefix/lib/groff/font/devps/DESC
582      else
583        for f in $groff_prefix/share/groff/*/font/devps/DESC; do
584          if test -r $f; then
585            descfile=$f
586            break
587          fi
588        done
589      fi
591      if test -n "$descfile"; then
592        if grep ['^paperlength[   ]\+841890'] $descfile >/dev/null 2>&1; then
593          PAGE=A4
594        elif grep ['^papersize[   ]\+[aA]4'] $descfile >/dev/null 2>&1; then
595          PAGE=A4
596        fi
597      fi
598    fi
600    if test -z "$PAGE"; then
601      dom=`awk '([$]1 == "dom" || [$]1 == "search") { print [$]2; exit}' \
602          /etc/resolv.conf 2>/dev/null`
603      if test -z "$dom"; then
604        dom=`(domainname) 2>/dev/null | tr -d '+'`
605        if test -z "$dom" \
606           || test "$dom" = '(none)'; then
607          dom=`(hostname) 2>/dev/null | grep '\.'`
608        fi
609      fi
610      # If the top-level domain is two letters and it's not `us' or `ca'
611      # then they probably use A4 paper.
612      case "$dom" in
613      [*.[Uu][Ss]|*.[Cc][Aa])]
614        ;;
615      [*.[A-Za-z][A-Za-z])]
616        PAGE=A4 ;;
617      esac
618    fi
620    test -n "$PAGE" || PAGE=letter
621    if test "x$PAGE" = "xA4"; then
622      AC_DEFINE([PAGEA4], [1],
623        [Define if the printer's page size is A4.])
624    fi
625    AC_MSG_RESULT([$PAGE])
626    AC_SUBST([PAGE])])
628 AC_DEFUN([GROFF_CXX_CHECK],
629   [AC_REQUIRE([AC_PROG_CXX])
630    AC_LANG_PUSH([C++])
631    if test "$cross_compiling" = no; then
632      AC_MSG_CHECKING([that C++ compiler can compile simple program])
633    fi
634    AC_RUN_IFELSE([
635        AC_LANG_SOURCE([[
637 int main() {
638   return 0;
641        ]])
642      ],
643      [AC_MSG_RESULT([yes])],
644      [AC_MSG_RESULT([no])
645       AC_MSG_ERROR([a working C++ compiler is required])],
646      [:])
648    if test "$cross_compiling" = no; then
649      AC_MSG_CHECKING([that C++ static constructors and destructors are called])
650    fi
651    AC_RUN_IFELSE([
652        AC_LANG_SOURCE([[
654 extern "C" {
655   void _exit(int);
658 int i;
659 struct A {
660   char dummy;
661   A() { i = 1; }
662   ~A() { if (i == 1) _exit(0); }
665 A a;
667 int main()
669   return 1;
672        ]])
673      ],
674      [AC_MSG_RESULT([yes])],
675      [AC_MSG_RESULT([no])
676       AC_MSG_ERROR([a working C++ compiler is required])],
677      [:])
679    AC_MSG_CHECKING([that header files support C++])
680    AC_LINK_IFELSE([
681        AC_LANG_PROGRAM([[
683 #include <stdio.h>
685        ]],
686        [[
688 fopen(0, 0);
690        ]])
691      ],
692      [AC_MSG_RESULT([yes])],
693      [AC_MSG_RESULT([no])
694       AC_MSG_ERROR([header files do not support C++
695                    (if you are using a version of gcc/g++ earlier than 2.5,
696                    you should install libg++)])])
697    AC_LANG_POP([C++])])
699 AC_DEFUN([GROFF_TMAC],
700   [AC_MSG_CHECKING([for prefix of system macro packages])
701    sys_tmac_prefix=
702    sys_tmac_file_prefix=
703    for d in /usr/share/lib/tmac /usr/lib/tmac; do
704      for t in "" tmac.; do
705        for m in an s m; do
706          f=$d/$t$m
707          if test -z "$sys_tmac_prefix" \
708             && test -f $f \
709             && grep '^\.if' $f >/dev/null 2>&1; then
710            sys_tmac_prefix=$d/$t
711            sys_tmac_file_prefix=$t
712          fi
713        done
714      done
715    done
716    AC_MSG_RESULT([$sys_tmac_prefix])
717    AC_SUBST([sys_tmac_prefix])
719    AC_MSG_CHECKING([which system macro packages should be made available])
720    tmac_wrap=
721    if test "x$sys_tmac_file_prefix" = "xtmac."; then
722      for f in $sys_tmac_prefix*; do
723        suff=`echo $f | sed -e "s;$sys_tmac_prefix;;"`
724        case "$suff" in
725        e)
726          ;;
727        *)
728          grep "Copyright.*Free Software Foundation" $f >/dev/null \
729               || tmac_wrap="$tmac_wrap $suff" ;;
730        esac
731      done
732    elif test -n "$sys_tmac_prefix"; then
733      files=`echo $sys_tmac_prefix*`
734      grep "\\.so" $files >conftest.sol
735      for f in $files; do
736        case "$f" in
737        ${sys_tmac_prefix}e)
738          ;;
739        *.me)
740          ;;
741        */ms.*)
742          ;;
743        *)
744          b=`basename $f`
745          if grep "\\.so.*/$b\$" conftest.sol >/dev/null \
746             || grep -l "Copyright.*Free Software Foundation" $f >/dev/null; then
747            :
748          else
749            suff=`echo $f | sed -e "s;$sys_tmac_prefix;;"`
750            case "$suff" in
751            tmac.*)
752              ;;
753            *)
754              tmac_wrap="$tmac_wrap $suff" ;;
755            esac
756          fi
757        esac
758      done
759      rm -f conftest.sol
760    fi
761    AC_MSG_RESULT([$tmac_wrap])
762    AC_SUBST([tmac_wrap])])
764 AC_DEFUN([GROFF_G],
765   [AC_MSG_CHECKING([for existing troff installation])
766    if test "x`(echo .tm '|n(.g' | tr '|' '\\\\' | troff -z -i 2>&1) 2>/dev/null`" = x0; then
767      AC_MSG_RESULT([yes])
768      g=g
769    else
770      AC_MSG_RESULT([no])
771      g=
772    fi
773    AC_SUBST([g])])
775 # We need the path to install-sh to be absolute.
777 AC_DEFUN([GROFF_INSTALL_SH],
778   [AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT])
779    ac_dir=`cd $ac_aux_dir; pwd`
780    ac_install_sh="$ac_dir/install-sh -c"])
782 # Test whether install-info is available.
784 AC_DEFUN([GROFF_INSTALL_INFO],
785   [AC_CHECK_PROGS([INSTALL_INFO], [install-info], [:])])
787 # At least one UNIX system, Apple Macintosh Rhapsody 5.5,
788 # does not have -lm ...
790 AC_DEFUN([GROFF_LIBM],
791   [AC_CHECK_LIB([m], [sin], [LIBM=-lm])
792    AC_SUBST([LIBM])])
794 # ... while the MinGW implementation of GCC for Microsoft Win32
795 # does not seem to have -lc.
797 AC_DEFUN([GROFF_LIBC],
798   [AC_CHECK_LIB([c], [main], [LIBC=-lc])
799    AC_SUBST([LIBC])])
801 # Check for EBCDIC -- stolen from the OS390 Unix LYNX port
803 AC_DEFUN([GROFF_EBCDIC],
804   [AC_MSG_CHECKING([whether character set is EBCDIC])
805    AC_COMPILE_IFELSE([
806        AC_LANG_PROGRAM([[
808 /* Treat any failure as ASCII for compatibility with existing art.
809    Use compile-time rather than run-time tests for cross-compiler
810    tolerance. */
811 #if '0' != 240
812 make an error "Character set is not EBCDIC"
813 #endif
815        ]])
816      ],
817      [groff_cv_ebcdic="yes"
818       TTYDEVDIRS="font/devcp1047"
819       AC_MSG_RESULT([yes])
820       AC_DEFINE(IS_EBCDIC_HOST, 1,
821         [Define if the host's encoding is EBCDIC.])],
822      [groff_cv_ebcdic="no"
823      TTYDEVDIRS="font/devascii font/devlatin1"
824      OTHERDEVDIRS="font/devlj4 font/devlbp"
825      AC_MSG_RESULT([no])])
826    AC_SUBST([TTYDEVDIRS])
827    AC_SUBST([OTHERDEVDIRS])])
829 # Check for OS/390 Unix.  We test for EBCDIC also -- the Linux port (with
830 # gcc) to OS/390 uses ASCII internally.
832 AC_DEFUN([GROFF_OS390],
833   [if test "$groff_cv_ebcdic" = "yes"; then
834      AC_MSG_CHECKING([for OS/390 Unix])
835      case `uname` in
836      OS/390)
837        CFLAGS="$CFLAGS -D_ALL_SOURCE"
838        AC_MSG_RESULT([yes]) ;;
839      *)
840        AC_MSG_RESULT([no]) ;;
841      esac
842    fi])
844 # Check whether we need a declaration for a function.
846 # Stolen from GNU bfd.
848 AC_DEFUN([GROFF_NEED_DECLARATION],
849   [AC_MSG_CHECKING([whether $1 must be declared])
850    AC_LANG_PUSH([C++])
851    AC_CACHE_VAL([groff_cv_decl_needed_$1],
852      [AC_COMPILE_IFELSE([
853           AC_LANG_PROGRAM([[
855 #include <stdio.h>
856 #ifdef HAVE_STRING_H
857 #include <string.h>
858 #endif
859 #ifdef HAVE_STRINGS_H
860 #include <strings.h>
861 #endif
862 #ifdef HAVE_STDLIB_H
863 #include <stdlib.h>
864 #endif
865 #ifdef HAVE_SYS_TIME_H
866 #include <sys/time.h>
867 #endif
868 #ifdef HAVE_UNISTD_H
869 #include <unistd.h>
870 #endif
871 #ifdef HAVE_MATH_H
872 #include <math.h>
873 #endif
875           ]],
876           [[
878 #ifndef $1
879   char *p = (char *) $1;
880 #endif
882           ]])
883       ],
884       [groff_cv_decl_needed_$1=no],
885       [groff_cv_decl_needed_$1=yes])])
886    AC_MSG_RESULT([$groff_cv_decl_needed_$1])
887    if test $groff_cv_decl_needed_$1 = yes; then
888      AC_DEFINE([NEED_DECLARATION_]translit($1, [a-z], [A-Z]), [1],
889        [Define if your C++ doesn't declare ]$1[().])
890    fi
891    AC_LANG_POP([C++])])
893 # If mkstemp() isn't available, use our own mkstemp.cpp file.
895 AC_DEFUN([GROFF_MKSTEMP],
896   [AC_MSG_CHECKING([for mkstemp])
897    AC_LANG_PUSH([C++])
898    AC_LIBSOURCE([mkstemp.cpp])
899    AC_LINK_IFELSE([
900        AC_LANG_PROGRAM([[
902 #include <stdlib.h>
903 #include <unistd.h>
904 int (*f) (char *);
906        ]],
907        [[
909 f = mkstemp;
911        ]])
912      ],
913      [AC_MSG_RESULT([yes])
914       AC_DEFINE([HAVE_MKSTEMP], [1], [Define if you have mkstemp().])],
915      [AC_MSG_RESULT([no])
916       _AC_LIBOBJ([mkstemp])])
917    AC_LANG_POP([C++])])
919 # Test whether <inttypes.h> exists, doesn't clash with <sys/types.h>,
920 # and declares uintmax_t.  Taken from the fileutils package.
922 AC_DEFUN([GROFF_INTTYPES_H],
923   [AC_LANG_PUSH([C++])
924    AC_MSG_CHECKING([C++ <inttypes.h>])
925    AC_COMPILE_IFELSE([
926        AC_LANG_PROGRAM([[
928 #include <sys/types.h>
929 #include <inttypes.h>
931        ]],
932        [[
934 uintmax_t i = (uintmax_t)-1;
936        ]])
937      ],
938      [groff_cv_header_inttypes_h=yes
939       AC_DEFINE([HAVE_CC_INTTYPES_H], [1],
940         [Define if you have a C++ <inttypes.h>.])],
941      [groff_cv_header_inttypes_h=no])
942    AC_MSG_RESULT([$groff_cv_header_inttypes_h])
943    AC_LANG_POP([C++])])
945 # Test for working `unsigned long long'.  Taken from the fileutils package.
947 AC_DEFUN([GROFF_UNSIGNED_LONG_LONG],
948   [AC_LANG_PUSH([C++])
949    AC_MSG_CHECKING([for unsigned long long])
950    AC_LINK_IFELSE([
951        AC_LANG_PROGRAM([[
953 unsigned long long ull = 1;
954 int i = 63;
955 unsigned long long ullmax = (unsigned long long)-1;
957        ]],
958        [[
960 return ull << i | ull >> i | ullmax / ull | ullmax % ull;
962        ]])
963      ],
964      [groff_cv_type_unsigned_long_long=yes],
965      [groff_cv_type_unsigned_long_long=no])
966    AC_MSG_RESULT([$groff_cv_type_unsigned_long_long])
967    AC_LANG_POP([C++])])
969 # Define uintmax_t to `unsigned long' or `unsigned long long'
970 # if <inttypes.h> does not exist.  Taken from the fileutils package.
972 AC_DEFUN([GROFF_UINTMAX_T],
973   [AC_REQUIRE([GROFF_INTTYPES_H])
974    if test $groff_cv_header_inttypes_h = no; then
975      AC_REQUIRE([GROFF_UNSIGNED_LONG_LONG])
976      test $groff_cv_type_unsigned_long_long = yes \
977           && ac_type='unsigned long long' \
978           || ac_type='unsigned long'
979      AC_DEFINE_UNQUOTED([uintmax_t], [$ac_type],
980        [Define uintmax_t to `unsigned long' or `unsigned long long' if
981         <inttypes.h> does not exist.])
982    fi])
984 # Identify PATH_SEPARATOR character to use in GROFF_FONT_PATH and
985 # GROFF_TMAC_PATH which is appropriate for the target system (POSIX=':',
986 # MS-DOS/Win32=';').
988 # The logic to resolve this test is already encapsulated in
989 # `${srcdir}/src/include/nonposix.h'.
991 AC_DEFUN([GROFF_TARGET_PATH_SEPARATOR],
992   [AC_MSG_CHECKING([separator character to use in groff search paths])
993    cp ${srcdir}/src/include/nonposix.h conftest.h
994    AC_COMPILE_IFELSE([
995        AC_LANG_PROGRAM([[
996         
997 #include <ctype.h>
998 #include "conftest.h"
1000        ]],
1001        [[
1003 #if PATH_SEP_CHAR == ';'
1004 make an error "Path separator is ';'"
1005 #endif
1007        ]])
1008      ],
1009      [GROFF_PATH_SEPARATOR=":"],
1010      [GROFF_PATH_SEPARATOR=";"])
1011    AC_MSG_RESULT([$GROFF_PATH_SEPARATOR])
1012    AC_SUBST(GROFF_PATH_SEPARATOR)])
1014 # Check for X11.
1016 AC_DEFUN([GROFF_X11],
1017   [AC_REQUIRE([AC_PATH_XTRA])
1018    groff_no_x=$no_x
1019    if test -z "$groff_no_x"; then
1020      OLDCFLAGS=$CFLAGS
1021      OLDLDFLAGS=$LDFLAGS
1022      OLDLIBS=$LIBS
1023      CFLAGS="$CFLAGS $X_CFLAGS"
1024      LDFLAGS="$LDFLAGS $X_LIBS"
1025      LIBS="$LIBS $X_PRE_LIBS -lX11 $X_EXTRA_LIBS"
1027      LIBS="$LIBS -lXaw"
1028      AC_MSG_CHECKING([for Xaw library and header files])
1029      AC_LINK_IFELSE([
1030          AC_LANG_PROGRAM([[
1032 #include <X11/Intrinsic.h>
1033 #include <X11/Xaw/Simple.h>
1035          ]],
1036          [])
1037        ],
1038        [AC_MSG_RESULT([yes])],
1039        [AC_MSG_RESULT([no])
1040         groff_no_x="yes"])
1042      LIBS="$LIBS -lXmu"
1043      AC_MSG_CHECKING([for Xmu library and header files])
1044      AC_LINK_IFELSE([
1045          AC_LANG_PROGRAM([[
1047 #include <X11/Intrinsic.h>
1048 #include <X11/Xmu/Converters.h>
1050          ]],
1051          [])
1052        ],
1053        [AC_MSG_RESULT([yes])],
1054        [AC_MSG_RESULT([no])
1055         groff_no_x="yes"])
1057      CFLAGS=$OLDCFLAGS
1058      LDFLAGS=$OLDLDFLAGS
1059      LIBS=$OLDLIBS
1060    fi
1062    if test "x$groff_no_x" = "xyes"; then
1063      AC_MSG_NOTICE([gxditview and xtotroff won't be built])
1064    else
1065      XDEVDIRS="font/devX75 font/devX75-12 font/devX100 font/devX100-12"
1066      XPROGDIRS="src/devices/xditview src/utils/xtotroff"
1067      XLIBDIRS="src/libs/libxutil"
1068    fi
1070    AC_SUBST([XDEVDIRS])
1071    AC_SUBST([XPROGDIRS])
1072    AC_SUBST([XLIBDIRS])])
1074 # Set up the `--with-appresdir' command line option.
1076 AC_DEFUN([GROFF_APPRESDIR_OPTION],
1077   [AC_ARG_WITH([appresdir],
1078      dnl Don't quote AS_HELP_STRING!
1079      AS_HELP_STRING([--with-appresdir=DIR],
1080                     [X11 application resource files]))])
1082 # Get a default value for the application resource directory.
1084 # We ignore the `XAPPLRES' and `XUSERFILESEARCHPATH' environment variables.
1086 # The goal is to find the `root' of X11.  Under most systems this is
1087 # `/usr/X11/lib'.  Application default files are then in
1088 # `/usr/X11/lib/X11/app-defaults'.
1090 # Based on autoconf's AC_PATH_X macro.
1092 AC_DEFUN([GROFF_APPRESDIR_DEFAULT],
1093   [if test -z "$groff_no_x"; then
1094      # Create an Imakefile, run `xmkmf', then `make'.
1095      rm -f -r conftest.dir
1096      if mkdir conftest.dir; then
1097        cd conftest.dir
1098        # Make sure to not put `make' in the Imakefile rules,
1099        # since we grep it out.
1100        cat >Imakefile <<'EOF'
1102 xlibdirs:
1103         @echo 'groff_x_usrlibdir="${USRLIBDIR}"; groff_x_libdir="${LIBDIR}"'
1106        if (xmkmf) >/dev/null 2>/dev/null && test -f Makefile; then
1107          # GNU make sometimes prints "make[1]: Entering...",
1108          # which would confuse us.
1109          eval `${MAKE-make} xlibdirs 2>/dev/null | grep -v make`
1111          # Open Windows `xmkmf' reportedly sets LIBDIR instead of USRLIBDIR.
1112          for groff_extension in a so sl; do
1113            if test ! -f $groff_x_usrlibdir/libX11.$groff_extension &&
1114               test -f $groff_x_libdir/libX11.$groff_extension; then
1115              groff_x_usrlibdir=$groff_x_libdir
1116              break
1117            fi
1118          done
1119        fi
1121        cd ..
1122        rm -f -r conftest.dir
1123      fi
1125      # In case the test with `xmkmf' wasn't successful, try a suite of
1126      # standard directories.  Check `X11' before `X11Rn' because it is often
1127      # a symlink to the current release.
1128      groff_x_libdirs='
1129        /usr/X11/lib
1130        /usr/X11R6/lib
1131        /usr/X11R5/lib
1132        /usr/X11R4/lib
1134        /usr/lib/X11
1135        /usr/lib/X11R6
1136        /usr/lib/X11R5
1137        /usr/lib/X11R4
1139        /usr/local/X11/lib
1140        /usr/local/X11R6/lib
1141        /usr/local/X11R5/lib
1142        /usr/local/X11R4/lib
1144        /usr/local/lib/X11
1145        /usr/local/lib/X11R6
1146        /usr/local/lib/X11R5
1147        /usr/local/lib/X11R4
1149        /usr/X386/lib
1150        /usr/x386/lib
1151        /usr/XFree86/lib/X11
1153        /usr/lib
1154        /usr/local/lib
1155        /usr/unsupported/lib
1156        /usr/athena/lib
1157        /usr/local/x11r5/lib
1158        /usr/lpp/Xamples/lib
1160        /usr/openwin/lib
1161        /usr/openwin/share/lib'
1163      if test -z "$groff_x_usrlibdir"; then
1164        # We only test whether libX11 exists.
1165        for groff_dir in $groff_x_libdirs; do
1166          for groff_extension in a so sl; do
1167            if test ! -r $groff_dir/libX11.$groff_extension; then
1168              groff_x_usrlibdir=$groff_dir
1169              break 2
1170            fi
1171          done
1172        done
1173      fi
1175      if test "x$with_appresdir" = "x"; then
1176        appresdir=$groff_x_usrlibdir/X11/app-defaults
1177      else
1178        appresdir=$with_appresdir
1179      fi
1180    fi
1181    AC_SUBST([appresdir])])
1184 # Emit warning if --with-appresdir hasn't been used.
1186 AC_DEFUN([GROFF_APPRESDIR_CHECK],
1187   [if test -z "$groff_no_x"; then
1188      if test "x$with_appresdir" = "x"; then
1189        AC_MSG_NOTICE([
1191   The application resource file for gxditview will be installed as
1193     $appresdir/GXditview
1195   (an existing file will be saved as `GXditview.old').
1196   To install it into a different directory, say, `/etc/gxditview',
1197   add `--with-appresdir=/etc/gxditview' to the configure script
1198   command line options and rerun it.  The environment variable
1199   `APPLRESDIR' must then be set to `/etc/' (note the trailing slash),
1200   omitting the `gxditview' part which is automatically appended by
1201   the X11 searching routines for resource files.  More details can be
1202   found in the X(7) manual page.
1203        ])
1204      fi
1205    fi])