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
|
#! /bin/sh
# Adapted from the ocamlnet configure script.
#######################################################################
# Helpers:
test_binary () {
# $1: the name of the binary
echo -n "Checking for $1 ... "
if command -v "$1" >/dev/null 2>/dev/null; then
echo "found"
return 0
else
echo "not found"
return 1
fi
}
fail_binary () {
echo
echo "Required command '$1' not found!"
[ -z "$2" ] || echo "===> $2"
exit 1
}
check_binary () {
# $1: the name of the binary
# $2: an URL
if test_binary $1; then
return
else
fail_binary $1 $2
fi
}
test_library () {
# $1: the name of the library (findlib)
echo -n "Checking for $1 ... "
if ocamlfind query $1 >/dev/null 2>/dev/null; then
echo "found"
return 0
else
echo "not found"
return 1
fi
}
fail_library () {
echo
echo "Required library $1 not found!"
[ -z "$2" ] || echo "===> $2"
exit 1
}
check_library () {
# $1: the name of the library (findlib)
# $2: an URL
if test_library $1; then
return
else
fail_library $1 "$2"
fi
}
#######################################################################
# Defaults
#--- Options ---
# value 0: off
# value 1: on
# defaults:
set_defaults () {
with_sqlite=1
with_pgsql=1
with_dbm=1
prefix="/usr/local"
bindir=""
logdir=""
libdir=""
libdir_set=0
mandir=""
docdir=""
sysconfdir="/etc/ocsigenserver"
staticpagesdir="/var/www/ocsigenserver"
uploaddir="/tmp"
datadir="/var/lib/ocsigenserver"
temproot="local"
root=""
ocsigen_user="www-data"
ocsigen_group="www-data"
}
set_defaults
my_pwd=`dirname $0`
version=`head -n 1 $my_pwd/VERSION`
full_pwd=`pwd`
########################################################################
## Option parsing
## Which options exist? eoptions for enable/disable, woptions for with/without:
eoptions=""
woptions="pgsql sqlite dbm"
print_options () {
for opt in $eoptions; do
e="o=\$enable_$opt"
eval "$e"
uopt=`echo $opt | sed -e 's/_/-/g'`
if [ $o -gt 0 ]; then
echo " --enable-$uopt"
else
echo " --disable-$uopt"
fi
done
for opt in $woptions; do
e="o=\$with_$opt"
eval "$e"
uopt=`echo $opt | sed -e 's/_/-/g'`
if [ $o -gt 0 ]; then
echo " --with-$uopt"
else
echo " --without-$uopt"
fi
done
case "$bindir" in
"") bindir2="<prefix>/bin";;
*) bindir2=$bindir;;
esac
case "$logdir" in
"") logdir2="<prefix>/var/log/<name>";;
*) logdir2=$logdir;;
esac
case "$libdir" in
"") libdir2="\$(shell \${OCAMLFIND} printconf destdir)";;
*) libdir2=$libdir;;
esac
case "$mandir" in
"") mandir2="<prefix>/share/man/man1";;
*) mandir2=$mandir;;
esac
case "$docdir" in
"") docdir2="<prefix>/share/doc/ocsigenserver";;
*) docdir2=$docdir;;
esac
echo " --name $name"
echo " --root $root"
echo " --temproot $temproot"
echo " --prefix $prefix"
echo " --ocsigen-user $ocsigen_user"
echo " --ocsigen-group $ocsigen_group"
echo " --bindir $bindir2"
echo " --libdir $libdir2"
echo " --sysconfdir $sysconfdir"
echo " --mandir $mandir2"
echo " --docdir $docdir2"
echo " --logdir $logdir2"
echo " --staticpagesdir $staticpagesdir"
echo " --uploaddir $uploaddir"
echo " --datadir $datadir"
echo " --commandpipe $commandpipe"
}
usage () {
set_defaults
cat <<_EOF_ >&2
usage: ./configure [ options ]
--name NAME The name of the server binary and ocamlfind package.
--ocsigen-user NAME The name of the ocsigen user
--ocsigen-group NAME The name of the ocsigen group
--root DIR Root directory to install the package, every other options are relatives to this path. (usually /)
--temproot DIR Temporary root directory to install the package (usually always "" but for package makers)
--prefix DIR Subdirectory where to install binaries and libs (usually /usr or /usr/local)
--bindir DIR Install binaries into this directory
--libdir DIR Common directory for Ocsigen server's libraries
--sysconfdir DIR Create configuration files in this directory
--mandir DIR Install man pages in this directory
--docdir DIR Install documentation in this directory
--logdir DIR Use this directory for Ocsigen's logs
--datadir DIR The directory for data written by the server
--staticpagesdir DIR Install default static pages in this directory
--uploaddir DIR By default, files will be uploaded in this directory
--commandpipe FILE The name of the named pipe used to command the server
Defaults are:
_EOF_
print_options >&2
exit 1
}
check_eopt () {
for x in $eoptions; do
if [ "$x" = "$1" ]; then
return 0
fi
done
echo "Unknown option: $1" >&2
exit 1
}
check_wopt () {
for x in $woptions; do
if [ "$x" = "$1" ]; then
return 0
fi
done
echo "Unknown option: $1" >&2
exit 1
}
echo "\n\tWelcome to Ocsigen server, version $version.\n" >&2
while [ "$#" -gt 0 ]; do
case "$1" in
--enable-*)
opt=`echo "$1" | sed -e 's/--enable-//' -e 's/-/_/g'`
check_eopt "$opt"
eval "enable_$opt=2"
shift
;;
--disable-*)
opt=`echo "$1" | sed -e 's/--disable-//' -e 's/-/_/g'`
check_eopt "$opt"
eval "enable_$opt=-1"
shift
;;
--with-*)
opt=`echo "$1" | sed -e 's/--with-//' -e 's/-/_/g'`
check_wopt "$opt"
eval "with_$opt=2"
shift
;;
--without-*)
opt=`echo "$1" | sed -e 's/--without-//' -e 's/-/_/g'`
check_wopt "$opt"
eval "with_$opt=-1"
shift
;;
--root)
root="$2"
shift
shift
;;
--temproot)
temproot="$2"
shift
shift
;;
--prefix)
prefix="$2"
shift
shift
;;
--bindir)
bindir="$2"
shift
shift
;;
--logdir)
logdir="$2"
shift
shift
;;
--libdir)
libdir="$2"
libdir_set=1
shift
shift
;;
--mandir)
mandir="$2"
shift
shift
;;
--docdir)
docdir="$2"
shift
shift
;;
--staticpagesdir)
staticpagesdir="$2"
shift
shift
;;
--sysconfdir)
sysconfdir="$2"
shift
shift
;;
--uploaddir)
uploaddir="$2"
shift
shift
;;
--datadir)
datadir="$2"
shift
shift
;;
--name)
name="$2"
shift
shift
;;
--ocsigen-user)
ocsigen_user="$2"
shift
shift
;;
--ocsigen-group)
ocsigen_group="$2"
shift
shift
;;
--commandpipe)
commandpipe="$2"
shift
shift
;;
*)
echo "Unknown option: $1" >&2
usage
esac
done
case "$bindir" in
"") bindir="$prefix/bin";;
esac
case "$logdir" in
"") logdir="/var/log/ocsigenserver";;
esac
case "$libdir" in
"") libdir="\$(shell \${OCAMLFIND} printconf destdir)";;
*) libdir=$root$libdir
esac
case "$mandir" in
"") mandir="$prefix/share/man/man1";;
esac
case "$docdir" in
"") docdir="$prefix/share/doc/ocsigenserver";;
esac
case "$commandpipe" in
"") commandpipe="/var/run/ocsigenserver_command";;
esac
check_binary ocamlc "See: http://www.ocaml.org/"
check_ocamlversion () {
echo -n "Checking for OCaml version... "
version=`ocamlc -version`
echo $version
n1=`echo $version | sed 's/^\([0-9][0-9]*\)\..*$/\1/'`
n2=`echo $version | sed 's/^[0-9][0-9]*\.\([0-9][0-9]*\)\..*$/\1/'`
# n3=`echo $version | sed 's/^[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\)\..*$/\1/'`
if [ $n1 -eq 3 ] && [ $n2 -lt 12 ]; then
echo;
echo "OCaml >= 3.12 is required. Aborting.";
exit 1;
fi
}
check_ocamlversion
check_binary ocamlfind "See: http://projects.camlcity.org/projects/findlib.html"
check_library cohttp "See: https://github.com/mirage/ocaml-cohttp"
check_library cohttp-lwt-unix "Missing support for 'lwt' in cohttp."
check_library react "See: http://erratique.ch/software/react"
check_library ssl "See: http://sourceforge.net/projects/savonet/files/ocaml-ssl"
check_library http ""
check_library lwt "See: http://ocsigen.org/lwt"
check_library lwt.unix "Missing support for 'unix' in lwt."
check_library lwt_react "See: http://ocsigen.org/lwt"
check_library lwt_ssl "See: http://ocsigen.org/lwt"
check_library logs ""
check_library logs-syslog "Missing syslog support."
check_library re "See: https://github.com/ocaml/ocaml-re/"
check_library cryptokit "See: http://pauillac.inria.fr/~xleroy/software.html#cryptokit"
check_library xml-light "See: https://github.com/ncannasse/xml-light"
# Check PostgreSQL
case "$with_pgsql" in
1) if test_library pgocaml; then with_pgsql=1; else with_pgsql=0; fi;;
2) check_library pgocaml "https://github.com/darioteixeira/pgocaml";;
esac
# Check Sqlite3
case "$with_sqlite" in
1) if test_library sqlite3; then with_sqlite=1; else with_sqlite=0; fi;;
2) check_library sqlite3 "See: http://ocaml.info/home/ocaml_sources.html";;
esac
# Check dbm
if [ "$with_dbm" -gt 0 ]; then
if test_library dbm; then
echo -n
elif [ "$with_dbm" -gt 1 ]; then
fail_library dbm
else
with_dbm=0
fi
fi
# Check rlwrap or ledit
if test_binary rlwrap; then
rlwrap=rlwrap
elif test_binary ledit; then
rlwrap=ledit
else
rlwrap=
fi
######################################################################
# Summary
echo
echo "Effective options:"
print_options
echo
#Convert 0/1 values to YES/NO
if [ $with_dbm -gt 0 ] ; then
with_dbm="YES"
else
with_dbm="NO"
fi
if [ $with_sqlite -gt 0 ] ; then
with_sqlite="YES"
else
with_sqlite="NO"
fi
if [ $with_pgsql -gt 0 ] ; then
with_pgsql="YES"
else
with_pgsql="NO"
fi
ocamlinclude=`ocamlfind printconf stdlib`
######################################################################
# Write Makefile.conf
echo "Writing Makefile.config"
cat <<_EOF_ > $my_pwd/Makefile.config
#### External binaries ####
OCAMLFIND := ocamlfind
OCAMLLEX := ocamllex
OCAMLMKLIB:= ocamlmklib
CHOWN := chown
CHMOD := chmod
INSTALL := install
CC := gcc
# optional
RLWRAP := $rlwrap
### Paths ###
# Temporary root directory to install the package (usually always "" but for package makers)
TEMPROOT := $temproot
# The directory for ocsigen manpage:
MANDIR := $root$mandir
# ocsigen's logs:
LOGDIR := $root$logdir
# Config files:
CONFIGDIR := $root$sysconfdir
# Where to put static pages:
STATICPAGESDIR := $root$staticpagesdir
# Where to put dynamic data:
DATADIR := $root$datadir
# Default directory for file upload:
UPLOADDIR := $root$uploaddir
# Where to put Ocsigen documentation:
DOCDIR := $root$docdir
# The name of the named pipe used to command the server
COMMANDPIPE := $root$commandpipe
# The source directory
SRC := $full_pwd
include \$(SRC)/Makefile.options
_EOF_
echo "Writing config options"
cat <<_EOF_ > $my_pwd/src/files/ocsigenserver.conf/options.ml
let version = "$version"
let src = "$full_pwd"
let port = 80
let bindir = "$root$bindir"
let libdir = "$libdir"
let libdir_set = $libdir_set
let logdir = "$root$logdir"
let configdir = "$root$sysconfdir"
let staticpagesdir = "$root$staticpagesdir"
let datadir = "$root$datadir"
let uploaddir = "$root$uploaddir"
let commandpipe = "$root$commandpipe"
let mimefile = "$root$sysconfdir/mime.types"
_EOF_
######################################################################
# Finish
echo
echo
echo "Please check Makefile.config."
echo
echo "You can now compile Ocsigen Server by invoking:"
echo
echo " make"
echo " make doc"
echo
echo "You may test the server by invoking:"
echo
echo " make run.local"
echo " make run.opt.local"
echo
|