aboutsummaryrefslogtreecommitdiff
path: root/build
diff options
context:
space:
mode:
authorAndrew Waterman <andrew@sifive.com>2024-05-29 17:31:43 -0700
committerAndrew Waterman <andrew@sifive.com>2024-05-29 17:34:10 -0700
commit120b7b08978fc948dd5efde782155bf51dd3ac74 (patch)
tree44aee765cdaa648deaab08ddcb7d0a9d67fedb20 /build
parent5cf4a1ae667af6648319323b6f3eb0b0b1b34a98 (diff)
downloadriscv-isa-manual-120b7b08978fc948dd5efde782155bf51dd3ac74.zip
riscv-isa-manual-120b7b08978fc948dd5efde782155bf51dd3ac74.tar.gz
riscv-isa-manual-120b7b08978fc948dd5efde782155bf51dd3ac74.tar.bz2
Automatically use docker container if asciidoctor is not installed
Diffstat (limited to 'build')
-rw-r--r--build/Makefile54
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))