###############################################################################
# Licensed Materials - Property of IBM Copyright IBM Corporation 2017, 2019. All Rights Reserved.
# Copyright (c) 2020 Red Hat, Inc.
# U.S. Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP
# Schedule Contract with IBM Corp.
#
# Contributors:
#  IBM Corporation - initial API and implementation
###############################################################################

include build-tools/Configfile

ifeq ($(ARCH), x86_64)
ETCD_ARCH = amd64
else
ETCD_ARCH = $(ARCH)
endif

USE_VENDORIZED_BUILD_HARNESS ?=

ifndef USE_VENDORIZED_BUILD_HARNESS
-include $(shell curl -s -H 'Authorization: token ${GITHUB_TOKEN}' -H 'Accept: application/vnd.github.v4.raw' -L https://api.github.com/repos/open-cluster-management/build-harness-extensions/contents/templates/Makefile.build-harness-bootstrap -o .build-harness-bootstrap; echo .build-harness-bootstrap)
else
-include vbh/.build-harness-bootstrap
endif

default::
	@echo "Build Harness Bootstrapped"

deps:
	go get golang.org/x/lint/golint
	go get -u github.com/apg/patter
	go get -u github.com/wadey/gocovmerge
	go get -u github.com/alecthomas/gometalinter
	gometalinter --install
	curl -L https://github.com/etcd-io/etcd/releases/download/v3.3.18/etcd-v3.3.18-linux-amd64.tar.gz -o ../../../../bin/etcd-v3.3.18-linux-amd64.tar.gz
	tar xzvf ../../../../bin/etcd-v3.3.18-linux-amd64.tar.gz -C ../../../../bin --strip-components=1
	rm -f ../../../../bin/etcd-v3.3.18-linux-amd64.tar.gz
	curl -O https://storage.googleapis.com/kubernetes-release/release/v1.10.3/bin/linux/amd64/kube-apiserver
	chmod a+x kube-apiserver &&	mv kube-apiserver ${GOPATH}/bin
	go get -u github.com/golang/dep/cmd/dep
	dep ensure -v

gocompile:
	build-tools/build-all.sh

propagator:
	build-tools/build-propagator.sh

clean::
	rm -rf _build/

clean-test:
	-@rm -rf test-output
	-@rm -f cover.*

copyright-check:
	./build-tools/copyright-check.sh $(TRAVIS_BRANCH)

lint: 
	golint -set_exit_status=true pkg/

fmt:
	gofmt -l ${GOFILES}

vet:
	gometalinter  --deadline=1000s --disable-all --enable=vet --enable=vetshadow --enable=ineffassign --enable=goconst --tests  --vendor ./...

lintall: fmt lint vet

.PHONY: test
test:
ifneq ($(ARCH), s390x)
	@./build-tools/test.sh
endif

coverage:
	go tool cover -html=cover.out -o=cover.html
	@./build-tools/calculate-coverage.sh
