#!/usr/bin/make -f

include /usr/share/dpkg/default.mk

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

include /usr/share/dpkg/architecture.mk
export LUAJIT_INC=/usr/include/luajit-2.1
export LUAJIT_LIB=/usr/lib/$(DEB_HOST_MULTIARCH)/libluajit-5.1.so

export DEB_CFLAGS_MAINT_APPEND = -DLUA_DEFAULT_PATH=\"/usr/share/lua/5.1/\?.lua\;\"

%:
	dh $@

execute_before_dh_auto_clean:
	# remove forgotten autogenerated file src/ngx_http_lua_autoconf.h
	# It fixes problem, when package fails to build a source package
	# after a successful build (dpkg-buildpackage; dpkg-buildpackage -S)
	rm -f ./src/ngx_http_lua_autoconf.h

NGINX_VERSION = $(shell /usr/sbin/nginx -V 2>&1 | sed -ne 's,nginx version: nginx/,,p')
DEB_VERSION_EPOCH = $(call dpkg_late_eval,DEB_VERSION_EPOCH,echo '$(DEB_VERSION_EPOCH_UPSTREAM)' | sed -e 's/[^:]*$$//')
DEB_VERSION_REVISION = $(call dpkg_late_eval,DEB_VERSION_REVISION,echo '$(DEB_VERSION_UPSTREAM_REVISION)' | sed -e 's/^.*-//')
NGINX_DEB_VERSION = $(DEB_VERSION_EPOCH)$(DEB_VERSION_UPSTREAM)+$(NGINX_VERSION)-$(DEB_VERSION_REVISION)

override_dh_gencontrol:
	dh_gencontrol --remaining-packages -- -v$(NGINX_DEB_VERSION)
