7448d38df46e46bfeb7ae1c864a13f24cb96c27b
[tpg/acess2.git] / Tools / GCCProxy / gccproxy.sh
1 #!/bin/bash
2
3 # Get invocation path (which could be a symlink in $PATH)
4 fullpath=`which "$0"`
5 if [[ !$? ]]; then
6         fullpath="$0"
7 fi
8
9 # Resolve symlink
10 fullpath=`readlink -f "$fullpath"`
11
12 # Get base directory
13 BASEDIR=`dirname "$fullpath"`
14
15 _miscargs=""
16 _compile=0
17 _linktype=Applications
18
19 while [[ $# -gt 0 ]]; do
20         case "$1" in
21         -E)
22                 _preproc=1
23                 ;;
24         -M)
25                 _makedep=1
26                 ;;
27         -c)
28                 _compile=1
29                 ;;
30         -o)
31                 shift
32                 _outfile="-o $1"
33                 ;;
34         -shared)
35                 _ldflags=$_ldflags" -shared -lc -lgcc"
36                 _linktype=Libraries
37                 ;;
38         -I|-D|-O)
39                 _cflags=$_cflags" $1 $2"
40                 shift
41                 ;;
42         -I*|-D*|-O*)
43                 _cflags=$_cflags" $1"
44                 ;;
45         -Wl,*)
46                 arg=$1
47                 arg=${arg#-Wl}
48                 arg=${arg/,/ }
49                 _ldflags=$_ldflags" ${arg}"
50                 ;;
51         -l|-L)
52                 _libs=$_libs" $1$2"
53                 shift
54                 ;;
55         -l*|-L*)
56                 _libs=$_libs" $1"
57                 ;;
58         -v|--version|-V)
59                 _verarg=$_verarg" $1"
60                 ;;
61         --inv=ld)
62                 _actas=ld
63                 ;;
64         -print-prog-name=ld)
65                 echo $0 --inv=ld
66                 exit 0
67                 ;;
68         *)
69                 _miscargs=$_miscargs" $1"
70                 ;;
71         esac
72         shift
73 done
74
75 run() {
76         if [[ "x$GCCPROXY_DEBUG" != "x" ]]; then
77                 echo --- $*
78         fi
79         $*
80         return $?
81 }
82
83 _ldflags="-lposix -lpsocket "$_ldflags
84 _cflags=$_cflags" -fno-omit-frame-pointer"
85
86 cfgfile=`mktemp`
87 make --no-print-directory -f $BASEDIR/getconfig.mk ARCH=x86 TYPE=$_linktype > $cfgfile
88 . $cfgfile
89 rm $cfgfile
90
91 #echo "_compile = $_compile, _preproc = $_preproc"
92
93 if [[ "x$_verarg" != "x" ]]; then
94         if [[ "x$_actas" == "xld" ]]; then
95                 run $_LD $_miscargs $_verarg
96         else
97                 run $_CC $_miscargs $_verarg
98         fi
99         exit $?
100 fi
101
102 if [[ "x$_actas" == "xld" ]]; then
103         if echo "$_miscargs" | grep '\.o\|\.a'; then
104                 run $_LD $LDFLAGS $_ldflags $_outfile $_miscargs $LIBGCC_PATH $_libs
105         else
106                 run $_LD $_miscargs $_verarg
107         fi
108         exit $?
109 fi
110
111 if [[ $_preproc -eq 1 ]]; then
112         run $_CC -E $CFLAGS $_cflags $_miscargs $_outfile
113 elif [[ $_makedep -eq 1 ]]; then
114         run $_CC -M $CFLAGS $_cflags $_miscargs $_outfile
115 elif [[ $_compile -eq 1 ]]; then
116         run $_CC $CFLAGS $_cflags $_miscargs -c $_outfile
117 elif echo " $_miscargs" | grep '\.c' >/dev/null; then
118         tmpout=`mktemp acess_gccproxy.XXXXXXXXXX.o --tmpdir`
119         run $_CC $CFLAGS $_cflags $_miscargs -c -o $tmpout
120         run $_LD $LDFLAGS $_ldflags $_libs $tmpout $_outfile $_libs $LIBGCC_PATH
121         _rv=$?
122         rm $tmpout
123         exit $_rv
124 else
125         run $_LD $_ldflags $_miscargs $_outfile $LDFLAGS $_libs $LIBGCC_PATH
126 fi
127

UCC git Repository :: git.ucc.asn.au