Makefile raw

   1  # torly - a TinyGo Nostr relay.
   2  #
   3  # Build uses TinyGo; the standard Go toolchain is still required by TinyGo for
   4  # its standard library sources (TinyGo shells out to `go`). Both are located
   5  # through PATH; the fallback below provisions this checkout's local toolchain.
   6  
   7  TINYGO ?= tinygo
   8  GO     ?= go
   9  
  10  # The host shell may export a GOROOT that does not contain a Go toolchain.
  11  # Prefer a working one, else the local install used to bootstrap this tree.
  12  ifeq ($(wildcard $(GOROOT)/bin/go),)
  13    ifneq ($(wildcard $(HOME)/.local/goroot/bin/go),)
  14      GOROOT := $(HOME)/.local/goroot
  15    endif
  16  endif
  17  export GOROOT
  18  export PATH := $(GOROOT)/bin:$(PATH)
  19  
  20  BIN     ?= torly
  21  PKG     := ./cmd/torly
  22  PORT    ?= 3334
  23  DATA    ?= ./data
  24  STATIC  ?= ./web/static
  25  
  26  .PHONY: all build build-go test test-tinygo e2e check vet fmt run clean size help
  27  
  28  all: build
  29  
  30  ## build: compile the relay with TinyGo
  31  build:
  32  	$(TINYGO) build -o $(BIN) $(PKG)
  33  
  34  ## build-go: compile with the standard Go toolchain (for debugging/tests)
  35  build-go:
  36  	$(GO) build -o $(BIN)-go $(PKG)
  37  
  38  ## test: run the unit tests with the standard Go toolchain
  39  test:
  40  	$(GO) test ./...
  41  
  42  ## test-tinygo: run the unit tests under TinyGo
  43  test-tinygo:
  44  	$(TINYGO) test ./...
  45  
  46  ## e2e: build and drive the relay with the real nak client
  47  e2e: build
  48  	./scripts/e2e.sh
  49  
  50  ## check: vet + test
  51  check: vet test
  52  
  53  vet:
  54  	$(GO) vet ./...
  55  
  56  fmt:
  57  	$(GO) fmt ./...
  58  
  59  ## run: build and serve on PORT with DATA
  60  run: build
  61  	TORLY_PORT=$(PORT) TORLY_DATA_DIR=$(DATA) TORLY_STATIC_DIR=$(STATIC) ./$(BIN) serve
  62  
  63  ## size: show the binary size breakdown
  64  size: build
  65  	ls -lh $(BIN)
  66  	@command -v size >/dev/null && size $(BIN) || true
  67  
  68  clean:
  69  	rm -f $(BIN) $(BIN)-go
  70  
  71  help:
  72  	@grep -E '^## ' $(MAKEFILE_LIST) | sed 's/## /  /'
  73