#!/usr/bin/make -f

HUGO := obj-$(DEB_HOST_GNU_TYPE)/bin/hugo

# We need to add -tags to for gccgo to handle MIPS architectures where
# gccgo uses "mipso32" for mips/mipsle and "mipsn64" for mips64/mips64le
ifeq ($(findstring mips,$(DEB_BUILD_ARCH)),mips)
# mipsel => mipsle, mips64el => mips64le
BUILDTAGS := $(DEB_BUILD_ARCH:el=le)
endif

%:
	dh $@ --buildsystem=golang --with=golang

override_dh_auto_build:
ifdef BUILDTAGS
	dh_auto_build -O--buildsystem=golang -O--no-parallel -- -tags $(BUILDTAGS) || \
	dh_auto_build -O--buildsystem=golang -O--no-parallel -- -tags $(BUILDTAGS) || \
	dh_auto_build -O--buildsystem=golang -O--no-parallel -- -tags $(BUILDTAGS) || \
	dh_auto_build -O--buildsystem=golang -O--no-parallel -- -tags $(BUILDTAGS) || \
	dh_auto_build -O--buildsystem=golang -O--no-parallel -- -tags $(BUILDTAGS) || \
	dh_auto_build -O--buildsystem=golang -O--no-parallel -- -tags $(BUILDTAGS) || \
	dh_auto_build -O--buildsystem=golang -O--no-parallel -- -tags $(BUILDTAGS)
else
	dh_auto_build -O--buildsystem=golang
endif
	$(HUGO) gen autocomplete --completionfile=debian/hugo.bash-completion
	$(HUGO) gen man --dir=debian/man
	# TODO: Add "hugo-docs" package in the future
	$(HUGO) -s docs -d public/html --uglyURLs

# Disable network access during testing by using -test.short flag,
# and skip Git tests which upstream has also disabled for Travis CI.
override_dh_auto_test:
ifdef BUILDTAGS
	CI=true dh_auto_test -O--buildsystem=golang -O--no-parallel -- -tags $(BUILDTAGS) -test.short || \
	CI=true dh_auto_test -O--buildsystem=golang -O--no-parallel -- -tags $(BUILDTAGS) -test.short || \
	CI=true dh_auto_test -O--buildsystem=golang -O--no-parallel -- -tags $(BUILDTAGS) -test.short || \
	CI=true dh_auto_test -O--buildsystem=golang -O--no-parallel -- -tags $(BUILDTAGS) -test.short || \
	CI=true dh_auto_test -O--buildsystem=golang -O--no-parallel -- -tags $(BUILDTAGS) -test.short || \
	CI=true dh_auto_test -O--buildsystem=golang -O--no-parallel -- -tags $(BUILDTAGS) -test.short || \
	CI=true dh_auto_test -O--buildsystem=golang -O--no-parallel -- -tags $(BUILDTAGS) -test.short || \
	CI=true dh_auto_test -O--buildsystem=golang -O--no-parallel -- -tags $(BUILDTAGS) -test.short
else
	CI=true dh_auto_test -O--buildsystem=golang -- -test.short
endif

override_dh_auto_install:
	dh_auto_install -O--buildsystem=golang
	dh_bash-completion -O--buildsystem=golang
