Makefile 2.9 KB

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