[project @ 2001-03-13 14:59:56 by simonmar]
[ghc-hetmet.git] / aclocal.m4
1 dnl $Id: aclocal.m4,v 1.68 2001/03/13 14:59:56 simonmar 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 Is timezone around? (in a header file)
11 dnl 
12 AC_DEFUN(FPTOOLS_HAVE_TIMEZONE,
13 [AC_CACHE_CHECK([timezone], fptools_cv_have_timezone,
14 [AC_TRY_COMPILE([#if TIME_WITH_SYS_TIME
15 # include <sys/time.h>
16 # include <time.h>
17 #else
18 # if HAVE_SYS_TIME_H
19 #  include <sys/time.h>
20 # else
21 #  include <time.h>
22 # endif
23 #endif
24 ], [return timezone;], 
25 fptools_cv_have_timezone=yes, fptools_cv_have_timezone=no)])
26 if test "$fptools_cv_have_timezone" = yes; then
27   AC_DEFINE(HAVE_TIMEZONE)
28 fi
29 ])
30
31 dnl
32 dnl Has timezone the type time_t or long (HP-UX 10.20 apparently
33 dnl has `long'..)
34 dnl 
35 AC_DEFUN(FPTOOLS_TYPE_TIMEZONE,
36 [AC_CACHE_CHECK([type of timezone], fptools_cv_type_timezone,
37 [AC_TRY_COMPILE([#if TIME_WITH_SYS_TIME
38 # include <sys/time.h>
39 # include <time.h>
40 #else
41 # if HAVE_SYS_TIME_H
42 #  include <sys/time.h>
43 # else
44 #  include <time.h>
45 # endif
46 #endif
47
48 extern time_t timezone; 
49 ],
50 [int i;], fptools_cv_type_timezone=time_t, fptools_cv_type_timezone=long)])
51 AC_DEFINE_UNQUOTED(TYPE_TIMEZONE, $fptools_cv_type_timezone)
52 ])
53
54 dnl *** Is altzone available? ***
55 dnl 
56 AC_DEFUN(FPTOOLS_ALTZONE,
57 [AC_CACHE_CHECK([altzone], fptools_cv_altzone,
58 [AC_TRY_LINK([#if TIME_WITH_SYS_TIME
59 # include <sys/time.h>
60 # include <time.h>
61 #else
62 # if HAVE_SYS_TIME_H
63 #  include <sys/time.h>
64 # else
65 #  include <time.h>
66 # endif
67 #endif
68 ], [return altzone;], 
69 fptools_cv_altzone=yes, fptools_cv_altzone=no)])
70 if test "$fptools_cv_altzone" = yes; then
71   AC_DEFINE(HAVE_ALTZONE)
72 fi
73 ])
74
75
76 dnl *** Does libc contain GNU regex? ***
77 dnl 
78 AC_DEFUN(FPTOOLS_REGEX_IN_LIBC,
79 [AC_CACHE_CHECK([for GNU regex in libc], fptools_cv_have_regex,
80 [AC_TRY_LINK([#if HAVE_UNISTD_H
81 #include <unistd.h>
82 #endif
83 #include <regex.h>
84 ],[ struct re_pattern_buffer patbuf; re_compile_pattern("",0,&patbuf); ],
85 fptools_cv_have_regex=yes, fptools_cv_have_regex=no)])
86 if test "$fptools_cv_have_regex" = yes; then
87         HaveRegex=YES
88 else
89         HaveRegex=NO
90 fi
91 AC_SUBST(HaveRegex)
92 ])
93
94
95 dnl ** check for leading underscores in symbol names
96 dnl 
97 dnl Test for determining whether symbol names have a leading
98 dnl underscore.
99 dnl 
100 dnl We assume that they _haven't_ if anything goes wrong.
101 dnl
102 dnl Some nlist implementations seem to try to be compatible by ignoring
103 dnl a leading underscore sometimes (eg. FreeBSD).  We therefore have
104 dnl to work around this by checking for *no* leading underscore first.
105 dnl Sigh.  --SDM
106 dnl
107 AC_DEFUN(FPTOOLS_UNDERSCORE,
108 [AC_CHECK_LIB(elf, nlist, LIBS="-lelf $LIBS")dnl
109 AC_CACHE_CHECK([leading underscore in symbol names], fptools_cv_lead_uscore,
110
111 dnl
112 dnl Hack!: nlist() under Digital UNIX insist on there being an _,
113 dnl but symbol table listings shows none. What is going on here?!?
114 dnl
115 dnl Another hack: cygwin doesn't come with nlist.h , so we hardwire
116 dnl the underscoredness of that "platform"
117 changequote(<<, >>)dnl
118 <<
119 case $HostPlatform in
120 alpha-dec-osf*) fptools_cv_lead_uscore='no';;
121 *cygwin32) fptools_cv_lead_uscore='yes';;
122 *mingw32) fptools_cv_lead_uscore='yes';;
123 *) >>
124 changequote([, ])dnl
125 AC_TRY_RUN([#ifdef HAVE_NLIST_H
126 #include <nlist.h>
127 changequote(<<, >>)dnl
128 <<
129 struct nlist xYzzY1[] = {{"xYzzY1", 0},{0}};
130 struct nlist xYzzY2[] = {{"_xYzzY2", 0},{0}};
131 #endif
132
133 main(argc, argv)
134 int argc;
135 char **argv;
136 {
137 #ifdef HAVE_NLIST_H
138     if(nlist(argv[0], xYzzY1) == 0 && xYzzY1[0].n_value != 0)
139         exit(1);
140     if(nlist(argv[0], xYzzY2) == 0 && xYzzY2[0].n_value != 0)
141         exit(0);>>
142 changequote([, ])dnl
143 #endif
144     exit(1);
145 }], fptools_cv_lead_uscore=yes, fptools_cv_lead_uscore=no, fptools_cv_lead_uscore=NO)
146 ;;
147 esac);
148 LeadingUnderscore=`echo $fptools_cv_lead_uscore | sed 'y/yesno/YESNO/'`
149 AC_SUBST(LeadingUnderscore)
150 case $LeadingUnderscore in
151 YES) AC_DEFINE(LEADING_UNDERSCORE);;
152 esac
153 ])
154
155 dnl
156 dnl Check for Happy and version.  If we're building GHC, then we need
157 dnl at least Happy version 1.9.  If there's no installed Happy, we look
158 dnl for a happy source tree and point the build system at that instead.
159 dnl
160 dnl ToDo: when we reset HappyCmd to the source tree, autoconf doesn't
161 dnl seems to insert it in the cache file.  sigh.
162 dnl
163 AC_DEFUN(FPTOOLS_HAPPY,
164 [AC_PATH_PROG(HappyCmd,happy)
165 AC_CACHE_CHECK([for version of happy], fptools_cv_happy_version,
166 [if test x"$HappyCmd" != x; then
167    fptools_cv_happy_version="`$HappyCmd -v |
168 changequote(, )dnl
169                           grep 'Happy Version' | sed -e 's/Happy Version \([^ ]*\).*/\1/g'`" ;
170 elif test -d $srcdir/happy; then
171    HappyCmd=$hardtop/happy/src/happy-inplace;
172    fptools_cv_happy_version=`grep '^ProjectVersion[     ]*=' $srcdir/happy/mk/version.mk | sed 's/.*\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/g'`;
173    echo -n "using happy from the source tree... ";
174 else
175    fptools_cv_happy_version="";
176 fi;
177 changequote([, ])dnl
178 if test -d $srcdir/ghc; then
179   if ( test "$fptools_cv_happy_version" = "" || (
180        test `echo "$fptools_cv_happy_version" | sed -e "s/\(.*\)\..*/\1/g"` "-eq" "1" &&
181        test `echo "$fptools_cv_happy_version" | sed -e "s/.*\.\(.*\)/\1/g"` "-lt" "9" )); then
182      echo
183      echo "Happy version 1.9 or later is required to compile GHC."
184      exit 1;
185    fi
186 fi;
187 ])
188 HappyVersion=$fptools_cv_happy_version;
189 AC_SUBST(HappyVersion)
190 ])
191
192 dnl
193 dnl What's the best way of doing context diffs?
194 dnl
195 dnl (NB: NeXTStep thinks diff'ing a file against itself is "trouble")
196 dnl
197 AC_DEFUN(FPTOOLS_PROG_DIFF,
198 [AC_CACHE_CHECK([for ok way to do context diffs], fptools_cv_context_diffs,
199 [echo foo > conftest1
200 echo foo > conftest2
201 if diff -C 1 conftest1 conftest2 > /dev/null 2>&1 ; then
202     fptools_cv_context_diffs='diff -C 1'
203 else
204     if diff -c1 conftest1 conftest2 > /dev/null 2>&1 ; then
205         fptools_cv_context_diffs='diff -c1'
206     else
207         echo "Can't figure out how to do context diffs."
208         echo "Neither \`diff -C 1' nor \`diff -c1' works."
209         exit 1
210     fi
211 fi
212 rm -f conftest1 conftest2
213 ])
214 ContextDiffCmd=$fptools_cv_context_diffs
215 AC_SUBST(ContextDiffCmd)
216 ])
217
218 dnl
219 dnl Finding the Right Yacc
220 dnl
221 AC_DEFUN(FPTOOLS_PROG_YACCY,
222 [AC_PROG_YACC
223 if test "$YACC" = "yacc"; then
224    AC_CACHE_CHECK([if it is an OK yacc], ac_cv_prog_yacc,
225    [AC_CHECK_PROG(WhatCmd, what, what, :)
226     $WhatCmd $YACC > conftest.out
227     if egrep 'y1\.c 1\..*SMI' conftest.out >/dev/null 2>&1; then
228         echo "I don't trust your $YaccCmd; it looks like an old Sun yacc"
229         if test -f /usr/lang/yacc; then
230            echo "I'm going to use /usr/lang/yacc instead"
231            ac_cv_prog_yacc=/usr/lang/yacc
232         else
233            echo "I'm assuming the worst...no parser generator at all"
234            ac_cv_prog_yacc=:
235         fi
236     elif egrep 'y1\.c.*Revision: 4\.2\.6\.3.*DEC' conftest.out >/dev/null 2>&1; then
237         echo "I don't trust your $YaccCmd; it looks like a lame DEC yacc"
238         echo "I'm assuming the worst...no parser generator at all"
239         ac_cv_prog_yacc=:
240     else
241         ac_cv_prog_yacc=$YACC
242     fi
243     rm -fr conftest*
244 ])
245 else
246     ac_cv_prog_yacc=$YACC
247 fi
248 YaccCmd=$ac_cv_prog_yacc
249 AC_SUBST(YaccCmd)
250 ])
251
252 dnl *** Checking for ar and its arguments + whether we need ranlib.
253 dnl
254 dnl ArCmd and RANLIB are AC_SUBST'ed
255 dnl 
256 AC_DEFUN(FPTOOLS_PROG_AR_AND_RANLIB,
257 [AC_PATH_PROG(ArCmd,ar)
258 if test -z "$ArCmd"; then
259     echo "You don't seem to have ar in your PATH...I have no idea how to make a library"
260     exit 1;
261 fi
262 if $ArCmd clqs conftest.a >/dev/null 2>/dev/null; then
263     ArCmd="$ArCmd clqs"
264     NeedRanLib=''
265 elif $ArCmd cqs conftest.a >/dev/null 2>/dev/null; then
266     ArCmd="$ArCmd cqs"
267     NeedRanLib=''
268 elif $ArCmd clq conftest.a >/dev/null 2>/dev/null; then
269     ArCmd="$ArCmd clq"
270     NeedRanLib='YES'
271 elif $ArCmd cq conftest.a >/dev/null 2>/dev/null; then
272     ArCmd="$ArCmd cq"
273     NeedRanLib='YES'
274 elif $ArCmd cq conftest.a 2>&1 | grep 'no archive members specified' >/dev/null 2>/dev/null; then
275     ArCmd="$ArCmd cq"
276     NeedRanLib='YES'
277 else
278     echo "I can't figure out how to use your $ArCmd"
279     exit 1
280 fi
281 rm -rf conftest*
282 test -n "$ArCmd" && test -n "$verbose" && echo "        setting ArCmd to $ArCmd"
283 AC_SUBST(ArCmd)
284 if test -z "$NeedRanLib"; then
285     RANLIB=':'
286     test -n "$verbose" && echo "        setting RANLIB to $RANLIB"
287     AC_SUBST(RANLIB)
288 else
289     AC_PROG_RANLIB
290 fi
291 ])
292
293 dnl
294 dnl AC_SHEBANG_PERL - can we she-bang perl?
295 dnl
296 AC_DEFUN(FPTOOLS_SHEBANG_PERL,
297 [AC_CACHE_CHECK([if your perl works in shell scripts], fptools_cv_shebang_perl,
298 [echo "#!$PerlCmd"'
299 exit $1;
300 ' > conftest
301 chmod u+x conftest
302 (SHELL=/bin/sh; export SHELL; ./conftest 69 > /dev/null)
303 if test $? -ne 69; then
304    fptools_cv_shebang_perl=yes
305 else
306    fptools_cv_shebang_perl=no
307 fi
308 rm -f conftest
309 ])])
310
311 dnl
312 dnl Extra testing of the result AC_PROG_CC, testing the gcc version no.
313 dnl *Must* be called after AC_PROG_CC
314 dnl
315 AC_DEFUN(FPTOOLS_HAVE_GCC,
316 [AC_CACHE_CHECK([whether you have an ok gcc], fptools_cv_have_gcc,
317 [if test -z "$GCC"; then
318     echo ''
319     echo "You would be better off with gcc"
320     echo "Perhaps it is already installed, but not in your PATH?"
321     fptools_cv_have_gcc='no'
322 else
323 changequote(, )dnl
324     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' `"
325 changequote([, ])dnl
326     if test `eval $cmd_string 2>/dev/null` != "1"; then
327         echo ''
328         echo "I'm not sure if your version of gcc will work,"
329         echo "but it's worth a shot, eh?"
330     fi
331     fptools_cv_have_gcc='yes'
332 fi
333 ])
334 HaveGcc=`echo $fptools_cv_have_gcc | sed 'y/yesno/YESNO/'`
335 AC_SUBST(HaveGcc)
336 ])
337
338 dnl Small feature test for perl version. Assumes PerlCmd
339 dnl contains path to perl binary
340 dnl
341 AC_DEFUN(FPTOOLS_CHECK_PERL_VERSION,
342 [$PerlCmd -v >conftest.out 2>&1
343 if grep "version 5" conftest.out >/dev/null 2>&1; then
344    :
345 else
346   if grep "v5.6" conftest.out >/dev/null 2>&1; then
347      :
348   else
349      if grep "version 6" conftest.out >/dev/null 2>&1; then
350         :
351      else
352        echo "Your version of perl probably won't work."
353      fi
354   fi
355 fi
356 rm -fr conftest*
357 ])
358
359 dnl
360 dnl FPTOOLS_GHC_VERSION(version)
361 dnl FPTOOLS_GHC_VERSION(major, minor [, patchlevel])
362 dnl FPTOOLS_GHC_VERSION(version, major, minor, patchlevel)
363 dnl
364 dnl Test for version of installed ghc.  Uses $GHC.
365 dnl [original version pinched from c2hs]
366 dnl
367 AC_DEFUN(FPTOOLS_GHC_VERSION,
368 [define([FPTOOLS_CV_GHC_VERSION], [fptools_cv_ghc_version])dnl
369 AC_CACHE_CHECK([version of ghc], FPTOOLS_CV_GHC_VERSION, [dnl
370 ${WithGhc-ghc} --version > conftestghc 2>&1
371   cat conftestghc >&AC_FD_CC
372 dnl `Useless Use Of cat' award...
373 changequote(<<, >>)dnl
374   FPTOOLS_CV_GHC_VERSION=`cat conftestghc | sed -n -e 's/, patchlevel *\([0-9]\)/.\1/;s/.* version \([0-9][0-9.]*\).*/\1/p'`
375 changequote([, ])dnl
376   rm -fr conftest*
377   if test "[$]FPTOOLS_CV_GHC_VERSION" = ""
378   then
379     FPTOOLS_CV_GHC_VERSION='unknown'
380   fi])
381 changequote(<<, >>)dnl
382 FPTOOLS_CV_GHC_VERSION<<_major>>=`echo <<$>>FPTOOLS_CV_GHC_VERSION | sed -e 's/^\([0-9]\).*/\1/'`
383 FPTOOLS_CV_GHC_VERSION<<_minor>>=`echo <<$>>FPTOOLS_CV_GHC_VERSION | sed -e 's/^[0-9]\.\([0-9]*\).*/\1/'`
384 FPTOOLS_CV_GHC_VERSION<<_pl>>=`echo <<$>>FPTOOLS_CV_GHC_VERSION | sed -n -e 's/^[0-9]\.[0-9]*\.\([0-9]*\)/\1/p'`
385 changequote([, ])dnl
386 if test "[$]FPTOOLS_CV_GHC_VERSION[_pl]" = ""
387 then
388   FPTOOLS_CV_GHC_VERSION[_all]="[$]FPTOOLS_CV_GHC_VERSION[_major].[$]FPTOOLS_CV_GHC_VERSION[_minor]"
389   FPTOOLS_CV_GHC_VERSION[_pl]="0"
390 else
391   FPTOOLS_CV_GHC_VERSION[_all]="[$]FPTOOLS_CV_GHC_VERSION[_major].[$]FPTOOLS_CV_GHC_VERSION[_minor].[$]FPTOOLS_CV_GHC_VERSION[_pl]"
392 fi
393 ifelse($#, [1], [dnl
394 [$1]="[$]FPTOOLS_CV_GHC_VERSION[_all]"
395 ], $#, [2], [dnl
396 [$1]="[$]FPTOOLS_CV_GHC_VERSION[_major]"
397 [$2]="[$]FPTOOLS_CV_GHC_VERSION[_minor]"
398 ], $#, [3], [dnl
399 [$1]="[$]FPTOOLS_CV_GHC_VERSION[_major]"
400 [$2]="[$]FPTOOLS_CV_GHC_VERSION[_minor]"
401 [$3]="[$]FPTOOLS_CV_GHC_VERSION[_pl]"
402 ], $#, [4], [dnl
403 [$1]="[$]FPTOOLS_CV_GHC_VERSION[_all]"
404 [$2]="[$]FPTOOLS_CV_GHC_VERSION[_major]"
405 [$3]="[$]FPTOOLS_CV_GHC_VERSION[_minor]"
406 [$4]="[$]FPTOOLS_CV_GHC_VERSION[_pl]"
407 ], [AC_MSG_ERROR([wrong number of arguments to [$0]])])dnl
408 undefine([FPTOOLS_CV_GHC_VERSION])dnl
409 ])dnl
410
411
412 dnl ** figure out the alignment restriction of a type
413 dnl    (required SIZEOF test but AC_CHECK_SIZEOF doesn't call PROVIDE
414 dnl     so we can't call REQUIRE)
415
416 dnl FPTOOLS_CHECK_ALIGNMENT(TYPE)
417 AC_DEFUN(FPTOOLS_CHECK_ALIGNMENT,
418 [changequote(<<, >>)dnl
419 dnl The name to #define.
420 define(<<AC_TYPE_NAME>>, translit(alignment_$1, [a-z *], [A-Z_P]))dnl
421 dnl The cache variable name.
422 define(<<AC_CV_NAME>>, translit(ac_cv_alignment_$1, [ *], [_p]))dnl
423 dnl The name of the corresponding size.
424 define(<<AC_CV_SIZEOF_NAME>>, translit(ac_cv_sizeof_$1, [ *], [_p]))dnl
425 changequote([, ])dnl
426 AC_MSG_CHECKING(alignment of $1)
427 AC_CACHE_VAL(AC_CV_NAME,
428 [AC_TRY_RUN([
429 #include <stdio.h>
430 #if HAVE_STDDEF_H
431 #include <stddef.h>
432 #endif
433 #ifndef offsetof
434 #define offsetof(ty,field) ((size_t)((char *)&((ty *)0)->field - (char *)(ty *)0))
435 #endif
436 int
437 main()
438 {
439   FILE *f=fopen("conftestval", "w");
440   if (!f) exit(1);
441   fprintf(f, "%d", offsetof(struct { char c; $1 ty;},ty));
442   exit(0);
443 }],
444 AC_CV_NAME=`cat conftestval`,
445 AC_CV_NAME=$AC_CV_SIZEOF_NAME,
446 AC_CV_NAME=$AC_CV_SIZEOF_NAME)])
447 AC_MSG_RESULT($AC_CV_NAME)
448 AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME)
449 AC_PROVIDE($AC_TYPE_NAME)
450 undefine([AC_TYPE_NAME])dnl
451 undefine([AC_CV_NAME])dnl
452 undefine([AC_CV_SIZEOF_NAME])dnl
453 ])
454
455 dnl ** Map an arithmetic C type to a Haskell type.
456 dnl    Based on autconf's AC_CHECK_SIZEOF.
457
458 dnl FPTOOLS_CHECK_HTYPE(TYPE [, DEFAULT_VALUE, [, VALUE-FOR-CROSS-COMPILATION])
459 AC_DEFUN(FPTOOLS_CHECK_HTYPE,
460 [changequote(<<, >>)dnl
461 dnl The name to #define.
462 define(<<AC_TYPE_NAME>>, translit(htype_$1, [a-z *], [A-Z_P]))dnl
463 dnl The cache variable name.
464 define(<<AC_CV_NAME>>, translit(fptools_cv_htype_$1, [ *], [_p]))dnl
465 changequote([, ])dnl
466 AC_MSG_CHECKING(Haskell type for $1)
467 AC_CACHE_VAL(AC_CV_NAME,
468 [AC_TRY_RUN([#include <stdio.h>
469 #include <stddef.h>
470 #ifdef HAVE_SIGNAL_H
471 #include <signal.h>
472 #endif
473 #ifdef HAVE_TIME_H
474 #include <time.h>
475 #endif
476 #ifdef HAVE_GL_GL_H
477 #include <GL/gl.h>
478 #endif
479
480 typedef $1 testing;
481
482 main() {
483   FILE *f=fopen("conftestval", "w");
484   if (!f) exit(1);
485   if (((testing)((int)((testing)1.4))) == ((testing)1.4)) {
486     fprintf(f, "%s%d\n",
487            ((testing)(-1) < (testing)0) ? "Int" : "Word",
488            sizeof(testing)*8);
489   } else {
490     fprintf(f,"%s\n",
491            (sizeof(testing) >  sizeof(double)) ? "LDouble" :
492            (sizeof(testing) == sizeof(double)) ? "Double"  : "Float");
493   }
494   fclose(f);
495   exit(0);
496 }], AC_CV_NAME=`cat conftestval`,
497 ifelse([$2], , AC_CV_NAME=NotReallyAType,      AC_CV_NAME=$2),
498 ifelse([$3], , AC_CV_NAME=NotReallyATypeCross, AC_CV_NAME=$3))]) dnl
499 AC_MSG_RESULT($AC_CV_NAME)
500 AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME)
501 undefine([AC_TYPE_NAME])dnl
502 undefine([AC_CV_NAME])dnl
503 ])
504
505 dnl ** figure out whether C compiler supports 'long long's
506 dnl    (Closely based on Andreas Zeller's macro for testing
507 dnl     for this under C++)
508 dnl
509 dnl    If the C compiler supports `long long' types,
510 dnl    define `HAVE_LONG_LONG'.
511 dnl
512 AC_DEFUN(FPTOOLS_C_LONG_LONG,
513 [
514 AC_REQUIRE([AC_PROG_CC])
515 AC_MSG_CHECKING(whether ${CC} supports long long types)
516 AC_CACHE_VAL(fptools_cv_have_long_long,
517 [
518 AC_LANG_SAVE
519 AC_LANG_C
520 AC_TRY_COMPILE(,[long long a;],
521 fptools_cv_have_long_long=yes,
522 fptools_cv_have_long_long=no)
523 AC_LANG_RESTORE
524 ])
525 AC_MSG_RESULT($fptools_cv_have_long_long)
526 if test "$fptools_cv_have_long_long" = yes; then
527 AC_DEFINE(HAVE_LONG_LONG)
528 fi
529 ])
530
531 dnl ** Obtain the value of a C constant.
532 dnl    The value will be `(-1)' if the constant is undefined.
533 dnl
534 dnl    This is set up so that the argument can be a shell variable.
535 dnl
536 AC_DEFUN(FPTOOLS_CHECK_CCONST,
537 [
538 eval "def_name=CCONST_$1"
539 eval "cv_name=ac_cv_cconst_$1"
540 AC_MSG_CHECKING(value of $1)
541 AC_CACHE_VAL($cv_name,
542 [AC_TRY_RUN([#include <stdio.h>
543 #include <errno.h>
544 main()
545 {
546   FILE *f=fopen("conftestval", "w");
547   if (!f) exit(1);
548   fprintf(f, "%d\n", $1);
549   exit(0);
550 }], 
551 eval "$cv_name=`cat conftestval`",
552 eval "$cv_name=-1",
553 ifelse([$2], , , eval "$cv_name=$2"))])dnl
554 eval "fptools_check_cconst_result=`echo '$'{$cv_name}`"
555 AC_MSG_RESULT($fptools_check_cconst_result)
556 AC_DEFINE_UNQUOTED($def_name, $fptools_check_cconst_result)
557 unset fptools_check_cconst_result
558 ])
559
560 dnl ** Invoke AC_CHECK_CCONST on each argument (which have to separate with 
561 dnl    spaces)
562 dnl
563 AC_DEFUN(FPTOOLS_CHECK_CCONSTS,
564 [for ac_const_name in $1
565 do
566 FPTOOLS_CHECK_CCONST($ac_const_name)dnl
567 done
568 ])
569
570
571 dnl *** Can we open files in binary mode? ***
572 dnl 
573 AC_DEFUN(FPTOOLS_O_BINARY,
574 [
575 AC_REQUIRE([AC_PROG_CC])
576 AC_MSG_CHECKING(whether we can open files in binary mode)
577 AC_CACHE_VAL(fptools_cv_have_o_binary,
578 [
579 AC_LANG_SAVE
580 AC_LANG_C
581 AC_TRY_COMPILE(,
582 [#ifdef HAVE_FCNTL_H
583 #include <fcntl.h>
584 #endif
585 int x = O_BINARY;],
586 fptools_cv_have_o_binary=yes,
587 fptools_cv_have_o_binary=no)
588 AC_LANG_RESTORE
589 ])
590 AC_MSG_RESULT($fptools_cv_have_o_binary)
591 if test "$fptools_cv_have_o_binary" = yes; then
592 AC_DEFINE(HAVE_O_BINARY)
593 fi
594 ])
595
596 dnl *** Which one comes first, .text or .data? ***
597 dnl 
598 AC_DEFUN(FPTOOLS_CODE_BEFORE_DATA,
599 [AC_CACHE_CHECK([if code section appears before data], fptools_cv_code_bef_data,
600 [AC_TRY_RUN([
601 int f() { return 1; }
602 int i;
603 int main() { return ((char*)&f > (char*)&i); }
604
605 ],
606 fptools_cv_code_bef_data=yes, fptools_cv_code_bef_data=no,false)])
607 if test "$fptools_cv_code_bef_data" = yes; then
608   AC_DEFINE(CODE_BEFORE_DATA)
609 fi
610 ])
611
612 dnl *** Helper function **
613 dnl 
614 AC_DEFUN(FPTOOLS_IN_SCOPE,AC_TRY_LINK([extern char* $1;],[return (int)&$2], $3=yes, $3=no))
615
616 dnl *** What's the end-of-text-section marker called? ***
617 dnl
618 AC_DEFUN(FPTOOLS_END_TEXT_SECTION,
619 [AC_MSG_CHECKING([for end of text section marker])
620 not_done=1
621 for i in data_start _data_start etext _etext __etext; do
622   FPTOOLS_IN_SCOPE($i,$i,fptools_end_of_text)
623   if test "$fptools_end_of_text" = yes; then
624    AC_CACHE_VAL([fptools_cv_end_of_text_decl], AC_DEFINE_UNQUOTED(TEXT_SECTION_END_MARKER_DECL, $i))
625    AC_CACHE_VAL([fptools_cv_end_of_text], AC_DEFINE_UNQUOTED(TEXT_SECTION_END_MARKER, $i))
626    not_done=0
627    break
628   fi
629 done
630 if test "$not_done" = 1; then
631 FPTOOLS_IN_SCOPE(etext asm("etext"),etext,fptools_end_of_text);
632 if test "$fptools_end_of_text" = yes; then
633   AC_CACHE_VAL([fptools_cv_end_of_text], AC_DEFINE_UNQUOTED(TEXT_SECTION_END_MARKER, etext))
634   AC_CACHE_VAL([fptools_cv_end_of_text_decl], AC_DEFINE_UNQUOTED(TEXT_SECTION_END_MARKER_DECL, etext asm("etext")))
635 else
636   AC_DEFINE_UNQUOTED(TEXT_SECTION_END_MARKER_DECL, dunno_what_it_is)
637   AC_DEFINE_UNQUOTED(TEXT_SECTION_END_MARKER, dunno_what_it_is)
638 fi
639 fi
640 AC_MSG_RESULT([$]fptools_cv_end_of_text)
641 ])
642
643 dnl *** What's the end-of-data-section marker called? ***
644 dnl
645 AC_DEFUN(FPTOOLS_END_DATA_SECTION,
646 [AC_MSG_CHECKING([for end of data section marker])
647 not_done=1
648 for i in end _end __end; do
649   FPTOOLS_IN_SCOPE($i,$i,fptools_end_of_data)
650   if test "$fptools_end_of_data" = yes; then
651    AC_CACHE_VAL([fptools_cv_end_of_data_decl], [AC_DEFINE_UNQUOTED(DATA_SECTION_END_MARKER_DECL, $i)])
652    AC_CACHE_VAL([fptools_cv_end_of_data], [AC_DEFINE_UNQUOTED(DATA_SECTION_END_MARKER, $i)])
653    not_done=0
654    break
655   fi
656 done
657 if test "$not_done" = 1; then
658 FPTOOLS_IN_SCOPE(end asm("end"),end,fptools_end_of_data);
659 if test "$fptools_end_of_data" = yes; then
660   AC_CACHE_VAL([fptools_cv_end_of_data_decl], [AC_DEFINE_UNQUOTED(DATA_SECTION_END_MARKER_DECL, end asm("end"))])
661   AC_CACHE_VAL([fptools_cv_end_of_data], [AC_DEFINE_UNQUOTED(DATA_SECTION_END_MARKER, end)])
662 else
663   AC_CACHE_VAL([fptools_cv_end_of_data_decl], [AC_DEFINE_UNQUOTED(DATA_SECTION_END_MARKER_DECL, dunno_what_it_is)])
664   AC_CACHE_VAL([fptools_cv_end_of_data], [AC_DEFINE_UNQUOTED(DATA_SECTION_END_MARKER, dunno_what_it_is)])
665 fi
666 fi
667 AC_MSG_RESULT([$]fptools_cv_end_of_data)
668 ])
669
670
671
672 dnl Based on AC_TRY_LINK - run iftrue if links cleanly with no warning
673
674 dnl FPTOOLS_TRY_LINK_NOWARN(flags,main?,iftrue,iffalse)
675
676 AC_DEFUN(FPTOOLS_TRY_LINK_NOWARN,
677 [
678 ac_save_LIBS="$LIBS"
679 LIBS=[$1];
680 cat > conftest.$ac_ext <<EOF
681 dnl This sometimes fails to find confdefs.h, for some reason.
682 dnl [#]line __oline__ "[$]0"
683 [#]line __oline__ "configure"
684 #include "confdefs.h"
685 [$2]
686 int t() { return 0; }
687 EOF
688 if AC_TRY_EVAL(ac_link); then
689   ifelse([$3], , :, [
690     LIBS="$ac_save_LIBS"
691     rm -rf conftest*
692     $3])
693   ifelse([$4], , , [else
694     LIBS="$ac_save_LIBS"
695     rm -rf conftest*
696     $4
697 ])dnl
698 fi
699 rm -f conftest*
700 ]
701 )
702
703 dnl Loosely based on AC_CHECK_LIB in acgeneral.m4 in autoconf distribution
704
705 dnl FPTOOLS_CHECK_FLAG_NOWARN(NAME, FLAG, CODE, iftrue, iffalse)
706
707 AC_DEFUN(FPTOOLS_CHECK_FLAG_NOWARN,
708 [AC_MSG_CHECKING([for $1])
709  AC_CACHE_VAL(ac_cv_flag_$1,
710    [FPTOOLS_TRY_LINK_NOWARN("$2", [main() { $3; exit(0); } ],
711      eval "ac_cv_flag_$1=yes",
712      eval "ac_cv_flag_$1=no"
713    )]
714  )
715 if eval "test \"`echo '$ac_cv_flag_'$1`\" = yes"; then
716   AC_MSG_RESULT(yes)
717   LIBS="$2 $LIBS"
718   $4
719 else
720   AC_MSG_RESULT(no)
721   $5
722 fi
723 ])
724
725 dnl FPTOOLS_CHECK_LIB_NOWARN(LIBRARY, FUNCTION)
726
727 AC_DEFUN(FPTOOLS_CHECK_LIB_NOWARN,
728 [FPTOOLS_CHECK_FLAG_NOWARN([function_$2],[],[extern char $2(); $2();],
729 [changequote(, )dnl
730   ac_tr_lib=HAVE_LIB`echo $1 | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
731  changequote([, ])dnl
732  AC_DEFINE_UNQUOTED($ac_tr_lib)
733 ],
734 [FPTOOLS_CHECK_FLAG_NOWARN([library_$1],[-l$1],[extern char $2(); $2();],
735 [changequote(, )dnl
736   ac_tr_lib=HAVE_LIB`echo $1 | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
737  changequote([, ])dnl
738  AC_DEFINE_UNQUOTED($ac_tr_lib)
739 ],
740 []
741 )])]
742 )
743
744 dnl check for prototypes
745 dnl
746 AC_DEFUN(AC_C_PROTOTYPES,
747 [AC_CACHE_CHECK([prototypes], ac_cv_prototypes,
748 [AC_TRY_COMPILE([
749 void foo(int);
750 void foo(i)
751 int i; { 
752 return;
753 }
754 ],
755 [int i;], 
756 ac_cv_prototypes=yes,
757 ac_cv_prototypes=no)])
758 if test "$ac_cv_prototypes" = yes; then
759 AC_DEFINE(HAVE_PROTOTYPES)
760 fi
761 ])
762
763 dnl ** Check which CATALOG file we have to use with DocBook SGML.
764 dnl
765 dnl FPTOOLS_DOCBOOK_CATALOG(VARIABLE, JADE, STYLESHEET, CATALOGS-TO-CHECK-FOR)
766 dnl
767 dnl If any of the catalogs given in CATALOGS-TO-CHECK-FOR works on this
768 dnl platform, let VARIABLE refer to this catalog; otherwise, VARIABLE
769 dnl is set to "no".  JADE is the jade executable and STYLESHEET
770 dnl a DocBook style sheet.
771 dnl
772 AC_DEFUN(FPTOOLS_DOCBOOK_CATALOG,
773 [AC_CACHE_CHECK([for DocBook CATALOG], fptools_cv_sgml_catalog,
774 [
775 cat > conftest.sgml << EOF
776 <!DOCTYPE Article PUBLIC "-//OASIS//DTD DocBook V3.1//EN">
777 <Article>
778 <ArtHeader>
779 <Title>Test</Title>
780 <Author><OtherName>Test</OtherName></Author>
781 <Address>Test</Address>
782 <PubDate>Test</PubDate>
783 </ArtHeader>
784 <Sect1><Title>Test</Title>
785 <Para>
786 Test.
787 </Para>
788 </Sect1>
789 </Article>
790 EOF
791 fptools_cv_sgml_catalog=no
792 for fptools_catalog in $4; do
793   ac_try="$2 -t rtf -d $3#print -c $fptools_catalog conftest.sgml"
794   if AC_TRY_EVAL(ac_try); then
795     fptools_cv_sgml_catalog=[$]fptools_catalog
796     break
797   fi
798 done
799 ])
800 rm -rf conftest*
801 if test $fptools_cv_sgml_catalog != "no"; then
802   $1=$fptools_cv_sgml_catalog
803 fi
804 ])
805
806 dnl ######################################################################
807 dnl FPTOOLS_SEARCH_LIBS(INCLUDES, FUNCTION, SEARCH-LIBS [, ACTION-IF-FOUND
808 dnl                     [, ACTION-IF-NOT-FOUND [, OTHER-LIBRARIES]]])
809 dnl Search for a library defining FUNC, if it's not already available.
810 dnl This is almost the same as AC_SEARCH_LIBS, but the INCLUDES can be
811 dnl specified.
812 dnl ######################################################################
813
814 AC_DEFUN(FPTOOLS_SEARCH_LIBS,
815 [AC_PREREQ([2.13])
816 AC_CACHE_CHECK([for library containing $2], [ac_cv_search_$2],
817 [ac_func_search_save_LIBS="$LIBS"
818 ac_cv_search_$2="no"
819 AC_TRY_LINK([$1], [$2()], [ac_cv_search_$2="none required"])
820 test "$ac_cv_search_$2" = "no" && for i in $3; do
821 LIBS="-l$i $6 $ac_func_search_save_LIBS"
822 AC_TRY_LINK([$1], [$2()],
823 [ac_cv_search_$2="-l$i"
824 break])
825 done
826 LIBS="$ac_func_search_save_LIBS"])
827 if test "$ac_cv_search_$2" != "no"; then
828   test "$ac_cv_search_$2" = "none required" || LIBS="$ac_cv_search_$2 $LIBS"
829   $4
830 else :
831   $5
832 fi])
833
834 dnl ####################### -*- Mode: M4 -*- ###########################
835 dnl Copyright (C) 98, 1999 Matthew D. Langston <langston@SLAC.Stanford.EDU>
836 dnl
837 dnl This file is free software; you can redistribute it and/or modify it
838 dnl under the terms of the GNU General Public License as published by
839 dnl the Free Software Foundation; either version 2 of the License, or
840 dnl (at your option) any later version.
841 dnl
842 dnl This file is distributed in the hope that it will be useful, but
843 dnl WITHOUT ANY WARRANTY; without even the implied warranty of
844 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
845 dnl General Public License for more details.
846 dnl
847 dnl You should have received a copy of the GNU General Public License
848 dnl along with this file; if not, write to:
849 dnl
850 dnl   Free Software Foundation, Inc.
851 dnl   Suite 330
852 dnl   59 Temple Place
853 dnl   Boston, MA 02111-1307, USA.
854 dnl ####################################################################
855
856
857 dnl @synopsis FPTOOLS_CHECK_LIBM
858 dnl 
859 dnl Search for math library (typically -lm).
860 dnl
861 dnl The variable LIBM (which is not an output variable by default) is
862 dnl set to a value which is suitable for use in a Makefile (for example,
863 dnl in make's LOADLIBES macro) provided you AC_SUBST it first.
864 dnl
865 dnl @version 0.01 $Id: aclocal.m4,v 1.68 2001/03/13 14:59:56 simonmar Exp $
866 dnl @author Matthew D. Langston <langston@SLAC.Stanford.EDU>
867
868 # FPTOOLS_CHECK_LIBM - check for math library
869 AC_DEFUN(FPTOOLS_CHECK_LIBM,
870 [AC_REQUIRE([AC_CANONICAL_HOST])dnl
871 LIBM=
872 case "$host" in
873 *-*-beos* | *-*-macosx*)
874   # These system don't have libm
875   ;;
876 *-ncr-sysv4.3*)
877   AC_CHECK_LIB(mw, _mwvalidcheckl, LIBM="-lmw")
878   AC_CHECK_LIB(m, main, LIBM="$LIBM -lm")
879   ;;
880 *)
881   AC_CHECK_LIB(m, main, LIBM="-lm")
882   ;;
883 esac
884 ])
885
886 dnl ######################################################################
887 dnl NOTE: Because of portability issues between different autoconf
888 dnl versions the AC_HELP_STRING macro has been removed from FPTOOLS_HAVE_OPENGL.
889 dnl Furthermore, caching has been completely rewritten.
890 dnl ######################################################################
891
892 dnl ########################### -*- Mode: M4 -*- #######################
893 dnl Copyright (C) 98, 1999 Matthew D. Langston <langston@SLAC.Stanford.EDU>
894 dnl
895 dnl This file is free software; you can redistribute it and/or modify it
896 dnl under the terms of the GNU General Public License as published by
897 dnl the Free Software Foundation; either version 2 of the License, or
898 dnl (at your option) any later version.
899 dnl
900 dnl This file is distributed in the hope that it will be useful, but
901 dnl WITHOUT ANY WARRANTY; without even the implied warranty of
902 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
903 dnl General Public License for more details.
904 dnl
905 dnl You should have received a copy of the GNU General Public License
906 dnl along with this file; if not, write to:
907 dnl
908 dnl   Free Software Foundation, Inc.
909 dnl   Suite 330
910 dnl   59 Temple Place
911 dnl   Boston, MA 02111-1307, USA.
912 dnl ####################################################################
913
914 dnl @synopsis FPTOOLS_HAVE_OPENGL
915 dnl 
916 dnl Search for OpenGL.  We search first for Mesa (a GPL'ed version of
917 dnl OpenGL) before a vendor's version of OpenGL, unless we were
918 dnl specifically asked not to with `--with-Mesa=no' or `--without-Mesa'.
919 dnl
920 dnl The four "standard" OpenGL libraries are searched for: "-lGL",
921 dnl "-lGLU", "-lGLX" (or "-lMesaGL", "-lMesaGLU" as the case may be) and
922 dnl "-lglut".
923 dnl
924 dnl All of the libraries that are found (since "-lglut" or "-lGLX" might
925 dnl be missing) are added to the shell output variable "GL_LIBS", along
926 dnl with any other libraries that are necessary to successfully link an
927 dnl OpenGL application (e.g. the X11 libraries).  Care has been taken to
928 dnl make sure that all of the libraries in "GL_LIBS" are listed in the
929 dnl proper order.
930 dnl
931 dnl Additionally, the shell output variable "GL_CFLAGS" is set to any
932 dnl flags (e.g. "-I" flags) that are necessary to successfully compile
933 dnl an OpenGL application.
934 dnl
935 dnl The following shell variable (which are not output variables) are
936 dnl also set to either "yes" or "no" (depending on which libraries were
937 dnl found) to help you determine exactly what was found.
938 dnl
939 dnl   have_GL
940 dnl   have_GLU
941 dnl   have_GLX
942 dnl   have_glut
943 dnl
944 dnl A complete little toy "Automake `make distcheck'" package of how to
945 dnl use this macro is available at:
946 dnl
947 dnl   ftp://ftp.slac.stanford.edu/users/langston/autoconf/ac_opengl-0.01.tar.gz
948 dnl
949 dnl Please note that as the ac_opengl macro and the toy example evolves,
950 dnl the version number increases, so you may have to adjust the above
951 dnl URL accordingly.
952 dnl
953 dnl @version 0.01 $Id: aclocal.m4,v 1.68 2001/03/13 14:59:56 simonmar Exp $
954 dnl @author Matthew D. Langston <langston@SLAC.Stanford.EDU>
955
956 AC_DEFUN(FPTOOLS_HAVE_OPENGL,
957 [
958   AC_REQUIRE([AC_PROG_CC])
959   AC_REQUIRE([AC_PATH_X])
960   AC_REQUIRE([AC_PATH_XTRA])
961   AC_REQUIRE([FPTOOLS_CHECK_LIBM])
962
963 dnl Check for Mesa first, unless we were asked not to.
964 dnl    AC_HELP_STRING([--with-Mesa],
965 dnl                   [Prefer the Mesa library over a vendors native OpenGL library (default=yes)],
966 dnl                   with_Mesa_help_string)
967 dnl    AC_ARG_ENABLE(Mesa, $with_Mesa_help_string, use_Mesa=$enableval, use_Mesa=yes)
968   AC_ARG_ENABLE(Mesa, [  --with-Mesa             Prefer the Mesa library over a vendors native OpenGL library (default=yes)], use_Mesa=$enableval, use_Mesa=yes)
969
970   if test x"$use_Mesa" = xyes; then
971      GL_search_list="MesaGL  GL  opengl32"
972     GLU_search_list="MesaGLU GLU glu32"
973     GLX_search_list="MesaGLX GLX"
974   else
975      GL_search_list="GL  opengl32 MesaGL"
976     GLU_search_list="GLU glu32    MesaGLU"
977     GLX_search_list="GLX          MesaGLX"
978   fi      
979
980   AC_LANG_SAVE
981   AC_LANG_C
982
983 dnl If we are running under X11 then add in the appropriate libraries.
984   if ! test x"$no_x" = xyes; then
985 dnl Add everything we need to compile and link X programs to GL_CFLAGS
986 dnl and GL_X_LIBS.
987     GL_CFLAGS="$X_CFLAGS"
988     GL_X_LIBS="$X_PRE_LIBS $X_LIBS -lX11 -lXext -lXmu -lXt -lXi $X_EXTRA_LIBS $LIBM"
989   fi
990   GL_save_CPPFLAGS="$CPPFLAGS"
991   CPPFLAGS="$GL_CFLAGS"
992
993   GL_save_LIBS="$LIBS"
994   LIBS="$GL_X_LIBS"
995
996   FPTOOLS_SEARCH_LIBS([#include <GL/gl.h>],   glEnd,           $GL_search_list,  have_GL=yes,   have_GL=no)
997   FPTOOLS_SEARCH_LIBS([#include <GL/glu.h>],  gluNewQuadric,   $GLU_search_list, have_GLU=yes,  have_GLU=no)
998   FPTOOLS_SEARCH_LIBS([#include <GL/glx.h>],  glXChooseVisual, $GLX_search_list, have_GLX=yes,  have_GLX=no)
999   FPTOOLS_SEARCH_LIBS([#include <GL/glut.h>], glutMainLoop,    glut glut32,      have_glut=yes, have_glut=no)
1000
1001   if test -n "$LIBS"; then
1002     GL_LIBS="$LIBS"
1003   else
1004     GL_LIBS=
1005     GL_CFLAGS=
1006   fi
1007
1008   AC_CACHE_CHECK([OpenGL flags], mdl_cv_gl_cflags, [mdl_cv_gl_cflags="$GL_CFLAGS"])
1009   GL_CFLAGS="$mdl_cv_gl_cflags"
1010   AC_SUBST(GL_CFLAGS)
1011   AC_CACHE_CHECK([OpenGL libs],  mdl_cv_gl_libs,   [mdl_cv_gl_libs="$GL_LIBS"])
1012   GL_LIBS="$mdl_cv_gl_libs"
1013   AC_SUBST(GL_LIBS)
1014
1015 dnl Reset GL_X_LIBS regardless, since it was just a temporary variable
1016 dnl and we don't want to be global namespace polluters.
1017   GL_X_LIBS=
1018
1019   LIBS="$GL_save_LIBS"
1020   CPPFLAGS="$GL_save_CPPFLAGS"
1021
1022   AC_LANG_RESTORE
1023 ])
1024
1025 # LocalWords:  fi