Daniel J Walsh c417f6
# installation paths
Daniel J Walsh c417f6
SHAREDIR := $(PREFIX)/share/selinux
Daniel J Walsh c417f6
HEADERDIR := $(SHAREDIR)/refpolicy/include
Daniel J Walsh de82d8
Daniel J Walsh c417f6
include $(HEADERDIR)/build.conf
Daniel J Walsh de82d8
Daniel J Walsh de82d8
# executables
Daniel J Walsh de82d8
PREFIX := /usr
Daniel J Walsh de82d8
BINDIR := $(PREFIX)/bin
Daniel J Walsh de82d8
SBINDIR := $(PREFIX)/sbin
Daniel J Walsh de82d8
CHECKMODULE := $(BINDIR)/checkmodule
Daniel J Walsh de82d8
SEMODULE := $(SBINDIR)/semodule
Daniel J Walsh de82d8
SEMOD_PKG := $(BINDIR)/semodule_package
Daniel J Walsh c417f6
XMLLINT := $(BINDIR)/xmllint
Daniel J Walsh de82d8
Daniel J Walsh de82d8
# helper tools
Daniel J Walsh de82d8
AWK ?= gawk
Daniel J Walsh de82d8
INSTALL ?= install
Daniel J Walsh de82d8
M4 ?= m4
Daniel J Walsh de82d8
SED ?= sed
Daniel J Walsh de82d8
EINFO ?= echo
Daniel J Walsh c417f6
PYTHON ?= python
Daniel J Walsh de82d8
Daniel J Walsh c417f6
# set default build options if missing
Daniel J Walsh de82d8
NAME ?= $(shell . /etc/selinux/config; echo $$SELINUXTYPE)
Daniel J Walsh de82d8
MLSENABLED := $(shell cat /selinux/mls)
Daniel J Walsh c417f6
MODPKGDIR := $(SHAREDIR)/$(NAME)
Daniel J Walsh de82d8
Daniel J Walsh de82d8
ifeq ($(MLSENABLED),1)
Daniel J Walsh de82d8
MCSFLAG=-mcs
Daniel J Walsh de82d8
endif
Daniel J Walsh de82d8
Daniel J Walsh de82d8
TYPE ?= $(NAME)${MCSFLAG}
Daniel J Walsh de82d8
DIRECT_INITRC ?= n
Daniel J Walsh de82d8
POLY ?= n
Daniel J Walsh c417f6
QUIET ?= y
Daniel J Walsh de82d8
Daniel J Walsh de82d8
# compile strict policy if requested.
Daniel J Walsh de82d8
ifneq ($(findstring strict,$(TYPE)),)
Daniel J Walsh de82d8
	M4PARAM += -D strict_policy
Daniel J Walsh de82d8
endif
Daniel J Walsh de82d8
Daniel J Walsh de82d8
# compile targeted policy if requested.
Daniel J Walsh de82d8
ifneq ($(findstring targeted,$(TYPE)),)
Daniel J Walsh de82d8
	M4PARAM += -D targeted_policy
Daniel J Walsh de82d8
endif
Daniel J Walsh de82d8
Daniel J Walsh de82d8
# enable MLS if requested.
Daniel J Walsh de82d8
ifneq ($(findstring -mls,$(TYPE)),)
Daniel J Walsh de82d8
	M4PARAM += -D enable_mls
Daniel J Walsh de82d8
	CHECKPOLICY += -M
Daniel J Walsh de82d8
	CHECKMODULE += -M
Daniel J Walsh de82d8
endif
Daniel J Walsh de82d8
Daniel J Walsh de82d8
# enable MLS if MCS requested.
Daniel J Walsh de82d8
ifneq ($(findstring -mcs,$(TYPE)),)
Daniel J Walsh de82d8
	M4PARAM += -D enable_mcs
Daniel J Walsh de82d8
	CHECKPOLICY += -M
Daniel J Walsh de82d8
	CHECKMODULE += -M
Daniel J Walsh de82d8
endif
Daniel J Walsh de82d8
Daniel J Walsh de82d8
# enable distribution-specific policy
Daniel J Walsh de82d8
ifneq ($(DISTRO),)
Daniel J Walsh de82d8
	M4PARAM += -D distro_$(DISTRO)
Daniel J Walsh de82d8
endif
Daniel J Walsh de82d8
Daniel J Walsh de82d8
# enable polyinstantiation
Daniel J Walsh de82d8
ifeq ($(POLY),y)
Daniel J Walsh de82d8
	M4PARAM += -D enable_polyinstantiation
Daniel J Walsh de82d8
endif
Daniel J Walsh de82d8
Daniel J Walsh de82d8
ifeq ($(DIRECT_INITRC),y)
Daniel J Walsh de82d8
	M4PARAM += -D direct_sysadm_daemon
Daniel J Walsh de82d8
endif
Daniel J Walsh de82d8
Daniel J Walsh de82d8
ifneq ($(VERBOSE),y)
Daniel J Walsh de82d8
	quiet := @
Daniel J Walsh de82d8
endif
Daniel J Walsh de82d8
Daniel J Walsh de82d8
M4PARAM += -D hide_broken_symptoms
Daniel J Walsh de82d8
Daniel J Walsh de82d8
# policy headers
Daniel J Walsh de82d8
m4support := $(wildcard $(HEADERDIR)/*.spt)
Daniel J Walsh de82d8
all_interfaces := $(wildcard $(HEADERDIR)/*.if)
Daniel J Walsh de82d8
rolemap := $(HEADERDIR)/rolemap
Daniel J Walsh de82d8
Daniel J Walsh de82d8
detected_mods := $(wildcard *.te)
Daniel J Walsh de82d8
detected_ifs := $(detected_mods:.te=.if)
Daniel J Walsh de82d8
all_packages := $(detected_mods:.te=.pp)
Daniel J Walsh de82d8
install_mods := $(MODPKGDIR)/$(all_packages)
Daniel J Walsh de82d8
Daniel J Walsh de82d8
########################################
Daniel J Walsh de82d8
#
Daniel J Walsh de82d8
# Functions
Daniel J Walsh de82d8
#
Daniel J Walsh de82d8
Daniel J Walsh de82d8
# parse-rolemap modulename,outputfile
Daniel J Walsh de82d8
define parse-rolemap
Daniel J Walsh de82d8
	$(verbose) $(M4) $(M4PARAM) $(rolemap) | \
Daniel J Walsh de82d8
		$(AWK) '/^[[:blank:]]*[A-Za-z]/{ print "gen_require(type " $$3 "; role " $$1 ";)\n$1_per_userdomain_template(" $$2 "," $$3 "," $$1 ")" }' >> $2
Daniel J Walsh de82d8
endef
Daniel J Walsh de82d8
Daniel J Walsh de82d8
# peruser-expansion modulename,outputfile
Daniel J Walsh de82d8
define peruser-expansion
Daniel J Walsh de82d8
	$(verbose) echo "ifdef(\`""$1""_per_userdomain_template',\`" > $2
Daniel J Walsh de82d8
	$(call parse-rolemap,$1,$2)
Daniel J Walsh de82d8
	$(verbose) echo "')" >> $2
Daniel J Walsh de82d8
endef
Daniel J Walsh de82d8
Daniel J Walsh de82d8
########################################
Daniel J Walsh de82d8
#
Daniel J Walsh de82d8
# Main targets
Daniel J Walsh de82d8
#
Daniel J Walsh de82d8
Daniel J Walsh de82d8
all: $(all_packages)
Daniel J Walsh de82d8
Daniel J Walsh de82d8
########################################
Daniel J Walsh de82d8
#
Daniel J Walsh de82d8
# Build module packages
Daniel J Walsh de82d8
#
Daniel J Walsh de82d8
tmp/%.mod: $(m4support) tmp/all_interfaces.conf %.te
Daniel J Walsh de82d8
	@$(EINFO) "Compliling $(NAME) $(basename $(@F)) module"
Daniel J Walsh de82d8
	@test -d tmp || mkdir -p tmp
Daniel J Walsh de82d8
	$(call peruser-expansion,$(basename $(@F)),$@.role)
Daniel J Walsh de82d8
	$(verbose) $(M4) $(M4PARAM) -s $^ $@.role > $(@:.mod=.tmp)
Daniel J Walsh de82d8
	$(verbose) $(CHECKMODULE) -m $(@:.mod=.tmp) -o $@
Daniel J Walsh de82d8
Daniel J Walsh de82d8
tmp/%.mod.fc: $(m4support) %.fc
Daniel J Walsh de82d8
	$(verbose) $(M4) $(M4PARAM) $^ > $@
Daniel J Walsh de82d8
Daniel J Walsh de82d8
%.pp: tmp/%.mod tmp/%.mod.fc
Daniel J Walsh de82d8
	@echo "Creating $(NAME) $(@F) policy package"
Daniel J Walsh de82d8
	$(verbose) $(SEMOD_PKG) -o $@ -m $< -f $<.fc
Daniel J Walsh de82d8
Daniel J Walsh de82d8
tmp/all_interfaces.conf: $(m4support) $(all_interfaces) $(detected_ifs)
Daniel J Walsh de82d8
	@test -d tmp || mkdir -p tmp
Daniel J Walsh de82d8
	$(verbose) m4 $^ | sed -e s/dollarsstar/\$$\*/g > $@
Daniel J Walsh de82d8
Daniel J Walsh de82d8
########################################
Daniel J Walsh de82d8
#
Daniel J Walsh de82d8
# Clean the environment
Daniel J Walsh de82d8
#
Daniel J Walsh de82d8
Daniel J Walsh de82d8
clean:
Daniel J Walsh de82d8
	rm -fR tmp
Daniel J Walsh de82d8
	rm -f *.pp
Daniel J Walsh de82d8
Daniel J Walsh de82d8
.PHONY: clean install all default