OSDN Git Service

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