Makefile 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. GOMINVERSION = 1.17
  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. linux-riscv64
  40. ALL = $(ALL_LINUX) \
  41. darwin-amd64 \
  42. darwin-arm64 \
  43. freebsd-amd64 \
  44. windows-amd64
  45. e2e:
  46. $(TEST_ENV) go test -tags=e2e_testing -count=1 $(TEST_FLAGS) ./e2e
  47. e2ev: TEST_FLAGS = -v
  48. e2ev: e2e
  49. e2evv: TEST_ENV += TEST_LOGS=1
  50. e2evv: e2ev
  51. e2evvv: TEST_ENV += TEST_LOGS=2
  52. e2evvv: e2ev
  53. e2evvvv: TEST_ENV += TEST_LOGS=3
  54. e2evvvv: e2ev
  55. all: $(ALL:%=build/%/nebula) $(ALL:%=build/%/nebula-cert)
  56. release: $(ALL:%=build/nebula-%.tar.gz)
  57. release-linux: $(ALL_LINUX:%=build/nebula-%.tar.gz)
  58. release-freebsd: build/nebula-freebsd-amd64.tar.gz
  59. BUILD_ARGS = -trimpath
  60. bin-windows: build/windows-amd64/nebula.exe build/windows-amd64/nebula-cert.exe
  61. mv $? .
  62. bin-darwin: build/darwin-amd64/nebula build/darwin-amd64/nebula-cert
  63. mv $? .
  64. bin-freebsd: build/freebsd-amd64/nebula build/freebsd-amd64/nebula-cert
  65. mv $? .
  66. bin:
  67. go build $(BUILD_ARGS) -ldflags "$(LDFLAGS)" -o ./nebula${NEBULA_CMD_SUFFIX} ${NEBULA_CMD_PATH}
  68. go build $(BUILD_ARGS) -ldflags "$(LDFLAGS)" -o ./nebula-cert${NEBULA_CMD_SUFFIX} ./cmd/nebula-cert
  69. install:
  70. go install $(BUILD_ARGS) -ldflags "$(LDFLAGS)" ${NEBULA_CMD_PATH}
  71. go install $(BUILD_ARGS) -ldflags "$(LDFLAGS)" ./cmd/nebula-cert
  72. build/linux-arm-%: GOENV += GOARM=$(word 3, $(subst -, ,$*))
  73. build/linux-mips-%: GOENV += GOMIPS=$(word 3, $(subst -, ,$*))
  74. # Build an extra small binary for mips-softfloat
  75. build/linux-mips-softfloat/%: LDFLAGS += -s -w
  76. build/%/nebula: .FORCE
  77. GOOS=$(firstword $(subst -, , $*)) \
  78. GOARCH=$(word 2, $(subst -, ,$*)) $(GOENV) \
  79. go build $(BUILD_ARGS) -o $@ -ldflags "$(LDFLAGS)" ${NEBULA_CMD_PATH}
  80. build/%/nebula-cert: .FORCE
  81. GOOS=$(firstword $(subst -, , $*)) \
  82. GOARCH=$(word 2, $(subst -, ,$*)) $(GOENV) \
  83. go build $(BUILD_ARGS) -o $@ -ldflags "$(LDFLAGS)" ./cmd/nebula-cert
  84. build/%/nebula.exe: build/%/nebula
  85. mv $< $@
  86. build/%/nebula-cert.exe: build/%/nebula-cert
  87. mv $< $@
  88. build/nebula-%.tar.gz: build/%/nebula build/%/nebula-cert
  89. tar -zcv -C build/$* -f $@ nebula nebula-cert
  90. build/nebula-%.zip: build/%/nebula.exe build/%/nebula-cert.exe
  91. cd build/$* && zip ../nebula-$*.zip nebula.exe nebula-cert.exe
  92. vet:
  93. go vet -v ./...
  94. test:
  95. go test -v ./...
  96. test-cov-html:
  97. go test -coverprofile=coverage.out
  98. go tool cover -html=coverage.out
  99. bench:
  100. go test -bench=.
  101. bench-cpu:
  102. go test -bench=. -benchtime=5s -cpuprofile=cpu.pprof
  103. go tool pprof go-audit.test cpu.pprof
  104. bench-cpu-long:
  105. go test -bench=. -benchtime=60s -cpuprofile=cpu.pprof
  106. go tool pprof go-audit.test cpu.pprof
  107. proto: nebula.pb.go cert/cert.pb.go
  108. nebula.pb.go: nebula.proto .FORCE
  109. go build github.com/gogo/protobuf/protoc-gen-gogofaster
  110. PATH="$(CURDIR):$(PATH)" protoc --gogofaster_out=paths=source_relative:. $<
  111. rm protoc-gen-gogofaster
  112. cert/cert.pb.go: cert/cert.proto .FORCE
  113. $(MAKE) -C cert cert.pb.go
  114. service:
  115. @echo > $(NULL_FILE)
  116. $(eval NEBULA_CMD_PATH := "./cmd/nebula-service")
  117. ifeq ($(words $(MAKECMDGOALS)),1)
  118. @$(MAKE) service ${.DEFAULT_GOAL} --no-print-directory
  119. endif
  120. bin-docker: bin build/linux-amd64/nebula build/linux-amd64/nebula-cert
  121. smoke-docker: bin-docker
  122. cd .github/workflows/smoke/ && ./build.sh
  123. cd .github/workflows/smoke/ && ./smoke.sh
  124. smoke-docker-race: BUILD_ARGS = -race
  125. smoke-docker-race: smoke-docker
  126. .FORCE:
  127. .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
  128. .DEFAULT_GOAL := bin