diff --git a/projects/tea.xyz/gx/cc/cc.rb b/projects/tea.xyz/gx/cc/cc.rb index 98b9238e..4f312bb5 100755 --- a/projects/tea.xyz/gx/cc/cc.rb +++ b/projects/tea.xyz/gx/cc/cc.rb @@ -16,10 +16,23 @@ args = ARGV.map do |arg| arg unless arg == "-Wl,-rpath,#$tea_prefix" or arg == "-nodefaultrpaths" end.compact +def is_tea? path + path = File.realpath path while File.symlink? path + return File.basename(path) == "tea" +end + # find next example of ourselves # this will either pick the Apple provided clang or the tea one exe_path = ENV['PATH'].split(":").filter { |path| - path != File.dirname(__FILE__) && path != File.join($tea_prefix, ".local/bin") + if path == File.dirname(__FILE__) + false + elsif path == File.join($tea_prefix, ".local/bin") + false + elsif is_tea?(path) + false + else + true + end }.map { |path| "#{path}/#{exe}" }.reject { |path| diff --git a/projects/tea.xyz/gx/cc/ld b/projects/tea.xyz/gx/cc/ld index 1b3bd42f..f26ff991 100755 --- a/projects/tea.xyz/gx/cc/ld +++ b/projects/tea.xyz/gx/cc/ld @@ -1,4 +1,6 @@ -#!/bin/sh +#!/bin/bash + +set -e if test -z "$TEA_PREFIX" then @@ -6,22 +8,37 @@ then exit 1 fi -dir=$(dirname "$0") -exe=$(basename "$0") +DIR=$(dirname "$0") +IFS=: read -r -a PATHS <<< "$PATH" -# Remove us from our path -PATH=$(echo "$PATH" | tr ":" "\n" | grep -v "$dir" | tr "\n" ":") -PATH=$(echo "$PATH" | tr ":" "\n" | grep -v "$TEA_PREFIX/.local/bin" | tr "\n" ":") +__which() { + for dir in "${PATHS[@]}"; do + if test "$dir" == "$DIR"; then + : # no fork bombs thanks + elif [ -L "$dir/$1" ]; then + # no fork bombs thanks + foo="$(realpath "$dir/$1")" + foo="$(basename "$foo")" + if [ "$foo" != "tea" ]; then + exe="$dir/$1" + return 0 + fi + elif [ -x "$dir/$1" ]; then + exe="$dir/$1" + return 0 + fi + done + + return 1 +} # If we can find our specific name, e.g. `lld`, # passthrough to that -if which "$exe" >/dev/null 2>&1; then - exe=$(which "$exe") # Otherwise, fallback to `ld` # NB: this might not have the right invocations, sometimes; # (invoking `ld` as `lld64.ld`) watch for those potential cases -elif which ld >/dev/null 2>&1; then - exe=$(which ld) +if __which $(basename "$0") || __which ld; then + : else echo 'ld not found in PATH' >&2 exit 127 @@ -35,4 +52,5 @@ for word in "$@"; do exec "$exe" "$@" fi done + exec "$exe" "$@" -rpath "$TEA_PREFIX" diff --git a/projects/tea.xyz/gx/cc/package.yml b/projects/tea.xyz/gx/cc/package.yml index b95e6068..eeb726ef 100644 --- a/projects/tea.xyz/gx/cc/package.yml +++ b/projects/tea.xyz/gx/cc/package.yml @@ -3,7 +3,7 @@ distributable: ~ # FIXME we want the c version eg. c99 # or should that be some kind of option? so you specify you want a cc that support c99 versions: - - 0.1.5 + - 0.1.6 dependencies: linux: