]> git.ipfire.org Git - people/stevee/selinux-policy.git/blame - refpolicy/Makefile
initial commit
[people/stevee/selinux-policy.git] / refpolicy / Makefile
CommitLineData
b4cd1533
CP
1########################################
2#
3# Configurable portions of the Makefile
4#
5
6# Build compatibility policies
7POLICYCOMPAT = -c 18
8
9# set distribution
10#override M4PARAM += -D distro_redhat
11
12# Uncomment this to disable command echoing
13#QUIET:=@
14
15########################################
16#
17# Invariant portions of the Makefile
18#
19
20# executable paths
21PREFIX := /usr
22BINDIR := $(PREFIX)/bin
23SBINDIR := $(PREFIX)/sbin
24CHECKPOLICY := $(BINDIR)/checkpolicy
25SETFILES := $(SBINDIR)/setfiles
26
27# determine the policy version and current kernel version if possible
28PV := $(shell $(CHECKPOLICY) $(POLICYCOMPAT) -V |cut -f 1 -d ' ')
29KV := $(shell cat /selinux/policyvers)
30
31# dont print version warnings if we are unable to determine
32# the currently running kernel's policy version
33ifeq ($(KV),)
34KV := $(PV)
35endif
36
37FC := file_contexts
38POLVER := policy.$(PV)
39TYPE := strict
40
41# install paths
42TOPDIR = $(DESTDIR)/etc/selinux
43INSTALLDIR = $(TOPDIR)/$(TYPE)
44POLICYPATH = $(INSTALLDIR)/policy
45SRCPATH = $(INSTALLDIR)/src
46USERPATH = $(INSTALLDIR)/users
47CONTEXTPATH = $(INSTALLDIR)/contexts
48LOADPATH = $(POLICYPATH)/$(POLVER)
49FCPATH = $(CONTEXTPATH)/files/file_contexts
50HOMEDIRPATH = $(CONTEXTPATH)/files/homedir_template
51
52BASE_MODULE = kernel
53FLASKDIR = $(BASE_MODULE)/flask/
54MISCDIR = $(BASE_MODULE)/misc/
55
56DETECTED_DIRS := $(shell find $(wildcard *) -maxdepth 0 -type d)
57ALL_MODULES := $(filter-out tmp,$(DETECTED_DIRS))
58
59PRE_TE_FILES := $(addprefix $(FLASKDIR),security_classes initial_sids access_vectors)
60ALL_INTERFACES := $(foreach dir,$(ALL_MODULES),$(wildcard $(dir)/*.if))
61ALL_TE_FILES := $(foreach dir,$(ALL_MODULES),$(wildcard $(dir)/*.te))
62POST_TE_FILES := $(addprefix $(MISCDIR),users constraints mls initial_sid_contexts fs_use genfs_contexts)
63
64ALL_FC_FILES := $(foreach dir,$(ALL_MODULES),$(wildcard $(dir)/*.fc))
65
66POLICY_SECTIONS := tmp/pre_te_files.conf tmp/generated_definitions.conf tmp/all_interfaces.conf tmp/all_attributes.conf tmp/only_te_rules.conf tmp/all_post.conf
67
68override M4PARAM += -D monolithic_policy
69
70########################################
71#
72# default action: build policy locally
73#
74default: policy
75
76policy: $(POLVER)
77
78install: $(LOADPATH)
79
80########################################
81#
82# Build a binary policy locally
83#
84$(POLVER): policy.conf
85ifneq ($(PV),$(KV))
86 @echo
87 @echo "WARNING: Policy version mismatch! Is your POLICYCOMPAT set correctly?"
88 @echo
89endif
90 $(QUIET) $(CHECKPOLICY) $(POLICYCOMPAT) $^ -o $(POLVER)
91
92########################################
93#
94# Install a binary policy
95#
96$(LOADPATH): policy.conf
97 @mkdir -p $(POLICYPATH)
98ifneq ($(PV),$(KV))
99 @echo
100 @echo "WARNING: Policy version mismatch! Is your POLICYCOMPAT set correctly?"
101 @echo
102endif
103 $(QUIET) $(CHECKPOLICY) $(POLICYCOMPAT) $^ -o $(LOADPATH)
104
105########################################
106#
107# Construct a monolithic policy.conf
108#
109policy.conf: $(POLICY_SECTIONS)
110 $(QUIET) m4 $(M4PARAM) $^ > tmp/$@.tmp
111 $(QUIET) sed -e /^portcon/d -e /^nodecon/d -e /^netifcon/d < tmp/$@.tmp > $@
112 $(QUIET) # the ordering of these ocontexts matters:
113 $(QUIET) grep ^portcon tmp/$@.tmp >> $@ || true
114 $(QUIET) grep ^netifcon tmp/$@.tmp >> $@ || true
115 $(QUIET) grep ^nodecon tmp/$@.tmp >> $@ || true
116
117tmp/pre_te_files.conf: $(PRE_TE_FILES)
118 @test -d tmp || mkdir -p tmp
119 $(QUIET) cat $^ > $@
120
121tmp/generated_definitions.conf: $(ALL_MODULES) $(ALL_TE_FILES) $(BASE_MODULE)/corenetwork.if $(BASE_MODULE)/corenetwork.te
122 @test -d tmp || mkdir -p tmp
123 $(QUIET) echo "define(\`per_userdomain_templates',\`" > $@
124 $(QUIET) for i in $(ALL_MODULES); do \
125 echo "ifdef(\`""$$i""_per_userdomain_template',\`""$$i""_per_userdomain_template("'$$1'")')" \
126 >> $@ ;\
127 done
128 $(QUIET) echo "')" >> $@
129 $(QUIET) for i in $(notdir $(ALL_TE_FILES)); do \
130 echo "define(\`$$i')" >> $@ ;\
131 done
132 $(QUIET) m4 $(M4PARAM) -D interface_pass $(BASE_MODULE)/corenetwork.if $(BASE_MODULE)/corenetwork.te \
133 | sed -e 's/dollarsone/\$$1/g' -e 's/dollarstwo/\$$2/g' >> $@
134
135tmp/all_interfaces.conf: $(ALL_INTERFACES)
136 @test -d tmp || mkdir -p tmp
137 $(QUIET) cat $^ > $@
138
139tmp/all_te_files.conf: $(ALL_TE_FILES)
140 @test -d tmp || mkdir -p tmp
141 $(QUIET) cat $^ > $@
142
143tmp/post_te_files.conf: $(POST_TE_FILES)
144 @test -d tmp || mkdir -p tmp
145 $(QUIET) cat $^ > $@
146
147# extract attributes and put them first. extract post te stuff
148# like genfscon and put last. portcon, nodecon, and netifcon
149# is delayed since they are generated by m4
150tmp/all_attributes.conf tmp/only_te_rules.conf tmp/all_post.conf: tmp/all_te_files.conf tmp/post_te_files.conf
151 $(QUIET) grep ^attribute tmp/all_te_files.conf > tmp/all_attributes.conf || true
152 $(QUIET) cat tmp/post_te_files.conf > tmp/all_post.conf
153 $(QUIET) grep ^genfscon tmp/all_te_files.conf >> tmp/all_post.conf || true
154 $(QUIET) sed -e /^attribute/d -e /^genfscon/d < tmp/all_te_files.conf > tmp/only_te_rules.conf
155
156########################################
157#
158# Construct file_contexts
159#
160$(FC): $(ALL_FC_FILES)
161 @test -d tmp || mkdir -p tmp
162 $(QUIET) m4 $(M4PARAM) $^ > $@
163
164########################################
165#
166# Filesystem labeling
167#
168FILESYSTEMS=`mount | grep -v "context=" | egrep -v '\((|.*,)bind(,.*|)\)' | awk '/(ext[23]| xfs| jfs).*rw/{print $$3}';`
169
170checklabels: $(SETFILES)
171 $(QUIET) $(SETFILES) -v -n $(FC) $(FILESYSTEMS)
172
173restorelabels: $(SETFILES)
174 $(QUIET) $(SETFILES) -v $(FC) $(FILESYSTEMS)
175
176relabel: $(FC) $(SETFILES)
177 $(QUIET) $(SETFILES) $(FC) $(FILESYSTEMS)
178
179clean:
180 rm -fR tmp
181 rm -f policy.conf
182 rm -f policy.$(PV)
183 rm -f $(FC)
184
185.PHONY: default clean policy install