#!/usr/bin/make -f

DHFLAGS=--parallel

export GOCACHE=$(CURDIR)/debian/.go-cache
export GOMODCACHE=$(CURDIR)/debian/.go-mod-cache
export DEB_BUILD_MAINT_OPTIONS=hardening=+all
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

BUILD_ARCH = $(shell dpkg-architecture -qDEB_HOST_ARCH)

%:
	dh $@ $(DHFLAGS) --without autoreconf

#override_dh_missing:
#	dh_missing --fail-missing

override_dh_install:
	rm -rfv debian/tmp/usr/lib/*/caja/extensions-2.0/libcaja-engrampa.la
ifeq ($(BUILD_ARCH), amd64)
	install -D -m 755 third-party/libzip/amd/7za-zstd debian/tmp/usr/bin/7za-zstd
endif
ifeq ($(BUILD_ARCH), arm64)
	install -D -m 755 third-party/libzip/arm/7za-zstd debian/tmp/usr/bin/7za-zstd
endif
ifeq ($(BUILD_ARCH), aarch64)
	install -D -m 755 third-party/libzip/arm/7za-zstd debian/tmp/usr/bin/7za-zstd
endif
	dh_install

override_dh_installchangelogs:
	dh_installchangelogs NEWS

override_dh_dwz:

override_dh_auto_configure:
	# upstream tarball is without configure. autogen.sh will create it
	NOCONFIGURE=1 ./autogen.sh
	dh_auto_configure $(DHFLAGS) -- \
		--disable-silent-rules \
		--disable-packagekit \
		--enable-magic \
		--libexecdir=/usr/lib/engrampa

override_dh_auto_build:
	mkdir -p $(GOCACHE) $(GOMODCACHE)
	dh_auto_build

override_dh_auto_test:
	mkdir -p $(GOCACHE) $(GOMODCACHE)
	dh_auto_test

get-orig-source:
	uscan --noconf --force-download --rename --download-current-version --destdir=..
