#!/usr/bin/make -f

export PYBUILD_NAME=fltk
%:
	dh $@ --with python3 --buildsystem=pybuild

override_dh_auto_build:
	python3 setup.py swig
	dh_auto_build

override_dh_auto_install:
	dh_auto_install

ifneq (,$(filter python3-fltk-doc,$(shell dh_listpackages)))
	# I'm building the docs, so presumably we're not cross-building, and I
	# can run pydoc3 on the just-built binaries. This is declared in the
	# Build-Profiles field in debian/control
	#
	# Pick the first requested python version: I could have more than one if
	# multiple Python versions are currently installed. I don't care which I
	# use, but I must pick one
	#
	# I also remove links to absolute build-time paths
	set -e;										\
	V=`py3versions -r | awk '{sub("python","",$$1); print $$1; exit}'`;		\
	Din=python3-fltk/usr/lib/python$$V/dist-packages/fltk;				\
	Dout=python3-fltk-doc/usr/share/doc/python3-fltk;				\
	mkdir -p debian/$$Dout;								\
	( cd debian/$$Din &&								\
	    pydoc$$V -w ./ &&								\
	    mv fltk.html _fltk.html							\
	       ../../../../../../$$Dout; );						\
	perl -p -i -e 's{(<a href="file:).*?(/usr/.*?">).*?(/usr/)}{$$1$$2$$3}'		\
	  debian/$$Dout/fltk.html							\
	  debian/$$Dout/_fltk.html
endif





# There aren't any tests defined in this package, and the autodetection in
# pybuild fails with errors
override_dh_auto_test:
	true
