central-arch-doc/Makefile

68 lines
1.7 KiB
Makefile
Raw Normal View History

2024-10-12 21:18:36 +00:00
# Taken and adapted from https://github.com/riscv/riscv-isa-manual/blob/main/Makefile
# vim: noexpandtab:tabstop=4:shiftwidth=4
DOCS := central-execution-engine-spec
DOCKER_IMG := docker-asciidoctor-wavedrom:latest
2024-10-12 21:18:36 +00:00
ENV := LANG=C.utf8
OPTIONS := -D build \
--trace \
--failure-level=ERROR
REQUIRES := --require=asciidoctor-diagram
DOCKER_IS_ROOTLESS = \
$(shell ! ps ux | grep -v grep | grep dockerd-rootless >/dev/null ; echo $$?)
ifneq "$(DOCKER_IS_ROOTLESS)" "1"
# Rooted Docker requires this flag so that the files it creates are
# owned by the current user instead of root. Rootless docker does not
# require it, and Podman doesn't either since it is always rootless.
DOCKER_USER_ARG := --user $(shell id -u)
SUDO_PREFIX := sudo
endif
DOCKER_CMD = \
$(SUDO_PREFIX) docker run --rm \
-v $(PWD)/$@.workdir:/build \
-w /build \
$(DOCKER_USER_ARG) \
$(DOCKER_IMG) \
/bin/sh -c
WORKDIR_SETUP = \
rm -rf $@.workdir && \
mkdir -p $@.workdir && \
cp -r src $@.workdir
WORKDIR_TEARDOWN = \
mv $@.workdir/$@ $@ && \
rm -rf $@.workdir
SRC_DIR := src
BUILD_DIR := build
DOCKER_DIR := docker
2024-10-12 21:18:36 +00:00
ALL_SRC := $(shell find $(SRC_DIR) -type f -name '*.adoc' -print)
DOCS_PDF := $(addprefix $(BUILD_DIR)/, $(addsuffix .pdf, $(DOCS)))
.PHONY: all build create-docker-image clean
2024-10-12 21:18:36 +00:00
all: build-pdf
build-pdf: $(DOCS_PDF)
$(BUILD_DIR)/%.pdf: $(SRC_DIR)/%.adoc $(ALL_SRC)
$(WORKDIR_SETUP)
$(DOCKER_CMD) '$(ENV) asciidoctor-pdf $(OPTIONS) $(REQUIRES) $<'
$(WORKDIR_TEARDOWN)
create-docker-image:
$(SUDO_PREFIX) docker build -t $(DOCKER_IMG) $(DOCKER_DIR)
2024-10-12 21:18:36 +00:00
clean:
@echo "Cleaning up generated files..."
rm -rf $(BUILD_DIR)
@echo "Cleanup completed."