forked from radareorg/radare2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cccl
executable file
·325 lines (272 loc) · 6.89 KB
/
cccl
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#!/bin/sh
# cccl
# Wrapper around MS's cl.exe to make it act more like Unix cc
#
# Copyright (C) 2000-2015 by contributors listed in the AUTHORS file.
#
# 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 3 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, see <http://www.gnu.org/licenses/>.
# Modified for radare2 purposes
usage()
{
cat <<EOF
Usage: cccl [--cccl-link] [--cccl-muffle] [--cccl-verbose] [--help] [--version]
[OPTIONS]
cccl is a wrapper around Microsoft's cl.exe compiler. It translates parameters
given by [OPTIONS] that Unix cc understands into parameters that cl understands.
EOF
}
case ${MACHTYPE} in
*-msys)
slash="-"
;;
*)
slash="/"
;;
esac
# prog specifies the program that should be run cl.exe
prog=cl
# opts specifies the command line to pass to the MSVC program
clopt="${slash}nologo"
linkopt="${slash}link"
debug=
# gotparam is 0 if we didn't ever see a param, in which case we show usage()
gotparam=
muffle=
verbose=
shared_index=-1
processargs()
{
### 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
--help)
usage
exit 0
;;
--cccl-link)
# One single option for the linker
shift
case "$1" in
/*)
val=$(echo "$1" | cut -c2-)
linkopt="${linkopt} ${slash}${val}"
;;
*)
linkopt="${linkopt} $1"
;;
esac
;;
--cccl-muffle)
# Remove the unnecessary junk that the compiler outputs to stdout
muffle=1
;;
--cccl-verbose)
verbose=1
;;
--version)
cat <<EOF
cccl 1.0
EOF
exit 0;
;;
-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"
debug=1
;;
-O0)
clopt="${clopt},${slash}Ot"
;;
-O2)
clopt="${clopt},${slash}O2"
;;
-I*)
path=$(echo "$1" | sed 's,-I,,')
path=$(cygpath -aw "$path")
clopt="${clopt},${slash}I${path}"
;;
-L*)
path=$(echo "$1" | sed 's,-L,,')
path=$(cygpath -aw "$path")
linkopt="${linkopt},${slash}LIBPATH:$path"
;;
-l*)
lib=$(echo "$1" | sed 's,-l,,')
lib="$lib.lib"
clopt="${clopt},${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
path=$(cygpath -w "$1")
case "${path}" in
*.o | *.obj)
clopt="${clopt},${slash}Fo${path}"
;;
*.exe | *.dll | *.pyd)
clopt="${clopt},${slash}Fe${path}"
;;
*)
echo "Warning: Could not understand -o directive. Producing .exe by default."
clopt="${clopt},${slash}Fe${path}.exe"
;;
esac
;;
-pedantic)
#ignore pedantic
;;
-W*)
#ignore warnings
;;
-fno-strict-aliasing*)
#ignore aliasing
;;
-isystem)
shift
clopt="${clopt},${slash}I$1"
;;
-MT)
exit 0
;;
-mno-cygwin)
;;
-shared)
shared_index=${#clopt[@]}
clopt="${clopt},${slash}LD"
;;
-std=*)
#ignore std
;;
-MMD)
#ignore MMD
;;
-fPIC)
#ignore fPIC
;;
-*)
# Remaining '-' options are passed to the compiler
val=$(echo "$1" | cut -c2-)
if test x$optarg != x ; then
clopt="${clopt},${slash}${val}=$optarg"
else
clopt="${clopt},${slash}${val}"
fi
;;
*.cc | *.cxx | *.C)
# C++ source file with non .cpp extension, make sure cl understand
# that it is C++
clopt="${clopt},${slash}Tp$1"
;;
*.c)
# Translate it into windows path in case it's a linux absolute path
# Because /cygdrive/d/wtf would be read as an option
path=$(cygpath -w "$1")
clopt="${clopt},${path}"
;;
*.a)
# Translate it into .lib and make sure it's a windows path cf above
path=$(cygpath -w "$1" | sed 's,\.a,.lib,')
clopt="${clopt},${path}"
;;
/link)
# Same behaviour as cl - all options after /link are linker options
shift
while test $# -gt 0; do
case "$1" in
/*)
val=$(echo "$1" | cut -c2-)
linkopt="${linkopt},${slash}${val}"
;;
*)
linkopt="${linkopt},$1"
;;
esac
shift
done
;;
/*/*)
# If there are multiple slashes, then it's an absolute path
path=$(cygpath -aw "$1")
clopt="${clopt},${path}"
;;
/*)
# All '/' options (except the one above) are assumed to be options
val=$(echo "$1" | cut -c2-)
clopt="${clopt},${slash}${val}"
;;
*)
clopt="${clopt},$1"
;;
esac
shift
done
}
# Whitespace in paths is dealt with by setting IFS and using bash arrays
# Except additional arguments in CCCL_OPTIONS need to be space separated
processargs ${CCCL_OPTIONS}
IFS=""
processargs $@
if test "$shared_index" -ge 0 -a -n "$debug"; then
clopt[$shared_index]="${slash}LDd"
fi
if test x$gotparam = x ; then
usage
exit 1
fi
if test "x$V" = "x1" ; then
verbose=1
fi
IFS=","
if test -n "$verbose" ; then
printf "%s" "$prog"
for opt in ${clopt} ; do
printf "%s" " \"$opt\""
done
for opt in ${linkopt} ; do
printf "%s" " \"$opt\""
done
echo ""
fi
if test -z "$muffle" ; then
exec $prog $clopt $linkopt
else
# tr needed below for $ in regex to work (simple alternative to dos2unix)
exec $prog $clopt $linkopt | tr -d '\r' | grep -v -e "\.cpp$" -e "\.cxx$" -e "\.cc$" -e "\.C$" -e "\.c$" -e "^ Creating library" -e "^Generating Code"
exit $?
fi