Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 342 lines (277 sloc) 7.67 KB
#! /bin/sh
# adapted from ocamlnet's configure
#######################################################################
# Helpers:
# Split $PATH into words:
oldifs="$IFS"
IFS=" :"
spacepath=`echo $PATH`
IFS="$oldifs"
in_path () {
# Does $1 exist in $PATH?
for d in $spacepath; do
if test -x "$d/$1"; then
return 0
fi
done
return 1
}
get_path () {
for d in $spacepath; do
if test -x "$d/$1"; then
echo "$d/$1"
return
fi
done
}
#######################################################################
# Defaults
#--- Options ---
# value 0: off
# value 1: on
# defaults:
set_defaults () {
bindir=`dirname $ocamlc`
libdir=`ocamlc -where`
}
ocamlc=`get_path ocamlc`
set_defaults
version="0.3"
exec_suffix=""
#######################################################################
# Option parsing
# Packages to include anyway:
requires="ulex"
check_library () {
# $1: the name of the library (findlib)
ocamlfind query "$1" >/dev/null 2>/dev/null
return
}
library_version () {
# $1: the name of the library (findlib)
ocamlfind query -format "%v" "$1" 2>/dev/null
return
}
absolute_dir () {
case $1 in
/*) echo $1 ;;
*) echo `pwd`/$1 ;;
esac
}
print_options () {
echo " -bindir $bindir"
echo " -libdir $libdir"
if [ "x$srcdir" != x ]; then echo " -srcdir $srcdir"; fi
if [ "x$srcdir_ounit" != x ]; then echo " -srcdir-ounit $srcdir_ounit"; fi
if [ "x$srcdir_lwt" != x ]; then echo " -srcdir-lwt $srcdir_lwt"; fi
}
usage () {
set_defaults
cat <<_EOF_ >&2
usage: ./configure [ options ]
_EOF_
cat <<_EOF_ >&2
-srcdir dir
OCaml source is in this directory (default ../ocaml-\$VERSION)
-srcdir-lwt dir
Lwt source is in this directory (default ../lwt-\$VERSION)
-srcdir-ounit dir
OUnit source is in this directory (default ../ounit-\$VERSION)
-bindir dir
Install binaries into this directory (default same as ocamlc)
-libdir dir
Install libraries into this directory (default same as ocamlc -where)
Defaults are:
_EOF_
print_options >&2
exit 1
}
echo "Welcome to ocamljs version $version" >&2
while [ "$#" -gt 0 ]; do
case "$1" in
-bindir)
bindir="$2"
shift
shift
;;
-libdir)
libdir="$2"
shift
shift
;;
-srcdir)
srcdir="$2"
shift
shift
;;
-srcdir-ounit)
srcdir_ounit="$2"
shift
shift
;;
-srcdir-lwt)
srcdir_lwt="$2"
shift
shift
;;
-version)
echo "$version"
exit 0
;;
*)
usage
esac
done
# Sanity checks
case "$bindir" in
/*) ;;
"") ;;
*) echo "The -bindir directory must be absolute." 1>&2; exit 2;;
esac
case "$libdir" in
/*) ;;
"") ;;
*) echo "The -libdir directory must be absolute." 1>&2; exit 2;;
esac
######################################################################
# Check OCaml version and source
printf "%s" "Checking OCaml version... "
ocamlc_version=`ocamlc -version`
case $ocamlc_version in
3.11.0 | 3.11.1 | 3.11.2 | 3.12.0)
echo "ok, $ocamlc_version";;
*)
echo "unsupported version $ocamlc_version"
echo "Sorry, ocamljs needs OCaml version 3.11.x or 3.12.0."
echo "Download OCaml from http://caml.inria.fr/download.en.html"
exit 1;;
esac
printf "%s" "Checking for OCaml source... "
x=${srcdir:=`absolute_dir "../ocaml-$ocamlc_version"`}
if [ -f $srcdir/VERSION ]; then
src_version=`head -1 $srcdir/VERSION`
if [ "$src_version" != "$ocamlc_version" ]; then
echo "source version $src_version != $ocamlc_version"
echo "You need to set -srcdir to a version $ocamlc_version OCaml source tree."
echo "Download OCaml from http://caml.inria.fr/download.en.html"
exit 1
else
echo "found"
fi
else
echo "not found"
echo "You need to set -srcdir to a version $ocamlc_version OCaml source tree."
echo "Download OCaml from http://caml.inria.fr/download.en.html"
exit 1
fi
######################################################################
# Check ocamlfind
printf "%s" "Checking for findlib... "
if check_library stdlib; then
echo "found"
else
echo "not found"
echo "Download findlib from http://projects.camlcity.org/projects/findlib.html"
exit 1
fi
######################################################################
# Check ulex
printf "%s" "Checking for ulex... "
if check_library ulex; then
echo "found"
else
echo "not found"
echo "Download ulex from http://www.cduce.org/download.html#side"
exit 1
fi
######################################################################
# Check Ounit
printf "%s" "Checking for Ounit... "
has_ounit=0
if check_library oUnit; then
ounit_version=`library_version oUnit`
printf "%s" "checking for source... "
x=${srcdir_ounit:=`absolute_dir "../ounit-$ounit_version"`}
if [ -d $srcdir_ounit ]; then
# XXX check version
has_ounit=1
echo "found"
else
srcdir_ounit=""
echo "$srcdir_ounit not found, continuing"
echo "Download ounit from http://www.xs4all.nl/~mmzeeman/ocaml/"
fi
else
echo "not found, continuing"
echo "Download ounit from http://www.xs4all.nl/~mmzeeman/ocaml/"
fi
######################################################################
# Check Lwt
printf "%s" "Checking for Lwt... "
has_lwt=0
if check_library lwt; then
lwt_version=`library_version lwt`
printf "%s" "checking for source... "
x=${srcdir_lwt:=`absolute_dir "../lwt-$lwt_version"`}
if [ -d $srcdir_lwt ]; then
# XXX check version
has_lwt=1
echo "found"
else
srcdir_lwt=""
echo "not found, continuing"
echo "Download lwt from http://ocsigen.org/lwt/install"
fi
else
echo "not found, continuing"
echo "Download lwt from http://ocsigen.org/lwt/install"
fi
######################################################################
# Summary
echo
echo "Effective options:"
print_options
echo
pkglist="jslib jscomp ocamljs stdlib javascript mozilla dom gmaps jquery"
if [ $has_ounit -gt 0 ]; then
pkglist="$pkglist ounit"
fi
if [ $has_lwt -gt 0 ]; then
pkglist="$pkglist lwt lwt-dom"
fi
######################################################################
# Configure OCaml
printf "%s" "Configuring OCaml... "
rm -f ocaml; ln -s $srcdir ocaml
(cd ocaml; make clean; ./configure -bindir $bindir -libdir $libdir) >/dev/null 2>&1
echo "done"
######################################################################
# Write Makefile.conf
echo "Writing Makefile.conf"
cat <<_EOF_ >Makefile.conf
# Makefile.conf written by configure
# The ocamljs version
VERSION = $version
# The packages to build in the right order:
PKGLIST = $pkglist
# Required packages (findlib):
REQUIRES = $requires
# Where binaries are installed:
BINDIR = $bindir
# Where libraries are installed:
LIBDIR = $libdir
OCAML_VERSION = $ocamlc_version
SRCDIR_OUNIT = $srcdir_ounit
SRCDIR_LWT = $srcdir_lwt
VERSIONS=3.11.0 3.11.1 3.11.2 3.12.0
_EOF_
######################################################################
# Finish
echo
echo "Please check Makefile.conf."
echo
echo "You can now compile ocamljs by invoking"
echo " make all"
echo "Finally, a"
echo " make install"
echo "will install the package(s)."