#!/usr/bin/make -f

export DH_VERBOSE=1

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
include /usr/share/dpkg/architecture.mk
ifeq ($(origin CC),default)
    CC = $(DEB_HOST_GNU_TYPE)-gcc
endif

ifeq ($(DEB_HOST_ARCH),$(filter $(DEB_HOST_ARCH),amd64 i386))
        CFLAGS += -mtune=generic -msse3
endif
ifeq ($(DEB_HOST_ARCH_OS), kfreebsd)
        CFLAGS += -D KFREEBSD
endif

%:
	dh $@ --buildsystem=makefile

override_dh_auto_clean:
	dh_auto_clean
	rm -f test/subread-align/data/test-err-mut-r1.fq.gz test/subread-align/data/test-err-mut-r2.fq.gz
	rm -rf bin src/longread-one/make.version
	find . -name "*.o" -delete
	dh_auto_clean --sourcedirectory=src -- -f Makefile.Linux

override_dh_auto_build:
	dh_auto_build --sourcedirectory=src -- -f Makefile.Linux CC=$(CC) ; \

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	debian/tests/subread-tests $(CURDIR)
endif

override_dh_auto_install:
#fix for gzip-file-is-not-multi-arch-same-safe
	cp annotation/mm39_RefSeq_exon.txt.gz debian/mm39_RefSeq_exon.txt.gz.orig
	find $(CURDIR) -name "*.gz" -exec bash -c 'name="{}"; gzip -d "{}"; gzip -n "$${name%.*}"' \;
	dh_auto_install
	mv debian/mm39_RefSeq_exon.txt.gz.orig annotation/mm39_RefSeq_exon.txt.gz

override_dh_installexamples-indep:
	tar --sort=name \
            --mtime="@${SOURCE_DATE_EPOCH}" \
            --owner=root --group=root --numeric-owner \
            --mode=go=rX,u+rw,a-s \
            -cJf $(CURDIR)/debian/subread-data/usr/share/doc/subread/examples/test.tar.xz  test/
