@@ -21,6 +21,10 @@ SHELL := /bin/bash
21
21
# set in main Makefile of a repository.
22
22
# CMDS=
23
23
24
+ # Normally, commands are expected in "cmd". That can be changed for a
25
+ # repository to something else by setting CMDS_DIR before including build.make.
26
+ CMDS_DIR ?= cmd
27
+
24
28
# This is the default. It can be overridden in the main Makefile after
25
29
# including build.make.
26
30
REGISTRY_NAME? =quay.io/k8scsi
@@ -90,15 +94,15 @@ $(CMDS:%=build-%): build-%: check-go-version-go
90
94
if ! [ $${# os_arch_seen_pre} = $${#os_arch_seen} ]; then \
91
95
continue; \
92
96
fi; \
93
- if ! (set -x; CGO_ENABLED=0 GOOS="$$os" GOARCH="$$arch" go build $(GOFLAGS_VENDOR) -a -ldflags '$(FULL_LDFLAGS)' -o "./bin/$*$$suffix" ./cmd/$* ); then \
97
+ if ! (set -x; cd ./$(CMDS_DIR)/$* && CGO_ENABLED=0 GOOS="$$os" GOARCH="$$arch" go build $(GOFLAGS_VENDOR) -a -ldflags '$(FULL_LDFLAGS)' -o "$(abspath ./bin) /$*$$suffix" .); then \
94
98
echo "Building $* for GOOS=$$os GOARCH=$$arch failed, see error(s) above."; \
95
99
exit 1; \
96
100
fi; \
97
101
os_arch_seen+=";$$os-$$arch"; \
98
102
done
99
103
100
104
$(CMDS:% =container-%): container-%: build-%
101
- docker build -t $*:latest -f $(shell if [ -e ./cmd /$*/Dockerfile ]; then echo ./cmd /$*/Dockerfile; else echo Dockerfile; fi) --label revision=$(REV) .
105
+ docker build -t $*:latest -f $(shell if [ -e ./$(CMDS_DIR) /$*/Dockerfile ]; then echo ./$(CMDS_DIR) /$*/Dockerfile; else echo Dockerfile; fi) --label revision=$(REV) .
102
106
103
107
$(CMDS:% =push-%): push-%: container-%
104
108
set -ex; \
@@ -133,7 +137,7 @@ DOCKER_BUILDX_CREATE_ARGS ?=
133
137
# This target builds a multiarch image for one command using Moby BuildKit builder toolkit.
134
138
# Docker Buildx is included in Docker 19.03.
135
139
#
136
- # ./cmd /<command>/Dockerfile[.Windows] is used if found, otherwise Dockerfile[.Windows].
140
+ # ./$(CMDS_DIR) /<command>/Dockerfile[.Windows] is used if found, otherwise Dockerfile[.Windows].
137
141
# It is currently optional: if no such file exists, Windows images are not included,
138
142
# even when Windows is listed in BUILD_PLATFORMS. That way, projects can test that
139
143
# Windows binaries can be built before adding a Dockerfile for it.
@@ -146,8 +150,8 @@ $(CMDS:%=push-multiarch-%): push-multiarch-%: check-pull-base-ref build-%
146
150
export DOCKER_CLI_EXPERIMENTAL=enabled; \
147
151
docker buildx create $(DOCKER_BUILDX_CREATE_ARGS) --use --name multiarchimage-buildertest; \
148
152
trap "docker buildx rm multiarchimage-buildertest" EXIT; \
149
- dockerfile_linux=$$(if [ -e ./cmd /$*/Dockerfile ]; then echo ./cmd /$*/Dockerfile; else echo Dockerfile; fi); \
150
- dockerfile_windows=$$(if [ -e ./cmd /$*/Dockerfile.Windows ]; then echo ./cmd /$*/Dockerfile.Windows; else echo Dockerfile.Windows; fi); \
153
+ dockerfile_linux=$$(if [ -e ./$(CMDS_DIR) /$*/Dockerfile ]; then echo ./$(CMDS_DIR) /$*/Dockerfile; else echo Dockerfile; fi); \
154
+ dockerfile_windows=$$(if [ -e ./$(CMDS_DIR) /$*/Dockerfile.Windows ]; then echo ./$(CMDS_DIR) /$*/Dockerfile.Windows; else echo Dockerfile.Windows; fi); \
151
155
if [ '$(BUILD_PLATFORMS)' ]; then build_platforms='$(BUILD_PLATFORMS)'; else build_platforms="linux amd64"; fi; \
152
156
if ! [ -f "$$dockerfile_windows" ]; then \
153
157
build_platforms="$$(echo "$$build_platforms" | sed -e 's/windows *[^ ]* *.exe *[^ ]* *[^ ]*//g' -e 's/; *;/;/g' -e 's/;[ ]*$$//')"; \
0 commit comments