# Copyright (C) 2001 Free Software Foundation, Inc.
# This file is part of the GNU C Library.

# The GNU C Library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.

# The GNU C Library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Library General Public License for more details.

# You should have received a copy of the GNU Library General Public
# License along with the GNU C Library; see the file COPYING.LIB.  If not,
# write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.

#
#	Sub-makefile for libgcc portion of the library.
#

subdir := libgcc

include ../Makeconfig

libgcc-release := $(shell $(CC) -dumprelease)
libgcc-map := $(shell $(CC) -print-file-name=libgcc.map)
libgcc-installed-name := libgcc_s.so$(libgcc_s.so-version)

libgcc-routines := dummy
libgcc-inhibit-o = $(filter-out .os,$(object-suffixes))

extra-objs = $(libgcc-routines:=.os)
generated += $(rtld-installed-name)
install-others = $(inst_slibdir)/$(libgcc-installed-name)

include ../Rules

others: $(objpfx)$(libgcc-installed-name) \
	$(addprefix $(objpfx),$(extra-objs))

# Make sure $(libgcc-installed-name) exists in the build directory so
# that we can run binaries linked against it.
$(objpfx)libgcc_s.so: $(objpfx)dummy.os $(+preinit) $(+postinit) \
  $(common-objpfx)libc.so$(libc.so-version) \
  $(common-objpfx)$(patsubst %,$(libtype.oS),c)
	$(LINK.o) -nodefaultlibs -shared -B$(csu-objpfx) -o $@ \
		-Wl,--whole-archive -lgcc -Wl,--no-whole-archive \
		$(filter-out $(+preinit) $(+postinit),$^) \
		-Wl,--soname,$(libgcc-installed-name) \
		-Wl,--version-script,$(libgcc-map)

$(objpfx)$(libgcc-installed-name): $(objpfx)libgcc_s.so
	$(make-link)

$(inst_slibdir)/libgcc_s-$(libgcc-release).so: \
  $(objpfx)$(libgcc-installed-name)
	$(make-target-directory)
	$(do-install-program)

$(inst_slibdir)/$(libgcc-installed-name): \
  $(inst_slibdir)/libgcc_s-$(libgcc-release).so
	$(make-shlib-link)

subdir_install: $(inst_libdir)/libgcc_s.so

$(inst_libdir)/libgcc_s.so: $(inst_slibdir)/$(libgcc-installed-name)
	$(make-link)
