Plasma GitLab Archive
Projects Blog Knowledge

#! /bin/sh
# $Id: configure 122 2007-11-13 13:31:39Z gerd $
# ----------------------------------------------------------------------
#

# Some functions

#set -x

version="1.2.1"

# Remember the old IFS value:
oldifs="$IFS"


in_path () {
    # Does $1 exist in $PATH?
    IFS=":"
    for d in $PATH; do
	if test -x "$d/$1"; then
	    IFS="$oldifs"
	    return 0
	fi
    done
    IFS="$oldifs"
    return 1
#--- The following is not portable enough:
#    if test -x `type -p ls`; then
#	# type -p works!
#        type -p $1 >/dev/null
#    else
#        # use 'which' instead
#        p=`which $1`
#	test -x "$p"
#    fi
}


get_path () {
    IFS=":"
    for d in $PATH; do
	if test -x "$d/$1"; then
	    IFS="$oldifs"
	    echo "$d/$1"
	    return
	fi
    done
    IFS="$oldifs"
#--- The following is not portable enough:
#    if test -x `type -p ls`; then
#	# type -p works!
#        type -p $1
#    else
#        # use 'which' instead
#        p=`which $1`
#	test -x "$p" && echo $p
#    fi
}


get_stdlib () {
    # Older versions of ocamlc do not accept -where, so there is a fallback
    # method:
    ocamlc -where 2>/dev/null || {
	ocamlc -v | sed -n -e "/Standard library directory/s/.*: \(.*\)/\1/p"; }
}


get_lib () {
    # $1: name of a library to search for
    # $2...: places to test
    libname="$1"
    while [ "$#" != "0" ]; do
	if [ -f "$1/lib${libname}.so" -o -f "$1/lib${libname}.a" ]; then
	    echo "$1"
	    return 0
	fi
	shift
    done
    return 1
}


get_lib_file () {
    # $1: name of library without "lib" and suffix
    # $2: directory
    # returns full path of library
    if [ -f "$2/lib$1.so" ]; then
	echo "$2/lib$1.so"
    elif [ -f "$2/lib$1.a" ]; then
	echo "$2/lib$1.a"
    else
	echo ""
    fi
}


cygpath_to_unix () {
    v=$1
    eval "p=\"\$$v\""
    p="`cygpath -w -s \"$p\"`"
    p="`cygpath -u \"$p\"`"
    eval "$v=\"$p\""
}


######################################################################
# Here the main program begins:

######################################################################
# Interpret the command line

ocamlfind_bin=""
ocamlfind_man=""
ocaml_sitelib=""
ocamlfind_config=""
with_toolbox=0
with_topfind=1
system=""

while [ "$#" != "0" ]; do
    case "$1" in
        -bindir) ocamlfind_bin=$2
	         shift 2
		 ;;
        -mandir) ocamlfind_man=$2
	         shift 2
		 ;;
        -sitelib) ocaml_sitelib=$2
	          shift 2
		  ;;
        -config) ocamlfind_config=$2
	         shift 2
		 ;;
	-cygpath) system=mingw
	         shift
		 ;;
	-system) system=$2
	         shift 2
		 ;;
	-with-toolbox) with_toolbox=1
	         shift
		 ;;
	-no-topfind) with_topfind=0
	         shift
		 ;;
	-version)
	         echo "$version"
		 exit 0
		 ;;
        -h|-help|--help) echo "usage: configure [options]" 1>&2
		  echo "  -bindir path         where binaries are installed" 1>&2
		  echo "  -mandir path         where manual pages are installed" 1>&2
		  echo "  -sitelib path        set the location of the site-specific packages" 1>&2
                  echo "  -config path         set the location of the configuration file" 1>&2
		  echo "  -system <systype>    override system type (esp. mingw and win32)" 1>&2
		  echo "  -with-toolbox        also build the toolbox" 1>&2
		  echo "  -no-topfind          don't install topfind script into stdlib directory" 1>&2
		  exit
		  ;;
         *)       echo "configure: run 'configure -h' to get help" 1>&2
		  exit 1
		  ;;
    esac
done

echo "Welcome to findlib version $version"
echo "Configuring core..."


#######################################################################
# inspect the system

# Some standard Unix tools must be available:

for tool in sed awk ocaml ocamlc uname rm make cat m4 dirname basename; do
    if in_path $tool; then true; else
	echo "configure: $tool not in PATH; this is required" 1>&2
	exit 1
    fi
done

# Check for Cygwin:

exec_suffix=
case `uname` in
  CYGWIN*)
    exec_suffix=.exe
    echo "Cygwin build environment found; using .exe as suffix for binaries"
    ;;
  *)
    true ;;
esac

######################################################################
# Is the target Win32?

use_cygpath=0
# Whether we have to translate Unix paths to/from Windows paths.

if [ -z "$system" ]; then
    system=`ocamlc -config 2>/dev/null|grep system|sed 's/system: //'`
    # This may be
    # - mingw
    # - win32
    # - cygwin
    # - some other string means Unix
    # - empty means ocamlc does not support -config
fi

case "$system" in
    mingw) use_cygpath=1;;
    win32) use_cygpath=1;;
esac

######################################################################
# Find out standard library location

ocaml_core_stdlib=`get_stdlib`
if [ ! -d "$ocaml_core_stdlib" ]; then
   echo "configure: cannot determine ocaml's standard library directory" 1>&2
    exit 1
fi

if [ ${use_cygpath} -gt 0 ]; then
    cygpath_to_unix ocaml_core_stdlib
    # This makes ocaml_core_stdlib a Unix-type path
fi

# Set site-lib directory:

if [ -z "$ocaml_sitelib" ]; then
    case "$ocaml_core_stdlib" in
	/opt/*)		ocaml_sitelib=`dirname ${ocaml_core_stdlib}`/site-lib
			;;
	*)		ocaml_sitelib="${ocaml_core_stdlib}/site-lib"
			;;
    esac
fi

# Find out the directory where ocamlc is:

ocamlc=`get_path ocamlc`
ocaml_core_bin=`dirname ${ocamlc}`

# Set the directory of ocamlfind:

test -n "$ocamlfind_bin" || ocamlfind_bin="$ocaml_core_bin"

# Find the directory for the manual:

# Fallback:
ocaml_core_man=/usr/local/man

d="$ocaml_core_bin"
while [ "$d" != '/' ]; do
    f=0
    if [ -d "$d/man/man1" ]; then
	if [ -f "$d/man/man1/ocamlc.1" -o \
	     -f "$d/man/man1/ocamlc.1.gz" -o \
	     -f "$d/man/man1/ocamlc.1.Z" ]; then
	     f=1
	fi
    else
	if [ -d "$d/man/mann" ]; then
	    if [ -f "$d/man/mann/ocamlc.n" -o \
		 -f "$d/man/mann/ocamlc.n.gz" -o \
		 -f "$d/man/mann/ocamlc.n.Z" ]; then
		f=1
	    fi
	fi
    fi
    if [ "$f" = "1" ]; then
	ocaml_core_man="$d/man"
	d="/"
    else
	d=`dirname $d`
    fi
done

# Set the directory for ocamlfind's manuals:

test -n "$ocamlfind_man" || ocamlfind_man="$ocaml_core_man"

# Guess the right directory for the configuration file:

if [ -z "${ocamlfind_config}" ]; then
    d="$ocaml_core_bin"
    case "$d" in
        */bin)
	    ocamlfind_config=`dirname $d`/etc/findlib.conf
	    ;;
	*)
	    ocamlfind_config=/usr/local/etc/findlib.conf
	    # Fallback value
	    ;;
    esac
fi

######################################################################
# Test the threading model

echo "Testing threading model..."

if ocamlc -vmthread >/dev/null 2>/dev/null; then
    :
else
    echo "The -vmthread switch is not supported: Your ocaml version is too old!"
    exit 1
fi

if ocamlc -config >/dev/null 2>/dev/null; then
    # Good. ocamlc tells us the threading model.
    if ocamlc -config | grep 'systhread_supported: true'; then
	ocaml_threads="posix"
    else
	ocaml_threads="vm"
    fi
else
    # Old ocamlc do not have -config. 
    rm -f itest-aux/simple
    ocamlc -w a -custom -thread -o itest-aux/simple unix.cma threads.cma itest-aux/simple_threads.ml \
	>itest-aux/err.out 2>&1
    output=`cat itest-aux/err.out`

    if [ -z "$output" ]; then
	ocaml_threads="posix"
    else
	ocaml_threads="vm"
    fi
fi

######################################################################
# Does this version of OCaml support autolinking?

# Works for O'Caml >= 3.00 on. Because findlib can only be compiled
# with these O'Caml versions, we can safely assume that autolinking
# is enabled.

ocaml_autolink="true"

######################################################################
# Does this version of OCaml support DLLs?

echo "Testing DLLs..."

have_dlls="yes"

ocaml unix.cma itest-aux/simple.ml >/dev/null || have_dlls="no"

######################################################################
# Configure libraries

echo "Configuring libraries..."

# Check whether Bigarray is present.

lbigarray=bigarray
# always

# Check whether labltk is present.

if [ -f "${ocaml_core_stdlib}/labltk/labltk.cma" ]; then
    llabltk=labltk
    echo "labltk: found"
else
    llabltk=''
    echo "labltk: not present"
    if [ $with_toolbox -gt 0 ]; then
	echo "Sorry, toolbox requires labltk - omitting toolbox."
    fi
    with_toolbox=0
fi

# Check on camlp4:

if in_path camlp4; then
    camlp4_dir=`camlp4 -where`
    if [ ${use_cygpath} -gt 0 ]; then
	camlp4_dir=`echo x | env USE_CYGPATH=1 tools/patch x "$camlp4_dir"`
        # This makes camlp4_dir a windows path
    fi
    camlp4_version=`camlp4 -v 2>&1`
    if [ "$have_dlls" = "yes" ]; then
	camlp4_cmd="camlp4"
    else
	camlp4_cmd="safe_camlp4"
    fi
    # Check whether 3.09 or 3.10 style:
    if camlp4 -loaded-modules >/dev/null 2>/dev/null; then
	camlp4style=310
    else
	camlp4style=309
    fi
    lcamlp4="camlp4"
    rm -rf "site-lib-src/camlp4"
    mkdir "site-lib-src/camlp4"
    cp "site-lib-src/camlp4.$camlp4style/META.in" "site-lib-src/camlp4/"
    echo "camlp4: using $camlp4_cmd, style $camlp4style"
else
    lcamlp4=''
    echo "camlp4: not present"
fi

# Generate the META files now.

l="dbm dynlink graphics num num-top str threads unix stdlib bigarray $llabltk $lcamlp4"

for dir in site-lib-src/*; do
    # We do not really know if $dir is a directory.
    rm -f $dir/META
done

for lib in $l; do
    if=""
    if [ -f site-lib-src/$lib/interfaces.out ]; then
	if=`cat site-lib-src/$lib/interfaces.out`
    fi
    m4 -Dos=$os \
	"-Dtype_of_threads=${ocaml_threads}" \
	"-Dcamlp4_dir=${camlp4_dir}" \
	"-Dcamlp4_version=${camlp4_version}" \
	"-Dcamlp4_cmd=${camlp4_cmd}" \
	"-Dinterfaces=${if}" \
	"-Dfindlib_version=${version}" \
	site-lib-src/$lib/META.in >site-lib-src/$lib/META
    echo "Configuration for $lib written to site-lib-src/$lib/META"
done

for part in `cd src; echo *`; do
    if [ -f "src/$part/META.in" ]; then
	sed -e "s/@VERSION@/$version/g" src/$part/META.in >src/$part/META
    fi
done

######################################################################

printf "Detecting compiler arguments: "

( cd tools/extract_args && make ) >ocargs.log 2>&1
if [ "$?" -eq 0 ]; then
    printf "(extractor built) "
    tools/extract_args/extract_args -o src/findlib/ocaml_args.ml ocamlc ocamlcp ocamlmktop ocamlopt ocamldep ocamldoc >>ocargs.log 2>&1
    # ocamlbrowser does not work!
    if [ $? -eq 0 ]; then
	echo "ok"
    else
	echo "FAILED"
	exit 1
    fi
else
    echo "FAILED"
    exit 1
fi

######################################################################
# Write Makefile.config

parts="findlib"
if [ $with_toolbox -gt 0 ]; then
    parts="$parts findlib-toolbox"
fi

echo "# Makefile.config written by configure" >Makefile.config
echo "OCAML_CORE_STDLIB=${ocaml_core_stdlib}" >>Makefile.config
echo "OCAML_CORE_BIN=${ocaml_core_bin}" >>Makefile.config
echo "OCAML_CORE_MAN=${ocaml_core_man}" >>Makefile.config
echo "OCAML_SITELIB=${ocaml_sitelib}" >>Makefile.config
echo "OCAML_THREADS=${ocaml_threads}" >>Makefile.config
echo "OCAMLFIND_BIN=${ocamlfind_bin}" >>Makefile.config
echo "OCAMLFIND_MAN=${ocamlfind_man}" >>Makefile.config
echo "OCAMLFIND_CONF=${ocamlfind_config}" >>Makefile.config
echo "OCAML_AUTOLINK=${ocaml_autolink}" >>Makefile.config
echo "EXEC_SUFFIX=${exec_suffix}" >>Makefile.config
echo "PARTS=${parts}" >>Makefile.config
echo "INSTALL_TOPFIND=${with_topfind}" >>Makefile.config
echo "USE_CYGPATH=${use_cygpath}" >>Makefile.config
echo "VERSION=${version}" >>Makefile.config
echo "SYSTEM=${system}" >>Makefile.config

# All OK

echo
echo "About the OCAML core installation:"
echo "    Standard library:      ${ocaml_core_stdlib}"
echo "    Binaries:              ${ocaml_core_bin}"
echo "    Manual pages:          ${ocaml_core_man}"
echo "    Multi-threading type:  ${ocaml_threads}"
echo "The directory of site-specific packages will be"
echo "    site-lib:              ${ocaml_sitelib}"
echo "The configuration file is written to:"
echo "    findlib config file:   ${ocamlfind_config}"
echo "Software will be installed:"
echo "    Libraries:             in <site-lib>/findlib"
echo "    Binaries:              ${ocamlfind_bin}"
echo "    Manual pages:          ${ocamlfind_man}"
if [ $with_topfind -gt 0 ]; then
    echo "    topfind script:        ${ocaml_core_stdlib}"
else
    echo "    topfind script:        omitted"
fi

if [ $with_toolbox -gt 0 ]; then
    echo "Toolbox:                   yes"
else
    echo "Toolbox:                   no"
fi

echo
echo "Configuration has been written to Makefile.config"
echo
echo "You can now do 'make all', and optionally 'make opt', to build ocamlfind."

This web site is published by Informatikbüro Gerd Stolpmann
Powered by Caml