Makefile 6.6 KB

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