Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit dc6f43a

Browse files
Merge pull request #233 from mat007/fix-windows-make
Fix windows make
2 parents 913c753 + d83ffd1 commit dc6f43a

2 files changed

Lines changed: 28 additions & 25 deletions

File tree

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ coverage: coverage-test-unit coverage-test-e2e ## run tests with coverage
6060
go tool cover -html _build/cov/all.out -o _build/cov/coverage.html
6161

6262
clean: ## clean build artifacts
63-
$(call rm,bin)
64-
$(call rm,_build)
63+
$(call rmdir,bin)
64+
$(call rmdir,_build)
6565
$(call rm,docker-app-*.tar.gz)
6666

6767
vendor: ## update vendoring
68-
$(call rm,vendor)
68+
$(call rmdir,vendor)
6969
dep ensure -v
7070

7171
help: ## this help

vars.mk

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,37 @@ EXPERIMENTAL := off
88
# Comma-separated list of renderers
99
RENDERERS := "none"
1010

11-
TAG ?= $(shell git describe --always --dirty 2>/dev/null)
12-
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null)
13-
CWD = $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
14-
15-
# Used by ci-gradle-test target
16-
DOCKERAPP_BINARY ?= $(CWD)/bin/$(BIN_NAME)-linux
11+
# Failing to resolve sh.exe to a full path denotes a windows vanilla shell.
12+
# Although 'simple' commands are still exec'ed, 'complex' ones are batch'ed instead of sh'ed.
13+
ifeq ($(SHELL),sh.exe)
14+
mkdir = mkdir $(subst /,\,$(1)) > nul 2>&1 || (exit 0)
15+
rm = del /F /Q $(subst /,\,$(1)) > nul 2>&1 || (exit 0)
16+
rmdir = rmdir /S /Q $(subst /,\,$(1)) > nul 2>&1 || (exit 0)
17+
chmod =
18+
BUILDTIME ?= unknown
19+
NULL := nul
20+
else
21+
# The no-op redirection forces make to shell out the commands instead of spawning a process as
22+
# the latter can fail on windows running cmd or powershell while having a unix style shell in the path.
23+
mkdir = mkdir -p $(1) 1>&1
24+
rm = rm -rf $(1) 1>&1
25+
rmdir = rm -rf $(1) 1>&1
26+
chmod = chmod $(1) $(2) 1>&1
27+
NULL := /dev/null
28+
endif
1729

18-
WINDOWS := no
19-
ifneq ($(filter cmd.exe powershell.exe,$(subst /, ,$(SHELL))),)
20-
WINDOWS := yes
21-
BUILDTIME := unknown
30+
ifeq ($(TAG),)
31+
TAG := $(shell git describe --always --dirty 2> $(NULL))
32+
endif
33+
ifeq ($(COMMIT),)
34+
COMMIT := $(shell git rev-parse --short HEAD 2> $(NULL))
2235
endif
2336

2437
ifeq ($(BUILDTIME),)
25-
BUILDTIME := ${shell date --utc --rfc-3339 ns 2> /dev/null | sed -e 's/ /T/'}
38+
BUILDTIME := $(shell date --utc --rfc-3339 ns 2> /dev/null | sed -e 's/ /T/')
2639
endif
2740
ifeq ($(BUILDTIME),)
28-
BUILDTIME := ${shell gdate --utc --rfc-3339 ns 2> /dev/null | sed -e 's/ /T/'}
41+
BUILDTIME := $(shell gdate --utc --rfc-3339 ns 2> /dev/null | sed -e 's/ /T/')
2942
endif
3043
ifeq ($(BUILDTIME),)
3144
$(error unable to set BUILDTIME, ensure that you have GNU date installed or set manually)
@@ -38,16 +51,6 @@ LDFLAGS := "-s -w \
3851
-X $(PKG_NAME)/internal.Renderers=$(RENDERERS) \
3952
-X $(PKG_NAME)/internal.BuildTime=$(BUILDTIME)"
4053

41-
ifeq ($(WINDOWS),yes)
42-
mkdir = mkdir $(subst /,\,$(1)) > nul 2>&1 || (exit 0)
43-
rm = del /S /Q $(subst /,\,$(1)) > nul 2>&1 || (exit 0)
44-
chmod =
45-
else
46-
mkdir = mkdir -p $(1)
47-
rm = rm -rf $(1)
48-
chmod = chmod $(1) $(2)
49-
endif
50-
5154
EXEC_EXT :=
5255
ifeq ($(OS),Windows_NT)
5356
EXEC_EXT := .exe

0 commit comments

Comments
 (0)