#! /usr/bin/make -f
#
# 	Nicotine+
#	Copyright (C) 2016 Kip Warner. Released under the GPLv3 or later.
#

# Output every command that modifies files on the build system...
DH_VERBOSE = 1
export DH_OPTIONS=-v

# Set flags for how the package will be built. Note separated with white
#  space and not comma, as per DPM § 4.9.1...

    # Use as many CPUs as possible for pkgstripfiles which takes forever on
    #  all our PNGs...
    DEB_BUILD_OPTIONS +=parallel=0

    # The above should be reflected when dpkg-buildflags is called and merged
    #  with the defaults...
    export DEB_BUILD_OPTIONS
    export DPKG_EXPORT_BUILDFLAGS = 1

# Standard rules and preset shell variables...
include /usr/share/dpkg/default.mk

# Directory containing package since may not be called from current working
#  directory. MAKEFILE_LIST pre-defined by Make and appended each time another
#  makefile is included, so first one should be debian/rules...
PACKAGE_DIR = $(abspath $(dir $(firstword $(MAKEFILE_LIST))))

# Source directory...
SOURCE_DIR  = $(abspath $(PACKAGE_DIR)/../)

# Get the upstream version according to distutils. Distutils gets it from a variable
#  embedded directly in the Python source...
VERSION_UPSTREAM_DISTUTILS = $(shell sed -n 's/^version\s*=\s*"\(\S*\)"$$/\1/p' $(SOURCE_DIR)/pynicotine/utils.py)

# Catch all debhelper rule...
%:
	dh $@ --with python2 --buildsystem=pybuild

# Prepare an upstream vanilla distribution tarball as per DPM § 4.9...
#  http://wiki.debian.org/onlyjob/get-orig-source
get-orig-source: $(DEB_SOURCE)_$(DEB_VERSION_UPSTREAM).orig.tar.gz $(info I: $(DEB_SOURCE)_$(DEB_VERSION_UPSTREAM))
	@

# Prepare an upstream vanilla distribution tarball...
$(DEB_SOURCE)_$(DEB_VERSION_UPSTREAM).orig.tar.gz:
	@echo "# Preparing source for $(DEB_SOURCE) v$(DEB_VERSION_UPSTREAM)..."
	cd $(SOURCE_DIR) \
	&& python setup.py sdist --formats=gztar --dist-dir=../ \
	&& mv -v ../$(DEB_SOURCE)-$(VERSION_UPSTREAM_DISTUTILS).tar.gz ../$@

# Targets which aren't actually files...
.PHONY: get-orig-source
