summaryrefslogtreecommitdiffstats
blob: 86eda96331feef7dbc0f03923af4a7c51035e03f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#!/bin/sh

# cccl 
# Wrapper around MS's cl.exe and link.exe to make them act more like
# Unix cc and ld
#
# Copyright (C) 2000-2003 Geoffrey Wossum (gwossum@acm.org)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#

usage()
{
	cat <<EOF
Usage: cccl [OPTIONS]

cccl is a wrapper around Microsoft's cl.exe and link.exe.  It translates
parameters that Unix cc's and ld's understand to parameters that cl and link
understand.
EOF
	exit $1
}

# Put /usr/bin last in the path, to avoid clashes with MSVC's link
# Ugly workaround, but should work
PATH=`echo $PATH | sed -e "s#/usr/bin:##" | sed -e "s#/bin:##"`:/usr/bin

case $MACHTYPE in
	*-msys)
		slash="//"
		;;
	*)
		slash="/"
		;;
esac
# prog specifies the program that should be run (cl.exe or link.exe)
# We'll assume cl to start out
prog=cl
# opts specifies the command line to pass to the MSVC program
clopt="${slash}nologo"
linkopt="${slash}nologo"
# gotparam is 0 if we didn't ever see a param, in which case we show usage()
gotparam=

# We want exceptions
clopt="$clopt ${slash}EHsc"

### Run through every option and convert it to the proper MS one
while test $# -gt 0; do
	case "$1" in
	-D*) optarg= ;;
	-*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
	*) optarg= ;;
	esac
	gotparam=1

	case "$1" in
	--version)
		cat <<EOF
cccl 0.03

Copyright 2000-2003 Geoffrey Wossum
This is free software; see the source for copying conditions.  There is NO
waranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
EOF
		exit 1;
		;;

	-ansi)
		clopt="$clopt ${slash}Za"
		;;

	-c)
		# -c (compile only) is actually the same, but for clarity...
		clopt="$clopt ${slash}c"
		;;

	-g[0-9] | -g)
		# cl only supports one debugging level
		clopt="$clopt ${slash}Zi ${slash}MDd"
		;;

	-L*)
		path=`echo "$1" | sed 's/-L//'`
		linkopt="$linkopt /LIBPATH:$path"
		;;

	-l*)
		lib=`echo "$1" | sed 's/-l//'`
    if [ $lib != "dnsapi" -a $lib != "ws2_32" -a $lib != "wsock32" ]; then
      lib="lib$lib.lib"
    else
      lib="$lib.lib"
    fi
		
		clopt="$clopt $lib"
		linkopt="$linkopt $lib"
		;;

	-m386)
		clopt="$clopt ${slash}G3"
		;;

	-m486)
		clopt="$clopt ${slash}G4"
		;;

	-mpentium)
		clopt="$clopt ${slash}G5"
		;;

	-mpentiumpro)
		clopt="$clopt ${slash}G6"
		;;

	-o)
		# specifying output file, is it an object or an executable
		shift
		case "$1" in
		*.o | *.obj)
			clopt="$clopt ${slash}Fo$1"
		;;
		*)
			clopt="$clopt ${slash}Fe$1";
			linkopt="$linkopt ${slash}out:$1"
		;;
		esac;;

	-pedantic)
		#ignore pedantic
		;;

	-W*)
		#ignore warnings
		;;

	-isystem)
		shift
		clopt="$clopt -I$1"
		;;

	-MT)
		exit 0
		;;

	-mno-cygwin)
		;;

	*.cc | *.cxx | *.C)
		# C++ source file with non .cpp extension, make sure cl understand 
		# that it is C++
		clopt="$clopt ${slash}Tp$1"
		;;

	*.o | *.obj | *.a | *.lib)
		# Object files/libraries seen, this command will require link
		# Switch the prog to link
		linkopt="$linkopt $1"
		prog="link"
		;;

	*)
		clopt="$clopt $1"
		linkopt="$linkopt $1"
		if test x$optarg != x ; then
			clopt="$clopt=$optarg"
			linkopt="$linkopt=$optarg"
		fi
		;;

	esac
	shift
done

if test x$gotparam = x ; then
	usage
	exit 1
fi

# choose which opts we built up based on which program will actually run
if test x$prog = xcl ; then
	opts=$clopt
else
	opts=$linkopt
fi

#echo "$prog $opts"
exec $prog $opts
exit 0