#!/usr/bin/make -f

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

export PYBUILD_NAME = spglib
export PYBUILD_SYSTEM = pyproject
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

%:
	dh $@ --buildsystem cmake --with python3,ruby

override_dh_auto_configure:
	dh_auto_configure -- -DSPGLIB_WITH_Fortran=ON
	dh_auto_configure --buildsystem ruby

execute_after_dh_auto_build:
	dh_auto_build --buildsystem pybuild -- --after-build 'rm {build_dir}/spglib/libsymspg.so*'
	dh_auto_build --buildsystem ruby

execute_after_dh_auto_test:
	LD_LIBRARY_PATH=$(CURDIR)/obj-$(DEB_HOST_GNU_TYPE) dh_auto_test --buildsystem pybuild

execute_after_dh_auto_install:
	dh_auto_install --buildsystem pybuild
	cd ruby && ruby -I/usr/lib/ruby/vendor_ruby extconf.rb --with-getspg-lib=$$(realpath ../obj-*) --with-getspg-include=../src
	ABS_TOP_DESTDIR=$(CURDIR)/debian/tmp/usr dh_auto_install --buildsystem ruby

execute_after_dh_makeshlibs:
	cut -d - -f 1 debian/libsymspg2/DEBIAN/symbols | sponge debian/libsymspg2/DEBIAN/symbols

override_dh_installchangelogs:
	dh_installchangelogs ChangeLog.md

execute_after_dh_auto_clean:
	dh_auto_clean --buildsystem pybuild
	rm -rf .pytest_cache/ test/functional/python/__pycache__/
	dh_auto_clean --buildsystem ruby
