#!/usr/bin/make -f

# See debhelper(7) (uncomment to enable).
# Output every command that modifies files on the build system.

# Detect architecture for ABI-specific fixes
include /usr/share/dpkg/architecture.mk

#export DH_VERBOSE = 1


# See FEATURE AREAS in dpkg-buildflags(1).
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# 1. Fix the "Unknown debugging section .debug_addr" by forcing DWARF 4
# 2. Fix potential "getVirtualFileRef" ABI mismatches on 32-bit ARM
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_CXXFLAGS_MAINT_APPEND = -gdwarf-4

ifeq ($(DEB_HOST_ARCH), armhf)
    export DEB_CFLAGS_MAINT_STRIP = -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
    export DEB_CXXFLAGS_MAINT_STRIP = -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
endif

# See ENVIRONMENT in dpkg-buildflags(1).
# Package maintainers to append CFLAGS.
#export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
# Package maintainers to append LDFLAGS.
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed


%:
	dh $@ --buildsystem=cmake


# dh_make generated override targets.
# This is an example for Cmake (see <https://bugs.debian.org/641051>).
#override_dh_auto_configure:
#	dh_auto_configure -- \
#	-DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH)

override_dh_auto_configure:
	dh_auto_configure -- \
		-DOIDN_APPS_OPENIMAGEIO=ON \
		-DISPC_EXECUTABLE=/usr/bin/ispc \
		-DCMAKE_BUILD_TYPE=Release

# If dwz still complains even with dwarf-4, we override it to do nothing
override_dh_dwz:
	dh_dwz || echo "dwz failed, but continuing anyway to bypass DWARF version issues"

override_dh_compress:
	dh_compress -X.pdf