#!/usr/bin/make -f
# See debhelper(7) (uncomment to enable)
# output every command that modifies files on the build system.
#export DH_VERBOSE = 1


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

# 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

# Workaround gcc-13 bug.  See Gcc bug #110764[1].  FIXME: this is fixed in
# upcoming upstream build flags[2], so won't be necessary for long.
# [1]: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110764
# [2]: https://github.com/max0x7ba/atomic_queue/commit/c79be00ef12a5f3dc4294ba4954194a712a2853d
export DEB_CXXFLAGS_MAINT_APPEND  = -Wno-error=array-bounds


%:
	dh $@

override_dh_install:
	dh_install
	mv `find . -name "*.a"` `dirname $$(find . -name "*.so")`
	d-shlibmove --commit \
		    --multiarch \
		    --devunversioned \
		    --exclude-la \
		    --movedev include usr \
		    $$(find . -name "*.so")

# FIXME: No idea why  dh_strip  fails with
#strip: debian/libatomic-queue-dev/usr/lib/x86_64-linux-gnu/libatomic_queue.a: sorry: copying thin archives is not currently supported: invalid operation
#dh_strip: error: strip --strip-debug --remove-section=.comment --remove-section=.note --enable-deterministic-archives -R .gnu.lto_\* -R .gnu.debuglto_\* -N __gnu_lto_slim -N __gnu_lto_v1 debian/libatomic-queue-dev/usr/lib/x86_64-linux-gnu/libatomic_queue.a returned exit code 1
#dh_strip: error: Aborting due to earlier error
override_dh_strip:
	dh_strip || true

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	$(MAKE) example run_tests
endif
