.DEFAULT_GOAL := help
# Convenience wrappers around the Maven build profiles.
#
#   make               plain jar (default build, not self-contained)
#   make jar           same as above
#   make standalone    self-contained jar + upstream .deb
#   make distro        slim jar whose manifest Class-Path points at system jars
#   make native-image  jar with picocli native-image metadata
#   make test          run the test suite
#   make clean         remove target/
#
# The jar-producing targets run `clean` first: the plain, standalone, distro and
# native-image variants share the same output filename, so a stale target/ must
# never be reused.
#
# Overridable variables, e.g.:
#   make distro SWT_VERSION=4.x PICOCLI_VERSION=4.7.6
#   make distro SYSTEM_JAR_DIR=/usr/lib/jvm/java
#
# `make distro` mirrors the Debian package: it needs the distro's SWT/picocli
# jars under the coordinates in SWT_VERSION/PICOCLI_VERSION (e.g.
# org.eclipse.swt:org.eclipse.swt:debian, available from Debian's maven-repo),
# it skips the picocli man-page generator just as Debian's maven.ignoreRules
# does (the man pages are committed in misc/man/), and it skips the tests like
# Debian's maven.test.skip=true (JUnit 6 is not packaged in Debian).

MVN ?= mvn
SWT_VERSION ?= debian
PICOCLI_VERSION ?= debian
SYSTEM_JAR_DIR ?= /usr/share/java

.PHONY: jar standalone deb distro native-image test clean

jar:  ## plain jar (default build, not self-contained)
	$(MVN) clean package

standalone:  ## self-contained jar + upstream .deb
	$(MVN) -Pstandalone clean package

distro: ## slim jar whose manifest Class-Path points at system jars
	$(MVN) -Dstegosuite.distro=true \
		-Dswt.version=$(SWT_VERSION) \
		-Dpicocli.version=$(PICOCLI_VERSION) \
		-Dstegosuite.systemJarDir=$(SYSTEM_JAR_DIR) \
		-Dexec.skip=true \
		-Dmaven.test.skip=true \
		clean package

native-image:  ## jar with picocli native-image metadata
	$(MVN) -Pnative-image clean package

test: ## run the test suite
	$(MVN) test

clean: ## remove target/
	$(MVN) clean

help: ## This help.
	@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
