#!/usr/bin/make -f

ARCH=$(shell dpkg-architecture -qDEB_BUILD_ARCH)
VERSION=$(shell LC_ALL=C dpkg-parsechangelog | grep ^Version: | cut -d ' ' -f 2)
DATE=$(shell echo $(VERSION) | cut -d '.' -f 1)
SUITE=$(shell LC_ALL=C dpkg-parsechangelog | grep ^Distribution: | cut -d ' ' -f 2 | cut -d - -f 1)
ifeq (${SUITE},UNRELEASED)
USE_UDEBS_FROM=lucid
TRANSSTATUS=
BOOTMENU_BEEP=n
else
USE_UDEBS_FROM=$(SUITE)
TRANSSTATUS=translation-status
BOOTMENU_BEEP=y
endif

ARCHIVEDIR=debian/tmp/installer-$(ARCH)
DESTDIR=$(ARCHIVEDIR)/$(VERSION)
IMAGEDIR=$(DESTDIR)/images
TARNAME=debian-installer-images_$(VERSION)_$(ARCH).tar.gz

clean:
	dh_testdir
	dh_testroot
	dh_clean build-stamp
	$(MAKE) -C build reallyclean
	$(MAKE) -C doc/devel/partman clean
	$(MAKE) -C doc/devel/internals clean

# Must run as root, so is not run as part of regular build.
build-images:
	$(MAKE) -C build all_build stats release \
		USE_UDEBS_FROM=$(USE_UDEBS_FROM) BUILD_DATE=$(DATE) \
		TRANSSTATUS=$(TRANSSTATUS) BOOTMENU_BEEP=$(BOOTMENU_BEEP)
	
build: build-stamp
build-stamp:
	rm -f $@
	$(MAKE) -C doc/devel/internals
	$(MAKE) -C doc/devel/partman
	touch $@

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs
	
	debian/rules build-images

	install -d $(IMAGEDIR)
	cp -a build/dest/* $(IMAGEDIR)
	ln -s $(VERSION) $(ARCHIVEDIR)/current

binary-arch: install  
	dh_testdir
	dh_testroot
	dh_installchangelogs
	dh_installdocs doc/* -X Makefile -X build.sh -X .xsl \
		-X internals.xml -X partman-doc.sgml
	dh_compress
	dh_fixperms
	dh_gencontrol
	dh_md5sums
	dh_builddeb
	cd debian/tmp && tar czvf ../../../$(TARNAME) .
	dpkg-distaddfile $(TARNAME) raw-installer -

binary-indep:

binary: binary-indep binary-arch 
.PHONY: build build-images clean binary-indep binary-arch binary install 
