3
0

Makefile 5.5 KB

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