Makefile 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. GOMINVERSION = 1.16
  2. NEBULA_CMD_PATH = "./cmd/nebula"
  3. GO111MODULE = on
  4. export GO111MODULE
  5. # Set up OS specific bits
  6. ifeq ($(OS),Windows_NT)
  7. #TODO: we should be able to ditch awk as well
  8. GOVERSION := $(shell go version | awk "{print substr($$3, 3)}")
  9. GOISMIN := $(shell IF "$(GOVERSION)" GEQ "$(GOMINVERSION)" ECHO 1)
  10. NEBULA_CMD_SUFFIX = .exe
  11. NULL_FILE = nul
  12. else
  13. GOVERSION := $(shell go version | awk '{print substr($$3, 3)}')
  14. GOISMIN := $(shell expr "$(GOVERSION)" ">=" "$(GOMINVERSION)")
  15. NEBULA_CMD_SUFFIX =
  16. NULL_FILE = /dev/null
  17. endif
  18. # Only defined the build number if we haven't already
  19. ifndef BUILD_NUMBER
  20. ifeq ($(shell git describe --exact-match 2>$(NULL_FILE)),)
  21. BUILD_NUMBER = $(shell git describe --abbrev=0 --match "v*" | cut -dv -f2)-$(shell git branch --show-current)-$(shell git describe --long --dirty | cut -d- -f2-)
  22. else
  23. BUILD_NUMBER = $(shell git describe --exact-match --dirty | cut -dv -f2)
  24. endif
  25. endif
  26. LDFLAGS = -X main.Build=$(BUILD_NUMBER)
  27. ALL_LINUX = linux-amd64 \
  28. linux-386 \
  29. linux-ppc64le \
  30. linux-arm-5 \
  31. linux-arm-6 \
  32. linux-arm-7 \
  33. linux-arm64 \
  34. linux-mips \
  35. linux-mipsle \
  36. linux-mips64 \
  37. linux-mips64le \
  38. linux-mips-softfloat
  39. ALL = $(ALL_LINUX) \
  40. darwin-amd64 \
  41. darwin-arm64 \
  42. freebsd-amd64 \
  43. windows-amd64
  44. e2e:
  45. $(TEST_ENV) go test -tags=e2e_testing -count=1 $(TEST_FLAGS) ./e2e
  46. e2ev: TEST_FLAGS = -v
  47. e2ev: e2e
  48. e2evv: TEST_ENV += TEST_LOGS=1
  49. e2evv: e2ev
  50. e2evvv: TEST_ENV += TEST_LOGS=2
  51. e2evvv: e2ev
  52. e2evvvv: TEST_ENV += TEST_LOGS=3
  53. e2evvvv: e2ev
  54. all: $(ALL:%=build/%/nebula) $(ALL:%=build/%/nebula-cert)
  55. release: $(ALL:%=build/nebula-%.tar.gz)
  56. release-linux: $(ALL_LINUX:%=build/nebula-%.tar.gz)
  57. release-freebsd: build/nebula-freebsd-amd64.tar.gz
  58. BUILD_ARGS = -trimpath
  59. bin-windows: build/windows-amd64/nebula.exe build/windows-amd64/nebula-cert.exe
  60. mv $? .
  61. bin-darwin: build/darwin-amd64/nebula build/darwin-amd64/nebula-cert
  62. mv $? .
  63. bin-freebsd: build/freebsd-amd64/nebula build/freebsd-amd64/nebula-cert
  64. mv $? .
  65. bin:
  66. go build $(BUILD_ARGS) -ldflags "$(LDFLAGS)" -o ./nebula${NEBULA_CMD_SUFFIX} ${NEBULA_CMD_PATH}
  67. go build $(BUILD_ARGS) -ldflags "$(LDFLAGS)" -o ./nebula-cert${NEBULA_CMD_SUFFIX} ./cmd/nebula-cert
  68. install:
  69. go install $(BUILD_ARGS) -ldflags "$(LDFLAGS)" ${NEBULA_CMD_PATH}
  70. go install $(BUILD_ARGS) -ldflags "$(LDFLAGS)" ./cmd/nebula-cert
  71. build/linux-arm-%: GOENV += GOARM=$(word 3, $(subst -, ,$*))
  72. build/linux-mips-%: GOENV += GOMIPS=$(word 3, $(subst -, ,$*))
  73. # Build an extra small binary for mips-softfloat
  74. build/linux-mips-softfloat/%: LDFLAGS += -s -w
  75. build/%/nebula: .FORCE
  76. GOOS=$(firstword $(subst -, , $*)) \
  77. GOARCH=$(word 2, $(subst -, ,$*)) $(GOENV) \
  78. go build $(BUILD_ARGS) -o $@ -ldflags "$(LDFLAGS)" ${NEBULA_CMD_PATH}
  79. build/%/nebula-cert: .FORCE
  80. GOOS=$(firstword $(subst -, , $*)) \
  81. GOARCH=$(word 2, $(subst -, ,$*)) $(GOENV) \
  82. go build $(BUILD_ARGS) -o $@ -ldflags "$(LDFLAGS)" ./cmd/nebula-cert
  83. build/%/nebula.exe: build/%/nebula
  84. mv $< $@
  85. build/%/nebula-cert.exe: build/%/nebula-cert
  86. mv $< $@
  87. build/nebula-%.tar.gz: build/%/nebula build/%/nebula-cert
  88. tar -zcv -C build/$* -f $@ nebula nebula-cert
  89. build/nebula-%.zip: build/%/nebula.exe build/%/nebula-cert.exe
  90. cd build/$* && zip ../nebula-$*.zip nebula.exe nebula-cert.exe
  91. vet:
  92. go vet -v ./...
  93. test:
  94. go test -v ./...
  95. test-cov-html:
  96. go test -coverprofile=coverage.out
  97. go tool cover -html=coverage.out
  98. bench:
  99. go test -bench=.
  100. bench-cpu:
  101. go test -bench=. -benchtime=5s -cpuprofile=cpu.pprof
  102. go tool pprof go-audit.test cpu.pprof
  103. bench-cpu-long:
  104. go test -bench=. -benchtime=60s -cpuprofile=cpu.pprof
  105. go tool pprof go-audit.test cpu.pprof
  106. proto: nebula.pb.go cert/cert.pb.go
  107. nebula.pb.go: nebula.proto .FORCE
  108. go build github.com/gogo/protobuf/protoc-gen-gogofaster
  109. PATH="$(CURDIR):$(PATH)" protoc --gogofaster_out=paths=source_relative:. $<
  110. rm protoc-gen-gogofaster
  111. cert/cert.pb.go: cert/cert.proto .FORCE
  112. $(MAKE) -C cert cert.pb.go
  113. service:
  114. @echo > $(NULL_FILE)
  115. $(eval NEBULA_CMD_PATH := "./cmd/nebula-service")
  116. ifeq ($(words $(MAKECMDGOALS)),1)
  117. @$(MAKE) service ${.DEFAULT_GOAL} --no-print-directory
  118. endif
  119. bin-docker: bin build/linux-amd64/nebula build/linux-amd64/nebula-cert
  120. smoke-docker: bin-docker
  121. cd .github/workflows/smoke/ && ./build.sh
  122. cd .github/workflows/smoke/ && ./smoke.sh
  123. smoke-docker-race: BUILD_ARGS = -race
  124. smoke-docker-race: smoke-docker
  125. .FORCE:
  126. .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
  127. .DEFAULT_GOAL := bin