cccl: A wrapper that calls visual c++ compiler.
[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 # Put /usr/bin last in the path, to avoid clashes with MSVC's link
37 # Ugly workaround, but should work
38 PATH=`echo $PATH | sed -e "s#/usr/bin:##" | sed -e "s#/bin:##"`:/usr/bin
39
40 case $MACHTYPE in
41     *-msys)
42         slash="//"
43         ;;
44     *)
45         slash="/"
46         ;;
47 esac
48 # prog specifies the program that should be run (cl.exe or link.exe)
49 # We'll assume cl to start out
50 prog=cl
51 # opts specifies the command line to pass to the MSVC program
52 clopt="${slash}nologo"
53 linkopt="${slash}nologo"
54 # gotparam is 0 if we didn't ever see a param, in which case we show usage()
55 gotparam=
56
57 # We want exceptions
58 clopt="$clopt ${slash}EHsc"
59
60 ### Run through every option and convert it to the proper MS one
61 while test $# -gt 0; do
62     case "$1" in
63     -D*) optarg= ;;
64     -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
65     *) optarg= ;;
66     esac
67     gotparam=1
68
69     case "$1" in
70     --version)
71         cat <<EOF
72 cccl 0.03
73
74 Copyright 2000-2003 Geoffrey Wossum
75 This is free software; see the source for copying conditions.  There is NO
76 waranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
77 EOF
78         exit 1;
79         ;;
80
81     -ansi)
82         clopt="$clopt ${slash}Za"
83         ;;
84
85     -c)
86         # -c (compile only) is actually the same, but for clarity...
87         clopt="$clopt ${slash}c"
88         ;;
89
90     -g[0-9] | -g)
91         # cl only supports one debugging level
92         clopt="$clopt ${slash}Zi"
93         ;;
94
95     -L*)
96         path=`echo "$1" | sed 's/-L//'`
97         linkopt="$linkopt /LIBPATH:$path"
98         ;;
99
100     -l*)
101         lib=`echo "$1" | sed 's/-l//'`
102     if [ $lib != "dnsapi" -a $lib != "ws2_32" -a $lib != "wsock32" ]; then
103       lib="lib$lib.lib"
104     else
105       lib="$lib.lib"
106     fi
107
108         clopt="$clopt $lib"
109         linkopt="$linkopt $lib"
110         ;;
111
112     -m386)
113         clopt="$clopt ${slash}G3"
114         ;;
115
116     -m486)
117         clopt="$clopt ${slash}G4"
118         ;;
119
120     -mpentium)
121         clopt="$clopt ${slash}G5"
122         ;;
123
124     -mpentiumpro)
125         clopt="$clopt ${slash}G6"
126         ;;
127
128     -o)
129         # specifying output file, is it an object or an executable
130         shift
131         case "$1" in
132         *.o | *.obj)
133             clopt="$clopt ${slash}Fo$1"
134         ;;
135         *)
136             clopt="$clopt ${slash}Fe$1";
137             linkopt="$linkopt ${slash}out:$1"
138         ;;
139         esac;;
140
141     -pedantic)
142         #ignore pedantic
143         ;;
144
145     -W*)
146         #ignore warnings
147         ;;
148
149     -isystem)
150         shift
151         clopt="$clopt -I$1"
152         ;;
153
154     -MT)
155         exit 0
156         ;;
157
158     -mno-cygwin)
159         ;;
160
161     *.cc | *.cxx | *.C)
162         # C++ source file with non .cpp extension, make sure cl understand
163         # that it is C++
164         clopt="$clopt ${slash}Tp$1"
165         ;;
166
167     *.o | *.obj | *.a | *.lib)
168         # Object files/libraries seen, this command will require link
169         # Switch the prog to link
170         linkopt="$linkopt $1"
171         prog="link"
172         ;;
173
174     *)
175         clopt="$clopt $1"
176         linkopt="$linkopt $1"
177         if test x$optarg != x ; then
178             clopt="$clopt=$optarg"
179             linkopt="$linkopt=$optarg"
180         fi
181         ;;
182
183     esac
184     shift
185 done
186
187 if test x$gotparam = x ; then
188     usage
189     exit 1
190 fi
191
192 # choose which opts we built up based on which program will actually run
193 if test x$prog = xcl ; then
194     opts=$clopt
195 else
196     opts=$linkopt
197 fi
198
199 #echo "$prog $opts"
200 exec $prog $opts
201 exit 0