#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

%:
	dh $@ 

override_dh_auto_build:
	make -C src V=1 NO_WERROR=1 allqemu
	#make -C src V=1 NO_WERROR=1 all allroms allqemu bin/ipxe.pxe bin/ipxe.lkrn

override_dh_auto_clean:
	make -C src veryclean
	rm -f src/config/local/*

override_dh_auto_install:
	mkdir -p $(CURDIR)/debian/kvm-ipxe-precise/usr/share/qemu
	mv src/bin/e1000_82540.rom   $(CURDIR)/debian/kvm-ipxe-precise/usr/share/qemu/pxe-e1000.rom.12.04
	mv src/bin/ne2k_isa.rom      $(CURDIR)/debian/kvm-ipxe-precise/usr/share/qemu/pxe-ne2k_isa.rom.12.04
	mv src/bin/pcnet32.rom       $(CURDIR)/debian/kvm-ipxe-precise/usr/share/qemu/pxe-pcnet32.rom.12.04
	mv src/bin/rtl8139.rom       $(CURDIR)/debian/kvm-ipxe-precise/usr/share/qemu/pxe-rtl8139.rom.12.04
	mv src/bin/virtio-net.rom    $(CURDIR)/debian/kvm-ipxe-precise/usr/share/qemu/pxe-virtio.rom.12.04

# Stuff for get-orig-source.
version_prefix := $(shell dpkg-parsechangelog | sed -ne 's/^Version.*git-\(.*\)\..*/\1/p')
# Git short hash is prefixed with version number - 
# increment for next snapshot
new_prefix := $(shell expr $(version_prefix) + 1)

get-orig-source:
	# Grab the latest snapshot of the upstream git repository
	[ ! -d ipxe-snapshot ] || rm -rf ipxe-snapshot
	git clone git://git.ipxe.org/ipxe.git ipxe-snapshot
	cd ipxe-snapshot && \
		commit=`git rev-parse --short HEAD` && \
		git archive --format=tar --prefix=ipxe-1.0.0+git-$(new_prefix).$${commit} master |\
			gzip -9 --no-name > ../../ipxe_1.0.0+git-$(new_prefix).$${commit}.orig.tar.gz
	rm -rf ipxe-snapshot
