Makefile raw

   1  # nostrino - a wasm BIP157 light client and its Nostr relay bridge.
   2  #
   3  # The primary target is the browser: `make wasm`. The gateway is native.
   4  # TinyGo shells out to the Go toolchain for its standard library sources; the
   5  # fallback below picks the local install when the inherited GOROOT is empty.
   6  
   7  GO     ?= go
   8  TINYGO ?= tinygo
   9  BIN    ?= bin
  10  WASM   ?= $(BIN)/nostrino.wasm
  11  CHANNEL ?= $(BIN)/nostrino-channel.wasm
  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 build wasm channel web tinygo tinygo-bridge tinygo-neutrino test race vet fmt smoke idb-smoke serve-web clean help
  22  
  23  all: build wasm
  24  
  25  ## build: native gateway and fixture commands with the Go toolchain
  26  build: bridge neutrino testnode discover
  27  
  28  bridge:
  29  	@mkdir -p $(BIN)
  30  	$(GO) build -o $(BIN)/nostrino-bridge ./cmd/nostrino-bridge
  31  
  32  neutrino:
  33  	@mkdir -p $(BIN)
  34  	$(GO) build -o $(BIN)/nostrino-neutrino ./cmd/nostrino-neutrino
  35  
  36  testnode:
  37  	@mkdir -p $(BIN)
  38  	$(GO) build -o $(BIN)/nostrino-testnode ./cmd/nostrino-testnode
  39  
  40  discover:
  41  	@mkdir -p $(BIN)
  42  	$(GO) build -o $(BIN)/nostrino-discover ./cmd/nostrino-discover
  43  
  44  ## wasm: the browser light client (the primary deliverable)
  45  wasm:
  46  	@mkdir -p $(BIN)
  47  	$(TINYGO) build -target wasm -o $(WASM) ./cmd/nostrino-wasm
  48  
  49  ## channel: the worker that answers a wallet's chain-data frames
  50  channel:
  51  	@mkdir -p $(BIN)
  52  	$(TINYGO) build -target wasm -o $(CHANNEL) ./cmd/nostrino-channel
  53  
  54  ## web: assemble the worker demo in bin/web
  55  web: wasm
  56  	@mkdir -p $(BIN)/web
  57  	cp $(WASM) $(BIN)/web/nostrino.wasm
  58  	cp "$$($(TINYGO) env TINYGOROOT)/targets/wasm_exec.js" $(BIN)/web/wasm_exec.js
  59  	cp web/index.html web/worker.js $(BIN)/web/
  60  	@echo "serve: cd $(BIN)/web && python3 -m http.server 8080"
  61  
  62  ## serve-web: serve the assembled demo on 127.0.0.1:8080
  63  serve-web: web
  64  	cd $(BIN)/web && python3 -m http.server 8080
  65  
  66  ## tinygo: build the gateway and native client with TinyGo
  67  tinygo: tinygo-bridge tinygo-neutrino
  68  
  69  tinygo-bridge:
  70  	@mkdir -p $(BIN)
  71  	$(TINYGO) build -o $(BIN)/nostrino-bridge-tiny ./cmd/nostrino-bridge
  72  
  73  tinygo-neutrino:
  74  	@mkdir -p $(BIN)
  75  	$(TINYGO) build -o $(BIN)/nostrino-neutrino-tiny ./cmd/nostrino-neutrino
  76  
  77  ## test: unit and integration tests with the Go toolchain
  78  test:
  79  	$(GO) test ./...
  80  
  81  ## race: the tunnel and end-to-end suites under the race detector
  82  race:
  83  	$(GO) test -race ./pkg/tunnel ./internal/e2e
  84  
  85  vet:
  86  	$(GO) vet ./...
  87  
  88  fmt:
  89  	$(GO) fmt ./...
  90  
  91  ## smoke: torly + test node + bridge + wasm in Node
  92  smoke: build wasm
  93  	WASM=$(abspath $(WASM)) ./scripts/wasm-smoke.sh
  94  
  95  ## idb-smoke: smoke plus IndexedDB persistence (needs fake-indexeddb)
  96  idb-smoke: build wasm
  97  	WASM=$(abspath $(WASM)) ./scripts/idb-smoke.sh
  98  
  99  clean:
 100  	rm -rf $(BIN)
 101  
 102  help:
 103  	@grep -E '^## ' $(MAKEFILE_LIST) | sed 's/## /  /'
 104