OSDN Git Service

PR ada/24533
[pf3gnuchains/gcc-fork.git] / gcc / mklibgcc.in
1 #!/bin/sh
2 # Construct makefile for libgcc.
3 #   Copyright (C) 2000, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
4 #
5 # This file is part of GCC.
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 # LIB1ASMFUNCS
12 # LIB2FUNCS_ST
13 # LIBGCOV
14 # LIB2ADD
15 # LIB2ADD_ST 
16 # LIB2ADDEH
17 # LIB2ADDEHSTATIC
18 # LIB2ADDEHSHARED
19 # LIB2ADDEHDEP
20 # LIBUNWIND
21 # LIBUNWINDDEP
22 # SHLIBUNWIND_LINK
23 # SHLIBUNWIND_INSTALL
24 # FPBIT
25 # FPBIT_FUNCS
26 # LIB2_DIVMOD_FUNCS
27 # DPBIT
28 # DPBIT_FUNCS
29 # TPBIT
30 # TPBIT_FUNCS
31 # D32PBIT
32 # D32PBIT_FUNCS
33 # D64PBIT
34 # D64PBIT_FUNCS
35 # D128PBIT
36 # D128PBIT_FUNCS
37 # LIBGCC
38 # MULTILIBS
39 # EXTRA_MULTILIB_PARTS
40 # SHLIB_EXT
41 # SHLIB_LINK
42 # SHLIB_MKMAP
43 # SHLIB_MKMAP_OPTS
44 # SHLIB_MAPFILES
45 # SHLIB_NM_FLAGS
46 # SHLIB_INSTALL
47 # MULTILIB_OSDIRNAMES
48 # ASM_HIDDEN_OP
49 # GCC_FOR_TARGET
50
51 # Make needs VPATH to be literal.
52 echo 'srcdir = @srcdir@'
53 echo 'VPATH = @srcdir@'
54 echo 'EQ = ='
55 echo 'objects = $(filter %'$objext',$^)'
56 echo
57 echo '# Dependencies are accumulated as we go.'
58 echo 'all: stmp-dirs'
59 echo 'dirs = libgcc'
60 echo
61
62 # Library members defined in libgcc2.c.
63 lib2funcs='_muldi3 _negdi2 _lshrdi3 _ashldi3 _ashrdi3
64         _cmpdi2 _ucmpdi2 _floatdidf _floatdisf _fixunsdfsi _fixunssfsi
65         _fixunsdfdi _fixdfdi _fixunssfdi _fixsfdi _fixxfdi _fixunsxfdi
66         _floatdixf _fixunsxfsi _fixtfdi _fixunstfdi _floatditf _clear_cache
67         _enable_execute_stack _trampoline __main _absvsi2 _absvdi2 _addvsi3
68         _addvdi3 _subvsi3 _subvdi3 _mulvsi3 _mulvdi3 _negvsi2 _negvdi2 _ctors
69         _ffssi2 _ffsdi2 _clz _clzsi2 _clzdi2 _ctzsi2 _ctzdi2 _popcount_tab
70         _popcountsi2 _popcountdi2 _paritysi2 _paritydi2 _powisf2 _powidf2
71         _powixf2 _powitf2 _mulsc3 _muldc3 _mulxc3 _multc3 _divsc3 _divdc3
72         _divxc3 _divtc3 _floatundidf _floatundisf _floatundixf _floatunditf'
73
74 # Disable SHLIB_LINK if shared libgcc not enabled.
75 if [ "@enable_shared@" = "no" ]; then
76   SHLIB_LINK=""
77 fi
78
79 # Build lines.
80
81 gcc_compile='$(GCC_FOR_TARGET) $(LIBGCC2_CFLAGS) $(INCLUDES)'
82 gcc_s_compile="$gcc_compile -DSHARED"
83 make_compile='$(MAKE) GCC_FOR_TARGET="$(GCC_FOR_TARGET)" \
84           AR_FOR_TARGET="$(AR_FOR_TARGET)" \
85           AR_CREATE_FOR_TARGET="$(AR_CREATE_FOR_TARGET)" \
86           AR_EXTRACT_FOR_TARGET="$(AR_EXTRACT_FOR_TARGET)" \
87           AR_FLAGS_FOR_TARGET="$(AR_FLAGS_FOR_TARGET)" \
88           CC="$(CC)" CFLAGS="$(CFLAGS)" \
89           BUILD_PREFIX="$(BUILD_PREFIX)" \
90           BUILD_PREFIX_1="$(BUILD_PREFIX_1)" \
91           LANGUAGES="$(LANGUAGES)"'
92
93 # Generic dependencies for libgcc
94 libgcc_dep='$(CONFIG_H) coretypes.h $(TM_H) $(MACHMODE_H) longlong.h config.status stmp-int-hdrs tsystem.h'
95
96 # Dependencies for libgcc2.c
97 libgcc2_c_dep='stmp-dirs $(srcdir)/libgcc2.c $(srcdir)/libgcc2.h gbl-ctors.h'" $libgcc_dep"
98
99 # Dependencies for libgcov.c
100 libgcov_c_dep='stmp-dirs $(srcdir)/libgcov.c $(srcdir)/gcov-io.h $(srcdir)/gcov-io.c gcov-iov.h'" $libgcc_dep"
101
102 # Dependencies for fp-bit.c
103 fpbit_c_dep='stmp-dirs config.status tsystem.h'
104
105 # Dependencies for decnumber and friends.  This is an overzealous set,
106 # but at least we can be sure to recompile if anything gets modified.
107 decnumber_dep='stmp-dirs $(srcdir)/../libdecnumber/decContext.h $(srcdir)/../libdecnumber/decNumber.h
108         $(srcdir)/../libdecnumber/decNumberLocal.h $(srcdir)/../libdecnumber/decimal32.h $(srcdir)/../libdecnumber/decimal64.h
109         $(srcdir)/../libdecnumber/decimal128.h $(srcdir)/../libdecnumber/decDPD.h $(srcdir)/../libdecnumber/decUtility.h'
110
111 # Flag whether we need eh_dummy.c
112 need_eh_dummy=
113
114 if [ "$SHLIB_LINK" ]; then
115   # Test -fvisibility=hidden.  We need both a -fvisibility=hidden on
116   # the command line, and a #define to prevent libgcc2.h etc from
117   # overriding that with #pragmas.  The dance with @ is to prevent
118   # echo from seeing anything it might take for an option.
119   # echo turns the \$\$\$\$ into $$$$ and when make sees it it
120   # becomes $$ and the shell substitutes the pid. Makes for a
121   # slightly safer temp file.
122   echo "vis_hide := \$(strip \$(subst @,-,\\"
123   echo "    \$(shell if echo 'void foo(void); void foo(void) {}' | \\"
124   echo "          $gcc_compile -fvisibility=hidden -Werror \\"
125   echo "          -c -xc - -o vis_temp_file\$\$\$\$.o 2> /dev/null; \\"
126   echo "          then echo @fvisibility=hidden @DHIDE_EXPORTS; \\"
127   echo "          rm vis_temp_file\$\$\$\$.o 2> /dev/null; \\"
128   echo "          fi)))"
129   echo
130
131   # If we have -fvisibility=hidden, then we need to generate hide
132   # lists for object files implemented in assembly.  The default
133   # pseudo-op for this is ".hidden", but can be overridden with
134   # ASM_HIDDEN_OP.
135   [ "$ASM_HIDDEN_OP" ] || ASM_HIDDEN_OP=".hidden"
136   
137   echo "ifneq (,\$(vis_hide))"
138   echo "define gen-hide-list"
139   echo "\$(NM_FOR_TARGET) ${SHLIB_NM_FLAGS} \$< | \\"
140   # non-GNU nm emits three fields even for undefined and typeless symbols,
141   # so explicitly omit them
142   echo "  \$(AWK) 'NF == 3 && \$\$2 !~ /^[UN]\$\$/ { print \"\\t${ASM_HIDDEN_OP}\", \$\$3 }' > \$@T"
143   echo "mv -f \$@T \$@"
144   echo "endef"
145   echo "else"
146   echo "gen-hide-list = echo > \$@"
147   echo "endif"
148   echo
149 else
150   # It is too hard to guarantee that vis_hide and gen-hide-list will never
151   # be referenced if SHLIB_LINK is not set, so set them to the values they'd
152   # have if SHLIB_LINK were set and we didn't have visibility support.
153   echo "vis_hide ="
154   echo "gen-hide-list = echo > \$@"
155 fi
156
157 # Remove any objects from lib2funcs and LIB2_DIVMOD_FUNCS that are
158 # defined as optimized assembly code in LIB1ASMFUNCS.
159 for name in $LIB1ASMFUNCS; do
160   lib2funcs=`echo $lib2funcs | sed -e 's/^'$name' //' \
161                                    -e 's/ '$name' / /' \
162                                    -e 's/ '$name'$//'`
163   LIB2_DIVMOD_FUNCS=`echo $LIB2_DIVMOD_FUNCS | sed -e 's/^'$name' //' \
164                                                    -e 's/ '$name' / /' \
165                                                    -e 's/ '$name'$//'`
166 done
167
168 #
169 # Rules to generate object files.
170 #
171
172 for ml in $MULTILIBS; do
173
174   # Work out relevant parameters that depend only on the multilib.
175   dir=`echo ${ml} | sed -e 's/;.*$//' -e 's/=/$(EQ)/g'`
176   flags=`echo ${ml} | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
177   shlib_slibdir_qual=
178   libgcc_a=$dir/libgcc.a
179   libgcov_a=$dir/libgcov.a
180   libgcc_eh_a=
181   libgcc_s_so=
182   libunwind_a=
183   libunwind_so=
184
185   if [ "$LIBUNWIND" ]; then
186     libunwind_a=$dir/libunwind.a
187   fi
188   if [ "$SHLIB_LINK" ]; then
189     libgcc_eh_a=$dir/libgcc_eh.a
190     libgcc_s_so=$dir/libgcc_s${SHLIB_EXT}
191     if [ "$LIBUNWIND" ]; then
192       libunwind_so=$dir/libunwind${SHLIB_EXT}
193     fi
194     os_multilib_dir=`$GCC_FOR_TARGET $flags --print-multi-os-directory`
195     if [ "$os_multilib_dir" != . ]; then
196       shlib_slibdir_qual="/$os_multilib_dir"
197     fi
198   fi
199
200   libgcc_s_so_extra=
201   libunwind_so_extra=
202
203   echo
204   echo \#
205   echo \# ml: $ml
206   echo \# dir: $dir
207   echo \# flags: $flags
208   echo \# libgcc_a: $libgcc_a
209   echo \# libgcov_a: $libgcov_a
210   echo \# libgcc_eh_a: $libgcc_eh_a
211   echo \# libunwind_a: $libunwind_a
212   echo \#
213   echo \# shlib_slibdir_qual: $shlib_slibdir_qual
214   echo \# libgcc_s_so: $libgcc_s_so
215   echo \# libunwind_so: $libunwind_so
216   echo \#
217   echo
218
219   # Update list of directories.
220   if [ $dir != . ]; then
221     echo "dirs += ${dir} libgcc/${dir}"
222     echo
223   fi
224
225   #
226   # Build libgcc1 components.
227   #
228   for name in $LIB1ASMFUNCS; do
229     if [ "$libgcc_s_so" ]; then
230       out="libgcc/${dir}/${name}${objext}"
231       outS="libgcc/${dir}/${name}_s${objext}"
232       outV="libgcc/${dir}/${name}.vis"
233
234       echo ${outS}: stmp-dirs '$(srcdir)/config/$(LIB1ASMSRC)'
235       echo "    $gcc_s_compile" $flags -DL$name -xassembler-with-cpp \
236           -c '$(srcdir)/config/$(LIB1ASMSRC)' -o $outS
237
238       echo ${out}: stmp-dirs '$(srcdir)/config/$(LIB1ASMSRC)' ${outV}
239       echo "    $gcc_compile" $flags -DL$name -xassembler-with-cpp \
240           -c '$(srcdir)/config/$(LIB1ASMSRC)' -include $outV -o $out
241
242       echo "${outV}: ${outS}; \$(gen-hide-list)"
243
244       echo $libgcc_a: $out
245       echo $libgcc_s_so: $outS
246       if [ "$SHLIB_MKMAP" ]; then
247         echo libgcc/${dir}/libgcc.map: $outS
248       fi
249     else
250       out="libgcc/${dir}/${name}${objext}"
251       echo ${out}: stmp-dirs '$(srcdir)/config/$(LIB1ASMSRC)'
252       echo "    $gcc_compile" $flags -DL$name -xassembler-with-cpp \
253           -c '$(srcdir)/config/$(LIB1ASMSRC)' -o $out
254       echo $libgcc_a: $out
255     fi
256   done
257
258   #
259   # Build libgcc2 components.
260   #
261
262   for name in $lib2funcs; do
263     if [ "$libgcc_s_so" ]; then
264       out="libgcc/${dir}/${name}${objext}"
265       outS="libgcc/${dir}/${name}_s${objext}"
266
267       echo $outS: $libgcc2_c_dep
268       echo "    $gcc_s_compile" $flags -DL$name -c '$(srcdir)/libgcc2.c' \
269         -o $outS
270
271       echo $out: $libgcc2_c_dep
272       echo "    $gcc_compile" $flags -DL$name '$(vis_hide)' \
273         -c '$(srcdir)/libgcc2.c' -o $out
274
275       echo $libgcc_a: $out
276       echo $libgcc_s_so: $outS
277       if [ "$SHLIB_MKMAP" ]; then
278         echo libgcc/${dir}/libgcc.map: $outS
279       fi
280     else
281       out="libgcc/${dir}/${name}${objext}"
282       echo ${out}: stmp-dirs '$(srcdir)/config/$(LIB1ASMSRC)'
283       echo "    $gcc_compile" $flags -DL$name -c '$(srcdir)/libgcc2.c' -o $out
284       echo $libgcc_a: $out
285     fi
286   done
287
288   for name in $LIB2FUNCS_ST; do
289     out="libgcc/${dir}/${name}${objext}"
290
291     echo $out: $libgcc2_c_dep
292     echo "      $gcc_compile" $flags -DL$name '$(vis_hide)' \
293       -c '$(srcdir)/libgcc2.c' -o $out
294     echo ${dir}/libgcc.a: $out
295   done
296
297   for name in $LIB2_DIVMOD_FUNCS; do
298     if [ "$libgcc_s_so" ]; then
299       out="libgcc/${dir}/${name}${objext}"
300       outS="libgcc/${dir}/${name}_s${objext}"
301
302       echo $outS: $libgcc2_c_dep
303       echo "    $gcc_s_compile" $flags -DL$name \
304         -fexceptions -fnon-call-exceptions -c '$(srcdir)/libgcc2.c' -o $outS
305
306       echo $out: $libgcc2_c_dep
307       echo "    $gcc_compile" $flags -DL$name '$(vis_hide)' \
308         -fexceptions -fnon-call-exceptions -c '$(srcdir)/libgcc2.c' -o $out
309
310       echo $libgcc_a: $out
311       echo $libgcc_s_so: $outS
312       if [ "$SHLIB_MKMAP" ]; then
313         echo libgcc/${dir}/libgcc.map: $outS
314       fi
315     else
316       out="libgcc/${dir}/${name}${objext}"
317       echo ${out}: stmp-dirs '$(srcdir)/config/$(LIB1ASMSRC)'
318       echo "    $gcc_compile" $flags -DL$name \
319         -fexceptions -fnon-call-exceptions -c '$(srcdir)/libgcc2.c' -o $out
320       echo $libgcc_a: $out
321     fi
322   done
323
324   #
325   # Build software floating point functions.
326   #
327
328   for fpbit_var in FPBIT DPBIT TPBIT ; do
329       fpfuncs_var="${fpbit_var}_FUNCS"
330       eval fpbit=\$$fpbit_var
331       eval fpfuncs=\$$fpfuncs_var
332
333       if [ "$fpbit" ] ; then
334           for name in $fpfuncs; do
335               if [ "$libgcc_s_so" ]; then
336                   out="libgcc/${dir}/${name}${objext}"
337                   outS="libgcc/${dir}/${name}_s${objext}"
338
339                   echo $outS: $fpbit $fpbit_c_dep
340                   echo "        $gcc_s_compile" -DFINE_GRAINED_LIBRARIES $flags -DL$name \
341                       -c $fpbit -o $outS
342
343                   echo $out: $fpbit $fpbit_c_dep
344                   echo "        $gcc_compile" -DFINE_GRAINED_LIBRARIES $flags -DL$name \
345                       '$(vis_hide)' -c $fpbit -o $out
346                   
347                   echo $libgcc_a: $out
348                   echo $libgcc_s_so: $outS
349                   if [ "$SHLIB_MKMAP" ]; then
350                       echo libgcc/${dir}/libgcc.map: $outS
351                   fi
352               else
353                   out="libgcc/${dir}/${name}${objext}"
354                   echo $out: $fpbit $fpbit_c_dep
355                   echo "        $gcc_compile" -DFINE_GRAINED_LIBRARIES $flags -DL$name \
356                       -c $fpbit -o $out
357                   
358                   echo $libgcc_a: $out
359               fi
360           done
361       fi
362   done
363
364   if [ "@enable_decimal_float@" = "yes" -a -z "$libgcc_so" ]; then
365     # Bring in the DFP support code if D32PBIT, D64PBIT or D128PBIT are set.
366     if [ -n "$D32PBIT" -o -n "$D64PBIT" -o -n "$D128PBIT" ] ; then
367       dec_filenames="decContext decNumber decRound decLibrary decUtility"
368     fi
369
370     # Only bring in decimal*.c files for types we support.
371     if [ -n "$D32PBIT" ] ; then
372       dec_filenames="$dec_filenames decimal32"
373     fi
374     if [ -n "$D64PBIT" ] ; then
375       dec_filenames="$dec_filenames decimal64"
376     fi
377     if [ -n "$D128PBIT" ] ; then
378       dec_filenames="$dec_filenames decimal128"
379     fi
380
381     for name in $dec_filenames ; do
382       out="libgcc/${dir}/${name}${objext}"
383       echo $out: "\$(srcdir)/../libdecnumber/${name}.c" $decnumber_dep
384       echo "    $gcc_compile" $flags -c "\$(srcdir)/../libdecnumber/${name}.c" -o $out
385       echo $libgcc_a: $out
386     done
387
388     # For individual functions, loop over each variable by name.
389     for dpbit_var in D32PBIT D64PBIT D128PBIT ; do
390       dpfuncs_var="${dpbit_var}_FUNCS"
391       eval dpbit=\$$dpbit_var
392       eval dpfuncs=\$$dpfuncs_var
393
394       if [ "$dpbit" ]; then
395         for name in $dpfuncs; do
396           out="libgcc/${dir}/${name}${objext}"
397           echo $out: $dpbit $fpbit_c_dep
398           echo "        $gcc_compile" -DFINE_GRAINED_LIBRARIES $flags -DL$name \
399             -c $dpbit -o $out
400
401           echo $libgcc_a: $out
402         done
403       fi
404     done
405   fi
406
407   for file in $LIB2ADD; do
408     name=`echo $file | sed -e 's/[.][cS]$//' -e 's/[.]asm$//'`
409     oname=`echo $name | sed -e 's,.*/,,'`
410
411     if [ "$libgcc_s_so" ]; then
412       out="libgcc/${dir}/${oname}${objext}"
413       outS="libgcc/${dir}/${oname}_s${objext}"
414
415       case $file in
416         *.c)
417           echo $outS: stmp-dirs $file $libgcc_dep
418           echo "        $gcc_s_compile" $flags -c $file -o $outS
419
420           echo $out: stmp-dirs $file $libgcc_dep
421           echo "        $gcc_compile" $flags '$(vis_hide)' -c $file -o $out
422         ;;
423
424         *.asm | *.S)
425           outV="libgcc/${dir}/${oname}.vis"
426
427           echo $outS: stmp-dirs $file $libgcc_dep
428           echo "        $gcc_s_compile" $flags -xassembler-with-cpp \
429                  -c $file -o $outS
430
431           echo $out: stmp-dirs $file $libgcc_dep $outV
432           echo "        $gcc_compile" $flags -xassembler-with-cpp \
433                  -include $outV -c $file -o $out
434           echo "${outV}: ${outS}; \$(gen-hide-list)"
435         ;;
436         
437         *)
438           echo "Unhandled extension: $file" >&2
439           exit 1
440         ;;
441       esac
442
443       echo $libgcc_a: $out
444       echo $libgcc_s_so: $outS
445       if [ "$SHLIB_MKMAP" ]; then
446         echo libgcc/${dir}/libgcc.map: $outS
447       fi
448     else
449       out="libgcc/${dir}/${oname}${objext}"
450       case $file in
451         *.c)
452           echo $out: stmp-dirs $file $libgcc_dep
453           echo "        $gcc_compile" $flags -c $file -o $out
454         ;;
455
456         *.asm | *.S)
457           echo $out: stmp-dirs $file $libgcc_dep
458           echo "        $gcc_compile" $flags -xassembler-with-cpp \
459                  -c $file -o $out
460         ;;
461         
462         *)
463           echo "Unhandled extension: $file" >&2
464           exit 1
465         ;;
466       esac
467       
468       echo $libgcc_a: $out
469     fi
470   done
471
472
473   for file in $LIB2ADD_ST; do
474     name=`echo $file | sed -e 's/[.][cSo]$//' -e 's/[.]asm$//'`
475     oname=`echo $name | sed -e 's,.*/,,'`
476     out="libgcc/${dir}/${oname}${objext}"
477
478     case $file in
479       *.c)
480         echo $out: stmp-dirs $file $libgcc_dep
481         echo "  $gcc_compile" $flags '$(vis_hide)' -c $file -o $out
482       ;;
483
484       *.asm | *.S)
485         # We may have to compile it twice in order to establish the list
486         # of symbols to be marked hidden.
487         if [ "$libgcc_so" ]; then
488           outV="libgcc/${dir}/${oname}.vis"
489           outT="libgcc/${dir}/${oname}_t${objext}"
490           echo ${outT}: stmp-dirs $file $libgcc_dep
491           echo "        $gcc_compile" $flags -xassembler-with-cpp \
492                   -c $file -o ${outT}
493           echo $out: stmp-dirs $file $libgcc_dep $outV
494           echo "        $gcc_compile" $flags -xassembler-with-cpp \
495                   -include $outV -c $file -o $out
496           echo "${outV}: ${outT}; \$(gen-hide-list)"
497         else
498           echo $out: stmp-dirs $file $libgcc_dep
499           echo "        $gcc_compile" $flags -xassembler-with-cpp \
500                   -c $file -o $out
501         fi
502       ;;
503
504       *)
505       echo "Unhandled extension: $file" >&2
506       exit 1
507       ;;
508     esac
509     echo $libgcc_a: $out
510   done
511
512   # If we don't have libgcc_eh.a, only LIB2ADDEH matters.  If we do, only
513   # LIB2ADDEHSTATIC and LIB2ADDEHSHARED matter.  (Usually all three are
514   # identical.)
515
516   if [ "$libgcc_eh_a" ]; then
517     for file in $LIB2ADDEHSTATIC; do
518       name=`echo $file | sed -e 's/[.][cSo]$//' -e 's/[.]asm$//'`
519       oname=`echo $name | sed -e 's,.*/,,'`
520       out="libgcc/${dir}/${oname}${objext}"
521
522       case $file in
523         *.c)
524           echo $out: stmp-dirs $file $LIB2ADDEHDEP $libgcc_dep
525           echo "        $gcc_compile" $flags -fexceptions '$(vis_hide)' -c $file -o $out
526           ;;
527         *.asm | *.S)
528           # We have to compile it twice in order to establish the list
529           # of symbols to be marked hidden.
530           outV="libgcc/${dir}/${oname}.vis"
531           outT="libgcc/${dir}/${oname}_t${objext}"
532           echo ${outT}: stmp-dirs $file $LIB2ADDEHDEP $libgcc_dep
533           echo "        $gcc_compile" $flags -xassembler-with-cpp \
534                   -c $file -o ${outT}
535           echo $out: stmp-dirs $file $LIB2ADDEHDEP $libgcc_dep $outV
536           echo "        $gcc_compile" $flags -xassembler-with-cpp \
537                   -include $outV -c $file -o $out
538           echo "${outV}: ${outT}; \$(gen-hide-list)"
539           ;;
540         *)   echo "Unhandled extension: $file">&2; exit 1 ;;
541       esac
542
543       echo $libgcc_eh_a: $out
544     done
545
546     for file in $LIB2ADDEHSHARED; do
547       name=`echo $file | sed -e 's/[.][cSo]$//' -e 's/[.]asm$//'`
548       oname=`echo $name | sed -e 's,.*/,,'`
549       outS="libgcc/${dir}/${oname}_s${objext}"
550
551       case $file in
552         *.c)
553           echo $outS: stmp-dirs $file $LIB2ADDEHDEP $libgcc_dep
554           echo "        $gcc_s_compile" $flags -fexceptions -c $file -o $outS
555           ;;
556         *.asm | *.S)
557           echo $outS: stmp-dirs $file $LIB2ADDEHDEP $libgcc_dep
558           echo "        $gcc_s_compile" $flags -xassembler-with-cpp -c $file -o $outS
559           ;;
560         *)   echo "Unhandled extension: $file">&2; exit 1 ;;
561       esac
562
563       echo $libgcc_s_so: $outS
564       if [ "$SHLIB_MKMAP" ]; then
565         echo libgcc/${dir}/libgcc.map: $outS
566       fi
567     done
568
569     # If nothing went into libgcc_eh.a, create a dummy object -
570     # some linkers don't like totally empty archives.
571     if [ -z "$LIB2ADDEHSTATIC" ]; then
572       file=eh_dummy.c
573       out="libgcc/${dir}/eh_dummy${objext}"
574       need_eh_dummy=1
575
576       echo $out: stmp-dirs $file
577       echo "    $gcc_compile" $flags '$(vis_hide)' -fexceptions -c $file -o $out
578       echo $libgcc_eh_a: $out
579     fi
580    
581
582   else # no libgcc_eh.a
583     for file in $LIB2ADDEH; do
584       name=`echo $file | sed -e 's/[.][cSo]$//' -e 's/[.]asm$//'`
585       oname=`echo $name | sed -e 's,.*/,,'`
586       out="libgcc/${dir}/${oname}${objext}"
587
588       case $file in
589         *.c)
590           echo $out: stmp-dirs $file $LIB2ADDEHDEP $libgcc_dep
591           echo "        $gcc_compile" $flags '$(vis_hide)' -fexceptions -c $file -o $out
592           ;;
593         *.asm | *.S)
594           echo $out: stmp-dirs $file $LIB2ADDEHDEP $libgcc_dep
595           echo "        $gcc_compile" $flags -xassembler-with-cpp \
596                   -c $file -o $out
597           ;;
598         *)   echo "Unhandled extension: $file">&2; exit 1 ;;
599       esac
600
601       echo $libgcc_a: $out
602     done
603   fi
604
605   # We do _not_ handle assembly files in this context.
606   if [ "$LIBUNWIND" ]; then
607     for file in $LIBUNWIND; do
608       case $file in
609         *.c) ;;
610         *)   echo "Unhandled extension: $file">&2; exit 1 ;;
611        esac
612
613       name=`echo $file | sed -e 's/[.]c$//'`
614       oname=`echo $name | sed -e 's,.*/,,'`
615
616       if [ "$libunwind_so" ]; then
617         out="libgcc/${dir}/${oname}${objext}"
618         outS="libgcc/${dir}/${oname}_s${objext}"
619
620         echo $out: stmp-dirs $file $LIBUNWINDDEP
621         echo "  $gcc_compile $flags -fexceptions \$(vis_hide) -c $file -o $out"
622
623         echo $outS: stmp-dirs $file $LIBUNWINDDEP
624         echo "  $gcc_s_compile $flags -fexceptions -c $file -o $outS"
625
626         echo $libunwind_a: $out
627         echo $libunwind_so: $outS
628       else
629         out="libgcc/${dir}/${oname}${objext}"
630         echo $out: stmp-dirs $file $LIBUNWINDDEP
631         echo "  $gcc_compile $flags -fexceptions \$(vis_hide) -c $file -o $out"
632         echo $libunwind_a: $out
633       fi
634     done
635   fi
636
637   #
638   # build libgcov components
639   #
640   for name in $LIBGCOV; do
641     dir=`echo ${ml} | sed -e 's/;.*$//' -e 's/=/$(EQ)/g'`
642     flags=`echo ${ml} | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
643     out="libgcc/${dir}/${name}${objext}"
644
645     echo $out: $libgcov_c_dep
646     echo "      $gcc_compile $flags -DL$name -c \$(srcdir)/libgcov.c -o $out"
647     echo $libgcov_a: $out
648   done
649
650   # EXTRA_MULTILIB_PARTS.
651   if [ -n "$EXTRA_MULTILIB_PARTS" ]; then
652     # Each of the EXTRA_MULTILIB_PARTS is built by recursive invocation
653     # of the parent Makefile.  We must do this just once for each
654     # multilib, passing it all the EXTRA_MULTILIB_PARTS as
655     # simultaneous goal targets, so that rules which cannot execute
656     # simultaneously are properly serialized.
657     
658     extra=
659     echo
660     for f in $EXTRA_MULTILIB_PARTS; do
661       case $dir in
662       .) out=$f ; t= ;;
663       *) out=$dir/$f ; t=$dir/ ;;
664       esac
665       case $out in
666       # Prevent `make' from interpreting $out as a macro assignment
667       *'$(EQ)'*) targ="T_TARGET=$out T_TARGET" ;;
668       *) targ=$out ;;
669       esac
670       extra="$extra $targ"
671     done
672
673     if [ "$dir" = . ]; then
674       suffix=
675     else
676       suffix=`echo $dir | sed s,/,_,g`
677     fi
678     echo extra$suffix: stmp-dirs
679     echo "      $make_compile" \\
680     echo '        LIBGCC2_CFLAGS="$(LIBGCC2_CFLAGS)' $flags '" ' \\
681     echo '        MULTILIB_CFLAGS="'$flags'"' T=$t $extra
682     echo "all: extra$suffix"
683
684     # Make libunwind.so and libgcc_s.so depend on these, since they
685     # are likely to be implicitly used by the link process.
686     if [ "$libgcc_s_so" ]; then
687       echo "$libgcc_s_so: extra$suffix"
688     fi
689     if [ "$libunwind_so" ]; then
690       echo "$libunwind_so: extra$suffix"
691     fi
692   fi
693
694   # Library build rules.
695   dir=`echo ${ml} | sed -e 's/;.*$//' -e 's/=/$(EQ)/g'`
696   flags=`echo ${ml} | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
697
698   # Map-file generation.
699   if [ "$SHLIB_LINK" -a "$SHLIB_MKMAP" ]; then
700     mapfile="libgcc/${dir}/libgcc.map"
701     tmpmapfile="libgcc/${dir}/tmp-libgcc.map"
702     # This uses a here document instead of echos because some shells
703     # will convert the \1 in the second sed command to a control-A.
704     # The behavior of here documents is more predictable.
705     cat <<EOF
706
707 ${mapfile}: $SHLIB_MKMAP $SHLIB_MAPFILES
708         { \$(NM_FOR_TARGET) $SHLIB_NM_FLAGS \$(objects); echo %%; \\
709           cat $SHLIB_MAPFILES \\
710             | sed -e '/^[   ]*#/d' \\
711                   -e 's/^%\(if\|else\|elif\|endif\|define\)/#\1/' \\
712             | $gcc_compile $flags -E -xassembler-with-cpp -; \\
713         } | \$(AWK) -f $SHLIB_MKMAP $SHLIB_MKMAP_OPTS > ${tmpmapfile}
714         mv '$tmpmapfile' \$@
715 $libgcc_s_so: ${mapfile}
716 EOF
717   fi
718
719   # Static libraries.
720
721   # Each of these .a files depends on stmp-dirs.  It would seem that
722   # this dependency is redundant, since each of the object files
723   # itself depends on stmp-dirs.  However, it is possible that there
724   # are in fact no object files.  In that case, the stmp-dirs
725   # dependency is required; the directory containing the archive must
726   # exist before the archive itself can be created.
727   echo ""
728   echo "$libgcc_a: stmp-dirs"
729   echo "        -rm -f $libgcc_a"
730   echo '        $(AR_CREATE_FOR_TARGET)' $libgcc_a '$(objects)'
731   echo '        $(RANLIB_FOR_TARGET)' $libgcc_a
732   echo "all: $libgcc_a"
733
734   echo ""
735   echo "$libgcov_a: stmp-dirs"
736   echo "        -rm -f $libgcov_a"
737   echo '        $(AR_CREATE_FOR_TARGET)' $libgcov_a '$(objects)'
738   echo '        $(RANLIB_FOR_TARGET)' $libgcov_a
739   echo "all: $libgcov_a"
740
741   # These libraries are not always built.
742   if [ "$libunwind_a" ]; then
743     echo ""
744     echo "$libunwind_a: stmp-dirs"
745     echo "      -rm -f $libunwind_a"
746     echo '      $(AR_CREATE_FOR_TARGET)' $libunwind_a '$(objects)'
747     echo '      $(RANLIB_FOR_TARGET)' $libunwind_a
748     echo "all: $libunwind_a"
749   fi
750
751   if [ "$libgcc_eh_a" ]; then
752     echo ""
753     echo "${dir}/libgcc_eh.a: stmp-dirs"
754     echo "      -rm -f ${dir}/libgcc_eh.a"
755     echo '      $(AR_CREATE_FOR_TARGET)' ${dir}/libgcc_eh.a '$(objects)'
756     echo '      $(RANLIB_FOR_TARGET)' ${dir}/libgcc_eh.a
757     echo "all: $libgcc_eh_a"
758   fi
759
760   # Shared libraries.
761   if [ "$libgcc_s_so" ]; then
762     echo ""
763     echo "$libgcc_s_so: stmp-dirs $libunwind_so"
764     echo "      $SHLIB_LINK" \
765          | sed -e "s%@multilib_flags@%$flags%g" \
766                -e "s%@multilib_dir@%$dir%g" \
767                -e "s%@shlib_objs@%\$(objects)%g" \
768                -e "s%@shlib_base_name@%libgcc_s%g" \
769                -e "s%@shlib_map_file@%$mapfile%g" \
770                -e "s%@shlib_slibdir_qual@%$shlib_dir_qual%g"
771     echo "all: $libgcc_s_so"
772   fi
773
774   if [ "$libunwind_so" ]; then
775     echo ""
776     echo "$libunwind_so: stmp-dirs"
777     echo "      $SHLIBUNWIND_LINK" \
778            | sed -e "s%@multilib_flags@%$flags%g" \
779                  -e "s%@multilib_dir@%$dir%g" \
780                  -e "s%@shlib_objs@%\$(objects)%g" \
781                  -e "s%@shlib_base_name@%libunwind%g" \
782                  -e "s%@shlib_slibdir_qual@%$shlib_dir_qual%g"
783     echo "all: $libunwind_so"
784   fi
785
786 done # ml in MULTILIBS
787
788 echo
789 echo "libgcc-stage-start:"
790 echo "  for dir in \$(dirs); do \\"
791 echo "    if [ -d \$(stage)/\$\$dir ]; then :; \\"
792 echo "    else $mkinstalldirs \$(stage)/\$\$dir; fi; \\"
793 echo "  done"
794 echo "  -for dir in \$(dirs); do \\"
795 echo "    mv \$\$dir/*${objext} \$(stage)/\$\$dir; \\"
796 echo "    mv \$\$dir/*.vis \$(stage)/\$\$dir; \\"
797 echo "    mv \$\$dir/*.map \$(stage)/\$\$dir; \\"
798 echo "    test ! -f \$\$dir/libgcc.a || mv \$\$dir/lib* \$(stage)/\$\$dir; \\"
799 echo "  done"
800
801 echo 
802 echo "stmp-dirs:"
803 echo "  for d in \$(dirs); do \\"
804 echo "    if [ -d \$\$d ]; then true; else $mkinstalldirs \$\$d; fi; \\"
805 echo "  done"
806 echo "  if [ -f stmp-dirs ]; then true; else touch stmp-dirs; fi"
807
808 if [ "$need_eh_dummy" ]; then
809   echo "eh_dummy.c:"
810   echo "        echo 'int __libgcc_eh_dummy;' > \$@"
811 fi
812
813 echo ""
814 echo "install: all"
815 for ml in $MULTILIBS; do
816   dir=`echo ${ml} | sed -e 's/;.*$//' -e 's/=/$(EQ)/g'`
817   flags=`echo ${ml} | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
818   if [ $dir != . ]; then
819     ldir='$(DESTDIR)$(libsubdir)'/$dir
820     echo "      if [ -d $ldir ]; then true; else $mkinstalldirs $ldir; chmod a+rx $ldir; fi;"
821   else
822     ldir='$(DESTDIR)$(libsubdir)'
823   fi
824   echo '        $(INSTALL_DATA)' ${dir}/libgcc.a ${ldir}/
825   echo '        $(RANLIB_FOR_TARGET)' ${ldir}/libgcc.a
826   echo '        $(INSTALL_DATA)' ${dir}/libgcov.a ${ldir}/
827   echo '        $(RANLIB_FOR_TARGET)' ${ldir}/libgcov.a
828
829   if [ "$SHLIB_LINK" ]; then
830     echo '      $(INSTALL_DATA)' ${dir}/libgcc_eh.a ${ldir}/
831     echo '      $(RANLIB_FOR_TARGET)' ${ldir}/libgcc_eh.a
832
833     shlib_slibdir_qual=
834     os_multilib_dir=`$GCC_FOR_TARGET $flags --print-multi-os-directory`
835     if [ "$os_multilib_dir" != . ]; then
836       shlib_slibdir_qual="/$os_multilib_dir"
837     fi
838     echo "      $SHLIB_INSTALL" \
839       | sed -e "s%@multilib_dir@%$dir%g" \
840             -e "s%@shlib_base_name@%libgcc_s%g" \
841             -e "s%@shlib_slibdir_qual@%$shlib_slibdir_qual%g"
842     if [ "$LIBUNWIND" ]; then
843       echo "    $SHLIBUNWIND_INSTALL" \
844         | sed -e "s%@multilib_dir@%$dir%g" \
845               -e "s%@shlib_base_name@%libunwind%g" \
846               -e "s%@shlib_slibdir_qual@%$shlib_slibdir_qual%g"
847       libunwinddir='$(DESTDIR)$(slibdir)$(shlib_slibdir_qual)/$(shlib_dir)'
848       echo '    $(INSTALL_DATA)' ${dir}/libunwind.a ${libunwinddir}/
849       echo '    $(RANLIB_FOR_TARGET)' ${libunwinddir}/libunwind.a
850     fi
851   fi
852 done
853 for f in $EXTRA_MULTILIB_PARTS; do
854   for ml in $MULTILIBS; do
855     dir=`echo ${ml} | sed -e 's/;.*$//' -e 's/=/$(EQ)/g'`
856     if [ $dir != . ]; then
857       out=${dir}/$f
858       ldir='$(DESTDIR)$(libsubdir)'/$dir
859     else
860       out=$f
861       ldir='$(DESTDIR)$(libsubdir)'
862     fi
863     echo '      $(INSTALL_DATA)' $out $ldir/
864   done
865 done
866
867 echo '.PHONY: all install'