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