Skip to content

Commit e32775c

Browse files
committed
#1353 Document and fix indentation problem of conditionals in make
Problem is, if the body of a conditional is indented like: ``` ifeq (1,1) $(error SNAFU!) endif ``` and the indentation is done with tabs (spaces didn't produce the eror) then the script fails on macOS/FreeBSD because the indented line is interpreted as command. GNU Make on macOS/FreBSD is more strict about that than GNU Make on GNU/Linux system. The script fails with: > Makefile:8: *** commands commence before first target. Stop. This means that a command (with tab indented line) must be written after a recipe (target). The solution is to remove all indentation in conditional blocks. The solution to use spaces was discarded because it is errorprone to accidentally convert them to tabs and introduce a regression, even if the readability of such conditionals suffer. Signed-off-by: Sven Strittmatter <sven.strittmatter@iteratec.com>
1 parent 6a2626c commit e32775c

File tree

4 files changed

+42
-19
lines changed

4 files changed

+42
-19
lines changed

auto-discovery/kubernetes/Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ IMG ?= auto-discovery-kubernetes
1010
# Tag used for the image
1111
IMG_TAG ?= sha-$$(git rev-parse --short HEAD)
1212

13-
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
13+
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set).
14+
# IMPORTANT: The body of conditionals MUST not be indented! Indentation result in
15+
# errors on macOS/FreeBSD because the line wil be interpreted as command which must
16+
# inside a recipe (target). (see https://github.com/secureCodeBox/secureCodeBox/issues/1353)
1417
ifeq (,$(shell go env GOBIN))
1518
GOBIN=$(shell go env GOPATH)/bin
1619
else
@@ -115,8 +118,11 @@ helm-deploy:
115118
--set="image.tag=$(IMG_TAG)" \
116119
--set="image.pullPolicy=IfNotPresent" \
117120

121+
# IMPORTANT: The body of conditionals MUST not be indented! Indentation result in
122+
# errors on macOS/FreeBSD because the line wil be interpreted as command which must
123+
# inside a recipe (target). (see https://github.com/secureCodeBox/secureCodeBox/issues/1353)
118124
ifndef ignore-not-found
119-
ignore-not-found = false
125+
ignore-not-found = false
120126
endif
121127

122128
.PHONY: install

common.mk

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,41 @@
1818
# - helm
1919
# - yq
2020

21+
# IMPORTANT: The body of conditionals MUST not be indented! Indentation result in
22+
# errors on macOS/FreeBSD because the line wil be interpreted as command which must
23+
# inside a recipe (target). (see https://github.com/secureCodeBox/secureCodeBox/issues/1353)
2124
ifeq ($(include_guard),)
22-
$(error you should never run this makefile directly!)
25+
$(error you should never run this makefile directly!)
2326
endif
2427

28+
# IMPORTANT: The body of conditionals MUST not be indented! Indentation result in
29+
# errors on macOS/FreeBSD because the line wil be interpreted as command which must
30+
# inside a recipe (target). (see https://github.com/secureCodeBox/secureCodeBox/issues/1353)
2531
ifeq ($(name),)
26-
$(error name ENV is not set)
32+
$(error name ENV is not set)
2733
endif
2834

2935
PYTHON = $(shell which python3)
30-
36+
# IMPORTANT: The body of conditionals MUST not be indented! Indentation result in
37+
# errors on macOS/FreeBSD because the line wil be interpreted as command which must
38+
# inside a recipe (target). (see https://github.com/secureCodeBox/secureCodeBox/issues/1353)
39+
ifeq ($(PYTHON),)
40+
PYTHON = $(shell which python)
3141
ifeq ($(PYTHON),)
32-
PYTHON = $(shell which python)
33-
ifeq ($(PYTHON),)
34-
$(error "PYTHON=$(PYTHON) not found in $(PATH)")
35-
endif
42+
$(error "PYTHON=$(PYTHON) not found in $(PATH)")
43+
endif
3644
endif
3745

3846
PYTHON_VERSION_MIN=3.0
3947
PYTHON_VERSION=$(shell $(PYTHON) -c \
4048
'import sys; print(float(str(sys.version_info[0]) + "." + str(sys.version_info[1])))')
4149
PYTHON_VERSION_OK=$(shell $(PYTHON) -c 'print(int($(PYTHON_VERSION) >= $(PYTHON_VERSION_MIN)))' )
4250

51+
# IMPORTANT: The body of conditionals MUST not be indented! Indentation result in
52+
# errors on macOS/FreeBSD because the line wil be interpreted as command which must
53+
# inside a recipe (target). (see https://github.com/secureCodeBox/secureCodeBox/issues/1353)
4354
ifeq ($(PYTHON_VERSION_OK), 0) # True == 1
44-
$(error "Need python version >= $(PYTHON_VERSION_MIN) (current: $(PYTHON_VERSION))")
55+
$(error "Need python version >= $(PYTHON_VERSION_MIN) (current: $(PYTHON_VERSION))")
4556
endif
4657

4758
# Thx to https://stackoverflow.com/questions/5618615/check-if-a-program-exists-from-a-makefile

operator/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ LURKER_IMG ?= lurker
1919
IMG_TAG ?= sha-$$(git rev-parse --short HEAD)
2020

2121
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
22+
# IMPORTANT: The body of conditionals MUST not be indented! Indentation result in
23+
# errors on macOS/FreeBSD because the line wil be interpreted as command which must
24+
# inside a recipe (target). (see https://github.com/secureCodeBox/secureCodeBox/issues/1353)
2225
ifeq (,$(shell go env GOBIN))
2326
GOBIN=$(shell go env GOPATH)/bin
2427
else

scanners.mk

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,19 @@ PROJECT_DIR=../..
2828

2929
module = $(scanner-prefix)
3030

31+
# IMPORTANT: The body of conditionals MUST not be indented! Indentation result in
32+
# errors on macOS/FreeBSD because the line wil be interpreted as command which must
33+
# inside a recipe (target). (see https://github.com/secureCodeBox/secureCodeBox/issues/1353)
3134
ifeq ($(custom_scanner),)
32-
docker-build: | docker-build-parser
33-
docker-export: | docker-export-parser
34-
kind-import: | kind-import-parser
35-
deploy: deploy-without-scanner
35+
docker-build: | docker-build-parser
36+
docker-export: | docker-export-parser
37+
kind-import: | kind-import-parser
38+
deploy: deploy-without-scanner
3639
else
37-
docker-build: | docker-build-parser docker-build-scanner
38-
docker-export: | docker-export-parser docker-export-scanner
39-
kind-import: | kind-import-parser kind-import-scanner
40-
deploy: deploy-with-scanner
40+
docker-build: | docker-build-parser docker-build-scanner
41+
docker-export: | docker-export-parser docker-export-scanner
42+
kind-import: | kind-import-parser kind-import-scanner
43+
deploy: deploy-with-scanner
4144
endif
4245

4346
unit-tests:
@@ -86,4 +89,4 @@ deploy-with-scanner:
8689
integration-tests:
8790
@echo ".: 🩺 Starting integration test in kind namespace 'integration-tests'."
8891
kubectl -n integration-tests delete scans --all
89-
cd $(SCANNERS_DIR) && npm ci && cd $(scanner)/integration-tests && npm run test --yes --package jest@$(JEST_VERSION) $(scanner)/integration-tests
92+
cd $(SCANNERS_DIR) && npm ci && cd $(scanner)/integration-tests && npm run test --yes --package jest@$(JEST_VERSION) $(scanner)/integration-tests

0 commit comments

Comments
 (0)