-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
140 lines (112 loc) · 3.79 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
SHELL := /bin/bash
PATH := $(PATH):$(HOME)/.pub-cache/bin:$(PWD)/bin:$(HOME)/go/bin
.DEFAULT_GOAL := help
PROJECT_NAME=$(shell basename "$(PWD)")
CLIENT_STORE_SOURCES=$(wildcard src/client-store/*.proto)
METADATA_SOURCES=$(wildcard src/metadata/*.proto)
VOCHAIN_SOURCES=$(wildcard src/vochain/*.proto)
IPFSSYNC_SOURCES=$(wildcard src/ipfsSync/*.proto)
VOCDONI_NODE_SOURCES=$(wildcard src/vocdoni-node/*.proto)
PROTOC?=$(shell which protoc)
$(if $(PROTOC),,$(eval PROTOC=bin/protoc))
PROTOC_TS_PLUGIN := ./node_modules/.bin/protoc-gen-ts_proto
define install_protoc
@if [ "$(PROTOC)" == "bin/protoc" -a ! -x bin/protoc ]; then \
case "$$(uname)" in \
linux|Linux) \
curl -L https://github.com/protocolbuffers/protobuf/releases/download/v3.15.8/protoc-3.15.8-linux-x86_64.zip > protoc.zip \
;;\
darwin|Darwin) \
curl -L https://github.com/protocolbuffers/protobuf/releases/download/v3.15.8/protoc-3.15.8-osx-x86_64.zip > protoc.zip \
;;\
*) \
echo "Unsupported platform: $$(uname)" ;\
exit 1 ;\
esac ;\
unzip -d . protoc.zip ;\
rm protoc.zip readme.txt;\
fi
endef
define install_protoc_go
@if [ "$(PROTOC)" == "bin/protoc" -a ! -x bin/protoc-gen-go ]; then \
if [ ! -d "$$GOPATH" ] ; then \
export GOPATH="$$HOME/go" ;\
fi ; \
go install google.golang.org/protobuf/cmd/protoc-gen-go ;\
fi
endef
#-----------------------------------------------------------------------
# HELP
#-----------------------------------------------------------------------
## help: Display this message
.PHONY: help
help:
@echo
@echo " Available actions in "$(PROJECT_NAME)":"
@echo
@sed -n 's/^##//p' Makefile | column -t -s ':' | sed -e 's/^/ /'
@echo
## :
## init: Install external dependencies
init: protoc $(PROTOC_TS_PLUGIN) protoc-go-plugin
## clean: Remove the build artifacts
clean:
rm -Rf build include
## :
#-----------------------------------------------------------------------
# RECIPES
#-----------------------------------------------------------------------
## all: Generate the source code for all supported languages
all: golang js
## golang: Generate the Golang protobuf artifacts
golang: protoc protoc-go-plugin build/go/models
build/go/models: $(VOCHAIN_SOURCES) $(VOCDONI_NODE_SOURCES) $(IPFSSYNC_SOURCES)
rm -rf $@
mkdir -p $@
for f in $^ ; do \
$(PROTOC) --go_opt=paths=source_relative --experimental_allow_proto3_optional -I=$(PWD)/src --go_out=$@ $(PWD)/$$f ; \
done
find $@ -iname "*.go" -type f -exec mv {} $@ \;
find $@ -type d -empty -delete
@touch $@
## dart: Generate the Dart protobuf artifacts
dart: protoc protoc-dart-plugin build/dart
build/dart: $(CLIENT_STORE_SOURCES) $(METADATA_SOURCES) $(VOCHAIN_SOURCES)
mkdir -p $@
for f in $^ ; do \
$(PROTOC) --experimental_allow_proto3_optional -I=$(PWD)/src --dart_out=$(PWD)/$@ $(PWD)/$$f ; \
done
@touch $@
## ts: Generate the TypeScript protobuf artifacts
ts: protoc $(PROTOC_TS_PLUGIN) build/ts
build/ts: $(VOCHAIN_SOURCES) $(CLIENT_STORE_SOURCES) $(METADATA_SOURCES)
mkdir -p build
cp -r typescript build/ts
mkdir -p $@
for f in $^ ; do \
$(PROTOC) -I=$(PWD)/src --plugin=$(PROTOC_TS_PLUGIN) --experimental_allow_proto3_optional --ts_proto_opt=esModuleInterop=true --ts_proto_opt=exportCommonSymbols=false --ts_proto_opt=oneof=unions --ts_proto_out=$@ $(PWD)/$$f ; \
done
@touch $@
npm i --no-package-lock
## js: Generate the JavaScript bundle
js: ts build/js
build/js:
yarn
yarn build
#-----------------------------------------------------------------------
# COMPILERS
#-----------------------------------------------------------------------
.PHONY: protoc
protoc:
$(call install_protoc)
# DART
.PHONY: protoc-dart-plugin
protoc-dart-plugin:
dart pub global activate protoc_plugin
# TS
$(PROTOC_TS_PLUGIN):
@npm install ts-proto --no-package-lock
# GO
.PHONY: protoc-go-plugin
protoc-go-plugin:
$(call install_protoc_go)