Makefile raw

   1  # tinywallet - the browser wallet, its worker, and the tests that do not need a browser.
   2  #
   3  # The Go toolchain is picked from GOROOT when it is set; TinyGo builds the wasm side. The
   4  # nostrino channel worker is built from ../nostrino so the two bundles sit together.
   5  
   6  GO     ?= go
   7  TINYGO ?= tinygo
   8  BIN    ?= bin
   9  WALLET ?= $(BIN)/tinywallet.wasm
  10  CHANNEL ?= $(BIN)/nostrino-channel.wasm
  11  NOSTRINO ?= ../nostrino
  12  
  13  ifeq ($(wildcard $(GOROOT)/bin/go),)
  14    ifneq ($(wildcard $(HOME)/.local/goroot/bin/go),)
  15      GOROOT := $(HOME)/.local/goroot
  16    endif
  17  endif
  18  export GOROOT
  19  export PATH := $(GOROOT)/bin:$(PATH)
  20  
  21  .PHONY: all test race vet fmt wasm channel web clean
  22  
  23  all: test wasm
  24  
  25  ## test: the host tests, which cover everything but the browser edges
  26  test:
  27  	$(GO) test ./...
  28  
  29  ## race: the same, with the race detector, which the store and domain tests want
  30  race:
  31  	$(GO) test -race ./...
  32  
  33  vet:
  34  	$(GO) vet ./...
  35  
  36  fmt:
  37  	gofmt -l .
  38  
  39  ## wasm: the wallet worker
  40  wasm:
  41  	@mkdir -p $(BIN)
  42  	$(TINYGO) build -target wasm -o $(WALLET) ./cmd/tinywallet-wasm
  43  
  44  ## channel: the light-client worker, built from the repository beside this one
  45  channel:
  46  	@mkdir -p $(BIN)
  47  	cd $(NOSTRINO) && $(TINYGO) build -target wasm -o $(abspath $(BIN))/nostrino-channel.wasm ./cmd/nostrino-channel
  48  
  49  ## web: assemble both wasm bundles and the page in bin/web
  50  web: wasm channel
  51  	@mkdir -p $(BIN)/web
  52  	cp $(WALLET) $(CHANNEL) $(BIN)/web/
  53  	cp "$$($(TINYGO) env TINYGOROOT)/targets/wasm_exec.js" $(BIN)/web/wasm_exec.js
  54  	cp web/index.html web/wallet.js web/worker.js $(BIN)/web/
  55  	@echo "serve: cd $(BIN)/web && python3 -m http.server 8080"
  56  
  57  clean:
  58  	rm -rf $(BIN)
  59