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