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

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

VERSION := $(shell dpkg-parsechangelog | sed -ne 's,^Version: *\(.*\)$$,\1,p')

%:
	+dh $@ 

override_dh_auto_configure:
	cp debian/config/* src/config/local

src/bin/% src/bin-x86_64-efi/%:
	$(MAKE) -C src V=1 NO_WERROR=1 VERSION="$(VERSION)" $(subst src/,,$@)

src/bin-efi/%.efirom: src/bin/%.rom src/bin-x86_64-efi/%.efirom
	@[ -d $(dir $@) ] || mkdir $(dir $@)
	src/util/catrom.pl $^ > $@

override_dh_auto_build: $(shell grep -hoE 'src/bin(-[^/]*)?/\S+' debian/*.install)

override_dh_auto_clean:
	$(MAKE) -C src veryclean
	rm -fr src/bin-efi src/bin-x86_64-efi
	rm -f src/config/local/*

# Stuff for get-orig-source.
version_prefix := $(shell dpkg-parsechangelog | sed -ne 's/^Version.*git-\(.*\)\..*/\1/p')
# Git short hash is prefixed with date of snapshot
new_prefix := $(shell date +%Y%m%d)

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

.NOTPARALLEL:
.SECONDARY:
