2
# Icky cl wrapper that does it's best to behave like a Unixish cc.
3
# Made to work for Erlang builds and to make configure happy, not really
6
# Save the command line for debug outputs
10
COMMON_CFLAGS="-nologo -D__WIN32__ -DWIN32 -DWINDOWS -D_WIN32 -DNT"
13
# The stdout and stderr for the compiler
14
MSG_FILE=/tmp/cl.exe.$$.1
15
ERR_FILE=/tmp/cl.exe.$$.2
17
# "Booleans" determined during "command line parsing"
18
# If the stdlib option is explicitly passed to this program
20
# If we're preprocession (only) i.e. -E
22
# If this is supposed to be a debug build
24
# If this is supposed to be an optimized build (there can only be one...)
26
# If we're linking or only compiling
29
# This data is accumulated during command line "parsing"
30
# The stdlibrary option, default multithreaded dynamic
32
# Flags for debug compilation
34
# Flags for optimization
36
# The specified output filename (if any), may be either object or exe.
38
# Unspe3cified command line options for the compiler
40
# All the c source files, in unix style
42
# All the options to pass to the linker, kept in Unix style
46
# Loop through the parameters and set the above variables accordingly
47
# Also convert some cygwin filenames to "mixed style" dito (understood by the
48
# compiler very well), except for anything passed to the linker, that script
49
# handles those and the sources, which are also kept unixish for now
51
while test -n "$1" ; do
61
LINKING=false;; # Obviously...
64
# Optimization hardcoded, needs to disable debugging too
68
if [ $MD_FORCED = false ]; then
71
OPTIMIZED_BUILD=true;;
73
if [ $OPTIMIZED_BUILD = false ];then
74
# Hardcoded windows debug flags
76
if [ $MD_FORCED = false ]; then
79
LINKCMD="$LINKCMD -g";
82
# Allow forcing of stdlib
105
y=`echo $x | sed 's,^-[Io]\(.*\),\1,g'`;
108
y=`echo $x | sed 's,^-[Io]\(/.*\),\1,g'`;
109
z=`echo $x | sed 's,^-\([Io]\)\(/.*\),\1,g'`;
110
MPATH=`cygpath -m $y`;
111
CMD="$CMD -$z\"$MPATH\"";;
113
y=`echo $x | sed 's,",\\\",g'`;
116
y=`echo $x | sed 's,",\\\",g'`;
119
y=`echo $x | sed 's,^-l\(.*\),\1,g'`;
120
LINKCMD="$LINKCMD $x";;
122
SOURCES="$SOURCES $x";;
124
SOURCES="$SOURCES $x";;
126
LINKCMD="$LINKCMD $x";;
128
LINKCMD="$LINKCMD $x";;
130
# Try to quote uninterpreted options
131
y=`echo $x | sed 's,",\\\",g'`;
132
LINKCMD="$LINKCMD $y";;
137
#Return code from compiler, linker.sh and finally this script...
140
# Accumulated object names
143
# A temporary object file location
144
TMPOBJDIR=/tmp/tmpobj$$
148
for x in $SOURCES; do
149
# Compile each source
150
if [ $LINKING = false ]; then
151
# We should have an output defined, which is a directory
155
# Simple output, SOURCES should be one single
156
n=`echo $SOURCES | wc -w`;
157
if [ $n -gt 1 ]; then
158
echo "cc.sh:Error, multiple sources, one object output.";
161
output_filename=`cygpath -m $OUTFILE`;
164
# Relative path needs no translation
165
n=`echo $SOURCES | wc -w`
166
if [ $n -gt 1 ]; then
167
echo "cc.sh:Error, multiple sources, one object output."
170
output_filename=$OUTFILE
174
o=`echo $x | sed 's,.*/,,' | sed 's,\.c$,.o,'`
175
output_filename=`cygpath -m $OUTFILE`
176
output_filename="$output_filename/${o}";;
178
# Relative_directory or empty string (.//x.o is valid)
179
o=`echo $x | sed 's,.*/,,' | sed 's,\.c$,.o,'`
180
output_filename="./${OUTFILE}/${o}";;
183
# We are linking, which means we build objects in a temporary
184
# directory and link from there. We should retain the basename
185
# of each source to make examining the exe easier...
186
o=`echo $x | sed 's,.*/,,' | sed 's,\.c$,.o,'`
187
output_filename=$TMPOBJDIR/$o
188
ACCUM_OBJECTS="$ACCUM_OBJECTS $output_filename"
190
# Now we know enough, lets try a compilation...
191
MPATH=`cygpath -m $x`
192
if [ $PREPROCESSING = true ]; then
195
output_flag="-c -Fo`cygpath -m ${output_filename}`"
197
params="$COMMON_CFLAGS $MD $DEBUG_FLAGS $OPTIMIZE_FLAGS \
198
$CMD ${output_flag} $MPATH"
199
if [ "X$CC_SH_DEBUG_LOG" != "X" ]; then
200
echo cc.sh "$SAVE" >>$CC_SH_DEBUG_LOG
201
echo cl.exe $params >>$CC_SH_DEBUG_LOG
203
eval cl.exe $params >$MSG_FILE 2>$ERR_FILE
205
if test $PREPROCESSING = false; then
209
tail +2 $ERR_FILE >&2
212
rm -f $ERR_FILE $MSG_FILE
213
if [ $RES != 0 ]; then
219
# If we got here, we succeeded in compiling (if there were anything to compile)
220
# The output filename should name an executable if we're linking
221
if [ $LINKING = true ]; then
224
# Use the first source name to name the executable
226
for x in $SOURCES; do first_source=$x; break; done;
227
if [ -n "$first_source" ]; then
228
e=`echo $x | sed 's,.*/,,' | sed 's,\.c$,.exe,'`;
234
out_spec="-o $OUTFILE";;
236
# Descide which standard library to link against
251
# And finally call the next script to do the linking...
252
params="$out_spec $LINKCMD $stdlib"
253
eval ld.sh $ACCUM_OBJECTS $params