Makefile 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. netbsd-amd64
  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. all: $(ALL:%=build/%/nebula) $(ALL:%=build/%/nebula-cert)
  66. release: $(ALL:%=build/nebula-%.tar.gz)
  67. release-linux: $(ALL_LINUX:%=build/nebula-%.tar.gz)
  68. release-freebsd: $(ALL_FREEBSD:%=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. bench:
  122. go test -bench=.
  123. bench-cpu:
  124. go test -bench=. -benchtime=5s -cpuprofile=cpu.pprof
  125. go tool pprof go-audit.test cpu.pprof
  126. bench-cpu-long:
  127. go test -bench=. -benchtime=60s -cpuprofile=cpu.pprof
  128. go tool pprof go-audit.test cpu.pprof
  129. proto: nebula.pb.go cert/cert.pb.go
  130. nebula.pb.go: nebula.proto .FORCE
  131. go build github.com/gogo/protobuf/protoc-gen-gogofaster
  132. PATH="$(CURDIR):$(PATH)" protoc --gogofaster_out=paths=source_relative:. $<
  133. rm protoc-gen-gogofaster
  134. cert/cert.pb.go: cert/cert.proto .FORCE
  135. $(MAKE) -C cert cert.pb.go
  136. service:
  137. @echo > $(NULL_FILE)
  138. $(eval NEBULA_CMD_PATH := "./cmd/nebula-service")
  139. ifeq ($(words $(MAKECMDGOALS)),1)
  140. @$(MAKE) service ${.DEFAULT_GOAL} --no-print-directory
  141. endif
  142. bin-docker: bin build/linux-amd64/nebula build/linux-amd64/nebula-cert
  143. smoke-docker: bin-docker
  144. cd .github/workflows/smoke/ && ./build.sh
  145. cd .github/workflows/smoke/ && ./smoke.sh
  146. cd .github/workflows/smoke/ && NAME="smoke-p256" CURVE="P256" ./build.sh
  147. cd .github/workflows/smoke/ && NAME="smoke-p256" ./smoke.sh
  148. smoke-relay-docker: bin-docker
  149. cd .github/workflows/smoke/ && ./build-relay.sh
  150. cd .github/workflows/smoke/ && ./smoke-relay.sh
  151. smoke-docker-race: BUILD_ARGS = -race
  152. smoke-docker-race: smoke-docker
  153. .FORCE:
  154. .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
  155. .DEFAULT_GOAL := bin