Makefile 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. DOCKER_BIN = build/linux-amd64/nebula build/linux-amd64/nebula-cert
  64. all: $(ALL:%=build/%/nebula) $(ALL:%=build/%/nebula-cert)
  65. release: $(ALL:%=build/nebula-%.tar.gz)
  66. release-linux: $(ALL_LINUX:%=build/nebula-%.tar.gz)
  67. release-freebsd: $(ALL_FREEBSD:%=build/nebula-%.tar.gz)
  68. release-openbsd: $(ALL_OPENBSD:%=build/nebula-%.tar.gz)
  69. release-netbsd: $(ALL_NETBSD:%=build/nebula-%.tar.gz)
  70. release-boringcrypto: build/nebula-linux-$(shell go env GOARCH)-boringcrypto.tar.gz
  71. BUILD_ARGS = -trimpath
  72. bin-windows: build/windows-amd64/nebula.exe build/windows-amd64/nebula-cert.exe
  73. mv $? .
  74. bin-windows-arm64: build/windows-arm64/nebula.exe build/windows-arm64/nebula-cert.exe
  75. mv $? .
  76. bin-darwin: build/darwin-amd64/nebula build/darwin-amd64/nebula-cert
  77. mv $? .
  78. bin-freebsd: build/freebsd-amd64/nebula build/freebsd-amd64/nebula-cert
  79. mv $? .
  80. bin-freebsd-arm64: build/freebsd-arm64/nebula build/freebsd-arm64/nebula-cert
  81. mv $? .
  82. bin-boringcrypto: build/linux-$(shell go env GOARCH)-boringcrypto/nebula build/linux-$(shell go env GOARCH)-boringcrypto/nebula-cert
  83. mv $? .
  84. bin:
  85. go build $(BUILD_ARGS) -ldflags "$(LDFLAGS)" -o ./nebula${NEBULA_CMD_SUFFIX} ${NEBULA_CMD_PATH}
  86. go build $(BUILD_ARGS) -ldflags "$(LDFLAGS)" -o ./nebula-cert${NEBULA_CMD_SUFFIX} ./cmd/nebula-cert
  87. install:
  88. go install $(BUILD_ARGS) -ldflags "$(LDFLAGS)" ${NEBULA_CMD_PATH}
  89. go install $(BUILD_ARGS) -ldflags "$(LDFLAGS)" ./cmd/nebula-cert
  90. build/linux-arm-%: GOENV += GOARM=$(word 3, $(subst -, ,$*))
  91. build/linux-mips-%: GOENV += GOMIPS=$(word 3, $(subst -, ,$*))
  92. # Build an extra small binary for mips-softfloat
  93. build/linux-mips-softfloat/%: LDFLAGS += -s -w
  94. # boringcrypto
  95. build/linux-amd64-boringcrypto/%: GOENV += GOEXPERIMENT=boringcrypto CGO_ENABLED=1
  96. build/linux-arm64-boringcrypto/%: GOENV += GOEXPERIMENT=boringcrypto CGO_ENABLED=1
  97. build/%/nebula: .FORCE
  98. GOOS=$(firstword $(subst -, , $*)) \
  99. GOARCH=$(word 2, $(subst -, ,$*)) $(GOENV) \
  100. go build $(BUILD_ARGS) -o $@ -ldflags "$(LDFLAGS)" ${NEBULA_CMD_PATH}
  101. build/%/nebula-cert: .FORCE
  102. GOOS=$(firstword $(subst -, , $*)) \
  103. GOARCH=$(word 2, $(subst -, ,$*)) $(GOENV) \
  104. go build $(BUILD_ARGS) -o $@ -ldflags "$(LDFLAGS)" ./cmd/nebula-cert
  105. build/%/nebula.exe: build/%/nebula
  106. mv $< $@
  107. build/%/nebula-cert.exe: build/%/nebula-cert
  108. mv $< $@
  109. build/nebula-%.tar.gz: build/%/nebula build/%/nebula-cert
  110. tar -zcv -C build/$* -f $@ nebula nebula-cert
  111. build/nebula-%.zip: build/%/nebula.exe build/%/nebula-cert.exe
  112. cd build/$* && zip ../nebula-$*.zip nebula.exe nebula-cert.exe
  113. vet:
  114. go vet $(VET_FLAGS) -v ./...
  115. test:
  116. go test -v ./...
  117. test-boringcrypto:
  118. GOEXPERIMENT=boringcrypto CGO_ENABLED=1 go test -v ./...
  119. test-cov-html:
  120. go test -coverprofile=coverage.out
  121. go tool cover -html=coverage.out
  122. build-test-mobile:
  123. GOARCH=amd64 GOOS=ios go build $(shell go list ./... | grep -v '/cmd/\|/examples/')
  124. GOARCH=arm64 GOOS=ios go build $(shell go list ./... | grep -v '/cmd/\|/examples/')
  125. GOARCH=amd64 GOOS=android go build $(shell go list ./... | grep -v '/cmd/\|/examples/')
  126. GOARCH=arm64 GOOS=android go build $(shell go list ./... | grep -v '/cmd/\|/examples/')
  127. bench:
  128. go test -bench=.
  129. bench-cpu:
  130. go test -bench=. -benchtime=5s -cpuprofile=cpu.pprof
  131. go tool pprof go-audit.test cpu.pprof
  132. bench-cpu-long:
  133. go test -bench=. -benchtime=60s -cpuprofile=cpu.pprof
  134. go tool pprof go-audit.test cpu.pprof
  135. proto: nebula.pb.go cert/cert.pb.go
  136. nebula.pb.go: nebula.proto .FORCE
  137. go build github.com/gogo/protobuf/protoc-gen-gogofaster
  138. PATH="$(CURDIR):$(PATH)" protoc --gogofaster_out=paths=source_relative:. $<
  139. rm protoc-gen-gogofaster
  140. cert/cert.pb.go: cert/cert.proto .FORCE
  141. $(MAKE) -C cert cert.pb.go
  142. service:
  143. @echo > $(NULL_FILE)
  144. $(eval NEBULA_CMD_PATH := "./cmd/nebula-service")
  145. ifeq ($(words $(MAKECMDGOALS)),1)
  146. @$(MAKE) service ${.DEFAULT_GOAL} --no-print-directory
  147. endif
  148. bin-docker: bin build/linux-amd64/nebula build/linux-amd64/nebula-cert
  149. smoke-docker: bin-docker
  150. cd .github/workflows/smoke/ && ./build.sh
  151. cd .github/workflows/smoke/ && ./smoke.sh
  152. cd .github/workflows/smoke/ && NAME="smoke-p256" CURVE="P256" ./build.sh
  153. cd .github/workflows/smoke/ && NAME="smoke-p256" ./smoke.sh
  154. smoke-relay-docker: bin-docker
  155. cd .github/workflows/smoke/ && ./build-relay.sh
  156. cd .github/workflows/smoke/ && ./smoke-relay.sh
  157. smoke-docker-race: BUILD_ARGS = -race
  158. smoke-docker-race: CGO_ENABLED = 1
  159. smoke-docker-race: smoke-docker
  160. smoke-vagrant/%: bin-docker build/%/nebula
  161. cd .github/workflows/smoke/ && ./build.sh $*
  162. cd .github/workflows/smoke/ && ./smoke-vagrant.sh $*
  163. .FORCE:
  164. .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 smoke-vagrant/%
  165. .DEFAULT_GOAL := bin