Blob Blame History Raw
#! /bin/sh

# Try to turn internationalization off
unset LANG
unset LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME

set -e

PINNED=0
for i in "$@"; do
  case $i in
    --bindir=*)
      BINDIR=${i##*=}
      ;;
    --libdir=*)
      LIBDIR=${i##*=}
      ;;
    --pkgdir=*)
      PKGDIR=${i##*=}
      ;;
    --pinned*)
      PINNED=1
      ;;
    *)
      echo "usage: ./configure [--bindir=<dir>] [--libdir=<dir>] [--pkgdir=<dir>]" 1>&2
      exit 2
      ;;
  esac
done

# OCaml is already installed, this means we should have everything we
# need. Just dump its configuration.

ocaml_version=`ocamlc -version`
major=`echo $ocaml_version | cut -d. -f1`
minor=`echo $ocaml_version | cut -d. -f2`

if [ $major -lt 4 -o \( $major -eq 4 -a $minor -lt 2 \) ]; then
    echo "The standalone Camlp4 requires OCaml >= 4.02."
    echo "For previous versions of OCaml use the Camlp4 distributed with OCaml."
    exit 2
elif [ $major -ne 4 -o $minor -ne 7 ]; then
    echo "This version of Camlp4 is for OCaml 4.07 but you are using OCaml $ocaml_version."
    if [ -d .git ] ; then
      if [ $PINNED -eq 1 ] ; then
        echo "You've used the wrong opam pin URL for this switch.">&2
        echo "Try https://github.com/ocaml/camlp4.git#$major.$minor instead">&2
      else
        echo "You appear to be building Camlp4 from git, so try the $major.$minor branch."
      fi
    fi
    exit 2
fi

ocamlc -config | tr -d '\015' | sed 's/: /="/;s/$/"/' > config.sh
ocamlc -config | tr -d '\015' | sed 's/^/let /;s/: / = "/;s/$/"/' > myocamlbuild_config.ml

# Add a few things to config.sh

. ./config.sh

if [ "$os_type" = Win32 ]; then
    ext_exe=".exe"
else
    ext_exe=""
fi

OCAMLC="`command -v ocamlc`"
LIBDIR="${LIBDIR:-$standard_library}"
BINDIR="${BINDIR:-`dirname $OCAMLC`}"
PKGDIR="${PKGDIR:-$standard_library}"

if [ -x "`command -v ocamlopt`" ]; then
    OB_FLAGS=""
else
    OB_FLAGS="-byte-plugin"
fi

COMPLIBS="`ocamlc -where`/compiler-libs"
if [ -f "$COMPLIBS/opttoploop.cmi" ]; then
    OCAMLNAT=true
else
    OCAMLNAT=false
fi

cat >> config.sh <<EOF
A="$ext_lib"
O="$ext_obj"
EXE="$ext_exe"
LIBDIR="$LIBDIR"
BINDIR="$BINDIR"
PKGDIR="$PKGDIR"
OB_FLAGS=$OB_FLAGS
OCAMLNAT=$OCAMLNAT
EOF

cat >> myocamlbuild_config.ml <<EOF
let libdir="$LIBDIR"
let bindir="$BINDIR"
let pkgdir="$PKGDIR"
let ocamlnat=$OCAMLNAT
EOF