#!/usr/bin/make -f

ifeq (,$(filter nodoc,$(DEB_BUILD_PROFILES)))
    DH_FLAGS += --with sphinxdoc
endif

ifndef PYBUILD_AUTOPKGTEST
ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
    NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
    TEST_FLAGS += --threads=$(NUMJOBS)
endif
export PYBUILD_BEFORE_TEST=ln -s {dir}/crazy-complete {build_dir}
else
export PYBUILD_BEFORE_TEST=ln -s /usr/bin/crazy-complete {build_dir}
endif

export PYBUILD_TEST_CUSTOM=1
export PYBUILD_TEST_ARGS=test/run.sh --driver=tmux $(TEST_FLAGS) || (diff -u test/tests/tests.yaml test/tests/tests.new.yaml; exit 1)
export PYBUILD_AFTER_TEST=rm {build_dir}/crazy-complete

%:
	dh $@ --with python3 --with shell_completions --buildsystem=pybuild $(DH_FLAGS)

execute_before_dh_installman:
ifeq (,$(filter nodoc,$(DEB_BUILD_PROFILES)))
	PYTHONPATH=. argparse-manpage \
		--description="Generate auto completion files for all major shells" \
		--author="Benjamin Abendroth" \
		--pyfile=crazy-complete \
		--object=p \
		> crazy-complete.1
endif

execute_before_dh_installdocs:
ifeq (,$(filter nodoc,$(DEB_BUILD_PROFILES)))
	PYTHONPATH=. python3 -m sphinx -N -bhtml docs/ build/html
endif
