#!/usr/bin/make -f

include /usr/share/dpkg/pkg-info.mk

# Golang does not support PIE on mips
# cf. https://github.com/golang/go/issues/21222
ifeq ($(filter $(DEB_HOST_ARCH),mips mipsel mips64el),)
GO_FLAGS += -buildmode=pie
endif

# pass the right paths & version number (see upstream Makefile)
CONFFILE=/etc/GeoIP.conf
DATADIR=/var/lib/GeoIP
VERSION=$(DEB_VERSION_UPSTREAM)
GO_FLAGS += -ldflags '-X main.defaultConfigFile=$(CONFFILE) -X main.defaultDatabaseDirectory=$(DATADIR) -X "main.version=$(VERSION)"'

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

override_dh_auto_build:
	dh_auto_build --builddirectory=build --buildsystem=golang -- $(GO_FLAGS)
	# build the manpages
	CONFFILE=$(CONFFILE) DATADIR=$(DATADIR) make data

override_dh_auto_install:
	dh_auto_install -- --no-source
