#!/usr/bin/make -f
%:
	dh $@

this_arch := $(shell dpkg-architecture --query DEB_TARGET_ARCH)

# check if arch is known
this_known_archs := amd64 i386 armel armhf arm64 ppc64 ppc64el mips mipsel mips64el riscv64 s390x loong64
ifeq ($(filter $(this_arch),$(this_known_archs)),)
    $(error unknown debian architecture: $(this_arch))
endif

# map debian arch to golang arch
ifeq ($(this_arch),armel)
	this_arch := arm5
else ifeq ($(this_arch),armhf)
	this_arch := arm
else ifeq ($(this_arch),i386)
	this_arch := 386
else ifeq ($(this_arch),mipsel)
	this_arch := mipsle
else ifeq ($(this_arch),mips64el)
	this_arch := mips64le
else ifeq ($(this_arch),ppc64el)
	this_arch := ppc64le
endif

this_artifact_runner_file := artifacts/binary-linux-${this_arch}/github-act-runner-linux-${this_arch}

.PHONY: override_dh_auto_install
override_dh_auto_install:
	mkdir --parents debian/tmp/
	cp --recursive systemd/* debian/tmp/
	chmod +x $(this_artifact_runner_file)
	cp $(this_artifact_runner_file) debian/tmp/usr/lib/github-act-runner/runner

.PHONY: override_dh_strip
override_dh_strip:
	@echo "skip stripping"

# override build rule to use old gzip compression instead of new zst compression
# because some not very old Debian releases do not support zst compression
override_dh_builddeb:
	dh_builddeb -- -Zgzip
