VPATH		= @srcdir@
srcdir		= @srcdir@
top_srcdir	= @top_srcdir@

VERSION		= $(shell cat version-nr)

GENFILES	= version.h

default: all
include Makefile.conf

SUBDIRS		= include optlib lib dpkg-deb split scripts utils main \
		  @DSELECTDIR@ po methods man doc

all: version.h all-recursive

install: all install-recursive
	$(mkinstalldirs) $(DESTDIR)$(dpkgconfdir)/origins
	$(mkinstalldirs) $(DESTDIR)$(dpkgsharedir)/origins
	$(INSTALL_DATA) $(srcdir)/origin $(DESTDIR)$(dpkgconfdir)/origins/debian
	$(INSTALL_DATA) $(srcdir)/archtable $(DESTDIR)$(dpkgsharedir)/archtable

clean: clean-recursive
	rm -f $(GENFILES)

distclean: clean distclean-recursive
	rm -f Makefile.conf Makefile config.cache config.h config.log config.status
	rm -f automake/gettext.m4 automake/progtest.m4 automake/lcmessage.m4

version.h: version-nr
	echo "#define DPKG_VERSION \"$(VERSION)\" /* This line modified by Makefile */" > version.h

all-recursive install-recursive clean-recursive distclean-recursive: %-recursive:
	$(MAKE) $(MFLAGS) $(patsubst %,$*-%,$(SUBDIRS))

$(foreach target,all install clean distclean,$(patsubst %,$(target)-%,$(SUBDIRS))):
	$(MAKE) $(MFLAGS) -C "$(shell echo "$@" | sed 's/[^-]*-//')" "$(shell echo "$@" | sed 's/-.*//')"

.PHONY: all install clean distclean 
.PHONY: all-recursive install-recursive clean-recursive distclean-recursive
