PR opt/3995
[official-gcc.git] / gcc / mklibgcc.in
blob8018eca2f643a0a6d0fb0447c445de765be47370
1 #!/bin/sh
2 # Construct makefile for libgcc.
3 # Copyright (C) 2000, 2002 Free Software Foundation, Inc.
5 # This file is part of GCC.
7 # Arguments, taken from the environment, since there are a lot
8 # of them, and positional args becomes quite ugly.
10 # objext
11 # LIB1ASMFUNCS
12 # LIB2FUNCS_1
13 # LIB2FUNCS_2
14 # LIB2FUNCS_ST
15 # LIB2ADD
16 # LIB2ADD_ST
17 # LIB2ADDEH
18 # LIB2ADDEHDEP
19 # FPBIT
20 # FPBIT_FUNCS
21 # LIB2_DIVMOD_FUNCS
22 # DPBIT
23 # DPBIT_FUNCS
24 # LIBGCC
25 # MULTILIBS
26 # EXTRA_MULTILIB_PARTS
27 # SHLIB_EXT
28 # SHLIB_LINK
29 # SHLIB_MULTILIB
30 # SHLIB_MKMAP
31 # SHLIB_MKMAP_OPTS
32 # SHLIB_MAPFILES
33 # SHLIB_NM_FLAGS
34 # SHLIB_INSTALL
36 # Make needs VPATH to be literal.
37 echo 'srcdir = @srcdir@'
38 echo 'VPATH = @srcdir@'
39 echo 'EQ = ='
40 echo
41 echo 'force:'
42 echo
44 # Disable SHLIB_LINK if shared libgcc not enabled.
45 if [ "@enable_shared@" = "no" ]; then
46 SHLIB_LINK=""
49 # Build lines.
51 gcc_compile='$(GCC_FOR_TARGET) $(LIBGCC2_CFLAGS) $(INCLUDES)'
52 make_compile='$(MAKE) GCC_FOR_TARGET="$(GCC_FOR_TARGET)" \
53 AR_FOR_TARGET="$(AR_FOR_TARGET)" \
54 AR_CREATE_FOR_TARGET="$(AR_CREATE_FOR_TARGET)" \
55 AR_EXTRACT_FOR_TARGET="$(AR_EXTRACT_FOR_TARGET)" \
56 AR_FLAGS_FOR_TARGET="$(AR_FLAGS_FOR_TARGET)" \
57 CC="$(CC)" CFLAGS="$(CFLAGS)" \
58 HOST_PREFIX="$(HOST_PREFIX)" \
59 HOST_PREFIX_1="$(HOST_PREFIX_1)" \
60 LANGUAGES="$(LANGUAGES)"'
62 # Dependencies for libgcc2.c
63 libgcc2_c_dep='stmp-dirs $(srcdir)/libgcc2.c $(CONFIG_H) $(MACHMODE_H) longlong.h gbl-ctors.h config.status stmp-int-hdrs tsystem.h'" $LIB2ADDEHDEP"
65 # Dependencies for fp-bit.c
66 fpbit_c_dep='stmp-dirs config.status tsystem.h'
69 # Build libgcc1 components.
72 libgcc1_objs=""
74 for name in $LIB1ASMFUNCS; do
75 for ml in $MULTILIBS; do
76 dir=`echo ${ml} | sed -e 's/;.*$//' -e 's/=/$(EQ)/g'`
77 flags=`echo ${ml} | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
78 out="libgcc/${dir}/${name}${objext}"
80 echo ${out}: stmp-dirs '$(srcdir)/config/$(LIB1ASMSRC)'
81 echo " $gcc_compile" $flags -DL$name -xassembler-with-cpp \
82 -c '$(srcdir)/config/$(LIB1ASMSRC)' -o $out
84 # Remove any objects from LIB2FUNCS and LIB2_DIVMOD_FUNCS that are
85 # defined as optimized assembly code in LIB1ASMFUNCS.
86 LIB2FUNCS_1=`echo $LIB2FUNCS_1 | sed -e 's/^'$name' //' \
87 -e 's/ '$name' / /' \
88 -e 's/ '$name'$//'`
89 LIB2FUNCS_2=`echo $LIB2FUNCS_2 | sed -e 's/^'$name' //' \
90 -e 's/ '$name' / /' \
91 -e 's/ '$name'$//'`
92 LIB2_DIVMOD_FUNCS=`echo $LIB2_DIVMOD_FUNCS | sed -e 's/^'$name' //' \
93 -e 's/ '$name' / /' \
94 -e 's/ '$name'$//'`
95 done
96 libgcc1_objs="$libgcc1_objs ${name}${objext}"
97 done
100 # Build libgcc2 components.
103 libgcc2_objs=""
104 libgcc2_st_objs=""
105 libgcc2_eh_objs=""
107 for name in $LIB2FUNCS_1 $LIB2FUNCS_2; do
108 for ml in $MULTILIBS; do
109 dir=`echo ${ml} | sed -e 's/;.*$//' -e 's/=/$(EQ)/g'`
110 flags=`echo ${ml} | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
111 out="libgcc/${dir}/${name}${objext}"
113 echo $out: $libgcc2_c_dep
114 echo " $gcc_compile" '$(MAYBE_USE_COLLECT2)' $flags -DL$name \
115 -c '$(srcdir)/libgcc2.c' -o $out
116 done
117 libgcc2_objs="$libgcc2_objs ${name}${objext}"
118 done
120 for name in $LIB2FUNCS_ST; do
121 for ml in $MULTILIBS; do
122 dir=`echo ${ml} | sed -e 's/;.*$//' -e 's/=/$(EQ)/g'`
123 flags=`echo ${ml} | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
124 out="libgcc/${dir}/${name}${objext}"
126 echo $out: $libgcc2_c_dep
127 echo " $gcc_compile" '$(MAYBE_USE_COLLECT2)' $flags -DL$name \
128 -c '$(srcdir)/libgcc2.c' -o $out
129 done
130 libgcc2_st_objs="$libgcc2_st_objs ${name}${objext}"
131 done
133 for name in $LIB2_DIVMOD_FUNCS; do
134 for ml in $MULTILIBS; do
135 dir=`echo ${ml} | sed -e 's/;.*$//' -e 's/=/$(EQ)/g'`
136 flags=`echo ${ml} | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
137 out="libgcc/${dir}/${name}${objext}"
139 echo $out: $libgcc2_c_dep
140 echo " $gcc_compile" '$(MAYBE_USE_COLLECT2)' $flags -DL$name \
141 -c '$(srcdir)/libgcc2.c' -fexceptions -fnon-call-exceptions -o $out
142 done
143 libgcc2_objs="$libgcc2_objs ${name}${objext}"
144 done
146 if [ "$FPBIT" ]; then
147 for name in $FPBIT_FUNCS; do
148 for ml in $MULTILIBS; do
149 dir=`echo ${ml} | sed -e 's/;.*$//' -e 's/=/$(EQ)/g'`
150 flags=`echo ${ml} | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
151 out="libgcc/${dir}/${name}${objext}"
153 echo $out: $FPBIT $fpbit_c_dep
154 echo " $gcc_compile" -DFINE_GRAINED_LIBRARIES $flags -DL$name \
155 -c $FPBIT -o $out
156 done
157 libgcc2_objs="$libgcc2_objs ${name}${objext}"
158 done
161 if [ "$DPBIT" ]; then
162 for name in $DPBIT_FUNCS; do
163 for ml in $MULTILIBS; do
164 dir=`echo ${ml} | sed -e 's/;.*$//' -e 's/=/$(EQ)/g'`
165 flags=`echo ${ml} | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
166 out="libgcc/${dir}/${name}${objext}"
168 echo $out: $DPBIT $fpbit_c_dep
169 echo " $gcc_compile" -DFINE_GRAINED_LIBRARIES $flags -DL$name \
170 -c $DPBIT -o $out
171 done
172 libgcc2_objs="$libgcc2_objs ${name}${objext}"
173 done
176 for file in $LIB2ADD; do
177 name=`echo $file | sed -e 's/[.][cSo]$//' -e 's/[.]asm$//' -e 's/[.]txt$//'`
178 oname=`echo $name | sed -e 's,.*/,,'`
180 for ml in $MULTILIBS; do
181 dir=`echo ${ml} | sed -e 's/;.*$//' -e 's/=/$(EQ)/g'`
182 flags=`echo ${ml} | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
183 out="libgcc/${dir}/${oname}${objext}"
184 if [ ${name}.asm = ${file} ]; then
185 flags="$flags -xassembler-with-cpp"
188 echo $out: stmp-dirs $file
189 echo " $gcc_compile" $flags -c $file -o $out
190 done
191 libgcc2_objs="$libgcc2_objs ${oname}${objext}"
192 done
194 for file in $LIB2ADDEH; do
195 name=`echo $file | sed -e 's/[.][cSo]$//' -e 's/[.]asm$//' -e 's/[.]txt$//'`
196 oname=`echo $name | sed -e 's,.*/,,'`
198 for ml in $MULTILIBS; do
199 dir=`echo ${ml} | sed -e 's/;.*$//' -e 's/=/$(EQ)/g'`
200 flags=`echo ${ml} | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
201 out="libgcc/${dir}/${oname}${objext}"
202 if [ ${name}.asm = ${file} ]; then
203 flags="$flags -xassembler-with-cpp"
206 echo $out: stmp-dirs $file
207 echo " $gcc_compile" $flags -fexceptions -c $file -o $out
208 done
209 if [ "$SHLIB_LINK" ]; then
210 libgcc2_eh_objs="$libgcc2_eh_objs ${oname}${objext}"
211 else
212 libgcc2_objs="$libgcc2_objs ${oname}${objext}"
214 done
216 for file in $LIB2ADD_ST; do
217 name=`echo $file | sed -e 's/[.][cSo]$//' -e 's/[.]asm$//' -e 's/[.]txt$//'`
218 oname=`echo $name | sed -e 's,.*/,,'`
220 for ml in $MULTILIBS; do
221 dir=`echo ${ml} | sed -e 's/;.*$//' -e 's/=/$(EQ)/g'`
222 flags=`echo ${ml} | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
223 out="libgcc/${dir}/${oname}${objext}"
224 if [ ${name}.asm = ${file} ]; then
225 flags="$flags -xassembler-with-cpp"
228 echo $out: stmp-dirs $file
229 echo " $gcc_compile" $flags -c $file -o $out
230 done
231 libgcc2_st_objs="$libgcc2_st_objs ${oname}${objext}"
232 done
234 # SHLIB_MKMAP
235 # SHLIB_MKMAP_OPTS
236 # SHLIB_MAPFILES
237 for ml in $MULTILIBS; do
238 dir=`echo ${ml} | sed -e 's/;.*$//' -e 's/=/$(EQ)/g'`
239 flags=`echo ${ml} | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
241 libgcc_objs=""
242 libgcc_eh_objs=""
243 for o in $libgcc1_objs; do
244 libgcc_objs="$libgcc_objs libgcc/${dir}/$o"
245 done
246 for o in $libgcc2_objs; do
247 libgcc_objs="$libgcc_objs libgcc/${dir}/$o"
248 done
249 for o in $libgcc2_eh_objs; do
250 libgcc_eh_objs="$libgcc_eh_objs libgcc/${dir}/$o"
251 done
252 libgcc_sh_objs="$libgcc_objs $libgcc_eh_objs"
253 shlib_deps="$libgcc_sh_objs"
255 libgcc_st_objs=""
256 for o in $libgcc2_st_objs; do
257 libgcc_st_objs="$libgcc_st_objs libgcc/${dir}/$o"
258 done
260 if [ "$SHLIB_LINK" -a "$SHLIB_MKMAP" ]; then
261 mapfile="libgcc/${dir}/libgcc.map"
262 tmpmapfile="libgcc/${dir}/tmp-libgcc.map"
263 echo ""
264 echo "${mapfile}: $SHLIB_MKMAP $SHLIB_MAPFILES $libgcc_sh_objs"
265 echo ' { $(NM_FOR_TARGET)'" $SHLIB_NM_FLAGS $libgcc_sh_objs; echo %%; cat $SHLIB_MAPFILES; } | "'$(AWK)'" -f $SHLIB_MKMAP $SHLIB_MKMAP_OPTS > ${tmpmapfile}"
266 echo ' mv '"$tmpmapfile"' $@'
268 shlib_deps="$shlib_deps $mapfile"
270 # Depend on EXTRA_MULTILIB_PARTS, since that's where crtbegin/end
271 # usually are put in a true multilib situation.
272 for f in $EXTRA_MULTILIB_PARTS; do
273 shlib_deps="$shlib_deps $dir/$f"
274 done
276 libgcc_a_objs="$libgcc_objs $libgcc_st_objs"
278 if [ "@libgcc_visibility@" = yes -a "$SHLIB_LINK" ]; then
279 libgcc_a_objs=
280 echo ""
281 for o in $libgcc_objs $libgcc_st_objs; do
282 # .oS objects will have all non-local symbol definitions .hidden
283 oS=`echo ${o} | sed s~${objext}'$~.oS~g'`
284 echo "${oS}: stmp-dirs ${o}"
285 echo ' @$(NM_FOR_TARGET) '${SHLIB_NM_FLAGS} ${o}' | $(AWK) '\''NF == 3 { print "\t.hidden", $$3 }'\'' | $(GCC_FOR_TARGET) $(LIBGCC2_CFLAGS) '${flags}' -r -nostdinc -nostdlib -o $@ '${o}' -xassembler -'
286 libgcc_a_objs="${libgcc_a_objs} ${oS}"
287 done
290 echo ""
291 echo "${dir}/libgcc.a: $libgcc_a_objs"
292 echo " -rm -rf ${dir}/libgcc.a"
293 echo ' $(AR_CREATE_FOR_TARGET)' ${dir}/libgcc.a $libgcc_a_objs
294 echo ' if $(RANLIB_TEST_FOR_TARGET) ; then' \\
295 echo ' $(RANLIB_FOR_TARGET)' ${dir}/libgcc.a ';' \\
296 echo ' else true; fi;'
298 if [ "$SHLIB_LINK" ]; then
300 echo ""
301 echo "${dir}/libgcc_eh.a: $libgcc_eh_objs"
302 echo " -rm -rf ${dir}/libgcc_eh.a"
303 echo ' $(AR_CREATE_FOR_TARGET)' ${dir}/libgcc_eh.a $libgcc_eh_objs
304 echo ' if $(RANLIB_TEST_FOR_TARGET) ; then' \\
305 echo ' $(RANLIB_FOR_TARGET)' ${dir}/libgcc_eh.a ';' \\
306 echo ' else true; fi;'
308 if [ -z "$SHLIB_MULTILIB" ]; then
309 if [ "$dir" = "." ]; then
310 shlib_base_name="libgcc_s";
311 else
312 shlib_base_name=libgcc_s_`echo $dir | sed s,/,_,g`
314 echo ""
315 echo "${dir}/${shlib_base_name}${SHLIB_EXT}: $shlib_deps"
316 echo " $SHLIB_LINK" \
317 | sed -e "s%@multilib_flags@%$flags%g" \
318 -e "s%@multilib_dir@%$dir%g" \
319 -e "s%@shlib_objs@%$libgcc_sh_objs%g" \
320 -e "s%@shlib_base_name@%$shlib_base_name%g" \
321 -e "s%@shlib_map_file@%$mapfile%g"
322 elif [ "$SHLIB_MULTILIB" = "$dir" ]; then
323 shlib_base_name="libgcc_s";
324 echo ""
325 echo "${shlib_base_name}${SHLIB_EXT}: $shlib_deps"
326 echo " $SHLIB_LINK" \
327 | sed -e "s%@multilib_flags@%$flags%g" \
328 -e "s%@multilib_dir@%$dir%g" \
329 -e "s%@shlib_objs@%$libgcc_sh_objs%g" \
330 -e "s%@shlib_base_name@%$shlib_base_name%g" \
331 -e "s%@shlib_map_file@%$mapfile%g"
334 done
336 dirs=libgcc
337 for ml in $MULTILIBS; do
338 dir=`echo ${ml} | sed -e 's/;.*$//' -e 's/=/$(EQ)/g'`
339 if [ $dir != . ]; then
340 dirs="$dirs libgcc/${dir}"
342 done
343 echo ''
344 echo 'libgcc-stage-start:'
345 echo ' for dir in '"${dirs}"'; do \'
346 echo ' if [ -d $(stage)/$$dir ]; then true; else mkdir $(stage)/$$dir; fi; \'
347 echo ' done'
348 echo ' -for dir in '"${dirs}"'; do \'
349 echo ' mv $$dir/*'"${objext}"' $(stage)/$$dir; \'
350 echo ' done'
352 echo ""
353 all=stmp-dirs
354 dirs=libgcc
356 for ml in $MULTILIBS; do
357 dir=`echo ${ml} | sed -e 's/;.*$//' -e 's/=/$(EQ)/g'`
358 if [ $dir != . ]; then
359 dirs="$dirs ${dir} libgcc/${dir}"
361 all="$all ${dir}/libgcc.a"
362 if [ "$SHLIB_LINK" ]; then
363 all="$all ${dir}/libgcc_eh.a"
364 if [ -z "$SHLIB_MULTILIB" ]; then
365 if [ "$dir" = "." ]; then
366 suff="";
367 else
368 suff=_`echo $dir | sed s,/,_,g`
370 all="$all ${dir}/libgcc_s${suff}${SHLIB_EXT}"
371 elif [ "$SHLIB_MULTILIB" = "$dir" ]; then
372 all="$all libgcc_s${SHLIB_EXT}"
375 done
377 echo 'stmp-dirs: force'
378 echo ' for d in '"$dirs"'; do \'
379 echo ' if [ -d $$d ]; then true; else '$mkinstalldirs' $$d; fi; \'
380 echo ' done'
381 echo ' if [ -f stmp-dirs ]; then true; else touch stmp-dirs; fi'
383 for f in $EXTRA_MULTILIB_PARTS; do
384 for ml in $MULTILIBS; do
385 dir=`echo ${ml} | sed -e 's/;.*$//' -e 's/=/$(EQ)/g'`
386 flags=`echo ${ml} | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
387 case $dir in
388 .) out=$f ; t= ;;
389 *) out=$dir/$f ; t=$dir/ ;;
390 esac
391 case $out in
392 # Prevent `make' from interpreting $out as a macro assignment
393 *'$(EQ)'*) targ="T_TARGET=$out T_TARGET" ;;
394 *) targ=$out ;;
395 esac
397 echo $out: stmp-dirs
398 echo " $make_compile" \\
399 echo ' LIBGCC2_CFLAGS="$(LIBGCC2_CFLAGS)' $flags '" ' \\
400 echo ' MULTILIB_CFLAGS="'$flags'"' T=$t $targ
402 all="$all $out"
403 done
404 done
406 echo ""
407 echo "all: $all"
409 echo ""
410 echo "install: $all"
411 for ml in $MULTILIBS; do
412 dir=`echo ${ml} | sed -e 's/;.*$//' -e 's/=/$(EQ)/g'`
413 if [ $dir != . ]; then
414 ldir='$(libsubdir)'/$dir
415 echo " if [ -d $ldir ]; then true; else mkdir $ldir; chmod a+rx $ldir; fi;"
416 else
417 ldir='$(libsubdir)'
419 echo ' $(INSTALL_DATA)' ${dir}/libgcc.a ${ldir}/
420 echo ' $(RANLIB_FOR_TARGET)' ${ldir}/libgcc.a
422 if [ "$SHLIB_LINK" ]; then
423 echo ' $(INSTALL_DATA)' ${dir}/libgcc_eh.a ${ldir}/
424 echo ' $(RANLIB_FOR_TARGET)' ${ldir}/libgcc_eh.a
426 if [ -z "$SHLIB_MULTILIB" ]; then
427 if [ "$dir" = "." ]; then
428 shlib_base_name="libgcc_s";
429 else
430 shlib_base_name=libgcc_s_`echo $dir | sed s,/,_,g`
432 echo " $SHLIB_INSTALL" \
433 | sed -e "s%@shlib_base_name@%$shlib_base_name%g"
434 elif [ "$SHLIB_MULTILIB" = "$dir" ]; then
435 shlib_base_name="libgcc_s";
436 echo " $SHLIB_INSTALL" \
437 | sed -e "s%@shlib_base_name@%$shlib_base_name%g"
440 done
441 for f in $EXTRA_MULTILIB_PARTS; do
442 for ml in $MULTILIBS; do
443 dir=`echo ${ml} | sed -e 's/;.*$//' -e 's/=/$(EQ)/g'`
444 if [ $dir != . ]; then
445 out=${dir}/$f
446 ldir='$(libsubdir)'/$dir
447 else
448 out=$f
449 ldir='$(libsubdir)'
451 echo ' $(INSTALL_DATA)' $out $ldir/
452 done
453 done