#!/usr/bin/make -f

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

export DH_GOPKG := github.com/opencontainers/runc
export DH_GOLANG_INSTALL_EXTRA := libcontainer/seccomp/fixtures
TAGS=apparmor seccomp selinux ambient

export PATH := /usr/lib/go-1.10/bin:$(PATH)

%:
ifneq ($(shell dpkg-architecture -qDEB_HOST_ARCH),powerpc)
	dh $@ --buildsystem=golang --with=golang --builddirectory=_build
else
	# powerpc is no longer supported
	if [ "$@" = "clean" ]; then \
		rm -f debian/runc.preinst debian/runc.templates; \
	fi; \
	if [ "$@" = "binary" ] || [ "$@" = "binary-arch" ]; then \
		cp debian/runc.preinst.powerpc debian/runc.preinst; \
		cp debian/runc.templates.powerpc debian/runc.templates; \
		dh_installdebconf; \
		dh_installdeb; \
		dh_gencontrol; \
		dh_builddeb; \
	fi;
endif

override_dh_auto_configure:
	cd man && ./md2man-all.sh
	dh_auto_configure
	for path in $$DH_GOLANG_INSTALL_EXTRA; do \
		cp -a $$path _build/src/$$DH_GOPKG/$$path; \
	done
	## Remove extra license files:
	$(RM) -v \
            _build/src/$(DH_GOPKG)/vendor/github.com/docker/docker/*/*/LICENSE* \
        ;

override_dh_auto_build:
	dh_auto_build -- -tags "$(TAGS)"

override_dh_auto_test:
	DH_GOLANG_EXCLUDES="libcontainer/integration" \
        dh_auto_test -- -tags "$(TAGS)"
