# Generated by yjcli (managed — regenerated when platforms or plugins change).
# Windows: use make.ps1 with the same targets.
# Each target only calls tools/<tool>/<platform>/<tool>.sh; see tools/<tool>/GUIDE.md.

PLATFORMS := {{platforms}}

.PHONY: help{{#if runner}} $(PLATFORMS){{/if}}{{#if builder}}{{#if platform_proto}} proto-build{{/if}}{{/if}}

help:
	@echo "Usage:"
{{#if runner}}
	@echo "  make <platform> [NAME=<service>]               # run locally (tools/runner)"
{{/if}}
{{#if builder}}
	@echo "  make <platform>-build-<env> [NAME=<service>]   # build into dist/ (tools/builder)"
{{#if platform_proto}}
	@echo "  make proto-build [PROTO_LANG=<language>]       # generate proto/dist/<language>/ (tools/builder/proto)"
{{/if}}
{{/if}}
{{#if deployer}}
	@echo "  make <platform>-deploy-<env> [NAME=<service>]  # deploy dist/ (tools/deployer)"
{{/if}}
	@echo "  <env>: development | production | any .env.<env> under tools/secrets/<platform>/<service>/"
	@echo ""
	@echo "Platforms: $(PLATFORMS)"
{{#if runner}}

$(PLATFORMS):
	@test -x "tools/runner/$@/runner.sh" || (echo "missing: tools/runner/$@/runner.sh"; exit 1)
	@"tools/runner/$@/runner.sh" $(NAME)
{{/if}}
{{#if builder}}

{{#if platform_proto}}

proto-build:
	@test -x "tools/builder/proto/builder.sh" || (echo "missing: tools/builder/proto/builder.sh"; exit 1)
	@"tools/builder/proto/builder.sh" $(PROTO_LANG)
{{/if}}
{{/if}}
{{#if builder}}

# <platform>-build-<env> / <platform>-deploy-<env> for any environment name.
.DEFAULT:
	@t="$@"; tool=""; \
{{#if builder}}
	case "$$t" in *-build-*) tool=builder; p="$${t%-build-*}"; e="$${t##*-build-}" ;; esac; \
{{/if}}
{{#if deployer}}
	case "$$t" in *-deploy-*) tool=deployer; p="$${t%-deploy-*}"; e="$${t##*-deploy-}" ;; esac; \
{{/if}}
	case " $(PLATFORMS) " in *" $$p "*) ;; *) tool="" ;; esac; \
	if [ -z "$$tool" ]; then echo "unknown target: $$t (see: make help)"; exit 1; fi; \
	test -x "tools/$$tool/$$p/$$tool.sh" || { echo "missing: tools/$$tool/$$p/$$tool.sh"; exit 1; }; \
	"tools/$$tool/$$p/$$tool.sh" "$$e" $(NAME)
{{/if}}
