-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
177 lines (136 loc) · 4.03 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
SHELL := bash
.SECONDEXPANSION:
.DELETE_ON_ERROR:
export ROOT := $(shell git rev-parse --show-toplevel)
export PATH := $(ROOT)/bin:$(PATH)
include Config.mk
#------------------------------------------------------------------------------
# Makefile variables defined here:
#------------------------------------------------------------------------------
BUILD := build
SITE := site
EXT := external
BPAN := .bpan
COMMON := ../yaml-common
include $(EXT)/ext.mk
BASEURL ?=
serve : BASEURL :=
PUBLISH_CNAME := play.yaml.io
REMOTE_NAME ?= origin
DOCKER_SHELL_CMD ?= bash
JEKYLL_BUILD := jekyll build --trace
JEKYLL_SERVE := jekyll serve --host 0.0.0.0
HISTORY_FILE := /tmp/docker-bash_history
SANDBOX_PORT ?= 1337
SANDBOX_IMAGE := yamlio/yaml-play-sandbox:$(SANDBOX_VERSION)
SANDBOX_RUN := \
docker run --rm -d -p \
$(SANDBOX_PORT):$(SANDBOX_PORT) \
$(SANDBOX_IMAGE) \
$(SANDBOX_PORT)
#------------------------------------------------------------------------------
# Gather all the build files:
#------------------------------------------------------------------------------
FILES := \
_config.yml \
favicon.svg \
Gemfile \
$(EXT_FILES) \
jekyll/_includes/sitedir-pulldown.html \
FILES := $(FILES:%.swp=)
#------------------------------------------------------------------------------
# Makefile rules start here:
#------------------------------------------------------------------------------
.PHONY: build site
list-files:
@printf "%s\n" $(FILES)
files: $(EXT_DIRS) $(FILES) track-gh-pages
build: files
jekyll-runner $(JEKYLL_BUILD)
ifneq (,$(SITEDIR))
ifneq (main,$(SITEDIR))
mv $(BUILD)/main $(BUILD)/$(SITEDIR)
endif
endif
site: build
git worktree add -f $@ gh-pages
git -C $(SITE) reset --hard origin/gh-pages
cd $(BUILD) && find . | grep -v Gemfile | cpio -dump ../$(SITE)
echo $(PUBLISH_CNAME) > $(SITE)/CNAME
touch $(SITE)/.nojekyll
no-docker:
$(eval override SANDBOX_RUN := true)
serve: files
$(eval override DOCKER_CID := $$(shell $$(SANDBOX_RUN)))
RUN_OR_DOCKER_OPTIONS='--publish 4000:4000' \
jekyll-runner $(JEKYLL_SERVE)
docker kill $(DOCKER_CID)
shell: files
RUN_OR_DOCKER_OPTIONS='--volume $(HISTORY_FILE):/home/jekyll/.bash_history' \
jekyll-runner $(DOCKER_SHELL_CMD)
publish: check-publish site
@(set -x ; \
git -C $(SITE) add -A . && \
git -C $(SITE) commit --allow-empty -m 'Publish' && \
git -C $(SITE) push -f $(REMOTE_NAME) gh-pages )
@echo
@echo "Published: https://$(PUBLISH_CNAME)/$(SITEDIR)"
@echo
push: docker-push
shell: docker-shell
docker-build docker-push docker-shell:
$(MAKE) -C docker $@
# Remove generated files to force rebuild:
force:
rm -fr ext $(BUILD) $(SITE) $(FILES)
common:
cp $(COMMON)/bpan/run-or-docker.bash $(BPAN)/
clean: force
$(MAKE) -C $(EXT) $@
clean-all:
$(MAKE) -C .. clean
#------------------------------------------------------------------------------
_config.yml: jekyll/_config.yml
@mkdir -p $(dir $@)
cp $< $@
echo >> $@
echo '# Added by build system:' >> $@
echo "baseurl: '$(BASEURL)'" >> $@
echo "sandbox_version: '$(SANDBOX_VERSION)'" >> $@
favicon.svg: $(EXT)/yaml-common/image/yaml-logo.svg
cp $< $@
$(EXT_DIRS):
$(MAKE) -C $(EXT) build
ext/%: $(EXT)/%
@mkdir -p $(dir $@)
cp $< $@
ext/%/: $(EXT)/%
mkdir -p $(shell dirname $@)
cp -r $< $(shell dirname $@)
ext/%.coffee: $(EXT)/%.coffee
@mkdir -p $(dir $@)
(echo '---'; echo '---'; cat $<) > $@
ext/%.scss: $(EXT)/%.scss
@mkdir -p $(dir $@)
(echo '---'; echo '---'; cat $<) > $@
Gemfile:
touch $@
jekyll/_includes/sitedir-pulldown.html:
./bin/generate-sitedir-pulldown > $@
#------------------------------------------------------------------------------
check-publish:
ifeq ($(SITEDIR),)
$(error Please set SITEDIR=<word>)
endif
ifneq ($(wildcard $(SITE)),)
$(error Please make clean before make publish)
endif
ifeq ($(SITEDIR),main)
ifneq ($(shell git rev-parse --abbrev-ref HEAD), main)
$(error Must be on branch main to use SITEDIR=main)
endif
endif
track-gh-pages:
git show-ref -q origin/gh-pages || \
git fetch origin gh-pages
-git branch --track gh-pages origin/gh-pages