VOL-2057 Ensure Makefile variables set correctly when tools are missing

Change-Id: Ib861cb290293e1e082327627e967ebc1a0233eb5
diff --git a/Makefile b/Makefile
index d962531..e2bcb27 100644
--- a/Makefile
+++ b/Makefile
@@ -116,19 +116,39 @@
 
 lint: lint-style lint-sanity lint-dep
 
-GO_JUNIT_REPORT:=$(shell which go-junit-report)
-GOCOVER_COBERTURA:=$(shell which gocover-cobertura)
-test:
+# Rules to automatically install golangci-lint
+GOLANGCI_LINT_TOOL?=$(shell which golangci-lint)
+ifeq (,$(GOLANGCI_LINT_TOOL))
+GOLANGCI_LINT_TOOL=$(GOPATH)/bin/golangci-lint
+golangci_lint_tool_install:
+	# Same version as installed by Jenkins ci-management
+	# Note that install using `go get` is not recommended as per https://github.com/golangci/golangci-lint
+	curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(GOPATH)/bin v1.17.0
+else
+golangci_lint_tool_install:
+endif
+
+# Rules to automatically install go-junit-report
+GO_JUNIT_REPORT?=$(shell which go-junit-report)
 ifeq (,$(GO_JUNIT_REPORT))
+GO_JUNIT_REPORT=$(GOPATH)/bin/go-junit-report
+go_junit_install:
 	go get -u github.com/jstemmer/go-junit-report
-	@GO_JUNIT_REPORT=$(GOPATH)/bin/go-junit-report
+else
+go_junit_install:
 endif
 
+# Rules to automatically install gocover-covertura
+GOCOVER_COBERTURA?=$(shell which gocover-cobertura)
 ifeq (,$(GOCOVER_COBERTURA))
-	go get -u github.com/t-yuki/gocover-cobertura
 	@GOCOVER_COBERTURA=$(GOPATH)/bin/gocover-cobertura
+gocover_cobertura_install:
+	go get -u github.com/t-yuki/gocover-cobertura
+else
+gocover_cobertura_install:
 endif
 
+test: go_junit_install gocover_cobertura_install
 	@mkdir -p ./tests/results
 
 	@go test -v -coverprofile ./tests/results/go-test-coverage.out -covermode count ./... 2>&1 | tee ./tests/results/go-test-results.out ;\
@@ -138,20 +158,15 @@
 	exit $$RETURN
 
 GOLANGCI_LINT_TOOL:=$(shell which golangci-lint)
-sca:
-ifeq (,$(GOLANGCI_LINT_TOOL))
-	@echo "Please install golangci-lint tool to run sca"
-	exit 1
-endif
+sca: golangci_lint_tool_install
 	@mkdir -p ./sca-report
-	GO111MODULE=on golangci-lint run --out-format junit-xml ./... 2>&1 | tee ./sca-report/sca-report.xml ;\
-	RETURN=$$? ;\
-	exit $$RETURN
+	GO111MODULE=on golangci-lint run --out-format junit-xml ./... 2>&1 | tee ./sca-report/sca-report.xml
 
 clean:
 	rm -rf sca-report
 
 distclean: clean
 	rm -rf ${VENVDIR}
+	rm -rf ./sca_report
 
 # end file