-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
171 lines (135 loc) · 6.31 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
PATH := node_modules/.bin:$(PATH)
SHELL := /bin/bash
PROJECT_NAME=$(shell basename "$(PWD)")
.DEFAULT_GOAL := help
SOLC := ./node_modules/.bin/solcjs
TSC := ./node_modules/.bin/tsc
TS_SOURCES := $(wildcard lib/*.ts)
# JS_TARGETS = $(patsubst lib/%.ts, build/%.js, $(TS_SOURCES))
VOTING_CONTRACTS = $(wildcard contracts/*.sol)
TEST_CONTRACTS = $(wildcard contracts/test/*.sol)
ENS_CONTRACTS = $(wildcard contracts/vendor/registry/*.sol contracts/vendor/resolver/*.sol)
# Declare new contract artifacts on `build/solc` here
ARTIFACT_BASE_NAMES = \
contracts_vendor_registry_ENSRegistry_sol_ENSRegistry \
contracts_vendor_resolver_PublicResolver_sol_PublicResolver \
contracts_genesis_sol_Genesis \
contracts_namespaces_sol_Namespaces \
contracts_processes_sol_Processes \
contracts_results_sol_Results \
contracts_token-storage-proof_sol_TokenStorageProof \
contracts_test_trie-proof_sol_TrieProofTest
SOLC_ABI_ARTIFACTS := $(patsubst %, build/solc/%.abi, $(ARTIFACT_BASE_NAMES))
SOLC_BIN_ARTIFACTS := $(patsubst %, build/solc/%.bin, $(ARTIFACT_BASE_NAMES))
SOLC_ARTIFACT_PREFIXES := $(patsubst %, build/solc/%, $(ARTIFACT_BASE_NAMES))
# Add new contract entries here
ENS_REGISTRY_ARTIFACT_PREFIX = $(filter %_sol_ENSRegistry, $(SOLC_ARTIFACT_PREFIXES))
ENS_RESOLVER_ARTIFACT_PREFIX = $(filter %_sol_PublicResolver, $(SOLC_ARTIFACT_PREFIXES))
GENESIS_ARTIFACT_PREFIX = $(filter %_sol_Genesis, $(SOLC_ARTIFACT_PREFIXES))
NAMESPACES_ARTIFACT_PREFIX = $(filter %_sol_Namespaces, $(SOLC_ARTIFACT_PREFIXES))
PROCESSES_ARTIFACT_PREFIX = $(filter %_sol_Processes, $(SOLC_ARTIFACT_PREFIXES))
RESULTS_ARTIFACT_PREFIX = $(filter %_sol_Results, $(SOLC_ARTIFACT_PREFIXES))
TOKEN_STORAGE_PROOF_ARTIFACT_PREFIX = $(filter %_sol_TokenStorageProof, $(SOLC_ARTIFACT_PREFIXES))
TRIE_PROOF_TEST_ARTIFACT_PREFIX = $(filter %_sol_TrieProofTest, $(SOLC_ARTIFACT_PREFIXES))
#-----------------------------------------------------------------------
# HELP
#-----------------------------------------------------------------------
## help: Display this message
.PHONY: help
help:
@echo
@echo " Available targets on "$(PROJECT_NAME)":"
@echo
@sed -n 's/^##//p' Makefile | column -t -s ':' | sed -e 's/^/ /'
@echo
#-----------------------------------------------------------------------
# RECIPES
#-----------------------------------------------------------------------
## all: Compile the contract artifacts and generate the TypeScript type definitions
all: node_modules javascript contract-objects
## :
## init: Install the dependencies
init: node_modules
node_modules: package.json
@echo Updating Node packages
rm -f package-lock.json
npm install || true
if [ -d node_modules/web3-providers/node_modules/websocket ]; then \
rm -Rf node_modules/web3-providers/node_modules/websocket/.git ; \
rm -Rf node_modules/web3-providers-ws/node_modules/websocket/.git ; \
fi
@touch $@
# Add new contract target files here
contract-objects: \
build/ens-registry.json \
build/ens-resolver.json \
build/processes.json \
build/results.json \
build/genesis.json \
build/namespaces.json \
build/token-storage-proof.json \
build/test/trie-proof.json
build:
@mkdir -p build
@mkdir -p build/test
@touch $@
javascript: build/index.js
build/index.js: build contract-objects $(TS_SOURCES)
@echo "Building JS/TS artifacts"
cp $(TS_SOURCES) build
$(TSC) --build tsconfig.json
# Contract artifacts
build/ens-registry.json: $(ENS_REGISTRY_ARTIFACT_PREFIX).abi $(ENS_REGISTRY_ARTIFACT_PREFIX).bin
@stat $^ > /dev/null
@echo "Building $@"
echo "{\"abi\":$$(cat $(ENS_REGISTRY_ARTIFACT_PREFIX).abi),\"bytecode\":\"0x$$(cat $(ENS_REGISTRY_ARTIFACT_PREFIX).bin)\"}" > $@
build/ens-resolver.json: $(ENS_RESOLVER_ARTIFACT_PREFIX).abi $(ENS_RESOLVER_ARTIFACT_PREFIX).bin
@stat $^ > /dev/null
@echo "Building $@"
echo "{\"abi\":$$(cat $(ENS_RESOLVER_ARTIFACT_PREFIX).abi),\"bytecode\":\"0x$$(cat $(ENS_RESOLVER_ARTIFACT_PREFIX).bin)\"}" > $@
build/processes.json: $(PROCESSES_ARTIFACT_PREFIX).abi $(PROCESSES_ARTIFACT_PREFIX).bin
@stat $^ > /dev/null
@echo "Building $@"
echo "{\"abi\":$$(cat $(PROCESSES_ARTIFACT_PREFIX).abi),\"bytecode\":\"0x$$(cat $(PROCESSES_ARTIFACT_PREFIX).bin)\"}" > $@
build/results.json: $(RESULTS_ARTIFACT_PREFIX).abi $(RESULTS_ARTIFACT_PREFIX).bin
@stat $^ > /dev/null
@echo "Building $@"
echo "{\"abi\":$$(cat $(RESULTS_ARTIFACT_PREFIX).abi),\"bytecode\":\"0x$$(cat $(RESULTS_ARTIFACT_PREFIX).bin)\"}" > $@
build/genesis.json: $(GENESIS_ARTIFACT_PREFIX).abi $(GENESIS_ARTIFACT_PREFIX).bin
@stat $^ > /dev/null
@echo "Building $@"
echo "{\"abi\":$$(cat $(GENESIS_ARTIFACT_PREFIX).abi),\"bytecode\":\"0x$$(cat $(GENESIS_ARTIFACT_PREFIX).bin)\"}" > $@
build/namespaces.json: $(NAMESPACES_ARTIFACT_PREFIX).abi $(NAMESPACES_ARTIFACT_PREFIX).bin
@stat $^ > /dev/null
@echo "Building $@"
echo "{\"abi\":$$(cat $(NAMESPACES_ARTIFACT_PREFIX).abi),\"bytecode\":\"0x$$(cat $(NAMESPACES_ARTIFACT_PREFIX).bin)\"}" > $@
build/token-storage-proof.json: $(TOKEN_STORAGE_PROOF_ARTIFACT_PREFIX).abi $(TOKEN_STORAGE_PROOF_ARTIFACT_PREFIX).bin
@stat $^ > /dev/null
@echo "Building $@"
echo "{\"abi\":$$(cat $(TOKEN_STORAGE_PROOF_ARTIFACT_PREFIX).abi),\"bytecode\":\"0x$$(cat $(TOKEN_STORAGE_PROOF_ARTIFACT_PREFIX).bin)\"}" > $@
build/test/trie-proof.json: $(TRIE_PROOF_TEST_ARTIFACT_PREFIX).abi $(TRIE_PROOF_TEST_ARTIFACT_PREFIX).bin
@stat $^ > /dev/null
@echo "Building $@"
echo "{\"abi\":$$(cat $(TRIE_PROOF_TEST_ARTIFACT_PREFIX).abi),\"bytecode\":\"0x$$(cat $(TRIE_PROOF_TEST_ARTIFACT_PREFIX).bin)\"}" > $@
$(SOLC_ABI_ARTIFACTS): build/solc
$(SOLC_BIN_ARTIFACTS): build/solc
# Link the contracts from node_modules
contracts/vendor: contracts/vendor/openzeppelin
contracts/vendor/openzeppelin: node_modules
rm -f $@
ln -s ../../node_modules/@openzeppelin/contracts $@
# Intermediate solidity compiled artifacts
build/solc: $(VOTING_CONTRACTS) $(TEST_CONTRACTS) $(ENS_CONTRACTS) contracts/vendor
@echo "Building contracts"
mkdir -p $@
$(SOLC) --optimize --bin --abi -o $@ --base-path ${PWD} $(VOTING_CONTRACTS)
$(SOLC) --optimize --bin --abi -o $@ --base-path ${PWD} $(TEST_CONTRACTS)
$(SOLC) --optimize --bin --abi -o $@ --base-path ${PWD}/contracts/vendor $(ENS_CONTRACTS)
@touch $@
## test: Compile and test the contracts
test: clean all
npm run test
## clean: Cleanup the build folder
clean:
rm -Rf ./build
rm -Rf ./contracts/vendor/openzeppelin