#!/usr/bin/make -f

DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
DEB_BUILD_ARCH:=$(shell dpkg --print-architecture)
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

LDFLAGS += -pthread

%:
	dh $@ --with pkgkde_symbolshelper,autoreconf

override_dh_auto_configure:
	[ ! -d libatomic_ops-1.2 ] || mv libatomic_ops-1.2 libatomic_ops-1.2.bak
	./configure \
		$(CONFIG_OPTS) \
		--enable-cplusplus \
		--disable-dependency-tracking \
		--with-tags=CXX \
		--prefix=/usr \
		--mandir=\$${prefix}/share/man \
		--sysconfdir=/etc \
		--localstatedir=/var/lib \
		--datadir=\$${prefix}/share/doc \
		--host=$(DEB_HOST_GNU_TYPE) \
		--build=$(DEB_BUILD_GNU_TYPE) \
		--libdir=\$${prefix}/lib/$(DEB_HOST_MULTIARCH)

ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
override_dh_auto_test:
	$(MAKE) check
endif

override_dh_install:
	install -D doc/gc.man debian/tmp/usr/share/man/man3/gc_malloc.3
	dh_install
	rm debian/libgc-dev/usr/share/doc/libgc1c2/README.environment

override_dh_auto_clean:
	[ -d libatomic_ops-1.2 ] || [ ! -d libatomic_ops-1.2.bak ] || mv libatomic_ops-1.2.bak libatomic_ops-1.2
	dh_auto_clean
	rm -rf autom4te.cache libatomic_ops atomic_ops_sysdeps.S atomic_ops.c

override_dh_installchangelogs:
	dh_installchangelogs ChangeLog
