1b0dfbe4f859b57ea39b1a0f90792a3992b48fae
[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 echo [GCCProxy] $* >&2
20
21 while [[ $# -gt 0 ]]; do
22         case "$1" in
23         -E)
24                 _preproc=1
25                 ;;
26         -M)
27                 _makedep=1
28                 ;;
29         -c)
30                 _compile=1
31                 ;;
32         -o)
33                 shift
34                 _outfile="-o $1"
35                 ;;
36         -shared)
37                 _ldflags=$_ldflags" -shared -lc -lgcc"
38                 _linktype=Libraries
39                 ;;
40         -I|-D|-O)
41                 _cflags=$_cflags" $1 $2"
42                 shift
43                 ;;
44         -I*|-D*|-O*)
45                 _cflags=$_cflags" $1"
46                 ;;
47         -Wl,*)
48                 arg=$1
49                 arg=${arg#-Wl}
50                 arg=${arg/,/ }
51                 _ldflags=$_ldflags" ${arg}"
52                 ;;
53         -Wall|-Werror|-Wextra)\
54                 _cflags=$_cflags" $1"
55                 ;;
56         -l|-L)
57                 _libs=$_libs" $1$2"
58                 shift
59                 ;;
60         -l*|-L*)
61                 _libs=$_libs" $1"
62                 ;;
63         -v|--version|-V)
64                 _verarg=$_verarg" $1"
65                 ;;
66         --inv=ld)
67                 _actas=ld
68                 ;;
69         -pthread)
70                 _ldflags=$_ldflags" -lpthread"
71                 ;;
72         -print-prog-name=ld)
73                 echo $0 --inv=ld
74                 exit 0
75                 ;;
76         -dumpspecs)
77                 _compile=1
78                 _miscargs=$_miscargs" $1"
79                 ;;
80         -dumpversion)
81                 _compile=1
82                 _miscargs=$_miscargs" $1"
83                 ;;
84         *)
85                 _miscargs=$_miscargs" $1"
86                 ;;
87         esac
88         shift
89 done
90
91 run() {
92         if [[ "x$GCCPROXY_DEBUG" != "x" ]]; then
93                 echo --- $*
94         fi
95         $*
96         return $?
97 }
98
99 _ldflags="-lposix -lpsocket "$_ldflags
100 _cflags=$_cflags" -fno-omit-frame-pointer"
101
102 cfgfile=`mktemp`
103 make --no-print-directory -f $BASEDIR/getconfig.mk ARCH=x86 TYPE=$_linktype > $cfgfile
104 . $cfgfile
105 rm $cfgfile
106
107 #echo "_compile = $_compile, _preproc = $_preproc"
108
109 if [[ "x$_verarg" != "x" ]]; then
110         if [[ "x$_actas" == "xld" ]]; then
111                 run $_LD $_miscargs $_verarg
112         else
113                 run $_CC $_miscargs $_verarg
114         fi
115         exit $?
116 fi
117
118 if [[ "x$_actas" == "xld" ]]; then
119         if echo "$_miscargs" | grep '\.o\|\.a'; then
120                 run $_LD $LDFLAGS $_ldflags $_outfile $_miscargs $LIBGCC_PATH $_libs
121         else
122                 run $_LD $_miscargs $_verarg
123         fi
124         exit $?
125 fi
126
127 if [[ $_preproc -eq 1 ]]; then
128         run $_CC -E $CFLAGS $_cflags $_miscargs $_outfile
129 elif [[ $_makedep -eq 1 ]]; then
130         run $_CC -M $CFLAGS $_cflags $_miscargs $_outfile
131 elif [[ $_compile -eq 1 ]]; then
132         run $_CC $CFLAGS $_cflags $_miscargs -c $_outfile
133 elif echo " $_miscargs" | grep '\.c' >/dev/null; then
134         tmpout=`mktemp acess_gccproxy.XXXXXXXXXX.o --tmpdir`
135         run $_CC $CFLAGS $_cflags $_miscargs -c -o $tmpout
136         run $_LD $LDFLAGS $_ldflags $_libs $tmpout $_outfile $_libs $LIBGCC_PATH
137         _rv=$?
138         rm $tmpout
139         exit $_rv
140 else
141         run $_LD $_ldflags $_miscargs $_outfile $LDFLAGS $_libs $LIBGCC_PATH
142 fi
143

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