summaryrefslogtreecommitdiff
path: root/configure
blob: 2cfbf7c43395dc52086e0589f22be8ff3f7348c3 (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
#!/bin/sh

##################################
#
#  Configuration script for Coq
# 
##################################

VERSION=8.1pl3
DATE="Dec. 2007"

# a local which command for sh
which () {
IFS=":" # set words separator in PATH to be ':' (it allows spaces in dirnames)
for i in $PATH; do
  if test -z "$i"; then i=.; fi 
  if [ -f "$i/$1" ] ; then
	IFS=" "
        echo "$i/$1"
	break
  fi
done
}

usage () {
    echo -e "Available options for configure are:\n"
    echo "-help"
    echo -e "\tDisplays this help page\n"
    echo "-prefix <dir>"
    echo -e "\tSet installation directory to <dir>\n"
    echo "-local"
    echo -e "\tSet installation directory to the current source tree\n"
    echo "-src"
    echo -e "\tSpecifies the source directory\n"
    echo "-bindir"
    echo "-libdir"
    echo "-mandir"
    echo -e "\tSpecifies where to install bin/lib/man files resp.\n"
    echo "-emacslib"
    echo "-emacs"
    echo -e "\tSpecifies where emacs files are to be installed\n"
    echo "-coqdocdir"
    echo -e "\tSpecifies where Coqdoc style files are to be installed\n"
    echo "-camldir"
    echo -e "\tSpecifies the path to the OCaml library\n"
    echo "-lablgtkdir"
    echo -e "\tSpecifies the path to the Lablgtk library\n"
    echo "-camlp5dir"
    echo -e "\tSpecifies where to look for the Camlp5 library and tells to use it\n"
    echo "-arch"
    echo -e "\tSpecifies the architecture\n"
    echo "-opt"
    echo -e "\tSpecifies whether or not to generate optimized executables\n"
    echo "-fsets (all|basic)"
    echo "-reals (all|basic)"
    echo -e "Specifies whether or not to compile full FSets/Reals library\n"
    echo "-coqide (opt|byte|no)"
    echo -e "\tSpecifies whether or not to compile Coqide\n"
    echo "-with-geoproof (yes|no)"
    echo -e "\tSpecifies whether or not to use Geoproof binding\n"
    echo "-with-cc <file>"
    echo "-with-ar <file>"
    echo "-with-ranlib <file>"
    echo -e "\tTells configure where to find gcc/ar/ranlib executables\n"
    echo "-byte-only"
    echo -e "\tCompiles only bytecode version of Coq\n"
    echo "-debug"
    echo -e "\tAdd debugging information in the Coq executables\n"
    echo "-profile"
    echo -e "\tAdd profiling information in the Coq executables\n"
    echo "-annotate"
    echo -e "\tCompiles Coq with -dtypes option"
}


# Default OCaml binaries
bytecamlc=ocamlc
nativecamlc=ocamlopt
ocamlexec=ocaml
ocamldepexec=ocamldep
ocamldocexec=ocamldoc
ocamllexexec=ocamllex
ocamlyaccexec=ocamlyacc
ocamlmktopexec=ocamlmktop
camlp4oexec=camlp4o


coq_debug_flag=
coq_profile_flag=
coq_annotate_flag=
coq_inline_flag=
best_compiler=opt
cflags="-fno-defer-pop -Wall -Wno-unused"

gcc_exec=gcc
ar_exec=ar
ranlib_exec=ranlib

local=false
src_spec=no
prefix_spec=no
bindir_spec=no
libdir_spec=no
mandir_spec=no
emacslib_spec=no
emacs_spec=no
camldir_spec=no
lablgtkdir_spec=no
coqdocdir_spec=no
fsets_opt=no
fsets=all
reals_opt=no
reals=all
arch_spec=no
coqide_spec=no
with_geoproof=false

COQSRC=`pwd`

# Parse command-line arguments

while : ; do
  case "$1" in
    "") break;;
    -help|--help) usage
	          exit;;
    -prefix|--prefix) prefix_spec=yes
                      prefix="$2"
		      shift;;
    -local|--local) local=true
		    reals_opt=yes
		    reals=all;;
    -src|--src) src_spec=yes
                COQSRC="$2"
	        shift;;
    -bindir|--bindir) bindir_spec=yes
                      bindir="$2"
		      shift;;
    -libdir|--libdir) libdir_spec=yes
                      libdir="$2"
		      shift;;
    -mandir|--mandir) mandir_spec=yes
                      mandir="$2"
		      shift;;
    -emacslib|--emacslib) emacslib_spec=yes
                          emacslib="$2"
			  shift;;
    -emacs |--emacs) emacs_spec=yes
		     emacs="$2"
		     shift;;
    -coqdocdir|--coqdocdir) coqdocdir_spec=yes
	              coqdocdir="$2"
		      shift;;
    -camldir|--camldir) camldir_spec=yes
	                camldir="$2"
			shift;;
    -lablgtkdir|--lablgtkdir) lablgtkdir_spec=yes
	                lablgtkdir="$2"
			shift;;
    -camlp5dir|--camlp5dir)
	                camlp5dir="$2"
			shift;;
    -arch|--arch) arch_spec=yes
                  arch=$2
		  shift;;
    -opt|--opt) bytecamlc=ocamlc.opt
                camlp4oexec=camlp4o  # can't add .opt since dyn load'll be required
                nativecamlc=ocamlopt.opt;;
    -fsets|--fsets) fsets_opt=yes
                    case "$2" in
			yes|all) fsets=all;;
			*) fsets=basic
		    esac
		    shift;;
    -reals|--reals) reals_opt=yes
	            case "$2" in
			yes|all) reals=all;;
			*) reals=basic
		    esac
		    shift;;
    -coqide|--coqide) coqide_spec=yes
		      case "$2" in
			  byte|opt) COQIDE=$2;;
			  *) COQIDE=no
		      esac
		      shift;;
    -with-geoproof|--with-geoproof) 
	  case $2 in
	      yes) with_geoproof=true;;
	      no) with_geoproof=false;;
	  esac
	  shift;;
    -with-cc|-with-gcc|--with-cc|--with-gcc) 
	  gcc_spec=yes
	  gcc_exec=$2
	  shift;;
    -with-ar|--with-ar) 
	  ar_spec=yes
	  ar_exec=$2
	  shift;;
    -with-ranlib|--with-ranlib) 
	  ranlib_spec=yes
	  ranlib_exec=$2
	  shift;;
    -byte-only|-byteonly|--byteonly|--byte-only) best_compiler=byte;;
    -debug|--debug) coq_debug_flag=-g;;
    -profile|--profile) coq_profile_flag=-p;;
    -annotate|--annotate) coq_annotate_flag=-dtypes;;
    *) echo "Unknown option \"$1\"." 1>&2; usage; exit 2;;
  esac
  shift
done

if [ $prefix_spec = yes -a $local = true ] ; then
  echo "Options -prefix and -local are incompatible"
  echo "Configure script failed!"
  exit 1
fi

# compile date
DATEPGM=`which date`
case $DATEPGM in
    "") echo "I can't find the program \"date\" in your path."
        echo "Please give me the current date"
	read COMPILEDATE;;
    *)  COMPILEDATE=`date +"%h %d %Y %H:%M:%S"`;;
esac

# Architecture

case $arch_spec in
    no) if test -x /bin/arch ; then
	    ARCH=`/bin/arch`
	elif test -x /usr/bin/arch ; then
	    ARCH=`/usr/bin/arch`
	elif test -x /usr/ucb/arch ; then
	    ARCH=`/usr/ucb/arch`
	elif test -x /bin/uname && (/bin/uname -s | grep -q -i CYGWIN) ; then
	    ARCH=win32
	    # cygwin returns a name of the form /cygdrive/c/... 
	    # that coqc does not understand; need to transform it
	    COQTOP=`echo $COQTOP | sed -e "s#.*cygdrive.\(.\)#\1:#"`
	elif test -x /bin/uname ; then
	    ARCH=`/bin/uname -s`
	elif test -x /usr/bin/uname ; then
	    ARCH=`/usr/bin/uname -s`
	else
	    echo "I can not automatically find the name of your architecture"
	    echo -n\
              "Give me a name, please [win32 for Win95, Win98 or WinNT]: "
	    read ARCH
	fi;;
    yes) ARCH=$arch
esac

# executable extension

case $ARCH in
    win32) EXE=".exe";;
    *) EXE=""
esac

# strip command

case $ARCH in
    win32)
	# true -> strip : it exists under cygwin !
	STRIPCOMMAND="strip";; 
    *)
    if [ "$coq_profile_flag" = "-p" ] ; then
	STRIPCOMMAND="true"
    else
	STRIPCOMMAND="strip"
    fi
esac

# Is the source tree checked out from svn ?
if test -e .svn/entries ; then 
    checkedout=1
else 
    checkedout=0
fi

#########################################
# Objective Caml programs

case $camldir_spec in
    no) CAMLC=`which $bytecamlc`
	case "$CAMLC" in
	    "") echo "$bytecamlc is not present in your path!"
		echo "Give me manually the path to the $bytecamlc executable [/usr/local/bin by default]: "
		read CAMLC
		
		case "$CAMLC" in
		    "") CAMLC=/usr/local/bin/$bytecamlc;;
		    */ocamlc|*/ocamlc.opt) true;;
		    */) CAMLC="${CAMLC}"$bytecamlc;;
		    *) CAMLC="${CAMLC}"/$bytecamlc;;
		esac
	esac
	CAMLBIN=`dirname "$CAMLC"`;;
    yes) CAMLC=$camldir/$bytecamlc
        
         CAMLBIN=`dirname "$CAMLC"`
	 bytecamlc="$CAMLC"
	 nativecamlc=$CAMLBIN/$nativecamlc
	 ocamlexec=$CAMLBIN/ocaml
	 ocamldepexec=$CAMLBIN/ocamldep
	 ocamldocexec=$CAMLBIN/ocamldoc
	 ocamllexexec=$CAMLBIN/ocamllex
	 ocamlyaccexec=$CAMLBIN/ocamlyacc
	 camlmktopexec=$CAMLBIN/ocamlmktop
	 camlp4oexec=$CAMLBIN/camlp4o
esac

if test ! -f "$CAMLC" ; then
    echo "I can not find the executable '$CAMLC'! (Have you installed it?)"
    echo "Configuration script failed!"
    exit 1
fi

# Under Windows, OCaml only understands Windows filenames (C:\...)
case $ARCH in
    win32) CAMLBIN=`cygpath -w ${CAMLBIN}`;;
esac

# this fixes a camlp4 bug under FreeBSD
# ("native-code program cannot do a dynamic load")
if [ `uname -s` = "FreeBSD" ]; then camlp4oexec=$camlp4oexec.byte; fi

CAMLVERSION=`"$bytecamlc" -v | sed -n -e 's|.*version* *\(.*\)$|\1|p' `

case $CAMLVERSION in
    1.*|2.*|3.00|3.01|3.02|3.03|3.03alpha|3.04|3.05beta|3.05|3.06|3.08.0)
	echo "Your version of Objective-Caml is $CAMLVERSION."
	if [ "$CAMLVERSION" = "3.08.0" ] ; then
	    echo "You need Objective-Caml 3.07 or later (to the exception of 3.08.0)!"
	else
	    echo "You need Objective-Caml 3.07 or later!"
	fi
	echo "Configuration script failed!"
	exit 1;;
    3.07*)
        cflags="$cflags -DOCAML_307"
	coq_inline_flag="-inline 0"
	echo "You have Objective-Caml $CAMLVERSION. Good!";;
    3.08*)
	coq_inline_flag="-inline 0"
	echo "You have Objective-Caml $CAMLVERSION. Good!";;
    ?*)
	CAMLP4COMPAT="-loc loc" 
	echo "You have Objective-Caml $CAMLVERSION. Good!";;
    *)
	echo "I found the Objective-Caml compiler but cannot find its version number!"
	echo "Is it installed properly?"
	echo "Configuration script failed!"
	exit 1;;
esac

CAMLTAG=OCAML`echo $CAMLVERSION | sed -e "s/\([1-9]\)\.\([0-9]*\).*/\1\2/g"`

# do we have a native compiler: test of ocamlopt and its version

if [ "$best_compiler" = "opt" ] ; then
  if test -e `which "$nativecamlc"` ; then
      CAMLOPTVERSION=`"$nativecamlc" -v | sed -n -e 's|.*version* *\(.*\)$|\1|p' `
      if [ "`uname -s`" = "Darwin" -a "$ARCH" = "i386" ]; then
	  case $CAMLOPTVERSION in
	      3.09.3|3.1?*) ;;
	      *) echo "Native compilation on MacOS X Pentium requires Objective-Caml >= 3.09.3,"
		 best_compiler=byte
		 echo "only the bytecode version of Coq will be available."
	  esac
      elif [ "$CAMLOPTVERSION" != "$CAMLVERSION" ] ; then
	  echo "Native and bytecode compilers do not have the same version!";
      fi
      echo "You have native-code compilation. Good!"
  else
      best_compiler=byte
      echo "You have only bytecode compilation."
  fi
fi


# For coqmktop & bytecode compiler

case $ARCH in
    win32) # Awfull trick to get around a ^M problem at the end of CAMLLIB
      CAMLLIB=`"$CAMLC" -where | sed -e 's/^\(.*\)$/\1/'` ;;
    *)
      CAMLLIB=`"$CAMLC" -where`
  esac
  

# Camlp4 / Camlp5 configuration
# Very basic for the moment: if camlp5 exists, we use it...

if [ "$camlp5dir" != "" ]; then
    CAMLP4=camlp5
    CAMLP4LIB=$camlp5dir
    camlp4oexec=`echo $camlp4oexec | sed -e 's/4/5/'`
elif [ "$CAMLTAG" = "OCAML310" ]; then
    if [ -x "${CAMLLIB}/camlp5" ]; then 
        CAMLP4LIB=+camlp5
    elif [ -x "${CAMLLIB}/site-lib/camlp5" ]; then 
        CAMLP4LIB=+site-lib/camlp5
    else
	echo "Objective Caml 3.10 found but no Camlp5 installed."
	echo "Configuration script failed!"
	exit 1
    fi
    CAMLP4=camlp5
    camlp4oexec=`echo $camlp4oexec | sed -e 's/4/5/'`
else 
    CAMLP4=camlp4
    CAMLP4LIB=+camlp4
fi

if [ "$CAMLP4" = "camlp5" ] && `$camlp4oexec -v 2>&1 | grep -q 5.00`; then
    echo "Camlp5 version 5.00 not supported: versions 4.0x or >= 5.01 are OK."
    echo "Configuration script failed!"
    exit 1
fi


case $CAMLP4LIB in
    +*) FULLCAMLP4LIB=$CAMLLIB/`echo $CAMLP4LIB | cut -b 2-`;;
    *)  FULLCAMLP4LIB=$CAMLP4LIB;;
esac

# Assume that camlp(4|5) binaries are at the same place as ocaml ones
# (this should become configurable some day) 
CAMLP4BIN=${CAMLBIN}


# OS dependent libraries

case $ARCH in
  sun4*) OS=`uname -r`
	case $OS in
	   5*) OS="Sun Solaris $OS"
	       OSDEPLIBS="-cclib -lunix -cclib -lnsl -cclib -lsocket";;
	   *) OS="Sun OS $OS"
	      OSDEPLIBS="-cclib -lunix"
        esac;;
  alpha) OSDEPLIBS="-cclib -lunix";;
  win32) OS="Win32" 
	 OSDEPLIBS="-cclib -lunix"
	 cflags="-mno-cygwin $cflags";;
  *) OSDEPLIBS="-cclib -lunix"
esac

# lablgtk2 and CoqIDE

# -byte-only should imply -coqide byte, unless the user decides otherwise

if [ "$best_compiler" = "byte" -a "$coqide_spec" = "no" ]; then 
    coqide_spec=yes
    COQIDE=byte
fi

# Which coqide is asked ? which one is possible ?

if [ "$coqide_spec" = "yes" -a "$COQIDE" = "no" ]; then 
    echo "CoqIde disabled as requested."
else
    case $lablgtkdir_spec in
	no) 
	    if [ -f "${CAMLLIB}/lablgtk2/glib.mli" ]; then
		lablgtkdir=${CAMLLIB}/lablgtk2
	    elif [ -f "${CAMLLIB}/site-lib/lablgtk2/glib.mli" ]; then
		lablgtkdir=${CAMLLIB}/site-lib/lablgtk2
	    fi;;
	yes)
	    if [ ! -f "$lablgtkdir/glib.mli" ]; then
		echo "Incorrect LablGtk2 library (glib.mli not found)."
		echo "Configuration script failed!"
		exit 1
	    fi;;
    esac
    if [ "$lablgtkdir" = "" ]; then
	echo "LablGtk2 not found: CoqIde will not be available."
	COQIDE=no
    elif [ -z "`grep -w convert_with_fallback "$lablgtkdir/glib.mli"`" ]; then
	echo "LablGtk2 found but too old: CoqIde will not be available."
	COQIDE=no;
    elif [ "$coqide_spec" = "yes" -a "$COQIDE" = "byte" ]; then 
	echo "LablGtk2 found, bytecode CoqIde will be used as requested."
	COQIDE=byte
    elif [ ! -f "${CAMLLIB}/threads/threads.cmxa" ]; then 
	echo "LablGtk2 found, no native threads: bytecode CoqIde will be available."
	COQIDE=byte
    else 
	echo "LablGtk2 found, native threads: native CoqIde will be available."
	COQIDE=opt
    fi
fi

case $COQIDE in
    byte|opt)
        case $lablgtkdir_spec in
            no)  LABLGTKLIB=+lablgtk2                   # Pour le message
                 LABLGTKINCLUDES="-I $LABLGTKLIB";;     # Pour le makefile
            yes) LABLGTKLIB="$lablgtkdir"               # Pour le message
                 LABLGTKINCLUDES="-I \"$LABLGTKLIB\"";; # Pour le makefile
        esac;;
    no) LABLGTKINCLUDES="";;
esac

# Tell on windows if ocaml understands cygwin or windows path formats

#"$CAMLC" -o config/giveostype config/giveostype.ml
#CAMLOSTYPE=`config/giveostype`
#rm config/giveostype

case $ARCH in
    win32)
	# true -> strip : it exists under cygwin !
	STRIPCOMMAND="strip";; 
    *)
    if [ "$coq_profile_flag" = "-p" ] ; then
	STRIPCOMMAND="true"
    else
	STRIPCOMMAND="strip"
    fi
esac

# mktexlsr
#MKTEXLSR=`which mktexlsr`
#case $MKTEXLSR in
#    "") MKTEXLSR=true;;
#esac

###########################################
# bindir, libdir, mandir, etc.

case $src_spec in
  no) COQTOP=${COQSRC}
esac

# OCaml only understand Windows filenames (C:\...)
case $ARCH in
    win32) COQTOP=`cygpath -w ${COQTOP}`
esac

case $ARCH in
  win32)
	 bindir_def='C:\coq\bin'
	 libdir_def='C:\coq\lib'
	 mandir_def='C:\coq\man'
	 emacslib_def='C:\coq\emacs'
         coqdocdir_def='C:\coq\latex';;
  *)
	 bindir_def=/usr/local/bin
	 libdir_def=/usr/local/lib/coq
	 mandir_def=/usr/local/man
	 emacslib_def=/usr/share/emacs/site-lisp
         coqdocdir_def=/usr/share/texmf/tex/latex/misc;;
esac

emacs_def=emacs

case $bindir_spec/$prefix_spec/$local in
    yes/*/*) BINDIR=$bindir ;;
    */yes/*) BINDIR=$prefix/bin ;;
    */*/true) BINDIR=$COQTOP/bin ;;
    *) echo "Where should I install the Coq binaries [$bindir_def] ?"
        read BINDIR
	case $BINDIR in
	    "") BINDIR=$bindir_def;;
	    *) true;;
	esac;;
esac

case $libdir_spec/$prefix_spec/$local in
    yes/*/*) LIBDIR=$libdir;;
    */yes/*)
        case $ARCH in
          win32) LIBDIR=$prefix ;;
          *)  LIBDIR=$prefix/lib/coq ;;
        esac ;;
    */*/true) LIBDIR=$COQTOP ;;
    *)  echo "Where should I install the Coq library [$libdir_def] ?"
        read LIBDIR
	case $LIBDIR in
	    "") LIBDIR=$libdir_def;;
	    *) true;;
	esac;;
esac

case $mandir_spec/$prefix_spec/$local in
    yes/*/*) MANDIR=$mandir;;
    */yes/*) MANDIR=$prefix/man ;;
    */*/true) MANDIR=$COQTOP/man ;;
    *)  echo "Where should I install the Coq man pages [$mandir_def] ?"
        read MANDIR
	case $MANDIR in
	    "") MANDIR=$mandir_def;;
	    *) true;;
	esac;;
esac

case $emacslib_spec/$prefix_spec/$local in
    yes/*/*) EMACSLIB=$emacslib;;
    */yes/*)
        case $ARCH in
          win32) EMACSLIB=$prefix/emacs ;;
          *)  EMACSLIB=$prefix/share/emacs/site-lisp ;;
        esac ;;
    */*/true) EMACSLIB=$COQTOP/tools/emacs ;;
    *) echo "Where should I install the Coq Emacs mode [$emacslib_def] ?"
        read EMACSLIB
	case $EMACSLIB in
	    "") EMACSLIB=$emacslib_def;;
	    *) true;;
	esac;;
esac

case $coqdocdir_spec/$prefix_spec/$local in
    yes/*/*) COQDOCDIR=$coqdocdir;;
    */yes/*)
        case $ARCH in
          win32) COQDOCDIR=$prefix/latex ;;
          *)  COQDOCDIR=$prefix/share/emacs/site-lisp ;;
        esac ;;
    */*/true) COQDOCDIR=$COQTOP/tools/coqdoc ;;
    *) echo "Where should I install Coqdoc TeX/LaTeX files [$coqdocdir_def] ?"
        read COQDOCDIR
	case $COQDOCDIR in
	    "") COQDOCDIR=$coqdocdir_def;;
	    *) true;;
	esac;;
esac

case $reals_opt in
    no) echo "Should I compile the complete theory of real analysis [Y/N, default is Y] ?"
	read reals_ans

	case $reals_ans in
	    "N"|"n"|"No"|"NO"|"no")
		    reals=basic;;
		*) reals=all;;
	esac;;
    yes) true;;
esac

# case $emacs_spec in
#     no) echo "Which Emacs command should I use to compile coq.el [$emacs_def] ?"
#         read EMACS
	
# 	case $EMACS in
# 	    "") EMACS=$emacs_def;;
# 	    *) true;;
# 	esac;;
#     yes) EMACS=$emacs;;
# esac

###########################################
# Summary of the configuration

echo ""
echo "  Coq top directory                 : $COQTOP"
echo "  Architecture                      : $ARCH"
if test ! -z "$OS" ; then
  echo "  Operating system                  : $OS"
fi
echo "  OS dependent libraries            : $OSDEPLIBS"
echo "  Objective-Caml/Camlp4 version     : $CAMLVERSION"
echo "  Objective-Caml/Camlp4 binaries in : $CAMLBIN"
echo "  Objective-Caml library in         : $CAMLLIB"
echo "  Camlp4 library in                 : $CAMLP4LIB"
if test "$COQIDE" != "no"; then
echo "  Lablgtk2 library in               : $LABLGTKLIB"
fi
if test "$fsets" = "all"; then
echo "  FSets theory                      : All"
else
echo "  FSets theory                      : Basic"
fi
if test "$reals" = "all"; then
echo "  Reals theory                      : All"
else
echo "  Reals theory                      : Basic"
fi
echo "  CoqIde                            : $COQIDE"
echo ""

echo "  Paths for true installation:"
echo "    binaries   will be copied in $BINDIR"
echo "    library    will be copied in $LIBDIR"
echo "    man pages  will be copied in $MANDIR"
echo "    emacs mode will be copied in $EMACSLIB"
echo ""

#####################################################
# Building the $COQTOP/config/coq_config.ml file
#####################################################

# An escaped version of a variable
escape_var () {
"$ocamlexec" 2>&1 1>/dev/null <<EOF
  prerr_endline(String.escaped(Sys.getenv"$VAR"));;
EOF
}

# damned backslashes under M$Windows
case $ARCH in
    win32)
	ESCCOQTOP=`echo $COQTOP |sed -e 's|\\\|\\\\\\\|g'`
	ESCBINDIR=`echo $BINDIR |sed -e 's|\\\|\\\\\\\|g'`
	ESCLIBDIR=`echo $LIBDIR |sed -e 's|\\\|\\\\\\\|g'`
	ESCCAMLDIR=`echo $CAMLBIN |sed -e 's|\\\|\\\\\\\|g'`
	ESCCAMLLIB=`echo $CAMLLIB |sed -e 's|\\\|\\\\\\\|g'`
  	ESCMANDIR=`echo $MANDIR |sed -e 's|\\\|\\\\\\\|g'`
   	ESCEMACSLIB=`echo $EMACSLIB |sed -e 's|\\\|\\\\\\\|g'`
   	ESCCOQDOCDIR=`echo $COQDOCDIR |sed -e 's|\\\|\\\\\\\|g'`
   	ESCCAMLP4BIN=`echo $CAMLP4BIN |sed -e 's|\\\|\\\\\\\|g'`
	ESCCAMLP4LIB=`echo $CAMLP4LIB |sed -e 's|\\\|\\\\\\\|g'`
	ESCLABLGTKINCLUDES=`echo $LABLGTKINCLUDES |sed -e 's|\\\|\\\\\\\|g'`
	;;
    *)
        ESCCOQTOP="$COQTOP"
	ESCBINDIR="$BINDIR"
	ESCLIBDIR="$LIBDIR"
	ESCCAMLDIR="$CAMLBIN"
	ESCCAMLLIB="$CAMLLIB"
  	ESCMANDIR="$MANDIR"
   	ESCEMACSLIB="$EMACSLIB"
   	ESCCOQDOCDIR="$COQDOCDIR"
   	ESCCAMLP4BIN="$CAMLP4BIN"
   	ESCCAMLP4LIB="$CAMLP4LIB"
	ESCLABLGTKINCLUDES="$LABLGTKINCLUDES"
	;;
esac

mlconfig_file="$COQSRC/config/coq_config.ml"
rm -f $mlconfig_file
cat << END_OF_COQ_CONFIG > $mlconfig_file
(* DO NOT EDIT THIS FILE: automatically generated by ../configure *)

let local = $local
let bindir = "$ESCBINDIR" 
let coqlib = "$ESCLIBDIR"
let coqtop = "$ESCCOQTOP"
let camldir = "$ESCCAMLDIR"
let camllib = "$ESCCAMLLIB"
let camlp4 = "$CAMLP4"
let camlp4lib = "$ESCCAMLP4LIB"
let best = "$best_compiler"
let arch = "$ARCH"
let osdeplibs = "$OSDEPLIBS"
let version = "$VERSION"
let versionsi = "$VERSIONSI"
let date = "$DATE"
let compile_date = "$COMPILEDATE"
let exec_extension = "$EXE"
let with_geoproof = ref $with_geoproof

END_OF_COQ_CONFIG

# to be sure printf is found on windows when spaces occur in PATH variable
PRINTF=`which printf`

# Subdirectories of theories/ added in coq_config.ml
subdirs () {
    (cd $1; find * -type d ! -name .svn -exec $PRINTF "\"%s\";\n" {} \; | grep -v extraction/test | grep -v correctness >> "$mlconfig_file")
}

echo "let theories_dirs = [" >> "$mlconfig_file"
subdirs theories
echo "]" >> "$mlconfig_file"

echo "let contrib_dirs = [" >> "$mlconfig_file"
subdirs contrib
echo "]" >> "$mlconfig_file"

chmod a-w "$mlconfig_file"


###############################################
# Building the $COQTOP/config/Makefile file
###############################################

rm -f "$COQSRC/config/Makefile"

sed -e "s|LOCALINSTALLATION|$local|" \
    -e "s|COQSRCDIRECTORY|$COQSRC|" \
    -e "s|COQVERSION|$VERSION|" \
    -e "s|BINDIRDIRECTORY|$ESCBINDIR|" \
    -e "s|COQLIBDIRECTORY|$ESCLIBDIR|" \
    -e "s|MANDIRDIRECTORY|$ESCMANDIR|" \
    -e "s|EMACSLIBDIRECTORY|$ESCEMACSLIB|" \
    -e "s|EMACSCOMMAND|$EMACS|" \
    -e "s|COQDOCDIRECTORY|$ESCCOQDOCDIR|" \
    -e "s|MKTEXLSRCOMMAND|$MKTEXLSR|" \
    -e "s|ARCHITECTURE|$ARCH|" \
    -e "s|OSDEPENDENTLIBS|$OSDEPLIBS|" \
    -e "s|OSDEPENDENTP4OPTFLAGS|$OSDEPP4OPTFLAGS|" \
    -e "s|CAMLLIBDIRECTORY|$ESCCAMLLIB|" \
    -e "s|CAMLTAG|$CAMLTAG|" \
    -e "s|CAMLP4BINDIRECTORY|$ESCCAMLP4BIN|" \
    -e "s|CAMLP4LIBDIRECTORY|$CAMLP4LIB|" \
    -e "s|CAMLP4TOOL|$camlp4oexec|" \
    -e "s|CAMLP4COMPATFLAGS|$CAMLP4COMPAT|" \
    -e "s|LABLGTKINCLUDES|$ESCLABLGTKINCLUDES|" \
    -e "s|COQDEBUGFLAG|$coq_debug_flag|" \
    -e "s|COQPROFILEFLAG|$coq_profile_flag|" \
    -e "s|COQINLINEFLAG|$coq_inline_flag|" \
    -e "s|CAMLANNOTATEFLAG|$coq_annotate_flag|" \
    -e "s|CCOMPILEFLAGS|$cflags|" \
    -e "s|BESTCOMPILER|$best_compiler|" \
    -e "s|EXECUTEEXTENSION|$EXE|" \
    -e "s|BYTECAMLC|$bytecamlc|" \
    -e "s|NATIVECAMLC|$nativecamlc|" \
    -e "s|OCAMLDEPEXEC|$ocamldepexec|" \
    -e "s|OCAMLDOCEXEC|$ocamldocexec|" \
    -e "s|OCAMLLEXEXEC|$ocamllexexec|" \
    -e "s|OCAMLYACCEXEC|$ocamlyaccexec|" \
    -e "s|CAMLMKTOPEXEC|$camlmktopexec|" \
    -e "s|CCEXEC|$gcc_exec|" \
    -e "s|AREXEC|$ar_exec|" \
    -e "s|RANLIBEXEC|$ranlib_exec|" \
    -e "s|STRIPCOMMAND|$STRIPCOMMAND|" \
    -e "s|FSETSOPT|$fsets|" \
    -e "s|REALSOPT|$reals|" \
    -e "s|COQIDEOPT|$COQIDE|" \
    -e "s|CHECKEDOUTSOURCETREE|$checkedout|" \
      "$COQSRC/config/Makefile.template" > "$COQSRC/config/Makefile"

chmod a-w "$COQSRC/config/Makefile"

##################################################
# Building the $COQTOP/dev/ocamldebug-coq file
##################################################

OCAMLDEBUGCOQ=$COQSRC/dev/ocamldebug-coq

if test "$coq_debug_flag" = "-g" ; then
  rm -f $OCAMLDEBUGCOQ
  sed -e "s|COQTOPDIRECTORY|$COQTOP|" \
      -e "s|COQLIBDIRECTORY|$LIBDIR|" \
      -e "s|CAMLBINDIRECTORY|$CAMLBIN|" \
      -e "s|CAMLP4LIBDIRECTORY|$FULLCAMLP4LIB|"\
      $OCAMLDEBUGCOQ.template > $OCAMLDEBUGCOQ
  chmod a-w,a+x $OCAMLDEBUGCOQ
fi

####################################################
# Fixing lablgtk types (before/after 2.6.0) 
####################################################

if [ ! "$COQIDE" = "no" ]; then 
    if grep "class view " "$lablgtkdir/gText.mli" | grep -q "\[>" ; then
	cp -f ide/undo_lablgtk_ge26.mli ide/undo.mli
    else
	cp -f ide/undo_lablgtk_lt26.mli ide/undo.mli
    fi
fi  

##################################################
# The end
####################################################

echo "If anything in the above is wrong, please restart './configure'"
echo
echo "*Warning* To compile the system for a new architecture"
echo "          don't forget to do a 'make archclean' before './configure'."

# $Id: configure 10375 2007-12-13 15:02:01Z notin $