~clint-fewbar/ubuntu/precise/erlang/merge-15b

« back to all changes in this revision

Viewing changes to erts/etc/win32/msys_tools/vc/cc.sh

  • Committer: Package Import Robot
  • Author(s): Sergei Golovan
  • Date: 2011-12-15 19:20:10 UTC
  • mfrom: (1.1.18) (3.5.15 sid)
  • mto: (3.5.16 sid)
  • mto: This revision was merged to the branch mainline in revision 33.
  • Revision ID: package-import@ubuntu.com-20111215192010-jnxcfe3tbrpp0big
Tags: 1:15.b-dfsg-1
* New upstream release.
* Upload to experimental because this release breaks external drivers
  API along with ABI, so several applications are to be fixed.
* Removed SSL patch because the old SSL implementation is removed from
  the upstream distribution.
* Removed never used patch which added native code to erlang beam files.
* Removed the erlang-docbuilder binary package because the docbuilder
  application was dropped by upstream.
* Documented dropping ${erlang-docbuilder:Depends} substvar in
  erlang-depends(1) manpage.
* Made erlang-base and erlang-base-hipe provide virtual package
  erlang-abi-15.b (the number means the first erlang version, which
  provides current ABI).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh
 
2
 
3
# %CopyrightBegin%
 
4
 
5
# Copyright Ericsson AB 2002-2011. All Rights Reserved.
 
6
 
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/.
 
12
 
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
 
16
# under the License.
 
17
 
18
# %CopyrightEnd%
 
19
 
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 
 
22
# general I suspect.
 
23
# set -x
 
24
# Save the command line for debug outputs
 
25
 
 
26
SAVE="$@"
 
27
 
 
28
# Constants
 
29
COMMON_CFLAGS="-nologo -D__WIN32__ -DWIN32 -DWINDOWS -D_WIN32 -DNT -D_CRT_SECURE_NO_DEPRECATE"
 
30
 
 
31
# Variables
 
32
# The stdout and stderr for the compiler
 
33
MSG_FILE=/tmp/cl.exe.$$.1
 
34
ERR_FILE=/tmp/cl.exe.$$.2
 
35
 
 
36
# "Booleans" determined during "command line parsing"
 
37
# If the stdlib option is explicitly passed to this program
 
38
MD_FORCED=false
 
39
# If we're preprocession (only) i.e. -E
 
40
PREPROCESSING=false
 
41
# If we're generating dependencies (implies preprocesing)
 
42
DEPENDENCIES=false
 
43
# If this is supposed to be a debug build
 
44
DEBUG_BUILD=false
 
45
# If this is supposed to be an optimized build (there can only be one...)
 
46
OPTIMIZED_BUILD=false
 
47
# If we're linking or only compiling
 
48
LINKING=true
 
49
 
 
50
# This data is accumulated during command line "parsing"
 
51
# The stdlibrary option, default multithreaded dynamic
 
52
MD=-MD
 
53
# Flags for debug compilation
 
54
DEBUG_FLAGS=""
 
55
# Flags for optimization
 
56
OPTIMIZE_FLAGS=""
 
57
# The specified output filename (if any), may be either object or exe.
 
58
OUTFILE=""
 
59
# Unspecified command line options for the compiler
 
60
CMD=""
 
61
# All the c source files, in unix style
 
62
SOURCES=""
 
63
# All the options to pass to the linker, kept in Unix style
 
64
LINKCMD=""
 
65
 
 
66
 
 
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
 
71
 
 
72
while test -n "$1" ; do
 
73
    x="$1"
 
74
    case "$x" in
 
75
        -Wall)
 
76
            ;;
 
77
        -c) 
 
78
            LINKING=false;;
 
79
            #CMD="$CMD -c";;
 
80
        -MM)
 
81
            PREPROCESSING=true;
 
82
            LINKING=false;
 
83
            DEPENDENCIES=true;;
 
84
        -E)
 
85
            PREPROCESSING=true;
 
86
            LINKING=false;; # Obviously...
 
87
            #CMD="$CMD -E";;
 
88
        -Owx)
 
89
            # Optimization hardcoded of wxErlang, needs to disable debugging too
 
90
            OPTIMIZE_FLAGS="-Ob2ity -Gs -Zi";
 
91
            DEBUG_FLAGS="";
 
92
            DEBUG_BUILD=false;
 
93
            if [ $MD_FORCED = false ]; then
 
94
                MD=-MD;
 
95
            fi
 
96
            OPTIMIZED_BUILD=true;;
 
97
        -O*)
 
98
            # Optimization hardcoded, needs to disable debugging too
 
99
            OPTIMIZE_FLAGS="-Ox -Zi";
 
100
            DEBUG_FLAGS="";
 
101
            DEBUG_BUILD=false;
 
102
            if [ $MD_FORCED = false ]; then
 
103
                MD=-MD;
 
104
            fi
 
105
            OPTIMIZED_BUILD=true;;
 
106
        -g|-ggdb)
 
107
            if [ $OPTIMIZED_BUILD = false ];then
 
108
                # Hardcoded windows debug flags
 
109
                DEBUG_FLAGS="-Z7";
 
110
                if [ $MD_FORCED = false ]; then
 
111
                    MD=-MDd;
 
112
                fi
 
113
                LINKCMD="$LINKCMD -g";
 
114
                DEBUG_BUILD=true;
 
115
            fi;;
 
116
        # Allow forcing of stdlib
 
117
        -mt|-MT)
 
118
            MD="-MT";
 
119
            MD_FORCED=true;;
 
120
        -md|-MD)
 
121
            MD="-MD";
 
122
            MD_FORCED=true;;
 
123
        -ml|-ML)
 
124
            MD="-ML";
 
125
            MD_FORCED=true;;
 
126
        -mdd|-MDD|-MDd)
 
127
            MD="-MDd";
 
128
            MD_FORCED=true;;
 
129
        -mtd|-MTD|-MTd)
 
130
            MD="-MTd";
 
131
            MD_FORCED=true;;
 
132
        -mld|-MLD|-MLd)
 
133
            MD="-MLd";
 
134
            MD_FORCED=true;;
 
135
        -o)
 
136
            shift;
 
137
            OUTFILE="$1";;
 
138
        -o*)
 
139
            y=`echo $x | sed 's,^-[Io]\(.*\),\1,g'`;
 
140
            OUTFILE="$y";;
 
141
        -I/*)
 
142
            y=`echo $x | sed 's,^-[Io]\(/.*\),\1,g'`;
 
143
            z=`echo $x | sed 's,^-\([Io]\)\(/.*\),\1,g'`;
 
144
            MPATH=`echo $y`;
 
145
            CMD="$CMD -$z\"$MPATH\"";; 
 
146
        -I*)
 
147
            y=`echo $x | sed 's,",\\\",g'`;
 
148
            CMD="$CMD $y";;
 
149
        -D*)
 
150
            y=`echo $x | sed 's,",\\\",g'`;
 
151
            CMD="$CMD $y";;
 
152
        -EH*)
 
153
            y=`echo $x | sed 's,",\\\",g'`;
 
154
            CMD="$CMD $y";;
 
155
        -TP|-Tp)
 
156
            y=`echo $x | sed 's,",\\\",g'`;
 
157
            CMD="$CMD $y";;
 
158
        -l*)
 
159
            y=`echo $x | sed 's,^-l\(.*\),\1,g'`;
 
160
            LINKCMD="$LINKCMD $x";;
 
161
        /*.c)
 
162
            SOURCES="$SOURCES $x";;
 
163
        *.c)
 
164
            SOURCES="$SOURCES $x";;
 
165
        /*.cc)
 
166
            SOURCES="$SOURCES $x";;
 
167
        *.cc)
 
168
            SOURCES="$SOURCES $x";;
 
169
        /*.cpp)
 
170
            SOURCES="$SOURCES $x";;
 
171
        *.cpp)
 
172
            SOURCES="$SOURCES $x";;
 
173
        /*.o)
 
174
            LINKCMD="$LINKCMD $x";;
 
175
        *.o)
 
176
            LINKCMD="$LINKCMD $x";;
 
177
        *)
 
178
            # Try to quote uninterpreted options
 
179
            y=`echo $x | sed 's,",\\\",g'`;
 
180
            LINKCMD="$LINKCMD $y";;
 
181
    esac
 
182
    shift
 
183
done
 
184
 
 
185
#Return code from compiler, linker.sh and finally this script...
 
186
RES=0
 
187
 
 
188
# Accumulated object names
 
189
ACCUM_OBJECTS=""
 
190
 
 
191
# A temporary object file location
 
192
TMPOBJDIR=/tmp/tmpobj$$
 
193
mkdir $TMPOBJDIR
 
194
 
 
195
# Compile
 
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 
 
201
        # or an object file
 
202
        case $OUTFILE in
 
203
            /*.o)
 
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.";
 
208
                    exit 1;
 
209
                else
 
210
                    output_filename=`echo $OUTFILE`;
 
211
                fi;;
 
212
            *.o)
 
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."
 
217
                    exit 1
 
218
                else
 
219
                    output_filename=$OUTFILE
 
220
                fi;;
 
221
            /*)
 
222
                # Absolute directory
 
223
                o=`echo $x | sed 's,.*/,,' | sed 's,\.c$,.o,'`
 
224
                output_filename=`echo $OUTFILE`
 
225
                output_filename="$output_filename/${o}";;
 
226
            *)
 
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}";;
 
230
        esac
 
231
    else
 
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"
 
238
    fi
 
239
    # Now we know enough, lets try a compilation...
 
240
    MPATH=`echo $x`
 
241
    if [ $PREPROCESSING = true ]; then
 
242
        output_flag="-E"
 
243
    else
 
244
        output_flag="-c -Fo`cmd //C echo ${output_filename}`"
 
245
    fi
 
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
 
251
    fi
 
252
    eval cl.exe $params >$MSG_FILE 2>$ERR_FILE
 
253
    RES=$?
 
254
    if test $PREPROCESSING = false; then
 
255
        cat $ERR_FILE >&2
 
256
        tail -n +2 $MSG_FILE
 
257
    else
 
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,'`
 
262
                echo -n $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)}' 
 
265
                echo
 
266
                echo 
 
267
                after_sed=`date '+%s'`
 
268
                echo Made dependencises for $x':' `expr $after_sed '-' $start_time` 's' >&2
 
269
            fi 
 
270
        else
 
271
            cat $MSG_FILE
 
272
        fi
 
273
    fi
 
274
    rm -f $ERR_FILE $MSG_FILE
 
275
    if [ $RES != 0 ]; then
 
276
        rm -rf $TMPOBJDIR
 
277
        exit $RES
 
278
    fi
 
279
done
 
280
 
 
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
 
284
    case $OUTFILE in
 
285
        "")
 
286
            # Use the first source name to name the executable
 
287
            first_source=""
 
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,'`;
 
291
                out_spec="-o $e";
 
292
            else
 
293
                out_spec="";
 
294
            fi;;
 
295
        *)
 
296
            out_spec="-o $OUTFILE";;
 
297
    esac
 
298
    # Descide which standard library to link against
 
299
    case $MD in
 
300
        -ML)
 
301
            stdlib="-lLIBC";;
 
302
        -MLd)
 
303
            stdlib="-lLIBCD";;
 
304
        -MD)
 
305
            stdlib="-lMSVCRT";;
 
306
        -MDd)
 
307
            stdlib="-lMSVCRTD";;
 
308
        -MT)
 
309
            stdlib="-lLIBCMT";;
 
310
        -MTd)
 
311
            stdlib="-lLIBMTD";;
 
312
    esac
 
313
    # And finally call the next script to do the linking...
 
314
    params="$out_spec $LINKCMD $stdlib" 
 
315
    eval ld.sh $ACCUM_OBJECTS $params
 
316
    RES=$?
 
317
fi
 
318
rm -rf $TMPOBJDIR
 
319
 
 
320
exit $RES