generated from riscv/docs-spec-template
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathMakefile.include
More file actions
112 lines (101 loc) · 3.25 KB
/
Makefile.include
File metadata and controls
112 lines (101 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# Makefile for RISC-V Doc Template
#
# This work is licensed under the Creative Commons Attribution-ShareAlike 4.0
# International License. To view a copy of this license, visit
# http://creativecommons.org/licenses/by-sa/4.0/ or send a letter to
# Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
#
# SPDX-License-Identifier: CC-BY-SA-4.0
#
# Description:
#
# This Makefile is designed to automate the process of building and packaging
# the Doc Template for RISC-V Extensions.
# Change these if you want;
# - SRC is the primary input file
# - DESTDIR is created/destroyed, choose it accordingly, or I'll pick one
# - for f in FORMATS, $(ASCIIDOCTOR_$f) is a build command to run and
# $(OUTPUT_$f) is the name of the output file
# - CONTIMG is the <img> name passed to docker-run
ifndef DOC
$(error "DOC must be defined, use appropriate wrapper Makefile")
endif
SRC ?= src/$(DOC).adoc
#DESTDIR := ${PWD}/build
#DESTDIR := /mnt/c/Users/$(shell whoami)/Downloads/$(DOC)
OUTPUT_PDF ?= $(DOC).pdf
OUTPUT_HTML ?= $(DOC).html
FORMATS := PDF HTML
CONTIMG := riscvintl/riscv-docs-base-container-image:latest
# If not specified, pick a useful default
ifeq (,$(DESTDIR))
ifneq (,$(wildcard /mnt/c/Users/$(shell whoami)/Downloads))
DESTDIR := /mnt/c/Users/$(shell whoami)/Downloads/$(DOC)
else
DESTDIR := ${PWD}/build
endif
endif
# Change these if you must;
ASCIIDOCTOR_PDF := asciidoctor-pdf
ASCIIDOCTOR_HTML := asciidoctor
OPTIONS := --trace \
-a compress \
-a allow-uri-read \
-a mathematical-format=svg \
-a pdf-fontsdir=/inputs/docs-resources/fonts \
-a pdf-theme=/inputs/docs-resources/themes/riscv-pdf.yml \
-D /outputs \
--failure-level=WARNING \
--require=asciidoctor-diagram \
--require=asciidoctor-mathematical
TOUCHFILE := $(DESTDIR)/buildcmd
# Change these at your peril;
# - PWD is mounted-read-only, so docker's blast-radius is DESTDIR
# - PWD/$(SRC) is the primary source file
# - Output is made dependent on all files inside PWD/src/
DOCKER_QUOTE := "
ifeq (,$(VERBOSE))
V := @
else
V :=
endif
BUILDCMD := docker run --rm \
-v ${PWD}:/inputs:ro \
-v $(DESTDIR):/outputs \
$(CONTIMG) /bin/sh -c \
$(DOCKER_QUOTE) \
$(foreach e,$(FORMATS),$(ASCIIDOCTOR_$(e)) $(OPTIONS) -o $(OUTPUT_$e) /inputs/$(SRC) && )true \
$(DOCKER_QUOTE)
CLEANCMD := docker run --rm \
-v $(DESTDIR):/outputs \
$(CONTIMG) /bin/sh -c \
$(DOCKER_QUOTE) \
rm -rf /outputs/* \
$(DOCKER_QUOTE) && rmdir $(DESTDIR)
DEPS ?= $(shell find ${PWD}/src -type f)
# Remove the touchfile if any aspect of the build command has changed (FORMATS,
# asciidoctor options, container image, ...).
ifneq (,$(wildcard $(TOUCHFILE)))
$(shell echo 'BUILDCMD := $(BUILDCMD)' > $(TOUCHFILE).tmp)
$(shell cmp $(TOUCHFILE) $(TOUCHFILE).tmp > /dev/null 2>&1 || rm -f $(TOUCHFILE))
$(shell rm -f $(TOUCHFILE).tmp)
endif
.PHONY: all build clean
all: build
build: $(TOUCHFILE)
# TBD: remove the sed line when copyright is no longer redirected to MIPS
$(TOUCHFILE): $(DEPS) | $(DESTDIR)
# $(V)sed -i.bak "s/RISC-V International/MIPS/g" docs-resources/themes/riscv-pdf.yml
@echo "[BUILD $(DOC) -> $(DESTDIR)]"
$(V)$(BUILDCMD)
$(V)echo 'BUILDCMD := $(BUILDCMD)' > $@
$(DESTDIR):
$(V)mkdir -p $@
ifeq (,$(wildcard $(DESTDIR)))
clean:
else
clean:
@echo "Cleaning up generated files..."
$(V)$(CLEANCMD)
@echo "Cleanup completed."
endif