5
# Copyright Ericsson AB 2002-2011. All Rights Reserved.
7
# The contents of this file are subject to the Erlang Public License,
8
# Version 1.1, (the "License"); you may not use this file except in
9
# compliance with the License. You should have received a copy of the
10
# Erlang Public License along with this software. If not, it can be
11
# retrieved online at http://www.erlang.org/.
13
# Software distributed under the License is distributed on an "AS IS"
14
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
15
# the License for the specific language governing rights and limitations
20
# Icky cl wrapper that does it's best to behave like a Unixish cc.
21
# Made to work for Erlang builds and to make configure happy, not really
24
# Save the command line for debug outputs
29
COMMON_CFLAGS="-nologo -D__WIN32__ -DWIN32 -DWINDOWS -D_WIN32 -DNT -D_CRT_SECURE_NO_DEPRECATE"
32
# The stdout and stderr for the compiler
33
MSG_FILE=/tmp/cl.exe.$$.1
34
ERR_FILE=/tmp/cl.exe.$$.2
36
# "Booleans" determined during "command line parsing"
37
# If the stdlib option is explicitly passed to this program
39
# If we're preprocession (only) i.e. -E
41
# If we're generating dependencies (implies preprocesing)
43
# If this is supposed to be a debug build
45
# If this is supposed to be an optimized build (there can only be one...)
47
# If we're linking or only compiling
50
# This data is accumulated during command line "parsing"
51
# The stdlibrary option, default multithreaded dynamic
53
# Flags for debug compilation
55
# Flags for optimization
57
# The specified output filename (if any), may be either object or exe.
59
# Unspecified command line options for the compiler
61
# All the c source files, in unix style
63
# All the options to pass to the linker, kept in Unix style
67
# Loop through the parameters and set the above variables accordingly
68
# Also convert some cygwin filenames to "mixed style" dito (understood by the
69
# compiler very well), except for anything passed to the linker, that script
70
# handles those and the sources, which are also kept unixish for now
72
while test -n "$1" ; do
86
LINKING=false;; # Obviously...
89
# Optimization hardcoded of wxErlang, needs to disable debugging too
90
OPTIMIZE_FLAGS="-Ob2ity -Gs -Zi";
93
if [ $MD_FORCED = false ]; then
96
OPTIMIZED_BUILD=true;;
98
# Optimization hardcoded, needs to disable debugging too
99
OPTIMIZE_FLAGS="-Ox -Zi";
102
if [ $MD_FORCED = false ]; then
105
OPTIMIZED_BUILD=true;;
107
if [ $OPTIMIZED_BUILD = false ];then
108
# Hardcoded windows debug flags
110
if [ $MD_FORCED = false ]; then
113
LINKCMD="$LINKCMD -g";
116
# Allow forcing of stdlib
139
y=`echo $x | sed 's,^-[Io]\(.*\),\1,g'`;
142
y=`echo $x | sed 's,^-[Io]\(/.*\),\1,g'`;
143
z=`echo $x | sed 's,^-\([Io]\)\(/.*\),\1,g'`;
145
CMD="$CMD -$z\"$MPATH\"";;
147
y=`echo $x | sed 's,",\\\",g'`;
150
y=`echo $x | sed 's,",\\\",g'`;
153
y=`echo $x | sed 's,",\\\",g'`;
156
y=`echo $x | sed 's,",\\\",g'`;
159
y=`echo $x | sed 's,^-l\(.*\),\1,g'`;
160
LINKCMD="$LINKCMD $x";;
162
SOURCES="$SOURCES $x";;
164
SOURCES="$SOURCES $x";;
166
SOURCES="$SOURCES $x";;
168
SOURCES="$SOURCES $x";;
170
SOURCES="$SOURCES $x";;
172
SOURCES="$SOURCES $x";;
174
LINKCMD="$LINKCMD $x";;
176
LINKCMD="$LINKCMD $x";;
178
# Try to quote uninterpreted options
179
y=`echo $x | sed 's,",\\\",g'`;
180
LINKCMD="$LINKCMD $y";;
185
#Return code from compiler, linker.sh and finally this script...
188
# Accumulated object names
191
# A temporary object file location
192
TMPOBJDIR=/tmp/tmpobj$$
196
for x in $SOURCES; do
197
start_time=`date '+%s'`
198
# Compile each source
199
if [ $LINKING = false ]; then
200
# We should have an output defined, which is a directory
204
# Simple output, SOURCES should be one single
205
n=`echo $SOURCES | wc -w`;
206
if [ $n -gt 1 ]; then
207
echo "cc.sh:Error, multiple sources, one object output.";
210
output_filename=`echo $OUTFILE`;
213
# Relative path needs no translation
214
n=`echo $SOURCES | wc -w`
215
if [ $n -gt 1 ]; then
216
echo "cc.sh:Error, multiple sources, one object output."
219
output_filename=$OUTFILE
223
o=`echo $x | sed 's,.*/,,' | sed 's,\.c$,.o,'`
224
output_filename=`echo $OUTFILE`
225
output_filename="$output_filename/${o}";;
227
# Relative_directory or empty string (.//x.o is valid)
228
o=`echo $x | sed 's,.*/,,' | sed 's,\.cp*$,.o,'`
229
output_filename="./${OUTFILE}/${o}";;
232
# We are linking, which means we build objects in a temporary
233
# directory and link from there. We should retain the basename
234
# of each source to make examining the exe easier...
235
o=`echo $x | sed 's,.*/,,' | sed 's,\.c$,.o,'`
236
output_filename=$TMPOBJDIR/$o
237
ACCUM_OBJECTS="$ACCUM_OBJECTS $output_filename"
239
# Now we know enough, lets try a compilation...
241
if [ $PREPROCESSING = true ]; then
244
output_flag="-c -Fo`cmd //C echo ${output_filename}`"
246
params="$COMMON_CFLAGS $MD $DEBUG_FLAGS $OPTIMIZE_FLAGS \
247
$CMD ${output_flag} $MPATH"
248
if [ "X$CC_SH_DEBUG_LOG" != "X" ]; then
249
echo cc.sh "$SAVE" >>$CC_SH_DEBUG_LOG
250
echo cl.exe $params >>$CC_SH_DEBUG_LOG
252
eval cl.exe $params >$MSG_FILE 2>$ERR_FILE
254
if test $PREPROCESSING = false; then
258
tail -n +2 $ERR_FILE >&2
259
if test $DEPENDENCIES = true; then
260
if test `grep -v $x $MSG_FILE | grep -c '#line'` != "0"; then
261
o=`echo $x | sed 's,.*/,,' | sed 's,\.cp*$,.o,'`
263
# cat $MSG_FILE | grep '#line' | grep -v $x | awk -F\" '{printf("%s\n",$2)}' | sort -u | grep -v " " | xargs -n 1 win2msys_path.sh | awk '{printf("\\\n %s ",$0)}'
264
cat $MSG_FILE | grep '#line' | grep -v $x | awk -F\" '{printf("%s\n",$2)}' | sort -u | grep -v " " | sed 's,^\([A-Za-z]\):[\\/]*,/\1/,;s,\\\\*,/,g'| awk '{printf("\\\n %s ",$0)}'
267
after_sed=`date '+%s'`
268
echo Made dependencises for $x':' `expr $after_sed '-' $start_time` 's' >&2
274
rm -f $ERR_FILE $MSG_FILE
275
if [ $RES != 0 ]; then
281
# If we got here, we succeeded in compiling (if there were anything to compile)
282
# The output filename should name an executable if we're linking
283
if [ $LINKING = true ]; then
286
# Use the first source name to name the executable
288
for x in $SOURCES; do first_source=$x; break; done;
289
if [ -n "$first_source" ]; then
290
e=`echo $x | sed 's,.*/,,' | sed 's,\.c$,.exe,'`;
296
out_spec="-o $OUTFILE";;
298
# Descide which standard library to link against
313
# And finally call the next script to do the linking...
314
params="$out_spec $LINKCMD $stdlib"
315
eval ld.sh $ACCUM_OBJECTS $params