Makefile 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. GOMINVERSION = 1.16
  2. NEBULA_CMD_PATH = "./cmd/nebula"
  3. BUILD_NUMBER ?= dev+$(shell date -u '+%Y%m%d%H%M%S')
  4. GO111MODULE = on
  5. export GO111MODULE
  6. # Ensure the version of go we are using is at least what is defined in GOMINVERSION at the top of this file
  7. GOVERSION := $(shell go version | awk '{print substr($$3, 3)}')
  8. GOISMIN := $(shell expr "$(GOVERSION)" ">=" "$(GOMINVERSION)")
  9. ifneq "$(GOISMIN)" "1"
  10. $(error "go version $(GOVERSION) is not supported, upgrade to $(GOMINVERSION) or above")
  11. endif
  12. LDFLAGS = -X main.Build=$(BUILD_NUMBER)
  13. ALL_LINUX = linux-amd64 \
  14. linux-386 \
  15. linux-ppc64le \
  16. linux-arm-5 \
  17. linux-arm-6 \
  18. linux-arm-7 \
  19. linux-arm64 \
  20. linux-mips \
  21. linux-mipsle \
  22. linux-mips64 \
  23. linux-mips64le \
  24. linux-mips-softfloat
  25. ALL = $(ALL_LINUX) \
  26. darwin-amd64 \
  27. darwin-arm64 \
  28. freebsd-amd64 \
  29. windows-amd64
  30. e2e:
  31. $(TEST_ENV) go test -tags=e2e_testing -count=1 $(TEST_FLAGS) ./e2e
  32. e2ev: TEST_FLAGS = -v
  33. e2ev: e2e
  34. e2evv: TEST_ENV += TEST_LOGS=1
  35. e2evv: e2ev
  36. e2evvv: TEST_ENV += TEST_LOGS=2
  37. e2evvv: e2ev
  38. e2evvvv: TEST_ENV += TEST_LOGS=3
  39. e2evvvv: e2ev
  40. all: $(ALL:%=build/%/nebula) $(ALL:%=build/%/nebula-cert)
  41. release: $(ALL:%=build/nebula-%.tar.gz)
  42. release-linux: $(ALL_LINUX:%=build/nebula-%.tar.gz)
  43. release-freebsd: build/nebula-freebsd-amd64.tar.gz
  44. BUILD_ARGS = -trimpath
  45. bin-windows: build/windows-amd64/nebula.exe build/windows-amd64/nebula-cert.exe
  46. mv $? .
  47. bin-darwin: build/darwin-amd64/nebula build/darwin-amd64/nebula-cert
  48. mv $? .
  49. bin-freebsd: build/freebsd-amd64/nebula build/freebsd-amd64/nebula-cert
  50. mv $? .
  51. bin:
  52. go build $(BUILD_ARGS) -ldflags "$(LDFLAGS)" -o ./nebula ${NEBULA_CMD_PATH}
  53. go build $(BUILD_ARGS) -ldflags "$(LDFLAGS)" -o ./nebula-cert ./cmd/nebula-cert
  54. install:
  55. go install $(BUILD_ARGS) -ldflags "$(LDFLAGS)" ${NEBULA_CMD_PATH}
  56. go install $(BUILD_ARGS) -ldflags "$(LDFLAGS)" ./cmd/nebula-cert
  57. build/linux-arm-%: GOENV += GOARM=$(word 3, $(subst -, ,$*))
  58. build/linux-mips-%: GOENV += GOMIPS=$(word 3, $(subst -, ,$*))
  59. # Build an extra small binary for mips-softfloat
  60. build/linux-mips-softfloat/%: LDFLAGS += -s -w
  61. build/%/nebula: .FORCE
  62. GOOS=$(firstword $(subst -, , $*)) \
  63. GOARCH=$(word 2, $(subst -, ,$*)) $(GOENV) \
  64. go build $(BUILD_ARGS) -o $@ -ldflags "$(LDFLAGS)" ${NEBULA_CMD_PATH}
  65. build/%/nebula-cert: .FORCE
  66. GOOS=$(firstword $(subst -, , $*)) \
  67. GOARCH=$(word 2, $(subst -, ,$*)) $(GOENV) \
  68. go build $(BUILD_ARGS) -o $@ -ldflags "$(LDFLAGS)" ./cmd/nebula-cert
  69. build/%/nebula.exe: build/%/nebula
  70. mv $< $@
  71. build/%/nebula-cert.exe: build/%/nebula-cert
  72. mv $< $@
  73. build/nebula-%.tar.gz: build/%/nebula build/%/nebula-cert
  74. tar -zcv -C build/$* -f $@ nebula nebula-cert
  75. build/nebula-%.zip: build/%/nebula.exe build/%/nebula-cert.exe
  76. cd build/$* && zip ../nebula-$*.zip nebula.exe nebula-cert.exe
  77. vet:
  78. go vet -v ./...
  79. test:
  80. go test -v ./...
  81. test-cov-html:
  82. go test -coverprofile=coverage.out
  83. go tool cover -html=coverage.out
  84. bench:
  85. go test -bench=.
  86. bench-cpu:
  87. go test -bench=. -benchtime=5s -cpuprofile=cpu.pprof
  88. go tool pprof go-audit.test cpu.pprof
  89. bench-cpu-long:
  90. go test -bench=. -benchtime=60s -cpuprofile=cpu.pprof
  91. go tool pprof go-audit.test cpu.pprof
  92. proto: nebula.pb.go cert/cert.pb.go
  93. nebula.pb.go: nebula.proto .FORCE
  94. go build google.golang.org/protobuf/cmd/protoc-gen-go
  95. PATH="$(CURDIR):$(PATH)" protoc --go_out=. --go_opt=paths=source_relative $<
  96. rm protoc-gen-go
  97. cert/cert.pb.go: cert/cert.proto .FORCE
  98. $(MAKE) -C cert cert.pb.go
  99. service:
  100. @echo > /dev/null
  101. $(eval NEBULA_CMD_PATH := "./cmd/nebula-service")
  102. ifeq ($(words $(MAKECMDGOALS)),1)
  103. $(MAKE) service ${.DEFAULT_GOAL} --no-print-directory
  104. endif
  105. bin-docker: bin build/linux-amd64/nebula build/linux-amd64/nebula-cert
  106. smoke-docker: bin-docker
  107. cd .github/workflows/smoke/ && ./build.sh
  108. cd .github/workflows/smoke/ && ./smoke.sh
  109. smoke-docker-race: BUILD_ARGS = -race
  110. smoke-docker-race: smoke-docker
  111. .FORCE:
  112. .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
  113. .DEFAULT_GOAL := bin