Skip to content

Instantly share code, notes, and snippets.

@MLKrisJohnson
Last active February 22, 2022 23:51
Show Gist options
  • Save MLKrisJohnson/6e309e1248db9b2af7aafe2f7e180884 to your computer and use it in GitHub Desktop.
Save MLKrisJohnson/6e309e1248db9b2af7aafe2f7e180884 to your computer and use it in GitHub Desktop.
Makefile for processing Mermaid files in the current directory
# Makefile for Mermaid files in this directory
#
# `make all` - build all targets
# `make png` - build PNGs for all source files
# `make svg` - build SVGs for all source files
# `make pdf` - build PDFs for all source files
# `make clean` - delete all targets
# `make listsources` - print list of all files to be processed
# `make listtargets` - print list of all output files
# `brew install mermaid-cli` to get the `mmdc` utility.
MMDC?=mmdc
MMDCFLAGS?=
%.png : %.mmd
$(MMDC) --input $< --output $@ $(MMDCFLAGS)
%.svg : %.mmd
$(MMDC) --input $< --output $@ $(MMDCFLAGS)
%.pdf : %.mmd
$(MMDC) --input $< --output $@ $(MMDCFLAGS) --pdfFit
# Process all *.mmd files in this directory, producing .png and .svg output.
MMD_SRC_FILES=$(wildcard *.mmd)
MMD_OUT_FILES=$(MMD_SRC_FILES:.mmd=.png) $(MMD_SRC_FILES:.mmd=.svg) $(MMD_SRC_FILES:.mmd=.pdf)
all: $(MMD_OUT_FILES)
.PHONY: all
png: $(MMD_SRC_FILES:.mmd=.png)
.PHONY: png
svg: $(MMD_SRC_FILES:.mmd=.svg)
.PHONY: svg
pdf: $(MMD_SRC_FILES:.mmd=.pdf)
.PHONY: pdf
listsources:
@ echo $(MMD_SRC_FILES)
.PHONY: listsources
listtargets:
@ echo $(MMD_OUT_FILES)
.PHONY: listtargets
clean:
- $(RM) $(MMD_OUT_FILES)
.PHONY: clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment