diff --git a/Makefile b/Makefile index 5e5afbc..8deb8b4 100644 --- a/Makefile +++ b/Makefile @@ -10,10 +10,19 @@ ifndef PLANTUML_PATH export PLANTUML_PATH = ./plantuml.jar endif -models := tm.py +MODEL?=tm + libs := $(wildcard pytm/*.py) $(wildcard pytm/threatlib/*.json) $(wildcard pytm/images/*) -all: clean -all: $(models:.py=/report.html) $(models:.py=/dfd.png) $(models:.py=/seq.png) docs/pytm/index.html + +all: clean docs/pytm/index.html + $(MAKE) $(MODEL) + +safe_filename: +ifeq ($(suffix $(MODEL)), .py) + @echo "I think you mean MODEL=$(patsubst .py,,$(MODEL))" + exit 1 +endif + docs/pytm/index.html: $(wildcard pytm/*.py) PYTHONPATH=. pdoc --html --force --output-dir docs pytm @@ -22,26 +31,27 @@ docs/threats.md: $(wildcard pytm/threatlib/*.json) printf "# Threat database\n" > $@ jq -r ".[] | \"$$(cat docs/threats.jq)\"" $< >> $@ -clean: - rm -rf dist/* build/* $(models:.py=/*) +clean: safe_filename + rm -rf dist/* build/* $(MODEL) -tm: - mkdir -p tm +$(MODEL): safe_filename + mkdir -p $(MODEL) + $(MAKE) MODEL=$(MODEL) report -%/dfd.png: %.py tm $(libs) +$(MODEL)/dfd.png: $(MODEL).py $(libs) ./$< --dfd | dot -Tpng -o $@ -%/seq.png: %.py tm $(libs) +$(MODEL)/seq.png: $(MODEL).py $(libs) ./$< --seq | java -Djava.awt.headless=true -jar $$PLANTUML_PATH -tpng -pipe > $@ -%/report.html: %.py tm $(libs) docs/template.md docs/Stylesheet.css - ./$< --report docs/template.md | pandoc -f markdown -t html > $@ +$(MODEL)/report.html: $(MODEL).py $(libs) docs/basic_template.md docs/Stylesheet.css + ./$< --report docs/basic_template.md | pandoc -f markdown -t html > $@ -dfd: $(models:.py=/dfd.png) +dfd: $(MODEL)/dfd.png -seq: $(models:.py=/seq.png) +seq: $(MODEL)/seq.png -report: $(models:.py=/report.html) seq dfd +report: $(MODEL)/report.html seq dfd .PHONY: test test: diff --git a/README.md b/README.md index 80e211d..f9b0e90 100644 --- a/README.md +++ b/README.md @@ -38,9 +38,11 @@ mkdir -p tm There's also an example `Makefile` that wraps all these into targets that can be easily shared for multiple models. If you have [GNU make](https://www.gnu.org/software/make/) installed (available by default on Linux distros but not on OSX), simply run: ``` -make +make MODEL=the_name_of_your_model_minus_.py ``` +You should either have plantuml.jar on the same directory as your model, or set PLANTUML_PATH. + To avoid installing all the dependencies, like `pandoc` or `Java`, the script can be run inside a container: ```