#!/usr/bin/make -f

export PYBUILD_NAME=healpy

# Enable build hardening
export DEB_BUILD_MAINT_OPTIONS = hardening=+bindnow
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

# Link-time optimisation demands knowledge about all CFLAGS both at
# compile time (as represented by CFLAGS and CXXFLAGS) but also at
# at link time.
#
# Adapted from
# http://anonscm.debian.org/cgit/pkg-boinc/boinc.git/tree/debian/rules
ifeq (,$(findstring nolto,$(DEB_BUILD_OPTIONS)))
 $(info I: Activating LinkTimeOptimisation)
 export CFLAGS += -flto
 export CXXFLAGS += -flto
 export LDFLAGS := $(CFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS)
 export AR := gcc-ar
 export RANLIB := gcc-ranlib
endif

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

override_dh_shlibdeps:
	dh_shlibdeps
	dh_numpy
	dh_numpy3

matplotlibrc:
	echo backend: agg > $@

override_dh_auto_test: matplotlibrc
	PYTHONDONTWRITEBYTECODE=yes dh_auto_test

# After installing, remove data directories that we will replace with symlinks
override_dh_install:
	dh_install
	rm -rf debian/python*-healpy/usr/lib/python*/dist-packages/healpy/data debian/python*-healpy/usr/lib/python*/dist-packages/healpy/test/data

# Fix permissions on data files
override_dh_fixperms-indep:
	find debian/healpy-data/usr/share/healpy -type f | xargs chmod -x
	dh_fixperms
