#
# Makefile for the security policy.
#
# Targets:
# 
# policy - compile the policy configuration.
# install - compile and install the policy configuration.
# load    - compile, install, and load the policy configuration.
#
# The default target is 'policy'.
#

# Set to y if MLS is enabled in the module.
MLS=n

BINDIR = /usr/local/selinux/bin
LOADPOLICY  = $(BINDIR)/load_policy
CHECKPOLICY = $(BINDIR)/checkpolicy

POLICYFILES = $(addprefix /usr/local/selinux/flask/,security_classes initial_sids access_vectors)
ifeq ($(MLS),y)
POLICYFILES += mls
endif
POLICYFILES += all.te rbac
POLICYFILES += users
POLICYFILES += constraints 
POLICYFILES += initial_sid_contexts fs_contexts devfs_contexts net_contexts

TESTPOLICYFILES = $(subst all.te,test_all.te,$(POLICYFILES))

policy:  policy.conf 
	$(CHECKPOLICY) -o $@ policy.conf

policy.conf: $(POLICYFILES)
	m4 -Imacros -s $^ > policy.conf

install: policy
	install -m 644 -o root -g root policy /ss_policy

load: install
	$(BINDIR)/load_policy /ss_policy

testpolicy:  testpolicy.conf 
	$(CHECKPOLICY) -o $@ testpolicy.conf

testinstall:  testpolicy
	install -m 644 -o root -g root testpolicy /ss_policy

testload:  testinstall
	$(BINDIR)/load_policy /ss_policy

testpolicy.conf: $(TESTPOLICYFILES)
	m4 -Imacros -s $^ > testpolicy.conf

test_all.te: macros/global_macros.te all_types.te all_domains.te test_domains.te
	cat $^ > $@
	rm -f all_types.te all_domains.te test_domains.te

all.te: macros/global_macros.te all_types.te all_domains.te assert.te
	cat $^ > $@
	rm -f all_types.te all_domains.te

all_types.te: $(wildcard types/*.te)
	cat $^ > $@

all_domains.te: $(wildcard domains/*.te domains/program/*.te)
	cat $^ > $@

test_domains.te: $(wildcard domains/test/*.te)
	cat $^ > $@

clean:
	rm -f policy policy.conf 
	rm -f all.te all_types.te all_domains.te test_domains.te
	rm -f test_all.te test_all_domains.te testpolicy testpolicy.conf

relabel:
	chcon system_u:object_r:policy_config_t /ss_policy
