#!/usr/bin/make -f
# This file is PUBLIC DOMAIN. 

DEB_BUILD_GNU_CPU ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_CPU)
DEB_BUILD_GNU_SYSTEM ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_SYSTEM)
ifeq ($(DEB_BUILD_GNU_SYSTEM),linux)
DEB_BUILD_GNU_SYSTEM = linux-gnu
endif
DEB_BUILD_GNU_TYPE = $(DEB_BUILD_GNU_CPU)-$(DEB_BUILD_GNU_SYSTEM)

types := $(shell dpkg-architecture --help 2>&1 | grep "^Known GNU" | cut -d " " -f 6- | sed "s/, / /g")

cpus := $(shell echo $(types) | tr " " "\n" | cut -d "-" -f 1 | sort | uniq)
systems := $(shell echo $(types) | tr " " "\n" | cut -d "-" -f 2-  | sort | uniq)
systems := $(shell echo $(systems) linux-gnu | tr " " "\n" | grep -vx linux | sort | uniq)

not_cpus := $(shell echo $(cpus) | tr " " "\n" | grep -vx $(DEB_BUILD_GNU_CPU))
not_systems := $(shell echo $(systems) | tr " " "\n" | grep -vx $(DEB_BUILD_GNU_SYSTEM))

not_cpus := $(shell for cpu in $(not_cpus) ; do echo -n , not+$$cpu ; done)
not_systems := $(shell for system in $(not_systems) ; do echo -n , not+$$system ; done)

provides = $(DEB_BUILD_GNU_CPU), $(DEB_BUILD_GNU_SYSTEM), \
$(DEB_BUILD_GNU_TYPE)$(not_cpus)$(not_systems)

clean::
	cat debian/control.in \
		| sed "s%@provides@%$(provides)%g" \
		> debian/control

include /usr/share/cdbs/1/rules/debhelper.mk
