#!/usr/bin/make -f

%:
	dh $@

override_dh_auto_clean:
	dh_clean
	$(MAKE) distclean
	$(MAKE) -C $(CURDIR)/debian/spapr-rtas clean

override_dh_auto_build-indep:
	env -u LDFLAGS -u CFLAGS $(MAKE) qemu CROSS="powerpc64-linux-gnu-" V=2
	$(MAKE) -C $(CURDIR)/debian/spapr-rtas CROSS="powerpc64-linux-gnu-"

override_dh_auto_install-indep:
	mkdir -p $(CURDIR)/debian/qemu-slof/usr/share/slof
	install -m 644 $(CURDIR)/boot_rom.bin $(CURDIR)/debian/qemu-slof/usr/share/slof/slof.bin
	install -m 644 $(CURDIR)/debian/spapr-rtas/spapr-rtas.bin $(CURDIR)/debian/qemu-slof/usr/share/slof/spapr-rtas.bin

#
# Rules to create the .orig.tar.xz file
#
SLOF_DEB_VERSION = $(shell dpkg-parsechangelog | awk '/^Version:/ {print $$2}')
SLOF_ORIG_VERSION = $(shell echo $(SLOF_DEB_VERSION) | sed -e 's/-.*//')
SLOF_URL = https://github.com/aik/SLOF/archive/qemu-slof-$(subst +dfsg,,$(SLOF_ORIG_VERSION)).tar.gz
SLOF_DIR = slof-$(SLOF_ORIG_VERSION)
SLOF_DEB_ORIG = ../slof_$(SLOF_ORIG_VERSION).orig.tar.xz

get-orig-source: $(SLOF_DEB_ORIG)
$(SLOF_DEB_ORIG):
	dh_testdir
	mkdir -p $(SLOF_DIR)
	wget -O - $(SLOF_URL) | (tar -C $(SLOF_DIR) --strip-components=1 -xzf -)
	tar --exclude="*.pdf" --exclude="*.oco" \
	    --mode=go=rX,u+rw,a-s \
	    --owner=root --group=root --numeric-owner \
	    -Jcf $(SLOF_DEB_ORIG) $(SLOF_DIR)
	rm -rf $(SLOF_DIR)
.PHONY: get-orig-source
