[project @ 1998-04-10 12:38:38 by simonm]
[ghc-hetmet.git] / aclocal.m4
1 dnl $Id: aclocal.m4,v 1.22 1998/04/10 12:38:38 simonm Exp $
2 dnl 
3 dnl Extra autoconf macros for the Glasgow fptools
4 dnl
5
6 dnl 
7 dnl Are we running under the GNU libc?  Need -D_GNU_SOURCE to get 
8 dnl caddr_t and such.
9 dnl 
10 AC_DEFUN(AC_GNU_LIBC,
11 [AC_CACHE_CHECK([GNU libc], ac_cv_gnu_libc,
12 [AC_EGREP_CPP(yes,
13 [#include <features.h>
14 #ifdef __GLIBC__
15 yes
16 #endif
17 ], ac_cv_gnu_libc=yes, ac_cv_gnu_libc=no)])
18 if test "$ac_cv_gnu_libc" = yes; then
19   AC_DEFINE(_GNU_SOURCE)
20 fi
21 ])
22
23 dnl
24 dnl Has timezone the type time_t or long (HP-UX 10.20 apparently
25 dnl has `long'..)
26 dnl 
27 AC_DEFUN(AC_TYPE_TIMEZONE,
28 [AC_CACHE_CHECK([type of timezone], ac_cv_type_timezone,
29 [AC_TRY_COMPILE([#if TIME_WITH_SYS_TIME
30 # include <sys/time.h>
31 # include <time.h>
32 #else
33 # if HAVE_SYS_TIME_H
34 #  include <sys/time.h>
35 # else
36 #  include <time.h>
37 # endif
38 #endif
39
40 extern time_t timezone;
41 ],
42 [int i;], ac_cv_type_timezone=time_t, ac_cv_type_timezone=long)])
43 AC_DEFINE_UNQUOTED(TYPE_TIMEZONE, $ac_cv_type_timezone)
44 ])
45
46 dnl *** Is altzone available? ***
47 dnl 
48 AC_DEFUN(AC_ALTZONE,
49 [AC_CACHE_CHECK([altzone], ac_cv_altzone,
50 [AC_TRY_LINK([#if TIME_WITH_SYS_TIME
51 # include <sys/time.h>
52 # include <time.h>
53 #else
54 # if HAVE_SYS_TIME_H
55 #  include <sys/time.h>
56 # else
57 #  include <time.h>
58 # endif
59 #endif
60 ], [return altzone;], 
61 ac_cv_altzone=yes, ac_cv_altzone=no)])
62 if test "$ac_cv_altzone" = yes; then
63   AC_DEFINE(HAVE_ALTZONE)
64 fi
65 ])
66
67 dnl ** check for leading underscores in symbol names
68 dnl 
69 dnl Test for determining whether symbol names have a leading
70 dnl underscore.
71 dnl 
72 dnl We assume that they _haven't_ if anything goes wrong.
73 dnl
74 AC_DEFUN(AC_UNDERSCORE,
75 [AC_CHECK_LIB(elf, nlist, LIBS="-lelf $LIBS")dnl
76 AC_CACHE_CHECK([leading underscore in symbol names], ac_cv_lead_uscore,
77
78 dnl
79 dnl Hack!: nlist() under Digital UNIX insist on there being an _,
80 dnl but symbol table listings show none. What is going on here?!?
81 dnl
82 changequote(<<, >>)dnl
83 <<
84 case $HostPlatform in
85 alpha-dec-osf*) ac_cv_lead_uscore='no';;
86 *) >>
87 changequote([, ])dnl
88 AC_TRY_RUN([#ifdef HAVE_NLIST_H
89 #include <nlist.h>
90 changequote(<<, >>)dnl
91 <<
92 struct nlist xYzzY[] = {{"_xYzzY", 0},{0}};
93 #endif
94
95 main(argc, argv)
96 int argc;
97 char **argv;
98 {
99 #ifdef HAVE_NLIST_H
100     if(nlist(argv[0], xYzzY) == 0 && xYzzY[0].n_value != 0)
101         exit(0);>>
102 changequote([, ])dnl
103 #endif
104     exit(1);
105 }], ac_cv_lead_uscore=yes, ac_cv_lead_uscore=no, ac_cv_lead_uscore=NO)
106 ;;
107 esac);
108 LeadingUnderscore=`echo $ac_cv_lead_uscore | sed 'y/yesno/YESNO/'`
109 AC_SUBST(LeadingUnderscore)
110 case $LeadingUnderscore in
111 YES) AC_DEFINE(LEADING_UNDERSCORE);;
112 esac
113 ])
114
115 dnl
116 dnl Check for Happy and version.
117 dnl
118 AC_DEFUN(AC_HAPPY,
119 [AC_PATH_PROG(HappyCmd,happy)
120 AC_CACHE_CHECK([for version of happy], ac_cv_happy_version,
121 [if test x"$HappyCmd" != x; then
122    ac_cv_happy_version="`$HappyCmd -v |
123 changequote(, )dnl
124                           grep 'Happy Version' | sed -e 's/Happy Version \([^ ]*\).*/\1/g'`" ;
125 changequote([, ])dnl
126 else
127    ac_cv_happy_version="";
128 fi;
129 if expr "$ac_cv_happy_version" "<" 1.4 > /dev/null 2>&1; then
130    echo
131    echo "Happy version 1.4 or later is required to compile GHC."
132    exit 1;
133 fi;
134 ])
135 HappyVersion=$ac_cv_happy_version;
136 AC_SUBST(HappyVersion)
137 ])
138
139 dnl
140 dnl What's the best way of doing context diffs?
141 dnl
142 dnl (NB: NeXTStep thinks diff'ing a file against itself is "trouble")
143 dnl
144 AC_DEFUN(AC_PROG_DIFF,
145 [AC_CACHE_CHECK([for ok way to do context diffs], ac_cv_context_diffs,
146 [echo foo > conftest1
147 echo foo > conftest2
148 if diff -C 1 conftest1 conftest2 > /dev/null 2>&1 ; then
149     ac_cv_context_diffs='diff -C 1'
150 else
151     if diff -c1 conftest1 conftest2 > /dev/null 2>&1 ; then
152         ac_cv_context_diffs='diff -c1'
153     else
154         echo "Can't figure out how to do context diffs."
155         echo "Neither \`diff -C 1' nor \`diff -c1' works."
156         exit 1
157     fi
158 fi
159 rm -f conftest1 conftest2
160 ])
161 ContextDiffCmd=$ac_cv_context_diffs
162 AC_SUBST(ContextDiffCmd)
163 ])
164
165 dnl
166 dnl Finding the Right Yacc
167 dnl
168 AC_DEFUN(AC_PROG_YACCY,
169 [AC_PROG_YACC
170 if test "$YACC" = "yacc"; then
171    AC_CACHE_CHECK([if it is an OK yacc], ac_cv_prog_yacc,
172    [AC_CHECK_PROG(WhatCmd, what, what, :)
173     $WhatCmd $YACC > conftest.out
174     if egrep 'y1\.c 1\..*SMI' conftest.out >/dev/null 2>&1; then
175         echo "I don't trust your $YaccCmd; it looks like an old Sun yacc"
176         if test -f /usr/lang/yacc; then
177            echo "I'm going to use /usr/lang/yacc instead"
178            ac_cv_prog_yacc=/usr/lang/yacc
179         else
180            echo "I'm assuming the worst...no parser generator at all"
181            ac_cv_prog_yacc=:
182         fi
183     elif egrep 'y1\.c.*Revision: 4\.2\.6\.3.*DEC' conftest.out >/dev/null 2>&1; then
184         echo "I don't trust your $YaccCmd; it looks like a lame DEC yacc"
185         echo "I'm assuming the worst...no parser generator at all"
186         ac_cv_prog_yacc=:
187     else
188         ac_cv_prog_yacc=$YACC
189     fi
190     rm -fr conftest*
191 ])
192 else
193     ac_cv_prog_yacc=$YACC
194 fi
195 YaccCmd=$ac_cv_prog_yacc
196 AC_SUBST(YaccCmd)
197 ])
198
199 dnl *** Checking for ar and its arguments + whether we need ranlib.
200 dnl
201 dnl ArCmd and RANLIB are AC_SUBST'ed
202 dnl 
203 AC_DEFUN(AC_PROG_AR_AND_RANLIB,
204 [AC_PATH_PROG(ArCmd,ar)
205 if test -z "$ArCmd"; then
206     echo "You don't seem to have ar in your PATH...I have no idea how to make a library"
207     exit 1;
208 fi
209 if $ArCmd clqs conftest.a >/dev/null 2>/dev/null; then
210     ArCmd="$ArCmd clqs"
211     NeedRanLib=''
212 elif $ArCmd cqs conftest.a >/dev/null 2>/dev/null; then
213     ArCmd="$ArCmd cqs"
214     NeedRanLib=''
215 elif $ArCmd clq conftest.a >/dev/null 2>/dev/null; then
216     ArCmd="$ArCmd clq"
217     NeedRanLib='YES'
218 elif $ArCmd cq conftest.a >/dev/null 2>/dev/null; then
219     ArCmd="$ArCmd cq"
220     NeedRanLib='YES'
221 elif $ArCmd cq conftest.a 2>&1 | grep 'no archive members specified' >/dev/null 2>/dev/null; then
222     ArCmd="$ArCmd cq"
223     NeedRanLib='YES'
224 else
225     echo "I can't figure out how to use your $ArCmd"
226     exit 1
227 fi
228 rm -rf conftest*
229 test -n "$ArCmd" && test -n "$verbose" && echo "        setting ArCmd to $ArCmd"
230 AC_SUBST(ArCmd)
231 if test -z "$NeedRanLib"; then
232     RANLIB=':'
233     test -n "$verbose" && echo "        setting RANLIB to $RANLIB"
234     AC_SUBST(RANLIB)
235 else
236     AC_PROG_RANLIB
237 fi
238 ])
239
240 dnl
241 dnl AC_SHEBANG_PERL - can we she-bang perl?
242 dnl
243 AC_DEFUN(AC_SHEBANG_PERL,
244 [AC_CACHE_CHECK([if your perl works in shell scripts], ac_cv_shebang_perl,
245 [echo "#!$PerlCmd"'
246 exit $1;
247 ' > conftest
248 chmod u+x conftest
249 (SHELL=/bin/sh; export SHELL; ./conftest 69 > /dev/null)
250 if test $? -ne 69; then
251    ac_cv_shebang_perl=yes
252 else
253    ac_cv_shebang_perl=no
254 fi
255 rm -f conftest
256 ])])
257
258 dnl
259 dnl Extra testing of the result AC_PROG_CC, testing the gcc version no.
260 dnl *Must* be called after AC_PROG_CC
261 dnl
262 AC_DEFUN(AC_HAVE_GCC,
263 [AC_CACHE_CHECK([whether you have an ok gcc], ac_cv_have_gcc,
264 [if test -z "$GCC"; then
265     echo ''
266     echo "You would be better off with gcc"
267     echo "Perhaps it is already installed, but not in your PATH?"
268     ac_cv_have_gcc='no'
269 else
270 changequote(, )dnl
271     cmd_string="`$CC -v 2>&1 | grep 'version ' | sed -e 's/.*version [^0-9]*\([0-9][0-9]*\)\.\([0-9][0-9]*\).*/expr 20 \\\< \1 \\\* 10 + \2/g' `"
272 changequote([, ])dnl
273     if test `eval $cmd_string 2>/dev/null` != "1"; then
274         echo ''
275         echo "I'm not sure if your version of gcc will work,"
276         echo "but it's worth a shot, eh?"
277     fi
278     ac_cv_have_gcc='yes'
279 fi
280 ])
281 HaveGcc=`echo $ac_cv_have_gcc | sed 'y/yesno/YESNO/'`
282 AC_SUBST(HaveGcc)
283 ])
284
285 dnl
286 dnl AC_PROG_GNUCPP gathers the path to the cpp that the
287 dnl gcc driver calls upon.
288 dnl
289 dnl Substitutes: GNUCPP and RAWCPP (latter is 'GNUCPP -traditional')
290 dnl
291 AC_DEFUN(AC_PROG_GNUCPP,
292 [AC_CACHE_CHECK([how to invoke GNU cpp directly], ac_cv_gnu_cpp,
293 [if test "$HaveGcc" = "YES"; then
294         echo > conftest.c
295         gcc -v -E conftest.c >/dev/null 2>conftest.out
296         # \x5c = backslash
297         echo 'tr/\x5c/\//; /(\S+\/cpp)/ && print "[$]1";' > conftest.pl
298         ac_cv_gnu_cpp="`eval $PerlCmd -n conftest.pl conftest.out`"
299         rm -fr conftest*
300  else
301         # We need to be able to invoke CPP directly, preferably
302         # with input from stdin (mkdependHS and hscpp depend on
303         # this at the moment).
304         # Take a guess at what to use, this probably won't work.
305         echo Warning: GNU cpp not found, using $CPP
306         ac_cv_gnu_cpp = $CPP
307  fi
308 ])
309 GNUCPP=$ac_cv_gnu_cpp
310 RAWCPP="$GNUCPP -traditional"
311 AC_SUBST(GNUCPP)
312 AC_SUBST(RAWCPP)
313 ])
314
315 dnl Small feature test for perl version. Assumes PerlCmd
316 dnl contains path to perl binary
317 dnl
318 AC_DEFUN(AC_CHECK_PERL_VERSION,
319 [$PerlCmd -v >conftest.out 2>&1
320 if grep "version 4" conftest.out >/dev/null 2>&1; then
321    if grep "Patch level: 35" conftest.out >/dev/null 2>&1; then
322       echo "
323 ************************************************************************
324 Uh-oh...looks like you have Perl 4.035.
325
326 Perl version 4.035 has a bug to do with recursion that will bite if
327 you run the lit2texi script, when making Info files from
328 literate files of various sorts.  Either use perl5, the last version of perl4 
329 (4.036), or an older version (e.g., perl 4.019). Failing that, don't create
330 any Info files :-)
331 ************************************************************************
332 "
333    fi
334 else
335    if grep "version 5" conftest.out >/dev/null 2>&1; then
336       :
337    else
338      echo "I'm not sure if your version of perl will work,"
339      echo "but it's worth a shot, eh?"
340    fi
341 fi
342 rm -fr conftest*
343 ])
344
345 dnl ** figure out the alignment restriction of a type
346 dnl    (required SIZEOF test but AC_CHECK_SIZEOF doesn't call PROVIDE
347 dnl     so we can't call REQUIRE)
348
349 dnl GHC_CHECK_ALIGNMENT(TYPE)
350 AC_DEFUN(GHC_CHECK_ALIGNMENT,
351 [changequote(<<, >>)dnl
352 dnl The name to #define.
353 define(<<AC_TYPE_NAME>>, translit(alignment_$1, [a-z *], [A-Z_P]))dnl
354 dnl The cache variable name.
355 define(<<AC_CV_NAME>>, translit(ac_cv_alignment_$1, [ *], [_p]))dnl
356 dnl The name of the corresponding size.
357 define(<<AC_CV_SIZEOF_NAME>>, translit(ac_cv_sizeof_$1, [ *], [_p]))dnl
358 changequote([, ])dnl
359 AC_MSG_CHECKING(alignment of $1)
360 AC_CACHE_VAL(AC_CV_NAME,
361 [AC_TRY_RUN([
362 #include <stdio.h>
363 #if HAVE_STDDEF_H
364 #include <stddef.h>
365 #endif
366 #ifndef offsetof
367 #define offsetof(ty,field) ((size_t)((char *)&((ty *)0)->field - (char *)(ty *)0))
368 #endif
369 int
370 main()
371 {
372   FILE *f=fopen("conftestval", "w");
373   if (!f) exit(1);
374   fprintf(f, "%d\n", offsetof(struct { char c; $1 ty;},ty));
375   exit(0);
376 }],
377 AC_CV_NAME=`cat conftestval`,
378 AC_CV_NAME=$AC_CV_SIZEOF_NAME,
379 AC_CV_NAME=$AC_CV_SIZEOF_NAME)])
380 AC_MSG_RESULT($AC_CV_NAME)
381 AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME)
382 AC_PROVIDE($AC_TYPE_NAME)
383 undefine([AC_TYPE_NAME])dnl
384 undefine([AC_CV_NAME])dnl
385 undefine([AC_CV_SIZEOF_NAME])dnl
386 ])
387