Tools/GCCProxy - -dumpversion/-dumpspecs used by netsurf
[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         -l|-L)
54                 _libs=$_libs" $1$2"
55                 shift
56                 ;;
57         -l*|-L*)
58                 _libs=$_libs" $1"
59                 ;;
60         -v|--version|-V)
61                 _verarg=$_verarg" $1"
62                 ;;
63         --inv=ld)
64                 _actas=ld
65                 ;;
66         -print-prog-name=ld)
67                 echo $0 --inv=ld
68                 exit 0
69                 ;;
70         -dumpspecs)
71                 _compile=1
72                 _miscargs=$_miscargs" $1"
73                 ;;
74         -dumpversion)
75                 _compile=1
76                 _miscargs=$_miscargs" $1"
77                 ;;
78         *)
79                 _miscargs=$_miscargs" $1"
80                 ;;
81         esac
82         shift
83 done
84
85 run() {
86         if [[ "x$GCCPROXY_DEBUG" != "x" ]]; then
87                 echo --- $*
88         fi
89         $*
90         return $?
91 }
92
93 _ldflags="-lposix -lpsocket "$_ldflags
94 _cflags=$_cflags" -fno-omit-frame-pointer"
95
96 cfgfile=`mktemp`
97 make --no-print-directory -f $BASEDIR/getconfig.mk ARCH=x86 TYPE=$_linktype > $cfgfile
98 . $cfgfile
99 rm $cfgfile
100
101 #echo "_compile = $_compile, _preproc = $_preproc"
102
103 if [[ "x$_verarg" != "x" ]]; then
104         if [[ "x$_actas" == "xld" ]]; then
105                 run $_LD $_miscargs $_verarg
106         else
107                 run $_CC $_miscargs $_verarg
108         fi
109         exit $?
110 fi
111
112 if [[ "x$_actas" == "xld" ]]; then
113         if echo "$_miscargs" | grep '\.o\|\.a'; then
114                 run $_LD $LDFLAGS $_ldflags $_outfile $_miscargs $LIBGCC_PATH $_libs
115         else
116                 run $_LD $_miscargs $_verarg
117         fi
118         exit $?
119 fi
120
121 if [[ $_preproc -eq 1 ]]; then
122         run $_CC -E $CFLAGS $_cflags $_miscargs $_outfile
123 elif [[ $_makedep -eq 1 ]]; then
124         run $_CC -M $CFLAGS $_cflags $_miscargs $_outfile
125 elif [[ $_compile -eq 1 ]]; then
126         run $_CC $CFLAGS $_cflags $_miscargs -c $_outfile
127 elif echo " $_miscargs" | grep '\.c' >/dev/null; then
128         tmpout=`mktemp acess_gccproxy.XXXXXXXXXX.o --tmpdir`
129         run $_CC $CFLAGS $_cflags $_miscargs -c -o $tmpout
130         run $_LD $LDFLAGS $_ldflags $_libs $tmpout $_outfile $_libs $LIBGCC_PATH
131         _rv=$?
132         rm $tmpout
133         exit $_rv
134 else
135         run $_LD $_ldflags $_miscargs $_outfile $LDFLAGS $_libs $LIBGCC_PATH
136 fi
137

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