#!make FORMAT_MARKER := mn-output- FORMATS := $(shell grep "$(FORMAT_MARKER)" *.adoc | cut -f 2 -d ' ' | tr ',' '\n' | sort | uniq | tr '\n' ' ') SRC := $(filter-out README.adoc, $(wildcard *.adoc)) XML := $(patsubst %.adoc,%.xml,$(SRC)) HTML := $(patsubst %.adoc,%.html,$(SRC)) DOC := $(patsubst %.adoc,%.doc,$(SRC)) PDF := $(patsubst %.adoc,%.pdf,$(SRC)) WSD := $(wildcard models/*.wsd) XMI := $(patsubst models/%,xmi/%,$(patsubst %.wsd,%.xmi,$(WSD))) PNG := $(patsubst models/%,images/%,$(patsubst %.wsd,%.png,$(WSD))) HOST_SHARE_DIR=$(USERPROFILE)\$(shell for %%I in (.) do echo %%~nxI) COMPILE_CMD_LOCAL := bundle exec metanorma $(SRC) COMPILE_CMD_DOCKER := docker run --rm -it -v $(CURDIR):/metanorma/ ribose/metanorma "metanorma $(SRC)" ifdef METANORMA_DOCKER COMPILE_CMD := echo "Compiling via docker..." & $(COMPILE_CMD_DOCKER) else COMPILE_CMD := echo "Compiling locally..." & $(COMPILE_CMD_LOCAL) endif _OUT_FILES := $(foreach FORMAT,$(FORMATS),$(shell echo $(FORMAT) | tr '[:lower:]' '[:upper:]')) OUT_FILES := $(foreach F,$(_OUT_FILES),$($F)) all: $(OUT_FILES) %.xml %.html %.doc %.pdf: %.adoc | bundle ${COMPILE_CMD} images: $(PNG) images/%.png: models/%.wsd plantuml -tpng -o ../images/ $< xmi: $(XMI) xmi/%.xmi: models/%.wsd plantuml -xmi:star -o ../xmi/ $< define FORMAT_TASKS OUT_FILES-$(FORMAT) := $($(shell echo $(FORMAT) | tr '[:lower:]' '[:upper:]')) open-$(FORMAT): $$(OUT_FILES-$(FORMAT)) clean-$(FORMAT): rm $$(OUT_FILES-$(FORMAT)) $(FORMAT): clean-$(FORMAT) $$(OUT_FILES-$(FORMAT)) .PHONY: clean-$(FORMAT) endef $(foreach FORMAT,$(FORMATS),$(eval $(FORMAT_TASKS))) open: open-html clean: rm -rf $(OUT_FILES) bundle: IF "" == "${METANORMA_DOCKER}" bundle .PHONY: bundle all open clean # # Watch-related jobs # .PHONY: watch serve watch-serve NODE_BINS := onchange live-serve run-p NODE_BIN_DIR := node_modules/.bin NODE_PACKAGE_PATHS := $(foreach PACKAGE_NAME,$(NODE_BINS),$(NODE_BIN_DIR)/$(PACKAGE_NAME)) $(NODE_PACKAGE_PATHS): package.json npm i watch: $(NODE_BIN_DIR)/onchange make all $< $(ALL_SRC) -- make all define WATCH_TASKS watch-$(FORMAT): $(NODE_BIN_DIR)/onchange make $(FORMAT) $$< $$(SRC_$(FORMAT)) -- make $(FORMAT) .PHONY: watch-$(FORMAT) endef $(foreach FORMAT,$(FORMATS),$(eval $(WATCH_TASKS))) serve: $(NODE_BIN_DIR)/live-server revealjs-css reveal.js images set PORT=$${PORT:-8123} & \ set port=$${PORT} & \ for /r %%html in $(HTML) do ( \ $< --entry-file=%%html --port=%port% --ignore="*.html,*.xml,Makefile,Gemfile.*,package.*.json" --wait=1000 & \ set /A port=%port%+1 \ ) watch-serve: $(NODE_BIN_DIR)/run-p $< watch serve # # Deploy jobs # publish: mkdir -p published xcopy $(basename $(SRC)).* published copy $(firstword $(HTML)) published\index.html IF EXIST "images" xcopy /E images published