Makefile 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 = $(ALL_LINUX) \
  47. $(ALL_FREEBSD) \
  48. darwin-amd64 \
  49. darwin-arm64 \
  50. windows-amd64 \
  51. windows-arm64
  52. e2e:
  53. $(TEST_ENV) go test -tags=e2e_testing -count=1 $(TEST_FLAGS) ./e2e
  54. e2ev: TEST_FLAGS = -v
  55. e2ev: e2e
  56. e2evv: TEST_ENV += TEST_LOGS=1
  57. e2evv: e2ev
  58. e2evvv: TEST_ENV += TEST_LOGS=2
  59. e2evvv: e2ev
  60. e2evvvv: TEST_ENV += TEST_LOGS=3
  61. e2evvvv: e2ev
  62. e2e-bench: TEST_FLAGS = -bench=. -benchmem -run=^$
  63. e2e-bench: e2e
  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-boringcrypto: build/nebula-linux-$(shell go env GOARCH)-boringcrypto.tar.gz
  69. BUILD_ARGS = -trimpath
  70. bin-windows: build/windows-amd64/nebula.exe build/windows-amd64/nebula-cert.exe
  71. mv $? .
  72. bin-windows-arm64: build/windows-arm64/nebula.exe build/windows-arm64/nebula-cert.exe
  73. mv $? .
  74. bin-darwin: build/darwin-amd64/nebula build/darwin-amd64/nebula-cert
  75. mv $? .
  76. bin-freebsd: build/freebsd-amd64/nebula build/freebsd-amd64/nebula-cert
  77. mv $? .
  78. bin-freebsd-arm64: build/freebsd-arm64/nebula build/freebsd-arm64/nebula-cert
  79. mv $? .
  80. bin-boringcrypto: build/linux-$(shell go env GOARCH)-boringcrypto/nebula build/linux-$(shell go env GOARCH)-boringcrypto/nebula-cert
  81. mv $? .
  82. bin:
  83. go build $(BUILD_ARGS) -ldflags "$(LDFLAGS)" -o ./nebula${NEBULA_CMD_SUFFIX} ${NEBULA_CMD_PATH}
  84. go build $(BUILD_ARGS) -ldflags "$(LDFLAGS)" -o ./nebula-cert${NEBULA_CMD_SUFFIX} ./cmd/nebula-cert
  85. install:
  86. go install $(BUILD_ARGS) -ldflags "$(LDFLAGS)" ${NEBULA_CMD_PATH}
  87. go install $(BUILD_ARGS) -ldflags "$(LDFLAGS)" ./cmd/nebula-cert
  88. build/linux-arm-%: GOENV += GOARM=$(word 3, $(subst -, ,$*))
  89. build/linux-mips-%: GOENV += GOMIPS=$(word 3, $(subst -, ,$*))
  90. # Build an extra small binary for mips-softfloat
  91. build/linux-mips-softfloat/%: LDFLAGS += -s -w
  92. # boringcrypto
  93. build/linux-amd64-boringcrypto/%: GOENV += GOEXPERIMENT=boringcrypto CGO_ENABLED=1
  94. build/linux-arm64-boringcrypto/%: GOENV += GOEXPERIMENT=boringcrypto CGO_ENABLED=1
  95. build/%/nebula: .FORCE
  96. GOOS=$(firstword $(subst -, , $*)) \
  97. GOARCH=$(word 2, $(subst -, ,$*)) $(GOENV) \
  98. go build $(BUILD_ARGS) -o $@ -ldflags "$(LDFLAGS)" ${NEBULA_CMD_PATH}
  99. build/%/nebula-cert: .FORCE
  100. GOOS=$(firstword $(subst -, , $*)) \
  101. GOARCH=$(word 2, $(subst -, ,$*)) $(GOENV) \
  102. go build $(BUILD_ARGS) -o $@ -ldflags "$(LDFLAGS)" ./cmd/nebula-cert
  103. build/%/nebula.exe: build/%/nebula
  104. mv $< $@
  105. build/%/nebula-cert.exe: build/%/nebula-cert
  106. mv $< $@
  107. build/nebula-%.tar.gz: build/%/nebula build/%/nebula-cert
  108. tar -zcv -C build/$* -f $@ nebula nebula-cert
  109. build/nebula-%.zip: build/%/nebula.exe build/%/nebula-cert.exe
  110. cd build/$* && zip ../nebula-$*.zip nebula.exe nebula-cert.exe
  111. vet:
  112. go vet $(VET_FLAGS) -v ./...
  113. test:
  114. go test -v ./...
  115. test-boringcrypto:
  116. GOEXPERIMENT=boringcrypto CGO_ENABLED=1 go test -v ./...
  117. test-cov-html:
  118. go test -coverprofile=coverage.out
  119. go tool cover -html=coverage.out
  120. bench:
  121. go test -bench=.
  122. bench-cpu:
  123. go test -bench=. -benchtime=5s -cpuprofile=cpu.pprof
  124. go tool pprof go-audit.test cpu.pprof
  125. bench-cpu-long:
  126. go test -bench=. -benchtime=60s -cpuprofile=cpu.pprof
  127. go tool pprof go-audit.test cpu.pprof
  128. proto: nebula.pb.go cert/cert.pb.go
  129. nebula.pb.go: nebula.proto .FORCE
  130. go build github.com/gogo/protobuf/protoc-gen-gogofaster
  131. PATH="$(CURDIR):$(PATH)" protoc --gogofaster_out=paths=source_relative:. $<
  132. rm protoc-gen-gogofaster
  133. cert/cert.pb.go: cert/cert.proto .FORCE
  134. $(MAKE) -C cert cert.pb.go
  135. service:
  136. @echo > $(NULL_FILE)
  137. $(eval NEBULA_CMD_PATH := "./cmd/nebula-service")
  138. ifeq ($(words $(MAKECMDGOALS)),1)
  139. @$(MAKE) service ${.DEFAULT_GOAL} --no-print-directory
  140. endif
  141. bin-docker: bin build/linux-amd64/nebula build/linux-amd64/nebula-cert
  142. smoke-docker: bin-docker
  143. cd .github/workflows/smoke/ && ./build.sh
  144. cd .github/workflows/smoke/ && ./smoke.sh
  145. cd .github/workflows/smoke/ && NAME="smoke-p256" CURVE="P256" ./build.sh
  146. cd .github/workflows/smoke/ && NAME="smoke-p256" ./smoke.sh
  147. smoke-relay-docker: bin-docker
  148. cd .github/workflows/smoke/ && ./build-relay.sh
  149. cd .github/workflows/smoke/ && ./smoke-relay.sh
  150. smoke-docker-race: BUILD_ARGS = -race
  151. smoke-docker-race: smoke-docker
  152. .FORCE:
  153. .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
  154. .DEFAULT_GOAL := bin