#!/usr/bin/make -f
# -*- makefile -*-

BUILD_DIR            = $(CURDIR)/ycm_build
GIT_URL              = https://github.com/Valloric/YouCompleteMe.git
DEB_SOURCE           = $(shell dpkg-parsechangelog | grep Source: | sed -e 's/Source: //')
DEB_VERSION          = $(shell dpkg-parsechangelog | grep Version: | sed -e 's/Version: //')
DEB_UPSTREAM_COMMIT  = $(shell echo $(DEB_VERSION) | sed -rn 's/.*git([^-]*).*/\1/p')
DEB_UPSTREAM_VERSION = $(shell echo $(DEB_VERSION) | sed -e 's/-[^-]*$$//')
DEB_INSTALL_DIR      = $(CURDIR)/debian/$(DEB_SOURCE)


%:
	dh $@ --with python3

override_dh_install:
	dh_install
	# No need to install tests
	$(RM) -rv $(DEB_INSTALL_DIR)/usr/share/vim-youcompleteme/python/ycm/tests \
              $(DEB_INSTALL_DIR)/usr/share/vim-youcompleteme/python/ycm/test_utils.py

override_dh_auto_test:
ifeq (,$(findstring nocheck,$(DEB_BUILD_OPTIONS)))
	flake8 --select=F,C9 --max-complexity=12 python
	PYTHONPATH=/usr/lib/ycmd:$(CURDIR)/third_party/retries nosetests3 -v --no-byte-compile python
endif

get-orig-source:
	TMPDIR=`mktemp -d -t`; \
	git clone $(GIT_URL) $$TMPDIR; \
	cd $$TMPDIR; git checkout $(DEB_UPSTREAM_COMMIT); \
	tar -czvf $(CURDIR)/vim-youcompleteme.orig.tar.gz .; \
	cd $(CURDIR); \
	dpt repack.sh --upstream-version $(DEB_UPSTREAM_VERSION) vim-youcompleteme.orig.tar.gz ; \
	$(RM) vim-youcompleteme.orig.tar.gz ; \
	$(RM) -r $$TMPDIR
