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

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

export DOCDIR=$(CURDIR)/debian/libgoogle-glog-doc/
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
BUILDDIR = obj-$(DEB_HOST_MULTIARCH)

CONFIGURE_ARGS= \
 -DCMAKE_BUILD_TYPE=Release \
 -DLIB_INSTALL_DIR:STRING="lib/$(DEB_HOST_MULTIARCH)"

override_dh_installdocs-indep:
	dh_installdocs
	sed -i 's|http.*/favicon.ico||' \
		$(DOCDIR)/usr/share/doc/libgoogle-glog-dev/glog.html

override_dh_auto_build:
	# dynamically linked
	dh_auto_build -B $(BUILDDIR)
	# statically linked
	dh_auto_build -B $(BUILDDIR)-static

override_dh_auto_configure:
	# dynamically linked
	dh_auto_configure -B $(BUILDDIR) \
		-- $(CONFIGURE_ARGS) \
		-DBUILD_SHARED_LIBS=ON \
		-DBUILD_TESTING=ON

	# statically linked
	dh_auto_configure -B $(BUILDDIR)-static \
		-- $(CONFIGURE_ARGS) \
		-DBUILD_SHARED_LIBS=OFF \
		-DBUILD_TESTING=OFF

override_dh_auto_install:
	dh_auto_install -O--buildsystem=cmake -B $(BUILDDIR)
	find $(CURDIR)/debian/tmp/ -type d -name .cmake | xargs -r rm -rfv

execute_before_dh_install:
	# put the static libs together with the rest of the stuff
	cp -v $(BUILDDIR)-static/*.a debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/
	-$(RM) -r $(BUILDDIR)-static

override_dh_auto_test:
	-if [ -f /proc/version ]; then $(MAKE) check; fi

%:
	dh  $@ --buildsystem=cmake

get-orig-source:
	uscan --verbose --force-download --rename

.PHONY: override_dh_installdocs-indep override_dh_auto_install \
	execute_before_dh_install override_dh_auto_build \
	override_dh_auto_test override_dh_auto_configure
