#!/usr/bin/make -f

DH_VERBOSE := 1
include /usr/share/dpkg/default.mk
export PYBUILD_DESTDIR=$(CURDIR)/debian/cwltool
export PYBUILD_AFTER_TEST=rm -Rf {build_dir}/tmp/ {build_dir}/main.cwl {build_dir}/output.txt*
export PYBUILD_TEST_ARGS=-k 'not (test_http_path_mapping or test_get_subgraph or test_udocker_usage_should_not_write_cid_file or test_udocker_should_display_memory_usage or test_content_types or test_get_step or test_udocker_nobanner)' $(DEB_BUILD_OPTION_PARALLEL:%=-n %) --ignore cwltool/schemas/ -rs --pyargs cwltool
# test_http_path_mapping requires internet access (could be mocked?)
# test_get_{subgraph,step} embedded local path isn't being cleaned properlyexport HOME=$(shell echo $$PWD"/fakehome")

%:
	dh $@ --buildsystem=pybuild

execute_after_dh_auto_build:
	PYTHONPATH=$(CURDIR)/cwltool $(MAKE) docs

debian/cwltool.1: debian/rules debian/cwltool.help2man
	export HOME=$(shell echo $$PWD"/fakehome") ; python3 setup.py develop --user ; \
	help2man --version-string $(DEB_VERSION_EPOCH_UPSTREAM) -I debian/cwltool.help2man -N \
		-o debian/cwltool.1  'python3 -m cwltool'
	sed -i 's/__main__.py/cwltool/g' debian/cwltool.1

ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
override_dh_installman: debian/cwltool.1
	dh_installman
else
override_dh_installman:
endif

execute_after_dh_auto_install:
	find debian -name '*.json' -exec chmod a-x {} \;
	find debian -name LICENSE.txt -delete
