-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathMakefile
More file actions
94 lines (72 loc) · 2.6 KB
/
Copy pathMakefile
File metadata and controls
94 lines (72 loc) · 2.6 KB
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
.PHOHY: import build-wasm npm-install build clean zip deploy-gcp help
go-sources = go.mod go.sum *.go
web-sources = package.json pnpm-lock.yaml vite.config.js src/*
GOROOT:=$(shell go env GOROOT)
# The below code utilizes make's file change tracking
# (i.e. not rebuilding targets unnecessarily)
# while still allowing human-readable target names.
#
# First we set a variable named foo that holds
# all the actual output filenames.
# Then we use $(foo) anywhere we need
# to reference that target as a prerequisite.
# Finally we create a target foo which
# has $(foo) as a prerequisite.
# make import: copy the required wasm_exec.js file from the Go toolchain (output in vendor/)
# Variables
IMPORT = vendor/wasm_exec.js
GO_VERSION := $(shell go env GOVERSION | sed 's/^go//')
GO_MAJOR := $(shell echo $(GO_VERSION) | cut -d. -f1)
GO_MINOR := $(shell echo $(GO_VERSION) | cut -d. -f2)
ifeq ($(shell [ $(GO_MAJOR) -eq 1 -a $(GO_MINOR) -lt 24 ] && echo yes),yes)
WASM_EXEC_PATH := $(GOROOT)/misc/wasm/wasm_exec.js
else
WASM_EXEC_PATH := $(GOROOT)/lib/wasm/wasm_exec.js
endif
# Rule to copy wasm_exec.js into vendor
$(IMPORT): $(WASM_EXEC_PATH)
mkdir -p vendor
cp "$(WASM_EXEC_PATH)" vendor/
# import target depends on the file
import: $(IMPORT)
# make build-wasm: build the WebAssembly module (output in vendor/)
build-wasm = vendor/age.wasm
$(build-wasm): $(go-sources)
mkdir -p vendor
GOOS=js GOARCH=wasm go build -mod=mod -o vendor/age.wasm
build-wasm: $(build-wasm)
# make npm-install: installs tools and dependencies from npm (output in node_modules/)
#
# This uses an empty target file to track when it needs to be re-ran
npm-install = node_modules/.make-sentinel
$(npm-install): package.json pnpm-lock.yaml
pnpm install
touch $(npm-install)
npm-install: $(npm-install)
# make build: build the complete static website (output in dist/)
#
# If dist/ doesn't exist $(build) will evaluate to 'dist/*'
# but that's fine here because it means the target will run.
build = dist/*
$(build): $(import) $(build-wasm) $(npm-install) $(web-sources)
pnpm run build
build: $(build)
# make clean: delete all existing build files (deletes vendor/* dist/*)
clean:
rm -rf vendor/ dist/
# make zip: create a zip archive with the output static website (outputs agewasm.zip)
zip = agewasm.zip
$(zip): $(build)
rm -f $(zip)
cd dist && zip -r ../$(zip) .
zip: $(zip)
# make deploy-gcp: deploys to google cloud
deploy-gcp: build
gcloud app deploy
# make help: print this help page
help:
@echo "agewasm Makefile"
@echo "Usage: make <TARGET>"
@echo ""
@echo "Available targets:"
@grep -P '^# make [[:alnum:]_-]+:' Makefile | sed -e 's/^# / /'