Makefile 5.2 KB

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