1- .PHOHY : import build deploy-gcp
1+ .PHOHY : import build-wasm npm-install build clean zip deploy-gcp help
2+
3+ go-sources = go.mod go.sum *.go
4+ web-sources = package.json pnpm-lock.yaml vite.config.js src/*
25
36GOROOT: =$(shell go env GOROOT)
47
5- import :
6- cp " $( GOROOT) /misc/wasm/wasm_exec.js" static/
8+ # The below code utilizes make's file change tracking
9+ # (i.e. not rebuilding targets unnecessarily)
10+ # while still allowing human-readable target names.
11+ #
12+ # First we set a variable named foo that holds
13+ # all the actual output filenames.
14+ # Then we use $(foo) anywhere we need
15+ # to reference that target as a prerequisite.
16+ # Finally we create a target foo which
17+ # has $(foo) as a prerequisite.
18+
19+ # make import: copy the required wasm_exec.js file from the Go toolchain (output in vendor/)
20+ import = vendor/wasm_exec.js
21+
22+ $(import ) : $(GOROOT ) /misc/wasm/wasm_exec.js
23+ mkdir -p vendor
24+ cp " $( GOROOT) /misc/wasm/wasm_exec.js" vendor/
25+
26+ import : $(import )
27+
28+ # make build-wasm: build the WebAssembly module (output in vendor/)
29+ build-wasm = vendor/age.wasm
30+
31+ $(build-wasm ) : $(go-sources )
32+ mkdir -p vendor
33+ GOOS=js GOARCH=wasm go build -mod=mod -o vendor/age.wasm
34+
35+ build-wasm : $(build-wasm )
36+
37+ # make npm-install: installs tools and dependencies from npm (output in node_modules/)
38+ #
39+ # This uses an empty target file to track when it needs to be re-ran
40+ npm-install = node_modules/.make-sentinel
41+
42+ $(npm-install ) : package.json pnpm-lock.yaml
43+ pnpm install
44+ touch $(npm-install )
45+
46+ npm-install : $(npm-install )
47+
48+ # make build: build the complete static website (output in dist/)
49+ #
50+ # If dist/ doesn't exist $(build) will evaluate to 'dist/*'
51+ # but that's fine here because it means the target will run.
52+ build = dist/*
53+
54+ $(build ) : $(import ) $(build-wasm ) $(npm-install ) $(web-sources )
55+ pnpm run build
56+
57+ build : $(build )
58+
59+ # make clean: delete all existing build files (deletes vendor/* dist/*)
60+ clean :
61+ rm -rf vendor/ dist/
762
8- build :
9- GOOS=js GOARCH=wasm go build -o static/age.wasm
63+ # make zip: create a zip archive with the output static website (outputs agewasm.zip)
64+ zip = agewasm.zip
65+ $(zip ) : $(build )
66+ cd dist && zip -r ../$(zip ) .
67+ zip : $(zip )
1068
11- zip :
12- cd static && zip -r ../agewasm.zip .
69+ # make deploy-gcp: deploys to google cloud
70+ deploy-gcp : build
71+ gcloud app deploy
1372
14- deploy-gcp :
15- gcloud app deploy
73+ # make help: print this help page
74+ help :
75+ @echo " agewasm Makefile"
76+ @echo " Usage: make <TARGET>"
77+ @echo " "
78+ @echo " Available targets:"
79+ @grep -P ' ^# make [[:alnum:]_-]+:' Makefile | sed -e ' s/^# / /'
0 commit comments