Skip to content

Commit 66212f1

Browse files
authored
Merge pull request #1814 from Adirio/build-variables
🌱 Set build variables during `make build`
2 parents 9f32232 + dd18973 commit 66212f1

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

Makefile

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,25 @@ help: ## Display this help
3838

3939
##@ Build
4040

41+
LD_FLAGS=-ldflags " \
42+
-X sigs.k8s.io/kubebuilder/v2/cmd.kubeBuilderVersion=$(shell git descripe --tags --dirty --broken) \
43+
-X sigs.k8s.io/kubebuilder/v2/cmd.goos=$(shell go env GOOS) \
44+
-X sigs.k8s.io/kubebuilder/v2/cmd.goarch=$(shell go env GOARCH) \
45+
-X sigs.k8s.io/kubebuilder/v2/cmd.gitCommit=$(shell git rev-parse HEAD) \
46+
-X sigs.k8s.io/kubebuilder/v2/cmd.buildDate=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ') \
47+
"
4148
.PHONY: build
4249
build: ## Build the project locally
43-
go build -o bin/kubebuilder ./cmd
50+
go build $(LD_FLAGS) -o bin/kubebuilder ./cmd
4451

4552
.PHONY: install
46-
install: ## Build and install the binary with the current source code. Use it to test your changes locally.
47-
make build
53+
install: build ## Build and install the binary with the current source code. Use it to test your changes locally.
4854
cp ./bin/kubebuilder $(GOBIN)/kubebuilder
4955

5056
##@ Development
5157

5258
.PHONY: generate
53-
generate: ## Update/generate all mock data. You should run this commands to update the mock data after your changes.
54-
make generate-testdata
59+
generate: generate-testdata ## Update/generate all mock data. You should run this commands to update the mock data after your changes.
5560
go mod tidy
5661

5762
.PHONY: generate-testdata

0 commit comments

Comments
 (0)