forked from SolarRepublic/wasm-secp256k1
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
96 lines (83 loc) · 2.77 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
define USAGE
REQUIREMENTS:
- Powershell Core
- Docker
- Bun
USAGE:
> make [
sense: see usage.
clean: clean build artifacts, environment, cache, etc..
build-container: build the docker image for WASM builder container.
build: build the project.
publish: publish to https://npm.pkg.github.com.
]
endef
#####################
# General Variables #
#####################
OS ?= $(shell uname -s | tr A-Z a-z)
PWD = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
HEAD_COMMIT ?= $(shell git rev-parse HEAD)
OUTPUT_DIR ?= $(PWD)/dist
NODE_MODULES ?= $(PWD)/node_modules
ROLLUP_CACHE ?= $(PWD)/.rollup.cache
DOCKER_DIST ?= $(PWD)/.docker
###################
# General Targets #
###################
.PHONY: all sense clean build
all: sense
sense:
$(info $(USAGE))
# Define directories to remove
DIRS_TO_REMOVE = $(OUTPUT_DIR) $(NODE_MODULES) $(DOCKER_DIST) $(ROLLUP_CACHE)
# Define Unix-like command to remove directories
UNIX_RM = for dir in $(DIRS_TO_REMOVE); do [ -d "$$dir" ] && rm -rf $$dir; done
# Define Windows command to remove directories
WINDOWS_RM = for %%d in ($(DIRS_TO_REMOVE)) do if exist "%%~d" rmdir /s /q "%%~d"
# For Unix-like systems, use the UNIX_RM command
ifdef OS
SHELL = /bin/bash
CLEAN_CMD = $(UNIX_RM)
else
ifeq ($(OS),Windows_NT)
# For Windows, use cmd and the WINDOWS_RM command
SHELL = cmd
CLEAN_CMD = $(WINDOWS_RM)
endif
endif
clean:
@$(CLEAN_CMD)
################
# Host Targets #
################
LIBSECP256K1_BUILDER_TAG = secp256k1-wasm-builder
LIBSECP256K1.WASM = $(PWD)/src/gen/secp256k1.wasm
LIBSECP256K1.JS = $(PWD)/src/gen/secp256k1.js
LIBSECP256K1.GLUE = $(PWD)/src/gen/glue.ts
$(DOCKER_DIST)/dist/secp256k1.wasm:
@make build-container
@docker run --rm -v $(DOCKER_DIST):/dist $(LIBSECP256K1_BUILDER_TAG)
$(DOCKER_DIST)/dist/secp256k1.js:
@make build-container
@docker run --rm -v $(DOCKER_DIST):/dist $(LIBSECP256K1_BUILDER_TAG)
$(OUTPUT_DIR):
@mkdir -p $(OUTPUT_DIR)
$(LIBSECP256K1.WASM): $(DOCKER_DIST)/dist/secp256k1.wasm
@cp $(DOCKER_DIST)/dist/secp256k1.wasm $(LIBSECP256K1.WASM)
$(LIBSECP256K1.JS): $(DOCKER_DIST)/dist/secp256k1.js
@cp $(DOCKER_DIST)/dist/secp256k1.js $(LIBSECP256K1.JS)
$(LIBSECP256K1.GLUE): $(LIBSECP256K1.JS)
@bun install acorn --no-save
@bun run ./libsecp256k1/generate_glue.ts $(LIBSECP256K1.JS) > $(LIBSECP256K1.GLUE)
$(OUTPUT_DIR)/secp256k1.js: $(LIBSECP256K1.JS)
@cp $(LIBSECP256K1.JS) $(OUTPUT_DIR)/secp256k1.js
$(OUTPUT_DIR)/secp256k1.wasm: $(LIBSECP256K1.WASM)
@cp $(LIBSECP256K1.WASM) $(OUTPUT_DIR)/secp256k1.wasm
build-container:
@docker build -f libsecp256k1/Dockerfile . -t $(LIBSECP256K1_BUILDER_TAG)
build: $(OUTPUT_DIR) $(LIBSECP256K1.JS) $(LIBSECP256K1.WASM) $(LIBSECP256K1.GLUE) $(OUTPUT_DIR)/secp256k1.js $(OUTPUT_DIR)/secp256k1.wasm
@bun install --frozen-lockfile
@bun run build
publish:
@npm publish