Advertisement
peetaur

gcc wrapper in bash - doesn't work properly

Oct 10th, 2012
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.35 KB | None | 0 0
  1. peter:/usr/bin # ls -l gcc*
  2. lrwxrwxrwx 1 root root      9 Oct 10 09:10 gcc -> gcc.wrap2
  3. -rwxr-xr-x 1 root root 345208 Oct 29  2011 gcc-4.6
  4. lrwxrwxrwx 1 root root      7 Jul  8 17:16 gcc.real -> gcc-4.6
  5. -rwxr-xr-x 1 root root    902 Oct  9 22:28 gcc.wrap
  6. -rwxr-xr-x 1 root root  11500 Oct 10 09:12 gcc.wrap2
  7. -rw-r--r-- 1 root root    539 Oct 10 09:12 gcc.wrap2.c
  8. -rwxr-xr-x 1 root root   2018 Oct 29  2011 gccmakedep
  9. peter:/usr/bin # cat gcc.wrap
  10. #!/bin/bash
  11.  
  12. dir=$(dirname "$0")
  13.  
  14. real="gcc.real"
  15.  
  16. IFS=$'\n'
  17. args=()
  18. i=0
  19. removed=0
  20.  
  21. for arg in "$@"; do
  22.     echo "PM gcc.wrap: arg is \"$arg\""
  23.     if echo "$arg " | grep "\-Werror" >/dev/null; then
  24.         echo "PM gcc.wrap:     found -Werror... removing it"
  25.         arg=$(echo "$arg" | sed -r "s/-Werror//")
  26.         echo "PM gcc.wrap:     arg after removal: $arg"
  27.         removed=1
  28.         if [ "$arg" = "" -o "$arg" = " " ]; then
  29.             echo "PM gcc.wrap:    arg is now blank, so omitting"
  30.             continue
  31.         fi
  32.     fi
  33.     args[$i]="$arg"
  34.     let i++
  35. done
  36.  
  37. if [ "$removed" = "1" ]; then
  38.     echo "PM gcc.wrap:command is: \"$dir\"/gcc.real ${args[@]} && exit 0 || exit 1"
  39.     "$dir"/"$real" "${args[@]}" && exit 0 || exit 1
  40. else
  41.     # for cases when nothing is changed, just run the thing normally (so buggy side effects are gone)
  42.     "$dir"/"$real" "$@" && exit 0 || exit 1
  43. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement