Makefile 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. all: $(ALL:%=build/%/nebula) $(ALL:%=build/%/nebula-cert)
  31. release: $(ALL:%=build/nebula-%.tar.gz)
  32. release-linux: $(ALL_LINUX:%=build/nebula-%.tar.gz)
  33. release-freebsd: build/nebula-freebsd-amd64.tar.gz
  34. BUILD_ARGS = -trimpath
  35. bin-windows: build/windows-amd64/nebula.exe build/windows-amd64/nebula-cert.exe
  36. mv $? .
  37. bin-darwin: build/darwin-amd64/nebula build/darwin-amd64/nebula-cert
  38. mv $? .
  39. bin-freebsd: build/freebsd-amd64/nebula build/freebsd-amd64/nebula-cert
  40. mv $? .
  41. bin:
  42. go build $(BUILD_ARGS) -ldflags "$(LDFLAGS)" -o ./nebula ${NEBULA_CMD_PATH}
  43. go build $(BUILD_ARGS) -ldflags "$(LDFLAGS)" -o ./nebula-cert ./cmd/nebula-cert
  44. install:
  45. go install $(BUILD_ARGS) -ldflags "$(LDFLAGS)" ${NEBULA_CMD_PATH}
  46. go install $(BUILD_ARGS) -ldflags "$(LDFLAGS)" ./cmd/nebula-cert
  47. build/linux-arm-%: GOENV += GOARM=$(word 3, $(subst -, ,$*))
  48. build/linux-mips-%: GOENV += GOMIPS=$(word 3, $(subst -, ,$*))
  49. # Build an extra small binary for mips-softfloat
  50. build/linux-mips-softfloat/%: LDFLAGS += -s -w
  51. build/%/nebula: .FORCE
  52. GOOS=$(firstword $(subst -, , $*)) \
  53. GOARCH=$(word 2, $(subst -, ,$*)) $(GOENV) \
  54. go build $(BUILD_ARGS) -o $@ -ldflags "$(LDFLAGS)" ${NEBULA_CMD_PATH}
  55. build/%/nebula-cert: .FORCE
  56. GOOS=$(firstword $(subst -, , $*)) \
  57. GOARCH=$(word 2, $(subst -, ,$*)) $(GOENV) \
  58. go build $(BUILD_ARGS) -o $@ -ldflags "$(LDFLAGS)" ./cmd/nebula-cert
  59. build/%/nebula.exe: build/%/nebula
  60. mv $< $@
  61. build/%/nebula-cert.exe: build/%/nebula-cert
  62. mv $< $@
  63. build/nebula-%.tar.gz: build/%/nebula build/%/nebula-cert
  64. tar -zcv -C build/$* -f $@ nebula nebula-cert
  65. build/nebula-%.zip: build/%/nebula.exe build/%/nebula-cert.exe
  66. cd build/$* && zip ../nebula-$*.zip nebula.exe nebula-cert.exe
  67. vet:
  68. go vet -v ./...
  69. test:
  70. go test -v ./...
  71. test-cov-html:
  72. go test -coverprofile=coverage.out
  73. go tool cover -html=coverage.out
  74. bench:
  75. go test -bench=.
  76. bench-cpu:
  77. go test -bench=. -benchtime=5s -cpuprofile=cpu.pprof
  78. go tool pprof go-audit.test cpu.pprof
  79. bench-cpu-long:
  80. go test -bench=. -benchtime=60s -cpuprofile=cpu.pprof
  81. go tool pprof go-audit.test cpu.pprof
  82. proto: nebula.pb.go cert/cert.pb.go
  83. nebula.pb.go: nebula.proto .FORCE
  84. go build github.com/golang/protobuf/protoc-gen-go
  85. PATH="$(PWD):$(PATH)" protoc --go_out=. $<
  86. rm protoc-gen-go
  87. cert/cert.pb.go: cert/cert.proto .FORCE
  88. $(MAKE) -C cert cert.pb.go
  89. service:
  90. @echo > /dev/null
  91. $(eval NEBULA_CMD_PATH := "./cmd/nebula-service")
  92. ifeq ($(words $(MAKECMDGOALS)),1)
  93. $(MAKE) service ${.DEFAULT_GOAL} --no-print-directory
  94. endif
  95. bin-docker: bin build/linux-amd64/nebula build/linux-amd64/nebula-cert
  96. smoke-docker: bin-docker
  97. cd .github/workflows/smoke/ && ./build.sh
  98. cd .github/workflows/smoke/ && ./smoke.sh
  99. smoke-docker-race: BUILD_ARGS = -race
  100. smoke-docker-race: smoke-docker
  101. .FORCE:
  102. .PHONY: test test-cov-html bench bench-cpu bench-cpu-long bin proto release service smoke-docker smoke-docker-race
  103. .DEFAULT_GOAL := bin