Kernel/VTerm - "Fix" wrapping issue in VTerm (why was old behavior there?)
[tpg/acess2.git] / Tools / GCCProxy / gccproxy.sh
1 #!/bin/bash
2
3 toolname=${0##*-}
4
5 # Get invocation path (which could be a symlink in $PATH)
6 fullpath=`which "$0"`
7 if [[ !$? ]]; then
8         fullpath="$0"
9 fi
10
11 # Resolve symlink
12 fullpath=`readlink -f "$fullpath"`
13
14 # Get base directory
15 BASEDIR=`dirname "$fullpath"`
16
17 _miscargs=""
18 _compile=0
19 _linktype=Applications
20
21 echo [GCCProxy] $toolname $* >&2
22
23
24
25 while [[ $# -gt 0 ]]; do
26         case "$1" in
27         -E)
28                 _preproc=1
29                 ;;
30         -M)
31                 _makedep=1
32                 ;;
33         -c)
34                 _compile=1
35                 ;;
36         -o)
37                 shift
38                 _outfile="-o $1"
39                 ;;
40         -shared)
41                 _ldflags=$_ldflags" -shared -lc -lgcc"
42                 _linktype=Libraries
43                 ;;
44         -I|-D|-O)
45                 _cflags=$_cflags" $1 $2"
46                 shift
47                 ;;
48         -I*|-D*|-O*)
49                 _cflags=$_cflags" $1"
50                 ;;
51         -Wl,*)
52                 arg=$1
53                 arg=${arg#-Wl}
54                 arg=${arg/,/ }
55                 _ldflags=$_ldflags" ${arg}"
56                 ;;
57         -Wall|-Werror|-Wextra)\
58                 _cflags=$_cflags" $1"
59                 ;;
60         -l|-L)
61                 _libs=$_libs" $1$2"
62                 shift
63                 ;;
64         -l*|-L*)
65                 _libs=$_libs" $1"
66                 ;;
67         -v|--version|-V)
68                 _verarg=$_verarg" $1"
69                 ;;
70         --inv=ld)
71                 _actas=ld
72                 ;;
73         -pthread)
74                 _ldflags=$_ldflags" -lpthread"
75                 ;;
76         -print-prog-name=ld)
77                 echo $0 --inv=ld
78                 exit 0
79                 ;;
80         -print-search-dirs)
81                 _compile=1
82                 _cflags=$_cflags" $1"
83                 ;;
84         -print-multi-os-directory)
85                 _compile=1
86                 _cflags=$_cflags" $1"
87                 ;;
88         -dumpspecs)
89                 _compile=1
90                 _miscargs=$_miscargs" $1"
91                 ;;
92         -dumpversion)
93                 _compile=1
94                 _miscargs=$_miscargs" $1"
95                 ;;
96         *)
97                 _miscargs=$_miscargs" $1"
98                 ;;
99         esac
100         shift
101 done
102
103 run() {
104         if [[ "x$GCCPROXY_DEBUG" != "x" ]]; then
105                 echo --- $*
106         fi
107         $*
108         return $?
109 }
110
111 _ldflags="-lposix -lpsocket "$_ldflags
112 _cflags=$_cflags" -fno-omit-frame-pointer"
113
114 cfgfile=`mktemp`
115 make --no-print-directory -f $BASEDIR/getconfig.mk ARCH=x86 TYPE=$_linktype > $cfgfile
116 . $cfgfile
117 rm $cfgfile
118
119 #echo "_compile = $_compile, _preproc = $_preproc"
120
121 if [[ "$toolname" == "g++" ]]; then
122         COMPILER=$_CXX
123         _libs="-lc++ $_libs"
124 elif [[ "$toolname" == "gcc" ]]; then
125         COMPILER=$_CC
126 else
127         echo "ERROR: Unknown tool name $toolname" >&2
128         exit 1
129 fi
130
131 if [[ "x$_verarg" != "x" ]]; then
132         if [[ "x$_actas" == "xld" ]]; then
133                 run $_LD $_miscargs $_verarg
134         else
135                 run $_CC $_miscargs $_verarg
136         fi
137         exit $?
138 fi
139
140 if [[ "x$_actas" == "xld" ]]; then
141         if echo "$_miscargs" | grep '\.o\|\.a'; then
142                 run $_LD $LDFLAGS $_ldflags $_outfile $_miscargs $LIBGCC_PATH $_libs
143         else
144                 run $_LD $_miscargs $_verarg
145         fi
146         exit $?
147 fi
148
149 if [[ $_preproc -eq 1 ]]; then
150         run $_CC -E $CFLAGS $_cflags $_miscargs $_outfile
151 elif [[ $_makedep -eq 1 ]]; then
152         run $_CC -M $CFLAGS $_cflags $_miscargs $_outfile
153 elif [[ $_compile -eq 1 ]]; then
154         run $_CC $CFLAGS $_cflags $_miscargs -c $_outfile
155 elif echo " $_miscargs" | grep '\.c' >/dev/null; then
156         tmpout=`mktemp acess_gccproxy.XXXXXXXXXX.o --tmpdir`
157         run $_CC $CFLAGS $_cflags $_miscargs -c -o $tmpout
158         run $_LD $LDFLAGS $_ldflags $CRTBEGIN $_libs $tmpout $_outfile $_libs $LIBGCC_PATH $CRTEND
159         _rv=$?
160         rm $tmpout
161         exit $_rv
162 else
163         run $_LD $_ldflags $CRTBEGIN $_miscargs $_outfile $LDFLAGS $_libs $LIBGCC_PATH $CRTEND
164 fi
165

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