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
2007-03-29 12:08:00 +00:00
CUT ?= cut
2006-02-22 18:30:15 +00:00
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
2007-10-02 16:04:50 +00:00
TYPE ?= standard
2006-02-10 18:41:53 +00:00
DIRECT_INITRC ?= n
POLY ?= n
QUIET ?= y
genxml := $( PYTHON) $( HEADERDIR) /support/segenxml.py
2007-09-21 15:06:58 +00:00
docs := doc
polxml := $( docs) /policy.xml
xmldtd := $( HEADERDIR) /support/policy.dtd
metaxml := metadata.xml
2006-02-10 18:41:53 +00:00
globaltun = $( HEADERDIR) /global_tunables.xml
globalbool = $( HEADERDIR) /global_booleans.xml
# enable MLS if requested.
2007-10-02 16:04:50 +00:00
i f e q "$(TYPE)" "mls"
2006-02-10 18:41:53 +00:00
M4PARAM += -D enable_mls
CHECKPOLICY += -M
CHECKMODULE += -M
e n d i f
# enable MLS if MCS requested.
2007-10-02 16:04:50 +00:00
i f e q "$(TYPE)" "mcs"
2006-02-10 18:41:53 +00:00
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
2008-11-05 16:10:46 +00:00
i f e q "$(UBAC)" "y"
M4PARAM += -D enable_ubac
e n d i f
2006-10-04 17:25:34 +00:00
# default MLS/MCS sensitivity and category settings.
MLS_SENS ?= 16
2010-08-26 16:55:57 +00:00
MLS_CATS ?= 1024
MCS_CATS ?= 1024
2006-10-04 17:25:34 +00:00
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)
2007-03-26 18:41:45 +00:00
2007-09-21 15:06:58 +00:00
header_layers := $( filter-out $( HEADERDIR) /support,$( shell find $( wildcard $( HEADERDIR) /*) -maxdepth 0 -type d) )
header_xml := $( addsuffix .xml,$( header_layers) )
header_interfaces := $( foreach layer,$( header_layers) ,$( wildcard $( layer) /*.if) )
2006-02-10 18:41:53 +00:00
2007-09-21 15:06:58 +00:00
rolemap := $( HEADERDIR) /rolemap
2007-03-26 18:41:45 +00:00
2007-09-21 15:06:58 +00:00
local_layers := $( filter-out CVS tmp $( docs) ,$( shell find $( wildcard *) -maxdepth 0 -type d) )
local_xml := $( addprefix tmp/, $( addsuffix .xml,$( local_layers) ) )
2007-03-26 18:41:45 +00:00
2007-09-21 15:06:58 +00:00
all_layer_names := $( sort $( notdir $( header_layers) $( local_layers) ) )
2007-03-26 18:41:45 +00:00
2007-09-21 15:06:58 +00:00
3rd_party_mods := $( wildcard *.te)
detected_mods := $( 3rd_party_mods) $( foreach layer,$( local_layers) ,$( wildcard $( layer) /*.te) )
2006-02-16 21:20:55 +00:00
2007-09-21 15:06:58 +00:00
detected_ifs := $( detected_mods:.te= .if)
detected_fcs := $( detected_mods:.te= .fc)
all_packages := $( notdir $( detected_mods:.te= .pp) )
2007-03-26 18:41:45 +00:00
2007-03-29 12:08:00 +00:00
# figure out what modules we may want to reload
loaded_mods = $( addsuffix .pp,$( shell $( SEMODULE) -l | $( CUT) -f1) )
sys_mods = $( wildcard $( SHAREDIR) /$( NAME) /*.pp)
match_sys = $( filter $( addprefix $( SHAREDIR) /$( NAME) /,$( loaded_mods) ) ,$( sys_mods) )
match_loc = $( filter $( all_packages) ,$( loaded_mods) )
2007-09-21 15:06:58 +00:00
v p a t h % . t e $( local_layers )
v p a t h % . i f $( local_layers )
v p a t h % . f c $( local_layers )
2006-02-10 18:41:53 +00:00
########################################
#
# 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 )
2007-03-29 12:08:00 +00:00
########################################
#
# Attempt to reinstall all installed packages
#
refresh :
@$( EINFO) " Refreshing $( NAME) modules "
$( verbose) $( SEMODULE) -b $( SHAREDIR) /$( NAME) /base.pp $( foreach mod,$( match_sys) $( match_loc) ,-i $( mod) )
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 "
2007-09-21 15:06:58 +00:00
@test -d $( @D) || mkdir -p $( @D)
2006-02-10 18:41:53 +00:00
$( 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
2007-09-21 15:06:58 +00:00
tmp/all_interfaces.conf : $( m 4support ) $( header_interfaces ) $( detected_ifs )
@test -d $( @D) || mkdir -p $( @D)
@echo "ifdef(\`__if_error',\`m4exit(1)')" > tmp/iferror.m4
@echo "divert(-1)" > $@
$( verbose) $( M4) $^ tmp/iferror.m4 | sed -e s/dollarsstar/\$ $\* /g >> $@
@echo "divert" >> $@
2006-02-10 18:41:53 +00:00
2006-04-06 19:18:53 +00:00
# so users dont have to make empty .fc and .if files
2007-09-21 15:06:58 +00:00
$(detected_fcs) :
2006-04-06 19:18:53 +00:00
@touch $@
2007-09-21 15:06:58 +00:00
$(detected_ifs) :
@echo " ## <summary> $( basename $( @D) ) </summary> " > $@
2006-02-10 18:41:53 +00:00
########################################
#
# Documentation generation
#
2007-09-21 15:06:58 +00:00
tmp/%.xml : %/*.te %/*.if
@test -d $( @D) || mkdir -p $( @D)
$( verbose) test -f $( HEADERDIR) /$* .xml || cat $* /$( metaxml) > $@
$( verbose) $( genxml) -w -m $( sort $( basename $^) ) >> $@
2006-02-10 18:41:53 +00:00
2007-09-21 15:06:58 +00:00
vars : $( local_xml )
2007-03-26 18:41:45 +00:00
2007-09-21 15:06:58 +00:00
$(polxml) : $( header_xml ) $( local_xml ) $( globaltun ) $( globalbool ) $( detected_mods ) $( detected_ifs )
2007-03-26 18:41:45 +00:00
@echo " Creating $( @F) "
2007-09-21 15:06:58 +00:00
@test -d $( @D) || mkdir -p $( @D)
2006-02-10 18:41:53 +00:00
$( verbose) echo '<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>' > $@
2007-03-26 18:41:45 +00:00
$( verbose) echo '<!DOCTYPE policy SYSTEM "$(notdir $(xmldtd))">' >> $@
$( verbose) echo '<policy>' >> $@
2007-09-21 15:06:58 +00:00
$( verbose) for i in $( all_layer_names) ; do \
echo " <layer name=\" $$ i\"> " >> $@ ; \
test -f $( HEADERDIR) /$$ i.xml && cat $( HEADERDIR) /$$ i.xml >> $@ ; \
test -f tmp/$$ i.xml && cat tmp/$$ i.xml >> $@ ; \
echo "</layer>" >> $@ ; \
done
i f n e q "$(strip $(3rd_party_mods))" ""
$( verbose) echo "<layer name=\"third_party\">" >> $@
$( verbose) echo "<summary>These are all third-party modules.</summary>" >> $@
$( verbose) $( genxml) -w -m $( addprefix ./,$( basename $( 3rd_party_mods) ) ) >> $@
$( verbose) echo "</layer>" >> $@
e n d i f
$( verbose) cat $( globaltun) $( globalbool) >> $@
2007-03-26 18:41:45 +00:00
$( verbose) echo '</policy>' >> $@
2006-02-10 18:41:53 +00:00
$( verbose) if test -x $( XMLLINT) && test -f $( xmldtd) ; then \
2007-03-26 18:41:45 +00:00
$( XMLLINT) --noout --path $( dir $( xmldtd) ) --dtdvalid $( xmldtd) $@ ; \
2006-02-10 18:41:53 +00:00
fi
########################################
#
# Clean the environment
#
clean :
rm -fR tmp
rm -f *.pp