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