#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

# Uncomment this to turn on verbose mode.
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 with_sdrs,$(DEB_BUILD_PROFILES)),)
	CONFIG_SWITCH += 'RTLSDR=yes'
	CONFIG_SWITCH += 'SOAPYSDR=yes'
	CONFIG_SWITCH += 'HACKRF=yes'
	CONFIG_SWITCH += 'BLADERF=yes'
	CONFIG_SWITCH += 'PLUTOSDR=yes'
endif

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

ifneq ($(filter soapysdr,$(DEB_BUILD_PROFILES)),)
	CONFIG_SWITCH += 'SOAPYSDR=yes'
endif

ifneq ($(filter hackrf,$(DEB_BUILD_PROFILES)),)
	CONFIG_SWITCH += 'HACKRF=yes'
endif

ifneq ($(filter bladerf,$(DEB_BUILD_PROFILES)),)
	CONFIG_SWITCH += 'BLADERF=yes'
endif

ifneq ($(filter plutosdr,$(DEB_BUILD_PROFILES)),)
	CONFIG_SWITCH += 'PLUTOSDR=yes'
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 biastee,$(DEB_BUILD_PROFILES)),)
        CONFIG_SWITCH += 'HAVE_BIASTEE=yes'
endif

override_dh_auto_build:
	make -j$(shell nproc) $(CONFIG_SWITCH)
	help2man -N --no-discard-stderr ./viewadsb > debian/viewadsb.1
	help2man -N --no-discard-stderr ./readsb > debian/readsb.1

override_dh_install:
	dh_install
	install -d debian/readsb/usr/bin
	cp -a readsb debian/readsb/usr/bin/readsb
	ln -s /usr/bin/readsb 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
