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