#!/usr/bin/make -f

%:
	dh $@

# ---------------------------------------------------------------------------
# Disable automatic build + tests for Debian package
#
# The package is effectively a wrapper around the project source and the
# Nix flake. We do not need dh_auto_build to invoke the top-level Makefile,
# because that Makefile is meant for developer workflows (venv, setup, etc.)
# and would fail in the minimal build environment.
# ---------------------------------------------------------------------------
override_dh_auto_build:
	# No build step required for this package; skip calling the top-level Makefile.
	:

override_dh_auto_test:
	# We do not run tests as part of the Debian package build.
	:

# ---------------------------------------------------------------------------
# Install phase: copy wrapper + Nix bootstrap (init + lib) + full project source
# ---------------------------------------------------------------------------
override_dh_auto_install:
	# Create target directories
	install -d debian/package-manager/usr/bin
	install -d debian/package-manager/usr/lib/package-manager

	# Install wrapper
	install -m0755 scripts/pkgmgr-wrapper.sh \
		debian/package-manager/usr/bin/pkgmgr

	# Install Nix bootstrap (init + lib)
	install -d debian/package-manager/usr/lib/package-manager/nix
	cp -a scripts/nix/* \
		debian/package-manager/usr/lib/package-manager/nix/
	chmod 0755 debian/package-manager/usr/lib/package-manager/nix/init.sh

	# Copy full project source into /usr/lib/package-manager,
	# but do not include the debian/ directory itself.
	find . -mindepth 1 -maxdepth 1 \
	  ! -name debian \
	  ! -name .git \
	  -exec cp -a {} debian/package-manager/usr/lib/package-manager/ \;

	# Remove packaging-only and development artefacts from the installed tree
	rm -rf \
	  debian/package-manager/usr/lib/package-manager/debian \
	  debian/package-manager/usr/lib/package-manager/PKGBUILD \
	  debian/package-manager/usr/lib/package-manager/Dockerfile \
	  debian/package-manager/usr/lib/package-manager/.git \
	  debian/package-manager/usr/lib/package-manager/.github \
	  debian/package-manager/usr/lib/package-manager/tests \
	  debian/package-manager/usr/lib/package-manager/.gitignore \
	  debian/package-manager/usr/lib/package-manager/__pycache__ \
	  debian/package-manager/usr/lib/package-manager/.gitkeep || true
