Makefile 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. GOMINVERSION = 1.20
  2. NEBULA_CMD_PATH = "./cmd/nebula"
  3. GO111MODULE = on
  4. export GO111MODULE
  5. CGO_ENABLED = 0
  6. export CGO_ENABLED
  7. # Set up OS specific bits
  8. ifeq ($(OS),Windows_NT)
  9. #TODO: we should be able to ditch awk as well
  10. GOVERSION := $(shell go version | awk "{print substr($$3, 3)}")
  11. GOISMIN := $(shell IF "$(GOVERSION)" GEQ "$(GOMINVERSION)" ECHO 1)
  12. NEBULA_CMD_SUFFIX = .exe
  13. NULL_FILE = nul
  14. # RIO on windows does pointer stuff that makes go vet angry
  15. VET_FLAGS = -unsafeptr=false
  16. else
  17. GOVERSION := $(shell go version | awk '{print substr($$3, 3)}')
  18. GOISMIN := $(shell expr "$(GOVERSION)" ">=" "$(GOMINVERSION)")
  19. NEBULA_CMD_SUFFIX =
  20. NULL_FILE = /dev/null
  21. endif
  22. # Only defined the build number if we haven't already
  23. ifndef BUILD_NUMBER
  24. ifeq ($(shell git describe --exact-match 2>$(NULL_FILE)),)
  25. BUILD_NUMBER = $(shell git describe --abbrev=0 --match "v*" | cut -dv -f2)-$(shell git branch --show-current)-$(shell git describe --long --dirty | cut -d- -f2-)
  26. else
  27. BUILD_NUMBER = $(shell git describe --exact-match --dirty | cut -dv -f2)
  28. endif
  29. endif
  30. LDFLAGS = -X main.Build=$(BUILD_NUMBER)
  31. ALL_LINUX = linux-amd64 \
  32. linux-386 \
  33. linux-ppc64le \
  34. linux-arm-5 \
  35. linux-arm-6 \
  36. linux-arm-7 \
  37. linux-arm64 \
  38. linux-mips \
  39. linux-mipsle \
  40. linux-mips64 \
  41. linux-mips64le \
  42. linux-mips-softfloat \
  43. linux-riscv64
  44. ALL_FREEBSD = freebsd-amd64 \
  45. freebsd-arm64
  46. ALL_OPENBSD = openbsd-amd64 \
  47. openbsd-arm64
  48. ALL_NETBSD = netbsd-amd64 \
  49. netbsd-arm64
  50. ALL = $(ALL_LINUX) \
  51. $(ALL_FREEBSD) \
  52. $(ALL_OPENBSD) \
  53. $(ALL_NETBSD) \
  54. darwin-amd64 \
  55. darwin-arm64 \
  56. windows-amd64 \
  57. windows-arm64
  58. e2e:
  59. $(TEST_ENV) go test -tags=e2e_testing -count=1 $(TEST_FLAGS) ./e2e
  60. e2ev: TEST_FLAGS = -v
  61. e2ev: e2e
  62. e2evv: TEST_ENV += TEST_LOGS=1
  63. e2evv: e2ev
  64. e2evvv: TEST_ENV += TEST_LOGS=2
  65. e2evvv: e2ev
  66. e2evvvv: TEST_ENV += TEST_LOGS=3
  67. e2evvvv: e2ev
  68. e2e-bench: TEST_FLAGS = -bench=. -benchmem -run=^$
  69. e2e-bench: e2e
  70. all: $(ALL:%=build/%/nebula) $(ALL:%=build/%/nebula-cert)
  71. release: $(ALL:%=build/nebula-%.tar.gz)
  72. release-linux: $(ALL_LINUX:%=build/nebula-%.tar.gz)
  73. release-freebsd: $(ALL_FREEBSD:%=build/nebula-%.tar.gz)
  74. release-openbsd: $(ALL_OPENBSD:%=build/nebula-%.tar.gz)
  75. release-netbsd: $(ALL_NETBSD:%=build/nebula-%.tar.gz)
  76. release-boringcrypto: build/nebula-linux-$(shell go env GOARCH)-boringcrypto.tar.gz
  77. BUILD_ARGS = -trimpath
  78. bin-windows: build/windows-amd64/nebula.exe build/windows-amd64/nebula-cert.exe
  79. mv $? .
  80. bin-windows-arm64: build/windows-arm64/nebula.exe build/windows-arm64/nebula-cert.exe
  81. mv $? .
  82. bin-darwin: build/darwin-amd64/nebula build/darwin-amd64/nebula-cert
  83. mv $? .
  84. bin-freebsd: build/freebsd-amd64/nebula build/freebsd-amd64/nebula-cert
  85. mv $? .
  86. bin-freebsd-arm64: build/freebsd-arm64/nebula build/freebsd-arm64/nebula-cert
  87. mv $? .
  88. bin-boringcrypto: build/linux-$(shell go env GOARCH)-boringcrypto/nebula build/linux-$(shell go env GOARCH)-boringcrypto/nebula-cert
  89. mv $? .
  90. bin:
  91. go build $(BUILD_ARGS) -ldflags "$(LDFLAGS)" -o ./nebula${NEBULA_CMD_SUFFIX} ${NEBULA_CMD_PATH}
  92. go build $(BUILD_ARGS) -ldflags "$(LDFLAGS)" -o ./nebula-cert${NEBULA_CMD_SUFFIX} ./cmd/nebula-cert
  93. install:
  94. go install $(BUILD_ARGS) -ldflags "$(LDFLAGS)" ${NEBULA_CMD_PATH}
  95. go install $(BUILD_ARGS) -ldflags "$(LDFLAGS)" ./cmd/nebula-cert
  96. build/linux-arm-%: GOENV += GOARM=$(word 3, $(subst -, ,$*))
  97. build/linux-mips-%: GOENV += GOMIPS=$(word 3, $(subst -, ,$*))
  98. # Build an extra small binary for mips-softfloat
  99. build/linux-mips-softfloat/%: LDFLAGS += -s -w
  100. # boringcrypto
  101. build/linux-amd64-boringcrypto/%: GOENV += GOEXPERIMENT=boringcrypto CGO_ENABLED=1
  102. build/linux-arm64-boringcrypto/%: GOENV += GOEXPERIMENT=boringcrypto CGO_ENABLED=1
  103. build/%/nebula: .FORCE
  104. GOOS=$(firstword $(subst -, , $*)) \
  105. GOARCH=$(word 2, $(subst -, ,$*)) $(GOENV) \
  106. go build $(BUILD_ARGS) -o $@ -ldflags "$(LDFLAGS)" ${NEBULA_CMD_PATH}
  107. build/%/nebula-cert: .FORCE
  108. GOOS=$(firstword $(subst -, , $*)) \
  109. GOARCH=$(word 2, $(subst -, ,$*)) $(GOENV) \
  110. go build $(BUILD_ARGS) -o $@ -ldflags "$(LDFLAGS)" ./cmd/nebula-cert
  111. build/%/nebula.exe: build/%/nebula
  112. mv $< $@
  113. build/%/nebula-cert.exe: build/%/nebula-cert
  114. mv $< $@
  115. build/nebula-%.tar.gz: build/%/nebula build/%/nebula-cert
  116. tar -zcv -C build/$* -f $@ nebula nebula-cert
  117. build/nebula-%.zip: build/%/nebula.exe build/%/nebula-cert.exe
  118. cd build/$* && zip ../nebula-$*.zip nebula.exe nebula-cert.exe
  119. vet:
  120. go vet $(VET_FLAGS) -v ./...
  121. test:
  122. go test -v ./...
  123. test-boringcrypto:
  124. GOEXPERIMENT=boringcrypto CGO_ENABLED=1 go test -v ./...
  125. test-cov-html:
  126. go test -coverprofile=coverage.out
  127. go tool cover -html=coverage.out
  128. build-test-mobile:
  129. GOARCH=amd64 GOOS=ios go build $(shell go list ./... | grep -v '/cmd/\|/examples/')
  130. GOARCH=arm64 GOOS=ios go build $(shell go list ./... | grep -v '/cmd/\|/examples/')
  131. GOARCH=amd64 GOOS=android go build $(shell go list ./... | grep -v '/cmd/\|/examples/')
  132. GOARCH=arm64 GOOS=android go build $(shell go list ./... | grep -v '/cmd/\|/examples/')
  133. bench:
  134. go test -bench=.
  135. bench-cpu:
  136. go test -bench=. -benchtime=5s -cpuprofile=cpu.pprof
  137. go tool pprof go-audit.test cpu.pprof
  138. bench-cpu-long:
  139. go test -bench=. -benchtime=60s -cpuprofile=cpu.pprof
  140. go tool pprof go-audit.test cpu.pprof
  141. proto: nebula.pb.go cert/cert.pb.go
  142. nebula.pb.go: nebula.proto .FORCE
  143. go build github.com/gogo/protobuf/protoc-gen-gogofaster
  144. PATH="$(CURDIR):$(PATH)" protoc --gogofaster_out=paths=source_relative:. $<
  145. rm protoc-gen-gogofaster
  146. cert/cert.pb.go: cert/cert.proto .FORCE
  147. $(MAKE) -C cert cert.pb.go
  148. service:
  149. @echo > $(NULL_FILE)
  150. $(eval NEBULA_CMD_PATH := "./cmd/nebula-service")
  151. ifeq ($(words $(MAKECMDGOALS)),1)
  152. @$(MAKE) service ${.DEFAULT_GOAL} --no-print-directory
  153. endif
  154. bin-docker: bin build/linux-amd64/nebula build/linux-amd64/nebula-cert
  155. smoke-docker: bin-docker
  156. cd .github/workflows/smoke/ && ./build.sh
  157. cd .github/workflows/smoke/ && ./smoke.sh
  158. cd .github/workflows/smoke/ && NAME="smoke-p256" CURVE="P256" ./build.sh
  159. cd .github/workflows/smoke/ && NAME="smoke-p256" ./smoke.sh
  160. smoke-relay-docker: bin-docker
  161. cd .github/workflows/smoke/ && ./build-relay.sh
  162. cd .github/workflows/smoke/ && ./smoke-relay.sh
  163. smoke-docker-race: BUILD_ARGS = -race
  164. smoke-docker-race: CGO_ENABLED = 1
  165. smoke-docker-race: smoke-docker
  166. .FORCE:
  167. .PHONY: bench bench-cpu bench-cpu-long bin build-test-mobile e2e e2ev e2evv e2evvv e2evvvv proto release service smoke-docker smoke-docker-race test test-cov-html
  168. .DEFAULT_GOAL := bin