#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
export DH_VERBOSE=1

# This has to be exported to make some magic below work.
export DH_OPTIONS

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
DEB_HOST_ARCH := $(shell dpkg-architecture -qDEB_HOST_ARCH)
DEB_BUILD_ARCH ?= $(shell dpkg-architecture -qDEB_BUILD_ARCH)

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
CUFLAGS = -O0
else
CUFLAGS = -O2 -fomit-frame-pointer -fpermissive
ifneq (,$(findstring i386,$(DEB_BUILD_ARCH)))
CUFLAGS = -O2 -fomit-frame-pointer -march=i686 -mmmx -msse -mno-sse2 -mno-sse3 -fpermissive -mfpmath=sse -mno-align-double
endif
ifneq (,$(findstring i486,$(DEB_BUILD_ARCH)))
CUFLAGS = -O2 -fomit-frame-pointer -march=i686 -mmmx -msse -mno-sse2 -mno-sse3 -fpermissive -mfpmath=sse -mno-align-double
endif
ifneq (,$(findstring amd64,$(DEB_BUILD_ARCH)))
CUFLAGS = -O2 -fomit-frame-pointer -mmmx -msse -msse2 -fpermissive -mfpmath=sse -mno-align-double
endif
endif
export CFLAGS=$(CUFLAGS)
export CXXFLAGS=$(CUFLAGS)
export DEB_CFLAGS_MAINT_APPEND = $(CUFLAGS)
export DEB_CXXFLAGS_MAINT_APPEND = $(CUFLAGS)

export DEB_BUILD_MAINT_OPTIONS = hardening=+fortify,+stackprotector,+relro,+bindnow,-pie
# older bz comprension
export DEB_DH_BUILDDEB_ARGS = -- -Zbzip2
# avoid useless dependencies
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed


SPATIALINDEX_VERSION = $(shell dpkg-parsechangelog | sed -ne 's/^Version: \(.*\)-.*/\1/p' | sed -e 's/\+.*//; s/^[0-9]://')

%:
	dh $@ --with autoreconf

override_dh_install:
	$(RM) $(CURDIR)/debian/tmp/usr/lib/*/*.la

	dh_install --list-missing

override_dh_makeshlibs:
	dh_makeshlibs -- -c0 -v$(SPATIALINDEX_VERSION)

override_dh_strip:
	dh_strip --dbg-package=libspatialindex4-dbg

