Skip to content

Commit 06eff3e

Browse files
authored
Merge pull request #131 from grahamwhaley/native_pandoc
Makefile: Enable native pandoc builds
2 parents 7cb2899 + e6e9e4a commit 06eff3e

File tree

1 file changed

+35
-28
lines changed

1 file changed

+35
-28
lines changed

Makefile

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
11
GO15VENDOREXPERIMENT=1
22
export GO15VENDOREXPERIMENT
33

4-
DOCKER ?= $(shell which docker)
4+
DOCKER ?= $(shell command -v docker 2>/dev/null)
5+
PANDOC ?= $(shell command -v pandoc 2>/dev/null)
6+
7+
ifeq "$(strip $(PANDOC))" ''
8+
ifneq "$(strip $(DOCKER))" ''
9+
PANDOC = $(DOCKER) run \
10+
-it \
11+
--rm \
12+
-v $(shell pwd)/:/input/:ro \
13+
-v $(shell pwd)/$(OUTPUT_DIRNAME)/:/$(OUTPUT_DIRNAME)/ \
14+
-u $(shell id -u) \
15+
--workdir /input \
16+
vbatts/pandoc
17+
PANDOC_SRC := /input/
18+
PANDOC_DST := /
19+
endif
20+
endif
21+
522
# These docs are in an order that determines how they show up in the PDF/HTML docs.
623
DOC_FILES := \
724
README.md \
@@ -14,7 +31,7 @@ DOC_FILES := \
1431
FIGURE_FILES := \
1532
img/media-types.png
1633

17-
OUTPUT ?= output/
34+
OUTPUT_DIRNAME ?= output/
1835
DOC_FILENAME ?= oci-image-spec
1936

2037
EPOCH_TEST_COMMIT ?= v0.2.0
@@ -24,7 +41,7 @@ default: help
2441
help:
2542
@echo "Usage: make <target>"
2643
@echo
27-
@echo " * 'docs' - produce document in the $(OUTPUT) directory"
44+
@echo " * 'docs' - produce document in the $(OUTPUT_DIRNAME) directory"
2845
@echo " * 'fmt' - format the json with indentation"
2946
@echo " * 'validate-examples' - validate the examples in the specification markdown files"
3047
@echo " * 'oci-image-tool' - build the oci-image-tool binary"
@@ -38,33 +55,23 @@ help:
3855
fmt:
3956
for i in schema/*.json ; do jq --indent 2 -M . "$${i}" > xx && cat xx > "$${i}" && rm xx ; done
4057

41-
docs: $(OUTPUT)/$(DOC_FILENAME).pdf $(OUTPUT)/$(DOC_FILENAME).html
42-
43-
$(OUTPUT)/$(DOC_FILENAME).pdf: $(DOC_FILES) $(FIGURE_FILES)
44-
@mkdir -p $(OUTPUT)/ && \
45-
cp -ap img/ $(shell pwd)/$(OUTPUT)/&& \
46-
$(DOCKER) run \
47-
-it \
48-
--rm \
49-
-v $(shell pwd)/:/input/:ro \
50-
-v $(shell pwd)/$(OUTPUT)/:/$(OUTPUT)/ \
51-
-u $(shell id -u) \
52-
--workdir /input \
53-
vbatts/pandoc -f markdown_github -t latex -o /$(OUTPUT)/$(DOC_FILENAME).pdf $(patsubst %,/input/%,$(DOC_FILES)) && \
58+
docs: $(OUTPUT_DIRNAME)/$(DOC_FILENAME).pdf $(OUTPUT_DIRNAME)/$(DOC_FILENAME).html
59+
60+
ifeq "$(strip $(PANDOC))" ''
61+
$(OUTPUT_DIRNAME)/$(DOC_FILENAME).pdf: $(DOC_FILES) $(FIGURE_FILES)
62+
$(error cannot build $@ without either pandoc or docker)
63+
else
64+
$(OUTPUT_DIRNAME)/$(DOC_FILENAME).pdf: $(DOC_FILES) $(FIGURE_FILES)
65+
@mkdir -p $(OUTPUT_DIRNAME)/ && \
66+
$(PANDOC) -f markdown_github -t latex -o $(PANDOC_DST)$@ $(patsubst %,$(PANDOC_SRC)%,$(DOC_FILES))
5467
ls -sh $(shell readlink -f $@)
5568

56-
$(OUTPUT)/$(DOC_FILENAME).html: $(DOC_FILES) $(FIGURE_FILES)
57-
@mkdir -p $(OUTPUT)/ && \
58-
cp -ap img/ $(shell pwd)/$(OUTPUT)/&& \
59-
$(DOCKER) run \
60-
-it \
61-
--rm \
62-
-v $(shell pwd)/:/input/:ro \
63-
-v $(shell pwd)/$(OUTPUT)/:/$(OUTPUT)/ \
64-
-u $(shell id -u) \
65-
--workdir /input \
66-
vbatts/pandoc -f markdown_github -t html5 -o /$(OUTPUT)/$(DOC_FILENAME).html $(patsubst %,/input/%,$(DOC_FILES)) && \
69+
$(OUTPUT_DIRNAME)/$(DOC_FILENAME).html: $(DOC_FILES) $(FIGURE_FILES)
70+
@mkdir -p $(OUTPUT_DIRNAME)/ && \
71+
cp -ap img/ $(shell pwd)/$(OUTPUT_DIRNAME)/&& \
72+
$(PANDOC) -f markdown_github -t html5 -o $(PANDOC_DST)$@ $(patsubst %,$(PANDOC_SRC)%,$(DOC_FILES))
6773
ls -sh $(shell readlink -f $@)
74+
endif
6875

6976
code-of-conduct.md:
7077
curl -o $@ https://raw.githubusercontent.com/opencontainers/tob/d2f9d68c1332870e40693fe077d311e0742bc73d/code-of-conduct.md
@@ -126,7 +133,7 @@ install.tools: .install.gitvalidation .install.glide .install.glide-vc
126133
go get github.com/sgotti/glide-vc
127134

128135
clean:
129-
rm -rf *~ $(OUTPUT)
136+
rm -rf *~ $(OUTPUT_DIRNAME)
130137
rm -f oci-image-tool
131138

132139
.PHONY: \

0 commit comments

Comments
 (0)