Skip to content

Commit 4be12d7

Browse files
committed
makefile: utilities
Signed-off-by: CrazyMax <[email protected]>
1 parent 1b9bd75 commit 4be12d7

File tree

4 files changed

+42
-9
lines changed

4 files changed

+42
-9
lines changed

Makefile

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,63 +9,75 @@ help: ## show make targets
99

1010
.PHONY: clean-src
1111
clean-src:
12-
[ ! -d src ] || $(CHOWN) -R $(shell id -u):$(shell id -g) src
13-
$(RM) -r src
12+
@[ ! -d src ] || $(CHOWN) -R $(shell id -u):$(shell id -g) src
13+
@$(RM) -r src
1414

1515
.PHONY: src
1616
src: src/github.com/docker/cli src/github.com/docker/docker src/github.com/docker/buildx src/github.com/docker/compose src/github.com/docker/scan-cli-plugin ## clone source
1717

1818
ifdef CLI_DIR
1919
src/github.com/docker/cli:
20+
$(call title,Copying $(CLI_DIR))
2021
mkdir -p "$(@D)"
2122
cp -r "$(CLI_DIR)" $@
2223
else
2324
src/github.com/docker/cli:
25+
$(call title,Init $(DOCKER_CLI_REPO))
2426
git init $@
2527
git -C $@ remote add origin "$(DOCKER_CLI_REPO)"
2628
endif
2729

2830
ifdef ENGINE_DIR
2931
src/github.com/docker/docker:
32+
$(call title,Copying $(ENGINE_DIR))
3033
mkdir -p "$(@D)"
3134
cp -r "$(ENGINE_DIR)" $@
3235
else
3336
src/github.com/docker/docker:
37+
$(call title,Init $(DOCKER_ENGINE_REPO))
3438
git init $@
3539
git -C $@ remote add origin "$(DOCKER_ENGINE_REPO)"
3640
endif
3741

3842
src/github.com/docker/buildx:
43+
$(call title,Init $(DOCKER_BUILDX_REPO))
3944
git init $@
4045
git -C $@ remote add origin "$(DOCKER_BUILDX_REPO)"
4146

4247
src/github.com/docker/compose:
48+
$(call title,Init $(DOCKER_COMPOSE_REPO))
4349
git init $@
4450
git -C $@ remote add origin "$(DOCKER_COMPOSE_REPO)"
4551

4652
src/github.com/docker/scan-cli-plugin:
53+
$(call title,Init $(DOCKER_SCAN_REPO))
4754
git init $@
4855
git -C $@ remote add origin "$(DOCKER_SCAN_REPO)"
4956

5057

5158
.PHONY: checkout-cli
5259
checkout-cli: src/github.com/docker/cli
60+
$(call title,Checkout $(DOCKER_CLI_REPO)#$(DOCKER_CLI_REF))
5361
./scripts/checkout.sh src/github.com/docker/cli "$(DOCKER_CLI_REF)"
5462

5563
.PHONY: checkout-docker
5664
checkout-docker: src/github.com/docker/docker
65+
$(call title,Checkout $(DOCKER_ENGINE_REPO)#$(DOCKER_ENGINE_REF))
5766
./scripts/checkout.sh src/github.com/docker/docker "$(DOCKER_ENGINE_REF)"
5867

5968
.PHONY: checkout-buildx
6069
checkout-buildx: src/github.com/docker/buildx
70+
$(call title,Checkout $(DOCKER_BUILDX_REPO)#$(DOCKER_BUILDX_REF))
6171
./scripts/checkout.sh src/github.com/docker/buildx "$(DOCKER_BUILDX_REF)"
6272

6373
.PHONY: checkout-compose
6474
checkout-compose: src/github.com/docker/compose
75+
$(call title,Checkout $(DOCKER_COMPOSE_REPO)#$(DOCKER_COMPOSE_REF))
6576
./scripts/checkout.sh src/github.com/docker/compose "$(DOCKER_COMPOSE_REF)"
6677

6778
.PHONY: checkout-scan-cli-plugin
6879
checkout-scan-cli-plugin: src/github.com/docker/scan-cli-plugin
80+
$(call title,Checkout $(DOCKER_SCAN_REPO)#$(DOCKER_SCAN_REF))
6981
./scripts/checkout.sh src/github.com/docker/scan-cli-plugin "$(DOCKER_SCAN_REF)"
7082

7183
.PHONY: checkout

common.mk

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,20 @@ export DOCKER_ENGINE_REF
6363
export DOCKER_SCAN_REF
6464
export DOCKER_COMPOSE_REF
6565
export DOCKER_BUILDX_REF
66+
67+
# utilities
68+
BOLD := $(shell tput -T linux bold)
69+
RED := $(shell tput -T linux setaf 1)
70+
GREEN := $(shell tput -T linux setaf 2)
71+
YELLOW := $(shell tput -T linux setaf 3)
72+
BLUE := $(shell tput -T linux setaf 4)
73+
PURPLE := $(shell tput -T linux setaf 5)
74+
CYAN := $(shell tput -T linux setaf 6)
75+
76+
RESET := $(shell tput -T linux sgr0)
77+
TITLE := $(BOLD)$(YELLOW)
78+
SUCCESS := $(BOLD)$(GREEN)
79+
80+
define title
81+
@printf '$(TITLE)$(1)$(RESET)\n'
82+
endef

scripts/checkout.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# limitations under the License.
1616

1717
checkout() (
18-
set -ex
18+
set -e
1919
SRC="$1"
2020
REF="$2"
2121
REF_FETCH="$REF"
@@ -27,11 +27,13 @@ checkout() (
2727
else
2828
REF="FETCH_HEAD"
2929
fi
30-
git -C "$SRC" fetch --update-head-ok --depth 1 origin "$REF_FETCH"
31-
git -C "$SRC" checkout -q "$REF"
30+
(
31+
set -x
32+
git -C "$SRC" fetch --update-head-ok --depth 1 origin "$REF_FETCH"
33+
git -C "$SRC" checkout -q "$REF"
34+
)
3235
)
3336

34-
3537
# Only execute checkout function above if this file is executed, not sourced from another script
3638
prog=checkout.sh # needs to be in sync with this file's name
3739
if [ "$(basename -- $0)" = "$prog" ]; then

static/Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,21 @@ export CONTAINERD_VERSION
1717
export RUNC_VERSION
1818

1919
.PHONY: help
20-
help:
21-
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "$(BOLD)$(CYAN)%-25s$(RESET)%s\n", $$1, $$2}'
20+
help: ## show make targets
21+
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $$2);printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
2222

2323
.PHONY: clean
2424
clean: ## remove build artifacts
25+
$(call title,Removing build artifacts)
2526
@[ ! -d build ] || $(CHOWN) -R $(shell id -u):$(shell id -g) build
2627
@$(RM) -r build
2728

2829
.PHONY: build
2930
build: ## build static package
31+
$(call title,Building static package for $(TARGETPLATFORM))
3032
./build-static "$(CURDIR)" "$(TARGETPLATFORM)"
3133

3234
.PHONY: hash_files
3335
hash_files: ## hash files
34-
@echo "Hashing directory $(DIR_TO_HASH)"
36+
$(call title,Hashing directory $(DIR_TO_HASH))
3537
$(HASH_CMD) "$(DIR_TO_HASH)"

0 commit comments

Comments
 (0)