Makefile 3.0 KB

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