diff --git a/configure b/configure
index 891cbfe7df..df132dcf8c 100755
--- a/configure
+++ b/configure
@@ -20,6 +20,7 @@ prefix='/usr/local'
bindir='$(PREFIX)/bin'
libdir='$(PREFIX)/lib/compcert'
mandir='$(PREFIX)/share/man'
+sharedir='' # determined later based on $bindir and -sharedir option
coqdevdir='$(PREFIX)/lib/compcert/coq'
toolprefix=''
target=''
@@ -88,6 +89,7 @@ Options:
-prefix
Install in /bin and /lib/compcert
-bindir Install binaries in
-libdir Install libraries in
+ -sharedir Install configuration file in
-mandir Install man pages in
-coqdevdir Install Coq development (.vo files) in
-toolprefix Prefix names of tools ("gcc", etc) with
@@ -120,6 +122,8 @@ while : ; do
libdir="$2"; shift;;
-mandir|--mandir)
mandir="$2"; shift;;
+ -sharedir|--sharedir)
+ sharedir="$2"; shift;;
-coqdevdir|--coqdevdir)
coqdevdir="$2"; install_coqdev=true; shift;;
-toolprefix|--toolprefix)
@@ -610,10 +614,36 @@ if $missingtools; then
exit 2
fi
+#
+# Determine $sharedir or check that user-provided $sharedir is valid
+#
+
+expandprefix() {
+ echo "$1" | sed -e "s|\\\$(PREFIX)|$prefix|"
+}
+
+if test -z "$sharedir"; then
+ sharedir=$(dirname "$bindir")/share
+else
+ expsharedir=$(expandprefix "$sharedir")
+ expbindir=$(expandprefix "$bindir")
+ expbindirshare=$(dirname "$expbindir")/share
+ if test "$expsharedir" = "$expbindirshare/compcert" \
+ || test "$expsharedir" = "$expbindirshare" \
+ || test "$expsharedir" = "$expbindir"
+ then : ; # ok!
+ else
+ echo "Wrong -sharedir option. The share directory must be one of"
+ echo " $expbindirshare/compcert"
+ echo " $expbindirshare"
+ echo " $expbindir"
+ exit 2
+ fi
+fi
+
#
# Generate Makefile.config
#
-sharedir="$(dirname "$bindir")"/share
rm -f Makefile.config
cat > Makefile.config <