#!/usr/bin/make -f

# DH_VERBOSE := 1
export LC_ALL=C.UTF-8

CLANG_SKIP=i386 alpha hppa ia64 m68k sh4 x32
# i386 is due to https://github.com/simd-everywhere/simde/issues/683
# ppc64 is due to https://github.com/simd-everywhere/simde/issues/185

include /usr/share/dpkg/default.mk
export DEB_BUILD_MAINT_OPTIONS=hardening=+all

ifneq (,$(filter $(DEB_BUILD_ARCH),armel))
  export DEB_LDFLAGS_MAINT_APPEND=-latomic
endif

%:
	dh $@ --buildsystem=meson+ninja

override_dh_auto_configure:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
  ifeq (,$(filter $(DEB_HOST_ARCH),$(CLANG_SKIP)))
	CC=clang CXX=clang++ dh_auto_configure --builddirectory=clang_test
  endif
# According to https://wiki.debian.org/ArchitectureSpecificsMemo#Architecture_baselines
# It is odd that gcc doesn't include this automatically, but clang does
ifneq (,$(filter $(DEB_BUILD_ARCH),ppc64))
  export DEB_CFLAGS_MAINT_APPEND+=-maltivec
  export DEB_CXXFLAGS_MAINT_APPEND+=-maltivec
endif
	CC=gcc-10 CXX=g++-10 dh_auto_configure --builddirectory=gcc_test
endif

override_dh_auto_build:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	dh_auto_build --builddirectory=gcc_test
  ifeq (,$(filter $(DEB_HOST_ARCH),$(CLANG_SKIP)))
	dh_auto_build --builddirectory=clang_test
  endif
endif

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	dh_auto_test --builddirectory=gcc_test
  ifeq (,$(filter $(DEB_HOST_ARCH),$(CLANG_SKIP)))
	dh_auto_test --builddirectory=clang_test
  endif
endif

override_dh_auto_clean:
	dh_auto_clean --builddirectory=gcc_test
ifeq (,$(filter $(DEB_HOST_ARCH),$(CLANG_SKIP)))
	dh_auto_clean --builddirectory=clang_test
endif

override_dh_auto_install:
	echo This is a header-only library, no need to install any binaries
