Skip to content

Commit

Permalink
refactor Makefile to support multiple docs and build in parallel
Browse files Browse the repository at this point in the history
relates to riscv#35

Signed-off-by: Kevin Broch <[email protected]>
  • Loading branch information
kbroch-rivosinc committed Feb 6, 2024
1 parent e1c38be commit e4fd750
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,25 @@
# This Makefile is designed to automate the process of building and packaging
# the Doc Template for RISC-V Extensions.

DOCS := \
spec-sample.adoc

DATE ?= $(shell date +%Y-%m-%d)
VERSION ?= v0.0.0
REVMARK ?= Draft
DOCKER_RUN := docker run --rm -v ${PWD}:/build -w /build \
riscvintl/riscv-docs-base-container-image:latest
ifneq ($(SKIP_DOCKER),true)
DOCKER_CMD := docker run --rm -v ${PWD}:/build -w /build \
riscvintl/riscv-docs-base-container-image:latest \
/bin/sh -c
DOCKER_QUOTE := "
endif

SRC_DIR := src
BUILD_DIR := build
HEADER_SOURCE := $(SRC_DIR)/spec-sample.adoc

DOCS_PDF := $(DOCS:%.adoc=%.pdf)
DOCS_HTML := $(DOCS:%.adoc=%.html)

XTRA_ADOC_OPTS :=
ASCIIDOCTOR_PDF := asciidoctor-pdf
ASCIIDOCTOR_HTML := asciidoctor
Expand All @@ -39,10 +49,20 @@ REQUIRES := --require=asciidoctor-bibtex \
--require=asciidoctor-diagram \
--require=asciidoctor-mathematical

.PHONY: all build clean build-container build-no-container
.PHONY: all build clean build-container build-no-container build-docs

all: build

build-docs: $(DOCS_PDF) $(DOCS_HTML)

vpath %.adoc $(SRC_DIR)

%.pdf: %.adoc
$(DOCKER_CMD) $(DOCKER_QUOTE) $(ASCIIDOCTOR_PDF) $(OPTIONS) $(REQUIRES) $< $(DOCKER_QUOTE)

%.html: %.adoc
$(DOCKER_CMD) $(DOCKER_QUOTE) $(ASCIIDOCTOR_HTML) $(OPTIONS) $(REQUIRES) $< $(DOCKER_QUOTE)

build:
@echo "Checking if Docker is available..."
@if command -v docker >/dev/null 2>&1 ; then \
Expand All @@ -55,14 +75,12 @@ build:

build-container:
@echo "Starting build inside Docker container..."
$(DOCKER_RUN) /bin/sh -c "$(ASCIIDOCTOR_PDF) $(OPTIONS) $(REQUIRES) $(HEADER_SOURCE)"
$(DOCKER_RUN) /bin/sh -c "$(ASCIIDOCTOR_HTML) $(OPTIONS) $(REQUIRES) $(HEADER_SOURCE)"
$(MAKE) build-docs
@echo "Build completed successfully inside Docker container."

build-no-container:
@echo "Starting build..."
$(ASCIIDOCTOR_PDF) $(OPTIONS) $(REQUIRES) $(HEADER_SOURCE)
$(ASCIIDOCTOR_HTML) $(OPTIONS) $(REQUIRES) $(HEADER_SOURCE)
$(MAKE) SKIP_DOCKER=true build-docs
@echo "Build completed successfully."

clean:
Expand Down

0 comments on commit e4fd750

Please sign in to comment.