From 43c303c946c61469181d633cd5620cb92e44c329 Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Mon, 21 Mar 2016 11:18:53 -0700 Subject: libc/*.sh: handle combinations of multilib root/dir. Install startfiles for libc variants into the most specific combination (suffixed sysroot, if applicable + suffixed multi-os dir, if applicable). Install headers once in every suffixed sysroot (although it seems that GCC picks up headers from top-level sysroot, GCC manual claims that sysroot suffix affects headers search path). In uClibc, this requires a better sanitization of the directory: it creates symlinks from {sysroot}/usr/lib/{multi_os_dir} to {sysroot}/lib/{multi_os_dir} and to do so, it counts the number of path components in the libdir. This breaks if one of such components is `..' - symlinks contain an extra `../..' then. Since such sanitization had to be implemented anyway, use it in other places to print more sensible directory names. Also, fix the description of configure --host/--target per musl's configure help message (and its actual code). Signed-off-by: Alexey Neyman --- scripts/functions | 54 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 9 deletions(-) (limited to 'scripts/functions') diff --git a/scripts/functions b/scripts/functions index 557c0282..2331557b 100644 --- a/scripts/functions +++ b/scripts/functions @@ -1,6 +1,6 @@ # -*- mode: sh; tab-width: 4 -*- # vi: ts=4:sw=4:sts=4:et -# This file contains some usefull common functions +# This file contains some useful common functions # Copyright 2007 Yann E. MORIN # Licensed under the GPL v2. See COPYING in the root of this package @@ -308,21 +308,57 @@ CT_SanitizePath() { PATH="${new}" } -# Sanitise the directory name contained in the variable passed as argument: +# Sanitize the directory name contained in the variable passed as argument: # - remove duplicate / -# Usage: CT_SanitiseVarDir CT_PREFIX_DIR -CT_SanitiseVarDir() { +# - remove . (current dir) at the beginning, in the middle or at the end +# - resolve .. (parent dir) if there is a previous component +# - remove .. (parent dir) if at the root +# +# Usage: CT_SanitizeVarDir CT_PREFIX_DIR +CT_SanitizeVarDir() { local var local old_dir - local new_dir + local new_dir tmp for var in "$@"; do eval "old_dir=\"\${${var}}\"" - new_dir="$( printf "${old_dir}" \ - |${sed} -r -e 's:/+:/:g;' \ - )" + new_dir=$( echo "${old_dir}" | ${awk} ' +{ + isabs = $1 == "" # Started with a slash + trail = $NF == "" # Ending with a slash + ncomp = 0 # Components in a path so far + for (i = 1; i <= NF; i++) { + # Double-slash or current dir? Ignore + if ($i == "" || $i == ".") { + continue; + } + # .. pops the last component unless it is at the beginning + if ($i == ".." && ncomp != 0 && comps[ncomp] != "..") { + ncomp--; + continue; + } + comps[++ncomp] = $i; + } + seencomp = 0 + for (i = 1; i <= ncomp; i++) { + if (comps[i] == ".." && isabs) { + # /../ at the beginning is equivalent to / + continue; + } + printf "%s%s", isabs || i != 1 ? "/" : "", comps[i]; + seencomp = 1; + } + if (!seencomp && !isabs && !trail) { + # Eliminated all components, but no trailing slash - + # if the result is appened with /foo, must not become absolute + printf "."; + } + if ((!seencomp && isabs) || (seencomp && trail)) { + printf "/"; + } +}' FS=/ ) eval "${var}=\"${new_dir}\"" - CT_DoLog DEBUG "Sanitised '${var}': '${old_dir}' -> '${new_dir}'" + CT_DoLog DEBUG "Sanitized '${var}': '${old_dir}' -> '${new_dir}'" done } -- cgit v1.2.3