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