#!/usr/bin/make -f

export DH_VERBOSE=1

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/default.mk

ifeq ($(DEB_HOST_ARCH),armhf)
  # Assume a Pi-like target, where using an 8-bit table is a fairly big win over the float path
  CPPFLAGS += -DSC16Q11_TABLE_BITS=8
endif

CONFIG_SWITCH =

ifneq ($(filter rtlsdr,$(DEB_BUILD_PROFILES)),)
	CONFIG_SWITCH += 'RTLSDR=yes'
	CONFIG_SWITCH += 'AIRCRAFT_HASH_BITS=15'
endif

ifneq ($(filter history,$(DEB_BUILD_PROFILES)),)
	CONFIG_SWITCH += 'HISTORY=yes'
endif

ifneq ($(filter native,$(DEB_BUILD_PROFILES)),)
	CONFIG_SWITCH += 'OPTIMIZE=-march=native'
endif

ifneq ($(filter plutosdr,$(DEB_BUILD_PROFILES)),)
        CONFIG_SWITCH += 'PLUTOSDR=yes'
endif

ifneq ($(filter biastee,$(DEB_BUILD_PROFILES)),)
        CONFIG_SWITCH += 'HAVE_BIASTEE=yes'
endif

override_dh_auto_build:
	make -j2 $(CONFIG_SWITCH)

override_dh_install:
	dh_install
	install -d debian/readsb/usr/bin
	cp -a readsb debian/readsb/usr/bin/readsb
	cp -a viewadsb debian/readsb/usr/bin/viewadsb

override_dh_installinit:
	dh_installinit --noscripts

override_dh_shlibdeps:
	dh_shlibdeps --dpkg-shlibdeps-params=--ignore-missing-info

%:
#	dh $@ --with=systemd
	dh $@
