OSDN Git Service

* Makefile.in (STAGESTUFF): Add libgcc libgcc.mk.
[pf3gnuchains/gcc-fork.git] / gcc / mklibgcc.in
1 #!/bin/sh
2 # Construct makefile for libgcc.
3 #   Copyright (C) 2000 Free Software Foundation, Inc.
4 #
5 # This file is part of GNU CC.
6
7 # Arguments, taken from the environment, since there are a lot
8 # of them, and positional args becomes quite ugly.
9 #
10 # objext
11 # OLDCC
12 # LIBGCC1
13 # LIB1FUNCS
14 # LIB1ASMFUNCS
15 # LIB1FUNCS_EXTRA
16 # LIB2FUNCS
17 # LIB2FUNCS_EH
18 # LIB2ADD
19 # FPBIT
20 # FPBIT_FUNCS
21 # DPBIT
22 # DPBIT_FUNCS
23 # LIBGCC
24 # MULTILIBS
25 # EXTRA_MULTILIB_PARTS
26
27 # Make needs VPATH to be literal.
28 echo 'srcdir = @srcdir@'
29 echo 'VPATH = @srcdir@'
30 echo
31
32 # Detect gcc as OLDCC.  This indicates a target for which LIB1FUNCS
33 # is not needed.  This is not quite the same as libgcc1.null, even
34 # on a target not using libgcc1-asm.a.
35
36 tmp="tmp-$$.c"
37 cat > $tmp <<EOF
38 #ifdef __GNUC__
39   yes;
40 #endif
41 EOF
42 if $OLDCC -E $tmp | grep yes > /dev/null 2>&1; then
43   LIB1FUNCS=""
44 fi
45 rm -f $tmp
46
47
48 #
49 # Utility functions
50 #
51
52 emit_gcc_compile() {
53   dst=$1; shift
54   src=$1; shift
55   flags=$*
56
57   echo '        $(GCC_FOR_TARGET) $(LIBGCC2_CFLAGS) $(INCLUDES)' \
58     $flags -c $src -o $dst
59 }
60
61 emit_oldcc_compile() {
62   dst=$1; shift
63   src=$1; shift
64   flags=$*
65
66   if [ -z "@NO_MINUS_C_MINUS_O@" ]; then
67     echo '      $(OLDCC) -DIN_LIBGCC1 $(CCLIBFLAGS) $(INCLUDES)' \
68       $flags -c $src -o $dst
69   else
70     echo '      $(OLDCC) -DIN_LIBGCC1 $(CCLIBFLAGS) $(INCLUDES)'
71       $flags -c $src
72     tmp=`echo $src | sed -e 's/[.]c$/'${objext}/ -e 's,.*/,,'`
73     echo "      mv $tmp $dst"
74   fi
75 }
76
77 emit_make_compile() {
78   dst=$1; shift
79   tgt=$1; shift
80   tmp="";
81   if [ "$1" = "T=t" ]; then
82     tmp="T=t"; tgt="t$tgt"; shift
83   fi
84   flags=$*
85
86   echo '        $(MAKE) GCC_FOR_TARGET="$(GCC_FOR_TARGET)"' \\
87   echo '          AR_FOR_TARGET="$(AR_FOR_TARGET)"' \\
88   echo '          AR_CREATE_FOR_TARGET="$(AR_CREATE_FOR_TARGET)"' \\
89   echo '          AR_EXTRACT_FOR_TARGET="$(AR_EXTRACT_FOR_TARGET)"' \\
90   echo '          AR_FLAGS_FOR_TARGET="$(AR_FLAGS_FOR_TARGET)"' \\
91   echo '          CC="$(CC)" CFLAGS="$(CFLAGS)"' \\
92   echo '          HOST_PREFIX="$(HOST_PREFIX)"' \\
93   echo '          HOST_PREFIX_1="$(HOST_PREFIX_1)"' \\
94   echo '          LANGUAGES="$(LANGUAGES)"' \\
95   echo '          LIBGCC2_CFLAGS="$(LIBGCC2_CFLAGS)' $flags '" ' \\
96   echo '          MULTILIB_CFLAGS="'$flags'"' $tmp $tgt
97   echo "        mv ${tgt} ${dst}"
98 }
99
100 # Dependancies for libgcc1.c
101 libgcc1_c_dep='$(srcdir)/libgcc1.c $(CONFIG_H)'
102
103 # Dependancies for libgcc2.c
104 libgcc2_c_dep='$(srcdir)/libgcc2.c $(CONFIG_H) $(MACHMODE_H) longlong.h frame.h gbl-ctors.h config.status stmp-int-hdrs tsystem.h'
105
106 # Dependancies for fp-bit.c
107 fpbit_c_dep='$(srcdir)/config/fp-bit.c config.status tsystem.h'
108
109 #
110 # Build libgcc1 components.
111 #
112
113 libgcc1_objs=""
114
115 case "$LIBGCC1" in
116   libgcc1.null)
117     ;;
118
119   libgcc1.cross)
120     echo "You must find a way to make libgcc1 components yourself" 1>&2
121     ;;
122
123   libgcc1-asm.a)
124     for name in $LIB1ASMFUNCS; do
125       for ml in $MULTILIBS; do
126         dir=`echo ${ml} | sed -e 's/;.*$//'`
127         flags=`echo ${ml} | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
128         out="libgcc/${dir}/${name}${objext}"
129
130         echo ${out}: '$(srcdir)/config/$(LIB1ASMSRC)'
131         emit_gcc_compile $out '$(srcdir)/config/$(LIB1ASMSRC)' \
132           $flags -DL$name -xassembler-with-cpp
133       done
134       libgcc1_objs="$libgcc1_objs ${name}${objext}"
135     done
136     ;;
137
138   *)
139     for name in $LIB1FUNCS; do
140       out="libgcc/${name}${objext}"
141
142       echo $out: $libgcc1_c_dep
143       emit_oldcc_compile $out '$(srcdir)/libgcc1.c' -DL${name}
144       libgcc1_objs="$libgcc1_objs ${name}${objext}"
145     done
146
147     for file in $LIB1FUNCS_EXTRA; do
148       name=`echo $file | sed -e 's/[.][cS]$//' -e 's/[.]asm$//'`
149       out="libgcc/${name}${objext}"
150
151       echo $out: $file
152       if [ ${name}.asm = $file ]; then
153         echo "  cp $file ${name}.s"
154         file=${name}.s
155       fi
156       emit_oldcc_compile $out $file
157       libgcc1_objs="$libgcc1_objs ${name}${objext}"
158     done
159     ;;
160 esac
161
162 #
163 # Build libgcc2 components.
164 #
165
166 libgcc2_objs=""
167
168 for name in $LIB2FUNCS; do
169   for ml in $MULTILIBS; do
170     dir=`echo ${ml} | sed -e 's/;.*$//'`
171     flags=`echo ${ml} | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
172     out="libgcc/${dir}/${name}${objext}"
173
174     echo $out: $libgcc2_c_dep
175     emit_gcc_compile $out '$(srcdir)/libgcc2.c' '$(MAYBE_USE_COLLECT2)' \
176       $flags -DL$name
177   done
178   libgcc2_objs="$libgcc2_objs ${name}${objext}"
179 done
180
181 for name in $LIB2FUNCS_EH; do
182   for ml in $MULTILIBS; do
183     dir=`echo ${ml} | sed -e 's/;.*$//'`
184     flags=`echo ${ml} | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
185     out="libgcc/${dir}/${name}${objext}"
186
187     echo $out: $libgcc2_c_dep
188     emit_gcc_compile $out '$(srcdir)/libgcc2.c' '$(MAYBE_USE_COLLECT2)' \
189       -fexceptions $flags -DL$name
190   done
191   libgcc2_objs="$libgcc2_objs ${name}${objext}"
192 done
193
194 if [ "$FPBIT" ]; then
195   for name in $FPBIT_FUNCS; do
196     for ml in $MULTILIBS; do
197       dir=`echo ${ml} | sed -e 's/;.*$//'`
198       flags=`echo ${ml} | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
199       out="libgcc/${dir}/${name}${objext}"
200
201       echo $out: $fpbit_c_dep
202       emit_gcc_compile $out '$(srcdir)/config/fp-bit.c' \
203         -DFLOAT -DFINE_GRAINED_LIBRARIES $flags -DL$name
204     done
205     libgcc2_objs="$libgcc2_objs ${name}${objext}"
206   done
207 fi
208
209 if [ "$DPBIT" ]; then
210   for name in $DPBIT_FUNCS; do
211     for ml in $MULTILIBS; do
212       dir=`echo ${ml} | sed -e 's/;.*$//'`
213       flags=`echo ${ml} | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
214       out="libgcc/${dir}/${name}${objext}"
215
216       echo $out: $fpbit_c_dep
217       emit_gcc_compile $out '$(srcdir)/config/fp-bit.c' \
218         -DFINE_GRAINED_LIBRARIES $flags -DL$name
219     done
220     libgcc2_objs="$libgcc2_objs ${name}${objext}"
221   done
222 fi
223
224 for file in $LIB2ADD; do
225   name=`echo $file | sed -e 's/[.][cSo]$//' -e 's/[.]asm$//' -e 's/[.]txt$//'`
226   oname=`echo $name | sed -e 's,.*/,,'`
227
228   if [ ${name}.txt = ${file} ]; then
229     fprime=`cat $file`
230     for f in $fprime; do
231
232       lastout=""
233       for ml in $MULTILIBS; do
234         dir=`echo ${ml} | sed -e 's/;.*$//'`
235         flags=`echo ${ml} | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
236         out="libgcc/${dir}/${f}"
237
238         # Depend on previous out to serialize all sub-makes of this
239         # target file.  This because ./$f is used as a temporary in
240         # each case before being moved to libgcc/$dir/.
241         echo $out: $lastout
242         emit_make_compile $out $f $flags
243
244         lastout="$out"
245       done
246
247       libgcc2_objs="$libgcc2_objs $f"
248     done
249   else
250     for ml in $MULTILIBS; do
251       dir=`echo ${ml} | sed -e 's/;.*$//'`
252       flags=`echo ${ml} | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
253       out="libgcc/${dir}/${oname}${objext}"
254       if [ ${name}.asm = ${file} ]; then
255         flags="$flags -xassembler-with-cpp"
256       fi
257
258       echo $out: $file
259       emit_gcc_compile $out $file $flags
260     done
261     libgcc2_objs="$libgcc2_objs ${oname}${objext}"
262   fi
263 done
264
265 for ml in $MULTILIBS; do
266   dir=`echo ${ml} | sed -e 's/;.*$//'`
267
268   libgcc_objs=""
269   for o in $libgcc1_objs; do
270     if [ "$LIBGCC1" = libgcc1-asm.a ]; then
271       libgcc_objs="$libgcc_objs libgcc/${dir}/$o"
272     else
273       libgcc_objs="$libgcc_objs libgcc/$o"
274     fi
275   done
276   for o in $libgcc2_objs; do
277     libgcc_objs="$libgcc_objs libgcc/${dir}/$o"
278   done
279
280   echo ""
281   echo "${dir}/libgcc.a: $libgcc_objs"
282   echo "        -rm -rf ${dir}/libgcc.a"
283   echo '        $(AR_CREATE_FOR_TARGET)' ${dir}/libgcc.a $libgcc_objs
284   echo '        if $(RANLIB_TEST_FOR_TARGET) ; then' \\
285   echo '          $(RANLIB_FOR_TARGET)' ${dir}/libgcc.a ';' \\
286   echo '        else true; fi;'
287 done
288
289 echo ""
290 all=""
291
292 for ml in $MULTILIBS; do
293   dir=`echo ${ml} | sed -e 's/;.*$//'`
294   if [ $dir = . ]; then
295     echo "libgcc:; mkdir libgcc"
296     all="$all libgcc"
297   else
298     echo "${dir}:; mkdir ${dir}"
299     echo "libgcc/${dir}:; mkdir libgcc/${dir}"
300     all="$all libgcc/${dir} ${dir}"
301   fi
302   all="$all ${dir}/libgcc.a"
303 done
304
305 for f in $EXTRA_MULTILIB_PARTS; do
306   lastout=""
307   for ml in $MULTILIBS; do
308     dir=`echo ${ml} | sed -e 's/;.*$//'`
309     flags=`echo ${ml} | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
310     out="$dir/$f"
311
312     # Depend on previous out to serialize all sub-makes of this
313     # target file.  This because ./$f is used as a temporary in
314     # each case before being moved to libgcc/$dir/.
315     echo $out: $lastout
316     emit_make_compile $out $f T=t $flags
317
318     all="$all $out"
319     lastout="$out"
320   done
321 done
322
323 echo ""
324 echo "all: $all"