ifneq ($(vafilt_defined),1)
  $(error rules.defs must be included before rules.sonames)
endif

ifeq (,$(wildcard debian/soname-cache))
  SONAME_VARS := $(shell \
	cache=debian/soname-cache; \
	rm -f $$cache; \
	v=`awk -F= '/^libtool_VERSION/ {split($$2,v,":"); print v[1]}' \
		$(srcdir)/libstdc++-v3/acinclude.m4`; \
	echo CXX_SONAME=$$v >> $$cache; \
	v=`awk -F= '/^VERSION/ {split($$2,v,":"); print v[1]}' \
		$(srcdir)/libobjc/configure.ac`; \
	echo OBJC_SONAME=$$v >> $$cache; \
	v=`tail -1 $(srcdir)/libgfortran/libtool-version | cut -d: -f1`; \
	echo FORTRAN_SONAME=$$v >> $$cache; \
	v=`tail -1 $(srcdir)/libmudflap/libtool-version | cut -d: -f1`; \
	echo MUDFLAP_SONAME=$$v >> $$cache; \
	v=`tail -1 $(srcdir)/libssp/libtool-version | cut -d: -f1`; \
	echo SSP_SONAME=$$v >> $$cache; \
	v=`tail -1 $(srcdir)/libjava/libtool-version | cut -d: -f1`; \
	echo GCJ_SONAME=$$v >> $$cache; \
	if [ "$$v" -ge 70 ]; then \
	  echo GCJ_SONAME1=`echo $$v | sed 's/.$$//'` >> $$cache; \
	  echo GCJ_SONAME2=`echo $$v | sed 's/.*\(.\)$$/\1/'` >> $$cache; \
	else \
	  echo GCJ_SONAME1=$$v >> $$cache; \
	  echo GCJ_SONAME2= >> $$cache; \
	fi; \
	v=`tail -1 $(srcdir)/libffi/libtool-version | cut -d: -f1`; \
	echo FFI_SONAME=$$v >> $$cache; \
	v=`awk -F= '/^libtool_VERSION/ {split($$2,v,":"); print v[1]}' \
		$(srcdir)/libgomp/configure.ac`; \
	echo GOMP_SONAME=$$v >> $$cache; \
        if [ "$(with_qmath)" = yes ]; then \
	  v=`tail -1 $(srcdir)/libquadmath/libtool-version | cut -d: -f1`; \
	  echo QUADMATH_SONAME=$$v >> $$cache; \
	fi; \
        if [ "$(with_libgmath)" = yes ]; then \
	  v=`tail -1 $(srcdir)/libgcc-math/libtool-version | cut -d: -f1`; \
	  echo GCCMATH_SONAME=$$v >> $$cache; \
	fi; \
	v=`grep '[^_]Library_Version.*:' $(srcdir)/gcc/ada/gnatvsn.ads \
		| sed -e 's/.*"\([^"]*\)".*/\1/'`; \
	echo GNAT_SONAME=$$v >> $$cache; \
	echo GO_SONAME=0 >> $$cache; \
	cat $$cache)
else
  SONAME_VARS := $(shell cat debian/soname-cache)
endif
CXX_SONAME	= $(call vafilt,$(SONAME_VARS),CXX_SONAME)
OBJC_SONAME	= $(call vafilt,$(SONAME_VARS),OBJC_SONAME)
FORTRAN_SONAME	= $(call vafilt,$(SONAME_VARS),FORTRAN_SONAME)
MUDFLAP_SONAME	= $(call vafilt,$(SONAME_VARS),MUDFLAP_SONAME)
SSP_SONAME	= $(call vafilt,$(SONAME_VARS),SSP_SONAME)
GCJ_SONAME	= $(call vafilt,$(SONAME_VARS),GCJ_SONAME)
GCJ_SONAME1	= $(call vafilt,$(SONAME_VARS),GCJ_SONAME1)
GCJ_SONAME2	= $(call vafilt,$(SONAME_VARS),GCJ_SONAME2)
FFI_SONAME	= $(call vafilt,$(SONAME_VARS),FFI_SONAME)
GOMP_SONAME	= $(call vafilt,$(SONAME_VARS),GOMP_SONAME)
GCCMATH_SONAME	= $(call vafilt,$(SONAME_VARS),GCCMATH_SONAME)
QUADMATH_SONAME	= $(call vafilt,$(SONAME_VARS),QUADMATH_SONAME)
GNAT_SONAME	= $(call vafilt,$(SONAME_VARS),GNAT_SONAME)
GO_SONAME	= $(call vafilt,$(SONAME_VARS),GO_SONAME)

# alias
GFORTRAN_SONAME = $(FORTRAN_SONAME)
