]> git.ipfire.org Git - people/stevee/selinux-policy.git/blame - refpolicy/Makefile
Add ctags Make target from Thomas Bleher.
[people/stevee/selinux-policy.git] / refpolicy / 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
8e0ef1f9
CP
26include build.conf
27
b4cd1533
CP
28# executable paths
29PREFIX := /usr
30BINDIR := $(PREFIX)/bin
31SBINDIR := $(PREFIX)/sbin
40a1f3db 32CHECKPOLICY := $(BINDIR)/checkpolicy
fb0a3a98 33CHECKMODULE := $(BINDIR)/checkmodule
c767b14c 34SEMODULE := $(SBINDIR)/semodule
fb0a3a98 35SEMOD_PKG := $(BINDIR)/semodule_package
547283e2 36LOADPOLICY := $(SBINDIR)/load_policy
b4cd1533 37SETFILES := $(SBINDIR)/setfiles
1beba1c6 38GENHOMEDIRCON := $(SBINDIR)/genhomedircon
fb0a3a98 39XMLLINT := $(BINDIR)/xmllint
8df65f13 40SECHECK := $(BINDIR)/sechecker
0447352a 41
c7b41e95
CP
42CFLAGS := -Wall
43
fb0a3a98 44# policy source layout
c04f2abe
CP
45POLDIR := policy
46MODDIR := $(POLDIR)/modules
47FLASKDIR := $(POLDIR)/flask
48SECCLASS := $(FLASKDIR)/security_classes
49ISIDS := $(FLASKDIR)/initial_sids
50AVS := $(FLASKDIR)/access_vectors
fb0a3a98
CP
51
52# policy building support tools
3a80ec29 53SUPPORT := support
95db4228 54GENXML := $(SUPPORT)/segenxml.py
3a80ec29 55GENDOC := $(SUPPORT)/sedoctool.py
c04f2abe 56GENPERM := $(SUPPORT)/genclassperms.py
254bbc7b 57FCSORT := $(SUPPORT)/fc_sort
84eb353c 58SETTUN := $(SUPPORT)/set_tunables
3a80ec29 59
fb0a3a98
CP
60# documentation paths
61DOCS = doc
62POLXML = $(DOCS)/policy.xml
63XMLDTD = $(DOCS)/policy.dtd
64LAYERXML = metadata.xml
65HTMLDIR = $(DOCS)/html
66DOCTEMPLATE = $(DOCS)/templates
67
68# config file paths
69GLOBALTUN := $(POLDIR)/global_tunables
4f9f30c8 70GLOBALBOOL := $(POLDIR)/global_booleans
fb0a3a98
CP
71MOD_CONF := $(POLDIR)/modules.conf
72TUNABLES := $(POLDIR)/tunables.conf
4f9f30c8 73BOOLEANS := $(POLDIR)/booleans.conf
fb0a3a98
CP
74
75# install paths
76TOPDIR = $(DESTDIR)/etc/selinux
77INSTALLDIR = $(TOPDIR)/$(NAME)
78SRCPATH = $(INSTALLDIR)/src
79USERPATH = $(INSTALLDIR)/users
80CONTEXTPATH = $(INSTALLDIR)/contexts
c767b14c
CP
81MODPKGDIR = $(DESTDIR)/usr/share/selinux/$(NAME)
82
83# compile strict policy if requested.
84ifneq ($(findstring strict,$(TYPE)),)
85 override M4PARAM += -D strict_policy
86endif
87
88# compile targeted policy if requested.
89ifneq ($(findstring targeted,$(TYPE)),)
90 override M4PARAM += -D targeted_policy
91endif
b4cd1533 92
134191be 93# enable MLS if requested.
a0824843 94ifneq ($(findstring -mls,$(TYPE)),)
134191be 95 override M4PARAM += -D enable_mls
c767b14c
CP
96 override CHECKPOLICY += -M
97 override CHECKMODULE += -M
134191be
CP
98endif
99
a0824843
CP
100# enable MLS if MCS requested.
101ifneq ($(findstring -mcs,$(TYPE)),)
102 override M4PARAM += -D enable_mcs
c767b14c
CP
103 override CHECKPOLICY += -M
104 override CHECKMODULE += -M
b67488e3
CP
105endif
106
25a0c61f
CP
107# enable distribution-specific policy
108ifneq ($(DISTRO),)
109 override M4PARAM += -D distro_$(DISTRO)
110endif
111
b07eaef9
CP
112# enable polyinstantiation
113ifeq ($(POLY),y)
114 override M4PARAM += -D enable_polyinstantiation
115endif
116
b67488e3 117ifneq ($(OUTPUT_POLICY),)
c767b14c 118 override CHECKPOLICY += -c $(OUTPUT_POLICY)
b67488e3
CP
119endif
120
121ifeq ($(NAME),)
122 NAME := $(TYPE)
134191be
CP
123endif
124
142e9f40
CP
125ifeq ($(DIRECT_INITRC),y)
126 override M4PARAM += -D direct_sysadm_daemon
127endif
128
ee7f66b0
CP
129override M4PARAM += -D hide_broken_symptoms
130
37227dcd
CP
131# we need exuberant ctags; unfortunately it is named
132# differently on different distros
133ifeq ($(DISTRO),debian)
134 CTAGS := ctags-exuberant
135endif
136
137ifeq ($(DISTRO),gentoo)
138 CTAGS := exuberant-ctags
139endif
140
141ifeq ($(CTAGS),)
142 CTAGS := ctags
143endif
144
b4cd1533 145# determine the policy version and current kernel version if possible
134191be 146PV := $(shell $(CHECKPOLICY) -V |cut -f 1 -d ' ')
b4cd1533
CP
147KV := $(shell cat /selinux/policyvers)
148
149# dont print version warnings if we are unable to determine
150# the currently running kernel's policy version
151ifeq ($(KV),)
134191be 152 KV := $(PV)
b4cd1533
CP
153endif
154
fb0a3a98 155M4SUPPORT = $(wildcard $(POLDIR)/support/*.spt)
0fbe15dc 156
c0e4fe2c 157APPCONF := config/appconfig-$(TYPE)
c9a26b3e 158APPDIR := $(CONTEXTPATH)
049e11af 159APPFILES := $(addprefix $(APPDIR)/,default_contexts default_type initrc_context failsafe_context userhelper_context removable_context dbus_contexts customizable_types) $(CONTEXTPATH)/files/media
2926f9c7 160CONTEXTFILES += $(wildcard $(APPCONF)/*_context*) $(APPCONF)/media
bdb2fac0 161USER_FILES := $(POLDIR)/users
c9a26b3e 162
57869a68 163ALL_LAYERS := $(filter-out $(MODDIR)/CVS,$(shell find $(wildcard $(MODDIR)/*) -maxdepth 0 -type d))
e12e5738
CP
164
165GENERATED_TE := $(basename $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.te.in)))
166GENERATED_IF := $(basename $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.if.in)))
167GENERATED_FC := $(basename $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.fc.in)))
168
8ae194f6
CP
169# sort here since it removes duplicates, which can happen
170# when a generated file is already generated
171DETECTED_MODS := $(sort $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.te)) $(GENERATED_TE))
19db6ba5 172
fb0a3a98 173# modules.conf setting for base module
e8b3e30a 174MODBASE := base
fb0a3a98 175
e0a9001b 176# modules.conf setting for loadable module
e8b3e30a 177MODMOD := module
fb0a3a98 178
e0a9001b
CP
179# modules.conf setting for unused module
180MODUNUSED := off
181
fb0a3a98 182# extract settings from modules.conf
c767b14c
CP
183BASE_MODS := $(addsuffix .te,$(shell awk '/^[[:blank:]]*[[:alpha:]]/{ if ($$3 == "$(MODBASE)") print $$1 }' $(MOD_CONF) 2> /dev/null))
184MOD_MODS := $(addsuffix .te,$(shell awk '/^[[:blank:]]*[[:alpha:]]/{ if ($$3 == "$(MODMOD)") print $$1 }' $(MOD_CONF) 2> /dev/null))
e0a9001b 185OFF_MODS := $(addsuffix .te,$(shell awk '/^[[:blank:]]*[[:alpha:]]/{ if ($$3 == "$(MODUNUSED)") print $$1 }' $(MOD_CONF) 2> /dev/null))
712566ee 186
b4cd1533
CP
187########################################
188#
fb0a3a98 189# Load appropriate rules
b4cd1533 190#
b4cd1533 191
fb0a3a98
CP
192ifeq ($(MONOLITHIC),y)
193 include Rules.monolithic
194else
195 include Rules.modular
b4cd1533 196endif
b4cd1533 197
88d14a22
CP
198########################################
199#
fb0a3a98 200# Generated files
b4cd1533 201#
f2e4ab3a 202$(MODDIR)/kernel/corenetwork.if: $(MODDIR)/kernel/corenetwork.if.m4 $(MODDIR)/kernel/corenetwork.if.in
61bbe531
CP
203 @echo "#" > $@
204 @echo "# This is a generated file! Instead of modifying this file, the" >> $@
205 @echo "# $(notdir $@).in or $(notdir $@).m4 file should be modified." >> $@
206 @echo "#" >> $@
207 $(QUIET) cat $(MODDIR)/kernel/corenetwork.if.in >> $@
f2e4ab3a 208 $(QUIET) egrep "^[[:blank:]]*network_(interface|node|port)\(.*\)" $(@:.if=.te).in \
cf6141a7 209 | m4 -D self_contained_policy $(M4PARAM) $(MODDIR)/kernel/corenetwork.if.m4 - \
f2e4ab3a 210 | sed -e 's/dollarsone/\$$1/g' -e 's/dollarszero/\$$0/g' >> $@
f2e4ab3a
CP
211
212$(MODDIR)/kernel/corenetwork.te: $(MODDIR)/kernel/corenetwork.te.m4 $(MODDIR)/kernel/corenetwork.te.in
61bbe531
CP
213 @echo "#" > $@
214 @echo "# This is a generated file! Instead of modifying this file, the" >> $@
215 @echo "# $(notdir $@).in or $(notdir $@).m4 file should be modified." >> $@
216 @echo "#" >> $@
cf6141a7 217 $(QUIET) m4 -D self_contained_policy $(M4PARAM) $^ \
61bbe531 218 | sed -e 's/dollarsone/\$$1/g' -e 's/dollarszero/\$$0/g' >> $@
f2e4ab3a 219
84eb353c
CP
220########################################
221#
222# Create config files
223#
4f9f30c8 224conf: $(MOD_CONF) $(BOOLEANS) $(GENERATED_TE) $(GENERATED_IF) $(GENERATED_FC)
d2d6c8ce 225
4f9f30c8
CP
226$(MOD_CONF) $(BOOLEANS): $(POLXML)
227 @echo "Updating $(MOD_CONF) and $(BOOLEANS)"
228 $(QUIET) cd $(DOCS) && ../$(GENDOC) -t ../$(BOOLEANS) -m ../$(MOD_CONF) -x ../$(POLXML)
84eb353c 229
6d314fd3
CP
230########################################
231#
232# Documentation generation
233#
234
d2d6c8ce 235# minimal dependencies here, because we don't want to rebuild
84eb353c 236# this and its dependents every time the dependencies
19db6ba5
CP
237# change. Also use all .if files here, rather then just the
238# enabled modules.
d233bfce 239$(POLXML): $(DETECTED_MODS:.te=.if) $(foreach dir,$(ALL_LAYERS),$(dir)/$(LAYERXML))
88c72f44 240 @echo "Creating $@"
84eb353c 241 @mkdir -p tmp
004db90d 242 $(QUIET) echo '<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>' > $@
95db4228 243 $(QUIET) echo '<!DOCTYPE policy SYSTEM "$(notdir $(XMLDTD))">' >> $@
4f9f30c8 244 $(QUIET) $(GENXML) -w -m $(LAYERXML) -t $(GLOBALTUN) -b $(GLOBALBOOL) $(ALL_LAYERS) >> $@
0447352a
CP
245 $(QUIET) if test -x $(XMLLINT) && test -f $(XMLDTD); then \
246 $(XMLLINT) --noout --dtdvalid $(XMLDTD) $@ ;\
004db90d 247 fi
6d314fd3 248
12b559a4 249html: $(POLXML)
2de03f30 250 @echo "Building html interface reference documentation in $(HTMLDIR)"
20030ef5 251 @mkdir -p $(HTMLDIR)
12b559a4 252 $(QUIET) cd $(DOCS) && ../$(GENDOC) -d ../$(HTMLDIR) -T ../$(DOCTEMPLATE) -x ../$(POLXML)
20030ef5
CP
253 $(QUIET) cp $(DOCTEMPLATE)/*.css $(HTMLDIR)
254
c9a26b3e
CP
255########################################
256#
257# Runtime binary policy patching of users
258#
1fb83a76 259$(USERPATH)/system.users: $(M4SUPPORT) tmp/generated_definitions.conf $(USER_FILES)
c9a26b3e
CP
260 @mkdir -p $(USERPATH)
261 @echo "Installing system.users"
262 @echo "# " > tmp/system.users
263 @echo "# Do not edit this file. " >> tmp/system.users
264 @echo "# This file is replaced on reinstalls of this policy." >> tmp/system.users
265 @echo "# Please edit local.users to make local changes." >> tmp/system.users
266 @echo "#" >> tmp/system.users
7dca64fa
CP
267 $(QUIET) m4 -D self_contained_policy $(M4PARAM) $^ | sed -r -e 's/^[[:blank:]]+//' \
268 -e '/^[[:blank:]]*($$|#)/d' >> tmp/system.users
c9a26b3e
CP
269 $(QUIET) install -m 644 tmp/system.users $@
270
1beba1c6 271$(USERPATH)/local.users: config/local.users
c9a26b3e
CP
272 @mkdir -p $(USERPATH)
273 @echo "Installing local.users"
c7b41e95 274 $(QUIET) install -b -m 644 $< $@
c9a26b3e
CP
275
276########################################
277#
278# Appconfig files
279#
280install-appconfig: $(APPFILES)
281
4f9f30c8 282$(INSTALLDIR)/booleans: $(BOOLEANS)
1beba1c6 283 @mkdir -p $(INSTALLDIR)
c43ecfc3 284 $(QUIET) sed -r -e 's/false/0/g' -e 's/true/1/g' \
7dca64fa 285 -e '/^[[:blank:]]*($$|#)/d' $(BOOLEANS) | sort > tmp/booleans
1beba1c6
CP
286 $(QUIET) install -m 644 tmp/booleans $@
287
2926f9c7 288$(CONTEXTPATH)/files/media: $(APPCONF)/media
1beba1c6
CP
289 @mkdir -p $(CONTEXTPATH)/files/
290 $(QUIET) install -m 644 $< $@
c9a26b3e 291
2926f9c7 292$(APPDIR)/default_contexts: $(APPCONF)/default_contexts
1beba1c6
CP
293 @mkdir -p $(APPDIR)
294 $(QUIET) install -m 644 $< $@
c9a26b3e 295
2926f9c7 296$(APPDIR)/removable_context: $(APPCONF)/removable_context
1beba1c6
CP
297 @mkdir -p $(APPDIR)
298 $(QUIET) install -m 644 $< $@
c9a26b3e 299
2926f9c7 300$(APPDIR)/default_type: $(APPCONF)/default_type
1beba1c6
CP
301 @mkdir -p $(APPDIR)
302 $(QUIET) install -m 644 $< $@
c9a26b3e 303
2926f9c7 304$(APPDIR)/userhelper_context: $(APPCONF)/userhelper_context
1beba1c6
CP
305 @mkdir -p $(APPDIR)
306 $(QUIET) install -m 644 $< $@
c9a26b3e 307
2926f9c7 308$(APPDIR)/initrc_context: $(APPCONF)/initrc_context
1beba1c6
CP
309 @mkdir -p $(APPDIR)
310 $(QUIET) install -m 644 $< $@
c9a26b3e 311
2926f9c7 312$(APPDIR)/failsafe_context: $(APPCONF)/failsafe_context
1beba1c6
CP
313 @mkdir -p $(APPDIR)
314 $(QUIET) install -m 644 $< $@
c9a26b3e 315
2926f9c7 316$(APPDIR)/dbus_contexts: $(APPCONF)/dbus_contexts
1beba1c6
CP
317 @mkdir -p $(APPDIR)
318 $(QUIET) install -m 644 $< $@
c9a26b3e 319
2926f9c7 320$(APPDIR)/users/root: $(APPCONF)/root_default_contexts
1beba1c6
CP
321 @mkdir -p $(APPDIR)/users
322 $(QUIET) install -m 644 $< $@
c9a26b3e 323
c592e52e
CP
324########################################
325#
326# Install policy sources
327#
328install-src:
329 rm -rf $(SRCPATH)/policy.old
330 -mv $(SRCPATH)/policy $(SRCPATH)/policy.old
331 mkdir -p $(SRCPATH)/policy
332 cp -R . $(SRCPATH)/policy
333
37227dcd
CP
334########################################
335#
336# Generate tags file
337#
338tags:
339 @($(CTAGS) --version | grep -q Exuberant) || (echo ERROR: Need exuberant-ctags to function!; exit 1)
340 @LC_ALL=C $(CTAGS) --langdef=te --langmap=te:..te.if.spt \
341 --regex-te='/^type[ \t]+(\w+)(,|;)/\1/t,type/' \
342 --regex-te='/^typealias[ \t]+\w+[ \t+]+alias[ \t]+(\w+);/\1/t,type/' \
343 --regex-te='/^attribute[ \t]+(\w+);/\1/a,attribute/' \
344 --regex-te='/^[ \t]*define\(`(\w+)/\1/d,define/' \
345 --regex-te='/^[ \t]*interface\(`(\w+)/\1/i,interface/' \
346 --regex-te='/^[ \t]*bool[ \t]+(\w+)/\1/b,bool/' policy/modules/*/*.{if,te} policy/support/*.spt
347
102a59ba
CP
348########################################
349#
350# Clean everything
351#
0fbe15dc 352bare: clean
12b559a4 353 rm -f $(POLXML)
254bbc7b
CP
354 rm -f $(SUPPORT)/*.pyc
355 rm -f $(FCSORT)
19db6ba5 356 rm -f $(MOD_CONF)
4f9f30c8 357 rm -f $(BOOLEANS)
20030ef5 358 rm -fR $(HTMLDIR)
37227dcd 359 rm -f tags
c767b14c
CP
360ifneq ($(GENERATED_TE),)
361 rm -f $(GENERATED_TE)
362endif
363ifneq ($(GENERATED_IF),)
364 rm -f $(GENERATED_IF)
365endif
366ifneq ($(GENERATED_FC),)
367 rm -f $(GENERATED_FC)
368endif
0fbe15dc 369
37227dcd 370.PHONY: install-src install-appconfig conf html bare tags
b8c79823
CP
371.SUFFIXES:
372.SUFFIXES: .c