2024-10-12 21:18:36 +00:00
|
|
|
# vim: noexpandtab:tabstop=4:shiftwidth=4
|
|
|
|
|
2024-10-13 16:36:56 +00:00
|
|
|
# Taken and adapted from https://github.com/riscv/riscv-isa-manual/blob/main/Makefile
|
|
|
|
# Adapted to run in Gitea Actions: https://gitea.com/gitea/act_runner/issues/189#issuecomment-812870
|
|
|
|
|
2024-10-12 21:18:36 +00:00
|
|
|
DOCS := central-execution-engine-spec
|
|
|
|
|
2024-10-13 14:03:36 +00:00
|
|
|
DOCKER_IMG_BASE := git.elyanpoujol.fr/elyan
|
|
|
|
DOCKER_IMG := $(DOCKER_IMG_BASE)/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 $$?)
|
2024-10-13 16:36:56 +00:00
|
|
|
|
|
|
|
VOLUME_LOCAL := -v $(PWD):$(PWD)
|
|
|
|
VOLUME_CI := --volumes-from=$(JOB_CONTAINER_NAME)
|
|
|
|
|
|
|
|
ifeq "$(CI)" "true"
|
|
|
|
VOLUME := VOLUME_CI
|
|
|
|
$(info Running in a CI environment)
|
|
|
|
else ifneq "$(DOCKER_IS_ROOTLESS)" "1"
|
2024-10-12 21:18:36 +00:00
|
|
|
# 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
|
2024-10-13 16:36:56 +00:00
|
|
|
VOLUME := $(VOLUME_LOCAL)
|
|
|
|
$(info Running locally)
|
|
|
|
else
|
|
|
|
VOLUME := $(VOLUME_LOCAL)
|
|
|
|
$(info Running locally in rootless mode)
|
2024-10-12 21:18:36 +00:00
|
|
|
endif
|
|
|
|
|
2024-10-12 23:27:08 +00:00
|
|
|
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)))
|
|
|
|
|
2024-10-13 16:36:56 +00:00
|
|
|
.PHONY: all build build-in-docker image clean
|
2024-10-12 21:18:36 +00:00
|
|
|
|
2024-10-13 16:36:56 +00:00
|
|
|
all: build
|
2024-10-12 21:18:36 +00:00
|
|
|
|
2024-10-13 16:36:56 +00:00
|
|
|
build:
|
|
|
|
$(SUDO_PREFIX) docker run --rm $(VOLUME) $(DOCKER_USER_ARG) $(DOCKER_IMG) /bin/sh -c "cd $(PWD) && make build-in-docker"
|
2024-10-12 21:18:36 +00:00
|
|
|
|
2024-10-13 16:36:56 +00:00
|
|
|
build-in-docker: $(DOCS_PDF)
|
2024-10-12 21:18:36 +00:00
|
|
|
|
2024-10-13 16:36:56 +00:00
|
|
|
$(BUILD_DIR)/%.pdf: $(SRC_DIR)/%.adoc $(ALL_SRC)
|
|
|
|
@echo "Building documentation in docker container..."
|
|
|
|
rm -rf $@.workdir
|
|
|
|
mkdir -p $@.workdir
|
|
|
|
cp -r src $@.workdir
|
|
|
|
$(ENV) cd $@.workdir && asciidoctor-pdf $(OPTIONS) $(REQUIRES) $<
|
|
|
|
mv $@.workdir/$@ $@
|
|
|
|
rm -rf $@.workdir
|
|
|
|
@echo "Build completed."
|
|
|
|
|
|
|
|
image:
|
2024-10-12 23:27:08 +00:00
|
|
|
$(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."
|