~ubuntu-branches/debian/squeeze/erlang/squeeze

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Erlang Packagers, Sergei Golovan
  • Date: 2006-12-03 17:07:44 UTC
  • mfrom: (2.1.11 feisty)
  • Revision ID: james.westby@ubuntu.com-20061203170744-rghjwupacqlzs6kv
Tags: 1:11.b.2-4
[ Sergei Golovan ]
Fixed erlang-base and erlang-base-hipe prerm scripts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh
 
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 
 
4
# general I suspect.
 
5
# set -x
 
6
# Save the command line for debug outputs
 
7
SAVE="$@"
 
8
 
 
9
# Constants
 
10
COMMON_CFLAGS="-nologo -D__WIN32__ -DWIN32 -DWINDOWS -D_WIN32 -DNT"
 
11
 
 
12
# Variables
 
13
# The stdout and stderr for the compiler
 
14
MSG_FILE=/tmp/cl.exe.$$.1
 
15
ERR_FILE=/tmp/cl.exe.$$.2
 
16
 
 
17
# "Booleans" determined during "command line parsing"
 
18
# If the stdlib option is explicitly passed to this program
 
19
MD_FORCED=false
 
20
# If we're preprocession (only) i.e. -E
 
21
PREPROCESSING=false
 
22
# If this is supposed to be a debug build
 
23
DEBUG_BUILD=false
 
24
# If this is supposed to be an optimized build (there can only be one...)
 
25
OPTIMIZED_BUILD=false
 
26
# If we're linking or only compiling
 
27
LINKING=true
 
28
 
 
29
# This data is accumulated during command line "parsing"
 
30
# The stdlibrary option, default multithreaded dynamic
 
31
MD=-MD
 
32
# Flags for debug compilation
 
33
DEBUG_FLAGS=""
 
34
# Flags for optimization
 
35
OPTIMIZE_FLAGS=""
 
36
# The specified output filename (if any), may be either object or exe.
 
37
OUTFILE=""
 
38
# Unspe3cified command line options for the compiler
 
39
CMD=""
 
40
# All the c source files, in unix style
 
41
SOURCES=""
 
42
# All the options to pass to the linker, kept in Unix style
 
43
LINKCMD=""
 
44
 
 
45
 
 
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
 
50
 
 
51
while test -n "$1" ; do
 
52
    x="$1"
 
53
    case "$x" in
 
54
        -Wall)
 
55
            ;;
 
56
        -c) 
 
57
            LINKING=false;;
 
58
            #CMD="$CMD -c";;
 
59
        -E)
 
60
            PREPROCESSING=true;
 
61
            LINKING=false;; # Obviously...
 
62
            #CMD="$CMD -E";;
 
63
        -O*)
 
64
            # Optimization hardcoded, needs to disable debugging too
 
65
            OPTIMIZE_FLAGS="-Ox";
 
66
            DEBUG_FLAGS="";
 
67
            DEBUG_BUILD=false;
 
68
            if [ $MD_FORCED = false ]; then
 
69
                MD=-MD;
 
70
            fi
 
71
            OPTIMIZED_BUILD=true;;
 
72
        -g|-ggdb)
 
73
            if [ $OPTIMIZED_BUILD = false ];then
 
74
                # Hardcoded windows debug flags
 
75
                DEBUG_FLAGS="-Z7";
 
76
                if [ $MD_FORCED = false ]; then
 
77
                    MD=-MDd;
 
78
                fi
 
79
                LINKCMD="$LINKCMD -g";
 
80
                DEBUG_BUILD=true;
 
81
            fi;;
 
82
        # Allow forcing of stdlib
 
83
        -mt|-MT)
 
84
            MD="-MT";
 
85
            MD_FORCED=true;;
 
86
        -md|-MD)
 
87
            MD="-MD";
 
88
            MD_FORCED=true;;
 
89
        -ml|-ML)
 
90
            MD="-ML";
 
91
            MD_FORCED=true;;
 
92
        -mdd|-MDD|-MDd)
 
93
            MD="-MDd";
 
94
            MD_FORCED=true;;
 
95
        -mtd|-MTD|-MTd)
 
96
            MD="-MTd";
 
97
            MD_FORCED=true;;
 
98
        -mld|-MLD|-MLd)
 
99
            MD="-MLd";
 
100
            MD_FORCED=true;;
 
101
        -o)
 
102
            shift;
 
103
            OUTFILE="$1";;
 
104
        -o*)
 
105
            y=`echo $x | sed 's,^-[Io]\(.*\),\1,g'`;
 
106
            OUTFILE="$y";;
 
107
        -I/*)
 
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\"";; 
 
112
        -I*)
 
113
            y=`echo $x | sed 's,",\\\",g'`;
 
114
            CMD="$CMD $y";;
 
115
        -D*)
 
116
            y=`echo $x | sed 's,",\\\",g'`;
 
117
            CMD="$CMD $y";;
 
118
        -l*)
 
119
            y=`echo $x | sed 's,^-l\(.*\),\1,g'`;
 
120
            LINKCMD="$LINKCMD $x";;
 
121
        /*.c)
 
122
            SOURCES="$SOURCES $x";;
 
123
        *.c)
 
124
            SOURCES="$SOURCES $x";;
 
125
        /*.o)
 
126
            LINKCMD="$LINKCMD $x";;
 
127
        *.o)
 
128
            LINKCMD="$LINKCMD $x";;
 
129
        *)
 
130
            # Try to quote uninterpreted options
 
131
            y=`echo $x | sed 's,",\\\",g'`;
 
132
            LINKCMD="$LINKCMD $y";;
 
133
    esac
 
134
    shift
 
135
done
 
136
 
 
137
#Return code from compiler, linker.sh and finally this script...
 
138
RES=0
 
139
 
 
140
# Accumulated object names
 
141
ACCUM_OBJECTS=""
 
142
 
 
143
# A temporary object file location
 
144
TMPOBJDIR=/tmp/tmpobj$$
 
145
mkdir $TMPOBJDIR
 
146
 
 
147
# Compile
 
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 
 
152
        # or an object file
 
153
        case $OUTFILE in
 
154
            /*.o)
 
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.";
 
159
                    exit 1;
 
160
                else
 
161
                    output_filename=`cygpath -m $OUTFILE`;
 
162
                fi;;
 
163
            *.o)
 
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."
 
168
                    exit 1
 
169
                else
 
170
                    output_filename=$OUTFILE
 
171
                fi;;
 
172
            /*)
 
173
                # Absolute directory
 
174
                o=`echo $x | sed 's,.*/,,' | sed 's,\.c$,.o,'`
 
175
                output_filename=`cygpath -m $OUTFILE`
 
176
                output_filename="$output_filename/${o}";;
 
177
            *)
 
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}";;
 
181
        esac
 
182
    else
 
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"
 
189
    fi
 
190
    # Now we know enough, lets try a compilation...
 
191
    MPATH=`cygpath -m $x`
 
192
    if [ $PREPROCESSING = true ]; then
 
193
        output_flag="-E"
 
194
    else
 
195
        output_flag="-c -Fo`cygpath -m ${output_filename}`"
 
196
    fi
 
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
 
202
    fi
 
203
    eval cl.exe $params >$MSG_FILE 2>$ERR_FILE
 
204
    RES=$?
 
205
    if test $PREPROCESSING = false; then
 
206
        cat $ERR_FILE >&2
 
207
        tail +2 $MSG_FILE
 
208
    else
 
209
        tail +2 $ERR_FILE >&2
 
210
        cat $MSG_FILE
 
211
    fi
 
212
    rm -f $ERR_FILE $MSG_FILE
 
213
    if [ $RES != 0 ]; then
 
214
        rm -rf $TMPOBJDIR
 
215
        exit $RES
 
216
    fi
 
217
done
 
218
 
 
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
 
222
    case $OUTFILE in
 
223
        "")
 
224
            # Use the first source name to name the executable
 
225
            first_source=""
 
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,'`;
 
229
                out_spec="-o $e";
 
230
            else
 
231
                out_spec="";
 
232
            fi;;
 
233
        *)
 
234
            out_spec="-o $OUTFILE";;
 
235
    esac
 
236
    # Descide which standard library to link against
 
237
    case $MD in
 
238
        -ML)
 
239
            stdlib="-lLIBC";;
 
240
        -MLd)
 
241
            stdlib="-lLIBCD";;
 
242
        -MD)
 
243
            stdlib="-lMSVCRT";;
 
244
        -MDd)
 
245
            stdlib="-lMSVCRTD";;
 
246
        -MT)
 
247
            stdlib="-lLIBCMT";;
 
248
        -MTd)
 
249
            stdlib="-lLIBMTD";;
 
250
    esac
 
251
    # And finally call the next script to do the linking...
 
252
    params="$out_spec $LINKCMD $stdlib" 
 
253
    eval ld.sh $ACCUM_OBJECTS $params
 
254
    RES=$?
 
255
fi
 
256
rm -rf $TMPOBJDIR
 
257
 
 
258
exit $RES