diff sources/functions.sh @ 899:726cac165450

Remove old RECORD_COMMANDS debris from host-tools.sh and simplify result (lots of white-noise from de-intenting the "else" case of an if/else), factor out wrap_path from sources/more/record-commands.sh, fix the "build host tools first, then wrap it afterwards" case.
author Rob Landley <rob@landley.net>
date Mon, 23 Nov 2009 21:58:49 -0600
parents db0f536aee7c
children 5ffc758bf60a
line wrap: on
line diff
--- a/sources/functions.sh	Sun Nov 22 03:56:04 2009 -0600
+++ b/sources/functions.sh	Mon Nov 23 21:58:49 2009 -0600
@@ -684,3 +684,35 @@
     X=$[$X+1]
   done
 }
+
+
+# Create a directory of symlinks to all binaries in a colon-separated path.
+
+# Arguments are path to search, directory to populate, and (optionally)
+# wrapper binary to symlink to instead of original binaries.
+
+wrap_path()
+{
+
+  # For each each $PATH element, loop through each file in that directory,
+  # and create a symlink to the wrapper with that name.  In the case of
+  # duplicates, keep the first one.
+
+  echo "$1" | sed 's/:/\n/g' | while read i
+  do
+    ls -1 "$i" | while read j
+    do
+      if [ ! -z "$3" ]
+      then
+        ln -s "$3" "$2/$j" 2>/dev/null
+      else
+        ln -s "$i/$j" "$2/$j" 2>/dev/null
+      fi
+
+      # Output is verbose.  Pipe it to dotprogress.
+
+      echo $j
+    done
+  done
+}
+