#! /bin/sh
# $Id: configure,v 3.18 2005/10/31 13:28:55 stolpmann Exp $
#--- Options ---
# value -1: off by command line ("forced")
# value 0: off by default
# value 1: on by default
# value 2: on by command line ("forced")
# defaults:
set_defaults () {
enable_findlib=1
with_wdialog_p4=1
with_wdialog_perlguts=0
# with_wd_debugger=1
with_wd_xmlcompiler=1
with_perl=0
with_wd_session_daemon=1
with_wd_inmemory_session=1
}
set_defaults
version="2.1.2"
exec_suffix=""
ehelp_findlib="Enable/disable installation as findlib package"
whelp_wd_session_daemon="Include/omit the session state daemon"
whelp_wd_inmemory_session="Include/omit support for in-memory sessions"
whelp_wdialog_p4="Include/omit wdialog syntax extensions (camlp4)"
whelp_wdialog_perlguts="Include/omit library for interfacing Perl"
#whelp_wd_debugger="Inlude/omit wdialog debugger"
whelp_wd_xmlcompiler="Include/omit wdialog XML tree compiler"
whelp_perl="Include/omit Perl bindings"
# Which options exist? eoptions for enable/disable, woptions for with/without:
eoptions="findlib"
woptions="wdialog_p4 wdialog_perlguts wd_xmlcompiler perl \
wd_session_daemon wd_inmemory_session"
# NOT YET: wd_debugger
# Directories to include. The notation +package is allowed.
incdirs=""
# Directory where to install the library:
libdir=`ocamlc -where`/wdialog
# Directory for libraries needed for Perl bindings:
perl_libdir=/usr/local/libexec/wdialog
# Packages to include anyway: (extended later)
requires="pxp-engine netstring unix pcre cgi"
libs_cma="unix.cma pcre.cma netstring.cma netcgi.cma pxp_engine.cma"
# For the META file of wdialog only:
requires_wdialog="$requires"
check_library () {
# $1: the name of the library (findlib)
# $2: a typical file in $incdirs
if [ "$enable_findlib" -gt 0 ]; then
ocamlfind query "$1" >/dev/null 2>/dev/null
return
else
stdlib=`ocamlc -where`
for dir in $incdirs; do
case "$dir" in
+*)
dir=`echo "$dir" | sed -e "s|^\+|$stdlib/|"` ;;
esac
if [ -f "$dir/$2" ]; then
return 0
fi
done
return 1 # not found
fi
}
check_library_version () {
# $1: the name of the library (findlib)
# $2: A regexp (egrep) for the version string
# $3: a typical file in $incdirs
if [ "$enable_findlib" -gt 0 ]; then
v=`ocamlfind query -format '%v' "$1"`
echo "$v" | egrep -e "$2" >/dev/null
# return exit code of grep
return
else
stdlib=`ocamlc -where`
for dir in $incdirs; do
case "$dir" in
+*)
dir=`echo "$dir" | sed -e "s|^\+|$stdlib/|"` ;;
esac
if [ -f "$dir/$3" ]; then
return 0
fi
done
return 1 # not found
fi
}
# Split $PATH into words:
oldifs="$IFS"
IFS=" :"
spacepath=`echo $PATH`
IFS="$oldifs"
get_path () {
for d in $spacepath; do
if test -x "$d/$1"; then
echo "$d/$1"
return
fi
done
}
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
if [ "$enable_findlib" -le 0 ]; then
if [ -n "$incdirs" ]; then
echo " -I $incdirs"
fi
if [ -n "$libdir" ]; then
echo " -libdir $libdir"
fi
fi
if [ "$with_perl" -gt 0 -o "$with_wdialog_perlguts" -gt 0 ]; then
echo " -perl-libdir $perl_libdir"
fi
}
usage () {
set_defaults
cat <<_EOF_ >&2
usage: ./configure [ options ]
_EOF_
for opt in $eoptions; do
e="help=\$ehelp_$opt"
eval "$e"
uopt=`echo $opt | sed -e 's/_/-/g'`
echo "-enable-$uopt:" >&2
echo "-disable-$uopt:" >&2
echo " $help" >&2
done
for opt in $woptions; do
e="help=\$whelp_$opt"
eval "$e"
uopt=`echo $opt | sed -e 's/_/-/g'`
echo "-with-$uopt:" >&2
echo "-without-$uopt:" >&2
echo " $help" >&2
done
cat <<_EOF_ >&2
-I dir
Add directory to include path (only if -disable-findlib)
-libdir dir
Install the library into this directory (only if -disable-findlib)
-ocamltree dir
The (already configured) OCaml source tree can be found here (for -with-perl)
-perl-libdir dir
Install libs for the Perl bindings here (for -with-perl & -with-wdialog-perlguts)
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 "Welcome to WDialog version $version" >&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
;;
-I|-include|-incdir)
incdirs="$incdirs $2"
shift; shift
;;
-ocamltree)
ocamltree="$2"
shift; shift
;;
-perl-libdir)
perl_libdir="$2"
shift; shift
;;
-version)
echo "$version"
exit 0
;;
*)
usage
esac
done
######################################################################
# Check ocaml
printf "%s" "Checking for ocaml... "
if ocamlc; then
echo "found"
else
echo "not found"
echo "Sorry, it is not possible to build WDialog without the Objective Caml compiler"
echo "Get it from: http://caml.inria.fr"
exit 1
fi
printf "%s" "Checking the version of ocaml... "
ov=`ocamlc -v | head -n 1`
case "$ov" in
*\ version\ 1*|*\ version\ 2*|*\ version\ 3\.0[0-3]*)
echo "too old"
exit 1
;;
*\ version\ 3\.0[46789]*)
echo "good"
;;
*)
echo "not recognized (newer than 3.09?) - trying to continue"
;;
esac
######################################################################
# Check ocamlfind
if [ "$enable_findlib" -gt 0 ]; then
printf "%s" "Checking for findlib... "
if ocamlfind query stdlib >/dev/null 2>/dev/null; then
echo "found"
else
echo "not found"
enable_findlib=0
if [ "$enable_findlib" -eq 2 ]; then
echo "Sorry, findlib cannot be found."
echo "Make sure that ocamlfind is in your PATH, or download findlib"
echo "from www.ocaml-programming.de"
exit 1
fi
fi
fi
######################################################################
# Check that options are sane
# -with-perl implies -with-wdialog-perlguts:
if [ "$with_perl" -gt 0 ]; then
if [ "$with_wdialog_perlguts" -le 0 ]; then
# Not possible. Try to correct.
# Try to set netstring to 1:
if [ "$with_wdialog_perlguts" -eq 0 ]; then
with_wdialog_perlguts=1
elif [ "$with_perl" -eq 1 ]; then
with_perl=0
else
echo "Sorry, it is not possible to build Perl bindings but omit perlguts support."
exit 1
fi
fi
fi
######################################################################
# Check that pcre is available:
if true; then
printf "%s" "Checking for PCRE... "
if check_library pcre pcre.cmi; then
echo "found"
else
echo "not found"
echo "Sorry, installation is not possible without PCRE."
echo "Get the PCRE library from:"
echo "http://miss.wu-wien.ac.at/~mottl/ocaml_sources/"
exit 1
fi
fi
######################################################################
# Check that netstring is available (and the right version):
if true; then
printf "%s" "Checking for netstring... "
if check_library netstring netstring.cma; then
echo "found"
printf "%s" "Checking whether netstring version >= 0.92... "
if check_library_version netstring '(0\.9[2-9]+)|([1-9].+)' netmime.mli; then
echo "good"
else
echo "Your netstring version seems to be too old."
echo "You need at least netstring 0.92 (contained in ocamlnet-0.92), available from"
echo "http://sourceforge.net/projects/ocamlnet"
exit 1
fi
else
echo "not found"
echo "Sorry, installation is not possible without netstring."
echo "Get the ocamlnet library (containing netstring) from:"
echo "http://sourceforge.net/projects/ocamlnet"
exit 1
fi
fi
######################################################################
# Check that cgi is available (and the right version):
if true; then
printf "%s" "Checking for cgi... "
if check_library cgi netcgi_types.mli; then
echo "found"
printf "%s" "Checking whether cgi version >= 0.92... "
if check_library_version cgi '(0\.9[2-9]+)|([1-9].+)' netcgi_jserv_app.mli; then
echo "good"
else
echo "Your cgi version seems to be too old."
echo "You need at least cgi 0.92 (contained in ocamlnet-0.92), available from"
echo "http://sourceforge.net/projects/ocamlnet"
exit 1
fi
else
echo "not found"
echo "Sorry, installation is not possible without cgi."
echo "Get the ocamlnet library (containing cgi) from:"
echo "http://sourceforge.net/projects/ocamlnet"
exit 1
fi
fi
######################################################################
# Check that pxp is available (and the right version):
if true; then
printf "%s" "Checking for PXP... "
if check_library pxp-engine pxp_types.mli; then
echo "found"
printf "%s" "Checking whether PXP version >= 1.1.3... "
if check_library_version pxp-engine '(1\.1\.[3-9].*)|(1\.2.*)|([2-9].*)' pxp_types.mli; then
echo "good"
else
echo "Your PXP version seems to be too old."
echo "You need at least PXP 1.1.3, available from"
echo "http://www.ocaml-programming.de"
exit 1
fi
else
echo "not found"
echo "Sorry, installation is not possible without PXP."
echo "Get the PXP parser from:"
echo "http://www.ocaml-programming.de"
exit 1
fi
fi
if true; then
printf "%s" "Checking for PXP lexer (wlex)... "
if check_library pxp-wlex pxp_wlex_link.cmi; then
requires="$requires pxp-wlex"
requires_wdialog="$requires_wdialog pxp-wlex"
libs_cma="$libs_cma pxp_wlex.cma"
echo "found"
else
echo "not found"
printf "%s" "Checking for PXP lexer (ISO-8859-1)... "
if check_library pxp-lex-iso88591 pxp_lex_link_iso88591.cmi; then
echo "found"
requires="$requires pxp-lex-iso88591"
requires_wdialog="$requires_wdialog pxp-lex-iso88591"
libs_cma="$libs_cma pxp_lex_iso88591.cma"
else
echo "not found"
echo "Sorry, the lexer for ISO-8859-1 is missing"
exit 1
fi
printf "%s" "Checking for PXP lexer (ulex)... "
if check_library pxp-ulex-utf8 pxp_ulex_link_utf8.cmi; then
requires="$requires pxp-ulex-utf8"
requires_wdialog="$requires_wdialog pxp-ulex-utf8"
libs_cma="$libs_cma pxp_ulex_utf8.cma"
echo "found"
else
echo "not found"
printf "%s" "Checking for PXP lexer (lex UTF-8)... "
if check_library pxp-lex-utf8 pxp_lex_link_utf8.cmi; then
echo "found"
requires="$requires pxp-lex-utf8"
requires_wdialog="$requires_wdialog pxp-lex-utf8"
libs_cma="$libs_cma pxp_lex_utf8.cma"
else
echo "not found"
echo "Sorry, the lexer for UTF-8 is missing"
exit 1
fi
fi
fi
fi
######################################################################
# Check for ulex (now needed for core Wdialog!)
printf "%s" "Checking for ulex... "
if check_library ulex ulexing.cmi; then
echo "found"
else
echo "not found"
echo "Sorry, you need ulex to build wdialog!"
exit 1
fi
######################################################################
# Check for wd-session-daemon and rpc, inifiles
if [ $with_wd_session_daemon -gt 0 ]; then
printf "%s" "Checking for RPC... "
if check_library rpc rpc.cmi; then
echo "found"
requires="$requires rpc"
libs_cma="$libs_cma rpc.cma"
# but requires_wdialog is not extended
else
echo "not found"
echo "Sorry, you need RPC for the wd-session-daemon"
exit 1
fi
printf "%s" "Checking for Inifiles... "
if check_library inifiles inifiles.cmi; then
echo "found"
requires="$requires inifiles"
libs_cma="$libs_cma inifiles.cma"
# but requires_wdialog is not extended
else
echo "not found"
echo "Sorry, you need Inifiles for the wd-session-daemon"
exit 1
fi
fi
######################################################################
# Check the name of the findlib loader for scripts
printf "%s" "Checking the name of the findlib loader... "
rm -rf ocaml-findlib
stdlib=`ocamlc -where`
if [ -f "$stdlib/topfind" ]; then
echo "<stdlib>/topfind"
ln -s "$stdlib/topfind" ocaml-findlib
else
if [ -f "$stdlib/findlib" ]; then
echo "<stdlib>/findlib"
ln -s "$stdlib/findlib" ocaml-findlib
else
if [ -f "$stdlib/ocamlfind" ]; then # debian
echo "<stdlib>/ocamlfind"
ln -s "$stdlib/ocamlfind" ocaml-findlib
else
echo "not found"
echo "Sorry, cannot find the findlib loader. Something is wrong"
echo "with your installation."
exit 1
fi
fi
fi
printf "%s" "Checking whether the findlib loader works... "
cat <<'EOF' >.testscript
#use "./ocaml-findlib";;
EOF
ocaml .testscript >.testout 2>&1
if [ -s .testout ]; then
echo "no"
echo "Sorry, something is wrong with your installation."
exit 1
else
echo "yes"
fi
######################################################################
# Check whether we need a toploop, and create it if so
printf "%s" "Checking whether we need a custom toploop for scripts... "
cat <<'EOF' >.testscript
#use "topfind";;
#require "pxp";;
EOF
ocaml .testscript >.testout 2>&1
if [ -s .testout ]; then
printf "%s" "yes, creating it... "
rm -f ocaml-toploop
ocamlfind ocamlmktop -o ocaml-toploop -custom -package pxp,findlib -linkpkg ||
exit
echo "done"
else
echo "no, not necessary"
rm -f ocaml-toploop
ln -s `get_path ocaml` ocaml-toploop
fi
######################################################################
# Check perl
if [ $with_perl -gt 0 ]; then
printf "%s" "Checking for perl... "
if [ "$enable_findlib" -le 0 ]; then
echo "error"
echo "Sorry, you need findlib to build the Perl bindings"
exit 1
fi
if perl -v >/dev/null 2>/dev/null; then
echo "found"
else
echo "not found"
echo "Sorry, cannot build Perl bindings without a Perl installation"
exit 1
fi
# Do we have camlidl?
printf "%s" "Checking for camlidl... "
f=0
if camlidl; then
if check_library camlidl com.cmi; then
f=1
fi
fi
if [ $f -gt 0 ]; then
echo "found"
else
echo "not found"
echo "Sorry, cannot build Perl bindings without camlidl"
echo "Get it from http://caml.inria.fr"
exit 1
fi
# Check whether the necessary libraries can be dynamically loaded:
printf "%s" "Checking whether libraries can be loaded... "
cat <<'EOF' >.testscript
#use "topfind";;
#require "unix";;
#require "pcre";;
#require "camlidl";;
EOF
ocaml .testscript >.testout 2>&1
if [ -s .testout ]; then
echo "no"
echo "Error: Cannot load some critical libraries dynamically"
echo "Look at .testscript and .testout for debugging"
exit 1
else
echo "passes"
fi
# Check OS
printf "%s" "Checking whether operating system is supported... "
case `uname` in
Linux)
echo "yes"
;;
*)
echo "unknown"
echo "WARNING! Building the Perl bindings has not been tested for your"
echo "operating system. It might work nevertheless, so I am trying..."
;;
esac
# Is -ocamltree set?
printf "%s" "Checking whether O'Caml source tree is available... "
if [ -z "$ocamltree" ]; then
echo "no"
echo "You must set the option -ocamltree to build the Perl bindings"
exit 1
fi
if [ ! -d "$ocamltree" ]; then
echo "no"
echo "Not found, or not a directory: $ocamltree"
exit 1
fi
if [ ! -f "$ocamltree/byterun/interp.c" ]; then
echo "no"
echo "The directory $ocamltree seems not to be the source ocaml tree"
exit 1
fi
if [ ! -f "$ocamltree/config/Makefile" -o \
! -f "$ocamltree/config/s.h" -o \
! -f "$ocamltree/config/m.h" ]; then
echo "unconfigured"
echo "The ocaml source tree is not configured. Go to $ocamltree"
echo "and configure it"
exit 1
fi
echo "passes"
fi
######################################################################
# Check cygwin
printf "%s" "Checking for cygwin... "
u=`uname`
case "$u" in
CYGWIN*)
echo "found"
exec_suffix=".exe"
;;
*)
echo "not found"
;;
esac
######################################################################
# Summary
echo
echo "Effective options:"
print_options
echo
pkglist="wdialog"
for opt in $woptions; do
e="o=\$with_$opt"
eval "$e"
if [ $o -gt 0 ]; then
uopt=`echo "$opt" | sed -e 's/_/-/g'`
case "$uopt" in
perl) uopt="ocamlrun-dso UI";;
esac
pkglist="$pkglist $uopt"
fi
done
#if [ -z "$pkglist" ]; then
# echo "Sorry, it is necessary that you want at least one package to be"
# echo "built."
# exit 1
#fi
#echo "Packages: $pkglist"
######################################################################
# Write META
for pkg in $pkglist; do
echo "Writing src/$pkg/META"
sed -e "s/@VERSION@/$version/g" \
-e "s/@REQUIRES@/$requires_wdialog/g" \
src/$pkg/META.in >src/$pkg/META
done
######################################################################
# Write Makefile.conf
includes=""
if [ -n "$incdirs" ]; then
for d in $incdirs; do
includes="$includes -I $d"
done
fi
instmethod="conventional"
useocamlfind=""
if [ "$enable_findlib" -gt 0 ]; then
instmethod="findlib"
useocamlfind='$(OCAMLFIND)'
includes="$includes -package \"\$(REQUIRES)\""
fi
echo "Writing Makefile.conf"
cat <<_EOF_ >Makefile.conf
# The version
VERSION = $version
# The packages to build in the right order:
PKGLIST = $pkglist
# Whether the OS needs an .exe suffix for executables:
EXEC_SUFFIX = $exec_suffix
# Required packages (findlib):
REQUIRES = $requires
# Included directories (-I dir, or -I +pkg, or -package pkg):
INCLUDES = $includes
# Archives to link into executables (non-findlib):
LIBS_CMA = $libs_cma
# Additional options only for ocamlc:
OCAMLC_OPTIONS =
# Additional options only for ocamlopt:
OCAMLOPT_OPTIONS =
# Where wdialog is to be installed (non-findlib):
LIBDIR = $libdir
# Method of installation:
INSTMETHOD = $instmethod
# Method of compilation:
# Either "" (non-findlib), or "\$(OCAMLFIND)"
USE_OCAMLFIND = $useocamlfind
# Where to find the ocaml sources: (only -with-perl)
OCAMLTREE = $ocamltree
# Where to install libs only used for the Perl bindings:
PERL_LIBDIR = $perl_libdir
_EOF_
######################################################################
# Finish
echo
echo "Please check Makefile.conf."
echo
echo "You can now compile WDialog by invoking"
echo " make all"
echo "for the bytecode compiler, and optionally by invoking"
echo " make opt"
echo "for the native-code compiler (if supported on your architecture)."
echo "Finally, a"
echo " make install"
echo "will install the package(s)."
if [ $with_perl -gt 0 ]; then
echo
echo 'Important note regarding the Perl bindings:'
echo 'These must be compiled and installed in a second step.'
echo 'So first do "make all; make opt; make install" to'
echo 'build the base system, then continue with the Perl'
echo 'bindings by running "make perlapi; make install-perlapi".'
fi