# Builds the modding subproject - see README.md.
#
# Targets:
#   all (default)   - `hacked` and `mods`.
#   build-image      - builds the hacked-build-image Docker image
#                       (./hacked-build-image.sh). Only needed once, or after
#                       hacked-build-image/ or hacked/go.mod|go.sum changes.
#   hacked           - compiles hacked/ for Linux and Windows via that image,
#                       offline. Output lands in dist/.
#   mdlp-image       - builds the mdlp-image Docker image (./mdlp-image.sh).
#                       Only needed once, or after mdlp-image/ or
#                       mdlp/go.mod|go.sum changes.
#   mods             - builds every mod under mods/ via that image, offline.
#                       Set MODS="name1 name2" to build only those. Output
#                       lands in dist/mods/.
#   clean            - removes dist/.
.PHONY: all build-image hacked mdlp-image mods clean

export MODS

all: hacked mods

build-image:
	./hacked-build-image.sh

# If we're already running inside the hacked-build-image
# (HACKED_BUILD_IMAGE, set by its Dockerfile), compile directly instead of
# trying to docker-run it again - e.g. a CI job already using this image as
# its container. Otherwise, run it via Docker as usual.
hacked:
	@if [ -n "$$HACKED_BUILD_IMAGE" ]; then \
		bash hacked-build-image/build-hacked.sh; \
	else \
		./hacked-build-run-image.sh; \
	fi

mdlp-image:
	./mdlp-image.sh

# Same already-in-the-image shortcut as `hacked` above, for MDLP_IMAGE.
mods:
	@if [ -n "$$MDLP_IMAGE" ]; then \
		bash mdlp-image/process-mods.sh; \
	else \
		./mdlp-run-image.sh; \
	fi

clean:
	rm -rf dist
