Chris PeBenito 885b83
Chris PeBenito 794a56
# helper tools
Chris PeBenito 794a56
AWK ?= gawk
Chris PeBenito 794a56
INSTALL ?= install
Chris PeBenito 794a56
M4 ?= m4
Chris PeBenito 794a56
SED ?= sed
Chris PeBenito 794a56
EINFO ?= echo
Chris PeBenito 794a56
PYTHON ?= python
Chris PeBenito 794a56
Chris PeBenito 794a56
NAME ?= $(shell $(AWK) -F= '/^SELINUXTYPE/{ print $$2 }' /etc/selinux/config)
Chris PeBenito 794a56
SHAREDIR ?= /usr/share/selinux
Chris PeBenito 794a56
HEADERDIR ?= $(SHAREDIR)/$(NAME)/include
Chris PeBenito 794a56
Chris PeBenito 885b83
include $(HEADERDIR)/build.conf
Chris PeBenito 885b83
Chris PeBenito 885b83
# executables
Chris PeBenito 885b83
PREFIX := /usr
Chris PeBenito 885b83
BINDIR := $(PREFIX)/bin
Chris PeBenito 885b83
SBINDIR := $(PREFIX)/sbin
Chris PeBenito 885b83
CHECKMODULE := $(BINDIR)/checkmodule
Chris PeBenito 885b83
SEMODULE := $(SBINDIR)/semodule
Chris PeBenito 885b83
SEMOD_PKG := $(BINDIR)/semodule_package
Chris PeBenito 885b83
XMLLINT := $(BINDIR)/xmllint
Chris PeBenito 885b83
Chris PeBenito 885b83
# set default build options if missing
Chris PeBenito 885b83
TYPE ?= strict
Chris PeBenito 885b83
DIRECT_INITRC ?= n
Chris PeBenito 885b83
POLY ?= n
Chris PeBenito 885b83
QUIET ?= y
Chris PeBenito 885b83
Chris PeBenito 885b83
genxml := $(PYTHON) $(HEADERDIR)/support/segenxml.py
Chris PeBenito 885b83
Chris PeBenito 885b83
docs = doc
Chris PeBenito 885b83
polxml = $(docs)/policy.xml
Chris PeBenito 885b83
xmldtd = $(HEADERDIR)/support/policy.dtd
Chris PeBenito 885b83
layerxml = metadata.xml
Chris PeBenito 885b83
Chris PeBenito 885b83
globaltun = $(HEADERDIR)/global_tunables.xml
Chris PeBenito 885b83
globalbool = $(HEADERDIR)/global_booleans.xml
Chris PeBenito 885b83
Chris PeBenito 885b83
# compile strict policy if requested.
Chris PeBenito 885b83
ifneq ($(findstring strict,$(TYPE)),)
Chris PeBenito 885b83
	M4PARAM += -D strict_policy
Chris PeBenito 885b83
endif
Chris PeBenito 885b83
Chris PeBenito 885b83
# compile targeted policy if requested.
Chris PeBenito 885b83
ifneq ($(findstring targeted,$(TYPE)),)
Chris PeBenito 885b83
	M4PARAM += -D targeted_policy
Chris PeBenito 885b83
endif
Chris PeBenito 885b83
Chris PeBenito 885b83
# enable MLS if requested.
Chris PeBenito 885b83
ifneq ($(findstring -mls,$(TYPE)),)
Chris PeBenito 885b83
	M4PARAM += -D enable_mls
Chris PeBenito 885b83
	CHECKPOLICY += -M
Chris PeBenito 885b83
	CHECKMODULE += -M
Chris PeBenito 885b83
endif
Chris PeBenito 885b83
Chris PeBenito 885b83
# enable MLS if MCS requested.
Chris PeBenito 885b83
ifneq ($(findstring -mcs,$(TYPE)),)
Chris PeBenito 885b83
	M4PARAM += -D enable_mcs
Chris PeBenito 885b83
	CHECKPOLICY += -M
Chris PeBenito 885b83
	CHECKMODULE += -M
Chris PeBenito 885b83
endif
Chris PeBenito 885b83
Chris PeBenito 885b83
# enable distribution-specific policy
Chris PeBenito 885b83
ifneq ($(DISTRO),)
Chris PeBenito 885b83
	M4PARAM += -D distro_$(DISTRO)
Chris PeBenito 885b83
endif
Chris PeBenito 885b83
Chris PeBenito 885b83
# enable polyinstantiation
Chris PeBenito 885b83
ifeq ($(POLY),y)
Chris PeBenito 885b83
	M4PARAM += -D enable_polyinstantiation
Chris PeBenito 885b83
endif
Chris PeBenito 885b83
Chris PeBenito 885b83
ifeq ($(DIRECT_INITRC),y)
Chris PeBenito 885b83
	M4PARAM += -D direct_sysadm_daemon
Chris PeBenito 885b83
endif
Chris PeBenito 885b83
Chris PeBenito 885b83
ifeq ($(QUIET),y)
Chris PeBenito 885b83
	verbose := @
Chris PeBenito 885b83
endif
Chris PeBenito 885b83
Chris PeBenito 885b83
M4PARAM += -D hide_broken_symptoms
Chris PeBenito 885b83
Chris PeBenito 885b83
# policy headers
Chris PeBenito 885b83
m4support = $(wildcard $(HEADERDIR)/support/*.spt)
Chris PeBenito 885b83
all_layers = $(filter-out $(HEADERDIR)/support,$(shell find $(wildcard $(HEADERDIR)/*) -maxdepth 0 -type d))
Chris PeBenito 885b83
all_interfaces = $(foreach layer,$(all_layers),$(wildcard $(layer)/*.if))
Chris PeBenito 885b83
rolemap = $(HEADERDIR)/rolemap
Chris PeBenito 885b83
Chris PeBenito 885b83
detected_layers =  $(filter-out CVS tmp $(docs),$(shell find $(wildcard *) -maxdepth 0 -type d))
Chris PeBenito 885b83
3rd_party_mods = $(wildcard *.te)
Chris PeBenito 885b83
detected_mods = $(3rd_party_mods) $(foreach layer,$(detected_layers),$(wildcard $(layer)/*.te))
Chris PeBenito 0578bf
detected_ifs = $(detected_mods:.te=.if)
Chris PeBenito 0578bf
detected_fcs = $(detected_mods:.te=.fc)
Chris PeBenito ad8af2
all_packages = $(notdir $(detected_mods:.te=.pp))
Chris PeBenito ad8af2
Chris PeBenito ad8af2
vpath %.te $(detected_layers)
Chris PeBenito ad8af2
vpath %.if $(detected_layers)
Chris PeBenito ad8af2
vpath %.fc $(detected_layers)
Chris PeBenito 885b83
Chris PeBenito 885b83
# if there are modules in the current directory, add them into the third party layer
Chris PeBenito 0578bf
ifneq "$(3rd_party_mods)" ""
Chris PeBenito 885b83
        genxml += -3 .
Chris PeBenito 885b83
endif
Chris PeBenito 885b83
Chris PeBenito 885b83
########################################
Chris PeBenito 885b83
#
Chris PeBenito 885b83
# Functions
Chris PeBenito 885b83
#
Chris PeBenito 885b83
Chris PeBenito 885b83
# parse-rolemap modulename,outputfile
Chris PeBenito 885b83
define parse-rolemap
Chris PeBenito 885b83
	$(verbose) $(M4) $(M4PARAM) $(rolemap) | \
Chris PeBenito 885b83
		$(AWK) '/^[[:blank:]]*[A-Za-z]/{ print "gen_require(type " $$3 "; role " $$1 ";)\n$1_per_userdomain_template(" $$2 "," $$3 "," $$1 ")" }' >> $2
Chris PeBenito 885b83
endef
Chris PeBenito 885b83
Chris PeBenito 885b83
# peruser-expansion modulename,outputfile
Chris PeBenito 885b83
define peruser-expansion
Chris PeBenito 885b83
	$(verbose) echo "ifdef(\`""$1""_per_userdomain_template',\`" > $2
Chris PeBenito 885b83
	$(call parse-rolemap,$1,$2)
Chris PeBenito 885b83
	$(verbose) echo "')" >> $2
Chris PeBenito 885b83
endef
Chris PeBenito 885b83
Chris PeBenito 885b83
.PHONY: clean all xml
Chris PeBenito 885b83
.SUFFIXES:
Chris PeBenito 885b83
.SUFFIXES: .pp
Chris PeBenito 0578bf
.SECONDARY:
Chris PeBenito 885b83
Chris PeBenito 885b83
########################################
Chris PeBenito 885b83
#
Chris PeBenito 885b83
# Main targets
Chris PeBenito 885b83
#
Chris PeBenito 885b83
Chris PeBenito 885b83
all: $(all_packages)
Chris PeBenito 885b83
Chris PeBenito 885b83
xml: $(polxml)
Chris PeBenito 885b83
Chris PeBenito 885b83
########################################
Chris PeBenito 885b83
#
Chris PeBenito 885b83
# Build module packages
Chris PeBenito 885b83
#
Chris PeBenito 885b83
tmp/%.mod: $(m4support) tmp/all_interfaces.conf %.te
Chris PeBenito 0578bf
	@$(EINFO) "Compiling $(NAME) $(basename $(@F)) module"
Chris PeBenito 885b83
	@test -d tmp || mkdir -p tmp
Chris PeBenito 885b83
	$(call peruser-expansion,$(basename $(@F)),$@.role)
Chris PeBenito 885b83
	$(verbose) $(M4) $(M4PARAM) -s $^ $@.role > $(@:.mod=.tmp)
Chris PeBenito 885b83
	$(verbose) $(CHECKMODULE) -m $(@:.mod=.tmp) -o $@
Chris PeBenito 885b83
Chris PeBenito 885b83
tmp/%.mod.fc: $(m4support) %.fc
Chris PeBenito 885b83
	$(verbose) $(M4) $(M4PARAM) $^ > $@
Chris PeBenito 885b83
Chris PeBenito 885b83
%.pp: tmp/%.mod tmp/%.mod.fc
Chris PeBenito 885b83
	@echo "Creating $(NAME) $(@F) policy package"
Chris PeBenito 885b83
	$(verbose) $(SEMOD_PKG) -o $@ -m $< -f $<.fc
Chris PeBenito 885b83
Chris PeBenito 885b83
tmp/all_interfaces.conf: $(m4support) $(all_interfaces) $(detected_ifs)
Chris PeBenito 885b83
	@test -d tmp || mkdir -p tmp
Chris PeBenito 885b83
	$(verbose) m4 $^ | sed -e s/dollarsstar/\$$\*/g > $@
Chris PeBenito 885b83
Chris PeBenito 0578bf
# so users dont have to make empty .fc and .if files
Chris PeBenito 0578bf
$(detected_ifs) $(detected_fcs):
Chris PeBenito 0578bf
	@touch $@
Chris PeBenito 885b83
Chris PeBenito 885b83
########################################
Chris PeBenito 885b83
#
Chris PeBenito 885b83
# Documentation generation
Chris PeBenito 885b83
#
Chris PeBenito 885b83
Chris PeBenito 885b83
# minimal dependencies here, because we don't want to rebuild
Chris PeBenito 885b83
# this and its dependents every time the dependencies
Chris PeBenito 885b83
# change.  Also use all .if files here, rather then just the
Chris PeBenito 885b83
# enabled modules.
Chris PeBenito 885b83
$(polxml): $(detected_ifs) $(foreach dir,$(all_layers),$(dir)/$(layerxml))
Chris PeBenito 885b83
	@echo "Creating $@"
Chris PeBenito 885b83
	@mkdir -p doc
Chris PeBenito 885b83
	$(verbose) echo '' > $@
Chris PeBenito 885b83
	$(verbose) echo '' >> $@
Chris PeBenito 885b83
	$(verbose) $(genxml) -m $(layerxml) --tunables-xml $(globaltun) --booleans-xml $(globalbool) $(all_layers) $(detected_layers) >> $@
Chris PeBenito 885b83
	$(verbose) if test -x $(XMLLINT) && test -f $(xmldtd); then \
Chris PeBenito 885b83
		$(XMLLINT) --noout --dtdvalid $(xmldtd) $@ ;\
Chris PeBenito 885b83
	fi
Chris PeBenito 885b83
Chris PeBenito 885b83
########################################
Chris PeBenito 885b83
#
Chris PeBenito 885b83
# Clean the environment
Chris PeBenito 885b83
#
Chris PeBenito 885b83
Chris PeBenito 885b83
clean:
Chris PeBenito 885b83
	rm -fR tmp
Chris PeBenito 885b83
	rm -f *.pp