github.com/slackhq/nebula@v1.9.0/Makefile (about)

     1  NEBULA_CMD_PATH = "./cmd/nebula"
     2  CGO_ENABLED = 0
     3  export CGO_ENABLED
     4  
     5  # Set up OS specific bits
     6  ifeq ($(OS),Windows_NT)
     7  	NEBULA_CMD_SUFFIX = .exe
     8  	NULL_FILE = nul
     9  	# RIO on windows does pointer stuff that makes go vet angry
    10  	VET_FLAGS = -unsafeptr=false
    11  else
    12  	NEBULA_CMD_SUFFIX =
    13  	NULL_FILE = /dev/null
    14  endif
    15  
    16  # Only defined the build number if we haven't already
    17  ifndef BUILD_NUMBER
    18  	ifeq ($(shell git describe --exact-match 2>$(NULL_FILE)),)
    19  		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-)
    20  	else
    21  		BUILD_NUMBER = $(shell git describe --exact-match --dirty | cut -dv -f2)
    22  	endif
    23  endif
    24  
    25  DOCKER_IMAGE_REPO ?= nebulaoss/nebula
    26  DOCKER_IMAGE_TAG ?= latest
    27  
    28  LDFLAGS = -X main.Build=$(BUILD_NUMBER)
    29  
    30  ALL_LINUX = linux-amd64 \
    31  	linux-386 \
    32  	linux-ppc64le \
    33  	linux-arm-5 \
    34  	linux-arm-6 \
    35  	linux-arm-7 \
    36  	linux-arm64 \
    37  	linux-mips \
    38  	linux-mipsle \
    39  	linux-mips64 \
    40  	linux-mips64le \
    41  	linux-mips-softfloat \
    42  	linux-riscv64 \
    43          linux-loong64
    44  
    45  ALL_FREEBSD = freebsd-amd64 \
    46  	freebsd-arm64
    47  
    48  ALL_OPENBSD = openbsd-amd64 \
    49  	openbsd-arm64
    50  
    51  ALL_NETBSD = netbsd-amd64 \
    52   	netbsd-arm64
    53  
    54  ALL = $(ALL_LINUX) \
    55  	$(ALL_FREEBSD) \
    56  	$(ALL_OPENBSD) \
    57  	$(ALL_NETBSD) \
    58  	darwin-amd64 \
    59  	darwin-arm64 \
    60  	windows-amd64 \
    61  	windows-arm64
    62  
    63  e2e:
    64  	$(TEST_ENV) go test -tags=e2e_testing -count=1 $(TEST_FLAGS) ./e2e
    65  
    66  e2ev: TEST_FLAGS = -v
    67  e2ev: e2e
    68  
    69  e2evv: TEST_ENV += TEST_LOGS=1
    70  e2evv: e2ev
    71  
    72  e2evvv: TEST_ENV += TEST_LOGS=2
    73  e2evvv: e2ev
    74  
    75  e2evvvv: TEST_ENV += TEST_LOGS=3
    76  e2evvvv: e2ev
    77  
    78  e2e-bench: TEST_FLAGS = -bench=. -benchmem -run=^$
    79  e2e-bench: e2e
    80  
    81  DOCKER_BIN = build/linux-amd64/nebula build/linux-amd64/nebula-cert
    82  
    83  all: $(ALL:%=build/%/nebula) $(ALL:%=build/%/nebula-cert)
    84  
    85  docker: docker/linux-$(shell go env GOARCH)
    86  
    87  release: $(ALL:%=build/nebula-%.tar.gz)
    88  
    89  release-linux: $(ALL_LINUX:%=build/nebula-%.tar.gz)
    90  
    91  release-freebsd: $(ALL_FREEBSD:%=build/nebula-%.tar.gz)
    92  
    93  release-openbsd: $(ALL_OPENBSD:%=build/nebula-%.tar.gz)
    94  
    95  release-netbsd: $(ALL_NETBSD:%=build/nebula-%.tar.gz)
    96  
    97  release-boringcrypto: build/nebula-linux-$(shell go env GOARCH)-boringcrypto.tar.gz
    98  
    99  BUILD_ARGS = -trimpath
   100  
   101  bin-windows: build/windows-amd64/nebula.exe build/windows-amd64/nebula-cert.exe
   102  	mv $? .
   103  
   104  bin-windows-arm64: build/windows-arm64/nebula.exe build/windows-arm64/nebula-cert.exe
   105  	mv $? .
   106  
   107  bin-darwin: build/darwin-amd64/nebula build/darwin-amd64/nebula-cert
   108  	mv $? .
   109  
   110  bin-freebsd: build/freebsd-amd64/nebula build/freebsd-amd64/nebula-cert
   111  	mv $? .
   112  
   113  bin-freebsd-arm64: build/freebsd-arm64/nebula build/freebsd-arm64/nebula-cert
   114  	mv $? .
   115  
   116  bin-boringcrypto: build/linux-$(shell go env GOARCH)-boringcrypto/nebula build/linux-$(shell go env GOARCH)-boringcrypto/nebula-cert
   117  	mv $? .
   118  
   119  bin:
   120  	go build $(BUILD_ARGS) -ldflags "$(LDFLAGS)" -o ./nebula${NEBULA_CMD_SUFFIX} ${NEBULA_CMD_PATH}
   121  	go build $(BUILD_ARGS) -ldflags "$(LDFLAGS)" -o ./nebula-cert${NEBULA_CMD_SUFFIX} ./cmd/nebula-cert
   122  
   123  install:
   124  	go install $(BUILD_ARGS) -ldflags "$(LDFLAGS)" ${NEBULA_CMD_PATH}
   125  	go install $(BUILD_ARGS) -ldflags "$(LDFLAGS)" ./cmd/nebula-cert
   126  
   127  build/linux-arm-%: GOENV += GOARM=$(word 3, $(subst -, ,$*))
   128  build/linux-mips-%: GOENV += GOMIPS=$(word 3, $(subst -, ,$*))
   129  
   130  # Build an extra small binary for mips-softfloat
   131  build/linux-mips-softfloat/%: LDFLAGS += -s -w
   132  
   133  # boringcrypto
   134  build/linux-amd64-boringcrypto/%: GOENV += GOEXPERIMENT=boringcrypto CGO_ENABLED=1
   135  build/linux-arm64-boringcrypto/%: GOENV += GOEXPERIMENT=boringcrypto CGO_ENABLED=1
   136  
   137  build/%/nebula: .FORCE
   138  	GOOS=$(firstword $(subst -, , $*)) \
   139  		GOARCH=$(word 2, $(subst -, ,$*)) $(GOENV) \
   140  		go build $(BUILD_ARGS) -o $@ -ldflags "$(LDFLAGS)" ${NEBULA_CMD_PATH}
   141  
   142  build/%/nebula-cert: .FORCE
   143  	GOOS=$(firstword $(subst -, , $*)) \
   144  		GOARCH=$(word 2, $(subst -, ,$*)) $(GOENV) \
   145  		go build $(BUILD_ARGS) -o $@ -ldflags "$(LDFLAGS)" ./cmd/nebula-cert
   146  
   147  build/%/nebula.exe: build/%/nebula
   148  	mv $< $@
   149  
   150  build/%/nebula-cert.exe: build/%/nebula-cert
   151  	mv $< $@
   152  
   153  build/nebula-%.tar.gz: build/%/nebula build/%/nebula-cert
   154  	tar -zcv -C build/$* -f $@ nebula nebula-cert
   155  
   156  build/nebula-%.zip: build/%/nebula.exe build/%/nebula-cert.exe
   157  	cd build/$* && zip ../nebula-$*.zip nebula.exe nebula-cert.exe
   158  
   159  docker/%: build/%/nebula build/%/nebula-cert
   160  	docker build . $(DOCKER_BUILD_ARGS) -f docker/Dockerfile --platform "$(subst -,/,$*)" --tag "${DOCKER_IMAGE_REPO}:${DOCKER_IMAGE_TAG}" --tag "${DOCKER_IMAGE_REPO}:$(BUILD_NUMBER)"
   161  
   162  vet:
   163  	go vet $(VET_FLAGS) -v ./...
   164  
   165  test:
   166  	go test -v ./...
   167  
   168  test-boringcrypto:
   169  	GOEXPERIMENT=boringcrypto CGO_ENABLED=1 go test -v ./...
   170  
   171  test-cov-html:
   172  	go test -coverprofile=coverage.out
   173  	go tool cover -html=coverage.out
   174  
   175  build-test-mobile:
   176  	GOARCH=amd64 GOOS=ios go build $(shell go list ./... | grep -v '/cmd/\|/examples/')
   177  	GOARCH=arm64 GOOS=ios go build $(shell go list ./... | grep -v '/cmd/\|/examples/')
   178  	GOARCH=amd64 GOOS=android go build $(shell go list ./... | grep -v '/cmd/\|/examples/')
   179  	GOARCH=arm64 GOOS=android go build $(shell go list ./... | grep -v '/cmd/\|/examples/')
   180  
   181  bench:
   182  	go test -bench=.
   183  
   184  bench-cpu:
   185  	go test -bench=. -benchtime=5s -cpuprofile=cpu.pprof
   186  	go tool pprof go-audit.test cpu.pprof
   187  
   188  bench-cpu-long:
   189  	go test -bench=. -benchtime=60s -cpuprofile=cpu.pprof
   190  	go tool pprof go-audit.test cpu.pprof
   191  
   192  proto: nebula.pb.go cert/cert.pb.go
   193  
   194  nebula.pb.go: nebula.proto .FORCE
   195  	go build github.com/gogo/protobuf/protoc-gen-gogofaster
   196  	PATH="$(CURDIR):$(PATH)" protoc --gogofaster_out=paths=source_relative:. $<
   197  	rm protoc-gen-gogofaster
   198  
   199  cert/cert.pb.go: cert/cert.proto .FORCE
   200  	$(MAKE) -C cert cert.pb.go
   201  
   202  service:
   203  	@echo > $(NULL_FILE)
   204  	$(eval NEBULA_CMD_PATH := "./cmd/nebula-service")
   205  ifeq ($(words $(MAKECMDGOALS)),1)
   206  	@$(MAKE) service ${.DEFAULT_GOAL} --no-print-directory
   207  endif
   208  
   209  bin-docker: bin build/linux-amd64/nebula build/linux-amd64/nebula-cert
   210  
   211  smoke-docker: bin-docker
   212  	cd .github/workflows/smoke/ && ./build.sh
   213  	cd .github/workflows/smoke/ && ./smoke.sh
   214  	cd .github/workflows/smoke/ && NAME="smoke-p256" CURVE="P256" ./build.sh
   215  	cd .github/workflows/smoke/ && NAME="smoke-p256" ./smoke.sh
   216  
   217  smoke-relay-docker: bin-docker
   218  	cd .github/workflows/smoke/ && ./build-relay.sh
   219  	cd .github/workflows/smoke/ && ./smoke-relay.sh
   220  
   221  smoke-docker-race: BUILD_ARGS = -race
   222  smoke-docker-race: CGO_ENABLED = 1
   223  smoke-docker-race: smoke-docker
   224  
   225  smoke-vagrant/%: bin-docker build/%/nebula
   226  	cd .github/workflows/smoke/ && ./build.sh $*
   227  	cd .github/workflows/smoke/ && ./smoke-vagrant.sh $*
   228  
   229  .FORCE:
   230  .PHONY: bench bench-cpu bench-cpu-long bin build-test-mobile e2e e2ev e2evv e2evvv e2evvvv proto release service smoke-docker smoke-docker-race test test-cov-html smoke-vagrant/%
   231  .DEFAULT_GOAL := bin