#!/usr/bin/make -f

include /usr/share/dpkg/architecture.mk

# Enable hardening build flags
export DEB_BUILD_MAINT_OPTIONS=hardening=+all

# set the MPLCONFIGDIR to avoid writing into non writable location
export HOME=$(CURDIR)/build
export MPLCONFIGDIR=$(CURDIR)/build

# Use agg Matplotlib backend for testing on headless machines.
export MPLBACKEND=agg

export LC_ALL=C.UTF-8
export ASTROPY_USE_SYSTEM_ALL=1
export SETUPTOOLS_SCM_PRETEND_VERSION=${DEB_VERSION_UPSTREAM}
PY3VERSION = $(shell py3versions -d -v)

# Generate PLY files
export PYBUILD_AFTER_BUILD=cd {build_dir}; python{version} -c 'import astropy.coordinates; astropy.coordinates.angle_utilities.parse_angle("0°"); import astropy.units.format; astropy.units.format.CDS.parse("m/s"); astropy.units.format.Generic.parse("m"); astropy.units.format.OGIP.parse("m/s")'

# Don't run hypothesis tests
export PYBUILD_TEST_ARGS=--astropy-header -m "not hypothesis"


%:
	dh $@ --with python3,sphinxdoc --buildsystem=pybuild

override_dh_shlibdeps:
	dh_shlibdeps
	dh_numpy3

override_dh_installdocs-indep:
	PYTHONPATH=$(CURDIR)/debian/tmp/usr/lib/python$(PY3VERSION)/dist-packages \
	    $(MAKE) -C docs -k html || true
	dh_installdocs

override_dh_sphinxdoc-arch:
	# sphinxdoc is only needed on indep and does not work here.

override_dh_installchangelogs:
	dh_installchangelogs docs/changelog.rst

override_dh_auto_clean:
	dh_auto_clean
	rm -rf build astropy.egg-info
	rm -rf astropy_helpers-*.egg
	rm -rf docs/_build docs/_generated

ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
override_dh_auto_test:
ifneq ($(DEB_HOST_ARCH),mipsel)
	dh_auto_test
endif
endif

override_dh_python3:
	dh_python3
	dh_python3-ply $$(find $(PYBUILD_DESTDIR_python3) -name '*tab.py'| grep -v test_tab.py)

override_dh_strip_nondeterminism:
	dh_strip_nondeterminism -Xinvalid.dat.gz

override_dh_missing:
	dh_missing --list-missing
