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

#export DH_VERBOSE=1
export PYBUILD_NAME=pydicom

# 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.
DEB_HOST_ARCH_ENDIAN ?= $(shell dpkg-architecture -qDEB_HOST_ARCH_ENDIAN)
ifeq ($(DEB_HOST_ARCH_ENDIAN),big)
export PYBUILD_TEST_PYTEST_ARGS := \
    --deselect=tests/pixels/test_utils.py::TestSetPixelData::test_grayscale_16bit_signed \
    --deselect=tests/test_waveform.py::TestHandlerGenerateMultiplex::test_as_raw \
    --deselect=tests/test_waveform.py::TestHandlerGenerateMultiplex::test_not_as_raw \
    --deselect=tests/test_waveform.py::TestHandlerMultiplexArray::test_as_raw \
    --deselect=tests/test_waveform.py::TestHandlerMultiplexArray::test_not_as_raw
endif

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
