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

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

# The IGTF installation bundle installs all profiles in one go,
# but we'll split them up in separate packages. All of the metadata
# goes to /usr/share/igtf-policy/<profile>. The config, postinst,
# templates, and prerm for the accredited profiles are so alike that
# they are generated in-line.

# the root of the installation tree.
BASE = /usr/share/igtf-policy

PROFILES = classic mics slcs iota

%:
	dh $@ 

override_dh_auto_configure:
	./configure --prefix=`pwd`/debian/tmp/$(BASE) \
	--with-profile=classic \
	--with-profile=slcs \
	--with-profile=mics \
	--with-profile=iota \
	--with-profile=unaccredited \
	--with-profile=experimental \
	--with-install="install -m 644"

override_dh_installdirs:
	cd debian && for profile in $(PROFILES); do \
	    cp dirs.in igtf-policy-$$profile.dirs ; \
	done
	dh_installdirs

override_dh_auto_install: profile_files
	for profile in $(PROFILES) unaccredited experimental; do \
	    mkdir -p debian/tmp/$(BASE)/$$profile ; \
	    mkdir -p debian/tmp/usr/share/ca-certificates/igtf-$$profile ; \
	    make install-$$profile prefix=`pwd`/debian/tmp/$(BASE)/$$profile ; \
	done

profile_files:
	po2debconf debian/templates.in > debian/templates-translated.in
	cd debian && for profile in $(PROFILES); do \
	    sed -e "s/@PROFILE@/$$profile/g" < config.in > igtf-policy-$$profile.config ; \
	    sed -e "s/@PROFILE@/$$profile/g" < postinst.in > igtf-policy-$$profile.postinst ; \
	    sed -e "s/@PROFILE@/$$profile/g" < prerm.in > igtf-policy-$$profile.prerm ; \
	    sed -e "s/@PROFILE@/$$profile/g" < templates-translated.in > igtf-policy-$$profile.templates ; \
	done
	cd debian && for profile in $(PROFILES) unaccredited experimental; do \
	    sed -e "s/@PROFILE@/$$profile/g" < install.in > igtf-policy-$$profile.install ; \
	    cp docs.in igtf-policy-$$profile.docs ; \
	done

# The .info files aren't GNU Info files
override_dh_installinfo:

override_dh_installchangelogs:
	dh_installchangelogs CHANGES
