| 1 | GO = go |
| 2 | GOFLAGS = |
| 3 | LDFLAGS = -s -w |
| 4 | TAGS = |
| 5 | PKG = ./... |
| 6 | SRCDIR = dnscrypt-proxy |
| 7 | BIN = dnscrypt-proxy |
| 8 | PREFIX = /usr/local |
| 9 | BINDIR = $(PREFIX)/bin |
| 10 | INSTALL = install |
| 11 | |
| 12 | .PHONY: all build install uninstall test test-short test-race test-suite \ |
| 13 | bench fmt vet tidy vendor staticcheck lint clean distclean run \ |
| 14 | version help |
| 15 | |
| 16 | all: build |
| 17 | |
| 18 | help: |
| 19 | @echo "Available targets:" |
| 20 | @echo " build Build the $(BIN) binary" |
| 21 | @echo " install Install $(BIN) to \$$PREFIX/bin (default /usr/local/bin)" |
| 22 | @echo " uninstall Remove the installed binary" |
| 23 | @echo " test Run the full test suite" |
| 24 | @echo " test-short Run tests with -short" |
| 25 | @echo " test-race Run tests with the race detector" |
| 26 | @echo " test-suite Run the categorized test script (run_tests.sh)" |
| 27 | @echo " bench Run benchmarks" |
| 28 | @echo " fmt Format the code with gofmt" |
| 29 | @echo " vet Run go vet" |
| 30 | @echo " staticcheck Run staticcheck (must be installed)" |
| 31 | @echo " lint Run fmt, vet and staticcheck" |
| 32 | @echo " tidy Run go mod tidy" |
| 33 | @echo " vendor Refresh the vendor directory" |
| 34 | @echo " run Build and run the binary in place" |
| 35 | @echo " version Print the application version" |
| 36 | @echo " clean Remove build artifacts" |
| 37 | @echo " distclean clean + remove the vendor directory" |
| 38 | |
| 39 | build: |
| 40 | cd $(SRCDIR) && $(GO) build $(GOFLAGS) -ldflags "$(LDFLAGS)" -tags "$(TAGS)" -o $(BIN) . |
| 41 | |
| 42 | install: build |
| 43 | $(INSTALL) -d $(DESTDIR)$(BINDIR) |
| 44 | $(INSTALL) -m 0755 $(SRCDIR)/$(BIN) $(DESTDIR)$(BINDIR)/$(BIN) |
| 45 | |
| 46 | uninstall: |
| 47 | rm -f $(DESTDIR)$(BINDIR)/$(BIN) |
| 48 | |
| 49 | test: |
| 50 | cd $(SRCDIR) && $(GO) test $(GOFLAGS) -tags "$(TAGS)" $(PKG) |
| 51 | |
| 52 | test-short: |
| 53 | cd $(SRCDIR) && $(GO) test $(GOFLAGS) -short -tags "$(TAGS)" $(PKG) |
| 54 | |
| 55 | test-race: |
| 56 | cd $(SRCDIR) && $(GO) test $(GOFLAGS) -race -tags "$(TAGS)" $(PKG) |
| 57 | |
| 58 | test-suite: |
| 59 | cd $(SRCDIR) && sh ./run_tests.sh |
| 60 | |
| 61 | bench: |
| 62 | cd $(SRCDIR) && $(GO) test $(GOFLAGS) -run=^$$ -bench=. -benchmem $(PKG) |
| 63 | |
| 64 | fmt: |
| 65 | $(GO) fmt ./... |
| 66 | |
| 67 | vet: |
| 68 | cd $(SRCDIR) && $(GO) vet $(PKG) |
| 69 | |
| 70 | staticcheck: |
| 71 | cd $(SRCDIR) && staticcheck $(PKG) |
| 72 | |
| 73 | lint: fmt vet staticcheck |
| 74 | |
| 75 | tidy: |
| 76 | $(GO) mod tidy |
| 77 | |
| 78 | vendor: |
| 79 | $(GO) mod vendor |
| 80 | |
| 81 | run: build |
| 82 | cd $(SRCDIR) && ./$(BIN) |
| 83 | |
| 84 | version: build |
| 85 | @$(SRCDIR)/$(BIN) -version |
| 86 | |
| 87 | clean: |
| 88 | rm -f $(SRCDIR)/$(BIN) |
| 89 | cd $(SRCDIR) && $(GO) clean $(PKG) |
| 90 | |
| 91 | distclean: clean |
| 92 | rm -rf vendor |