OSDN Git Service

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