Skip to content

Commit c1c7b07

Browse files
committed
improve Makefile for multi-binary projects
On-behalf-of: @SAP christoph.mewes@sap.com
1 parent 18afc13 commit c1c7b07

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*.dll
55
*.so
66
*.dylib
7-
/bin
7+
/_build
88

99
# Test binary, built with `go test -c`
1010
*.test

Makefile

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
SHELL := /usr/bin/env bash
1616

1717
GO_INSTALL = ./hack/go-install.sh
18+
BUILD_DEST ?= _build
19+
CMD ?= $(notdir $(wildcard ./cmd/*))
1820

1921
TOOLS_DIR=hack/tools
2022
GOBIN_DIR := $(abspath $(TOOLS_DIR))
@@ -72,11 +74,19 @@ $(KUBE_INFORMER_GEN):
7274
$(KUBE_APPLYCONFIGURATION_GEN):
7375
GOBIN=$(GOBIN_DIR) $(GO_INSTALL) k8s.io/code-generator/cmd/$(KUBE_APPLYCONFIGURATION_GEN_BIN) $(KUBE_APPLYCONFIGURATION_GEN_BIN) $(KUBE_APPLYCONFIGURATION_GEN_VER)
7476

77+
.PHONY: clean
78+
clean:
79+
rm -rf $(BUILD_DEST)
80+
@echo "Cleaned $(BUILD_DEST)"
7581

7682
.PHONY: build
77-
build: ## Build the project
78-
mkdir -p bin
79-
go build -o bin
83+
build: $(CMD)
84+
85+
.PHONY: $(CMD)
86+
$(CMD): %: $(BUILD_DEST)/%
87+
88+
$(BUILD_DEST)/%: cmd/%
89+
go build -o $@ ./cmd/$*
8090

8191
.PHONY: install
8292
install:

0 commit comments

Comments
 (0)