Drop patches
[pkg-ocaml-ocsigen.git] / configure
blob88972a67de03a7c0714444047b1971ab0a786407
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"
67 #######################################################################
68 # Defaults
70 #--- Options ---
71 # value 0: off
72 # value 1: on
73 # defaults:
75 set_defaults () {
76 name="ocsigenserver"
77 enable_natdynlink=1
78 enable_debug=0
79 enable_annot=0
80 with_sqlite=1
81 with_camlzip=1
82 with_dbm=1
83 with_preempt=1
84 prefix="/usr/local"
85 bindir=""
86 logdir=""
87 libdir=""
88 mandir=""
89 docdir=""
90 sysconfdir="/etc/\$(PROJECTNAME)"
91 staticpagesdir="/var/www/\$(PROJECTNAME)"
92 uploaddir="/tmp"
93 datadir="/var/lib/\$(PROJECTNAME)"
94 temproot=""
95 root=""
96 ocsigen_user="www-data"
97 ocsigen_group="www-data"
100 set_defaults
101 my_pwd=`dirname $0`
102 version=`head -n 1 $my_pwd/VERSION`
103 full_pwd=`pwd`
105 ########################################################################
106 ## Option parsing
108 ## Which options exist? eoptions for enable/disable, woptions for with/without:
109 eoptions="debug annot natdynlink"
110 woptions="sqlite dbm camlzip preempt"
112 print_options () {
113 for opt in $eoptions; do
114 e="o=\$enable_$opt"
115 eval "$e"
116 uopt=`echo $opt | sed -e 's/_/-/g'`
117 if [ $o -gt 0 ]; then
118 echo " --enable-$uopt"
119 else
120 echo " --disable-$uopt"
122 done
123 for opt in $woptions; do
124 e="o=\$with_$opt"
125 eval "$e"
126 uopt=`echo $opt | sed -e 's/_/-/g'`
127 if [ $o -gt 0 ]; then
128 echo " --with-$uopt"
129 else
130 echo " --without-$uopt"
132 done
133 case "$bindir" in
134 "") bindir2="<prefix>/bin";;
135 *) bindir2=$bindir;;
136 esac
138 case "$logdir" in
139 "") logdir2="<prefix>/var/log/<name>";;
140 *) logdir2=$logdir;;
141 esac
143 case "$libdir" in
144 "") libdir2="\$(shell \${OCAMLFIND} printconf destdir)";;
145 *) libdir2=$libdir;;
146 esac
148 case "$mandir" in
149 "") mandir2="<prefix>/share/man/man1";;
150 *) mandir2=$mandir;;
151 esac
153 case "$docdir" in
154 "") docdir2="<prefix>/share/doc/\$(PROJECTNAME)";;
155 *) docdir2=$docdir;;
156 esac
158 echo " --name $name"
159 echo " --root $root"
160 echo " --temproot $temproot"
161 echo " --prefix $prefix"
162 echo " --ocsigen-user $ocsigen_user"
163 echo " --ocsigen-group $ocsigen_group"
164 echo " --bindir $bindir2"
165 echo " --libdir $libdir2"
166 echo " --sysconfdir $sysconfdir"
167 echo " --mandir $mandir2"
168 echo " --docdir $docdir2"
169 echo " --logdir $logdir2"
170 echo " --staticpagesdir $staticpagesdir"
171 echo " --uploaddir $uploaddir"
172 echo " --datadir $datadir"
173 echo " --commandpipe $commandpipe"
177 usage () {
178 set_defaults
179 cat <<_EOF_ >&2
180 usage: ./configure [ options ]
182 --enable-debug, --disable-debug Enable/disable debug output
183 --enable-annot, --disable-annot Enable/disable .annot files generation
184 --enable-natdynlink, --disable-natdynlink Enable/disable nativecode dynamic linking
186 --with-sqlite, --without-sqlite Compile ocsipersist with SQLite for persistent storage
187 --with-dbm, --without-dbm Compile ocsipersist with DBM for persistent storage
188 --with-camlzip, --without-camlzip Compile deflatemod extension, requires camlzip
190 --name=NAME The name of the server binary and ocamlfind package.
192 --ocsigen-user=NAME The name of the ocsigen user
193 --ocsigen-group=NAME The name of the ocsigen group
195 --root=DIR Root directory to install the package, every other options are relatives to this path. (usually /)
196 --temproot=DIR Temporary root directory to install the package (usually always "" but for package makers)
197 --prefix=DIR Subdirectory where to install binaries and libs (usually /usr or /usr/local)
199 --bindir=DIR Install binaries into this directory
200 --libdir=DIR Common directory for Ocsigen server's libraries
202 --sysconfdir=DIR Create configuration files in this directory
203 --mandir=DIR Install man pages in this directory
204 --docdir=DIR Install documentation in this directory
206 --logdir=DIR Use this directory for Ocsigen's logs
207 --datadir=DIR The directory for data written by the server
209 --staticpagesdir=DIR Install default static pages in this directory
210 --uploaddir=DIR By default, files will be uploaded in this directory
212 --commandpipe=FILE The name of the named pipe used to command the server
214 Defaults are:
216 _EOF_
217 print_options >&2
218 exit 1
222 check_eopt () {
223 for x in $eoptions; do
224 if [ "$x" = "$1" ]; then
225 return 0
227 done
228 echo "Unknown option: $1" >&2
229 exit 1
233 check_wopt () {
234 for x in $woptions; do
235 if [ "$x" = "$1" ]; then
236 return 0
238 done
239 echo "Unknown option: $1" >&2
240 exit 1
243 echo "\n\tWelcome to Ocsigen server, version $version.\n" >&2
245 while [ "$#" -gt 0 ]; do
246 case "$1" in
247 --enable-*)
248 opt=`echo "$1" | sed -e 's/--enable-//' -e 's/-/_/g'`
249 check_eopt "$opt"
250 eval "enable_$opt=2"
251 shift
253 --disable-*)
254 opt=`echo "$1" | sed -e 's/--disable-//' -e 's/-/_/g'`
255 check_eopt "$opt"
256 eval "enable_$opt=-1"
257 shift
259 --with-*)
260 opt=`echo "$1" | sed -e 's/--with-//' -e 's/-/_/g'`
261 check_wopt "$opt"
262 eval "with_$opt=2"
263 shift
265 --without-*)
266 opt=`echo "$1" | sed -e 's/--without-//' -e 's/-/_/g'`
267 check_wopt "$opt"
268 eval "with_$opt=-1"
269 shift
271 --root)
272 root="$2"
273 shift
274 shift
276 --temproot)
277 temproot="$2"
278 shift
279 shift
281 --prefix)
282 prefix="$2"
283 shift
284 shift
286 --bindir)
287 bindir="$2"
288 shift
289 shift
291 --logdir)
292 logdir="$2"
293 shift
294 shift
296 --libdir)
297 libdir="$2"
298 shift
299 shift
301 --mandir)
302 mandir="$2"
303 shift
304 shift
306 --docdir)
307 docdir="$2"
308 shift
309 shift
311 --staticpagesdir)
312 staticpagesdir="$2"
313 shift
314 shift
316 --sysconfdir)
317 sysconfdir="$2"
318 shift
319 shift
321 --uploaddir)
322 uploaddir="$2"
323 shift
324 shift
326 --datadir)
327 datadir="$2"
328 shift
329 shift
331 --name)
332 name="$2"
333 shift
334 shift
336 --ocsigen-user)
337 ocsigen_user="$2"
338 shift
339 shift
341 --ocsigen-group)
342 ocsigen_group="$2"
343 shift
344 shift
346 --commandpipe)
347 commandpipe="$2"
348 shift
349 shift
352 echo "Unknown option: $1" >&2
353 usage
354 esac
355 done
357 case "$bindir" in
358 "") bindir="$prefix/bin";;
359 esac
361 case "$logdir" in
362 "") logdir="/var/log/\$(PROJECTNAME)";;
363 esac
365 case "$libdir" in
366 "") libdir="\$(shell \${OCAMLFIND} printconf destdir)";;
367 *) libdir=$root$libdir
368 esac
370 case "$mandir" in
371 "") mandir="$prefix/share/man/man1";;
372 esac
374 case "$docdir" in
375 "") docdir="$prefix/share/doc/\$(PROJECTNAME)";;
376 esac
378 case "$commandpipe" in
379 "") commandpipe="/var/run/\$(PROJECTNAME)_command";;
380 esac
384 check_binary ocamlc "See: http://www.ocaml.org/"
386 check_ocamlversion () {
388 echo -n "Checking for OCaml version... "
389 version=`ocamlc -version`
390 echo $version
391 n1=`echo $version | sed 's/^\([0-9][0-9]*\)\..*$/\1/'`
392 n2=`echo $version | sed 's/^[0-9][0-9]*\.\([0-9][0-9]*\)\..*$/\1/'`
393 # n3=`echo $version | sed 's/^[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\)\..*$/\1/'`
394 if [ $n1 -eq 3 ] && [ $n2 -lt 12 ]; then
395 echo;
396 echo "OCaml >= 3.12 is required. Aborting.";
397 exit 1;
402 check_ocamlversion
404 check_binary ocamlfind "See: http://projects.camlcity.org/projects/findlib.html"
406 check_library react "See: http://erratique.ch/software/react"
407 check_library ssl "See: http://sourceforge.net/projects/savonet/files/ocaml-ssl"
409 check_library lwt "See: http://ocsigen.org/lwt"
410 check_library lwt.unix "Missing support for 'unix' in lwt."
411 check_library lwt.react "Missing support for 'react' in lwt."
412 check_library lwt.ssl "Missing support for 'ssl' in lwt."
413 #check_library lwt.extra "Missing support for 'extra' in lwt."
415 check_library netstring \
416 "See ocamlnet: http://projects.camlcity.org/projects/ocamlnet.html"
417 check_library netsys \
418 "See ocamlnet: http://projects.camlcity.org/projects/ocamlnet.html"
420 check_library pcre "See: http://ocaml.info/home/ocaml_sources.html"
421 check_library cryptokit "See: http://pauillac.inria.fr/~xleroy/software.html#cryptokit"
423 check_library tyxml "See: http://ocsigen.org/tyxml/"
425 # Check Sqlite3
426 case "$with_sqlite" in
427 1) if test_library sqlite3; then with_sqlite=1; else with_sqlite=0; fi;;
428 2) check_library sqlite3 "See: http://ocaml.info/home/ocaml_sources.html";;
429 esac
431 # Check dbm
432 if [ "$with_dbm" -gt 0 ]; then
433 if test_library dbm; then
434 echo -n
435 elif [ "$with_dbm" -gt 1 ]; then
436 fail_library dbm
437 else
438 with_dbm=0
442 # Check Camlzip
443 if [ "$with_camlzip" -gt 0 ]; then
444 if test_library camlzip; then
445 zipname=camlzip
446 elif test_library zip; then
447 zipname=zip
448 elif [ "$with_camlzip" -gt 1 ]; then
449 fail_library camlzip "https://forge.ocamlcore.org/projects/camlzip/"
450 else
451 with_camlzip=0
455 # Check Lwt.extra
456 if [ "$with_preempt" -gt 0 ]; then
457 if test_library lwt.extra; then
458 echo -n
459 elif [ "$with_preempt" -gt 1 ]; then
460 fail_library lwt.extra "Missing support for 'extra' in lwt."
461 else
462 with_preempt=0
466 if [ "$with_sqlite" -eq 1 ] && [ "$with_preempt" -eq -1 ]; then
467 echo "preemptive threads are needed by sqlite, enable it with -with-preempt"
468 exit 1
471 # Check rlwrap or ledit
472 if test_binary rlwrap; then
473 rlwrap=rlwrap
474 elif test_binary ledit; then
475 rlwrap=ledit
476 else
477 rlwrap=
480 ######################################################################
481 # Summary
483 echo
484 echo "Effective options:"
485 print_options
486 echo
489 #Convert 0/1 values to YES/NO
490 if [ $enable_debug -gt 0 ] ; then
491 enable_debug="YES"
492 else
493 enable_debug="NO"
495 if [ $enable_annot -gt 0 ] ; then
496 enable_annot="YES"
497 else
498 enable_annot="NO"
500 if [ $enable_natdynlink -gt 0 ] ; then
501 enable_natdynlink="YES"
502 else
503 enable_natdynlink="NO"
505 if [ $with_dbm -gt 0 ] ; then
506 with_dbm="YES"
507 else
508 with_dbm="NO"
510 if [ $with_sqlite -gt 0 ] ; then
511 with_sqlite="YES"
512 else
513 with_sqlite="NO"
515 if [ $with_camlzip -gt 0 ] ; then
516 with_camlzip="YES"
517 else
518 with_camlzip="NO"
520 if [ $with_preempt -gt 0 ] ; then
521 with_preempt="YES"
522 else
523 with_preempt="NO"
526 ocamlinclude=`ocamlfind printconf stdlib`
528 ######################################################################
529 # Write Makefile.conf
531 echo "Writing Makefile.config"
532 cat <<_EOF_ > $my_pwd/Makefile.config
534 # The name of the server, the ocamlfind package, etc.
535 PROJECTNAME := $name
537 #### External binaries ####
539 OCAMLFIND := ocamlfind
540 OCAMLLEX := ocamllex
541 OCAMLMKLIB:= ocamlmklib
542 CHOWN := chown
543 CHMOD := chmod
544 INSTALL := install
545 CC := gcc
547 # optionnal
548 RLWRAP := $rlwrap
551 ### Options ###
553 # User who will run Ocsigen server (not root) (eg, for debian, www-data)
554 # (This user must exist on your system)
555 OCSIGENUSER := $ocsigen_user
557 # group who will run Ocsigen server (not root) (eg, for debian, www-data)
558 # (This group must exist)
559 OCSIGENGROUP := $ocsigen_group
561 # Do you want deflatemod? YES/NO (requires camlzip)
562 CAMLZIP:=$with_camlzip
564 # The name of camlzip package:
565 CAMLZIPNAME:=$zipname
567 # Do you want ocsipersist with sqlite? YES/NO
568 OCSIPERSISTSQLITE:=$with_sqlite
570 # Do you want ocsipersist with dbm? YES/NO
571 OCSIPERSISTDBM:=$with_dbm
573 # Do you want preemptive threads ? YES/NO
574 PREEMPTIVE:=$with_preempt
576 # Do you want debugging information (-g) ? YES/NO
577 DEBUG:=$enable_debug
579 # Do you want annot files (-dtypes) ? YES/NO
580 ANNOT:=$enable_annot
582 # Profiling (always put NO here - but if you want to debug ocsigen):
583 PROFILING:=NO
587 ### Paths ###
589 # Temporary root directory to install the package (usually always "" but for package makers)
590 TEMPROOT := $temproot
592 # Do you want to use dynamic linking for native code? YES/NO
593 NATDYNLINK:=$enable_natdynlink
595 # The directory for ocsigen server (binary):
596 BINDIR := $root$bindir
598 # The directory for ocsigen manpage:
599 MANDIR := $root$mandir
601 # Where to install the libraries
602 LIBDIR := $libdir
604 # ocsigen's logs:
605 LOGDIR := $root$logdir
607 # Config files:
608 CONFIGDIR := $root$sysconfdir
610 # Where to put static pages:
611 STATICPAGESDIR := $root$staticpagesdir
613 # Where to put dynamic data:
614 DATADIR := $root$datadir
616 # Default directory for file upload:
617 UPLOADDIR := $root$uploaddir
619 # Where to put Ocsigen documentation:
620 DOCDIR := $root$docdir
622 # The name of the named pipe used to command the server
623 COMMANDPIPE := $root$commandpipe
625 # The source directory
626 SRC := $full_pwd
628 include \$(SRC)/Makefile.options
629 _EOF_
631 ######################################################################
632 # Finish
634 echo
635 echo
636 echo "Please check Makefile.config."
637 echo
638 echo "You can now compile Ocsigen Server by invoking:"
639 echo
640 echo " make"
641 echo " make doc"
642 echo
643 echo "You may want to test the server before installation:"
644 echo
645 echo " make run.local"
646 echo " make run.opt.local"
647 echo
648 echo "Finally, if you want system-wide install, (become root if needed and) do:"
649 echo
650 echo " make install"
651 echo " make install.doc"
652 echo