Makefile 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. NEBULA_CMD_PATH = "./cmd/nebula"
  2. BUILD_NUMBER ?= dev+$(shell date -u '+%Y%m%d%H%M%S')
  3. GO111MODULE = on
  4. export GO111MODULE
  5. LDFLAGS = -X main.Build=$(BUILD_NUMBER)
  6. ALL_LINUX = linux-amd64 \
  7. linux-386 \
  8. linux-ppc64le \
  9. linux-arm-5 \
  10. linux-arm-6 \
  11. linux-arm-7 \
  12. linux-arm64 \
  13. linux-mips \
  14. linux-mipsle \
  15. linux-mips64 \
  16. linux-mips64le \
  17. linux-mips-softfloat
  18. ALL = $(ALL_LINUX) \
  19. darwin-amd64 \
  20. darwin-arm64 \
  21. freebsd-amd64 \
  22. windows-amd64
  23. all: $(ALL:%=build/%/nebula) $(ALL:%=build/%/nebula-cert)
  24. release: $(ALL:%=build/nebula-%.tar.gz)
  25. release-linux: $(ALL_LINUX:%=build/nebula-%.tar.gz)
  26. release-freebsd: build/nebula-freebsd-amd64.tar.gz
  27. BUILD_ARGS = -trimpath
  28. bin-windows: build/windows-amd64/nebula.exe build/windows-amd64/nebula-cert.exe
  29. mv $? .
  30. bin-darwin: build/darwin-amd64/nebula build/darwin-amd64/nebula-cert
  31. mv $? .
  32. bin-freebsd: build/freebsd-amd64/nebula build/freebsd-amd64/nebula-cert
  33. mv $? .
  34. bin:
  35. go build $(BUILD_ARGS) -ldflags "$(LDFLAGS)" -o ./nebula ${NEBULA_CMD_PATH}
  36. go build $(BUILD_ARGS) -ldflags "$(LDFLAGS)" -o ./nebula-cert ./cmd/nebula-cert
  37. install:
  38. go install $(BUILD_ARGS) -ldflags "$(LDFLAGS)" ${NEBULA_CMD_PATH}
  39. go install $(BUILD_ARGS) -ldflags "$(LDFLAGS)" ./cmd/nebula-cert
  40. build/linux-arm-%: GOENV += GOARM=$(word 3, $(subst -, ,$*))
  41. build/linux-mips-%: GOENV += GOMIPS=$(word 3, $(subst -, ,$*))
  42. # Build an extra small binary for mips-softfloat
  43. build/linux-mips-softfloat/%: LDFLAGS += -s -w
  44. build/%/nebula: .FORCE
  45. GOOS=$(firstword $(subst -, , $*)) \
  46. GOARCH=$(word 2, $(subst -, ,$*)) $(GOENV) \
  47. go build $(BUILD_ARGS) -o $@ -ldflags "$(LDFLAGS)" ${NEBULA_CMD_PATH}
  48. build/%/nebula-cert: .FORCE
  49. GOOS=$(firstword $(subst -, , $*)) \
  50. GOARCH=$(word 2, $(subst -, ,$*)) $(GOENV) \
  51. go build $(BUILD_ARGS) -o $@ -ldflags "$(LDFLAGS)" ./cmd/nebula-cert
  52. build/%/nebula.exe: build/%/nebula
  53. mv $< $@
  54. build/%/nebula-cert.exe: build/%/nebula-cert
  55. mv $< $@
  56. build/nebula-%.tar.gz: build/%/nebula build/%/nebula-cert
  57. tar -zcv -C build/$* -f $@ nebula nebula-cert
  58. build/nebula-%.zip: build/%/nebula.exe build/%/nebula-cert.exe
  59. cd build/$* && zip ../nebula-$*.zip nebula.exe nebula-cert.exe
  60. vet:
  61. go vet -v ./...
  62. test:
  63. go test -v ./...
  64. test-cov-html:
  65. go test -coverprofile=coverage.out
  66. go tool cover -html=coverage.out
  67. bench:
  68. go test -bench=.
  69. bench-cpu:
  70. go test -bench=. -benchtime=5s -cpuprofile=cpu.pprof
  71. go tool pprof go-audit.test cpu.pprof
  72. bench-cpu-long:
  73. go test -bench=. -benchtime=60s -cpuprofile=cpu.pprof
  74. go tool pprof go-audit.test cpu.pprof
  75. proto: nebula.pb.go cert/cert.pb.go
  76. nebula.pb.go: nebula.proto .FORCE
  77. go build github.com/golang/protobuf/protoc-gen-go
  78. PATH="$(PWD):$(PATH)" protoc --go_out=. $<
  79. rm protoc-gen-go
  80. cert/cert.pb.go: cert/cert.proto .FORCE
  81. $(MAKE) -C cert cert.pb.go
  82. service:
  83. @echo > /dev/null
  84. $(eval NEBULA_CMD_PATH := "./cmd/nebula-service")
  85. ifeq ($(words $(MAKECMDGOALS)),1)
  86. $(MAKE) service ${.DEFAULT_GOAL} --no-print-directory
  87. endif
  88. bin-docker: bin build/linux-amd64/nebula build/linux-amd64/nebula-cert
  89. smoke-docker: bin-docker
  90. cd .github/workflows/smoke/ && ./build.sh
  91. cd .github/workflows/smoke/ && ./smoke.sh
  92. smoke-docker-race: BUILD_ARGS = -race
  93. smoke-docker-race: smoke-docker
  94. .FORCE:
  95. .PHONY: test test-cov-html bench bench-cpu bench-cpu-long bin proto release service smoke-docker smoke-docker-race
  96. .DEFAULT_GOAL := bin