forked from theforeman/foreman-documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
76 lines (63 loc) · 2.74 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
SHELL := /bin/bash
BUILD = foreman-el
BUILD_DIR = ../build
BUILD_DIRA = $(realpath $(BUILD_DIR))/
COMMON_DIR = ../common
ROOTDIR = $(realpath .)
NAME = $(notdir $(ROOTDIR))
DEST_DIR = $(BUILD_DIR)/$(subst doc-,,$(NAME))
DEST_HTML = $(DEST_DIR)/index-$(BUILD).html
IMAGES_DIR = $(DEST_DIR)/images
IMAGES_TS = $(DEST_DIR)/.timestamp-images
CSS_SOURCES = $(shell find $(COMMON_DIR)/css -type f)
DOCINFO_SOURCES = $(shell find $(COMMON_DIR)/ -type f -name docinfo\*.html)
SOURCES = master.adoc $(shell find . -type f -name \*.adoc)
DEPENDENCIES = $(shell find $(COMMON_DIR) -type f -name \*.adoc)
IMAGES = $(shell find ./images ./common/images -type f 2>/dev/null || true)
UNAME = $(shell uname)
DATE_MDY = $(shell LC_ALL=C date "+%b %d %Y")
DATE_MY = $(shell LC_ALL=C date "+%b %Y")
CSS_STYLE = compressed
ifeq ($(UNAME), Linux)
BROWSER_OPEN = xdg-open
CP_ARGS = -lL
endif
ifeq ($(UNAME), Darwin)
BROWSER_OPEN = open
CP_ARGS =
endif
ifeq ($(LINKS), LOCAL)
# The Satellite build uses links which do not resolve. This does mean the link
# checker has issues with verification of guides that have not yet been built
# by downstream, but there really isn't a way around this unless we start
# building with downstream filenames.
ifneq ($(BUILD), satellite)
BASEURL_ATTR = -a "BaseURL=file://$(BUILD_DIRA)"
endif
endif
.SHELLFLAGS = -o pipefail -c
.PHONY = all prepare html clean browser server linkchecker
all: html
prepare:
@mkdir -p $(BUILD_DIR) $(DEST_DIR) $(IMAGES_DIR)
html: prepare $(IMAGES_TS) $(DEST_HTML)
clean:
@rm -rf "$(DEST_DIR)"
browser: html
${BROWSER_OPEN} "file://$(realpath $(ROOTDIR)/$(DEST_HTML))"
serve: html
python -m http.server --directory "$(realpath $(DEST_DIR))" 8813
linkchecker: html
linkchecker -r1 -f $(COMMON_DIR)/linkchecker.ini --check-extern "file://$(realpath $(ROOTDIR)/$(DEST_HTML))"
$(DEST_DIR)/$(BUILD).css: $(CSS_SOURCES)
bundle exec sass --sourcemap=none --no-cache --style $(CSS_STYLE) -I $(COMMON_DIR)/css $(COMMON_DIR)/css/default.scss $@
$(IMAGES_TS): $(IMAGES)
@[[ -h ./images/common ]] || echo "FAILURE: Missing ./images dir with ./images/common symlink to commons!"
cp -rf $(CP_ARGS) ./images/* $(IMAGES_DIR)
@touch $(IMAGES_TS)
$(DEST_HTML): $(SOURCES) $(DEPENDENCIES) $(DOCINFO_SOURCES) $(DEST_DIR)/$(BUILD).css $(IMAGES_TS)
bundle exec asciidoctor -a build=$(BUILD) $(BASEURL_ATTR) -a docinfo=shared -a docinfodir=common -a date_mdy="$(DATE_MDY)" -a date_my="$(DATE_MY)" -a docdatetime="$(DATE_MY)" -a stylesheet=$(DEST_DIR)/$(BUILD).css -a attribute-missing=warn -b html5 -d book --trace -o $@ $< 2>&1 | tee [email protected] 1>&2
@echo CHECKING FOR ASCIIDOCTOR ERRORS AND WARNINGS
@! grep -Eq "^asciidoctor: (ERROR|WARNING)" [email protected]
@echo CHECKING FOR ORPHAN XREFS HTML LINKS
@! grep -RE '<a href="#[a-zA-Z0-9_-]+">\[[a-zA-Z0-9_-]+\]</a>' $@