diff options
author | David Allsopp <david.allsopp@metastack.com> | 2021-05-12 14:36:14 +0100 |
---|---|---|
committer | David Allsopp <david.allsopp@metastack.com> | 2021-05-12 14:36:14 +0100 |
commit | 0222801d9c57d5c4188ca1d2a13d2e734892a44a (patch) | |
tree | f95efa1be068e6e7673ecfd3de665f3c246e295d | |
parent | f9117086ce29b101a241d3eb73cbc02a27d601c8 (diff) | |
download | ocaml-0222801d9c57d5c4188ca1d2a13d2e734892a44a.tar.gz |
Generate an OCaml quoted string ID in configure
The string @QS@ is available to use in template.in files that produce
OCaml code allowing strings to be written as
{@QS@|@variable_from_configure@|@QS@} guaranteeing that any value of
@variable_from_configure@ yields a properly quoted OCaml string.
The calculation inserts 'o' characters until none of the strings passed
to AC_SUBST include the sequence |o..o}
-rw-r--r-- | aclocal.m4 | 24 | ||||
-rwxr-xr-x | configure | 25 | ||||
-rw-r--r-- | configure.ac | 4 |
3 files changed, 53 insertions, 0 deletions
diff --git a/aclocal.m4 b/aclocal.m4 index 7bf3b2df1d..c79ad310b0 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -509,3 +509,27 @@ int main (void) { [AC_MSG_RESULT([cross-compiling; assume yes]) AC_DEFINE([HAS_WORKING_FMA])])]) ]) + +# Computes a suitable id to insert in quoted strings to ensure that all OCaml +# quoted strings generated by configure cannot be "escaped". The ID takes the +# form {o*|string|o*}. +AC_DEFUN([OCAML_QUOTED_STRING_ID], [ + # Go through ac_subst_vars and put all the values to be substituted in + # $all_values. + QS='' + all_values='' + for name in $ac_subst_vars; do + eval "value=\$${name}" + all_values="$all_values $value" + done + + # Keep adding 'o' to $QS until |$QS} doesn't appear in any substitution. + test_string='' + while test "x${test_string}" != "x${all_values}"; do + test_string="$all_values" + eval "test_string=\"\${test_string##*\|${QS}\}}\"" + if test "x${test_string}" != "x${all_values}"; then + QS="o${QS}" + fi + done +]) @@ -750,6 +750,7 @@ build_os build_vendor build_cpu build +QS force_instrumented_runtime compute_deps stdlib_manpages @@ -2957,6 +2958,7 @@ OCAML_VERSION_SHORT=5.0 + ## Generated files ac_config_files="$ac_config_files Makefile.build_config" @@ -2994,6 +2996,9 @@ $as_echo "#define OCAML_VERSION 50000" >>confdefs.h $as_echo "#define OCAML_VERSION_STRING \"5.0.0+dev0-2021-11-05\"" >>confdefs.h +# Works out how many "o"s are needed in quoted strings + + # Checks for system types # Make sure we can run config.sub. @@ -18195,6 +18200,26 @@ LTLIBOBJS=$ac_ltlibobjs + # Go through ac_subst_vars and put all the values to be substituted in + # $all_values. + QS='' + all_values='' + for name in $ac_subst_vars; do + eval "value=\$${name}" + all_values="$all_values $value" + done + + # Keep adding 'o' to $QS until |$QS} doesn't appear in any substitution. + test_string='' + while test "x${test_string}" != "x${all_values}"; do + test_string="$all_values" + eval "test_string=\"\${test_string##*\|${QS}\}}\"" + if test "x${test_string}" != "x${all_values}"; then + QS="o${QS}" + fi + done + + # Construct $mkexe mkexe="$mkexe_cmd" if test -n "$mkexe_cflags"; then : diff --git a/configure.ac b/configure.ac index 9c8a506b3f..b3a5df487b 100644 --- a/configure.ac +++ b/configure.ac @@ -169,6 +169,7 @@ AC_SUBST([PACKLD]) AC_SUBST([stdlib_manpages]) AC_SUBST([compute_deps]) AC_SUBST([force_instrumented_runtime]) +AC_SUBST([QS]) ## Generated files @@ -192,6 +193,9 @@ m4_if([OCAML__VERSION_EXTRA],[], [], AC_DEFINE([OCAML_VERSION], [OCAML__VERSION_NUMBER]) AC_DEFINE([OCAML_VERSION_STRING], ["][OCAML__VERSION]["]) +# Works out how many "o"s are needed in quoted strings +AC_CONFIG_COMMANDS_PRE(OCAML_QUOTED_STRING_ID) + # Checks for system types AC_CANONICAL_BUILD |