[project @ 1998-04-07 21:24:55 by sof]
[ghc-hetmet.git] / aclocal.m4
1 dnl $Id: aclocal.m4,v 1.21 1998/04/07 21:24:55 sof 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 ])
111
112 dnl
113 dnl Check for Happy and version.
114 dnl
115 AC_DEFUN(AC_HAPPY,
116 [AC_PATH_PROG(HappyCmd,happy)
117 AC_CACHE_CHECK([for version of happy], ac_cv_happy_version,
118 [if test x"$HappyCmd" != x; then
119    ac_cv_happy_version="`$HappyCmd -v |
120 changequote(, )dnl
121                           grep 'Happy Version' | sed -e 's/Happy Version \([^ ]*\).*/\1/g'`" ;
122 changequote([, ])dnl
123 else
124    ac_cv_happy_version="";
125 fi;
126 if expr "$ac_cv_happy_version" "<" 1.4 > /dev/null 2>&1; then
127    echo
128    echo "Happy version 1.4 or later is required to compile GHC."
129    exit 1;
130 fi;
131 ])
132 HappyVersion=$ac_cv_happy_version;
133 AC_SUBST(HappyVersion)
134 ])
135
136 dnl
137 dnl What's the best way of doing context diffs?
138 dnl
139 dnl (NB: NeXTStep thinks diff'ing a file against itself is "trouble")
140 dnl
141 AC_DEFUN(AC_PROG_DIFF,
142 [AC_CACHE_CHECK([for ok way to do context diffs], ac_cv_context_diffs,
143 [echo foo > conftest1
144 echo foo > conftest2
145 if diff -C 1 conftest1 conftest2 > /dev/null 2>&1 ; then
146     ac_cv_context_diffs='diff -C 1'
147 else
148     if diff -c1 conftest1 conftest2 > /dev/null 2>&1 ; then
149         ac_cv_context_diffs='diff -c1'
150     else
151         echo "Can't figure out how to do context diffs."
152         echo "Neither \`diff -C 1' nor \`diff -c1' works."
153         exit 1
154     fi
155 fi
156 rm -f conftest1 conftest2
157 ])
158 ContextDiffCmd=$ac_cv_context_diffs
159 AC_SUBST(ContextDiffCmd)
160 ])
161
162 dnl
163 dnl Finding the Right Yacc
164 dnl
165 AC_DEFUN(AC_PROG_YACCY,
166 [AC_PROG_YACC
167 if test "$YACC" = "yacc"; then
168    AC_CACHE_CHECK([if it is an OK yacc], ac_cv_prog_yacc,
169    [AC_CHECK_PROG(WhatCmd, what, what, :)
170     $WhatCmd $YACC > conftest.out
171     if egrep 'y1\.c 1\..*SMI' conftest.out >/dev/null 2>&1; then
172         echo "I don't trust your $YaccCmd; it looks like an old Sun yacc"
173         if test -f /usr/lang/yacc; then
174            echo "I'm going to use /usr/lang/yacc instead"
175            ac_cv_prog_yacc=/usr/lang/yacc
176         else
177            echo "I'm assuming the worst...no parser generator at all"
178            ac_cv_prog_yacc=:
179         fi
180     elif egrep 'y1\.c.*Revision: 4\.2\.6\.3.*DEC' conftest.out >/dev/null 2>&1; then
181         echo "I don't trust your $YaccCmd; it looks like a lame DEC yacc"
182         echo "I'm assuming the worst...no parser generator at all"
183         ac_cv_prog_yacc=:
184     else
185         ac_cv_prog_yacc=$YACC
186     fi
187     rm -fr conftest*
188 ])
189 else
190     ac_cv_prog_yacc=$YACC
191 fi
192 YaccCmd=$ac_cv_prog_yacc
193 AC_SUBST(YaccCmd)
194 ])
195
196 dnl *** Checking for ar and its arguments + whether we need ranlib.
197 dnl
198 dnl ArCmd and RANLIB are AC_SUBST'ed
199 dnl 
200 AC_DEFUN(AC_PROG_AR_AND_RANLIB,
201 [AC_PATH_PROG(ArCmd,ar)
202 if test -z "$ArCmd"; then
203     echo "You don't seem to have ar in your PATH...I have no idea how to make a library"
204     exit 1;
205 fi
206 if $ArCmd clqs conftest.a >/dev/null 2>/dev/null; then
207     ArCmd="$ArCmd clqs"
208     NeedRanLib=''
209 elif $ArCmd cqs conftest.a >/dev/null 2>/dev/null; then
210     ArCmd="$ArCmd cqs"
211     NeedRanLib=''
212 elif $ArCmd clq conftest.a >/dev/null 2>/dev/null; then
213     ArCmd="$ArCmd clq"
214     NeedRanLib='YES'
215 elif $ArCmd cq conftest.a >/dev/null 2>/dev/null; then
216     ArCmd="$ArCmd cq"
217     NeedRanLib='YES'
218 elif $ArCmd cq conftest.a 2>&1 | grep 'no archive members specified' >/dev/null 2>/dev/null; then
219     ArCmd="$ArCmd cq"
220     NeedRanLib='YES'
221 else
222     echo "I can't figure out how to use your $ArCmd"
223     exit 1
224 fi
225 rm -rf conftest*
226 test -n "$ArCmd" && test -n "$verbose" && echo "        setting ArCmd to $ArCmd"
227 AC_SUBST(ArCmd)
228 if test -z "$NeedRanLib"; then
229     RANLIB=':'
230     test -n "$verbose" && echo "        setting RANLIB to $RANLIB"
231     AC_SUBST(RANLIB)
232 else
233     AC_PROG_RANLIB
234 fi
235 ])
236
237 dnl
238 dnl AC_SHEBANG_PERL - can we she-bang perl?
239 dnl
240 AC_DEFUN(AC_SHEBANG_PERL,
241 [AC_CACHE_CHECK([if your perl works in shell scripts], ac_cv_shebang_perl,
242 [echo "#!$PerlCmd"'
243 exit $1;
244 ' > conftest
245 chmod u+x conftest
246 (SHELL=/bin/sh; export SHELL; ./conftest 69 > /dev/null)
247 if test $? -ne 69; then
248    ac_cv_shebang_perl=yes
249 else
250    ac_cv_shebang_perl=no
251 fi
252 rm -f conftest
253 ])])
254
255 dnl
256 dnl Extra testing of the result AC_PROG_CC, testing the gcc version no.
257 dnl *Must* be called after AC_PROG_CC
258 dnl
259 AC_DEFUN(AC_HAVE_GCC,
260 [AC_CACHE_CHECK([whether you have an ok gcc], ac_cv_have_gcc,
261 [if test -z "$GCC"; then
262     echo ''
263     echo "You would be better off with gcc"
264     echo "Perhaps it is already installed, but not in your PATH?"
265     ac_cv_have_gcc='no'
266 else
267 changequote(, )dnl
268     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' `"
269 changequote([, ])dnl
270     if test `eval $cmd_string 2>/dev/null` != "1"; then
271         echo ''
272         echo "I'm not sure if your version of gcc will work,"
273         echo "but it's worth a shot, eh?"
274     fi
275     ac_cv_have_gcc='yes'
276 fi
277 ])
278 HaveGcc=`echo $ac_cv_have_gcc | sed 'y/yesno/YESNO/'`
279 AC_SUBST(HaveGcc)
280 ])
281
282 dnl
283 dnl AC_PROG_GNUCPP gathers the path to the cpp that the
284 dnl gcc driver calls upon.
285 dnl
286 dnl Substitutes: GNUCPP and RAWCPP (latter is 'GNUCPP -traditional')
287 dnl
288 AC_DEFUN(AC_PROG_GNUCPP,
289 [AC_CACHE_CHECK([how to invoke GNU cpp directly], ac_cv_gnu_cpp,
290 [if test "$HaveGcc" = "YES"; then
291         echo > conftest.c
292         gcc -v -E conftest.c >/dev/null 2>conftest.out
293         # \x5c = backslash
294         echo 'tr/\x5c/\//; /(\S+\/cpp)/ && print "[$]1";' > conftest.pl
295         ac_cv_gnu_cpp="`eval $PerlCmd -n conftest.pl conftest.out`"
296         rm -fr conftest*
297  else
298         # We need to be able to invoke CPP directly, preferably
299         # with input from stdin (mkdependHS and hscpp depend on
300         # this at the moment).
301         # Take a guess at what to use, this probably won't work.
302         echo Warning: GNU cpp not found, using $CPP
303         ac_cv_gnu_cpp = $CPP
304  fi
305 ])
306 GNUCPP=$ac_cv_gnu_cpp
307 RAWCPP="$GNUCPP -traditional"
308 AC_SUBST(GNUCPP)
309 AC_SUBST(RAWCPP)
310 ])
311
312 dnl Small feature test for perl version. Assumes PerlCmd
313 dnl contains path to perl binary
314 dnl
315 AC_DEFUN(AC_CHECK_PERL_VERSION,
316 [$PerlCmd -v >conftest.out 2>&1
317 if grep "version 4" conftest.out >/dev/null 2>&1; then
318    if grep "Patch level: 35" conftest.out >/dev/null 2>&1; then
319       echo "
320 ************************************************************************
321 Uh-oh...looks like you have Perl 4.035.
322
323 Perl version 4.035 has a bug to do with recursion that will bite if
324 you run the lit2texi script, when making Info files from
325 literate files of various sorts.  Either use perl5, the last version of perl4 
326 (4.036), or an older version (e.g., perl 4.019). Failing that, don't create
327 any Info files :-)
328 ************************************************************************
329 "
330    fi
331 else
332    if grep "version 5" conftest.out >/dev/null 2>&1; then
333       :
334    else
335      echo "I'm not sure if your version of perl will work,"
336      echo "but it's worth a shot, eh?"
337    fi
338 fi
339 rm -fr conftest*
340 ])
341
342 dnl ** figure out the alignment restriction of a type
343 dnl    (required SIZEOF test but AC_CHECK_SIZEOF doesn't call PROVIDE
344 dnl     so we can't call REQUIRE)
345
346 dnl GHC_CHECK_ALIGNMENT(TYPE)
347 AC_DEFUN(GHC_CHECK_ALIGNMENT,
348 [changequote(<<, >>)dnl
349 dnl The name to #define.
350 define(<<AC_TYPE_NAME>>, translit(alignment_$1, [a-z *], [A-Z_P]))dnl
351 dnl The cache variable name.
352 define(<<AC_CV_NAME>>, translit(ac_cv_alignment_$1, [ *], [_p]))dnl
353 dnl The name of the corresponding size.
354 define(<<AC_CV_SIZEOF_NAME>>, translit(ac_cv_sizeof_$1, [ *], [_p]))dnl
355 changequote([, ])dnl
356 AC_MSG_CHECKING(alignment of $1)
357 AC_CACHE_VAL(AC_CV_NAME,
358 [AC_TRY_RUN([
359 #include <stdio.h>
360 #if HAVE_STDDEF_H
361 #include <stddef.h>
362 #endif
363 #ifndef offsetof
364 #define offsetof(ty,field) ((size_t)((char *)&((ty *)0)->field - (char *)(ty *)0))
365 #endif
366 int
367 main()
368 {
369   FILE *f=fopen("conftestval", "w");
370   if (!f) exit(1);
371   fprintf(f, "%d\n", offsetof(struct { char c; $1 ty;},ty));
372   exit(0);
373 }],
374 AC_CV_NAME=`cat conftestval`,
375 AC_CV_NAME=$AC_CV_SIZEOF_NAME,
376 AC_CV_NAME=$AC_CV_SIZEOF_NAME)])
377 AC_MSG_RESULT($AC_CV_NAME)
378 AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME)
379 AC_PROVIDE($AC_TYPE_NAME)
380 undefine([AC_TYPE_NAME])dnl
381 undefine([AC_CV_NAME])dnl
382 undefine([AC_CV_SIZEOF_NAME])dnl
383 ])
384