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 /aclocal.m4 | |
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}
Diffstat (limited to 'aclocal.m4')
-rw-r--r-- | aclocal.m4 | 24 |
1 files changed, 24 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 +]) |