aboutsummaryrefslogtreecommitdiff
path: root/gcc/mklibgcc.in
blob: 28ea8532fa70cea20065a0e66772fa9d012bbde6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
#!/bin/sh
# Construct makefile for libgcc.
#   Copyright (C) 2000, 2002, 2003 Free Software Foundation, Inc.
#
# This file is part of GCC.

# Arguments, taken from the environment, since there are a lot
# of them, and positional args becomes quite ugly.
#
# objext
# LIB1ASMFUNCS
# LIB2FUNCS_ST
# LIBGCOV
# LIB2ADD
# LIB2ADD_ST 
# LIB2ADDEH
# LIB2ADDEHDEP
# FPBIT
# FPBIT_FUNCS
# LIB2_DIVMOD_FUNCS
# DPBIT
# DPBIT_FUNCS
# TPBIT
# TPBIT_FUNCS
# LIBGCC
# MULTILIBS
# EXTRA_MULTILIB_PARTS
# SHLIB_EXT
# SHLIB_LINK
# SHLIB_MULTILIB
# SHLIB_MKMAP
# SHLIB_MKMAP_OPTS
# SHLIB_MAPFILES
# SHLIB_NM_FLAGS
# SHLIB_INSTALL
# MULTILIB_OSDIRNAMES

# Make needs VPATH to be literal.
echo 'srcdir = @srcdir@'
echo 'VPATH = @srcdir@'
echo 'EQ = ='
echo
echo 'force:'
echo

# Library members defined in libgcc2.c.
lib2funcs='_muldi3 _negdi2 _lshrdi3 _ashldi3 _ashrdi3
	_cmpdi2 _ucmpdi2 _floatdidf _floatdisf _fixunsdfsi _fixunssfsi
	_fixunsdfdi _fixdfdi _fixunssfdi _fixsfdi _fixxfdi _fixunsxfdi
	_floatdixf _fixunsxfsi _fixtfdi _fixunstfdi _floatditf _clear_cache
	_trampoline __main _absvsi2 _absvdi2 _addvsi3 _addvdi3
	_subvsi3 _subvdi3 _mulvsi3 _mulvdi3 _negvsi2 _negvdi2 _ctors
	_ffssi2 _ffsdi2 _clz _clzsi2 _clzdi2 _ctzsi2 _ctzdi2 _popcount_tab
	_popcountsi2 _popcountdi2 _paritysi2 _paritydi2'

# Disable SHLIB_LINK if shared libgcc not enabled.
if [ "@enable_shared@" = "no" ]; then
  SHLIB_LINK=""
fi

# Build lines.

gcc_compile='$(GCC_FOR_TARGET) $(LIBGCC2_CFLAGS) $(INCLUDES)'
make_compile='$(MAKE) GCC_FOR_TARGET="$(GCC_FOR_TARGET)" \
	  AR_FOR_TARGET="$(AR_FOR_TARGET)" \
	  AR_CREATE_FOR_TARGET="$(AR_CREATE_FOR_TARGET)" \
	  AR_EXTRACT_FOR_TARGET="$(AR_EXTRACT_FOR_TARGET)" \
	  AR_FLAGS_FOR_TARGET="$(AR_FLAGS_FOR_TARGET)" \
	  CC="$(CC)" CFLAGS="$(CFLAGS)" \
	  BUILD_PREFIX="$(BUILD_PREFIX)" \
	  BUILD_PREFIX_1="$(BUILD_PREFIX_1)" \
	  LANGUAGES="$(LANGUAGES)"'

# Dependencies for libgcc2.c
libgcc2_c_dep='stmp-dirs $(srcdir)/libgcc2.c $(CONFIG_H) coretypes.h $(TM_H) $(MACHMODE_H) longlong.h gbl-ctors.h config.status stmp-int-hdrs tsystem.h'" $LIB2ADDEHDEP"

# Dependencies for libgcov.c
libgcov_c_dep='stmp-dirs $(srcdir)/libgcov.c $(CONFIG_H) coretypes.h $(TM_H) $(MACHMODE_H) longlong.h gbl-ctors.h config.status stmp-int-hdrs tsystem.h $(srcdir)/gcov-io.h $(srcdir)/gcov-io.c gcov-iov.h'

# Dependencies for fp-bit.c
fpbit_c_dep='stmp-dirs config.status tsystem.h'

#
# Build libgcc1 components.
#

libgcc1_objs=""

for name in $LIB1ASMFUNCS; do
  for ml in $MULTILIBS; do
    dir=`echo ${ml} | sed -e 's/;.*$//' -e 's/=/$(EQ)/g'`
    flags=`echo ${ml} | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
    out="libgcc/${dir}/${name}${objext}"

    echo ${out}: stmp-dirs '$(srcdir)/config/$(LIB1ASMSRC)'
    echo "	$gcc_compile" $flags -DL$name -xassembler-with-cpp \
	  -c '$(srcdir)/config/$(LIB1ASMSRC)' -o $out

    # Remove any objects from lib2funcs and LIB2_DIVMOD_FUNCS that are
    # defined as optimized assembly code in LIB1ASMFUNCS.
    lib2funcs=`echo $lib2funcs | sed -e 's/^'$name' //' \
				     -e 's/ '$name' / /' \
				     -e 's/ '$name'$//'`
    LIB2_DIVMOD_FUNCS=`echo $LIB2_DIVMOD_FUNCS | sed -e 's/^'$name' //' \
				                     -e 's/ '$name' / /' \
				                     -e 's/ '$name'$//'`
  done
  libgcc1_objs="$libgcc1_objs ${name}${objext}"
done

#
# Build libgcc2 components.
#

libgcc2_objs=""
libgcc2_st_objs=""
libgcc2_eh_objs=""

for name in $lib2funcs; do
  for ml in $MULTILIBS; do
    dir=`echo ${ml} | sed -e 's/;.*$//' -e 's/=/$(EQ)/g'`
    flags=`echo ${ml} | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
    out="libgcc/${dir}/${name}${objext}"

    echo $out: $libgcc2_c_dep
    echo "	$gcc_compile" '$(MAYBE_USE_COLLECT2)' $flags -DL$name \
      -c '$(srcdir)/libgcc2.c' -o $out
  done
  libgcc2_objs="$libgcc2_objs ${name}${objext}"
done

for name in $LIB2FUNCS_ST; do
  for ml in $MULTILIBS; do
    dir=`echo ${ml} | sed -e 's/;.*$//' -e 's/=/$(EQ)/g'`
    flags=`echo ${ml} | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
    out="libgcc/${dir}/${name}${objext}"

    echo $out: $libgcc2_c_dep
    echo "	$gcc_compile" '$(MAYBE_USE_COLLECT2)' $flags -DL$name \
      -c '$(srcdir)/libgcc2.c' -o $out
  done
  libgcc2_st_objs="$libgcc2_st_objs ${name}${objext}"
done

for name in $LIB2_DIVMOD_FUNCS; do
  for ml in $MULTILIBS; do
    dir=`echo ${ml} | sed -e 's/;.*$//' -e 's/=/$(EQ)/g'`
    flags=`echo ${ml} | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
    out="libgcc/${dir}/${name}${objext}"

    echo $out: $libgcc2_c_dep
    echo "	$gcc_compile" '$(MAYBE_USE_COLLECT2)' $flags -DL$name \
      -c '$(srcdir)/libgcc2.c' -fexceptions -fnon-call-exceptions -o $out
  done
  libgcc2_objs="$libgcc2_objs ${name}${objext}"
done

if [ "$FPBIT" ]; then
  for name in $FPBIT_FUNCS; do
    for ml in $MULTILIBS; do
      dir=`echo ${ml} | sed -e 's/;.*$//' -e 's/=/$(EQ)/g'`
      flags=`echo ${ml} | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
      out="libgcc/${dir}/${name}${objext}"

      echo $out: $FPBIT $fpbit_c_dep
      echo "	$gcc_compile" -DFINE_GRAINED_LIBRARIES $flags -DL$name \
	-c $FPBIT -o $out
    done
    libgcc2_objs="$libgcc2_objs ${name}${objext}"
  done
fi

if [ "$DPBIT" ]; then
  for name in $DPBIT_FUNCS; do
    for ml in $MULTILIBS; do
      dir=`echo ${ml} | sed -e 's/;.*$//' -e 's/=/$(EQ)/g'`
      flags=`echo ${ml} | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
      out="libgcc/${dir}/${name}${objext}"

      echo $out: $DPBIT $fpbit_c_dep
      echo "	$gcc_compile" -DFINE_GRAINED_LIBRARIES $flags -DL$name \
	-c $DPBIT -o $out
    done
    libgcc2_objs="$libgcc2_objs ${name}${objext}"
  done
fi

if [ "$TPBIT" ]; then
  for name in $TPBIT_FUNCS; do
    for ml in $MULTILIBS; do
      dir=`echo ${ml} | sed -e 's/;.*$//' -e 's/=/$(EQ)/g'`
      flags=`echo ${ml} | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
      out="libgcc/${dir}/${name}${objext}"

      echo $out: $TPBIT $fpbit_c_dep
      echo "	$gcc_compile" -DFINE_GRAINED_LIBRARIES $flags -DL$name \
	-c $TPBIT -o $out
    done
    libgcc2_objs="$libgcc2_objs ${name}${objext}"
  done
fi

for file in $LIB2ADD; do
  name=`echo $file | sed -e 's/[.][cSo]$//' -e 's/[.]asm$//' -e 's/[.]txt$//'`
  oname=`echo $name | sed -e 's,.*/,,'`

  for ml in $MULTILIBS; do
    dir=`echo ${ml} | sed -e 's/;.*$//' -e 's/=/$(EQ)/g'`
    flags=`echo ${ml} | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
    out="libgcc/${dir}/${oname}${objext}"
    if [ ${name}.asm = ${file} ]; then
      flags="$flags -xassembler-with-cpp"
    fi

    echo $out: stmp-dirs $file
    echo "	$gcc_compile" $flags -c $file -o $out
  done
  libgcc2_objs="$libgcc2_objs ${oname}${objext}"
done

for file in $LIB2ADDEH; do
  name=`echo $file | sed -e 's/[.][cSo]$//' -e 's/[.]asm$//' -e 's/[.]txt$//'`
  oname=`echo $name | sed -e 's,.*/,,'`

  for ml in $MULTILIBS; do
    dir=`echo ${ml} | sed -e 's/;.*$//' -e 's/=/$(EQ)/g'`
    flags=`echo ${ml} | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
    out="libgcc/${dir}/${oname}${objext}"
    if [ ${name}.asm = ${file} ]; then
      flags="$flags -xassembler-with-cpp"
    fi

    echo $out: stmp-dirs $file
    echo "	$gcc_compile" $flags -fexceptions -c $file -o $out
  done
  if [ "$SHLIB_LINK" ]; then
    libgcc2_eh_objs="$libgcc2_eh_objs ${oname}${objext}"
  else
    libgcc2_objs="$libgcc2_objs ${oname}${objext}"
  fi
done

for file in $LIB2ADD_ST; do
  name=`echo $file | sed -e 's/[.][cSo]$//' -e 's/[.]asm$//' -e 's/[.]txt$//'`
  oname=`echo $name | sed -e 's,.*/,,'`

  for ml in $MULTILIBS; do
    dir=`echo ${ml} | sed -e 's/;.*$//' -e 's/=/$(EQ)/g'`
    flags=`echo ${ml} | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
    out="libgcc/${dir}/${oname}${objext}"
    if [ ${name}.asm = ${file} ]; then
      flags="$flags -xassembler-with-cpp"
    fi

    echo $out: stmp-dirs $file
    echo "	$gcc_compile" $flags -c $file -o $out
  done
  libgcc2_st_objs="$libgcc2_st_objs ${oname}${objext}"
done

#
# build libgcov components
#

libgcov_objs=""

for name in $LIBGCOV; do
  for ml in $MULTILIBS; do
    dir=`echo ${ml} | sed -e 's/;.*$//' -e 's/=/$(EQ)/g'`
    flags=`echo ${ml} | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
    out="libgcc/${dir}/${name}${objext}"

    echo $out: $libgcov_c_dep
    echo "	$gcc_compile" '$(MAYBE_USE_COLLECT2)' $flags -DL$name \
      -c '$(srcdir)/libgcov.c' -o $out
  done
  libgcov_objs="$libgcov_objs ${name}${objext}"
done

# SHLIB_MKMAP
# SHLIB_MKMAP_OPTS
# SHLIB_MAPFILES
for ml in $MULTILIBS; do
  dir=`echo ${ml} | sed -e 's/;.*$//' -e 's/=/$(EQ)/g'`
  flags=`echo ${ml} | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;

  libgcc_objs=""
  libgcc_eh_objs=""
  for o in $libgcc1_objs; do
    libgcc_objs="$libgcc_objs libgcc/${dir}/$o"
  done
  for o in $libgcc2_objs; do
    libgcc_objs="$libgcc_objs libgcc/${dir}/$o"
  done
  for o in $libgcc2_eh_objs; do
    libgcc_eh_objs="$libgcc_eh_objs libgcc/${dir}/$o"
  done
  libgcc_sh_objs="$libgcc_objs $libgcc_eh_objs"
  shlib_deps="$libgcc_sh_objs"

  libgcc_st_objs=""
  for o in $libgcc2_st_objs; do
    libgcc_st_objs="$libgcc_st_objs libgcc/${dir}/$o"
  done

  libgcov_a_objs=""
  for o in $libgcov_objs; do
    libgcov_a_objs="$libgcov_a_objs libgcc/${dir}/$o"
  done
  
  if [ "$SHLIB_LINK" -a "$SHLIB_MKMAP" ]; then
    mapfile="libgcc/${dir}/libgcc.map"
    tmpmapfile="libgcc/${dir}/tmp-libgcc.map"
    # This uses a here document instead of echos because some shells
    # will convert the \1 in the second sed command to a control-A.
    # The behavior of here documents is more predictable.
    cat <<EOF

${mapfile}: $SHLIB_MKMAP $SHLIB_MAPFILES $libgcc_sh_objs
	{ \$(NM_FOR_TARGET) $SHLIB_NM_FLAGS $libgcc_sh_objs; echo %%; \\
	  cat $SHLIB_MAPFILES \\
	    | sed -e '/^[   ]*#/d' \\
	          -e 's/^%\(if\|else\|elif\|endif\|define\)/#\1/' \\
	    | $gcc_compile $flags -E -xassembler-with-cpp -; \\
	} | \$(AWK) -f $SHLIB_MKMAP $SHLIB_MKMAP_OPTS > ${tmpmapfile}
	mv '$tmpmapfile' \$@
EOF
  fi
  shlib_deps="$shlib_deps $mapfile"

  # Depend on EXTRA_MULTILIB_PARTS, since that's where crtbegin/end
  # usually are put in a true multilib situation.
  for f in $EXTRA_MULTILIB_PARTS; do
    shlib_deps="$shlib_deps $dir/$f"
  done

  libgcc_a_objs="$libgcc_objs $libgcc_st_objs"

  if [ "@libgcc_visibility@" = yes -a "$SHLIB_LINK" ]; then
    libgcc_a_objs=
    echo ""
    echo "libgcc/${dir}/stacknote.s: stmp-dirs"
    echo '	@( echo | $(GCC_FOR_TARGET) $(LIBGCC2_CFLAGS) '${flags}' -S -o - -xc - | grep .note.GNU-stack || : ) > $@.tmp'
    echo '	@mv -f $@.tmp $@'
    echo ""
    for o in $libgcc_objs $libgcc_st_objs; do
      # .oS objects will have all non-local symbol definitions .hidden
      oS=`echo ${o} | sed s~${objext}'$~.oS~g'`
      echo "${oS}: stmp-dirs libgcc/${dir}/stacknote.s ${o}"
      # non-GNU nm emits three fields even for undefined and typeless symbols,
      # so explicitly omit them
      echo '	( $(NM_FOR_TARGET) '${SHLIB_NM_FLAGS} ${o}' | $(AWK) '\''NF == 3 && $$2 !~ /^[UN]$$/ { print "\t.hidden", $$3 }'\''; cat libgcc/${dir}/stacknote.s ) | $(GCC_FOR_TARGET) $(LIBGCC2_CFLAGS) '${flags}' -r -nostdinc -nostdlib -o $@ '${o}' -xassembler -'
      libgcc_a_objs="${libgcc_a_objs} ${oS}"
    done
  fi

  # Each of these .a files depends on stmp-dirs.  It would seem that
  # this dependency is redundant, since each of the object files
  # itself depends on stmp-dirs.  However, it is possible that there
  # are in fact no object files.  In that case, the stmp-dirs
  # dependency is required; the directory containing the archive must
  # exist before the archive itself can be created.
  echo ""
  echo "${dir}/libgcc.a: stmp-dirs $libgcc_a_objs"
  echo "	-rm -rf ${dir}/libgcc.a"
  echo '	$(AR_CREATE_FOR_TARGET)' ${dir}/libgcc.a $libgcc_a_objs
  echo '	$(RANLIB_FOR_TARGET)' ${dir}/libgcc.a

  echo ""
  echo "${dir}/libgcov.a: stmp-dirs $libgcov_a_objs"
  echo "	-rm -rf ${dir}/libgcov.a"
  echo '	$(AR_CREATE_FOR_TARGET)' ${dir}/libgcov.a $libgcov_a_objs
  echo '	$(RANLIB_FOR_TARGET)' ${dir}/libgcov.a

  if [ "$SHLIB_LINK" ]; then

    echo ""
    echo "${dir}/libgcc_eh.a: stmp-dirs $libgcc_eh_objs"
    echo "	-rm -rf ${dir}/libgcc_eh.a"
    echo '	$(AR_CREATE_FOR_TARGET)' ${dir}/libgcc_eh.a $libgcc_eh_objs
    echo '	$(RANLIB_FOR_TARGET)' ${dir}/libgcc_eh.a

    if [ -z "$SHLIB_MULTILIB" ]; then
      if [ "$dir" = . ]; then
	shlib_base_name=libgcc_s
      else
	shlib_base_name=libgcc_s_`echo $dir | sed s,/,_,g`
      fi
      shlib_so_name="$shlib_base_name"
      shlib_dir=
      if [ -n "$MULTILIB_OSDIRNAMES" ]; then
	if [ "$dir" != . ]; then
	  gcc_multilib_dir=`./xgcc -B./ $flags --print-multi-directory`
	  os_multilib_dir=`./xgcc -B./ $flags --print-multi-os-directory`
	  shlib_dir="$dir"/
	  gcc_multilib_sup=`echo $gcc_multilib_dir | sed 's~^[^/]*/~~'`
	  os_multilib_base=`echo $os_multilib_dir | sed -n "s~/${gcc_multilib_sup}\$~~p"`
	  if [ -z "$os_multilib_base" ]; then
	    shlib_so_name=libgcc_s
	  else
	    shlib_so_name=libgcc_s_`echo $gcc_multilib_sup | sed s,/,_,g`
	  fi
	fi
      fi
      echo ""
      echo "${dir}/${shlib_base_name}${SHLIB_EXT}: $shlib_deps"
      echo "	$SHLIB_LINK" \
	 | sed -e "s%@multilib_flags@%$flags%g" \
	       -e "s%@multilib_dir@%$dir%g" \
	       -e "s%@shlib_objs@%$libgcc_sh_objs%g" \
	       -e "s%@shlib_base_name@%$shlib_base_name%g" \
	       -e "s%@shlib_map_file@%$mapfile%g" \
	       -e "s%@shlib_so_name@%$shlib_so_name%g" \
	       -e "s%@shlib_dir@%$shlib_dir%g"
    elif [ "$SHLIB_MULTILIB" = "$dir" ]; then
      shlib_base_name="libgcc_s";
      echo ""
      echo "${shlib_base_name}${SHLIB_EXT}: $shlib_deps"
      echo "	$SHLIB_LINK" \
	 | sed -e "s%@multilib_flags@%$flags%g" \
	       -e "s%@multilib_dir@%$dir%g" \
	       -e "s%@shlib_objs@%$libgcc_sh_objs%g" \
	       -e "s%@shlib_base_name@%$shlib_base_name%g" \
	       -e "s%@shlib_map_file@%$mapfile%g" \
	       -e "s%@shlib_so_name@%$shlib_base_name%g" \
	       -e "s%@shlib_dir@%%g"
    fi
  fi
done

dirs=libgcc
for ml in $MULTILIBS; do
  dir=`echo ${ml} | sed -e 's/;.*$//' -e 's/=/$(EQ)/g'`
  if [ $dir != . ]; then
    dirs="$dirs ${dir} libgcc/${dir}"
  fi
done
echo ''
echo 'libgcc-stage-start:'
echo '	for dir in '"${dirs}"'; do \'
echo '	  if [ -d $(stage)/$$dir ]; then true; else '$mkinstalldirs' $(stage)/$$dir; fi; \'
echo '	done'
echo '	-for dir in '"${dirs}"'; do \'
echo '	  mv $$dir/*'"${objext}"' $(stage)/$$dir; \'
echo '	  test ! -f $$dir/stacknote.s || mv $$dir/stacknote.s $(stage)/$$dir; \'
echo '	  test ! -f $$dir/libgcc.a || mv $$dir/lib* $(stage)/$$dir; \'
echo '	done'

echo ""
all=stmp-dirs
dirs=libgcc

for ml in $MULTILIBS; do
  dir=`echo ${ml} | sed -e 's/;.*$//' -e 's/=/$(EQ)/g'`
  if [ $dir != . ]; then
    dirs="$dirs ${dir} libgcc/${dir}"
  fi
  all="$all ${dir}/libgcc.a ${dir}/libgcov.a"
  if [ "$SHLIB_LINK" ]; then
    all="$all ${dir}/libgcc_eh.a"
    if [ -z "$SHLIB_MULTILIB" ]; then
      if [ "$dir" = "." ]; then
	suff="";
      else
	suff=_`echo $dir | sed s,/,_,g`
      fi
      all="$all ${dir}/libgcc_s${suff}${SHLIB_EXT}"
    elif [ "$SHLIB_MULTILIB" = "$dir" ]; then
      all="$all libgcc_s${SHLIB_EXT}"
    fi
  fi
done

echo 'stmp-dirs: force'
echo '	for d in '"$dirs"'; do \'
echo '	  if [ -d $$d ]; then true; else '$mkinstalldirs' $$d; fi; \'
echo '	done'
echo '	if [ -f stmp-dirs ]; then true; else touch stmp-dirs; fi'

for f in $EXTRA_MULTILIB_PARTS; do
  for ml in $MULTILIBS; do
    dir=`echo ${ml} | sed -e 's/;.*$//' -e 's/=/$(EQ)/g'`
    flags=`echo ${ml} | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
    case $dir in
    .) out=$f ; t= ;;
    *) out=$dir/$f ; t=$dir/ ;;
    esac
    case $out in
    # Prevent `make' from interpreting $out as a macro assignment
    *'$(EQ)'*) targ="T_TARGET=$out T_TARGET" ;;
    *) targ=$out ;;
    esac

    echo $out: stmp-dirs
    echo "	$make_compile" \\
    echo '	  LIBGCC2_CFLAGS="$(LIBGCC2_CFLAGS)' $flags '" ' \\
    echo '	  MULTILIB_CFLAGS="'$flags'"' T=$t $targ

    all="$all $out"
  done
done

echo ""
echo "all: $all"

echo ""
echo "install: $all"
for ml in $MULTILIBS; do
  dir=`echo ${ml} | sed -e 's/;.*$//' -e 's/=/$(EQ)/g'`
  flags=`echo ${ml} | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
  if [ $dir != . ]; then
    ldir='$(DESTDIR)$(libsubdir)'/$dir
    echo "	if [ -d $ldir ]; then true; else $mkinstalldirs $ldir; chmod a+rx $ldir; fi;"
  else
    ldir='$(DESTDIR)$(libsubdir)'
  fi
  echo '	$(INSTALL_DATA)' ${dir}/libgcc.a ${ldir}/
  echo '	$(RANLIB_FOR_TARGET)' ${ldir}/libgcc.a
  echo '	$(INSTALL_DATA)' ${dir}/libgcov.a ${ldir}/
  echo '	$(RANLIB_FOR_TARGET)' ${ldir}/libgcov.a

  if [ "$SHLIB_LINK" ]; then
    echo '	$(INSTALL_DATA)' ${dir}/libgcc_eh.a ${ldir}/
    echo '	$(RANLIB_FOR_TARGET)' ${ldir}/libgcc_eh.a

    if [ -z "$SHLIB_MULTILIB" ]; then
      if [ "$dir" = . ]; then
	shlib_base_name=libgcc_s
      else
	shlib_base_name=libgcc_s_`echo $dir | sed s,/,_,g`
      fi
      shlib_so_name="$shlib_base_name"
      shlib_dir=
      shlib_slibdir_qual=
      if [ -n "$MULTILIB_OSDIRNAMES" ]; then
	gcc_multilib_dir=`./xgcc -B./ $flags --print-multi-directory`
	os_multilib_dir=`./xgcc -B./ $flags --print-multi-os-directory`
	if [ "$dir" != . ]; then
	  shlib_dir="$dir"/
	fi
	gcc_multilib_sup=`echo $gcc_multilib_dir | sed 's~^[^/]*/~~'`
	os_multilib_base=`echo $os_multilib_dir | sed -n "s~/${gcc_multilib_sup}\$~~p"`
	if [ -z "$os_multilib_base" ]; then
	  shlib_so_name=libgcc_s
	  if [ "$os_multilib_dir" != "." ]; then
	    shlib_slibdir_qual="/$os_multilib_dir"
	  fi
	else
	  shlib_so_name=libgcc_s_`echo $gcc_multilib_sup | sed s,/,_,g`
	  shlib_slibdir_qual="/$os_multilib_base"
	fi
      fi
      echo "	$SHLIB_INSTALL" \
	| sed -e "s%@shlib_base_name@%$shlib_base_name%g" \
	      -e "s%@shlib_so_name@%$shlib_so_name%g" \
	      -e "s%@shlib_dir@%$shlib_dir%g" \
	      -e "s%@shlib_slibdir_qual@%$shlib_slibdir_qual%g"
    elif [ "$SHLIB_MULTILIB" = "$dir" ]; then
      shlib_base_name="libgcc_s";
      echo "	$SHLIB_INSTALL" \
	| sed -e "s%@shlib_base_name@%$shlib_base_name%g" \
	      -e "s%@shlib_so_name@%$shlib_base_name%g" \
	      -e "s%@shlib_dir@%%g" \
	      -e "s%@shlib_slibdir_qual@%%g"
    fi
  fi
done
for f in $EXTRA_MULTILIB_PARTS; do
  for ml in $MULTILIBS; do
    dir=`echo ${ml} | sed -e 's/;.*$//' -e 's/=/$(EQ)/g'`
    if [ $dir != . ]; then
      out=${dir}/$f
      ldir='$(DESTDIR)$(libsubdir)'/$dir
    else
      out=$f
      ldir='$(DESTDIR)$(libsubdir)'
    fi
    echo '	$(INSTALL_DATA)' $out $ldir/
  done
done