]> git.ipfire.org Git - people/stevee/selinux-policy.git/blame - Makefile
trunk: merge UBAC.
[people/stevee/selinux-policy.git] / Makefile
CommitLineData
88d14a22
CP
1#
2# Makefile for the security policy.
3#
4# Targets:
5#
6# install - compile and install the policy configuration, and context files.
7# load - compile, install, and load the policy configuration.
8# reload - compile, install, and load/reload the policy configuration.
9# relabel - relabel filesystems based on the file contexts configuration.
10# checklabels - check filesystems against the file context configuration
11# restorelabels - check filesystems against the file context configuration
12# and restore the label of files with incorrect labels
13# policy - compile the policy configuration locally for testing/development.
14#
15# The default target is 'policy'.
16#
b4cd1533 17#
8e0ef1f9 18# Please see build.conf for policy build options.
b4cd1533
CP
19#
20
b4cd1533
CP
21########################################
22#
b67488e3 23# NO OPTIONS BELOW HERE
b4cd1533
CP
24#
25
c9f20d5b
CP
26# Include the local build.conf if it exists, otherwise
27# include the configuration of the root directory.
1a7175a8
CP
28include build.conf
29
30ifdef LOCAL_ROOT
31 -include $(LOCAL_ROOT)/build.conf
c9f20d5b 32endif
8e0ef1f9 33
120988c4 34# refpolicy version
c634db20 35version = $(shell cat VERSION)
120988c4 36
c9f20d5b 37ifdef LOCAL_ROOT
c634db20
CP
38builddir := $(LOCAL_ROOT)/
39tmpdir := $(LOCAL_ROOT)/tmp
40tags := $(LOCAL_ROOT)/tags
c9f20d5b 41else
c634db20
CP
42tmpdir := tmp
43tags := tags
c9f20d5b
CP
44endif
45
b4cd1533 46# executable paths
906f1084
CP
47BINDIR ?= /usr/bin
48SBINDIR ?= /usr/sbin
e2ae0861 49ifdef TEST_TOOLCHAIN
75beb950
CP
50tc_usrbindir := env LD_LIBRARY_PATH="$(TEST_TOOLCHAIN)/lib" $(TEST_TOOLCHAIN)$(BINDIR)
51tc_usrsbindir := env LD_LIBRARY_PATH="$(TEST_TOOLCHAIN)/lib" $(TEST_TOOLCHAIN)$(SBINDIR)
52tc_sbindir := env LD_LIBRARY_PATH="$(TEST_TOOLCHAIN)/lib" $(TEST_TOOLCHAIN)/sbin
e2ae0861 53else
75beb950
CP
54tc_usrbindir := $(BINDIR)
55tc_usrsbindir := $(SBINDIR)
56tc_sbindir := /sbin
e2ae0861 57endif
75beb950
CP
58CHECKPOLICY ?= $(tc_usrbindir)/checkpolicy
59CHECKMODULE ?= $(tc_usrbindir)/checkmodule
60SEMODULE ?= $(tc_usrsbindir)/semodule
61SEMOD_PKG ?= $(tc_usrbindir)/semodule_package
62SEMOD_LNK ?= $(tc_usrbindir)/semodule_link
63SEMOD_EXP ?= $(tc_usrbindir)/semodule_expand
64LOADPOLICY ?= $(tc_usrsbindir)/load_policy
e2ae0861 65SETFILES ?= $(tc_sbindir)/setfiles
906f1084
CP
66XMLLINT ?= $(BINDIR)/xmllint
67SECHECK ?= $(BINDIR)/sechecker
0447352a 68
0e686f1f
CP
69# interpreters and aux tools
70AWK ?= gawk
71GREP ?= egrep
cfd5c5e1 72INSTALL ?= install
0e686f1f
CP
73M4 ?= m4
74PYTHON ?= python
75SED ?= sed
f62f4c79 76SORT ?= LC_ALL=C sort
0e686f1f
CP
77
78CFLAGS += -Wall
c7b41e95 79
fb0a3a98 80# policy source layout
c634db20
CP
81poldir := policy
82moddir := $(poldir)/modules
83flaskdir := $(poldir)/flask
84secclass := $(flaskdir)/security_classes
85isids := $(flaskdir)/initial_sids
86avs := $(flaskdir)/access_vectors
fb0a3a98 87
c9f20d5b
CP
88# local source layout
89ifdef LOCAL_ROOT
c634db20
CP
90local_poldir := $(LOCAL_ROOT)/policy
91local_moddir := $(local_poldir)/modules
c9f20d5b
CP
92endif
93
fb0a3a98 94# policy building support tools
c634db20 95support := support
1a79cf05
CP
96genxml := $(PYTHON) -E $(support)/segenxml.py
97gendoc := $(PYTHON) -E $(support)/sedoctool.py
98genperm := $(PYTHON) -E $(support)/genclassperms.py
c634db20
CP
99fcsort := $(tmpdir)/fc_sort
100setbools := $(AWK) -f $(support)/set_bools_tuns.awk
101get_type_attr_decl := $(SED) -r -f $(support)/get_type_attr_decl.sed
102comment_move_decl := $(SED) -r -f $(support)/comment_move_decl.sed
1a79cf05 103gennetfilter := $(PYTHON) -E $(support)/gennetfilter.py
e276d50e 104m4iferror := $(support)/iferror.m4
fc47b34c
CP
105# use our own genhomedircon to make sure we have a known usable one,
106# so policycoreutils updates are not required (RHEL4)
1a79cf05 107genhomedircon := $(PYTHON) -E $(support)/genhomedircon
3a80ec29 108
fb0a3a98 109# documentation paths
c634db20
CP
110docs := doc
111xmldtd = $(docs)/policy.dtd
56e1b3d2 112metaxml = metadata.xml
c634db20
CP
113doctemplate = $(docs)/templates
114docfiles = $(docs)/Makefile.example $(addprefix $(docs)/,example.te example.if example.fc)
fb0a3a98 115
c9f20d5b 116ifndef LOCAL_ROOT
c634db20
CP
117polxml = $(docs)/policy.xml
118tunxml = $(docs)/global_tunables.xml
119boolxml = $(docs)/global_booleans.xml
120htmldir = $(docs)/html
c9f20d5b 121else
c634db20
CP
122polxml = $(LOCAL_ROOT)/doc/policy.xml
123tunxml = $(LOCAL_ROOT)/doc/global_tunables.xml
124boolxml = $(LOCAL_ROOT)/doc/global_booleans.xml
125htmldir = $(LOCAL_ROOT)/doc/html
c9f20d5b
CP
126endif
127
fb0a3a98 128# config file paths
c634db20
CP
129globaltun = $(poldir)/global_tunables
130globalbool = $(poldir)/global_booleans
131rolemap = $(poldir)/rolemap
132user_files := $(poldir)/users
c07f9ccd 133policycaps := $(poldir)/policy_capabilities
fb0a3a98 134
c9f20d5b
CP
135# local config file paths
136ifndef LOCAL_ROOT
c634db20
CP
137mod_conf = $(poldir)/modules.conf
138booleans = $(poldir)/booleans.conf
139tunables = $(poldir)/tunables.conf
c9f20d5b 140else
c634db20
CP
141mod_conf = $(local_poldir)/modules.conf
142booleans = $(local_poldir)/booleans.conf
143tunables = $(local_poldir)/tunables.conf
c9f20d5b
CP
144endif
145
fb0a3a98 146# install paths
c634db20
CP
147PKGNAME ?= refpolicy-$(version)
148prefix = $(DESTDIR)/usr
149topdir = $(DESTDIR)/etc/selinux
150installdir = $(topdir)/$(strip $(NAME))
151srcpath = $(installdir)/src
152userpath = $(installdir)/users
21283237 153policypath = $(installdir)/policy
c634db20 154contextpath = $(installdir)/contexts
21283237 155homedirpath = $(contextpath)/files/homedir_template
c634db20
CP
156fcpath = $(contextpath)/files/file_contexts
157ncpath = $(contextpath)/netfilter_contexts
158sharedir = $(prefix)/share/selinux
159modpkgdir = $(sharedir)/$(strip $(NAME))
160headerdir = $(modpkgdir)/include
161docsdir = $(prefix)/share/doc/$(PKGNAME)
c767b14c 162
134191be 163# enable MLS if requested.
350b6ab7 164ifeq "$(TYPE)" "mls"
3f026a90
CP
165 M4PARAM += -D enable_mls
166 CHECKPOLICY += -M
167 CHECKMODULE += -M
6962bb32 168 gennetfilter += -m
134191be
CP
169endif
170
a0824843 171# enable MLS if MCS requested.
350b6ab7 172ifeq "$(TYPE)" "mcs"
3f026a90
CP
173 M4PARAM += -D enable_mcs
174 CHECKPOLICY += -M
175 CHECKMODULE += -M
6962bb32 176 gennetfilter += -c
b67488e3
CP
177endif
178
25a0c61f
CP
179# enable distribution-specific policy
180ifneq ($(DISTRO),)
3f026a90 181 M4PARAM += -D distro_$(DISTRO)
25a0c61f
CP
182endif
183
2f1a8fbc
CP
184# rhel4 also implies redhat
185ifeq "$(DISTRO)" "rhel4"
186 M4PARAM += -D distro_redhat
187endif
188
12cf805e
CP
189ifeq "$(DISTRO)" "ubuntu"
190 M4PARAM += -D distro_debian
191endif
192
b67488e3 193ifneq ($(OUTPUT_POLICY),)
3f026a90 194 CHECKPOLICY += -c $(OUTPUT_POLICY)
b67488e3
CP
195endif
196
3f026a90
CP
197# if not set, use the type as the name.
198NAME ?= $(TYPE)
134191be 199
8acfcbcc
CP
200# default unknown permissions setting
201#UNK_PERMS ?= deny
202
142e9f40 203ifeq ($(DIRECT_INITRC),y)
3f026a90 204 M4PARAM += -D direct_sysadm_daemon
142e9f40
CP
205endif
206
296273a7
CP
207ifeq "$(UBAC)" "y"
208 M4PARAM += -D enable_ubac
209endif
210
e070dd2d
CP
211# default MLS/MCS sensitivity and category settings.
212MLS_SENS ?= 16
213MLS_CATS ?= 256
214MCS_CATS ?= 256
215
9b3756bf
CP
216ifeq ($(QUIET),y)
217 verbose = @
218endif
219
e070dd2d 220M4PARAM += -D mls_num_sens=$(MLS_SENS) -D mls_num_cats=$(MLS_CATS) -D mcs_num_cats=$(MCS_CATS) -D hide_broken_symptoms
ee7f66b0 221
37227dcd
CP
222# we need exuberant ctags; unfortunately it is named
223# differently on different distros
224ifeq ($(DISTRO),debian)
225 CTAGS := ctags-exuberant
226endif
227
228ifeq ($(DISTRO),gentoo)
229 CTAGS := exuberant-ctags
230endif
231
a4fae7fa 232CTAGS ?= ctags
37227dcd 233
c634db20 234m4support := $(wildcard $(poldir)/support/*.spt)
20144581 235ifdef LOCAL_ROOT
c634db20 236m4support += $(wildcard $(local_poldir)/support/*.spt)
20144581 237endif
0fbe15dc 238
c634db20
CP
239appconf := config/appconfig-$(TYPE)
240seusers := $(appconf)/seusers
241appdir := $(contextpath)
8a2492a2
CP
242user_default_contexts := $(wildcard config/appconfig-$(TYPE)/*_default_contexts)
243user_default_contexts_names := $(addprefix $(contextpath)/users/,$(subst _default_contexts,,$(notdir $(user_default_contexts))))
2c12b471 244appfiles := $(addprefix $(appdir)/,default_contexts default_type initrc_context failsafe_context userhelper_context removable_context dbus_contexts x_contexts customizable_types securetty_types) $(contextpath)/files/media $(user_default_contexts_names)
c634db20 245net_contexts := $(builddir)net_contexts
c9a26b3e 246
96fc0a45 247all_layers := $(shell find $(wildcard $(moddir)/*) -maxdepth 0 -type d)
c9f20d5b 248ifdef LOCAL_ROOT
96fc0a45 249all_layers += $(shell find $(wildcard $(local_moddir)/*) -maxdepth 0 -type d)
c9f20d5b 250endif
e12e5738 251
c634db20
CP
252generated_te := $(basename $(foreach dir,$(all_layers),$(wildcard $(dir)/*.te.in)))
253generated_if := $(basename $(foreach dir,$(all_layers),$(wildcard $(dir)/*.if.in)))
254generated_fc := $(basename $(foreach dir,$(all_layers),$(wildcard $(dir)/*.fc.in)))
e12e5738 255
8ae194f6
CP
256# sort here since it removes duplicates, which can happen
257# when a generated file is already generated
c634db20 258detected_mods := $(sort $(foreach dir,$(all_layers),$(wildcard $(dir)/*.te)) $(generated_te))
19db6ba5 259
96fc0a45
CP
260modxml := $(addprefix $(tmpdir)/, $(detected_mods:.te=.xml))
261layerxml := $(sort $(addprefix $(tmpdir)/, $(notdir $(addsuffix .xml,$(all_layers)))))
262layer_names := $(sort $(notdir $(all_layers)))
263all_metaxml = $(call detect-metaxml, $(layer_names))
56e1b3d2 264
fb0a3a98 265# modules.conf setting for base module
c634db20 266configbase := base
fb0a3a98 267
e0a9001b 268# modules.conf setting for loadable module
c634db20 269configmod := module
fb0a3a98 270
e0a9001b 271# modules.conf setting for unused module
c634db20 272configoff := off
e0a9001b 273
c9f20d5b 274# test for module overrides from command line
c634db20
CP
275mod_test = $(filter $(APPS_OFF), $(APPS_BASE) $(APPS_MODS))
276mod_test += $(filter $(APPS_MODS), $(APPS_BASE))
277ifneq "$(strip $(mod_test))" ""
278 $(error Applications must be base, module, or off, and not in more than one list! $(strip $(mod_test)) found in multiple lists!)
c9f20d5b
CP
279endif
280
20144581 281# add on suffix to modules specified on command line
c634db20
CP
282cmdline_base := $(addsuffix .te,$(APPS_BASE))
283cmdline_mods := $(addsuffix .te,$(APPS_MODS))
284cmdline_off := $(addsuffix .te,$(APPS_OFF))
20144581 285
fb0a3a98 286# extract settings from modules.conf
c634db20
CP
287mod_conf_base := $(addsuffix .te,$(sort $(shell awk '/^[[:blank:]]*[[:alpha:]]/{ if ($$3 == "$(configbase)") print $$1 }' $(mod_conf) 2> /dev/null)))
288mod_conf_mods := $(addsuffix .te,$(sort $(shell awk '/^[[:blank:]]*[[:alpha:]]/{ if ($$3 == "$(configmod)") print $$1 }' $(mod_conf) 2> /dev/null)))
289mod_conf_off := $(addsuffix .te,$(sort $(shell awk '/^[[:blank:]]*[[:alpha:]]/{ if ($$3 == "$(configoff)") print $$1 }' $(mod_conf) 2> /dev/null)))
20144581 290
c634db20
CP
291base_mods := $(cmdline_base)
292mod_mods := $(cmdline_mods)
293off_mods := $(cmdline_off)
87e73c5f 294
c634db20
CP
295base_mods += $(filter-out $(cmdline_off) $(cmdline_base) $(cmdline_mods), $(mod_conf_base))
296mod_mods += $(filter-out $(cmdline_off) $(cmdline_base) $(cmdline_mods), $(mod_conf_mods))
297off_mods += $(filter-out $(cmdline_off) $(cmdline_base) $(cmdline_mods), $(mod_conf_off))
87e73c5f
CP
298
299# add modules not in modules.conf to the off list
c634db20 300off_mods += $(filter-out $(base_mods) $(mod_mods) $(off_mods),$(notdir $(detected_mods)))
712566ee 301
90b331fa 302# filesystems to be used in labeling targets
c634db20 303filesystems = $(shell mount | grep -v "context=" | egrep -v '\((|.*,)bind(,.*|)\)' | awk '/(ext[23]| xfs| jfs).*rw/{print $$3}';)
120988c4 304
4ace0fa5
CP
305########################################
306#
307# Functions
308#
309
bbcd3c97
CP
310# parse-rolemap-compat modulename,outputfile
311define parse-rolemap-compat
312 $(verbose) $(M4) $(M4PARAM) $(rolemap) | \
313 $(AWK) '/^[[:blank:]]*[A-Za-z]/{ print "gen_require(type " $$3 "; role " $$1 ";)\n$1_per_userdomain_template(" $$2 "," $$3 "," $$1 ")" }' >> $2
314endef
315
4ace0fa5
CP
316# parse-rolemap modulename,outputfile
317define parse-rolemap
c634db20 318 $(verbose) $(M4) $(M4PARAM) $(rolemap) | \
bbcd3c97 319 $(AWK) '/^[[:blank:]]*[A-Za-z]/{ print "gen_require(type " $$3 "; role " $$1 ";)\n$1_per_role_template(" $$2 "," $$3 "," $$1 ")" }' >> $2
4ace0fa5
CP
320endef
321
bbcd3c97
CP
322# perrole-expansion modulename,outputfile
323define perrole-expansion
324 $(verbose) echo "ifdef(\`""$1""_per_role_template',\`" > $2
4ace0fa5 325 $(call parse-rolemap,$1,$2)
9b3756bf 326 $(verbose) echo "')" >> $2
bbcd3c97
CP
327
328 $(verbose) echo "ifdef(\`""$1""_per_userdomain_template',\`" >> $2
329 $(verbose) echo "errprint(\`Warning: per_userdomain_templates have been renamed to per_role_templates (""$1""_per_userdomain_template)'__endline__)" >> $2
330 $(call parse-rolemap-compat,$1,$2)
331 $(verbose) echo "')" >> $2
332endef
333
334# create-base-per-role-tmpl modulenames,outputfile
335define create-base-per-role-tmpl
336 $(verbose) echo "define(\`base_per_role_template',\`" >> $2
337
338 $(verbose) for i in $1; do \
339 echo "ifdef(\`""$$i""_per_role_template',\`""$$i""_per_role_template("'$$*'")')" \
340 >> $2 ;\
341 done
342
343 $(verbose) for i in $1; do \
344 echo "ifdef(\`""$$i""_per_userdomain_template',\`" >> $2 ;\
345 echo "errprint(\`Warning: per_userdomain_templates have been renamed to per_role_templates (""$$i""_per_userdomain_template)'__endline__)" >> $2 ;\
346 echo """$$i""_per_userdomain_template("'$$*'")')" >> $2 ;\
347 done
348 $(verbose) echo "')" >> $@
349
4ace0fa5
CP
350endef
351
96fc0a45
CP
352# detect-metaxml layer_names
353ifdef LOCAL_ROOT
354define detect-metaxml
355 $(shell for i in $1; do \
356 if [ -d $(moddir)/$$i -a -d $(local_moddir)/$$i ]; then \
357 if [ -f $(local_moddir)/$$i/$(metaxml) ]; then \
358 echo $(local_moddir)/$$i/$(metaxml) ;\
359 else \
360 echo $(moddir)/$$i/$(metaxml) ;\
361 fi \
362 elif [ -d $(local_moddir)/$$i ]; then
363 echo $(local_moddir)/$$i/$(metaxml) ;\
364 else \
365 echo $(moddir)/$$i/$(metaxml) ;\
366 fi \
367 done )
368endef
369else
370define detect-metaxml
371 $(shell for i in $1; do echo $(moddir)/$$i/$(metaxml); done)
372endef
373endif
374
b4cd1533
CP
375########################################
376#
fb0a3a98 377# Load appropriate rules
b4cd1533 378#
b4cd1533 379
fb0a3a98 380ifeq ($(MONOLITHIC),y)
5b45ffb0 381 include Rules.monolithic
fb0a3a98 382else
5b45ffb0 383 include Rules.modular
b4cd1533 384endif
b4cd1533 385
88d14a22
CP
386########################################
387#
fb0a3a98 388# Generated files
b4cd1533 389#
c9f20d5b
CP
390# NOTE: There is no "local" version of these files.
391#
c634db20 392generate: $(generated_te) $(generated_if) $(generated_fc)
fffba0ba 393
686f11c2 394$(moddir)/kernel/corenetwork.if: $(moddir)/kernel/corenetwork.te.in $(moddir)/kernel/corenetwork.if.m4 $(moddir)/kernel/corenetwork.if.in
61bbe531
CP
395 @echo "#" > $@
396 @echo "# This is a generated file! Instead of modifying this file, the" >> $@
397 @echo "# $(notdir $@).in or $(notdir $@).m4 file should be modified." >> $@
398 @echo "#" >> $@
686f11c2
CP
399 $(verbose) cat $@.in >> $@
400 $(verbose) $(GREP) "^[[:blank:]]*network_(interface|node|port|packet)\(.*\)" $< \
401 | $(M4) -D self_contained_policy $(M4PARAM) $@.m4 - \
cfd5c5e1 402 | $(SED) -e 's/dollarsone/\$$1/g' -e 's/dollarszero/\$$0/g' >> $@
f2e4ab3a 403
c634db20 404$(moddir)/kernel/corenetwork.te: $(moddir)/kernel/corenetwork.te.m4 $(moddir)/kernel/corenetwork.te.in
61bbe531
CP
405 @echo "#" > $@
406 @echo "# This is a generated file! Instead of modifying this file, the" >> $@
407 @echo "# $(notdir $@).in or $(notdir $@).m4 file should be modified." >> $@
408 @echo "#" >> $@
cfd5c5e1
CP
409 $(verbose) $(M4) -D self_contained_policy $(M4PARAM) $^ \
410 | $(SED) -e 's/dollarsone/\$$1/g' -e 's/dollarszero/\$$0/g' >> $@
f2e4ab3a 411
6962bb32
CP
412########################################
413#
414# Network packet labeling
415#
c634db20 416$(net_contexts): $(moddir)/kernel/corenetwork.te.in
6962bb32
CP
417 @echo "Creating netfilter network labeling rules"
418 $(verbose) $(gennetfilter) $^ > $@
419
84eb353c
CP
420########################################
421#
422# Create config files
423#
c634db20 424conf: $(mod_conf) $(booleans) $(generated_te) $(generated_if) $(generated_fc)
d2d6c8ce 425
c634db20
CP
426$(mod_conf) $(booleans): $(polxml)
427 @echo "Updating $(mod_conf) and $(booleans)"
428 $(verbose) $(gendoc) -b $(booleans) -m $(mod_conf) -x $(polxml)
84eb353c 429
c9f20d5b
CP
430########################################
431#
432# Generate the fc_sort program
433#
c634db20 434$(fcsort) : $(support)/fc_sort.c
96fc0a45 435 $(verbose) $(CC) $(CFLAGS) $^ -o $@
c9f20d5b 436
6d314fd3
CP
437########################################
438#
439# Documentation generation
440#
96fc0a45 441$(layerxml): %.xml: $(all_metaxml) $(filter $(addprefix $(moddir)/, $(notdir $*))%, $(detected_mods)) $(subst .te,.if, $(filter $(addprefix $(moddir)/, $(notdir $*))%, $(detected_mods)))
56e1b3d2 442 @test -d $(tmpdir) || mkdir -p $(tmpdir)
96fc0a45
CP
443 $(verbose) cat $(filter %$(notdir $*)/$(metaxml), $(all_metaxml)) > $@
444 $(verbose) for i in $(basename $(filter $(addprefix $(moddir)/, $(notdir $*))%, $(detected_mods))); do $(genxml) -w -m $$i >> $@; done
445ifdef LOCAL_ROOT
446 $(verbose) for i in $(basename $(filter $(addprefix $(local_moddir)/, $(notdir $*))%, $(detected_mods))); do $(genxml) -w -m $$i >> $@; done
447endif
56e1b3d2
CP
448
449$(tunxml): $(globaltun)
450 $(verbose) $(genxml) -w -t $< > $@
451
452$(boolxml): $(globalbool)
453 $(verbose) $(genxml) -w -b $< > $@
454
455$(polxml): $(layerxml) $(tunxml) $(boolxml)
1a7175a8 456 @echo "Creating $(@F)"
c634db20
CP
457 @test -d $(dir $(polxml)) || mkdir -p $(dir $(polxml))
458 @test -d $(tmpdir) || mkdir -p $(tmpdir)
9b3756bf 459 $(verbose) echo '<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>' > $@
c634db20 460 $(verbose) echo '<!DOCTYPE policy SYSTEM "$(notdir $(xmldtd))">' >> $@
56e1b3d2 461 $(verbose) echo '<policy>' >> $@
96fc0a45
CP
462 $(verbose) for i in $(basename $(notdir $(layerxml))); do echo "<layer name=\"$$i\">" >> $@; cat $(tmpdir)/$$i.xml >> $@; echo "</layer>" >> $@; done
463 $(verbose) cat $(tunxml) $(boolxml) >> $@
56e1b3d2 464 $(verbose) echo '</policy>' >> $@
c634db20
CP
465 $(verbose) if test -x $(XMLLINT) && test -f $(xmldtd); then \
466 $(XMLLINT) --noout --path $(dir $(xmldtd)) --dtdvalid $(xmldtd) $@ ;\
004db90d 467 fi
6d314fd3 468
56e1b3d2 469xml: $(polxml)
3d598062 470
c634db20
CP
471html $(tmpdir)/html: $(polxml)
472 @echo "Building html interface reference documentation in $(htmldir)"
473 @test -d $(htmldir) || mkdir -p $(htmldir)
474 @test -d $(tmpdir) || mkdir -p $(tmpdir)
475 $(verbose) $(gendoc) -d $(htmldir) -T $(doctemplate) -x $(polxml)
476 $(verbose) cp $(doctemplate)/*.css $(htmldir)
477 @touch $(tmpdir)/html
20030ef5 478
c9a26b3e
CP
479########################################
480#
481# Runtime binary policy patching of users
482#
c634db20
CP
483$(userpath)/system.users: $(m4support) $(tmpdir)/generated_definitions.conf $(user_files)
484 @mkdir -p $(tmpdir)
485 @mkdir -p $(userpath)
c9a26b3e 486 @echo "Installing system.users"
c634db20
CP
487 @echo "# " > $(tmpdir)/system.users
488 @echo "# Do not edit this file. " >> $(tmpdir)/system.users
489 @echo "# This file is replaced on reinstalls of this policy." >> $(tmpdir)/system.users
490 @echo "# Please edit local.users to make local changes." >> $(tmpdir)/system.users
491 @echo "#" >> $(tmpdir)/system.users
cfd5c5e1 492 $(verbose) $(M4) -D self_contained_policy $(M4PARAM) $^ | $(SED) -r -e 's/^[[:blank:]]+//' \
c634db20
CP
493 -e '/^[[:blank:]]*($$|#)/d' >> $(tmpdir)/system.users
494 $(verbose) $(INSTALL) -m 644 $(tmpdir)/system.users $@
c9a26b3e 495
c634db20
CP
496$(userpath)/local.users: config/local.users
497 @mkdir -p $(userpath)
c9a26b3e 498 @echo "Installing local.users"
cfd5c5e1 499 $(verbose) $(INSTALL) -b -m 644 $< $@
c9a26b3e
CP
500
501########################################
502#
e070dd2d
CP
503# Build Appconfig files
504#
505$(tmpdir)/initrc_context: $(appconf)/initrc_context
506 @mkdir -p $(tmpdir)
507 $(verbose) $(M4) $(M4PARAM) $(m4support) $^ | $(GREP) '^[a-z]' > $@
508
509########################################
510#
511# Install Appconfig files
c9a26b3e 512#
c634db20 513install-appconfig: $(appfiles)
c9a26b3e 514
c634db20
CP
515$(installdir)/booleans: $(booleans)
516 @mkdir -p $(tmpdir)
517 @mkdir -p $(installdir)
cfd5c5e1 518 $(verbose) $(SED) -r -e 's/false/0/g' -e 's/true/1/g' \
c634db20
CP
519 -e '/^[[:blank:]]*($$|#)/d' $(booleans) | $(SORT) > $(tmpdir)/booleans
520 $(verbose) $(INSTALL) -m 644 $(tmpdir)/booleans $@
1beba1c6 521
c634db20
CP
522$(contextpath)/files/media: $(appconf)/media
523 @mkdir -p $(contextpath)/files/
cfd5c5e1 524 $(verbose) $(INSTALL) -m 644 $< $@
c9a26b3e 525
8a2492a2 526$(contextpath)/users/%: $(appconf)/%_default_contexts
c634db20 527 @mkdir -p $(appdir)/users
8a2492a2 528 $(verbose) $(INSTALL) -m 644 $^ $@
9b3756bf 529
b23e1c1c
CP
530$(appdir)/%: $(appconf)/%
531 @mkdir -p $(appdir)
532 $(verbose) $(INSTALL) -m 644 $< $@
533
9b3756bf
CP
534########################################
535#
536# Install policy headers
537#
56e1b3d2 538install-headers: $(layerxml) $(tunxml) $(boolxml)
c634db20 539 @mkdir -p $(headerdir)
1a7175a8 540 @echo "Installing $(TYPE) policy headers."
96fc0a45 541 $(verbose) $(INSTALL) -m 644 $^ $(headerdir)
c634db20
CP
542 $(verbose) $(M4) $(M4PARAM) $(rolemap) > $(headerdir)/$(notdir $(rolemap))
543 $(verbose) mkdir -p $(headerdir)/support
544 $(verbose) $(INSTALL) -m 644 $(m4support) $(word $(words $(genxml)),$(genxml)) $(xmldtd) $(headerdir)/support
545 $(verbose) $(genperm) $(avs) $(secclass) > $(headerdir)/support/all_perms.spt
546 $(verbose) for i in $(notdir $(all_layers)); do \
547 mkdir -p $(headerdir)/$$i ;\
96fc0a45 548 $(INSTALL) -m 644 $(moddir)/$$i/*.if $(headerdir)/$$i ;\
885b83ec 549 done
c634db20
CP
550 $(verbose) echo "TYPE ?= $(TYPE)" > $(headerdir)/build.conf
551 $(verbose) echo "NAME ?= $(NAME)" >> $(headerdir)/build.conf
885b83ec 552ifneq "$(DISTRO)" ""
c634db20 553 $(verbose) echo "DISTRO ?= $(DISTRO)" >> $(headerdir)/build.conf
885b83ec 554endif
c634db20
CP
555 $(verbose) echo "MONOLITHIC ?= n" >> $(headerdir)/build.conf
556 $(verbose) echo "DIRECT_INITRC ?= $(DIRECT_INITRC)" >> $(headerdir)/build.conf
296273a7 557 $(verbose) echo "override UBAC := $(UBAC)" >> $(headerdir)/build.conf
e070dd2d
CP
558 $(verbose) echo "override MLS_SENS := $(MLS_SENS)" >> $(headerdir)/build.conf
559 $(verbose) echo "override MLS_CATS := $(MLS_CATS)" >> $(headerdir)/build.conf
560 $(verbose) echo "override MCS_CATS := $(MCS_CATS)" >> $(headerdir)/build.conf
c634db20 561 $(verbose) $(INSTALL) -m 644 $(support)/Makefile.devel $(headerdir)/Makefile
c9a26b3e 562
120988c4
CP
563########################################
564#
565# Install policy documentation
566#
c634db20
CP
567install-docs: $(tmpdir)/html
568 @mkdir -p $(docsdir)/html
120988c4 569 @echo "Installing policy documentation"
c634db20
CP
570 $(verbose) $(INSTALL) -m 644 $(docfiles) $(docsdir)
571 $(verbose) $(INSTALL) -m 644 $(wildcard $(htmldir)/*) $(docsdir)/html
120988c4 572
c592e52e
CP
573########################################
574#
575# Install policy sources
576#
577install-src:
c634db20
CP
578 rm -rf $(srcpath)/policy.old
579 -mv $(srcpath)/policy $(srcpath)/policy.old
580 mkdir -p $(srcpath)/policy
581 cp -R . $(srcpath)/policy
c592e52e 582
37227dcd
CP
583########################################
584#
585# Generate tags file
586#
c634db20
CP
587tags: $(tags)
588$(tags):
37227dcd 589 @($(CTAGS) --version | grep -q Exuberant) || (echo ERROR: Need exuberant-ctags to function!; exit 1)
c634db20 590 @LC_ALL=C $(CTAGS) -f $(tags) --langdef=te --langmap=te:..te.if.spt \
37227dcd
CP
591 --regex-te='/^type[ \t]+(\w+)(,|;)/\1/t,type/' \
592 --regex-te='/^typealias[ \t]+\w+[ \t+]+alias[ \t]+(\w+);/\1/t,type/' \
593 --regex-te='/^attribute[ \t]+(\w+);/\1/a,attribute/' \
594 --regex-te='/^[ \t]*define\(`(\w+)/\1/d,define/' \
595 --regex-te='/^[ \t]*interface\(`(\w+)/\1/i,interface/' \
42319885 596 --regex-te='/^[ \t]*template\(`(\w+)/\1/i,template/' \
37227dcd
CP
597 --regex-te='/^[ \t]*bool[ \t]+(\w+)/\1/b,bool/' policy/modules/*/*.{if,te} policy/support/*.spt
598
120988c4
CP
599########################################
600#
601# Filesystem labeling
602#
603checklabels:
604 @echo "Checking labels on filesystem types: ext2 ext3 xfs jfs"
c634db20 605 @if test -z "$(filesystems)"; then \
120988c4
CP
606 echo "No filesystems with extended attributes found!" ;\
607 false ;\
608 fi
c634db20 609 $(verbose) $(SETFILES) -v -n $(fcpath) $(filesystems)
120988c4
CP
610
611restorelabels:
612 @echo "Restoring labels on filesystem types: ext2 ext3 xfs jfs"
c634db20 613 @if test -z "$(filesystems)"; then \
120988c4
CP
614 echo "No filesystems with extended attributes found!" ;\
615 false ;\
616 fi
c634db20 617 $(verbose) $(SETFILES) -v $(fcpath) $(filesystems)
120988c4
CP
618
619relabel:
620 @echo "Relabeling filesystem types: ext2 ext3 xfs jfs"
c634db20 621 @if test -z "$(filesystems)"; then \
120988c4
CP
622 echo "No filesystems with extended attributes found!" ;\
623 false ;\
624 fi
c634db20 625 $(verbose) $(SETFILES) $(fcpath) $(filesystems)
120988c4
CP
626
627resetlabels:
628 @echo "Resetting labels on filesystem types: ext2 ext3 xfs jfs"
c634db20 629 @if test -z "$(filesystems)"; then \
120988c4
CP
630 echo "No filesystems with extended attributes found!" ;\
631 false ;\
632 fi
c634db20 633 $(verbose) $(SETFILES) -F $(fcpath) $(filesystems)
120988c4 634
102a59ba
CP
635########################################
636#
637# Clean everything
638#
0fbe15dc 639bare: clean
c634db20 640 rm -f $(polxml)
56e1b3d2
CP
641 rm -f $(layerxml)
642 rm -f $(modxml)
c634db20
CP
643 rm -f $(tunxml)
644 rm -f $(boolxml)
645 rm -f $(mod_conf)
646 rm -f $(booleans)
647 rm -fR $(htmldir)
648 rm -f $(tags)
c9f20d5b
CP
649# don't remove these files if we're given a local root
650ifndef LOCAL_ROOT
c634db20
CP
651 rm -f $(fcsort)
652 rm -f $(support)/*.pyc
653ifneq ($(generated_te),)
654 rm -f $(generated_te)
c767b14c 655endif
c634db20
CP
656ifneq ($(generated_if),)
657 rm -f $(generated_if)
c767b14c 658endif
c634db20
CP
659ifneq ($(generated_fc),)
660 rm -f $(generated_fc)
c767b14c 661endif
c9f20d5b 662endif
0fbe15dc 663
96fc0a45 664.PHONY: install-src install-appconfig install-headers generate xml conf html bare tags
b8c79823
CP
665.SUFFIXES:
666.SUFFIXES: .c