Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at netboot-syslinux-multiplatform 182 lines 5.4 kB view raw
1#! @shell@ 2set -eu -o pipefail +o posix 3shopt -s nullglob 4 5if (( "${NIX_DEBUG:-0}" >= 7 )); then 6 set -x 7fi 8 9path_backup="$PATH" 10 11# That @-vars are substituted separately from bash evaluation makes 12# shellcheck think this, and others like it, are useless conditionals. 13# shellcheck disable=SC2157 14if [[ -n "@coreutils_bin@" && -n "@gnugrep_bin@" ]]; then 15 PATH="@coreutils_bin@/bin:@gnugrep_bin@/bin" 16fi 17 18cInclude=0 19 20source @out@/nix-support/utils.bash 21 22# Flirting with a layer violation here. 23if [ -z "${NIX_BINTOOLS_WRAPPER_FLAGS_SET_@suffixSalt@:-}" ]; then 24 source @bintools@/nix-support/add-flags.sh 25fi 26 27# Put this one second so libc ldflags take priority. 28if [ -z "${NIX_CC_WRAPPER_FLAGS_SET_@suffixSalt@:-}" ]; then 29 source @out@/nix-support/add-flags.sh 30fi 31 32if [ -z "${NIX_GNAT_WRAPPER_EXTRA_FLAGS_SET_@suffixSalt@:-}" ]; then 33 source @out@/nix-support/add-gnat-extra-flags.sh 34fi 35 36# Parse command line options and set several variables. 37# For instance, figure out if linker flags should be passed. 38# GCC prints annoying warnings when they are not needed. 39dontLink=0 40nonFlagArgs=0 41# shellcheck disable=SC2193 42 43expandResponseParams "$@" 44declare -i n=0 45nParams=${#params[@]} 46while (( "$n" < "$nParams" )); do 47 p=${params[n]} 48 p2=${params[n+1]:-} # handle `p` being last one 49 if [ "$p" = -c ]; then 50 dontLink=1 51 elif [ "$p" = -S ]; then 52 dontLink=1 53 elif [ "$p" = -E ]; then 54 dontLink=1 55 elif [ "$p" = -E ]; then 56 dontLink=1 57 elif [ "$p" = -M ]; then 58 dontLink=1 59 elif [ "$p" = -MM ]; then 60 dontLink=1 61 elif [[ "$p" = -x && "$p2" = *-header ]]; then 62 dontLink=1 63 elif [[ "$p" != -?* ]]; then 64 # A dash alone signifies standard input; it is not a flag 65 nonFlagArgs=1 66 fi 67 n+=1 68done 69 70# If we pass a flag like -Wl, then gcc will call the linker unless it 71# can figure out that it has to do something else (e.g., because of a 72# "-c" flag). So if no non-flag arguments are given, don't pass any 73# linker flags. This catches cases like "gcc" (should just print 74# "gcc: no input files") and "gcc -v" (should print the version). 75if [ "$nonFlagArgs" = 0 ]; then 76 dontLink=1 77fi 78 79# Optionally filter out paths not refering to the store. 80if [[ "${NIX_ENFORCE_PURITY:-}" = 1 && -n "$NIX_STORE" ]]; then 81 rest=() 82 nParams=${#params[@]} 83 declare -i n=0 84 while (( "$n" < "$nParams" )); do 85 p=${params[n]} 86 p2=${params[n+1]:-} # handle `p` being last one 87 if [ "${p:0:3}" = -L/ ] && badPath "${p:2}"; then 88 skip "${p:2}" 89 elif [ "$p" = -L ] && badPath "$p2"; then 90 n+=1; skip "$p2" 91 elif [ "${p:0:3}" = -I/ ] && badPath "${p:2}"; then 92 skip "${p:2}" 93 elif [ "$p" = -I ] && badPath "$p2"; then 94 n+=1; skip "$p2" 95 elif [ "${p:0:4}" = -aI/ ] && badPath "${p:3}"; then 96 skip "${p:3}" 97 elif [ "$p" = -aI ] && badPath "$p2"; then 98 n+=1; skip "$p2" 99 elif [ "${p:0:4}" = -aO/ ] && badPath "${p:3}"; then 100 skip "${p:3}" 101 elif [ "$p" = -aO ] && badPath "$p2"; then 102 n+=1; skip "$p2" 103 elif [ "$p" = -isystem ] && badPath "$p2"; then 104 n+=1; skip "$p2" 105 else 106 rest+=("$p") 107 fi 108 n+=1 109 done 110 # Old bash empty array hack 111 params=(${rest+"${rest[@]}"}) 112fi 113 114 115# Clear march/mtune=native -- they bring impurity. 116if [ "$NIX_ENFORCE_NO_NATIVE_@suffixSalt@" = 1 ]; then 117 rest=() 118 # Old bash empty array hack 119 for p in ${params+"${params[@]}"}; do 120 if [[ "$p" = -m*=native ]]; then 121 skip "$p" 122 else 123 rest+=("$p") 124 fi 125 done 126 # Old bash empty array hack 127 params=(${rest+"${rest[@]}"}) 128fi 129 130case "$(basename $0)x" in 131 "gnatbindx") 132 extraBefore=() 133 extraAfter=($NIX_GNATFLAGS_COMPILE_@suffixSalt@) 134 ;; 135 "gnatchopx") 136 extraBefore=("--GCC=@out@/bin/gcc") 137 extraAfter=() 138 ;; 139 "gnatcleanx") 140 extraBefore=($NIX_GNATFLAGS_COMPILE_@suffixSalt@) 141 extraAfter=() 142 ;; 143 "gnatlinkx") 144 extraBefore=() 145 extraAfter=("--GCC=@out@/bin/gcc") 146 ;; 147 "gnatlsx") 148 extraBefore=() 149 extraAfter=($NIX_GNATFLAGS_COMPILE_@suffixSalt@) 150 ;; 151 "gnatmakex") 152 extraBefore=("--GNATBIND=@out@/bin/gnatbind" "--GNATLINK=@out@/bin/gnatlink") 153 extraAfter=($NIX_GNATFLAGS_COMPILE_@suffixSalt@ -cargs $NIX_GNATMAKE_CARGS_@suffixSalt@) 154 ;; 155esac 156 157# As a very special hack, if the arguments are just `-v', then don't 158# add anything. This is to prevent `gcc -v' (which normally prints 159# out the version number and returns exit code 0) from printing out 160# `No input files specified' and returning exit code 1. 161if [ "$*" = -v ]; then 162 extraAfter=() 163 extraBefore=() 164fi 165 166# Optionally print debug info. 167if (( "${NIX_DEBUG:-0}" >= 1 )); then 168 # Old bash workaround, see ld-wrapper for explanation. 169 echo "extra flags before to @prog@:" >&2 170 printf " %q\n" ${extraBefore+"${extraBefore[@]}"} >&2 171 echo "original flags to @prog@:" >&2 172 printf " %q\n" ${params+"${params[@]}"} >&2 173 echo "extra flags after to @prog@:" >&2 174 printf " %q\n" ${extraAfter+"${extraAfter[@]}"} >&2 175fi 176 177PATH="$path_backup" 178# Old bash workaround, see above. 179exec @prog@ \ 180 ${extraBefore+"${extraBefore[@]}"} \ 181 ${params+"${params[@]}"} \ 182 ${extraAfter+"${extraAfter[@]}"}