#!/usr/bin/make -f
# -*- mode: makefile; coding: utf-8 -*-
# Copyright © 2018 IOhannes m zmölnig <zmoelnig@iem.at>
# Description: Main Debian packaging script for zexy
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

#enable hardening
export DEB_BUILD_MAINT_OPTIONS=hardening=+all

DATE_FMT = %Y/%m/%d at %H:%M:%S UTC
ifdef SOURCE_DATE_EPOCH
    BUILD_DATE ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "+$(DATE_FMT)"  2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" "+$(DATE_FMT)" 2>/dev/null || date -u "+$(DATE_FMT)")
else
    BUILD_DATE ?= $(shell date "+$(DATE_FMT)")
endif

%:
	dh $@

override_dh_auto_configure:
	dh_auto_configure -- \
		--libdir=/usr/lib/pd/extra/ \
		--with-extension=pd_linux \
		--with-build-date="on $(BUILD_DATE)" \
		$(empty)

override_dh_auto_install:
	dh_auto_install
	# we rather link to the debian provided GPL-2
	rm -f -- "$(CURDIR)"/debian/*/usr/lib/pd/extra/*/LICENSE.txt
	# remove libtools leftovers
	find "$(CURDIR)"/debian/*/usr/ -name "*.la" -delete || true
	find "$(CURDIR)"/debian/*/usr/lib/pd/extra -type f -exec chmod -x {} +

licensecheck:
	licensecheck --deb-machine -r . \
		> debian/copyright_newhints
	cmp debian/copyright_hints debian/copyright_newhints \
		&& rm debian/copyright_newhints
