netdev-dpdk: fix mbuf leaks
[cascardo/ovs.git] / build-aux / cccl
1 #!/bin/sh
2
3 # cccl
4 # Wrapper around MS's cl.exe and link.exe to make them act more like
5 # Unix cc and ld
6 #
7 # Copyright (C) 2000-2003 Geoffrey Wossum (gwossum@acm.org)
8 #
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.    See the GNU
17 # General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #
23
24 usage()
25 {
26     cat <<EOF
27 Usage: cccl [OPTIONS]
28
29 cccl is a wrapper around Microsoft's cl.exe and link.exe.  It translates
30 parameters that Unix cc's and ld's understand to parameters that cl and link
31 understand.
32 EOF
33     exit $1
34 }
35
36 case $MACHTYPE in
37     *-msys)
38         slash="-"
39         ;;
40     *)
41         slash="/"
42         ;;
43 esac
44 # prog specifies the program that should be run (cl.exe or link.exe)
45 # We'll assume cl to start out
46 prog=cl
47 # opts specifies the command line to pass to the MSVC program
48 clopt="${slash}nologo ${slash}FS"
49 linkopt="${slash}nologo"
50 # gotparam is 0 if we didn't ever see a param, in which case we show usage()
51 gotparam=
52
53 # We want exceptions
54 clopt="$clopt ${slash}EHsc"
55
56 ### Run through every option and convert it to the proper MS one
57 while test $# -gt 0; do
58     case "$1" in
59     -D*) optarg= ;;
60     -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
61     *) optarg= ;;
62     esac
63     gotparam=1
64
65     case "$1" in
66     --version)
67         cat <<EOF
68 cccl 0.03
69
70 Copyright 2000-2003 Geoffrey Wossum
71 This is free software; see the source for copying conditions.  There is NO
72 waranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
73 EOF
74         exit 1;
75         ;;
76
77     -ansi)
78         clopt="$clopt ${slash}Za"
79         ;;
80
81     -c)
82         # -c (compile only) is actually the same, but for clarity...
83         clopt="$clopt ${slash}c"
84         ;;
85
86     -g[0-9] | -g)
87         # cl only supports one debugging level
88         clopt="$clopt ${slash}Zi"
89         linkopt="$linkopt ${slash}DEBUG"
90         ;;
91
92     -O0)
93         clopt="$clopt ${slash}Od ${slash}D_DEBUG"
94         ;;
95
96     -O2)
97         clopt="$clopt ${slash}O2"
98         ;;
99
100     -L*)
101         path=`echo "$1" | sed 's/-L//'`
102         linkopt="$linkopt ${slash}LIBPATH:$path"
103         cl_linkopt="${slash}link ${slash}LIBPATH:\"$path\""
104         ;;
105
106     -l*)
107         lib=`echo "$1" | sed 's/-l//'`
108         lib="$lib.lib"
109
110         clopt="$clopt $lib"
111         linkopt="$linkopt $lib"
112         ;;
113
114     -m386)
115         clopt="$clopt ${slash}G3"
116         ;;
117
118     -m486)
119         clopt="$clopt ${slash}G4"
120         ;;
121
122     -mpentium)
123         clopt="$clopt ${slash}G5"
124         ;;
125
126     -mpentiumpro)
127         clopt="$clopt ${slash}G6"
128         ;;
129
130     -o)
131         # specifying output file, is it an object or an executable
132         shift
133         case "$1" in
134         *.o | *.obj)
135             clopt="$clopt ${slash}Fo$1"
136         ;;
137         *)
138             clopt="$clopt ${slash}Fe$1";
139             linkopt="$linkopt ${slash}out:$1"
140         ;;
141         esac;;
142
143     -pedantic)
144         #ignore pedantic
145         ;;
146
147     -W*)
148         #ignore warnings
149         ;;
150
151     -Q*)
152         #ignore link warnings
153         ;;
154
155     -fno-strict-aliasing*)
156         #ignore aliasing
157         ;;
158
159     -isystem)
160         shift
161         clopt="$clopt -I$1"
162         ;;
163
164     -MT)
165         exit 0
166         ;;
167
168     -mno-cygwin)
169         ;;
170
171     *.cc | *.cxx | *.C)
172         # C++ source file with non .cpp extension, make sure cl understand
173         # that it is C++
174         clopt="$clopt ${slash}Tp$1"
175         ;;
176
177     *.o | *.obj | *.a | *.lib)
178         # Object files/libraries seen, this command will require link
179         # Switch the prog to link
180         linkopt="$linkopt $1"
181         prog="link"
182         ;;
183
184     *)
185         clopt="$clopt $1"
186         linkopt="$linkopt $1"
187         if test x$optarg != x ; then
188             clopt="$clopt=$optarg"
189             linkopt="$linkopt=$optarg"
190         fi
191         ;;
192
193     esac
194     shift
195 done
196
197 if test x$gotparam = x ; then
198     usage
199     exit 1
200 fi
201
202 # choose which opts we built up based on which program will actually run
203 if test x$prog = xcl ; then
204     opts="$clopt $cl_linkopt"
205 else
206     opts=$linkopt
207 fi
208
209 if test x$V = x1 ; then
210     echo "$prog $opts"
211 fi
212 exec $prog $opts
213 exit 0