COMMIT ?= $(shell git rev-parse --short HEAD)

# emily is aarch64, so that is the default target. A foreign platform needs
# the host's binfmt handlers, because podman has no built-in QEMU.
PLATFORMS ?= linux/arm64
IMAGE ?= registry.tanshu.com/hops

.PHONY: build-production
build-production: ## Build HEAD with podman, push :$(COMMIT) and :main
	@echo "==> podman build --platform $(PLATFORMS) -> $(IMAGE):$(COMMIT) + :main"
	@git archive --format=tar HEAD | podman build \
		--platform $(PLATFORMS) \
		--tag $(IMAGE):$(COMMIT) \
		--tag $(IMAGE):main \
		- || { \
		echo "podman build failed."; \
		echo "Cross-platform builds need binfmt on this host (podman has no built-in QEMU):"; \
		echo "  sudo apt install qemu-user-static    # on an x86_64 host, for $(PLATFORMS)"; \
		exit 1; \
	}
	podman push $(IMAGE):$(COMMIT)
	podman push $(IMAGE):main

.PHONY: build-check
build-check: ## Compile check from HEAD with podman, nothing pushed
	@git archive --format=tar HEAD | podman build \
		--platform $(PLATFORMS) \
		--tag hops:check \
		--pull \
		-
