#!/usr/bin/make -f
# -*- makefile -*-

include /usr/share/dpkg/buildtools.mk

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
# Query the generic "mpi" pc file (provided by both OpenMPI and MPICH)
# for the include path instead of "mpi-c", which only OpenMPI registers.
export DEB_CXXFLAGS_MAINT_APPEND = $(shell $(PKG_CONFIG) --cflags mpi)
# Use "mpi-c" when available (OpenMPI): it expands to -lmpi -lopen_mpi and
# is needed with OpenMPI's split library layout.  On MPICH only "mpi.pc"
# exists but its Libs: leaks MPICH's own build LDFLAGS, so fall back to
# linking through the libmpi.so alternative (-lmpi) there.
export DEB_LDFLAGS_MAINT_APPEND = $(shell $(PKG_CONFIG) --libs mpi-c 2>/dev/null || echo -lmpi)

%:
	dh $@

override_dh_auto_clean:
	dh_auto_clean -- CXXFLAGS="$(CXXFLAGS)" HAVE_LIBZ=y HAVE_LIBBZ2=y
	rm -rf install-prefix REFIX
	rm -f README.Ray README.RayPlatform RayPlatform/README

override_dh_auto_build:
	dh_auto_build -- MPICXX='$(CXX)' CXXFLAGS="$(CXXFLAGS)" DEBLDFLAGS="$(LDFLAGS) -lpthread" HAVE_LIBBZ2=y HAVE_LIBZ=y
	#Rename 2 docs to make more sence in package context
	cp README.md README.Ray
	cp RayPlatform/README.md README.RayPlatform
	cp RayPlatform/README.md RayPlatform/README
