Permalink
Fetching contributors…
Cannot retrieve contributors at this time
executable file 338 lines (284 sloc) 8.3 KB
#!/bin/sh
# Useful routines
# ===============
# [check_package $pkg $msg]
# - succeeds if findlib package $pkg is installed
# - or sets EXIT=1 and displays $msg
check_package()
{
if ocamlfind query "$1" >/dev/null 2>/dev/null; then
printf "Found $1\t${COL_GREEN}GOOD${COL_CLEAR}\n"
else
printf "${COL_RED}BAD${COL_CLEAR} $1 is missing\n\t$2\n"
EXIT=1
fi
}
# [filter_file $filename $filter...]
# filter the contents of $filename through $filter, updating the file
filter_file()
{
FILE="$1"
shift 1
mv "$FILE" "$FILE".org
"$@" < "$FILE".org > "$FILE"
rm "$FILE".org
}
# [usage] displays usage message for the configure script
usage()
{
cat <<END
\`configure' configures your Merlin installation.
The options available for better control are as follow:
--bindir <path> where to install merlin's executable
default: /usr/local/bin
--sharedir <path> where the different editor modes will be installed
default: /usr/local/share
--prefix <path> when given, bindir will be set to '<path>/bin' and
sharedir to '<path>/share'
--vimdir <path> when given, vim bindings will be installed to '<path>'
default: /usr/local/share/ocamlmerlin/vim
--with-bin-annot compiles merlin with '--bin-annot', useful if you plan
to work on merlin itself.
--enable-compiled-emacs-mode compiles the emacs mode.
Makes the plugin load slightly faster.
--with-version-string <str> Overwrite the version message printed by
merlin when called with -version or -vnum.
END
}
# Check prerequisite, setup defaults
# ==================================
## Color settings
if which tput > /dev/null 2>&1 ; then
COL_CLEAR=$(tput sgr0)
COL_RED=$(tput setf 4)
COL_GREEN=$(tput setf 2)
else
COL_CLEAR=
COL_RED=
COL_GREEN=
fi
## OCamlfind
if ! [ -x $(which ocamlfind) ]; then
echo "OCamlfind is missing. Please install it."
exit 1
fi
## Default variables
BIN_DIR=/usr/local/bin
SHARE_DIR=/usr/local/share
VIM_DIR=/usr/local/share/ocamlmerlin/vim
WITH_BIN_ANNOT=""
VERSION_STRING=""
EXIT=0
# Parse arguments
# ===============
while [ -n "$1" ]; do
case "$1" in
--prefix)
shift 1
BIN_DIR="$1/bin"
SHARE_DIR="$1/share"
VIM_DIR="$SHARE_DIR/ocamlmerlin/vim"
;;
--bindir)
shift 1
BIN_DIR="$1"
;;
--sharedir)
shift 1
SHARE_DIR="$1"
;;
--vimdir)
shift 1
VIM_DIR="$1"
;;
--with-bin-annot)
WITH_BIN_ANNOT=1
;;
--enable-compiled-emacs-mode)
ENABLE_COMPILED_EMACS_MODE=true
;;
--with-version-string)
shift 1
VERSION_STRING="$1"
;;
--help|-help|-h)
usage
exit 0
esac
shift 1
done
# Validate configuration and system settings
# ==========================================
cat <<END
Merlin configuration
--------------------
END
## Check findlib packages
## ======================
check_package findlib "Install findlib"
check_package yojson "Install yojson"
## Check OCaml version
## ===================
OCAML_VERSION="403"
OCAML_VERSION_MESSAGE="Unknown, defaulting to 4.03"
OCAML_VERSION_VAL='`OCaml_4_03_0'
OCAML_VERSION_TYP='[ `OCaml_4_02_0 | `OCaml_4_02_1 | `OCaml_4_02_2 | `OCaml_4_02_3 | `OCaml_4_03_0 | `OCaml_4_04_0 | `OCaml_4_05_0 ]'
MAGIC_NUMBERS=$(ocamlfind c -config | grep _magic_number)
CMI_NUMBER=$(echo "$MAGIC_NUMBERS" | grep cmi_magic_number | cut -d' ' -f2)
CMT_NUMBER=$(echo "$MAGIC_NUMBERS" | grep cmt_magic_number | cut -d' ' -f2)
FULL_VERSION=$(ocamlfind c -version)
### Patch certain versions of the typechecker
### =========================================
case "$CMI_NUMBER" in
"Caml1999I017")
OCAML_VERSION="402"
if [ "x$FULL_VERSION" = "x4.02.0" ]; then
OCAML_VERSION_MESSAGE="OCaml 4.02.0"
filter_file src/ocaml_402/typing/typecore.ml \
grep -v -F '| Scan_next_char
| Ignored_scan_next_char
| Any_ty
| Custom '
OCAML_VERSION_VAL='`OCaml_4_02_0'
elif [ "x$FULL_VERSION" = "x4.02.1" ]; then
OCAML_VERSION_MESSAGE="OCaml 4.02.1"
filter_file src/ocaml_402/typing/typecore.ml \
grep -v -F '| Any_ty
| Custom '
OCAML_VERSION_VAL='`OCaml_4_02_1'
elif [ "x$FULL_VERSION" = "x4.02.2" ]; then
OCAML_VERSION_MESSAGE="OCaml 4.02.2"
OCAML_VERSION_VAL='`OCaml_4_02_2'
else
OCAML_VERSION_MESSAGE="OCaml 4.02.3"
OCAML_VERSION_VAL='`OCaml_4_02_3'
fi
;;
"Caml1999I020")
OCAML_VERSION="403"
OCAML_VERSION_MESSAGE="OCaml 4.03.0"
OCAML_VERSION_VAL='`OCaml_4_03_0'
;;
"Caml1999I021")
case "$CMT_NUMBER" in
"Caml2012T008")
OCAML_VERSION="404"
OCAML_VERSION_MESSAGE="OCaml 4.04.0"
OCAML_VERSION_VAL='`OCaml_4_04_0'
;;
*)
OCAML_VERSION="405"
OCAML_VERSION_MESSAGE="OCaml 4.05.0"
OCAML_VERSION_VAL='`OCaml_4_05_0'
;;
esac;;
esac
## Findlib version check
## =====================
if [ "x1.5.1" = "x$(ocamlfind query findlib -format '%v')" ]; then
printf "\nOld version of findlib detected (1.5.1), patching\n"
filter_file src/kernel/dot_merlin.ml \
sed -e 's/Findlib\.resolve_path ~base:d ~explicit:true/Findlib.resolve_path ~base:d/'
fi
if ocamlfind ocamlopt; then
NATIVE=true
else
NATIVE=false
fi
## Sturgeon version check
## ======================
if ocamlfind query sturgeon >/dev/null 2>/dev/null; then
STURGEON_VERSION="stub"
STURGEON_VERSION_MESSAGE="stub (enabled, using 'sturgeon' package)"
STURGEON_PACKAGE=sturgeon.recipes_server
NEED_THREADS=1
NEED_THREADS_MESSAGE=yes
else
STURGEON_VERSION="null"
STURGEON_VERSION_MESSAGE="null (disabled)"
STURGEON_PACKAGE=
NEED_THREADS=0
NEED_THREADS_MESSAGE=no
fi
MERLIN_CONFIG_ENV="
export MERLIN_NEED_THREADS=${NEED_THREADS}
export MERLIN_STURGEON_PACKAGE=${STURGEON_PACKAGE}
"
## Windows compatibility checks
## ============================
OS_TYPE=$(ocamlfind c -config | grep os_type|cut -d' ' -f2)
# 64-bit Windows also has OS_TYPE = Win32
case "$OS_TYPE" in
Win32)
# Assume windows-like system
# Avoid symlinks, find right version through environment variable
touch "$PWD/src/ocaml"
MERLIN_CONFIG_ENV="$MERLIN_CONFIG_ENV
export MERLIN_OCAML_VERSION=_${OCAML_VERSION}
export MERLIN_STURGEON_VERSION=_${STURGEON_VERSION}
"
EXE=.exe
;;
*)
# Non windows-like system, use symlinks
rm -f "$PWD/src/ocaml/typer" 2>&1 >/dev/null
ln -sf "$PWD/src/ocaml/typer_$OCAML_VERSION" "$PWD/src/ocaml/typer"
rm -f "$PWD/src/sturgeon" 2>&1 >/dev/null
ln -sf "$PWD/src/sturgeon_$STURGEON_VERSION" "$PWD/src/sturgeon"
EXE=
;;
esac
# Configuration report
# ====================
cat <<END
System config:
OCaml ABI version: $OCAML_VERSION_MESSAGE
Native code: $NATIVE
Sturgeon version: $STURGEON_VERSION_MESSAGE
Need threads: $NEED_THREADS_MESSAGE
Will install:
ocamlmerlin binary in: $BIN_DIR
vim mode in: $VIM_DIR
To customize directories, use:
./configure [--prefix <dir>] [--bindir <dir>] [--sharedir <dir>] [--vimdir <vimdir>]
For more informations rerun with --help.
END
# Execute configuration actions
# =============================
mkdir -p "$PWD/src/config"
if [ -d "$BIN_DIR" ]; then
cat >Makefile.config <<END
BIN_DIR=$BIN_DIR
SHARE_DIR=$SHARE_DIR
VIM_DIR=$VIM_DIR
NATIVE=$NATIVE
WITH_BIN_ANNOT=$WITH_BIN_ANNOT
ENABLE_COMPILED_EMACS_MODE=$ENABLE_COMPILED_EMACS_MODE
EXE=$EXE
$MERLIN_CONFIG_ENV
END
if [ -n "$VERSION_STRING" ]; then
true
elif [ -d ".git" ]; then
VERSION_STRING="git-`git rev-parse HEAD`"
elif [ -f "CHANGELOG" ]; then
VERSION_STRING=`head -n1 CHANGELOG | cut -d' ' -f2`
else
VERSION_STRING="unknown"
fi
cat >src/config/my_config.ml <<END
let version = "$VERSION_STRING";;
let ocamlversion : $OCAML_VERSION_TYP = $OCAML_VERSION_VAL;;
END
if [ "$EXIT" -eq 0 ]; then
echo "Now, type 'make' to compile then 'make install'."
else
echo "Something bad happened. Check your configuration before trying to 'make'."
fi
else
[ -d "$BIN_DIR" ] || echo "'$BIN_DIR' not found or not a directory."
[ -d "$SHARE_DIR" ] || echo "'$SHARE_DIR' not found or not a directory."
[ -d "$VIM_DIR" ] || echo "'$VIM_DIR' not found or not a directory."
echo "Please check configuration."
exit 1
fi