# makefile
#
# @link        https://github.com/tecnickcom/tc-font-mirror

# ----------------------------------------------------------------------------------------------------------------------

# Project name
PROJECT=tc-font-mirror

# Project version
VERSION=$(shell cat VERSION)

# Font family directories
FAMILIES=core pdfa freefont dejavu unifont cid0

# --- MAKE TARGETS ---

# Display general help about this command
.PHONY: help
help:
	@if [ -t 1 ] && [ -z "$${NO_COLOR:-}" ]; then \
		B=$$(printf '\033[1m'); C=$$(printf '\033[36m'); Y=$$(printf '\033[33m'); D=$$(printf '\033[2m'); R=$$(printf '\033[0m'); \
	else \
		B=''; C=''; Y=''; D=''; R=''; \
	fi; \
	printf "\n%s%s%s %s(v%s)%s\n" "$$B" "$(PROJECT)" "$$R" "$$D" "$(VERSION)" "$$R"; \
	printf "\n%sUsage:%s make %s<target>%s\n\n" "$$Y" "$$R" "$$C" "$$R"; \
	printf "%sTargets:%s\n" "$$Y" "$$R"; \
	awk -v c="$$C" -v r="$$R" '/^## /{desc=substr($$0,4)} /^\.PHONY:/{if(NF>1){if(desc){n++; t[n]=$$2; d[n]=desc; if(length($$2)>w) w=length($$2)} desc=""}} END{fmt="  %s%-" w "s%s  %s\n"; for(i=1;i<=n;i++) printf fmt,c,t[i],r,d[i]}' Makefile; \
	printf "\n"

# alias for help target
.PHONY: all
all: help

## Check that every family directory has a non-empty LICENSE file
.PHONY: check
check:
	@status=0; \
	for dir in $(FAMILIES); do \
		if ! grep -q '[^[:space:]]' "$$dir/LICENSE" 2>/dev/null; then \
			echo "ERROR: missing or empty $$dir/LICENSE"; \
			status=1; \
		fi; \
	done; \
	exit $$status

## Tag this GIT version
.PHONY: tag
tag:
	git checkout main && \
	git tag -a ${VERSION} -m "Release ${VERSION}" && \
	git push origin --tags && \
	git pull

