xref: /aosp_15_r20/external/selinux/checkpolicy/Makefile (revision 2d543d20722ada2425b5bdab9d0d1d29470e7bba)
1*2d543d20SAndroid Build Coastguard Worker#
2*2d543d20SAndroid Build Coastguard Worker# Makefile for building the checkpolicy program
3*2d543d20SAndroid Build Coastguard Worker#
4*2d543d20SAndroid Build Coastguard WorkerLINGUAS ?=
5*2d543d20SAndroid Build Coastguard WorkerPREFIX ?= /usr
6*2d543d20SAndroid Build Coastguard WorkerBINDIR ?= $(PREFIX)/bin
7*2d543d20SAndroid Build Coastguard WorkerMANDIR ?= $(PREFIX)/share/man
8*2d543d20SAndroid Build Coastguard WorkerTARGETS = checkpolicy checkmodule
9*2d543d20SAndroid Build Coastguard Worker
10*2d543d20SAndroid Build Coastguard WorkerLEX = flex
11*2d543d20SAndroid Build Coastguard WorkerYACC = bison -y
12*2d543d20SAndroid Build Coastguard Worker
13*2d543d20SAndroid Build Coastguard WorkerCFLAGS ?= -g -Wall -Werror -Wshadow -O2 -fno-strict-aliasing
14*2d543d20SAndroid Build Coastguard Worker
15*2d543d20SAndroid Build Coastguard Worker# If no specific libsepol.a is specified, fall back on LDFLAGS search path
16*2d543d20SAndroid Build Coastguard Worker# Otherwise, as $(LIBSEPOLA) already appears in the dependencies, there
17*2d543d20SAndroid Build Coastguard Worker# is no need to define a value for LDLIBS_LIBSEPOLA
18*2d543d20SAndroid Build Coastguard Workerifeq ($(LIBSEPOLA),)
19*2d543d20SAndroid Build Coastguard Worker        LDLIBS_LIBSEPOLA := -l:libsepol.a
20*2d543d20SAndroid Build Coastguard Workerendif
21*2d543d20SAndroid Build Coastguard Worker
22*2d543d20SAndroid Build Coastguard WorkerCHECKOBJS = y.tab.o lex.yy.o queue.o module_compiler.o parse_util.o \
23*2d543d20SAndroid Build Coastguard Worker	    policy_define.o
24*2d543d20SAndroid Build Coastguard WorkerCHECKPOLOBJS = $(CHECKOBJS) checkpolicy.o
25*2d543d20SAndroid Build Coastguard WorkerCHECKMODOBJS = $(CHECKOBJS) checkmodule.o
26*2d543d20SAndroid Build Coastguard Worker
27*2d543d20SAndroid Build Coastguard WorkerGENERATED=lex.yy.c y.tab.c y.tab.h
28*2d543d20SAndroid Build Coastguard Worker
29*2d543d20SAndroid Build Coastguard Workerall:  $(TARGETS)
30*2d543d20SAndroid Build Coastguard Worker	$(MAKE) -C test
31*2d543d20SAndroid Build Coastguard Worker
32*2d543d20SAndroid Build Coastguard Workercheckpolicy: $(CHECKPOLOBJS) $(LIBSEPOLA)
33*2d543d20SAndroid Build Coastguard Worker	$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LDLIBS_LIBSEPOLA)
34*2d543d20SAndroid Build Coastguard Worker
35*2d543d20SAndroid Build Coastguard Workercheckmodule: $(CHECKMODOBJS) $(LIBSEPOLA)
36*2d543d20SAndroid Build Coastguard Worker	$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LDLIBS_LIBSEPOLA)
37*2d543d20SAndroid Build Coastguard Worker
38*2d543d20SAndroid Build Coastguard Worker%.o: %.c
39*2d543d20SAndroid Build Coastguard Worker	$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -c $<
40*2d543d20SAndroid Build Coastguard Worker
41*2d543d20SAndroid Build Coastguard Workery.tab.o: y.tab.c
42*2d543d20SAndroid Build Coastguard Worker	$(CC) $(filter-out -Werror, $(CPPFLAGS) $(CFLAGS)) -o $@ -c $<
43*2d543d20SAndroid Build Coastguard Worker
44*2d543d20SAndroid Build Coastguard Workerlex.yy.o: lex.yy.c
45*2d543d20SAndroid Build Coastguard Worker	$(CC) $(filter-out -Werror, $(CPPFLAGS) $(CFLAGS)) -o $@ -c $<
46*2d543d20SAndroid Build Coastguard Worker
47*2d543d20SAndroid Build Coastguard Workery.tab.c: policy_parse.y
48*2d543d20SAndroid Build Coastguard Worker	$(YACC) -d policy_parse.y
49*2d543d20SAndroid Build Coastguard Worker
50*2d543d20SAndroid Build Coastguard Workerlex.yy.c: policy_scan.l y.tab.c
51*2d543d20SAndroid Build Coastguard Worker	$(LEX) policy_scan.l
52*2d543d20SAndroid Build Coastguard Worker
53*2d543d20SAndroid Build Coastguard Worker.PHONY: test
54*2d543d20SAndroid Build Coastguard Workertest: checkpolicy
55*2d543d20SAndroid Build Coastguard Worker	./tests/test_roundtrip.sh
56*2d543d20SAndroid Build Coastguard Worker
57*2d543d20SAndroid Build Coastguard Worker# helper target for fuzzing
58*2d543d20SAndroid Build Coastguard Workercheckobjects: $(CHECKOBJS)
59*2d543d20SAndroid Build Coastguard Worker
60*2d543d20SAndroid Build Coastguard Workerinstall: all
61*2d543d20SAndroid Build Coastguard Worker	-mkdir -p $(DESTDIR)$(BINDIR)
62*2d543d20SAndroid Build Coastguard Worker	-mkdir -p $(DESTDIR)$(MANDIR)/man8
63*2d543d20SAndroid Build Coastguard Worker	install -m 755 $(TARGETS) $(DESTDIR)$(BINDIR)
64*2d543d20SAndroid Build Coastguard Worker	install -m 644 checkpolicy.8 $(DESTDIR)$(MANDIR)/man8
65*2d543d20SAndroid Build Coastguard Worker	install -m 644 checkmodule.8 $(DESTDIR)$(MANDIR)/man8
66*2d543d20SAndroid Build Coastguard Worker	for lang in $(LINGUAS) ; do \
67*2d543d20SAndroid Build Coastguard Worker		if [ -e $${lang} ] ; then \
68*2d543d20SAndroid Build Coastguard Worker			mkdir -p $(DESTDIR)$(MANDIR)/$${lang}/man8 ; \
69*2d543d20SAndroid Build Coastguard Worker			install -m 644 $${lang}/*.8 $(DESTDIR)$(MANDIR)/$${lang}/man8 ; \
70*2d543d20SAndroid Build Coastguard Worker		fi ; \
71*2d543d20SAndroid Build Coastguard Worker	done
72*2d543d20SAndroid Build Coastguard Worker
73*2d543d20SAndroid Build Coastguard Workerrelabel: install
74*2d543d20SAndroid Build Coastguard Worker	/sbin/restorecon $(DESTDIR)$(BINDIR)/checkpolicy
75*2d543d20SAndroid Build Coastguard Worker	/sbin/restorecon $(DESTDIR)$(BINDIR)/checkmodule
76*2d543d20SAndroid Build Coastguard Worker
77*2d543d20SAndroid Build Coastguard Workerclean:
78*2d543d20SAndroid Build Coastguard Worker	-rm -f $(TARGETS) $(CHECKPOLOBJS) $(CHECKMODOBJS) y.tab.c y.tab.h lex.yy.c tests/testpol.conf tests/testpol.bin
79*2d543d20SAndroid Build Coastguard Worker	$(MAKE) -C test clean
80*2d543d20SAndroid Build Coastguard Worker
81*2d543d20SAndroid Build Coastguard Workerindent:
82*2d543d20SAndroid Build Coastguard Worker	../scripts/Lindent $(filter-out $(GENERATED),$(wildcard *.[ch]))
83