#!/usr/bin/make -f

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

# Fuse uWSGI and our package versions, flattened to native format
UWSGI_VERSION = $(shell dpkg-query --show --showformat '$${Version}' uwsgi-src)
OUR_BINARY_VERSION = $(subst -,+,$(UWSGI_VERSION))+$(DEB_VERSION)

PYPY = $(shell readlink /usr/bin/pypy3)
DESTDIR = $(CURDIR)/debian/uwsgi-plugin-pypy3

%:
	dh $@

override_dh_auto_build:
	cp -ar /usr/src/uwsgi/plugins/pypy $(CURDIR)/
	uwsgi --build-plugin "pypy pypy3"

execute_before_dh_link:
	ln -s ../../../$(PYPY) $(DESTDIR)/usr/lib/uwsgi/plugins/pypy/home
	ln -s ../../../$(DEB_HOST_GNU_TYPE)/lib$(PYPY)-c.so $(DESTDIR)/usr/lib/uwsgi/plugins/pypy/libpypy3-c.so

override_dh_gencontrol:
	dh_gencontrol -- -v$(OUR_BINARY_VERSION)
