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