7914b4061f39c85dbb20f7811aadedf0119d843c
[sliver-openvswitch.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"
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     -L*)
93         path=`echo "$1" | sed 's/-L//'`
94         linkopt="$linkopt /LIBPATH:$path"
95         ;;
96
97     -l*)
98         lib=`echo "$1" | sed 's/-l//'`
99     if [ $lib != "dnsapi" -a $lib != "ws2_32" -a $lib != "wsock32" ]; then
100       lib="lib$lib.lib"
101     else
102       lib="$lib.lib"
103     fi
104
105         clopt="$clopt $lib"
106         linkopt="$linkopt $lib"
107         ;;
108
109     -m386)
110         clopt="$clopt ${slash}G3"
111         ;;
112
113     -m486)
114         clopt="$clopt ${slash}G4"
115         ;;
116
117     -mpentium)
118         clopt="$clopt ${slash}G5"
119         ;;
120
121     -mpentiumpro)
122         clopt="$clopt ${slash}G6"
123         ;;
124
125     -o)
126         # specifying output file, is it an object or an executable
127         shift
128         case "$1" in
129         *.o | *.obj)
130             clopt="$clopt ${slash}Fo$1"
131         ;;
132         *)
133             clopt="$clopt ${slash}Fe$1";
134             linkopt="$linkopt ${slash}out:$1"
135         ;;
136         esac;;
137
138     -pedantic)
139         #ignore pedantic
140         ;;
141
142     -W*)
143         #ignore warnings
144         ;;
145
146     -isystem)
147         shift
148         clopt="$clopt -I$1"
149         ;;
150
151     -MT)
152         exit 0
153         ;;
154
155     -mno-cygwin)
156         ;;
157
158     *.cc | *.cxx | *.C)
159         # C++ source file with non .cpp extension, make sure cl understand
160         # that it is C++
161         clopt="$clopt ${slash}Tp$1"
162         ;;
163
164     *.o | *.obj | *.a | *.lib)
165         # Object files/libraries seen, this command will require link
166         # Switch the prog to link
167         linkopt="$linkopt $1"
168         prog="link"
169         ;;
170
171     *)
172         clopt="$clopt $1"
173         linkopt="$linkopt $1"
174         if test x$optarg != x ; then
175             clopt="$clopt=$optarg"
176             linkopt="$linkopt=$optarg"
177         fi
178         ;;
179
180     esac
181     shift
182 done
183
184 if test x$gotparam = x ; then
185     usage
186     exit 1
187 fi
188
189 # choose which opts we built up based on which program will actually run
190 if test x$prog = xcl ; then
191     opts=$clopt
192 else
193     opts=$linkopt
194 fi
195
196 echo "$prog $opts"
197 exec $prog $opts
198 exit 0