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