forked from openjdk/guide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
102 lines (79 loc) · 2.92 KB
/
Makefile
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
default: all
define NEWLINE
endef
TITLE := The OpenJDK Developers' Guide
GUIDE_CHAPTERS := $(shell cat src/toc.conf)
GUIDE_CHAPTER_FILES := $(addprefix src/guide/, $(GUIDE_CHAPTERS))
GUIDE_CONCATENATED := build/support/index.md
GUIDE_FOOTER := build/support/footers/index.html
GUIDE_IMAGE_FILES := $(shell ls src/images/*)
GUIDE_UTF8 := build/support/utf-8/index.html
GUIDE_RESULT := build/dist/index.html
UTF8_HTML := $(patsubst build/dist/%.html, build/support/utf-8/%.html, $(GUIDE_RESULT))
FOUND_GUIDE_CHAPTERS := $(wildcard src/guide/*.md)
ifneq ($(sort $(FOUND_GUIDE_CHAPTERS)), $(sort $(GUIDE_CHAPTER_FILES)))
$(error "The guide chapters in src/guide do not match the chapters in src/toc.conf")
endif
ifneq ($(DEBUG_MAKE),)
.SECONDARY: $(LEGACY_FOOTER) $(GUIDE_CONCATENATED) $(GUIDE_FOOTER) $(UTF8_HTML)
endif
MERMAID ?= $(shell command -v mermaid-filter 2> /dev/null)
ifneq ($(MERMAID), )
MERMAID_FILTER := -F $(MERMAID)
else
$(info Notice: mermaid is not present; building without diagrams)
MERMAID_FILTER :=
endif
# Return the short form git hash for the last change to a file or set of files
# $1: the name of the file or files to get the hash for
GetHash = \
$(eval _shell_hash = $(shell git log -1 --pretty=format:"%h" -- $1)) \
$(if $(_shell_hash), \
$(_shell_hash), \
0000000)
# Generate a footer from the tempate in src/footer.html
# $1: output file name
# $2: git hash value
# $3: relative file name
GenerateFooter = \
sed -e 's@!git-commit-hash!@$(strip $2)@' -e 's@!source-file-name!@$(strip $3)@' src/footer.html > $1
# Convert markdown to html by pandoc
# $1: input markdown file
# $2: output html file
RunPandoc = \
pandoc $1 $(MERMAID_FILTER) --css guidestyle.css --strip-comments --standalone --toc --ascii --to html4 --title-prefix "$(TITLE)" --include-after-body=build/support/footers/$(notdir $2) > $2
# Convert utf-8 html to latin-1
# $1: input utf-8 file
# $2: output latin-1 file
ConvertToLatin1 = \
sed -e 's/ charset=utf-8//' $1 | iconv -f UTF-8 -t ISO-8859-1 > $2
$(GUIDE_CONCATENATED): $(GUIDE_CHAPTER_FILES)
rm -f [email protected]
mkdir -p build/support
$(foreach s, $^, \
cat $s >> [email protected] $(NEWLINE) \
printf "\n" >> [email protected] $(NEWLINE) \
)
mv [email protected] $@
$(GUIDE_FOOTER): $(GUIDE_CONCATENATED)
mkdir -p build/support/footers
$(call GenerateFooter, $@, $(call GetHash, $(GUIDE_CHAPTER_FILES)), src/guide)
$(GUIDE_UTF8): $(GUIDE_CONCATENATED) $(GUIDE_FOOTER)
mkdir -p build/support/utf-8
$(call RunPandoc, $<, $@)
build/dist/%.html: build/support/utf-8/%.html
mkdir -p build/dist
$(call ConvertToLatin1, $<, $@)
build/dist/guidestyle.css: src/guidestyle.css
mkdir -p build/dist
cp $< $@
copyimages:
mkdir -p build/dist
cp $(GUIDE_IMAGE_FILES) build/dist
all: $(GUIDE_RESULT) build/dist/guidestyle.css copyimages
clean:
rm -rf build
rm mermaid-filter.err
validate: build/dist/index.html
tidy -q -ascii -asxhtml -n --doctype omit --tidy-mark n build/dist/index.html > /dev/null
.PHONY: default all clean validate