-export LIBAPT_MAJOR:=$(shell egrep '^MAJOR=' apt-pkg/makefile |cut -d '=' -f 2)
-#debian/shlibs.local:
-# rm -f $@
-# echo "libapt-pkg $(LIBAPT_MAJOR) libapt-pkg$(LIBAPT_MAJOR)" >> $@
-# echo "libapt-pkg $(LIBAPT_MAJOR) apt $(APT_DEBVER)" >> $@
-
-build: build-stamp
-build-stamp: configure
+export LIBAPTPKG_MAJOR:=$(shell egrep '^MAJOR=' apt-pkg/makefile |cut -d '=' -f 2)
+export LIBAPTINST_MAJOR:=$(shell egrep '^MAJOR=' apt-inst/makefile |cut -d '=' -f 2)
+
+# Determine which package we should provide in the control files
+LIBAPTPKG_PROVIDE=libapt-pkg$(GLIBC_VER)$(LIBSTDCPP_VER)-$(LIBAPTPKG_MAJOR)
+LIBAPTINST_PROVIDE=libapt-inst$(GLIBC_VER)$(LIBSTDCPP_VER)-$(LIBAPTINST_MAJOR)
+
+debian/shlibs.local: apt-pkg/makefile
+ # We have 3 shlibs.local files.. One for 'apt', one for 'apt-utils' and
+ # one for the rest of the packages. This ensures that each package gets
+ # the right overrides..
+ rm -rf $@ $@.apt $@.apt-utils
+ echo "libapt-pkg$(GLIBC_VER)$(LIBSTDCPP_VER) $(LIBAPTPKG_MAJOR)" > $@.apt
+
+ echo "libapt-pkg$(GLIBC_VER)$(LIBSTDCPP_VER) $(LIBAPTPKG_MAJOR) $(LIBAPTPKG_PROVIDE)" > $@.apt-utils
+ echo "libapt-inst$(GLIBC_VER)$(LIBSTDCPP_VER) $(LIBAPTINST_MAJOR)" >> $@.apt-utils
+
+ echo "libapt-pkg$(GLIBC_VER)$(LIBSTDCPP_VER) $(LIBAPTPKG_MAJOR) $(LIBAPTPKG_PROVIDE)" > $@
+ echo "libapt-inst$(GLIBC_VER)$(LIBSTDCPP_VER) $(LIBAPTINST_MAJOR) $(LIBAPTINST_PROVIDE)" >> $@
+
+build: build/build-stamp
+
+# Note that this is unconditionally done first as part of loading environment.mak
+# The true is needed to force make to reload environment.mak after running
+# configure-stamp. Otherwise we can get stale or invalid, or missing config data.
+build/environment.mak: build/configure-stamp
+ @true
+
+configure: configure.in
+build/configure-stamp: configure