BSD 4_4_Lite2 development
[unix-history] / usr / src / contrib / groff-1.08 / acgroff.m4
CommitLineData
51524a77
C
1dnl Autoconf macros for groff.
2dnl Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
3dnl
4dnl This file is part of groff.
5dnl
6dnl groff is free software; you can redistribute it and/or modify it under
7dnl the terms of the GNU General Public License as published by the Free
8dnl Software Foundation; either version 2, or (at your option) any later
9dnl version.
10dnl
11dnl groff is distributed in the hope that it will be useful, but WITHOUT ANY
12dnl WARRANTY; without even the implied warranty of MERCHANTABILITY or
13dnl FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14dnl for more details.
15dnl
16dnl You should have received a copy of the GNU General Public License along
17dnl with groff; see the file COPYING. If not, write to the Free Software
18dnl Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
19dnl
20define(GROFF_EXIT,[rm -f conftest* core; exit 1])dnl
21define(GROFF_PREFIX,[AC_PROVIDE([$0])AC_PREFIX(grops)AC_PREFIX(gcc)])dnl
22define(GROFF_PROG_CCC,
23[AC_PROVIDE([$0])AC_REQUIRE([AC_PROG_CC])dnl
24cc_compile='$CCC conftest.cc -o conftest $CCLIBS $LIBS >/dev/null 2>&1'
25AC_SUBST(CCLIBS)
26if test -z "$CCC"; then
27# See whether the C compiler is also a C++ compiler.
28echo checking if C compiler is also a C++ compiler
29cat <<EOF > conftest.cc
30#ifdef __cplusplus
31 yes
32#endif
33EOF
34$CC -E conftest.cc >conftest.out 2>&1
35if egrep yes conftest.out >/dev/null 2>&1; then
36 CCC="$CC"
37fi
38fi
39AC_PROGRAM_CHECK(CCC,g++,g++,)
40AC_PROGRAM_CHECK(CCC,CC,CC,)
41AC_PROGRAM_CHECK(CCC,cc++,cc++,)
42if test -z "$CCC"; then
43cat <<EOM
44This package requires a C++ compiler, but I couldn't find one.
45Set the environment variable CCC to the name of your C++ compiler.
46EOM
47GROFF_EXIT
48fi
49echo checking that C++ compiler can compile very simple C++ program
50GROFF_CC_TEST_PROGRAM([
51extern "C" { void exit(int); }
52int main() { exit(0); }
53],,
54cat <<EOM
55$CCC was unable successfully to compile a very simple C++ program
56(the C++ program was in a file with a suffix of .cc)
57EOM
58GROFF_EXIT
59,)
60echo checking that C++ static constructors and destructors are called
61GROFF_CC_TEST_PROGRAM([
62extern "C" {
63 void exit(int);
64 void _exit(int);
65}
66int i;
67struct A {
68 char dummy;
69 A() { i = 1; }
70 ~A() { if (i == 1) _exit(0); }
71};
72A a;
73main() { exit(1); }
74],,
75cat <<EOM
76$CCC is not installed correctly: static constructors and destructors do not work
77EOM
78GROFF_EXIT
79,)
80GROFF_CC_COMPILE_CHECK([C++ header files],[#include <stdio.h>],
81[fopen(0, 0);],,
82[cat <<\EOF
83Your header files do not appear to support C++.
84I was unable to compile and link a simple C++ program that used a function
85declared in <stdio.h>.
86If you're using gcc/g++, you should install libg++.
87EOF
88GROFF_EXIT])])dnl
89define(GROFF_CC_COMPILE_CHECK,
90[AC_PROVIDE([$0])AC_REQUIRE([GROFF_PROG_CCC])echo checking for $1
91cat <<EOF >conftest.cc
92[$2]
93extern "C" { void exit(int); }
94int main() { exit(0); } void t() { [$3] }
95EOF
96dnl Don't try to run the program, which would prevent cross-configuring.
97if eval $cc_compile; then
98 ifelse([$4], , :, [$4])
99ifelse([$5], , , [else
100 $5
101])dnl
102fi
103rm -f conftest*])dnl
104dnl
105define(GROFF_CC_TEST_PROGRAM,
106[AC_PROVIDE([$0])AC_REQUIRE([GROFF_PROG_CCC])ifelse([$4], , ,
107[AC_REQUIRE([AC_CROSS_CHECK])if $cross_compiling
108then
109 $4
110else
111])dnl
112cat <<EOF > conftest.cc
113[$1]
114EOF
115rm -f conftest
116eval $cc_compile
117if test -s conftest && (./conftest) 2>/dev/null; then
118 ifelse([$2], , :, [$2])
119ifelse([$3], , , [else
120 $3
121])dnl
122fi
123ifelse([$4], , , fi
124)dnl
125rm -f conftest*])dnl
126dnl
127define(GROFF_PAGE,
128[AC_REQUIRE([GROFF_PREFIX])
129if test -z "$PAGE" && test -r $prefix/lib/groff/font/devps/DESC
130then
131 if grep "^paperlength 841890" \
132 $prefix/lib/groff/font/devps/DESC >/dev/null 2>&1
133 then
134 PAGE=A4
135 else
136 PAGE=letter
137 fi
138fi
139if test -z "$PAGE"
140then
141 dom=`awk '([$]1 == "dom" || [$]1 == "search") { print [$]2; exit}' \
142 /etc/resolv.conf 2>/dev/null`
143
144 if test -z "$dom"
145 then
146 dom=`(domainname) 2>/dev/null | tr -d '+'`
147 if test -z "$dom"
148 then
149 dom=`(hostname) 2>/dev/null | grep '\.'`
150 fi
151 fi
152
153changequote(,)dnl
154 # If the top-level domain is two letters and it's not `us' or `ca'
155 # then they probably use A4 paper.
156 case "$dom" in
157 *.[Uu][Ss]|*.[Cc][Aa]) ;;
158 *.[A-Za-z][A-Za-z]) PAGE=A4 ;;
159 esac
160changequote([,])dnl
161fi
162test -n "$PAGE" || PAGE=letter
163echo guessing $PAGE size paper
164AC_SUBST(PAGE)])dnl
165dnl
166define(GROFF_PERL_PATH,
167[echo checking for perl
168PERLPATH=
169saveifs="$IFS"; IFS="${IFS}:"
170for dir in $PATH; do
171 test -z "$dir" && dir=.
172 if test -f $dir/perl; then
173 PERLPATH="$dir/perl"
174 break
175 fi
176done
177IFS="$saveifs"
178AC_SUBST(PERLPATH)])dnl
179dnl
180define(GROFF_WCOREFLAG,
181[echo checking for w_coredump
182AC_TEST_PROGRAM([
183#include <sys/types.h>
184#include <sys/wait.h>
185main()
186{
187#ifdef WCOREFLAG
188 exit(1);
189#else
190 int i = 0;
191 ((union wait *)&i)->w_coredump = 1;
192 exit(i != 0200);
193#endif
194}
195],AC_DEFINE(WCOREFLAG,0200),,)])dnl
196dnl
197define(GROFF_MMAP,
198[AC_COMPILE_CHECK([mmap],[#include <sys/types.h>
199#include <sys/mman.h>],
200[char *p = mmap(0, 0, PROT_READ, MAP_PRIVATE, 0, 0); munmap(p, 0);],
201AC_DEFINE(HAVE_MMAP))])dnl
202dnl;
203define(GROFF_SYS_SIGLIST,
204[AC_COMPILE_CHECK([sys_siglist],,changequote(,)dnl
205extern char *sys_siglist[]; sys_siglist[0] = 0;,changequote([,])dnl
206AC_DEFINE(HAVE_SYS_SIGLIST))])dnl
207dnl
208define(GROFF_STRUCT_EXCEPTION,
209[AC_COMPILE_CHECK([struct exception],[#include <math.h>],
210[struct exception e;],
211AC_DEFINE(HAVE_STRUCT_EXCEPTION))])dnl
212define(GROFF_COOKIE_BUG,
213[echo checking for gcc/g++ delete bug
214GROFF_CC_TEST_PROGRAM([
215#include <stdlib.h>
216#include <stddef.h>
217
218int testit = 0;
219
220int main()
221{
222 testit = 1;
223 int *p = new int;
224 delete p;
225 testit = 0;
226 exit(1);
227}
228
229static unsigned dummy[3];
230
231void *operator new(size_t n)
232{
233 if (testit) {
234 dummy[1] = -(unsigned)(dummy + 2);
235 return dummy + 2;
236 }
237 else
238 return (void *)malloc(n);
239}
240
241void operator delete(void *p)
242{
243 if (testit) {
244 if (p == dummy)
245 exit(0);
246 }
247 else
248 free(p);
249}
250],AC_DEFINE(COOKIE_BUG),,)])dnl
251dnl
252define(GROFF_CFRONT_ANSI_BUG,
253[AC_REQUIRE([GROFF_LIMITS_H])echo checking for cfront ANSI C INT_MIN bug
254GROFF_CC_TEST_PROGRAM([#include <stdlib.h>
255#ifdef HAVE_CC_LIMITS_H
256#include <limits.h>
257#else
258#define INT_MAX 2147483647
259#endif
260
261#undef INT_MIN
262#define INT_MIN (-INT_MAX-1)
263
264int main()
265{
266 int z = 0;
267 exit(INT_MIN < z);
268}
269],AC_DEFINE(CFRONT_ANSI_BUG),,)])dnl
270dnl
271define(GROFF_ARRAY_DELETE,
272[GROFF_CC_COMPILE_CHECK(new array delete syntax,,
273changequote(,)dnl
274char *p = new char[5]; delete [] p;changequote([,]),
275,AC_DEFINE(ARRAY_DELETE_NEEDS_SIZE))])dnl
276dnl
277define(GROFF_BROKEN_SPOOLER_FLAGS,
278[test -n "${BROKEN_SPOOLER_FLAGS}" || BROKEN_SPOOLER_FLAGS=7
279echo using default value of ${BROKEN_SPOOLER_FLAGS} for grops -b option
280AC_SUBST(BROKEN_SPOOLER_FLAGS)])dnl
281dnl
282define(GROFF_PRINT,
283[if test -z "$PSPRINT"
284then
285 AC_PROGRAMS_CHECK(LPR,lpr)
286 AC_PROGRAMS_CHECK(LP,lp)
287 if test -n "$LPR" && test -n "$LP"
288 then
289 # HP-UX provides an lpr command that emulates lpr using lp,
290 # but it doesn't have lpq; in this case we want to use lp
291 # rather than lpr.
292 AC_PROGRAMS_CHECK(LPQ,lpq)
293 test -n "$LPQ" || LPR=
294 fi
295 if test -n "$LPR"
296 then
297 PSPRINT="$LPR"
298 elif test -n "$LP"
299 then
300 PSPRINT="$LP"
301 fi
302fi
303AC_SUBST(PSPRINT)
304# Figure out DVIPRINT from PSPRINT.
305if test -n "$PSPRINT" && test -z "$DVIPRINT"
306then
307 if test "X$PSPRINT" = "Xlpr"
308 then
309 DVIPRINT="lpr -d"
310 else
311 DVIPRINT="$PSPRINT"
312 fi
313fi
314AC_SUBST(DVIPRINT)])dnl
315define(GROFF_GETOPT,
316[GROFF_CC_COMPILE_CHECK([declaration of getopt in stdlib.h],
317[#include <stdlib.h>],
318[int opt = getopt(0, 0, 0); optarg = "foo"; optind = 1;],
319AC_DEFINE(STDLIB_H_DECLARES_GETOPT))
320GROFF_CC_COMPILE_CHECK([declaration of getopt in unistd.h],
321[#include <sys/types.h>
322#include <unistd.h>],
323[int opt = getopt(0, 0, 0);],
324AC_DEFINE(UNISTD_H_DECLARES_GETOPT))
325])dnl
326define(GROFF_PUTENV,
327[GROFF_CC_COMPILE_CHECK([declaration of putenv],[#include <stdlib.h>],
328[putenv((char *)0);],
329AC_DEFINE(STDLIB_H_DECLARES_PUTENV))])dnl
330define(GROFF_ETAGSCCFLAG,
331[echo checking for etags C++ option
332for flag in p C
333do
334 test -z "$ETAGSCCFLAG" || break
335 >conftest.c
336 (etags -$flag -o /dev/null conftest.c >/dev/null 2>&1) 2>/dev/null &&
337 ETAGSCCFLAG="-$flag"
338 rm -f conftest.c
339done
340AC_SUBST(ETAGSCCFLAG)])dnl
341define(GROFF_LIMITS_H,
342[AC_PROVIDE([$0])GROFF_CC_COMPILE_CHECK(['C++ <limits.h>'],
343[#include <limits.h>],
344[int x = INT_MIN; int y = INT_MAX; int z = UCHAR_MAX;],
345AC_DEFINE(HAVE_CC_LIMITS_H))])dnl
346define(GROFF_TRADITIONAL_CPP,
347[GROFF_CC_COMPILE_CHECK([traditional preprocessor],
348[#define name2(a,b) a/**/b],[int name2(foo,bar);],
349AC_DEFINE(TRADITIONAL_CPP))])dnl
350define(GROFF_TIME_T,
351[GROFF_CC_COMPILE_CHECK([time_t],[#include <time.h>],
352[time_t t = time(0); struct tm *p = localtime(&t);],,
353AC_DEFINE(LONG_FOR_TIME_T))])dnl
354define(GROFF_UNISTD_H,
355[GROFF_CC_COMPILE_CHECK(['C++ <unistd.h>'],[#include <unistd.h>],
356dnl Bison generated parsers have problems with C++ compilers other than g++.
357dnl So byacc is preferred over bison.
358[read(0, 0, 0);],AC_DEFINE(HAVE_CC_UNISTD_H))])dnl
359define(GROFF_PROG_YACC,
360[AC_PROGRAM_CHECK(YACC, byacc, byacc, )
361AC_PROGRAM_CHECK(YACC, bison, bison -y, yacc)
362])dnl
363dnl GROFF_CSH_HACK(if hack present, if not present)
364define(GROFF_CSH_HACK,
365[echo 'checking for csh # hack'
366cat <<EOF >conftest.sh
367#!/bin/sh
368true || exit 0
369export PATH || exit 0
370exit 1
371EOF
372chmod +x conftest.sh
373if echo ./conftest.sh | (csh >/dev/null 2>&1) >/dev/null 2>&1
374then
375 :; $1
376else
377 :; $2
378fi
379rm -f conftest.sh
380])dnl