+# $(prefix), expressed as a path relative to $(libsubdir).
+#
+# An explanation of the sed strings:
+# -e 's|^$(prefix)||' matches and eliminates 'prefix' from 'exec_prefix'
+# -e 's|/$$||' match a trailing forward slash and eliminates it
+# -e 's|^[^/]|/|' forces the string to start with a forward slash (*)
+# -e 's|/[^/]*|../|g' replaces each occurrence of /<directory> with ../
+#
+# (*) Note this pattern overwrites the first character of the string
+# with a forward slash if one is not already present. This is not a
+# problem because the exact names of the sub-directories concerned is
+# unimportant, just the number of them matters.
+#
+# The practical upshot of these patterns is like this:
+#
+# prefix exec_prefix result
+# ------ ----------- ------
+# /foo /foo/bar ../
+# /foo/ /foo/bar ../
+# /foo /foo/bar/ ../
+# /foo/ /foo/bar/ ../
+# /foo /foo/bar/ugg ../../
+libsubdir_to_prefix := \
+ $(unlibsubdir)/$(shell echo "$(libdir)" | \
+ sed -e 's|^$(prefix)||' -e 's|/$$||' -e 's|^[^/]|/|' \
+ -e 's|/[^/]*|../|g')
+# $(exec_prefix), expressed as a path relative to $(prefix).
+prefix_to_exec_prefix := \
+ $(shell echo "$(exec_prefix)" | \
+ sed -e 's|^$(prefix)||' -e 's|^/||' -e '/./s|$$|/|')