BASE_DIR         = $(shell pwd)
REBAR           ?= $(BASE_DIR)/rebar3
GIT_URL := $(shell git config --get remote.origin.url | sed -e 's/\(\/[^/]*\)$$//g')
GIT_URL := $(shell if [ "${GIT_URL}" = "file:/" ]; then echo 'ssh://git@git.onedata.org:7999/vfs'; else echo ${GIT_URL}; fi)
ONEDATA_GIT_URL := $(shell if [ "${ONEDATA_GIT_URL}" = "" ]; then echo ${GIT_URL}; else echo ${ONEDATA_GIT_URL}; fi)
export ONEDATA_GIT_URL

.PHONY: upgrade clean-link clean-all

all: compile

upgrade:
	$(REBAR) upgrade --all

deps:
	$(REBAR) get-deps
	make -C _build/default/lib/helpers submodules submodule=clproto

compile: deps
	$(REBAR) compile

clean:
	$(REBAR) clean


clean-link:
		rm -rf c_src/build priv/link

clean-all: clean-link
		rm -rf _build

##
## Dialyzer targets local
##

# Dialyzes the project.
dialyzer:
	$(REBAR) dialyzer

##
## Testing
##

eunit:
	$(REBAR) eunit skip_deps=true --suite=${SUITES}
## Rename all tests in order to remove duplicated names (add _(++i) suffix to each test)
	@for tout in `find test -name "TEST-*.xml"`; do awk '/testcase/{gsub("_[0-9]+\"", "_" ++i "\"")}1' $$tout > $$tout.tmp; mv $$tout.tmp $$tout; done

##
## Submodules
##

submodules:
	git submodule sync --recursive ${submodule}
	git submodule update --init --recursive ${submodule}

.PHONY: clang-format
clang-format:
	docker run --rm -v $(CURDIR):/root/sources onedata/clang-format-check:1.3

.PHONY: clang-tidy
clang-tidy:
	make -C c_src clang-tidy
