]> git.ipfire.org Git - people/stevee/selinux-policy.git/blame_incremental - refpolicy/Makefile
add lpr policy to lpd
[people/stevee/selinux-policy.git] / refpolicy / Makefile
... / ...
CommitLineData
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#
17#
18# Please see build.conf for policy build options.
19#
20
21########################################
22#
23# NO OPTIONS BELOW HERE
24#
25
26include build.conf
27
28# executable paths
29PREFIX := /usr
30BINDIR := $(PREFIX)/bin
31SBINDIR := $(PREFIX)/sbin
32CHECKPOLICY := $(BINDIR)/checkpolicy
33CHECKMODULE := $(BINDIR)/checkmodule
34SEMODULE := $(SBINDIR)/semodule
35SEMOD_PKG := $(BINDIR)/semodule_package
36LOADPOLICY := $(SBINDIR)/load_policy
37SETFILES := $(SBINDIR)/setfiles
38GENHOMEDIRCON := $(SBINDIR)/genhomedircon
39XMLLINT := $(BINDIR)/xmllint
40SECHECK := $(BINDIR)/sechecker
41
42CFLAGS := -Wall
43
44# policy source layout
45POLDIR := policy
46MODDIR := $(POLDIR)/modules
47FLASKDIR := $(POLDIR)/flask
48SECCLASS := $(FLASKDIR)/security_classes
49ISIDS := $(FLASKDIR)/initial_sids
50AVS := $(FLASKDIR)/access_vectors
51
52# policy building support tools
53SUPPORT := support
54GENXML := $(SUPPORT)/segenxml.py
55GENDOC := $(SUPPORT)/sedoctool.py
56GENPERM := $(SUPPORT)/genclassperms.py
57FCSORT := $(SUPPORT)/fc_sort
58SETTUN := $(SUPPORT)/set_tunables
59
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
70GLOBALBOOL := $(POLDIR)/global_booleans
71MOD_CONF := $(POLDIR)/modules.conf
72TUNABLES := $(POLDIR)/tunables.conf
73BOOLEANS := $(POLDIR)/booleans.conf
74
75# install paths
76TOPDIR = $(DESTDIR)/etc/selinux
77INSTALLDIR = $(TOPDIR)/$(NAME)
78SRCPATH = $(INSTALLDIR)/src
79USERPATH = $(INSTALLDIR)/users
80CONTEXTPATH = $(INSTALLDIR)/contexts
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
92
93# enable MLS if requested.
94ifneq ($(findstring -mls,$(TYPE)),)
95 override M4PARAM += -D enable_mls
96 override CHECKPOLICY += -M
97 override CHECKMODULE += -M
98endif
99
100# enable MLS if MCS requested.
101ifneq ($(findstring -mcs,$(TYPE)),)
102 override M4PARAM += -D enable_mcs
103 override CHECKPOLICY += -M
104 override CHECKMODULE += -M
105endif
106
107# enable distribution-specific policy
108ifneq ($(DISTRO),)
109 override M4PARAM += -D distro_$(DISTRO)
110endif
111
112# enable polyinstantiation
113ifeq ($(POLY),y)
114 override M4PARAM += -D enable_polyinstantiation
115endif
116
117ifneq ($(OUTPUT_POLICY),)
118 override CHECKPOLICY += -c $(OUTPUT_POLICY)
119endif
120
121ifeq ($(NAME),)
122 NAME := $(TYPE)
123endif
124
125ifeq ($(DIRECT_INITRC),y)
126 override M4PARAM += -D direct_sysadm_daemon
127endif
128
129override M4PARAM += -D hide_broken_symptoms
130
131# determine the policy version and current kernel version if possible
132PV := $(shell $(CHECKPOLICY) -V |cut -f 1 -d ' ')
133KV := $(shell cat /selinux/policyvers)
134
135# dont print version warnings if we are unable to determine
136# the currently running kernel's policy version
137ifeq ($(KV),)
138 KV := $(PV)
139endif
140
141M4SUPPORT = $(wildcard $(POLDIR)/support/*.spt)
142
143APPCONF := config/appconfig-$(TYPE)
144APPDIR := $(CONTEXTPATH)
145APPFILES := $(addprefix $(APPDIR)/,default_contexts default_type initrc_context failsafe_context userhelper_context removable_context dbus_contexts customizable_types) $(CONTEXTPATH)/files/media
146CONTEXTFILES += $(wildcard $(APPCONF)/*_context*) $(APPCONF)/media
147USER_FILES := $(POLDIR)/users
148
149ALL_LAYERS := $(filter-out $(MODDIR)/CVS,$(shell find $(wildcard $(MODDIR)/*) -maxdepth 0 -type d))
150
151GENERATED_TE := $(basename $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.te.in)))
152GENERATED_IF := $(basename $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.if.in)))
153GENERATED_FC := $(basename $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.fc.in)))
154
155# sort here since it removes duplicates, which can happen
156# when a generated file is already generated
157DETECTED_MODS := $(sort $(foreach dir,$(ALL_LAYERS),$(wildcard $(dir)/*.te)) $(GENERATED_TE))
158
159# modules.conf setting for base module
160MODBASE := base
161
162# modules.conf setting for loadable module
163MODMOD := module
164
165# modules.conf setting for unused module
166MODUNUSED := off
167
168# extract settings from modules.conf
169BASE_MODS := $(addsuffix .te,$(shell awk '/^[[:blank:]]*[[:alpha:]]/{ if ($$3 == "$(MODBASE)") print $$1 }' $(MOD_CONF) 2> /dev/null))
170MOD_MODS := $(addsuffix .te,$(shell awk '/^[[:blank:]]*[[:alpha:]]/{ if ($$3 == "$(MODMOD)") print $$1 }' $(MOD_CONF) 2> /dev/null))
171OFF_MODS := $(addsuffix .te,$(shell awk '/^[[:blank:]]*[[:alpha:]]/{ if ($$3 == "$(MODUNUSED)") print $$1 }' $(MOD_CONF) 2> /dev/null))
172
173########################################
174#
175# Load appropriate rules
176#
177
178ifeq ($(MONOLITHIC),y)
179 include Rules.monolithic
180else
181 include Rules.modular
182endif
183
184########################################
185#
186# Generated files
187#
188$(MODDIR)/kernel/corenetwork.if: $(MODDIR)/kernel/corenetwork.if.m4 $(MODDIR)/kernel/corenetwork.if.in
189 @echo "#" > $@
190 @echo "# This is a generated file! Instead of modifying this file, the" >> $@
191 @echo "# $(notdir $@).in or $(notdir $@).m4 file should be modified." >> $@
192 @echo "#" >> $@
193 $(QUIET) cat $(MODDIR)/kernel/corenetwork.if.in >> $@
194 $(QUIET) egrep "^[[:blank:]]*network_(interface|node|port)\(.*\)" $(@:.if=.te).in \
195 | m4 -D self_contained_policy $(M4PARAM) $(MODDIR)/kernel/corenetwork.if.m4 - \
196 | sed -e 's/dollarsone/\$$1/g' -e 's/dollarszero/\$$0/g' >> $@
197
198$(MODDIR)/kernel/corenetwork.te: $(MODDIR)/kernel/corenetwork.te.m4 $(MODDIR)/kernel/corenetwork.te.in
199 @echo "#" > $@
200 @echo "# This is a generated file! Instead of modifying this file, the" >> $@
201 @echo "# $(notdir $@).in or $(notdir $@).m4 file should be modified." >> $@
202 @echo "#" >> $@
203 $(QUIET) m4 -D self_contained_policy $(M4PARAM) $^ \
204 | sed -e 's/dollarsone/\$$1/g' -e 's/dollarszero/\$$0/g' >> $@
205
206########################################
207#
208# Create config files
209#
210conf: $(MOD_CONF) $(BOOLEANS) $(GENERATED_TE) $(GENERATED_IF) $(GENERATED_FC)
211
212$(MOD_CONF) $(BOOLEANS): $(POLXML)
213 @echo "Updating $(MOD_CONF) and $(BOOLEANS)"
214 $(QUIET) cd $(DOCS) && ../$(GENDOC) -t ../$(BOOLEANS) -m ../$(MOD_CONF) -x ../$(POLXML)
215
216########################################
217#
218# Documentation generation
219#
220
221# minimal dependencies here, because we don't want to rebuild
222# this and its dependents every time the dependencies
223# change. Also use all .if files here, rather then just the
224# enabled modules.
225$(POLXML): $(DETECTED_MODS:.te=.if) $(foreach dir,$(ALL_LAYERS),$(dir)/$(LAYERXML))
226 @echo "Creating $@"
227 @mkdir -p tmp
228 $(QUIET) echo '<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>' > $@
229 $(QUIET) echo '<!DOCTYPE policy SYSTEM "$(notdir $(XMLDTD))">' >> $@
230 $(QUIET) $(GENXML) -w -m $(LAYERXML) -t $(GLOBALTUN) -b $(GLOBALBOOL) $(ALL_LAYERS) >> $@
231 $(QUIET) if test -x $(XMLLINT) && test -f $(XMLDTD); then \
232 $(XMLLINT) --noout --dtdvalid $(XMLDTD) $@ ;\
233 fi
234
235html: $(POLXML)
236 @mkdir -p $(HTMLDIR)
237 $(QUIET) cd $(DOCS) && ../$(GENDOC) -d ../$(HTMLDIR) -T ../$(DOCTEMPLATE) -x ../$(POLXML)
238 $(QUIET) cp $(DOCTEMPLATE)/*.css $(HTMLDIR)
239
240########################################
241#
242# Runtime binary policy patching of users
243#
244$(USERPATH)/system.users: $(M4SUPPORT) tmp/generated_definitions.conf $(USER_FILES)
245 @mkdir -p $(USERPATH)
246 @echo "Installing system.users"
247 @echo "# " > tmp/system.users
248 @echo "# Do not edit this file. " >> tmp/system.users
249 @echo "# This file is replaced on reinstalls of this policy." >> tmp/system.users
250 @echo "# Please edit local.users to make local changes." >> tmp/system.users
251 @echo "#" >> tmp/system.users
252 $(QUIET) m4 -D self_contained_policy $(M4PARAM) $^ | \
253 egrep -v "^[[:blank:]]*($$|#)" | \
254 sed -r -e 's/^[[:blank:]]+//' >> tmp/system.users
255 $(QUIET) install -m 644 tmp/system.users $@
256
257$(USERPATH)/local.users: config/local.users
258 @mkdir -p $(USERPATH)
259 @echo "Installing local.users"
260 $(QUIET) install -b -m 644 $< $@
261
262########################################
263#
264# Appconfig files
265#
266install-appconfig: $(APPFILES)
267
268$(INSTALLDIR)/booleans: $(BOOLEANS)
269 @mkdir -p $(INSTALLDIR)
270 $(QUIET) egrep '^[[:blank:]]*[[:alpha:]]' $(BOOLEANS) \
271 | sed -e 's/false/0/g' -e 's/true/1/g' > tmp/booleans
272 $(QUIET) install -m 644 tmp/booleans $@
273
274$(CONTEXTPATH)/files/media: $(APPCONF)/media
275 @mkdir -p $(CONTEXTPATH)/files/
276 $(QUIET) install -m 644 $< $@
277
278$(APPDIR)/default_contexts: $(APPCONF)/default_contexts
279 @mkdir -p $(APPDIR)
280 $(QUIET) install -m 644 $< $@
281
282$(APPDIR)/removable_context: $(APPCONF)/removable_context
283 @mkdir -p $(APPDIR)
284 $(QUIET) install -m 644 $< $@
285
286$(APPDIR)/default_type: $(APPCONF)/default_type
287 @mkdir -p $(APPDIR)
288 $(QUIET) install -m 644 $< $@
289
290$(APPDIR)/userhelper_context: $(APPCONF)/userhelper_context
291 @mkdir -p $(APPDIR)
292 $(QUIET) install -m 644 $< $@
293
294$(APPDIR)/initrc_context: $(APPCONF)/initrc_context
295 @mkdir -p $(APPDIR)
296 $(QUIET) install -m 644 $< $@
297
298$(APPDIR)/failsafe_context: $(APPCONF)/failsafe_context
299 @mkdir -p $(APPDIR)
300 $(QUIET) install -m 644 $< $@
301
302$(APPDIR)/dbus_contexts: $(APPCONF)/dbus_contexts
303 @mkdir -p $(APPDIR)
304 $(QUIET) install -m 644 $< $@
305
306$(APPDIR)/users/root: $(APPCONF)/root_default_contexts
307 @mkdir -p $(APPDIR)/users
308 $(QUIET) install -m 644 $< $@
309
310########################################
311#
312# Install policy sources
313#
314install-src:
315 rm -rf $(SRCPATH)/policy.old
316 -mv $(SRCPATH)/policy $(SRCPATH)/policy.old
317 mkdir -p $(SRCPATH)/policy
318 cp -R . $(SRCPATH)/policy
319
320########################################
321#
322# Clean everything
323#
324bare: clean
325 rm -f $(POLXML)
326 rm -f $(SUPPORT)/*.pyc
327 rm -f $(FCSORT)
328 rm -f $(MOD_CONF)
329 rm -f $(BOOLEANS)
330 rm -fR $(HTMLDIR)
331ifneq ($(GENERATED_TE),)
332 rm -f $(GENERATED_TE)
333endif
334ifneq ($(GENERATED_IF),)
335 rm -f $(GENERATED_IF)
336endif
337ifneq ($(GENERATED_FC),)
338 rm -f $(GENERATED_FC)
339endif
340
341.PHONY: install-src install-appconfig conf html bare
342.SUFFIXES:
343.SUFFIXES: .c