#!/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

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

export DPKG_GENSYMBOLS_CHECK_LEVEL=4

include /usr/share/dpkg/default.mk

distro=$(shell lsb_release -c -s)

ifeq ($(distro),vivid)
	full_version=$(shell cat $(CURDIR)/debian/VERSION.vivid)
else
	full_version=$(shell cat $(CURDIR)/debian/VERSION)
endif

major=$(shell echo $(full_version) | cut -d'.' -f1)
minor=$(shell echo $(full_version) | cut -d'.' -f2)
patch=$(shell echo $(full_version) | cut -d'.' -f3)

ifneq (,$(filter $(DEB_HOST_ARCH),ppc64el powerpc arm64))
        LOCATION_SERVICE_ENABLE_GPS_PROVIDER = OFF
else
        LOCATION_SERVICE_ENABLE_GPS_PROVIDER = ON
endif

%:
	dh $@ --parallel --fail-missing

override_dh_install:
	dh_install -Xubuntu-location-service.1 --fail-missing

override_dh_strip:
	dh_strip --dbg-package=libubuntu-location-service-dbg

override_dh_auto_configure:
	dh_auto_configure -- -DCMAKE_INSTALL_LIBEXECDIR=/usr/lib/$(DEB_HOST_MULTIARCH)/ubuntu-location-service -DCMAKE_C_COMPILER=$(CC) -DCMAKE_CXX_COMPILER=$(CXX) -DLOCATION_SERVICE_ENABLE_GPS_PROVIDER=$(LOCATION_SERVICE_ENABLE_GPS_PROVIDER) -DUBUNTU_LOCATION_SERVICE_VERSION_MAJOR=$(major) -DUBUNTU_LOCATION_SERVICE_VERSION_MINOR=$(minor) -DUBUNTU_LOCATION_SERVICE_VERSION_PATCH=$(patch)

override_dh_auto_clean:
	rm -f $(CURDIR)/debian/libubuntu-location-service$(major).install.amd64
	rm -f $(CURDIR)/debian/libubuntu-location-service$(major).install.armhf
	rm -f $(CURDIR)/debian/libubuntu-location-service$(major).install.i386
	/bin/sh $(CURDIR)/debian/gen-debian-files.sh $(CURDIR)/debian
	dh_auto_clean
