aboutsummaryrefslogtreecommitdiff
path: root/config/open-axiom.m4
blob: 2397ab78078af0450bf381dededadfcf3a2baf90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
dnl ------------------------
dnl -- OPENAXIOM_MAKEFILE --
dnl ------------------------
AC_DEFUN([OPENAXIOM_MAKEFILE],
[AC_CONFIG_FILES([$1:config/var-def.mk:$1.in:config/setup-dep.mk])])

dnl --------------------------------
dnl -- OPENAXIOM_CANONICAL_SYSTEM --
dnl --------------------------------
AC_DEFUN([OPENAXIOM_CANONICAL_SYSTEM],[
AC_CANONICAL_SYSTEM

AC_SUBST(oa_src_srcdir,'$(top_srcdir)/src')
AC_SUBST(oa_src_docdir,'$(oa_src_srcdir)/doc')
AC_SUBST(oa_src_datadir,'$(oa_src_srcdir)/share')
AC_SUBST(oa_src_algdir,'$(oa_src_srcdir)/algebra')
AC_SUBST(oa_src_texdir,'$(oa_src_datadir)/tex')

AC_SUBST(oa_targetdir,'$(top_builddir)/$(target)')
AC_SUBST(oa_target_bindir,'$(oa_targetdir)/bin')
AC_SUBST(oa_target_libdir,'$(oa_targetdir)/lib')
AC_SUBST(oa_target_srcdir,'$(oa_targetdir)/src')
AC_SUBST(oa_target_docdir,'$(oa_targetdir)/doc')
AC_SUBST(oa_target_datadir,'$(oa_targetdir)/share')
AC_SUBST(oa_target_texdir,'$(oa_target_datadir)/texmf/tex')
AC_SUBST(oa_target_includedir,'$(oa_targetdir)/include')

AC_SUBST(oa_configdir,'$(top_builddir)/config')
AC_SUBST(oa_c_macros,'$(oa_configdir)/axiom-c-macros.h')
])

dnl ----------------------
dnl -- OPENAXIOM_SHELLS --
dnl ----------------------
dnl Check for shell availability, specifically PowerShell on 
dnl Windows platforms.
AC_DEFUN([OPENAXIOM_SHELLS],[
AC_SYS_INTERPRETER
case $host in
  *mingw*)
     AC_PATH_PROG([OA_WINDOWS_POWERSHELL],[powershell.exe])
     ;;
esac
])

dnl ------------------------------------------
dnl -- OPENAXIOM_CHECK_FOR_ADDITIONAL_PATHS --
dnl ------------------------------------------
AC_DEFUN([OPENAXIOM_CHECK_FOR_ADDITIONAL_PATHS],[
# If there is a MacPort installation of QT5, use it.
case $host in
     *darwin*)
	if test -d /opt/local/libexec/qt5; then
	   PATH=/opt/local/libexec/qt5/bin:$PATH
	fi
	;;
esac
])

dnl ----------------------------------
dnl -- OPENAXIOM_REJECT_ROTTED_LISP --
dnl ----------------------------------
dnl Check for Lisp systems we know are just too buggy for use.
AC_DEFUN([OPENAXIOM_REJECT_ROTTED_LISP],[
if test x"$oa_include_gcl" != xyes; then
   case $OA_LISP in
      *gcl*)
	 AC_MSG_CHECKING([$OA_LISP version])
	 oa_lisp_version=`$OA_LISP -batch -eval "(format t \"~S\" (lisp-implementation-version))"`
	 AC_MSG_RESULT([$oa_lisp_version])
	 case $oa_lisp_version in
	   *2.6.7*|*2.6.8*|*2.6.9*|*2.6.10*) ;;         # OK
	   *)
	     AC_MSG_WARN([$oa_lisp_version is not supported by this version of OpenAxiom.])
	     ;;
	 esac
	 ;;
      # SBCL-1.0.29 has a nasty regression that prevents OpenAxiom build
      *sbcl*)
	 AC_MSG_CHECKING([$OA_LISP version])
	 oa_lisp_version=`$OA_LISP --version`
	 AC_MSG_RESULT([$oa_lisp_version])
	 case $oa_lisp_version in
	   *1.0.29)
	      AC_MSG_ERROR([This version of SBCL has a bug that breaks OpenAxiom build.  Consider SBCL-1.0.30 or higher.])
	      ;;
	 esac
	 ;;
   esac
fi
])

dnl -------------------------
dnl -- OPENAXIOM_PROG_LISP --
dnl -------------------------
dnl Find the host Lisp compiler to use
AC_DEFUN([OPENAXIOM_PROG_LISP],[
## Was a host Lisp system specified?
oa_user_lisp=
AC_ARG_WITH([lisp], [ --with-lisp=L         use L as Lisp platform],
              [oa_user_lisp=$withval])

## For all values of L, except gcl, the assumption is that the Lisp
## image L is available in the build environment.  For  gcl,
## we make an exception: if no GCL image is available, or if
## the option --enable-gcl is specified then OpenAxiom builds its 
## own version from the source tree.
## If --enable-gcl is specified, we need to check for coonsistency
oa_include_gcl=
AC_ARG_ENABLE([gcl], [  --enable-gcl            build GCL from OpenAxiom source],
	      [case $enableval in
		   yes|no) oa_include_gcl=$enableval ;;
		   *) AC_MSG_ERROR([erroneous value for --enable-gcl]) ;;
	       esac])

## If nothing was said about preferred Lisp, guess one.
AC_SUBST(OA_LISP)
if test -n "$oa_user_lisp"; then
    ## Honor use of Lisp image specified on command line
    OA_LISP=$oa_user_lisp
elif test -z "$oa_include_gcl"; then
    AC_CHECK_PROGS([OA_LISP], [sbcl gcl ecl clisp ccl64 ccl32 ccl])
fi
])

dnl -----------------------------------
dnl -- OPENAXIOM_CHECK_GCL_INCLUSION --
dnl -----------------------------------
dnl Check for consistency of configure options when GCL is requested.
AC_DEFUN([OPENAXIOM_CHECK_GCL_INCLUSION],[
case $oa_include_gcl,$OA_LISP in
    no,)
       ## It doesn't make sense not to include GCL when no Lisp image
       ## is available.  Give up.
       AC_MSG_ERROR([--disable-gcl specified but no Lisp system found])
       ;;

    ,|yes,)
       ## No Lisp image was specified and none was available from
       ## the build environment; build GCL from OpenAxiom source.
       ## User may explicilty specify --enable-gcl, but may be missing
       ## the dependency tarball.
       if test -d ${srcdir}/gcl; then
	  OA_LISP='$(oa_build_bindir)/gcl'
	  oa_include_gcl=yes
       elif test -z "$oa_include_gcl"; then
	  AC_MSG_ERROR([OpenAxiom requires a Lisp system.  Either separately build one (GCL-2.6.7, GCL-2.6.8, SBCL, ECL, CLisp, Clozure CL), or get the dependency tarball from OpenAxiom download website.])
       else
          AC_MSG_ERROR([The OpenAxiom dependency tarball is missing; please get it from our website.])
       fi
       ;;
    yes,*)
       AC_MSG_ERROR([--with-lisp=$OA_LISP conflicts with --enable-gcl])
       ;;
esac
])

dnl ---------------------------
dnl -- OPENAXIOM_LISP_FLAVOR --
dnl ---------------------------
dnl Determine the flavor of the host Lisp system.
AC_DEFUN([OPENAXIOM_LISP_FLAVOR],[
OPENAXIOM_CHECK_GCL_INCLUSION

oa_lisp_flavor=unknown
AC_SUBST(oa_lisp_flavor)
 
## Most Lisp systems don't use conventional methods for building programs.
oa_standard_linking=no
AC_SUBST(oa_standard_linking)
oa_lnkext='$(FASLEXT)'
## The pipe below is OK, for as of this writting, the free Lisp systems
##  ECL, GCL, SBCL, CLisp, and Clozure CL all exit at end of standard input.
AC_MSG_CHECKING([which flavor of Lisp])
if test x"$oa_include_gcl" = xyes; then
   oa_lisp_flavor=gcl
else
   case `echo '(lisp-implementation-type)' | $OA_LISP` in
       *GCL*) 
	   oa_lisp_flavor=gcl
	   ;;
       *"ECL"*) 
	   oa_lisp_flavor=ecl 
	   oa_standard_linking=yes
	   oa_lnkext='$(OBJEXT)'
	   ;;
       *"SBCL"*) 
	   oa_lisp_flavor=sbcl 
	   ;;
       *"CLISP"*)
	   ## Not all variants of CLisp have FFI support.  FFI is used
	   ## internally used by OpenAxiom in essential way.
	   if ! $OA_LISP -q -x '*features*' | grep ':FFI' > /dev/null
	   then
	     AC_MSG_ERROR([$OA_LISP does not support Foreign Function Interface.  Please upgrade to a better version of CLisp or install SBCL.])
	   fi
	   oa_lisp_flavor=clisp
	   ;;
       *"Armed Bear Common Lisp"*) 
	   oa_lisp_flavor=abcl 
	   ;;
       *"Clozure Common Lisp"*)
	   oa_lisp_flavor=clozure
	   ;;
   esac
fi
AC_MSG_RESULT([$oa_lisp_flavor])
AM_CONDITIONAL([OA_ECL_RT],[test $oa_lisp_flavor = ecl])
AM_CONDITIONAL([OA_GCL_RT],[test $oa_lisp_flavor = gcl])
AM_CONDITIONAL([OA_STANDARD_LINKING],[test $oa_standard_linking = yes])

AC_DEFINE_UNQUOTED([OPENAXIOM_BASE_RTS],
                   [Runtime::${oa_lisp_flavor}],
                   [The kind of base runtime system for this build.])
AC_SUBST(LNKEXT,[$oa_lnkext])
])

dnl ---------------------------------
dnl -- OPENAXIOM_CHECK_DELAYED_FFI --
dnl ---------------------------------
dnl Check whether loading modules for dynamic FFI support
dnl should be delayed to runtime.  This is needed for Lisp
dnl systems that have trouble with DLLs.
AC_DEFUN([OPENAXIOM_CHECK_DELAYED_FFI], [
case ${oa_lisp_flavor},$host in
  sbcl,* | clozure,* | clisp,*) 
     oa_delay_ffi=yes
     ;;
  *)
     oa_delay_ffi=no
     ;;
esac
AC_SUBST([oa_delay_ffi])
])

dnl --------------------------------------------
dnl -- OPENAXIOM_CPPFLAGS_FOR_VENDOR_LOCK_INS --
dnl --------------------------------------------
dnl Adjust CPPFLAGS before detecting several vendor lock-ins (or not.)
AC_DEFUN([OPENAXIOM_CPPFLAGS_FOR_VENDOR_LOCK_INS],[
case $host in
  *linux*)
     CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
     ;;
  *bsd*|*dragonfly*)
     CPPFLAGS="$CPPFLAGS -D_BSD_SOURCE"
     ;;
  *mingw*)
     CPPFLAGS="$CPPFLAGS -DOPENAXIOM_MS_WINDOWS_HOST"
     ;;
  *solaris*)
     ## FIXME: This should disappear
     CPPFLAGS="$CPPFLAGS -DSUNplatform"
     ;;
esac
])

dnl -----------------------------
dnl -- OPENAXIOM_REQUIRE_CXX14 --
dnl -----------------------------
AC_DEFUN([OPENAXIOM_REQUIRE_CXX14],[
oa_saved_cxxflags=$CXXFLAGS
CXXFLAGS="-std=c++14"
AC_MSG_CHECKING([whether $CXX supports $CXXFLAGS])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
  [AC_MSG_RESULT([yes])]
  [CXXFLAGS="$CXXFLAGS $oa_saved_cxxflags"],
  [AC_MSG_ERROR([OpenAxiom requires a C++11 compiler])])
])

dnl -------------------------------
dnl -- OPENAXIOM_CXX_GROK_OPTION --
dnl -------------------------------
dnl Check whether the C++ compiler accepts a given option.
dnl In case of success, augment the accumulator passed in
dnl (optional) second argument -- default: CXXFLAGS.
AC_DEFUN([OPENAXIOM_CXX_GROK_OPTION], [
opt=$1				      # mandatory
accumulator=$2			      # optional
if test -z $accumulator; then
   accumulator=CXXFLAGS
fi
current_options=\$${accumulator}
oa_saved_cxxflags="$CXXFLAGS"
AC_MSG_CHECKING([whether $CXX supports "$opt"])
CXXFLAGS="$CXXFLAGS $opt"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
	[AC_MSG_RESULT([yes])]
	[CXXFLAGS=$oa_saved_cxxflags]
	[eval "$accumulator=\"$current_options $opt\""],
	[AC_MSG_RESULT([no])]
	[CXXFLAGS=$oa_saved_cxxflags])
])


dnl --------------------------
dnl -- OPENAXIOM_CHECK_LLVM --
dnl --------------------------
dnl Do we have recent enough LLVM?
AC_DEFUN([OPENAXIOM_CHECK_LLVM],[
oa_use_llvm=no
AC_CHECK_PROGS([LLVM_CONFIG],[llvm-config])
if test -n "$LLVM_CONFIG"; then
  case `$LLVM_CONFIG --version` in
    3.[[5-9]].*)
      oa_use_llvm=yes
      ;;
    *)
       ;;
  esac
  AC_DEFINE_UNQUOTED([OPENAXIOM_HOST_HAS_LLVM],[],[Host has LLVM.])
fi
AC_SUBST(oa_use_llvm)
])

dnl ------------------------------
dnl -- OPENAXIOM_HOST_COMPILERS --
dnl ------------------------------
dnl Check for the host C, C++, and Lisp compilers
AC_DEFUN([OPENAXIOM_HOST_COMPILERS],[
OPENAXIOM_PROG_LISP
OPENAXIOM_LISP_FLAVOR
OPENAXIOM_REJECT_ROTTED_LISP
OPENAXIOM_HOST_LISP_CPU_PRECISION
OPENAXIOM_CHECK_DELAYED_FFI
## Force Clang on Apple platforms; that is the only way we get
## anything sane going on on this fine platform.
case $host in
   *apple*)
        oa_cc_list="clang"
        oa_cxx_list="clang++"
       ;;
   *)
        oa_cc_list="gcc clang cc"
        oa_cxx_list="g++ clang++ CC c++"
       ;;
esac
AC_PROG_CC([$oa_cc_list])
AC_PROG_CXX([$oa_cxx_list])
## Where are the compilers coming from?  GNU? Clang?
oa_cxx_compiler_lineage=unknown
case `$CXX -v` in
   *clang*) 
       oa_cxx_compiler_lineage=clang
       ;;
   *)
       if test x$GCC = xyes || test x$GXX = xyes; then
          oa_cxx_compiler_lineage=gnu
       fi
       ;;
esac
   
## Augment C and C++ compiler flags with ABI directives as appropriate
## before we proceed to infer other host datatype properties.
if test -n "$oa_host_lisp_precision"; then
   if test $oa_cxx_compiler_lineage = gnu; then
     CPPFLAGS="$CPPFLAGS -m$oa_host_lisp_precision"
     LDFLAGS="$LDFLAGS -m$oa_host_lisp_precision"
   ## else, cross fingers and pray.
   fi
fi
OPENAXIOM_SATISFY_GCL_NEEDS
AC_PROG_CPP
AC_PROG_CXXCPP
OPENAXIOM_CPPFLAGS_FOR_VENDOR_LOCK_INS
OPENAXIOM_CHECK_LLVM
])

dnl ---------------------------------
dnl -- OPENAXIOM_CXX_EXTRA_OPTIONS --
dnl ---------------------------------
AC_DEFUN([OPENAXIOM_EXTRA_CXX_OPTIONS], [
oa_extra_cxxflags=
OPENAXIOM_CXX_GROK_OPTION([-Wno-mismatched-tags],[oa_extra_cxxflags])
OPENAXIOM_CXX_GROK_OPTION([-Wno-string-plus-int],[oa_extra_cxxflags])

AC_SUBST(oa_extra_cxxflags)
])

dnl ---------------------------------
dnl -- OPENAXIOM_SATISFY_GCL_NEEDS --
dnl ---------------------------------
dnl GCL assumes that the C compiler is from GNU.
AC_DEFUN([OPENAXIOM_SATISFY_GCL_NEEDS],[
## If we are using GCL as the base runtime system, then we do really need
## a C compiler from GNU.  Well, at least for the moment.
case $oa_lisp_flavor,$oa_cxx_compiler_lineage in
   gcl,gnu)
       oa_cflags="-O2 -Wall -D_GNU_SOURCE"
       ;;
   
   gcl,*)
       AC_MSG_ERROR([We need a GNU C compiler])
       ;;
esac
AC_SUBST(oa_cflags)
])

dnl ---------------------------------
dnl -- OPENAXIOM_GCL_BUILD_OPTIONS --
dnl ---------------------------------
dnl Determine options needed to build included GCL, if need be.
AC_DEFUN([OPENAXIOM_GCL_BUILD_OPTIONS],[
oa_host_has_libbfd=
## Check for these only if we are going to build GCL from source.
if test x"$oa_include_gcl" = xyes; then
    AC_CHECK_HEADER([bfd.h])
    AC_HAVE_LIBRARY([bfd], [oa_host_has_libbfd=yes])

    oa_gcl_bfd_option=
    if test x"$ac_cv_header_bfd_h" = xyes \
	&& test x"$oa_host_has_libbfd" = xyes; then
	oa_gcl_bfd_option="--disable-dynsysbfd"
    else
	oa_gcl_bfd_option="--disable-statsysbfd"
    fi
fi

case $host in
   powerpc*darwin*)
      axiom_gcl_bfd_option="--disable-statsysbfd \
                                --enable-machine=powerpc-macosx"
      axiom_gcl_mm_option="--enable-vssize=65536*2"
      ;;
esac

## We don't need GCL to build support for X Window system or TCL/TK:
oa_gcl_x_option="--disable-tkconfig --disable-x --disable-xgcl --disable-tcltk"

GCLOPTS="$oa_gcl_bfd_option $oa_gcl_mm_option $oa_gcl_x_option"
AC_SUBST(GCLOPTS)
])

dnl --------------------------
dnl -- OPENAXIOM_LISP_FLAGS --
dnl --------------------------
dnl Determine how to invoke the host Lisp system in batch mode.
dnl We also take the opportunity to determine whether we can use
dnl dynamically loaded modules.
AC_DEFUN([OPENAXIOM_LISP_FLAGS],[
AC_SUBST(oa_quiet_flags)
AC_SUBST(oa_eval_flags)

## Can we use dynamically linked libraries?  
## Tentatively answer `yes' -- this is modern time.
oa_use_dynamic_lib=yes
AC_SUBST(oa_use_dynamic_lib)

## How are we supposed to tell the Lisp system to eval an expression
## in batch mode?  What is the extension of a compiled Lisp file?
case $oa_lisp_flavor in
    gcl) 
       oa_quiet_flags='-batch'
       oa_eval_flags='-eval'
       oa_use_dynamic_lib=no  
       ;;
    ecl) 
       oa_quiet_flags=
       oa_eval_flags='-norc -eval'
       oa_use_dynamic_lib=no  
       ;;
    sbcl) 
       oa_quiet_flags='--noinform --noprint'
       oa_eval_flags='--no-sysinit --no-userinit --disable-debugger --eval'
       ;;
    clisp) 
       oa_quiet_flags='--quiet'
       oa_eval_flags='-norc -x'
       ;;
    clozure)
       oa_quiet_flags='--quiet --no-init'
       oa_eval_flags='--eval'
       ;;
    *) AC_MSG_ERROR([We do not know how to build OpenAxiom this $OA_LISP]) ;;
esac
])


dnl -------------------------------
dnl -- OPENAXIOM_FILE_EXTENSIONS --
dnl -------------------------------
dnl Compute various file extensions used by the build system.
AC_DEFUN([OPENAXIOM_FILE_EXTENSIONS],[
# What is the extension of object and executable files on this platform?
AC_OBJEXT
AC_DEFINE_UNQUOTED([OPENAXIOM_EXEEXT], ["$ac_cv_exeext"], 
                   [Extension of executable file.])

oa_fasl_type=
AC_MSG_CHECKING([compiled Lisp file extension])
if test x"$oa_include_gcl" = xyes; then
   oa_fasl_type=o
else
   ## We set the IFS to <space> as we don't want automatic
   ## replacement of <newline> by <space>.
   openaxiom_save_IFS=$IFS
   IFS=' '
   oa_fasl_type=`$OA_LISP $oa_quiet_flags $oa_eval_flags '(progn (format t "oa_fasl_type=~a" (pathname-type (compile-file-pathname "foo.lisp"))) (quit))'`

   ## Now pull out the fasl type.  ECL has the habit of spitting noise
   ## about internal loading.  Therefore, we must look only for a line that
   ## begins with oa_fasl_type.
   oa_fasl_type=`echo $oa_fasl_type | grep '^oa_fasl_type'`
   IFS=$openaxiom_save_IFS
   oa_fasl_type=`echo $oa_fasl_type | sed -e 's/oa_fasl_type=//'`
   if test -z "$oa_fasl_type"; then
       AC_MSG_ERROR([Could not determine extension for compiled Lisp files])
   fi
fi
AC_MSG_RESULT([$oa_fasl_type])
AC_SUBST(FASLEXT,$oa_fasl_type)
])

dnl ------------------------------
dnl -- OPENAXIOM_FFI_TYPE_TABLE --
dnl ------------------------------
dnl Build FFI type translation table used by
dnl the Boot translator and the Spad compiler
AC_DEFUN([OPENAXIOM_FFI_TYPE_TABLE],[
AC_SUBST(void_type)
AC_SUBST(char_type)
AC_SUBST(int_type)
AC_SUBST(float_type)
AC_SUBST(double_type)
AC_SUBST(string_type)
AC_SUBST(pointer_type)

case $oa_lisp_flavor in
   gcl)
      void_type='void'
      char_type='char'
      int_type='int'
      float_type='float'
      double_type='double'
      string_type='string'
      case $oa_host_lisp_precision,$openaxiom_gcl_version in
         64,*2.6.7*|64,*2.6.8*) pointer_type='(signed-integer 64)' ;;
         *) pointer_type='fixnum' ;;
      esac
      ;;
   sbcl)
      void_type='void'
      char_type='char'
      int_type='int'
      float_type='float'
      double_type='double'
      string_type='c-string'
      pointer_type='(* t)'
      ;;
   clisp)
      void_type='nil'
      char_type='character'
      int_type='int'
      float_type='single-float'
      double_type='double-float'
      string_type='c-string'
      pointer_type='c-pointer'
      ;;
   ecl)
      void_type=':void'
      char_type=':char'
      int_type=':int'
      float_type=':float'
      double_type=':double'
      string_type=':cstring'
      pointer_type=':pointer-void'
      ;;
   clozure)
      void_type=':void'
      # FIXME: this is not really what we want, but good enough for now.
      char_type=':unsigned-byte'
      int_type=':signed-fullword'
      float_type=':single-float'
      double_type=':double-float'
      # Clozure CL wants you to deal with your own mess
      string_type=':address'
      pointer_type=':address'
      ;;
   *)
      AC_MSG_ERROR([We do not know how to translate native types for this Lisp])
      ;;
esac
])


dnl ---------------------------------------
dnl -- OPENAXIOM_HOST_LISP_CPU_PRECISION --
dnl ---------------------------------------
dnl Determine the register precision as seen by the host Lisp system, and
dnl set the global variable oa_host_lisp_precision.
AC_DEFUN([OPENAXIOM_HOST_LISP_CPU_PRECISION], [
if test x"$oa_include_gcl" != xyes; then
   AC_MSG_CHECKING([CPU precision as seen by $OA_LISP])
   # All Lisp systems we support put the relevant information
   # on the *FEATURES* list. 
   case `echo '*features*' | $OA_LISP` in
     *X86-64*|*X86_64*|*WORD-SIZE=64*|*64-BIT*)
	# PORTME: the pattern above covers only the supported free Lisps, i.e.
	# GCL, SBCL, CLisp, ECL and Clozure CL.
	oa_host_lisp_precision=64
	;;
     *)
	# assume everything else is 32-bit
	# FIXME: this is bold assumption.
	oa_host_lisp_precision=32
	;;
   esac
   AC_MSG_RESULT([$oa_host_lisp_precision])
fi
])


dnl ------------------------------------
dnl -- OPENAXIOM_HOST_DATA_PROPERTIES --
dnl ------------------------------------
AC_DEFUN([OPENAXIOM_HOST_DATA_PROPERTIES],[
## Byte order of the host.
AC_C_BIGENDIAN
AC_CHECK_SIZEOF([void*])
if test x"$oa_include_gcl" = xyes; then
   ## PORTME: does GCL really care about system where CHAR_BITS is not 8?
   oa_host_lisp_precision=`expr "$ac_cv_sizeof_voidp * 8"`
fi

## Now that we have full knowledge of the host Lisp to use, tell
## the rest of the runtime about the host natural integer precision.
AC_DEFINE_UNQUOTED([OPENAXIOM_HOST_LISP_PRECISION],
                   [$oa_host_lisp_precision],
                   [The width of the host Lisp and CPU registers.])
])

dnl --------------------------------------
dnl -- OPENAXIOM_DYNAMIC_MODULE_SUPPORT --
dnl --------------------------------------
dnl Infer compiler flags, file prefix and extensions associated
dnl with dynamic module support.
dnl We need to link some C object files into in the Lisp images we
dnl use.  Some Lisps (e.g. GCL, ECL) support inclusion of ``ordinary''
dnl object files.  Other Lisps (e.g. SBCL, Clozure CL) support only dynamic
dnl or shared libraries.  However, the exact minutia of  portably
dnl building shared libraries are known to be fraught with all kinds
dnl of traps.  Consequently, we sought to use dedicated tools such
dnl Libtool.  Unfortunately, Libtool has been steadily improved over the years
dnl to become nearly useless when mixed with non-libtool components.
AC_DEFUN([OPENAXIOM_DYNAMIC_MODULE_SUPPORT],[
AC_SUBST(oa_use_libtool_for_shared_lib)
AC_SUBST(oa_shrobj_flags)
AC_SUBST(oa_shrlib_flags)
AC_SUBST(oa_shrlib_prefix)
oa_use_libtool_for_shared_lib=no
oa_shrobj_flags=
oa_shrlib_flags=
## Tell Libtool to assume `dlopen' so that it does not have to
## emulate it.
LT_PREREQ([2.2.6])
LT_INIT([pic-only dlopen win32-dll shared])
AC_SUBST([LIBTOOL_DEPS])
# Most targets use 'lib' prefix, as in 'libOpenAxiom'.
oa_shrlib_prefix='lib'
# Give me extension of libraries
AC_SUBST(shared_ext)
AC_SUBST(libext)
module=yes
eval shared_ext=\"$shrext_cmds\"
case $host in
    *mingw*|*cygwin*)
       oa_shrobj_flags='-prefer-pic'
       oa_shrlib_flags="-shared -Wl,--export-all-symbols"
       # Windows platforms don't need a prefix
       oa_shrlib_prefix=
       ;;
    *darwin*)
       oa_shrobj_flags='-dynamic'
       oa_shrlib_flags='-bundle -undefined suppress -flat_namespace'
       ;;
    *)
       oa_shrobj_flags='-prefer-pic'
       oa_shrlib_flags='-shared'
       ;;
esac
])


dnl ---------------------------
dnl -- OPENAXIOM_BUILD_TOOLS --
dnl ---------------------------
dnl Check for utilities we need for building the system.
AC_DEFUN([OPENAXIOM_BUILD_TOOLS],[
AC_CHECK_PROG([TOUCH], [touch],
              [touch], [AC_MSG_ERROR(['touch' program is missing.])])
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_SED
AC_CHECK_PROGS([MKTEMP], [mktemp])
AC_PROG_AWK

## Find GNU Make
case $build in
    *linux*)
	# GNU/Linux systems come equipped with GNU Make, called `make'
        AC_CHECK_PROGS([MAKE], [make],
                       [AC_MSG_ERROR([Make utility missing.])])
	;;
    *)
        # Other systems tend to spell it `gmake' and such
        AC_CHECK_PROGS([MAKE], [gmake make],
                       [AC_MSG_ERROR([Make utility missing.])])
	if ! $MAKE --version | grep 'GNU' 2>/dev/null; then
	    AC_MSG_ERROR([OpenAxiom build system needs GNU Make.])
	fi
	;;
esac
])

dnl ---------------------------
dnl -- OPENAXIOM_HOST_EDITOR --
dnl ---------------------------
dnl Check for a text editor for use when
dnl the system is up and running.
AC_DEFUN([OPENAXIOM_HOST_EDITOR],[
AC_SUBST(oa_editor)
## On Windows system, we prefer the default installation
## location to be 'C:/OpenAxiom'.  We cannot use AC_PREFIX_DEFAULT
## directly as it seems to operate unconditionally.  Therefore, we 
## resort to this dirty trick stepping over Autoconf's internals.
case $host in
    *mingw*)
        ac_default_prefix="C:/OpenAxiom"
        AC_PATH_PROGS([oa_editor],[notepad.exe])
	;;
    *)  
        AC_PATH_PROGS([oa_editor],[vi])
        ;;
esac
])

dnl --------------------------
dnl -- OPENAXIOM_HOST_PROGS --
dnl --------------------------
dnl Check for programs we need in the host environment.
AC_DEFUN([OPENAXIOM_HOST_PROGS],[
OPENAXIOM_HOST_EDITOR
AC_PATH_PROG([PDFLATEX], [pdflatex])
if test -z "$PDFLATEX"; then
   AC_PATH_PROG([LATEX], [latex],
                [AC_MSG_NOTICE([Documentation is disabled.])])
fi
AC_CHECK_PROGS([MAKEINDEX], [makeindex])
])


dnl -----------------------------
dnl -- OPENAXIOM_BUILD_OPTIONS --
dnl -----------------------------
dnl Process build options specified on the command line.
AC_DEFUN([OPENAXIOM_BUILD_OPTIONS],[
## Does it make sense to pretend that we support multithreading?
oa_enable_threads=no
AC_ARG_ENABLE([threads], [  --enable-threads   turn on threads support],
              [case $enableval in
                  yes|no) oa_enable_threads=$enableval ;;
                  *) AC_MSG_ERROR([erroneous value for --enable-threads]) ;;
               esac])
# GNU compilers want hints about multithreading.
case $oa_cxx_compiler_lineage,$oa_enable_threads in
   gnu,yes)
     oa_cflags="$oa_cflags -pthread"
esac
AC_SUBST(oa_enable_threads)

## Occaionally, we may want to keep intermediary files.
oa_keep_files=
AC_ARG_ENABLE([int-file-retention], 
              [  --enable-int-file-retention   keep intermediary files],
              [case $enableval in
                  yes|no) oa_keep_files=$enableval ;;
                  *) AC_MSG_ERROR([erroneous value for --enable-int-file-retention]) ;;
               esac])
AC_SUBST(oa_keep_files)

## Parse args for profiling-enabled build.
oa_enable_profiling=no
AC_ARG_ENABLE([profiling], [  --enable-profiling  turn profiling on],
              [case $enableval in
                  yes|no) oa_enable_profiling=$enableval ;;
                  *) AC_MSG_ERROR([erroneous value for --enable-profiling]) ;;
               esac])
AC_SUBST(oa_enable_profiling)

## Lisp optimization settings
oa_optimize_options=speed
## Shall we proclaim safety?
oa_enable_checking=no          # don't turn on checking by default.
AC_ARG_ENABLE([checking], [  --enable-checking  turn runtime checking on],
              [case $enableval in
                  yes|no) oa_enable_checking=$enableval ;;
                  *) AC_MSG_ERROR([erroneous value for --enable-checking]) ;;
               esac])
if test x"$oa_enable_checking" = xyes; then
   case $oa_lisp_flavor in
     gcl) # GCL-2.6.x does not understand debug.
        oa_optimize_options="$oa_optimize_options safety" 
        ;;
     *) oa_optimize_options="$oa_optimize_options safety debug" 
        ;;
   esac
   AC_MSG_NOTICE([runtime checking may increase compilation time])
fi
AC_SUBST(oa_enable_checking)
AC_SUBST(oa_optimize_options)
])


dnl -----------------------------
dnl -- OPENAXIOM_CHECK_SIGNALS --
dnl -----------------------------
dnl The host platform must be able to handle signals.  Although, this is 
dnl not strictly necessary, that is the way OpenAxiom source code
dnl is currently written.  We ask for a POSIX or ISO C semantics, though
dnl we have a strong preference for POSIX-conformant semantics.
AC_DEFUN([OPENAXIOM_CHECK_SIGNALS],[
AC_CHECK_HEADERS([signal.h],
                 [],
                 [AC_MSG_ERROR([OpenAxiom needs signal support.])])
AC_CHECK_DECLS([sigaction], [], [], 
               [#include <signal.h>])
AC_CHECK_DECLS([kill], [], [],
               [#include <signal.h>])
])


dnl -----------------------------
dnl -- OPENAXIOM_CHECK_SOCKETS --
dnl -----------------------------
dnl The host environment must be capable of handling communication through
dnl sockets.  This is required for interfacing AXIOMsys
dnl and Superman.  Notice that ideally, we should decouple
dnl that interface in such a way that we can still build OpenAxiom
dnl when Superman is not needed or a socket library is not
dnl available.
AC_DEFUN([OPENAXIOM_CHECK_SOCKETS],[
case $host in
    *mingw*)
	AC_CHECK_HEADERS([winsock2.h],
	                [oa_host_has_socket=yes],
			[])
	oa_c_runtime_extra="-lwsock32"
	;;
    *)
        AC_CHECK_HEADERS([sys/socket.h], 
                         [oa_host_has_socket=yes],
		         [])
	;;
esac
if test x$oa_host_has_socket != xyes; then \
    AC_MSG_ERROR([OpenAxiom needs suport for sockets.])
fi
## solaris-based systems tend to hide the socket library.
case $host in
    *solaris*)
       AC_SEARCH_LIBS([accept], [socket],
	   [], [AC_MSG_ERROR([socket library not found])])
       AC_SEARCH_LIBS([gethostbyname], [nsl])
       ;;
    *) ;;
esac

AC_EGREP_CPP([has_af_local],
             [#if HAVE_SYS_SOCKET_H
#  include <sys/socket.h>
#else
#  include <winsock2.h>
#endif
#ifdef AF_LOCAL
   has_af_local
#endif
             ],
             [AC_DEFINE([HAVE_AF_LOCAL], [1], [Host has AF_LOCAL])])


AC_EGREP_CPP([has_af_unix],
             [#if HAVE_SYS_SOCKET_H
#  include <sys/socket.h>
#else
#  include <winsock2.h>
#endif
#ifdef AF_UNIX
   has_af_unix
#endif
             ],
             [AC_DEFINE([HAVE_AF_UNIX], [1], [Host has AF_UNIX])])
])

dnl --------------------------------
dnl -- OPENAXIOM_CHECK_FILESYSTEM --
dnl --------------------------------
dnl Some parts of OpenAxiom manipulate files and directories.  They
dnl more or less directly reflect the underlying platform semantics.
dnl For the moment, we require POSIX semantics, though that does not
dnl seem necessary.  That restriction should be removed as soon as possible.
AC_DEFUN([OPENAXIOM_CHECK_FILESYSTEM],[
AC_CHECK_HEADERS([sys/stat.h],
                 [],
		 [AC_MSG_ERROR([OpenAxiom needs <sys/stat.h>])])
case $host in
    *mingw*)
        ;;
    *)
	AC_CHECK_HEADERS([dirent.h],
			 [],
			 [AC_MSG_ERROR([OpenAxiom needs <dirent.h>])])
        ;;
esac

AC_CHECK_HEADERS([unistd.h], [],
                 [AC_MSG_ERROR([OpenAxiom needs <unistd.h>])])
])

dnl -----------------------------
dnl -- OPENAXIOM_CHECK_PROCESS --
dnl -----------------------------
AC_DEFUN([OPENAXIOM_CHECK_PROCESS],[
AC_CHECK_HEADERS([setenv, putenv], [], [], [#include <stdlib.h>])
AC_CHECK_DECLS([getuid, geteuid, getgid, getegid], [], [],
               [#include <unistd.h>])
AC_CHECK_HEADERS([sys/wait.h])
if test x"$ac_cv_header_sys_wait_h" = xyes; then \
    AC_CHECK_DECLS([wait], 
                   [], 
                   [], 
                   [#include <sys/wait.h>])
fi
AC_CHECK_DECLS([fork],
               [],
               [],
               [#include <unistd.h>])
])

dnl ----------------------------------
dnl -- OPENAXIOM_CHECK_CORE_SUPPORT --
dnl ----------------------------------
AC_DEFUN([OPENAXIOM_CHECK_CORE_SUPPORT],[
oa_c_runtime=
AC_SUBST(oa_c_runtime)

oa_c_runtime_extra=
AC_SUBST(oa_c_runtime_extra)

OPENAXIOM_CHECK_FILESYSTEM
OPENAXIOM_CHECK_SIGNALS
OPENAXIOM_CHECK_SOCKETS
OPENAXIOM_CHECK_PROCESS
#OPENAXIOM_CHECK_GMP
])

dnl ------------------------
dnl -- OPENAXIOM_CHECK_IO --
dnl ------------------------
AC_DEFUN([OPENAXIOM_CHECK_IO],[
# Utility for temporary pathnames.
if test -n $ac_cv_header_unistd_h; then
  AC_CHECK_DECLS([mktemp, mkdtemp, mkstemp], [], [], [[#include <unistd.h>]])
fi
if test -n $ac_cv_have_decl_mktemp; then
  AC_CHECK_DECLS([tempnam],[],[],[[#include <stdio.h>]])
fi
# Honor support for large files
AC_SYS_LARGEFILE
# What about long file names?
AC_SYS_LONG_FILE_NAMES
# Posix terminal IO?
AC_SYS_POSIX_TERMIOS
## Does this system have openpty or shall we emulate?
AC_CHECK_HEADERS([sys/ioctl.h pty.h util.h libutil.h termios.h])
AC_CHECK_DECLS([openpty],[],[],
   [#if HAVE_PTY_H
#  include <pty.h>
#endif
#if HAVE_UTIL_H
#  include <util.h>
#endif
#if HAVE_SYS_IOCTL_H
#  include <sys/ioctl.h>
#endif
#if HAVE_TERMIOS_H
#  include <termios.h>
#endif
#if HAVE_LIBUTIL_H
#  include <sys/types.h>
#  include <libutil.h>
#endif
   ])
if test x"$ac_cv_have_decl_openpty" = xyes; then \
   AC_SEARCH_LIBS([openpty],[util])
fi

oa_use_sman=1
if test x"$ac_cv_have_decl_fork" = xyes \
     -a x"$ac_cv_have_decl_wait" = xyes; then \
    oa_c_runtime="$oa_c_runtime terminal_io"
else
    oa_use_sman=0
    AC_MSG_NOTICE([Superman component is disabled.])
fi

AC_DEFINE_UNQUOTED([OPENAXIOM_USE_SMAN], [$oa_use_sman],
                   [Whether to use the session manager as driver.])
])


dnl -------------------------
dnl -- OPENAXIOM_CHECK_X11 --
dnl -------------------------
dnl One of the thorniest issues with programs that use the X Window System
dnl is portability.  There exist many implementations of the X11
dnl specification, each with its own variations, extensions, and what
dnl not.  Designing hand-written makefiles for such programs can be a
dnl daunting task, fraut with all kinds of traps.  Fortunately, Autoconf
dnl provides us with some help, namely the macro [[AC_PATH_X]] and 
dnl [[AC_PATH_XTRA]].  The former searches the directories where the
dnl X11 include files and the library files reside.  The latter is an
dnl enhanced version that:
dnl  1. computes the C compiler flags required by X11;
dnl  2. computes the linker flags required by X11;
dnl  3. checks for special libraries that some systems need in order to
dnl     compile X11 programs;
dnl  4. checks for special X11R6 libraries that need to be linked before
dnl      the flag [[-lX11]].
AC_DEFUN([OPENAXIOM_CHECK_X11],[
AC_PATH_XTRA

## Finally, output the list of libraries that need to appear before -lX11
## Some part of OpenAxiom depends on Xpm.  That library has kind of uncertain
## future.  At some point in the past, it was deprecated, to be
## replaced by xpm-nox; then came back again.  So, its support may
## vary from system to system.  For the moment, we assume that if X11
## is found then, Xpm is also present.  Though, clearly that is a
## very optimistic assumption.  Long term, OpenAxiom should get rid of
## dependence on Xpm.  A nearly fool-proof test would be probably
## inspired by AC_PATH_XTRA.  I don't have time to get to that 
## complication right now.  Will fix later.
## But we can check for the existence of <X11/xpm.h>
## Also check for Xt headers
X_PRE_LIBS="-lXpm -lXt $X_PRE_LIBS"
AC_SUBST(X_PRE_LIBS)

## If the system supports X11, then build graphics
oa_use_x=no
if test x"$no_x" = xyes; then
    AC_MSG_NOTICE([The Graphics component is disabled.])
else
    oa_saved_cxxflags=$CXXFLAGS
    oa_saved_cppflags=$CPPFLAGS
    oa_saved_ldflags=$LDFLAGS
    CXXFLAGS="$CXXFLAGS $X_CFLAGS"
    CPPFLAGS="$CPPFLAGS $X_CFLAGS"
    LDFLAGS="$X_PRE_LIBS $X_LIBS $X_EXTRA_LIBS"
    AC_CHECK_HEADERS([X11/xpm.h],[],
      [AC_MSG_ERROR([The header <X11/xpm.h> could not be found.  Install Xpm development package and re-start the configuration process.])])
    AC_CHECK_HEADERS([X11/Intrinsic.h],[],
      [AC_MSG_ERROR([The header <X11/Intrinsic.h> could not be found.  Install Xt development package and re-start the configuration process.])])
    oa_use_x=yes
    oa_c_runtime="$oa_c_runtime graphics"
    LDFLAGS=$oa_saved_ldflags
    CPPFLAGS=$oa_saved_cppflags
    CXXFLAGS=$oa_saved_cxxflags
fi
AC_SUBST(oa_use_x)
])

dnl ------------------------
dnl -- OPENAXIOM_CHECK_QT --
dnl ------------------------
AC_DEFUN([OPENAXIOM_CHECK_QT],[
# Check for Qt utilities.
oa_has_qt=no
AC_CHECK_PROGS([OA_QT_MOC], [moc])
AC_CHECK_PROGS([OA_QT_QMAKE], [qmake])
if test -n "$OA_QT_MOC"; then
  AC_MSG_CHECKING([Qt version])
  oa_qt_version=`"$OA_QT_MOC" -v 2>&1 | sed -e 's/^.*(\(.*\))$/\1/'`
  AC_MSG_RESULT([$oa_qt_version])
  case $oa_qt_version in
    *[1-3]\.[0-9]+\.[0-9]+)
       AC_MSG_WARN([This version of Qt is too old for OpenAxiom.])
       ;;
    *) 
       oa_has_qt=yes
       ;;
  esac
fi
AC_DEFINE_UNQUOTED([OPENAXIOM_USE_GUI], [`expr x$oa_has_qt = xyes`],
                   [Whether to use the QT-based GUI interface as driver.])
])

dnl -------------------------------------
dnl -- OPENAXIOM_CHECK_BROWSER_SUPPORT --
dnl -------------------------------------
dnl The HyperDoc component needs string pattern matching.  
dnl We require [[<regex.h>]], with POSIX-conformant definition.  We used
dnl to key build of HyperDoc component on the availability of X11
dnl functionalities.  That, however, is a severe restriction.  Not all
dnl of the HyperDoc components need X11.  Some, such as [[htadd]], don't
dnl need X11 at all.  Therefore we have lifted part of the restrictions.
dnl See \File{src/hyper/Makefile} for more details.  Note that is we don't
dnl build the HyperDoc component, the compilation of algebra files are
dnl drawn in [[Unexpected HT command]] noise.
AC_DEFUN([OPENAXIOM_CHECK_BROWSER_SUPPORT],[
oa_host_has_regex=
AC_CHECK_HEADER([regex.h], 
		[oa_host_has_regex=yes],
		[oa_host_has_regex=no])
AC_SUBST(oa_host_has_regex)
])

dnl ------------------------------
dnl -- OPENAXIOM_CHECK_GRAPHICS --
dnl ------------------------------
AC_DEFUN([OPENAXIOM_CHECK_GRAPHICS],[
OPENAXIOM_CHECK_X11
OPENAXIOM_CHECK_QT
OPENAXIOM_CHECK_BROWSER_SUPPORT
])


dnl ------------------------
dnl -- OPENAXIOM_CHECK_MM --
dnl ------------------------
dnl Check for host capability of memory mapping.
AC_DEFUN([OPENAXIOM_CHECK_MM],[
AC_CHECK_HEADERS([sys/mman.h fcntl.h])
## We want anonymous mapping for memory allocation.  Unfortunately,
## the flag for anonymous mapping is not standardized.  Popular names
##  are MAP_ANONYMOUS and MAP_ANON.
if test x"$ac_cv_header_sys_mman_h" = xyes; then
   AC_MSG_CHECKING([for flag to request anonymous memory mapping])
   AC_EGREP_CPP([MAP_ANONYMOUS],
                [#include <sys/mman.h>
#ifdef MAP_ANONYMOUS
   "MAP_ANONYMOUS"
#endif],
                [openaxiom_mm_anonymous_flag=MAP_ANONYMOUS])
   if test -z "$openaxiom_mm_anonymous_flag"; then
      AC_EGREP_CPP([MAP_ANON],
                   [#include <sys/mman.h>
#ifdef MAP_ANON
   "MAP_ANON"
#endif],
                   [openaxiom_mm_anonymous_flag=MAP_ANON])
   fi
   ## It would be curious that we don't have an anonymous mapping
   ## capability.  Let that be known loudly.
   if test -n "$openaxiom_mm_anonymous_flag"; then
      AC_MSG_RESULT([$openaxiom_mm_anonymous_flag])
   else
      AC_MSG_ERROR([Could not find flag for anonymous map])
   fi
   AC_DEFINE_UNQUOTED([OPENAXIOM_MM_ANONYMOUS_MAP_FLAG],
                      [$openaxiom_mm_anonymous_flag],
                      [mmap anonymous flag])
fi
])

dnl -------------------------
dnl -- OPENAXIOM_CHECK_GMP --
dnl -------------------------
AC_DEFUN([OPENAXIOM_CHECK_GMP],[
AC_CHECK_HEADERS([gmp.h], [AC_CHECK_LIB([gmp],[__gmpz_init])])
AM_CONDITIONAL([OA_HAS_GMP], [test -n $ac_cv_header_gmp_h])
])

dnl --------------------------
dnl -- OPENAXIOM_CHECK_MISC --
dnl --------------------------
AC_DEFUN([OPENAXIOM_CHECK_MISC],[
case $oa_cxx_compiler_lineage in
  gnu|clang)
     CFLAGS="$CFLAGS -O2 -Wall"
     CXXFLAGS="$CXXFLAGS -O2 -Wall"
     ;;
esac
])