Tools/GCCProxy - add -print-multi-os-directory handling
[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         -print-multi-os-directory)
77                 _compile=1
78                 _cflags=$_cflags" $1"
79                 ;;
80         -dumpspecs)
81                 _compile=1
82                 _miscargs=$_miscargs" $1"
83                 ;;
84         -dumpversion)
85                 _compile=1
86                 _miscargs=$_miscargs" $1"
87                 ;;
88         *)
89                 _miscargs=$_miscargs" $1"
90                 ;;
91         esac
92         shift
93 done
94
95 run() {
96         if [[ "x$GCCPROXY_DEBUG" != "x" ]]; then
97                 echo --- $*
98         fi
99         $*
100         return $?
101 }
102
103 _ldflags="-lposix -lpsocket "$_ldflags
104 _cflags=$_cflags" -fno-omit-frame-pointer"
105
106 cfgfile=`mktemp`
107 make --no-print-directory -f $BASEDIR/getconfig.mk ARCH=x86 TYPE=$_linktype > $cfgfile
108 . $cfgfile
109 rm $cfgfile
110
111 #echo "_compile = $_compile, _preproc = $_preproc"
112
113 if [[ "x$_verarg" != "x" ]]; then
114         if [[ "x$_actas" == "xld" ]]; then
115                 run $_LD $_miscargs $_verarg
116         else
117                 run $_CC $_miscargs $_verarg
118         fi
119         exit $?
120 fi
121
122 if [[ "x$_actas" == "xld" ]]; then
123         if echo "$_miscargs" | grep '\.o\|\.a'; then
124                 run $_LD $LDFLAGS $_ldflags $_outfile $_miscargs $LIBGCC_PATH $_libs
125         else
126                 run $_LD $_miscargs $_verarg
127         fi
128         exit $?
129 fi
130
131 if [[ $_preproc -eq 1 ]]; then
132         run $_CC -E $CFLAGS $_cflags $_miscargs $_outfile
133 elif [[ $_makedep -eq 1 ]]; then
134         run $_CC -M $CFLAGS $_cflags $_miscargs $_outfile
135 elif [[ $_compile -eq 1 ]]; then
136         run $_CC $CFLAGS $_cflags $_miscargs -c $_outfile
137 elif echo " $_miscargs" | grep '\.c' >/dev/null; then
138         tmpout=`mktemp acess_gccproxy.XXXXXXXXXX.o --tmpdir`
139         run $_CC $CFLAGS $_cflags $_miscargs -c -o $tmpout
140         run $_LD $LDFLAGS $_ldflags $_libs $tmpout $_outfile $_libs $LIBGCC_PATH
141         _rv=$?
142         rm $tmpout
143         exit $_rv
144 else
145         run $_LD $_ldflags $_miscargs $_outfile $LDFLAGS $_libs $LIBGCC_PATH
146 fi
147

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