# 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 := asciidoctor/docker-asciidoctor:latest 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 ALL_SRC := $(shell find $(SRC_DIR) -type f -name '*.adoc' -print) DOCS_PDF := $(addprefix $(BUILD_DIR)/, $(addsuffix .pdf, $(DOCS))) .PHONY: all build docker-pull-latest clean 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) docker-pull-latest: $(SUDO_PREFIX) docker pull $(DOCKER_IMG) clean: @echo "Cleaning up generated files..." rm -rf $(BUILD_DIR) @echo "Cleanup completed."