Initial packaging
[pkg-ocaml-eliom.git] / configure
blob03ba6e73180da12bf38ad2a75520b665960569a9
1 #! /bin/sh
3 # Adapted from the ocamlnet configure script.
5 #######################################################################
6 # Helpers:
8 test_binary () {
9 # $1: the name of the binary
10 echo -n "Checking for $1 ... "
11 if which "$1" >/dev/null 2>/dev/null; then
12 echo "found"
13 return 0
14 else
15 echo "not found"
16 return 1
20 fail_binary () {
21 echo
22 echo "Required command '$1' not found!"
23 [ -z "$2" ] || echo "===> $2"
24 exit 1
27 check_binary () {
28 # $1: the name of the binary
29 # $2: an URL
30 if test_binary "$1"; then
31 return
32 else
33 fail_binary "$1" "$2"
38 test_library () {
39 # $1: the name of the library (findlib)
40 echo -n "Checking for $1 ... "
41 if ocamlfind query $1 >/dev/null 2>/dev/null; then
42 echo "found"
43 return 0
44 else
45 echo "not found"
46 return 1
50 fail_library () {
51 echo
52 echo "Required library $1 not found!"
53 [ -z "$2" ] || echo "===> $2"
54 exit 1
57 check_library () {
58 # $1: the name of the library (findlib)
59 # $2: an URL
60 if test_library "$1"; then
61 return
62 else
63 fail_library "$1" "$2"
68 #######################################################################
69 # Defaults
71 #--- Options ---
72 # value 0: off
73 # value 1: on
74 # defaults:
76 set_defaults () {
77 name="eliom"
78 enable_natdynlink=1
79 enable_debug=0
80 enable_annot=0
81 with_preempt=1
82 with_ocamlduce=1
83 root=""
84 temproot=""
85 prefix="/usr/local"
86 bindir=""
87 libdir=""
88 docdir=""
91 set_defaults
92 my_pwd=$(dirname $0)
93 version=$(head -n 1 $my_pwd/VERSION)
94 full_pwd=$(pwd)
96 ########################################################################
97 ## Option parsing
100 ehelp_debug="Enable/disable debug output"
101 ehelp_annot="Enable/disable .annot files"
102 ehelp_natdynlink="Enable/disable nativecode dynamic linking"
103 whelp_ocamlduce="Compile Ocamlduce support for typing pages"
105 ## Which options exist? eoptions for enable/disable, woptions for with/without:
106 eoptions="debug annot natdynlink"
107 woptions="ocamlduce preempt"
109 print_options () {
110 for opt in $eoptions; do
111 e="o=\$enable_$opt"
112 eval "$e"
113 uopt=$(echo $opt | sed -e 's/_/-/g')
114 if [ $o -gt 0 ]; then
115 echo " --enable-$uopt"
116 else
117 echo " --disable-$uopt"
119 done
120 for opt in $woptions; do
121 e="o=\$with_$opt"
122 eval "$e"
123 uopt=$(echo $opt | sed -e 's/_/-/g')
124 if [ $o -gt 0 ]; then
125 echo " --with-$uopt"
126 else
127 echo " --without-$uopt"
129 done
130 case "$bindir" in
131 "") bindir2="<prefix>/bin";;
132 *) bindir2=$bindir;;
133 esac
135 case "$libdir" in
136 "") libdir2="\$(shell \${OCAMLFIND} printconf destdir)";;
137 *) libdir2=$libdir;;
138 esac
140 case "$docdir" in
141 "") docdir2="<prefix>/share/doc/\$(PROJECTNAME)";;
142 *) docdir2=$docdir;;
143 esac
145 echo " --name $name"
146 echo " --root $root"
147 echo " --temproot $temproot"
148 echo " --prefix $prefix"
149 echo " --bindir $bindir2"
150 echo " --libdir $libdir2"
151 echo " --docdir $docdir2"
154 usage () {
155 set_defaults
156 cat <<_EOF_ >&2
157 usage: ./configure [ options ]
159 --enable-debug, --disable-debug Enable/disable debug output
160 --enable-annot, --disable-annot Enable/disable .annot files generation
161 --enable-natdynlink, --disable-natdynlink Enable/disable nativecode dynamic linking
163 --with-preempt, --without-preempt compile with preemptive threads support.
164 --with-ocamlduce, --without-ocamlduce Compile ocamlduce based libraries.
166 --name=NAME The name of the library and ocamlfind package.
168 --root=DIR Root directory to install the package, every other options are relatives to this path. (usually /)
169 --temproot=DIR Temporary root directory to install the package (usually always "" but for package makers)
170 --prefix=DIR Subdirectory where to install binaries and libs (usually /usr or /usr/local)
172 --bindir=DIR Install binaries into this directory
173 --libdir=DIR Common directory for Ocsigen server's libraries
174 --docdir=DIR Install documentation in this directory
176 Defaults are:
178 _EOF_
179 print_options >&2
180 exit 1
184 check_eopt () {
185 for x in $eoptions; do
186 if [ "$x" = "$1" ]; then
187 return 0
189 done
190 echo "Unknown option: $1" >&2
191 exit 1
195 check_wopt () {
196 for x in $woptions; do
197 if [ "$x" = "$1" ]; then
198 return 0
200 done
201 echo "Unknown option: $1" >&2
202 exit 1
206 echo "Welcome to Eliom version $version" >&2
208 while [ "$#" -gt 0 ]; do
209 case "$1" in
210 --enable-*)
211 opt=$(echo "$1" | sed -e 's/--enable-//' -e 's/-/_/g')
212 check_eopt "$opt"
213 eval "enable_$opt=2"
214 shift
216 --disable-*)
217 opt=$(echo "$1" | sed -e 's/--disable-//' -e 's/-/_/g')
218 check_eopt "$opt"
219 eval "enable_$opt=-1"
220 shift
222 --with-*)
223 opt=$(echo "$1" | sed -e 's/--with-//' -e 's/-/_/g')
224 check_wopt "$opt"
225 eval "with_$opt=2"
226 shift
228 --without-*)
229 opt=$(echo "$1" | sed -e 's/--without-//' -e 's/-/_/g')
230 check_wopt "$opt"
231 eval "with_$opt=-1"
232 shift
234 --root)
235 root="$2"
236 shift
237 shift
239 --temproot)
240 temproot="$2"
241 shift
242 shift
244 --prefix)
245 prefix="$2"
246 shift
247 shift
249 --name)
250 name="$2"
251 shift
252 shift
254 --bindir)
255 bindir="$2"
256 shift
257 shift
259 --libdir)
260 libdir="$2"
261 shift
262 shift
264 --docdir)
265 docdir="$2"
266 shift
267 shift
270 echo "Unknown option: $1" >&2
271 usage
272 esac
273 done
275 case "$bindir" in
276 "") bindir="$prefix/bin";;
277 esac
279 case "$libdir" in
280 "") libdir="\$(shell \${OCAMLFIND} printconf destdir)";;
281 *) libdir=$root$libdir
282 esac
284 case "$docdir" in
285 "") docdir="$prefix/share/doc/\$(PROJECTNAME)";;
286 esac
289 check_binary ocamlc "See: http://www.ocaml.org/"
291 check_ocamlversion () {
293 echo -n "Checking for OCaml version... "
294 version=$(ocamlc -version)
295 echo $version
296 n1=$(echo $version | sed 's/^\([0-9][0-9]*\)\..*$/\1/')
297 n2=$(echo $version | sed 's/^[0-9][0-9]*\.\([0-9][0-9]*\)\..*$/\1/')
298 # n3=`echo $version | sed 's/^[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\)\..*$/\1/'`
299 if [ $n1 -eq 3 ] && [ $n2 -lt 12 ]; then
300 echo;
301 echo "OCaml >= 3.12 is required. Aborting.";
302 exit 1;
307 check_ocsigenserverversion () {
309 echo -n "Checking for ocsigenserver version... "
310 version=$(ocamlfind query ocsigenserver -l | grep version: | awk '{ print $2 }')
311 echo $version
312 n1=$(echo $version | sed 's/^\([0-9][0-9]*\)\..*$/\1/')
313 n2=$(echo $version | sed 's/^[0-9][0-9]*\.\([0-9][0-9]*\).*$/\1/')
314 # n3=`echo $version | sed 's/^[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\)\..*$/\1/'`
315 if [ $n1 -eq 1 ] && [ $n2 -lt 91 ]; then
316 echo;
317 echo "Ocsigenserver >= 1.91 is required. Aborting.";
318 exit 1;
323 check_ocamlversion
325 check_binary ocamlfind "See: http://projects.camlcity.org/projects/findlib.html"
327 check_library ocsigenserver "See: http://ocsigen.org/ocsigenserver/"
328 check_ocsigenserverversion
330 check_library deriving-ocsigen "See: https://github.com/hnrgrgr/deriving"
332 check_binary js_of_ocaml "See: http://ocsigen.org/js_of_ocaml"
333 check_library js_of_ocaml.deriving "Missing support for deriving-ocsigen in js_of_ocaml"
335 check_library react "See: http://erratique.ch/software/react"
337 check_library lwt "See: http://ocsigen.org/lwt"
338 check_library lwt.unix "Missing support for 'unix' in lwt."
339 check_library lwt.react "Missing support for 'react' in lwt."
341 check_library calendar "See: http://calendar.forge.ocamlcore.org/"
343 # Check ocamlduce
344 if [ "$with_ocamlduce" -gt 0 ]; then
345 if test_binary ocamlduce; then
346 echo -n
347 elif [ "$with_ocamlduce" -gt 1 ]; then
348 fail_binary ocamlduce "http://ocamlduce.forge.ocamlcore.org/"
349 else
350 with_ocamlduce=0
354 if [ "$with_ocamlduce" -gt 0 ]; then
355 check_library tyxml.duce "Missing support for 'ocamlduce' in tyxml."
358 ######################################################################
359 # Summary
361 echo
362 echo "Effective options:"
363 print_options
364 echo
366 #Convert 0/1 values to YES/NO
367 if [ $enable_debug -gt 0 ] ; then
368 enable_debug="YES"
369 else
370 enable_debug="NO"
372 if [ $enable_annot -gt 0 ] ; then
373 enable_annot="YES"
374 else
375 enable_annot="NO"
377 if [ $enable_natdynlink -gt 0 ] ; then
378 enable_natdynlink="YES"
379 else
380 enable_natdynlink="NO"
382 if [ $with_ocamlduce -gt 0 ] ; then
383 with_ocamlduce="YES"
384 else
385 with_ocamlduce="NO"
387 if [ $with_preempt -gt 0 ] ; then
388 with_preempt="YES"
389 else
390 with_preempt="NO"
393 ######################################################################
394 # Write Makefile.conf
396 echo "Writing Makefile.config"
397 cat <<_EOF_ > $my_pwd/Makefile.config
399 # The name of the library, ocamlfind package, etc.
400 PROJECTNAME := $name
402 #### External binaries ####
404 OCAMLFIND := ocamlfind
405 OCAMLMKLIB := ocamlmklib
406 JS_OF_OCAML := js_of_ocaml
407 CC := gcc
408 INSTALL := install
410 # optionnal
411 OCAMLDUCEFIND := ocamlducefind
415 ### Options ###
417 # Do you want the ocamlduce extension? YES/NO
418 # (You need ocamlduce to be installed)
419 OCAMLDUCE:=$with_ocamlduce
421 # Do you want preemptive threads ? YES/NO
422 PREEMPTIVE:=$with_preempt
424 # Do you want to use dynamic linking for native code? YES/NO
425 NATDYNLINK:=$enable_natdynlink
427 # Do you want debugging information (-g) ? YES/NO
428 DEBUG:=$enable_debug
430 # Do you want annot files (-dtypes) ? YES/NO
431 ANNOT:=$enable_annot
433 # Profiling (always put NO here - but if you want to debug eliom):
434 PROFILING:=NO
438 ### Paths ###
440 # Temporary root directory to install the package (usually always "" but for package makers)
441 TEMPROOT = $temproot
443 # The directory for eliom compiler (binary):
444 BINDIR := $root$bindir
446 # Where to install Eliom libraries:
447 LIBDIR := $libdir
449 # Where to put Eliom documentation:
450 DOCDIR := $root$docdir
452 # The source directory (needed for local testing)
453 SRC := $full_pwd
455 include \$(SRC)/Makefile.options
457 _EOF_
459 ######################################################################
460 # Finish
462 echo
463 echo
464 echo "Please check Makefile.config."
465 echo
466 echo "You can now compile Eliom by invoking:"
467 echo
468 echo " make"
469 echo " make doc"
470 echo
471 echo "You may want to test the extension before installation:"
472 echo
473 echo " make run.local"
474 echo " make run.opt.local"
475 echo
476 echo "Finally, if you want system-wide install, (become root if needed and) do"
477 echo
478 echo " make install"
479 echo " make install.doc"
480 echo