.PHONY: help
.DEFAULT_GOAL := help

TARGET ?= 3scale-amp-2.13-rhel-7-candidate
GIT_BRANCH = $(shell git symbolic-ref --short HEAD)
BUILD_TYPE ?= local

COMPONENT = memcached
MAJOR ?= 1
MINOR ?= 4
PATCHLEVEL ?= 16
LOCAL_IMAGE_TAG = $(COMPONENT):$(MAJOR).$(MINOR).$(PATCHLEVEL)

MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
PROJECT_PATH := $(patsubst %/,%,$(dir $(MKFILE_PATH)))

build: ## build on Docker with BUILD_TYPE = [local (default)]
	docker build -t $(LOCAL_IMAGE_TAG) -f $(PROJECT_PATH)/Dockerfile $(PROJECT_PATH) --build-arg BUILD_TYPE=$(BUILD_TYPE)

test: ## build on OSBS w/ --scratch
	cd $(PROJECT_PATH) && rhpkg container-build --scratch --target=$(TARGET)

brew: ## build on OSBS
ifneq (,$(findstring private-,$(GIT_BRANCH)))
	$(error can't build from private branch $(GIT_BRANCH))
else
	cd $(PROJECT_PATH) && rhpkg container-build --target=$(TARGET)
endif

#Check http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
help: ## Print this help
	@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
