Makefile 6.0 KB

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