33include embedded-bins/Makefile.variables
44include inttest/Makefile.variables
55
6+ ARCH ?= $(shell go env GOARCH)
7+
68BIN_DIR := $(shell pwd) /bin
79export PATH := $(BIN_DIR ) :$(PATH )
810
@@ -14,7 +16,15 @@ help: ## Display this help
1416
1517# #@ Build
1618
17- GO_TAGS = -tags=''
19+ # runs on linux even if it's built on mac or windows
20+ TARGET_OS ?= linux
21+ BUILD_GO_FLAGS := -tags osusergo
22+ BUILD_GO_FLAGS += -asmflags "all=-trimpath=$(shell dirname $(PWD ) ) "
23+ BUILD_GO_FLAGS += -gcflags "all=-trimpath=$(shell dirname $(PWD ) ) "
24+ LD_FLAGS := -X main.goos=$(shell go env GOOS)
25+ LD_FLAGS += -X main.goarch=$(shell go env GOARCH)
26+ LD_FLAGS += -X main.gitCommit=$(shell git rev-parse HEAD)
27+ LD_FLAGS += -X main.buildDate=$(shell date -u +'% Y-% m-% dT% H:% M:% SZ')
1828
1929GO_SRCS := $(shell find . -type f -name '* .go' -not -name '* _test.go' -not -name 'zz_generated* ')
2030
@@ -31,44 +41,39 @@ clean: ## Clean the bin directory
3141.PHONY : build
3242build : static bin/helmbin # # Build helmbin binaries
3343
34- GO_ASMFLAGS = -asmflags "all=-trimpath=$(shell dirname $(PWD ) ) "
35- GO_GCFLAGS = -gcflags "all=-trimpath=$(shell dirname $(PWD ) ) "
36- LD_FLAGS = -ldflags " \
37- -X main.goos=$(shell go env GOOS) \
38- -X main.goarch=$(shell go env GOARCH) \
39- -X main.gitCommit=$(shell git rev-parse HEAD) \
40- -X main.buildDate=$(shell date -u +'% Y-% m-% dT% H:% M:% SZ') \
41- "
42- BIN = bin/helmbin
44+ bin/helmbin : BIN = bin/helmbin
45+ bin/helmbin : TARGET_OS = linux
46+ bin/helmbin : BUILD_GO_CGO_ENABLED = 0
4347bin/helmbin : $(GO_SRCS ) go.sum
4448 @mkdir -p bin
45- CGO_ENABLED=0 go build $( GO_GCFLAGS ) $( GO_ASMFLAGS ) $( LD_FLAGS ) $( GO_TAGS ) -o $(BIN ) ./cmd/helmbin
49+ CGO_ENABLED=$( BUILD_GO_CGO_ENABLED ) GOOS= $( TARGET_OS ) go build $( BUILD_GO_FLAGS ) -ldflags= ' $(LD_FLAGS) ' -o $(BIN ) ./cmd/helmbin
4650
4751static : static/bin/k0s static/helm/000-admin-console-$(admin_console_version ) .tgz # # Build static assets
4852
4953static/bin/k0s :
5054 @mkdir -p static/bin
51- @ curl -fsSL -o static/bin/k0s https://github.com/k0sproject/k0s/releases/download/$(k0s_version ) /k0s-$(k0s_version ) -amd64
55+ curl -fsSL -o static/bin/k0s https://github.com/k0sproject/k0s/releases/download/$(k0s_version ) /k0s-$(k0s_version ) -$( ARCH )
5256 chmod +x static/bin/k0s
5357
5458static/helm/000-admin-console-$(admin_console_version ) .tgz : helm
5559 @mkdir -p static/helm
56- @ helm pull oci://registry.replicated.com/library/admin-console --version=$(admin_console_version )
60+ helm pull oci://registry.replicated.com/library/admin-console --version=$(admin_console_version )
5761 mv admin-console-$(admin_console_version ) .tgz static/helm/000-admin-console-$(admin_console_version ) .tgz
5862
5963# #@ Development
6064
6165.PHONY : lint
62- lint : golangci-lint # # Run golangci-lint linter
66+ lint : golangci-lint go.sum # # Run golangci-lint linter
6367 golangci-lint run
6468
6569.PHONY : lint-fix
6670lint-fix : golangci-lint # # Run golangci-lint linter and perform fixes
6771 golangci-lint run --fix
6872
6973.PHONY : test
70- test : # # Run the unit tests
71- go test $(GO_TAGS ) -race -v ./pkg/...
74+ test : GO_TEST_RACE ?= -race
75+ test : go.sum # # Run the unit tests
76+ go test $(GO_TEST_RACE ) -ldflags=' $(LD_FLAGS)' -v ./pkg/...
7277
7378.PHONY : $(smoketests )
7479$(smoketests ) : build
@@ -82,10 +87,15 @@ GOLANGCI_LINT = $(BIN_DIR)/golangci-lint
8287golangci-lint :
8388 @[ -f $( GOLANGCI_LINT) ] || { \
8489 set -e ; \
85- curl -fsSL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell dirname $(GOLANGCI_LINT ) ) ; \
90+ curl -fsSL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | \
91+ sh -s -- -b $(shell dirname $(GOLANGCI_LINT ) ) ; \
8692 }
8793
8894.PHONY : helm
8995helm :
9096 @mkdir -p $(BIN_DIR )
91- curl -fsSL https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | DESIRED_VERSION=v$(helm_version ) HELM_INSTALL_DIR=$(BIN_DIR ) bash
97+ curl -fsSL https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | \
98+ DESIRED_VERSION=v$(helm_version ) HELM_INSTALL_DIR=$(BIN_DIR ) USE_SUDO=false bash
99+
100+ go.sum : go.mod
101+ $(GO ) mod tidy && touch -c -- ' $@'
0 commit comments