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