arch = $(shell dpkg-architecture -qDEB_HOST_ARCH)
changes = adequate-testpkg_1_$(arch).changes

.PHONY: all
all: $(changes)
	$(info Run "make run" as root.)
	$(info Alternatively, if you have user-mode-linux installed, you can try "make run-uml" as normal user.)
	$(info )@:

$(changes):
	cd testpkg && dpkg-buildpackage -b -us -uc

.PHONY: run
run: $(changes)
	./run-tests $(<)

.PHONY: run-uml
run-uml: $(changes)
	fallocate -l 1G uml-guest-swap
	setsid linux init=$(CURDIR)/uml-guest-init \
		$(shell printf '%s' '$(CURDIR)' | base64 -w0 | tr = _) \
		$(shell printf '%s' '$(<)' | base64 -w0 | tr = _) \
		rootfstype=hostfs ubd0=uml-guest-swap mem=128M quiet con=null,fd:1 \
	| sed '/: adequate tests succeeded :/ q 100'; \
	[ $$? -eq 100 ]

.PHONY: clean
clean:
	cd testpkg && debian/rules clean
	rm -f *.changes *.deb
	rm -f uml-guest-swap

# vim:ts=4 sw=4 noet
