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