#!/usr/bin/make -f
# -*- GNUmakefile -*-

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

ifneq ($(DEB_HOST_GNU_TYPE),$(DEB_BUILD_GNU_TYPE))
CROSS= --build $(DEB_BUILD_GNU_TYPE) --host $(DEB_HOST_GNU_TYPE)
else
CROSS=
endif

# see FEATURE AREAS in dpkg-buildflags(1)
DEB_BUILD_MAINT_OPTIONS=hardening=+all

DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

# Improve manpage from perldoc
MOAR_VERSION=$(shell cat VERSION)
MOAR_DATE=$(subst .,-, $(MOAR_VERSION))

# Package specific directory as libmoar is not versioned
# https://github.com/MoarVM/MoarVM/issues/74
MOAR_LIB_DIR=/usr/lib/moar
LDFLAGS += -Wl,-rpath=$(MOAR_LIB_DIR)

.PHONY: build

# This looks redundant with the implicit rule for %, but it isn't: .PHONY
# is ignored for implicit rules, so we need a separate rule for build.
build:
	dh $@

%:
	dh $@

override_dh_auto_configure:
	perl Configure.pl $(CROSS) \
		--prefix=/usr \
		--libdir=$(MOAR_LIB_DIR) \
		--debug \
		--has-libtommath \
		--has-libuv \
		--has-libatomic_ops \
		--has-libffi

override_dh_auto_build:
	perldoc -F -onroff \
		-w center:MoarVM \
		-w "release:MoarVM-$(MOAR_VERSION)" \
		-w "date:$(MOAR_DATE)" \
		docs/moar.pod > debian/moar.1
	dh_auto_build -- NOISY=1

override_dh_missing:
	dh_missing --list-missing
