2006-02-10 18:41:53 +00:00
2006-02-22 18:30:15 +00:00
# helper tools
AWK ?= gawk
INSTALL ?= install
M4 ?= m4
SED ?= sed
EINFO ?= echo
PYTHON ?= python
NAME ?= $( shell $( AWK) -F= '/^SELINUXTYPE/{ print $$2 }' /etc/selinux/config)
SHAREDIR ?= /usr/share/selinux
HEADERDIR ?= $( SHAREDIR) /$( NAME) /include
2006-02-10 18:41:53 +00:00
i n c l u d e $( HEADERDIR ) / b u i l d . c o n f
# executables
PREFIX := /usr
BINDIR := $( PREFIX) /bin
SBINDIR := $( PREFIX) /sbin
CHECKMODULE := $( BINDIR) /checkmodule
SEMODULE := $( SBINDIR) /semodule
SEMOD_PKG := $( BINDIR) /semodule_package
XMLLINT := $( BINDIR) /xmllint
# set default build options if missing
TYPE ?= strict
DIRECT_INITRC ?= n
POLY ?= n
QUIET ?= y
genxml := $( PYTHON) $( HEADERDIR) /support/segenxml.py
docs = doc
polxml = $( docs) /policy.xml
xmldtd = $( HEADERDIR) /support/policy.dtd
layerxml = metadata.xml
globaltun = $( HEADERDIR) /global_tunables.xml
globalbool = $( HEADERDIR) /global_booleans.xml
# compile strict policy if requested.
i f n e q ( $( findstring strict ,$ ( TYPE ) ) , )
M4PARAM += -D strict_policy
e n d i f
# compile targeted policy if requested.
i f n e q ( $( findstring targeted ,$ ( TYPE ) ) , )
M4PARAM += -D targeted_policy
e n d i f
# enable MLS if requested.
i f n e q ( $( findstring -mls ,$ ( TYPE ) ) , )
M4PARAM += -D enable_mls
CHECKPOLICY += -M
CHECKMODULE += -M
e n d i f
# enable MLS if MCS requested.
i f n e q ( $( findstring -mcs ,$ ( TYPE ) ) , )
M4PARAM += -D enable_mcs
CHECKPOLICY += -M
CHECKMODULE += -M
e n d i f
# enable distribution-specific policy
i f n e q ( $( DISTRO ) , )
M4PARAM += -D distro_$( DISTRO)
e n d i f
i f e q ( $( DIRECT_INITRC ) , y )
M4PARAM += -D direct_sysadm_daemon
e n d i f
2006-10-04 17:25:34 +00:00
# default MLS/MCS sensitivity and category settings.
MLS_SENS ?= 16
MLS_CATS ?= 256
MCS_CATS ?= 256
2006-02-10 18:41:53 +00:00
i f e q ( $( QUIET ) , y )
verbose := @
e n d i f
2006-10-04 17:25:34 +00:00
M4PARAM += -D hide_broken_symptoms -D mls_num_sens = $( MLS_SENS) -D mls_num_cats = $( MLS_CATS) -D mcs_num_cats = $( MCS_CATS)
2006-02-10 18:41:53 +00:00
# policy headers
m4support = $( wildcard $( HEADERDIR) /support/*.spt)
all_layers = $( filter-out $( HEADERDIR) /support,$( shell find $( wildcard $( HEADERDIR) /*) -maxdepth 0 -type d) )
all_interfaces = $( foreach layer,$( all_layers) ,$( wildcard $( layer) /*.if) )
rolemap = $( HEADERDIR) /rolemap
detected_layers = $( filter-out CVS tmp $( docs) ,$( shell find $( wildcard *) -maxdepth 0 -type d) )
3rd_party_mods = $( wildcard *.te)
detected_mods = $( 3rd_party_mods) $( foreach layer,$( detected_layers) ,$( wildcard $( layer) /*.te) )
2006-04-06 19:18:53 +00:00
detected_ifs = $( detected_mods:.te= .if)
detected_fcs = $( detected_mods:.te= .fc)
2006-02-16 21:20:55 +00:00
all_packages = $( notdir $( detected_mods:.te= .pp) )
v p a t h % . t e $( detected_layers )
v p a t h % . i f $( detected_layers )
v p a t h % . f c $( detected_layers )
2006-02-10 18:41:53 +00:00
# if there are modules in the current directory, add them into the third party layer
2006-04-06 19:18:53 +00:00
i f n e q "$(3rd_party_mods)" ""
2006-02-10 18:41:53 +00:00
genxml += -3 .
e n d i f
########################################
#
# Functions
#
2006-09-06 22:07:25 +00:00
# parse-rolemap-compat modulename,outputfile
d e f i n e p a r s e - r o l e m a p - c o m p a t
$( verbose) $( M4) $( M4PARAM) $( rolemap) | \
$( AWK) '/^[[:blank:]]*[A-Za-z]/{ print "gen_require(type " $$3 "; role " $$1 ";)\n$1_per_userdomain_template(" $$2 "," $$3 "," $$1 ")" }' >> $2
e n d e f
2006-02-10 18:41:53 +00:00
# parse-rolemap modulename,outputfile
d e f i n e p a r s e - r o l e m a p
$( verbose) $( M4) $( M4PARAM) $( rolemap) | \
2006-09-06 22:07:25 +00:00
$( AWK) '/^[[:blank:]]*[A-Za-z]/{ print "gen_require(type " $$3 "; role " $$1 ";)\n$1_per_role_template(" $$2 "," $$3 "," $$1 ")" }' >> $2
2006-02-10 18:41:53 +00:00
e n d e f
# peruser-expansion modulename,outputfile
d e f i n e p e r u s e r - e x p a n s i o n
2006-09-06 22:07:25 +00:00
$( verbose) echo "ifdef(\`" " $1 " "_per_role_template',\`" > $2
2006-02-10 18:41:53 +00:00
$( call parse-rolemap,$1 ,$2 )
$( verbose) echo "')" >> $2
2006-09-06 22:07:25 +00:00
$( verbose) echo "ifdef(\`" " $1 " "_per_userdomain_template',\`" >> $2
$( verbose) echo "errprint(\`Warning: per_userdomain_templates have been renamed to per_role_templates (" " $1 " "_per_userdomain_template)'__endline__)" >> $2
$( call parse-rolemap-compat,$1 ,$2 )
$( verbose) echo "')" >> $2
2006-02-10 18:41:53 +00:00
e n d e f
2006-11-13 03:36:13 +00:00
.PHONY : clean all xml load reload
2006-02-10 18:41:53 +00:00
.SUFFIXES :
.SUFFIXES : .pp
2006-05-26 14:33:44 +00:00
# broken in make 3.81:
#.SECONDARY:
2006-02-10 18:41:53 +00:00
########################################
#
# Main targets
#
all : $( all_packages )
xml : $( polxml )
2006-10-10 15:23:17 +00:00
########################################
#
# Load module packages
#
2006-10-25 20:38:33 +00:00
load : tmp /loaded
2006-11-13 03:36:13 +00:00
tmp/loaded : $( all_packages )
@$( EINFO) " Loading $( NAME) modules: $( basename $( notdir $? ) ) "
$( verbose) $( SEMODULE) $( foreach mod,$? ,-i $( mod) )
@mkdir -p tmp
@touch tmp/loaded
2006-10-25 20:38:33 +00:00
2006-11-13 03:36:13 +00:00
reload : $( all_packages )
@$( EINFO) " Loading $( NAME) modules: $( basename $( notdir $^) ) "
2006-10-10 15:23:17 +00:00
$( verbose) $( SEMODULE) $( foreach mod,$^,-i $( mod) )
2006-10-25 20:38:33 +00:00
@mkdir -p tmp
@touch tmp/loaded
2006-10-10 15:23:17 +00:00
2006-02-10 18:41:53 +00:00
########################################
#
# Build module packages
#
tmp/%.mod : $( m 4support ) tmp /all_interfaces .conf %.te
2006-04-06 19:18:53 +00:00
@$( EINFO) " Compiling $( NAME) $( basename $( @F) ) module "
2006-02-10 18:41:53 +00:00
@test -d tmp || mkdir -p tmp
$( call peruser-expansion,$( basename $( @F) ) ,$@ .role)
$( verbose) $( M4) $( M4PARAM) -s $^ $@ .role > $( @:.mod= .tmp)
$( verbose) $( CHECKMODULE) -m $( @:.mod= .tmp) -o $@
tmp/%.mod.fc : $( m 4support ) %.fc
$( verbose) $( M4) $( M4PARAM) $^ > $@
%.pp : tmp /%.mod tmp /%.mod .fc
@echo " Creating $( NAME) $( @F) policy package "
$( verbose) $( SEMOD_PKG) -o $@ -m $< -f $<.fc
tmp/all_interfaces.conf : $( m 4support ) $( all_interfaces ) $( detected_ifs )
@test -d tmp || mkdir -p tmp
$( verbose) m4 $^ | sed -e s/dollarsstar/\$ $\* /g > $@
2006-04-06 19:18:53 +00:00
# so users dont have to make empty .fc and .if files
$(detected_ifs) $(detected_fcs) :
@touch $@
2006-02-10 18:41:53 +00:00
########################################
#
# Documentation generation
#
# minimal dependencies here, because we don't want to rebuild
# this and its dependents every time the dependencies
# change. Also use all .if files here, rather then just the
# enabled modules.
$(polxml) : $( detected_ifs ) $( foreach dir ,$ ( all_layers ) ,$ ( dir ) /$ ( layerxml ) )
@echo " Creating $@ "
@mkdir -p doc
$( verbose) echo '<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>' > $@
$( verbose) echo '<!DOCTYPE policy SYSTEM "$(xmldtd)">' >> $@
$( verbose) $( genxml) -m $( layerxml) --tunables-xml $( globaltun) --booleans-xml $( globalbool) $( all_layers) $( detected_layers) >> $@
$( verbose) if test -x $( XMLLINT) && test -f $( xmldtd) ; then \
$( XMLLINT) --noout --dtdvalid $( xmldtd) $@ ; \
fi
########################################
#
# Clean the environment
#
clean :
rm -fR tmp
rm -f *.pp