#!/usr/bin/make -f

PROFILES_DIR = $(CURDIR)/profiles
ABSTRACTIONS_DIR = $(PROFILES_DIR)/abstractions
PROFILES = $(filter-out $(ABSTRACTIONS_DIR)%,$(wildcard $(PROFILES_DIR)/*))

%:
	dh $@

debian/apparmor-profiles-extra.install: $(PROFILES)
	$(CURDIR)/debian/scripts/generate-apparmor-profiles-extra.install > $@

override_dh_clean:
	rm -f debian/apparmor-profiles-extra.install
	dh_clean

override_dh_install: debian/apparmor-profiles-extra.install
	for profile in $(shell grep '^profiles/' $(CURDIR)/debian/apparmor-profiles-extra.install | \
	                 awk '{print $$1}' | \
	                 grep -v '^profiles/abstractions/' | \
	                 cut -d/ -f2- | grep -v /); do \
	   dh_apparmor --profile-name=$$profile -papparmor-profiles-extra; \
	done
	dh_install
