# -*- make -*-

# This is the build directory make file, it sets the build directory
# and runs the src makefile.
ifndef NOISY
.SILENT:
endif
include environment.mak

SRCDIR=@top_srcdir@
DIRS:=./docs ./bin ./obj ./include ./scripts
SUBDIRS:= $(DIRS) ./docs/examples ./bin/methods ./include/apt-pkg \
         ./include/deity ./obj/apt-pkg ./obj/deity ./obj/gui ./obj/cmdline \
         ./obj/test ./obj/methods ./obj/methods/ftp ./scripts/dselect
BUILD:=$(shell pwd)
export BUILD

# Chain to the parent make to do the actual building
.PHONY: headers library clean veryclean all binary program doc \
        veryclean/local
all headers library clean veryclean binary program doc:
	$(MAKE) -C $(SRCDIR) -f Makefile $@

# Purge everything.
.PHONY: maintainer-clean dist-clean pristine sanity distclean
maintainer-clean dist-clean pristine sanity distclean:
	-rm -rf $(DIRS)
	-rm -f config.cache config.log config.status environment.mak makefile
	
# This makes any missing directories
.PHONY: dirs
MISSING_DIRS:=	$(filter-out $(wildcard $(SUBDIRS)),$(SUBDIRS))
dirs:
	@rm -f include/sys
ifneq ($(words $(MISSING_DIRS)),0)
	@mkdir  $(MISSING_DIRS)
endif	
ifeq ($(HAVE_C9X),yes)
	@rm -f include/inttypes.h > /dev/null 2>&1
else
	@cp -p $(SRCDIR)/buildlib/inttypes.h.in include/inttypes.h
endif
ifeq ($(HAVE_STATVFS),yes)
	@rm -f include/statvfs.h > /dev/null 2>&1
else
	@cp -p $(SRCDIR)/buildlib/statvfs.h.in include/statvfs.h
	ln -sf . include/sys
endif
ifeq ($(NEED_SOCKLEN_T_DEFINE),yes)
	@cp -p $(SRCDIR)/buildlib/netdb.h.in include/netdb.h
else
	@rm -f include/netdb.h > /dev/null 2>&1
endif
