Chris PeBenito fb0a3a
########################################
Chris PeBenito fb0a3a
#
Chris PeBenito c38127
# Rules and Targets for building modular policies
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
ALL_MODULES := $(filter $(BASE_MODS) $(MOD_MODS),$(DETECTED_MODS))
Chris PeBenito fb0a3a
ALL_INTERFACES := $(ALL_MODULES:.te=.if)
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
BASE_PKG := base.pp
Chris PeBenito fb0a3a
BASE_FC := base.fc
Chris PeBenito fb0a3a
Chris PeBenito 4f9f30
BASE_SECTIONS := tmp/pre_te_files.conf tmp/generated_definitions.conf tmp/all_interfaces.conf tmp/all_attrs_types.conf $(GLOBALBOOL) $(GLOBALTUN) tmp/only_te_rules.conf tmp/all_post.conf
Chris PeBenito fb0a3a
Chris PeBenito a08248
BASE_PRE_TE_FILES := $(SECCLASS) $(ISIDS) $(AVS) $(M4SUPPORT) $(POLDIR)/mls $(POLDIR)/mcs
Chris PeBenito fb0a3a
BASE_TE_FILES := $(BASE_MODS)
Chris PeBenito 712566
BASE_POST_TE_FILES := $(POLDIR)/systemuser $(POLDIR)/constraints
Chris PeBenito fb0a3a
BASE_FC_FILES := $(BASE_MODS:.te=.fc)
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
MOD_MODULES := $(MOD_MODS:.te=.mod)
Chris PeBenito c04f2a
MOD_PKGS := $(notdir $(MOD_MODS:.te=.pp))
Chris PeBenito c04f2a
Chris PeBenito c04f2a
# search layer dirs for source files
Chris PeBenito c04f2a
vpath %.te $(ALL_LAYERS)
Chris PeBenito c04f2a
vpath %.if $(ALL_LAYERS)
Chris PeBenito c04f2a
vpath %.fc $(ALL_LAYERS)
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
########################################
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
# default action: create all module packages
Chris PeBenito fb0a3a
#
Chris PeBenito fedd3c
default: base
Chris PeBenito fb0a3a
Chris PeBenito 06a536
all: base modules
Chris PeBenito 06a536
Chris PeBenito fb0a3a
base: $(BASE_PKG)
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
modules: $(MOD_PKGS)
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
#policy: $(POLVER)
Chris PeBenito fb0a3a
#install: $(LOADPATH) $(FCPATH) $(APPFILES) $(USERPATH)/local.users
Chris PeBenito fb0a3a
#load: tmp/load
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
########################################
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
# Create a base module package
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
$(BASE_PKG): tmp/base.mod $(BASE_FC)
Chris PeBenito fb0a3a
	@echo "Creating $(NAME) base module package"
Chris PeBenito fb0a3a
	$(QUIET) $(SEMOD_PKG) $@ $^
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
########################################
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
# Compile a base module
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
tmp/base.mod: base.conf
Chris PeBenito fb0a3a
	@echo "Compiling $(NAME) base module"
Chris PeBenito fb0a3a
	$(QUIET) $(CHECKMODULE) $^ -o $@
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
########################################
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
# Construct a base module policy.conf
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
base.conf: $(BASE_SECTIONS)
Chris PeBenito fb0a3a
	@echo "Creating $(NAME) base module policy.conf"
Chris PeBenito fb0a3a
# checkpolicy can use the #line directives provided by -s for error reporting:
Chris PeBenito 0e15cd
	$(QUIET) m4 -D self_contained_policy $(M4PARAM) -s $^ > tmp/$@.tmp
Chris PeBenito fb0a3a
	$(QUIET) sed -e /^portcon/d -e /^nodecon/d -e /^netifcon/d < tmp/$@.tmp > $@
Chris PeBenito fb0a3a
# the ordering of these ocontexts matters:
Chris PeBenito fb0a3a
	$(QUIET) grep ^portcon tmp/$@.tmp >> $@ || true
Chris PeBenito fb0a3a
	$(QUIET) grep ^netifcon tmp/$@.tmp >> $@ || true
Chris PeBenito fb0a3a
	$(QUIET) grep ^nodecon tmp/$@.tmp >> $@ || true
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
tmp/pre_te_files.conf: $(BASE_PRE_TE_FILES)
Chris PeBenito fb0a3a
	@test -d tmp || mkdir -p tmp
Chris PeBenito fb0a3a
	$(QUIET) cat $^ > $@
Chris PeBenito fb0a3a
Chris PeBenito 28f032
tmp/generated_definitions.conf: $(ALL_LAYERS) $(BASE_TE_FILES)
Chris PeBenito fb0a3a
	@test -d tmp || mkdir -p tmp
Chris PeBenito c04f2a
# define all available object classes
Chris PeBenito c04f2a
	$(QUIET) $(GENPERM) $(AVS) $(SECCLASS) > $@
Chris PeBenito 71fe0f
# per-userdomain templates
Chris PeBenito 71fe0f
	$(QUIET) echo "define(\`per_userdomain_templates',\`" >> $@
Chris PeBenito 71fe0f
	$(QUIET) for i in $(patsubst %.te,%,$(notdir $(ALL_MODULES))); do \
Chris PeBenito 71fe0f
		echo "ifdef(\`""$$i""_per_userdomain_template',\`""$$i""_per_userdomain_template("'$$*'")')" \
Chris PeBenito 71fe0f
			>> $@ ;\
Chris PeBenito 71fe0f
	done
Chris PeBenito 71fe0f
	$(QUIET) echo "')" >> $@
Chris PeBenito fb0a3a
# define foo.te
Chris PeBenito 28f032
	$(QUIET) for i in $(notdir $(BASE_TE_FILES)); do \
Chris PeBenito fb0a3a
		echo "define(\`$$i')" >> $@ ;\
Chris PeBenito fb0a3a
	done
Chris PeBenito 4f9f30
	$(QUIET) $(SETTUN) $(BOOLEANS) >> $@
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
tmp/all_interfaces.conf: $(M4SUPPORT) $(ALL_INTERFACES)
Chris PeBenito fb0a3a
ifeq ($(ALL_INTERFACES),)
Chris PeBenito fb0a3a
	$(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf")
Chris PeBenito fb0a3a
endif
Chris PeBenito fb0a3a
	@test -d tmp || mkdir -p tmp
Chris PeBenito fb0a3a
	$(QUIET) m4 $^ | sed -e s/dollarsstar/\$$\*/g > $@
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
tmp/all_te_files.conf: $(BASE_TE_FILES)
Chris PeBenito fb0a3a
ifeq ($(BASE_TE_FILES),)
Chris PeBenito fb0a3a
	$(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf")
Chris PeBenito fb0a3a
endif
Chris PeBenito fb0a3a
	@test -d tmp || mkdir -p tmp
Chris PeBenito fb0a3a
	$(QUIET) cat $^ > $@
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
tmp/post_te_files.conf: $(BASE_POST_TE_FILES)
Chris PeBenito fb0a3a
	@test -d tmp || mkdir -p tmp
Chris PeBenito fb0a3a
	$(QUIET) cat $^ > $@
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
# extract attributes and put them first. extract post te stuff
Chris PeBenito fb0a3a
# like genfscon and put last.  portcon, nodecon, and netifcon
Chris PeBenito fb0a3a
# is delayed since they are generated by m4
Chris PeBenito fb0a3a
tmp/all_attrs_types.conf tmp/only_te_rules.conf tmp/all_post.conf: tmp/all_te_files.conf tmp/post_te_files.conf
Chris PeBenito fb0a3a
	$(QUIET) grep ^attribute tmp/all_te_files.conf > tmp/all_attrs_types.conf || true
Chris PeBenito fb0a3a
	$(QUIET) grep '^type ' tmp/all_te_files.conf >> tmp/all_attrs_types.conf
Chris PeBenito fb0a3a
	$(QUIET) cat tmp/post_te_files.conf > tmp/all_post.conf
Chris PeBenito fb0a3a
	$(QUIET) grep '^sid ' tmp/all_te_files.conf >> tmp/all_post.conf || true
Chris PeBenito fb0a3a
	$(QUIET) egrep '^fs_use_(xattr|task|trans)' tmp/all_te_files.conf >> tmp/all_post.conf || true
Chris PeBenito fb0a3a
	$(QUIET) grep ^genfscon tmp/all_te_files.conf >> tmp/all_post.conf || true
Chris PeBenito fb0a3a
	$(QUIET) sed -r -e /^attribute/d -e '/^type /d' -e /^genfscon/d \
Chris PeBenito fb0a3a
			-e '/^sid /d' -e '/^fs_use_(xattr|task|trans)/d' \
Chris PeBenito fb0a3a
			< tmp/all_te_files.conf > tmp/only_te_rules.conf
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
########################################
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
# Construct base module file contexts
Chris PeBenito fb0a3a
#
Chris PeBenito 712566
$(BASE_FC): $(M4SUPPORT) tmp/generated_definitions.conf $(BASE_FC_FILES) $(FCSORT)
Chris PeBenito fb0a3a
ifeq ($(BASE_FC_FILES),)
Chris PeBenito fb0a3a
	$(error No enabled modules! $(notdir $(MOD_CONF)) may need to be generated by using "make conf")
Chris PeBenito fb0a3a
endif
Chris PeBenito fb0a3a
	@echo "Creating $(NAME) base module file contexts."
Chris PeBenito fb0a3a
	@test -d tmp || mkdir -p tmp
Chris PeBenito fb0a3a
	$(QUIET) m4 $(M4PARAM) $(M4SUPPORT) tmp/generated_definitions.conf $(BASE_FC_FILES) > tmp/$@.tmp
Chris PeBenito fb0a3a
	$(QUIET) grep -e HOME -e ROLE tmp/$@.tmp > $(HOMEDIR_TEMPLATE)
Chris PeBenito fb0a3a
	$(QUIET) sed -i -e /HOME/d -e /ROLE/d tmp/$@.tmp
Chris PeBenito fb0a3a
	$(QUIET) $(FCSORT) tmp/$@.tmp $@
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
########################################
Chris PeBenito fb0a3a
#
Chris PeBenito c04f2a
# Build module packages
Chris PeBenito fb0a3a
#
Chris PeBenito c04f2a
tmp/%.mod: $(M4SUPPORT) tmp/generated_definitions.conf tmp/all_interfaces.conf %.te
Chris PeBenito 843132
	@if test -z "$(filter $^,$(MOD_MODS))"; then \
Chris PeBenito 843132
		echo "The $(notdir $(basename $@)) module is not configured to be compiled as a lodable module." ;\
Chris PeBenito 843132
		false ;\
Chris PeBenito 843132
	fi
Chris PeBenito c04f2a
	@echo "Compliling $(NAME) $(@F) module"
Chris PeBenito c04f2a
	$(QUIET) m4 $(M4PARAM) -s $^ > $(@:.mod=.tmp)
Chris PeBenito c04f2a
	$(QUIET) $(CHECKMODULE) -m $(@:.mod=.tmp) -o $@
Chris PeBenito fb0a3a
Chris PeBenito c04f2a
%.pp: tmp/%.mod %.fc
Chris PeBenito c04f2a
	@echo "Creating $(NAME) $(@F) policy package"
Chris PeBenito c04f2a
	$(QUIET) $(SEMOD_PKG) $@ $^
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
########################################
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
# Clean the sources
Chris PeBenito fb0a3a
#
Chris PeBenito fb0a3a
clean:
Chris PeBenito fb0a3a
	rm -fR tmp
Chris PeBenito fb0a3a
	rm -f base.conf
Chris PeBenito c04f2a
	rm -f *.pp
Chris PeBenito 712566
	rm -f $(BASE_FC)
Chris PeBenito fb0a3a
Chris PeBenito fb0a3a
.PHONY: default base modules clean