components/ggrep/patches/correct_prefix.patch
author Mike Sullivan <Mike.Sullivan@Oracle.COM>
Sat, 24 Sep 2016 09:29:15 -0700
changeset 6971 32152bc508b7
parent 5391 5aa4a8c4577f
permissions -rw-r--r--
Close of build 109.

This patch was created inhouse and is not applicable for submitting to
upstream. This is because it implements Solaris oddity - having the binaries
available both without prefix and with 'g' prefix at the same time, only in
different paths.

--- grep-2.22-orig/src/egrep.sh	Wed Oct 21 22:00:20 2015
+++ grep-2.22/src/egrep.sh	Tue Jan 19 14:42:27 2016
@@ -1,2 +1,29 @@
 #!@SHELL@
-exec @grep@ @option@ "$@"
+# The script is a wrapper to GNU grep to be called with apropriate (-E or -F)
+# command line option. We can't just run 'ggrep' as the path may not contain
+# '/usr/bin' and we can't just use 'grep' as the PATH may not contain
+# '/usr/gnu/bin'. Also we can't just use fixed path as /usr/gnu/bin/grep because
+# this script must work even from workspace before being installed into /usr/...
+# testing the binaries from the workspace.
+
+if [[ "$( /usr/bin/basename "$0" )" == g* ]]; then
+  # gfgrep or gegrep (potentially in /usr/bin)
+  grep=ggrep
+else
+  # fgrep or egrep in (potentially in /usr/gnu/bin)
+  grep=grep
+fi
+
+case "$0" in
+  */*)
+    dir="${0%/*}"
+    if test -x "$dir/$grep"; then
+      PATH="$dir:$PATH"
+    fi
+    ;;
+  *)
+    PATH="@prefix@/bin:$PATH"
+    ;;
+esac
+
+exec "$grep" @option@ "$@"