Skip to content

Instantly share code, notes, and snippets.

@rkrug
Forked from hjst/Makefile
Created September 19, 2019 11:24
Show Gist options
  • Save rkrug/e3b2df0b0129ab4053e4a425530ef592 to your computer and use it in GitHub Desktop.
Save rkrug/e3b2df0b0129ab4053e4a425530ef592 to your computer and use it in GitHub Desktop.
Makefile for use with PlantUML diagrams
PLANTUML_JAR_URL = https://sourceforge.net/projects/plantuml/files/plantuml.jar/download
DIAGRAMS_SRC := $(wildcard diagrams/*.plantuml)
DIAGRAMS_PNG := $(addsuffix .png, $(basename $(DIAGRAMS_SRC)))
DIAGRAMS_SVG := $(addsuffix .svg, $(basename $(DIAGRAMS_SRC)))
# Default target first; build PNGs, probably what we want most of the time
png: plantuml.jar $(DIAGRAMS_PNG)
# SVG are nice-to-have but don't need to build by default
svg: plantuml.jar $(DIAGRAMS_SVG)
# clean up compiled files
clean:
rm -f plantuml.jar $(DIAGRAMS_PNG) $(DIAGRAMS_SVG)
# If the JAR file isn't already present, download it
plantuml.jar:
curl -sSfL $(PLANTUML_JAR_URL) -o plantuml.jar
# Each PNG output depends on its corresponding .plantuml file
diagrams/%.png: diagrams/%.plantuml
java -jar plantuml.jar -tpng $^
# Each SVG output depends on its corresponding .plantuml file
diagrams/%.svg: diagrams/%.plantuml
java -jar plantuml.jar -tsvg $^
# Quirk of GNU Make: https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html
.PHONY: png svg clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment