diff options
Diffstat (limited to 'build/Makefile')
-rw-r--r-- | build/Makefile | 54 |
1 files changed, 33 insertions, 21 deletions
diff --git a/build/Makefile b/build/Makefile index e3f938e..51a498d 100644 --- a/build/Makefile +++ b/build/Makefile @@ -27,10 +27,22 @@ SHORT_TARGETS := priv-pdf unpriv-pdf priv-html unpriv-html priv-epub unpriv-epu # Default target builds all all: $(TARGETS) -# Build with preinstalled docker container; first install it with: -# docker pull riscvintl/riscv-docs-base-container-image:latest +define run_with_docker + cd .. && docker run -it -v `pwd`:/build riscvintl/riscv-docs-base-container-image:latest /bin/sh -c 'export LANG=C.utf8; cd ./build; $(1)' +endef + +# Run natively if command exists, otherwise run with docker +define maybe_run_with_docker + @if command -v $(1) &> /dev/null; \ + then \ + $(1) $(2); \ + else \ + $(call run_with_docker, $(1) $(2)); \ + fi +endef + docker: - cd .. && docker run -it -v `pwd`:/build riscvintl/riscv-docs-base-container-image:latest /bin/sh -c 'export LANG=C.utf8; cd ./build; make -$(MAKEFLAGS) $(TARGETS)' + $(call run_with_docker, make -$(MAKEFLAGS) all) # Asciidoctor options ASCIIDOCTOR_OPTS := -a compress \ @@ -49,52 +61,52 @@ priv-pdf: priv-isa.pdf priv-isa.pdf: $(SRCDIR)/riscv-privileged.adoc $(SRCDIR)/*.adoc @echo "Building Privileged ISA" - rm -f $@.tmp - asciidoctor-pdf $(ASCIIDOCTOR_OPTS) --out-file=$@.tmp $< - mv $@.tmp $@ + @rm -f $@.tmp + $(call maybe_run_with_docker, asciidoctor-pdf, $(ASCIIDOCTOR_OPTS) --out-file=$@.tmp $<) + @mv $@.tmp $@ # Unprivileged ISA build unpriv-pdf: unpriv-isa.pdf unpriv-isa.pdf: $(SRCDIR)/riscv-unprivileged.adoc $(SRCDIR)/*.adoc @echo "Building Unprivileged ISA" - rm -f $@.tmp - asciidoctor-pdf $(ASCIIDOCTOR_OPTS) --out-file=$@.tmp $< - mv $@.tmp $@ + @rm -f $@.tmp + $(call maybe_run_with_docker, asciidoctor-pdf, $(ASCIIDOCTOR_OPTS) --out-file=$@.tmp $<) + @mv $@.tmp $@ # Privileged ISA HTML build priv-html: priv-isa.html priv-isa.html: $(SRCDIR)/riscv-privileged.adoc @echo "Building Privileged ISA HTML" - rm -f $@.tmp - asciidoctor $(ASCIIDOCTOR_OPTS) --out-file=$@.tmp $< - mv $@.tmp $@ + @rm -f $@.tmp + $(call maybe_run_with_docker, asciidoctor, $(ASCIIDOCTOR_OPTS) --out-file=$@.tmp $<) + @mv $@.tmp $@ # Unprivileged ISA HTML build unpriv-html: unpriv-isa.html unpriv-isa.html: $(SRCDIR)/riscv-unprivileged.adoc @echo "Building Unprivileged ISA HTML" - rm -f $@.tmp - asciidoctor $(ASCIIDOCTOR_OPTS) --out-file=$@.tmp $< - mv $@.tmp $@ + @rm -f $@.tmp + $(call maybe_run_with_docker, asciidoctor, $(ASCIIDOCTOR_OPTS) --out-file=$@.tmp $<) + @mv $@.tmp $@ priv-epub: priv-isa.epub priv-isa.epub: $(SRCDIR)/riscv-privileged.adoc @echo "Building Privileged ISA EPUB" - rm -f $@.tmp - asciidoctor-epub3 $(ASCIIDOCTOR_OPTS) --out-file=$@.tmp $< - mv $@.tmp $@ + @rm -f $@.tmp + $(call maybe_run_with_docker, asciidoctor-epub3, $(ASCIIDOCTOR_OPTS) --out-file=$@.tmp $<) + @mv $@.tmp $@ unpriv-epub: unpriv-isa.epub unpriv-isa.epub: $(SRCDIR)/riscv-unprivileged.adoc @echo "Building Unprivileged ISA EPUB" - rm -f $@.tmp - asciidoctor-epub3 $(ASCIIDOCTOR_OPTS) --out-file=$@.tmp $< - mv $@.tmp $@ + @rm -f $@.tmp + $(call maybe_run_with_docker, asciidoctor-epub3, $(ASCIIDOCTOR_OPTS) --out-file=$@.tmp $<) + @mv $@.tmp $@ clean: rm -f $(TARGETS) $(addsuffix .tmp,$(TARGETS)) |