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

#export DH_VERBOSE=1
export PYBUILD_NAME=pydicom

export PYBUILD_AFTER_INSTALL=rm -fr {destdir}/usr/lib/python3*/dist-packages/${PYBUILD_NAME}/data/charset_files/FileInfo.txt; \
                     find {destdir}/usr/lib/python3*/dist-packages/${PYBUILD_NAME} -name 'README*' -delete

#for clean searchindex.js in doc package
#importend for reproducible builds
export PYTHONHASHSEED=0
export LC_ALL=C
export LANG=C

%:
	dh $@ --buildsystem=pybuild

execute_before_dh_sphinxdoc:
ifeq (,$(findstring nodoc, $(DEB_BUILD_PROFILES)))
	cd doc; PYTHONPATH=$(CURDIR)/src sphinx-build -j1 -N -b html . $(CURDIR)/debian/python-$(PYBUILD_NAME)-doc/usr/share/doc/python-$(PYBUILD_NAME)-doc/html
	find  $(CURDIR)/debian/python-$(PYBUILD_NAME)-doc/usr/share/doc/python-$(PYBUILD_NAME)-doc/html -type f -exec sed -i 's,$(CURDIR),,g' {} +
endif

# pydicom byte-order bugs on big-endian (s390x): set_pixel_data / pixel_array
# and waveform generate_multiplex/multiplex_array don't byte-swap, so the
# round-trip values are byte-swapped. Fine on little-endian -> deselect there
# only. Upstream fix should make this block removable.
execute_before_dh_auto_test:
	@if [ "$$(dpkg-architecture -qDEB_HOST_ARCH_ENDIAN)" = "big" ] && ! grep -q "test_grayscale_16bit_signed" pytest.ini; then \
	printf '\n    --deselect=tests/pixels/test_utils.py::TestSetPixelData::test_grayscale_16bit_signed\n' >> pytest.ini; \
	printf '    --deselect=tests/test_waveform.py::TestHandlerGenerateMultiplex::test_as_raw\n' >> pytest.ini; \
	printf '    --deselect=tests/test_waveform.py::TestHandlerGenerateMultiplex::test_not_as_raw\n' >> pytest.ini; \
	printf '    --deselect=tests/test_waveform.py::TestHandlerMultiplexArray::test_as_raw\n' >> pytest.ini; \
	printf '    --deselect=tests/test_waveform.py::TestHandlerMultiplexArray::test_not_as_raw\n' >> pytest.ini; \
	fi
