# Auto-generated by Cimas: Do not edit it manually! # See https://github.com/metanorma/cimas #!make SHELL := cmd # Ensure the xml2rfc cache directory exists locally IGNORE := $(shell md $(USERPROFILE)\.cache\xml2rfc) SRC := $(shell yq r metanorma.yml metanorma.source.files | cut -c 3-) ifeq ($(SRC),null) SRC := endif ifeq ($(SRC),ll) SRC := endif ifeq ($(SRC),) BUILT := $(subst ${ },${\n},$(shell yq r metanorma.yml metanorma.source.built_targets | cut -d ":" -f 1)) ifeq ($(BUILT),null) BUILT := SRC := endif ifeq ($(BUILT),ll) BUILT := SRC := endif ifeq ($(BUILT),) SRC := endif ifeq ($(BUILT),) SRC := $(filter-out README.adoc, $(wildcard sources/*.adoc)) else XML := $(patsubst sources/%,documents/%,$(BUILT)) endif endif FORMATS := $(subst -,${ },$(strip $(shell yq r metanorma.yml metanorma.formats))) ifeq ($(FORMATS),null) FORMATS := endif ifeq ($(FORMATS),) FORMAT_MARKER := mn-output- FORMATS := $(subst ${\n},${ },$(shell grep "$(FORMAT_MARKER)" $(SRC) | cut -f 2 -d " " | tr "," "\n" | sort | uniq)) endif XML ?= $(patsubst sources/%,documents/%,$(patsubst %.adoc,%.xml,$(SRC))) HTML := $(patsubst %.xml,%.html,$(XML)) ifdef METANORMA_DOCKER PREFIX_CMD := echo "Running via docker..." & docker run -v "$$(pwd)":/metanorma/ $(METANORMA_DOCKER) else ifdef SKIP_BUNDLE PREFIX_CMD := echo "Running locally..." & else PREFIX_CMD := echo "Running locally via bundle ..." & bundle exec endif endif _OUT_FILES := $(foreach FORMAT,$(FORMATS),$(shell echo $(FORMAT) | tr '[:lower:]' '[:upper:]')) OUT_FILES := $(foreach F,$(_OUT_FILES),$($F)) define print_vars $(info "src $(SRC)") $(info "xml $(XML)") $(info "formats $(FORMATS)") endef all: documents.html $(call print_vars) documents: setlocal enableextensions & md $@ & endlocal documents/%.html: documents/%.xml | documents ${PREFIX_CMD} metanorma $< documents/%.xml: sources/%.xml | documents if not exist "$(subst /,\,$(dir $@))" md "$(subst /,\,$(dir $@))" move "$(subst /,\,$<)" "$(subst /,\,$@)" # Build canonical XML output # If XML file is provided, copy it over # Otherwise, build the xml using adoc sources/%.xml: | bundle $(eval BUILT_TARGET := $(subst /,\,$(shell yq r metanorma.yml metanorma.source.built_targets[$@]))) $(eval BUILT_TARGET_EMPTY := $(if $(filter $(or $(BUILT_TARGET),null),null ll),true,false)) if "$(BUILT_TARGET_EMPTY)" == "true" ( \ $(PREFIX_CMD) metanorma -x xml "$(subst xml,adoc,$@)" \ ) else ( \ if exist "$(BUILT_TARGET)" ( \ if "$(suffix $(BUILT_TARGET))" == ".xml" ( \ copy "$(BUILT_TARGET)" "$(subst /,\,$@)" \ ) else ( \ $(PREFIX_CMD) metanorma $(BUILT_TARGET) & \ copy "$(subst adoc,xml,$(BUILT_TARGET))" "$(subst /,\,$@)" \ ) \ ) else ( \ $(PREFIX_CMD) metanorma $(BUILT_TARGET) & \ copy "$(subst adoc,xml,$(BUILT_TARGET))" "$(subst /,\,$@)" \ ) \ ) documents.rxl: $(XML) $(HTML) ${PREFIX_CMD} relaton concatenate \ -t "$(shell yq r metanorma.yml relaton.collection.name)" \ -g "$(shell yq r metanorma.yml relaton.collection.organization)" \ documents $@ documents.html: documents.rxl $(PREFIX_CMD) relaton xml2html documents.rxl %.adoc: define FORMAT_TASKS OUT_FILES-$(FORMAT) := $($(shell echo $(FORMAT) | tr '[:lower:]' '[:upper:]')) open-$(FORMAT): "$$(OUT_FILES-$(FORMAT))" clean-$(FORMAT): del /q $$(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) del /q documents published del /q *_images del /q documents.* bundle: ifndef METANORMA_DOCKER ifndef SKIP_BUNDLE bundle install --jobs 4 --retry 3 endif endif $(call print_vars) .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))) ifndef PORT override PORT = 8123 endif serve: $(NODE_BIN_DIR)/live-server revealjs-css reveal.js 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: published published: documents.html setlocal enableextensions & md $@ & endlocal copy documents $@/ copy $< $@/index.html if exist "source\images" xcopy /E source\images $@ # # PDF # PDFTEXT := $(patsubst %.pdf,%.txt,$(subst /pdfs,/text,$(wildcard reference-docs/pdfs/*.pdf))) pdf2text: $(PDFTEXT) reference-docs/text: md $@ reference-docs/text/%.txt: reference-docs/pdfs/%.pdf | reference-docs/text ps2ascii "$<" "$@"