#!/usr/bin/make -f

HWLOC_VERSION := 2.13.0
INSTALL_PATH  := /opt/ohpc/pub/libs/hwloc
PKG           := $(CURDIR)/debian/hwloc-ohpc
SRCDIR        := $(CURDIR)/hwloc-$(HWLOC_VERSION)

%:
	dh $@

override_dh_auto_configure:
	test -s SOURCES/hwloc-$(HWLOC_VERSION).tar.bz2 || \
		wget -q -O SOURCES/hwloc-$(HWLOC_VERSION).tar.bz2 \
			https://download.open-mpi.org/release/hwloc/v2.13/hwloc-$(HWLOC_VERSION).tar.bz2
	rm -rf $(SRCDIR)
	tar xf SOURCES/hwloc-$(HWLOC_VERSION).tar.bz2
	cd $(SRCDIR) && ./configure --prefix=$(INSTALL_PATH)

override_dh_auto_build:
	cd $(SRCDIR) && $(MAKE) -j$$(nproc)

override_dh_auto_install:
	cd $(SRCDIR) && $(MAKE) DESTDIR=$(PKG) install
	find $(PKG) -name '*.la' -delete
	# Make the fixed OHPC hwloc library path visible to system daemons.
	mkdir -p $(PKG)/etc/ld.so.conf.d
	echo "$(INSTALL_PATH)/lib" > $(PKG)/etc/ld.so.conf.d/ohpc-hwloc.conf
	# Install modulefile
	mkdir -p $(PKG)/opt/ohpc/pub/modulefiles/hwloc
	install -m 644 debian/modulefile $(PKG)/opt/ohpc/pub/modulefiles/hwloc/$(HWLOC_VERSION)

override_dh_auto_clean:
	rm -rf $(SRCDIR)

override_dh_usrlocal:

override_dh_shlibdeps:
	dh_shlibdeps -l$(PKG)$(INSTALL_PATH)/lib -- --ignore-missing-info || true

override_dh_strip:
	dh_strip --no-automatic-dbgsym || true

override_dh_auto_test:
