#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS=optimize=+lto

include /usr/share/dpkg/default.mk

ifeq ($(origin FC),default)
export FC := $(DEB_HOST_GNU_TYPE)-gfortran
endif

PDF_DOCS := AMD/Doc/AMD_UserGuide.pdf CAMD/Doc/CAMD_UserGuide.pdf CHOLMOD/Doc/CHOLMOD_UserGuide.pdf KLU/Doc/KLU_UserGuide.pdf Mongoose/Doc/Mongoose_UserGuide.pdf UMFPACK/Doc/UMFPACK_QuickStart.pdf UMFPACK/Doc/UMFPACK_UserGuide.pdf LDL/Doc/ldl_userguide.pdf ParU/Doc/paru_user_guide.pdf SPQR/Doc/spqr_user_guide.pdf SPEX/Doc/SPEX_UserGuide.pdf

# Force CMake buildsystem, because otherwise the top-level Makefile is used
%:
	dh $@ --buildsystem=cmake

# We do not build GraphBLAS, because it is provided by src:suitesparse-graphblas.
# We also do not build LAGraph because suitesparse-graphblas is currently too old.
override_dh_auto_configure-arch:
	dh_auto_configure -- -DSUITESPARSE_ENABLE_PROJECTS="suitesparse_config;mongoose;amd;btf;camd;ccolamd;colamd;cholmod;cxsparse;ldl;klu;umfpack;paru;rbio;spqr;spex" -DBLA_VENDOR=Generic -DBLA_PREFER_PKGCONFIG=TRUE -DSUITESPARSE_USE_CUDA=OFF

# The docs are not built through the top-level CMakelists.txt, but through a Makefile
override_dh_auto_configure-indep:

override_dh_auto_build-indep:
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
	rm -f $(PDF_DOCS)
	# For Mongoose, the doc is built through CMake; the passed flag makes it work
	make CMAKE_OPTIONS='-DSUITESPARSE_ROOT_CMAKELISTS=ON' docs
endif

override_dh_auto_test-indep:

override_dh_auto_install-indep:

execute_after_dh_auto_install-indep:
	pybuild -d SPEX/Python/ --install

execute_after_dh_auto_clean:
	make purge
	rm -f $(PDF_DOCS)
	if [ -e .pybuild ]; then pybuild --clean; fi
	# For some unknown reason, pybuild --clean does not clean the following
	rm -rf .pybuild

override_dh_compress:
	dh_compress -X.pdf
