forked from filecoin-project/specs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
274 lines (217 loc) · 8.6 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# guidelines for editing this makefile:
#
# - keep it simple -- put complicated commands into scripts inside bin/ (eg install-deps.sh)
# - document targets in the 'help' target
# - distinguish main targets (meant for users) from intermediate targets
# - if you write a new tool that requires compilation:
# add a compilation target here and move the binary into bin/
# - if you add a dependency on another tool:
# make sure you edit install-deps.sh to install or prompt to install it
# - keep diagrams/builsys/buildsys.dot in sync with the targets here
# that is a diagram that is meant to make it easy to understand everything here.
help:
@echo "SYNOPSIS"
@echo " make -- filecoin spec build toolchain commands"
@echo ""
@echo "USAGE"
@echo " make deps-ga run this once, to instlal & build partial dependencies for Github Actions"
@echo " make deps-basic run this once, to install & build basic dependencies"
@echo " make build run this every time you want to re-build artifacts"
@echo ""
@echo "MAIN TARGETS"
@echo " make help description of the targets (this message)"
@echo " make build build all final artifacts (website only for now)"
@echo " make test run all test cases (test-code only for now)"
@echo " make drafts publish artifacts to ipfs and show an address"
@echo " make publish publish final artifacts to spec website (github pages)"
@echo " make clean removes all build artifacts. you shouldn't need this"
@echo " make serve start hugo in serving mode -- must run 'make build' on changes manually"
@echo ""
@echo "INSTALL DEPENDENCIES"
@echo " make deps install ALL dependencies of this tool chain"
@echo " make deps-ga install Github Action specific dependencies"
@echo " make deps-basic install minimal dependencies of this tool chain"
@echo " make deps-diag install dependencies for rendering diagrams"
@echo " make deps-orient install dependencies for running orient"
@echo " make deps-ouser install dependencies for orient user-environment tooling"
@echo " make bins compile some build tools whose source is in this repo"
@echo ""
@echo "INTERMEDIATE TARGETS"
@echo " make website build the website artifact"
@#echo " make pdf build the pdf artifact"
@echo " make diagrams build diagram artifacts ({dot, mmd} -> svg)"
@echo " make org2md run org mode to markdown compilation"
@echo ""
@echo "HUGO TARGETS"
@echo " make hugo-src copy sources into hugo dir"
@echo " make build-hugo run the hugo part of the pipeline"
@echo " make watch-hugo watch and rebuild hugo"
@echo ""
@echo "CODE TARGETS"
@echo " make gen-code generate code artifacts (eg id -> go)"
@echo " make test-code run test cases in code artifacts"
@echo " make build-code build all src go code (test it)"
@echo " make clean-code remove build code artifacts"
@echo " make watch-code watch and rebuild code"
@echo ""
@echo "CLEAN TARGETS"
@echo " make clean remove all build artifacts"
@echo " make clean-deps remove (some of) the dependencies installed in this repo"
@echo " make clean-hugo remove intermediate hugo artifacts"
@echo " make clean-code remove build code artifacts"
@echo ""
@echo "WATCH TARGETS"
@echo " make serve-and-watch -j2 serve, watch, and rebuild all - works for live edit"
@echo " make watch-code watch and rebuild code"
@echo " make watch-hugo watch and rebuild hugo"
@echo ""
# main Targets
build: diagrams build-code website
test: test-code test-codeGen
drafts: website
bin/publish-to-ipfs.sh
publish: website
bin/publish-to-gh-pages.sh
clean: .PHONY
rm -rf build
# install dependencies
deps: deps-basic deps-diag deps-orient
@# make bins last, after installing other deps
@# so we re-invoke make.
make bins
deps-ga:
bin/install-deps-ga.sh -y
deps-basic:
bin/install-deps-basic.sh -y
deps-ouser:
bin/install-deps-orient-user.sh -y
deps-orient: submodules
bin/install-deps-orient.sh -y
deps-diag:
bin/install-deps-diagrams.sh -y
submodules:
git submodule update --init --recursive
clean-deps: .PHONY
@echo "WARNING: this does not uninstall global packages, sorry."
@echo " If you would like to remove them, see bin/install-deps.sh"
-rm -r deps
-git checkout ./deps/package.json
-rm -r .slime
-rm -r bin/.emacs
# intermediate targets
# NOTE: For now, disable org2md — must manually generate until batch-mode build issues are resolved.
website: diagrams build-hugo # org2md
mkdir -p build/website
-rm -rf build/website/*
mv hugo/public/* build/website
@echo TODO: add generate-code to this target
pdf: diagrams build-hugo # org2md
@echo TODO: add generate-code to this target
bin/build-pdf.sh
build-hugo: hugo-src $(shell find hugo/content | grep '.md')
cd hugo && hugo
hugo-src: $(shell find src | grep '.md') hugo/data/version.yml
rm -rf hugo/content/docs
cp -r src hugo/content/docs
# ox-hugo exports to src/content, so we need to copy that also.
cp -R src/content/ hugo/content/docs
mkdir -p hugo/content/ox-hugo
cp src/static/ox-hugo/* hugo/content/ox-hugo
# run this every time.
hugo/data/version.yml: src/version.yml .PHONY
bin/write-spec-version.sh <$< >$@
# this is used to get "serve-and-watch" working. trick is to use
hugo-src-rsync: $(shell find src | grep '.md') gen-code diagrams
@mkdir -p hugo/content/docs
rsync -av --inplace src/ hugo/content/docs
printf " " >> hugo/content/_index.md # force reload
printf " " >> hugo/content/menu/index.md # force reload
watch-hugo: .PHONY
bin/watcher --cmd="make hugo-src-rsync" --startcmd src 2>/dev/null
clean-hugo: .PHONY
rm -rf hugo/content/docs
all-orient: .PHONY orient
bin/build-spec-orient.sh
ORIENT_FILES=$(shell find src -name '*.orient')
ORIENT_INPUT_FILES= $(patsubst %.orient, %.json, $(ORIENT_FILES))
ORIENT_OUTPUT_FILES=$(patsubst src/%.orient, build/%.orient.json, $(ORIENT_FILES))
orient: $(ORIENT_OUTPUT_FILES)
$(ORIENT_OUTPUT_FILES): build/%.orient.json: src/%.orient src/%.json
bin/solve-orient.sh $+ $@
# convert orgmode to markdown
ORG_FILES=$(shell find src | grep .org)
ORG_MD_FILES=$(patsubst %.org, %.md, $(ORG_FILES))
org2md: $(ORG_MD_FILES)
%.md: %.org
# use emacs to compile.
# cd to each target's directory, run there
# this should invoke orient
# this should produce hugo markdown output
# Skip this until batch-mode build issues are resolve.
# bin/org2hugomd.el <$< >$@
# building our tools
bins: bin/codeGen bin/watcher
bin/codeGen: $(shell find tools/codeGen | grep .go)
cd tools/codeGen && go build -o ../../bin/codeGen
bin/watcher:
go get -u github.com/radovskyb/watcher/...
go build -o $@ github.com/radovskyb/watcher/cmd/watcher
test-codeGen: bin/codeGen
cd tools/codeGen && go build && go test ./...
# cd tools/codeGen/test_cases && make test # this is broken
# other
serve: build-hugo .PHONY
echo "run 'make website' and refresh to update"
cd hugo && hugo serve --noHTTPCache
serve-website: website .PHONY
# use this if `make serve` breaks
echo "run 'make website' and refresh to update"
cd build/website && python -m SimpleHTTPServer 1313
serve-and-watch: serve watch-hugo
echo "make sure you run this with 'make -j2'"
.PHONY:
# code generation and building targets
GO_INPUT_FILES=$(shell find src -iname '*.go' | grep -v ^src/actors)
GO_OUTPUT_FILES=$(patsubst src/%.go, build/code/%.go, $(GO_INPUT_FILES))
GO_UTIL_INPUT_FILE=tools/codeGen/util/util.go
GO_UTIL_OUTPUT_FILE=build/code/util/util.go
$(GO_UTIL_OUTPUT_FILE): $(GO_UTIL_INPUT_FILE)
mkdir -p $(dir $@)
cp $< $@
build/code/%.go: src/%.go
mkdir -p $(dir $@)
cp $< $@
ID_FILES=$(shell find src -name '*.id')
GEN_GO_FILES=$(patsubst src/%.id, build/code/%.gen.go, $(ID_FILES))
build/code/%.gen.go: src/%.id bin/codeGen
mkdir -p $(dir $@)
-bin/codeGen gen $< $@
gen-code: bin/codeGen build/code/go.mod $(GEN_GO_FILES) $(GO_OUTPUT_FILES) $(GO_UTIL_OUTPUT_FILE)
build/code/go.mod: src/build_go.mod
mkdir -p $(dir $@)
cp $< $@
build-code: gen-code
cd build/code && go build -gcflags="-e" ./...
test-code: build-code
cd build/code && go test ./...
clean-code:
rm -rf build/code
fmt-code: bin/codeGen
bin/codeGen fmt ./src/...
go fmt ./src/...
go fmt ./tools/...
go fmt ./build/code/...
watch-code: .PHONY
bin/watcher --cmd="make build-code" --startcmd src 2>/dev/null
## diagrams
DOTs=$(shell find src -name '*.dot')
MMDs=$(shell find src -name '*.mmd')
SVGs=$(DOTs:%=%.svg) $(MMDs:%=%.svg)
diagrams: ${SVGs}
watch-diagrams: diagrams
bin/watcher --cmd="make diagrams" --startcmd src 2>/dev/null
%.dot.svg: %.dot
@which dot >/dev/null || echo "requires dot (graphviz) -- run make deps" && exit
dot -Tsvg $< >$@
%.mmd.svg: %.mmd %.mmd.css
deps/node_modules/.bin/mmdc -i $< -o $@ --cssFile $(word 2,$^)