Skip to content

Commit a3cbe16

Browse files
committed
add Makefile
"make all/clean/clobber/serve" can be used for building or viewing documentation locally. The default is to download the mdbook binary for Linux x86. This can be tuned with Makefile variables or a custom binary can be used, see Makefile for detail. Fixes: #78
1 parent 146ac9a commit a3cbe16

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ docs/example
44

55
# vim
66
*.swp
7+
8+
/mdbook
9+
/mdbook*.tar.gz

Makefile

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
ROOT := $(shell pwd)
2+
3+
# The default is to download the official release binary
4+
# for x86_64-unknown-linux-gnu. If that default is unsuitable,
5+
# build your own binary and copy or symlink it here, or
6+
# override the variable with "make MDBOOK_BINARY=...".
7+
MDBOOK_BINARY = $(ROOT)/mdbook
8+
9+
# The architecture can be changed. Only Linux .tar.gz files
10+
# are currently supported, though. See https://github.com/rust-lang-nursery/mdBook/releases
11+
# for available architectures.
12+
MDBOOK_ARCH = x86_64-unknown-linux-gnu
13+
14+
# The mdbook version.
15+
MDBOOK_RELEASE = v0.2.1
16+
17+
# Download URL for mdbook and resulting file.
18+
MDBOOK_FILE = mdbook-$(MDBOOK_RELEASE)-$(MDBOOK_ARCH).tar.gz
19+
MDBOOK_URL = https://github.com/rust-lang-nursery/mdBook/releases/download/$(MDBOOK_RELEASE)/$(MDBOOK_FILE)
20+
21+
# As an extra sanity check, the hash of the downloaded file must match before it is used.
22+
MDBOOK_SHA1 = 5da8d46d09df02d6a671dfbbde20ea85811edbaf
23+
24+
all: $(MDBOOK_BINARY)
25+
cd book && $(MDBOOK_BINARY) build
26+
27+
clean:
28+
rm -rf docs mdbook-*.tar.gz
29+
30+
clobber: clean
31+
rm -f mdbook
32+
33+
# Start mdbook as web server.
34+
MDBOOK_HOSTNAME = localhost
35+
MDBOOK_PORT = 3000
36+
serve:
37+
cd book && $(MDBOOK_BINARY) serve --hostname $(MDBOOK_HOSTNAME) --port $(MDBOOK_PORT)
38+
39+
$(MDBOOK_BINARY): $(MDBOOK_FILE)
40+
if [ "`sha1sum < $(MDBOOK_FILE) | sed -e 's/ *-$$//'`" != $(MDBOOK_SHA1) ]; then \
41+
echo "ERROR: hash mismatch, check downloaded file $(MDBOOK_FILE) and/or update MDBOOK_SHA1"; \
42+
exit 1; \
43+
fi
44+
tar xf $(MDBOOK_FILE)
45+
touch $@
46+
47+
$(MDBOOK_FILE):
48+
curl -L -O $(MDBOOK_URL)
49+
50+
.PHONY: all clean clobber serve

0 commit comments

Comments
 (0)