summaryrefslogtreecommitdiffstats
path: root/tools/make-version-header.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tools/make-version-header.sh')
-rwxr-xr-xtools/make-version-header.sh20
1 files changed, 15 insertions, 5 deletions
diff --git a/tools/make-version-header.sh b/tools/make-version-header.sh
index b5e69be95..26c5c1428 100755
--- a/tools/make-version-header.sh
+++ b/tools/make-version-header.sh
@@ -13,9 +13,6 @@
# #
#########################################################################
-# For maximal compatibility with older versions, we Use "ocamlc -v"
-# instead of "ocamlc -vnum" or the VERSION file in .../lib/ocaml/.
-
# This script extracts the components from an OCaml version number
# and provides them as C defines:
# OCAML_VERSION_MAJOR: the major version number
@@ -26,7 +23,18 @@
# Note that additional-info is always absent in officially-released
# versions of OCaml.
-version="`ocamlc -v | sed -n -e 's/.*version //p'`"
+# usage:
+# make-version-header.sh [version-file]
+# The argument is the VERSION file from the OCaml sources.
+# If the argument is not given, the version number from "ocamlc -v" will
+# be used.
+
+case $# in
+ 0) version="`ocamlc -v | sed -n -e 's/.*version //p'`";;
+ 1) version="`sed -e 1q $1`";;
+ *) echo "usage: make-version-header.sh [version-file]" >&2
+ exit 2;;
+esac
major="`echo "$version" | sed -n -e '1s/^\([0-9]*\)\..*/\1/p'`"
minor="`echo "$version" | sed -n -e '1s/^[0-9]*\.\([0-9]*\).*/\1/p'`"
@@ -34,10 +42,12 @@ patchlvl="`echo "$version" | sed -n -e '1s/^[0-9]*\.[0-9]*\.\([0-9]*\).*/\1/p'`"
suffix="`echo "$version" | sed -n -e '1s/^[^+]*+\(.*\)/\1/p'`"
echo "#define OCAML_VERSION_MAJOR $major"
-echo "#define OCAML_VERSION_MINOR $minor"
+printf "#define OCAML_VERSION_MINOR %d\n" $minor
case $patchlvl in "") patchlvl=0;; esac
echo "#define OCAML_VERSION_PATCHLEVEL $patchlvl"
case "$suffix" in
"") echo "#undef OCAML_VERSION_ADDITIONAL";;
*) echo "#define OCAML_VERSION_ADDITIONAL \"$suffix\"";;
esac
+printf "#define OCAML_VERSION %d%02d%02d\n" $major $minor $patchlvl
+echo "#define OCAML_VERSION_STRING \"$version\""