1#
2# Makefile for building the checkpolicy program
3#
4PREFIX ?= $(DESTDIR)/usr
5BINDIR ?= $(PREFIX)/bin
6MANDIR ?= $(PREFIX)/share/man
7LIBDIR ?= $(PREFIX)/lib
8INCLUDEDIR ?= $(PREFIX)/include
9TARGETS = checkpolicy checkmodule
10
11YACC = bison -y
12
13CFLAGS ?= -g -Wall -Werror -Wshadow -O2 -pipe -fno-strict-aliasing
14
15override CFLAGS += -I. -I${INCLUDEDIR}
16
17CHECKOBJS = y.tab.o lex.yy.o queue.o module_compiler.o parse_util.o \
18	    policy_define.o
19CHECKPOLOBJS = $(CHECKOBJS) checkpolicy.o
20CHECKMODOBJS = $(CHECKOBJS) checkmodule.o
21
22LDLIBS=$(LIBDIR)/libsepol.a -lfl
23
24GENERATED=lex.yy.c y.tab.c y.tab.h
25
26all:  $(TARGETS)
27	$(MAKE) -C test
28
29checkpolicy: $(CHECKPOLOBJS)
30
31checkmodule: $(CHECKMODOBJS)
32
33%.o: %.c
34	$(CC) $(CFLAGS) -o $@ -c $<
35
36y.tab.o: y.tab.c
37	$(CC) $(filter-out -Werror, $(CFLAGS)) -o $@ -c $<
38
39lex.yy.o: lex.yy.c
40	$(CC) $(filter-out -Werror, $(CFLAGS)) -o $@ -c $<
41
42y.tab.c: policy_parse.y
43	$(YACC) -d policy_parse.y
44
45lex.yy.c: policy_scan.l y.tab.c
46	$(LEX) policy_scan.l
47
48install: all
49	-mkdir -p $(BINDIR)
50	-mkdir -p $(MANDIR)/man8
51	install -m 755 $(TARGETS) $(BINDIR)
52	install -m 644 checkpolicy.8 $(MANDIR)/man8
53	install -m 644 checkmodule.8 $(MANDIR)/man8
54
55relabel: install
56	/sbin/restorecon $(BINDIR)/checkpolicy
57	/sbin/restorecon $(BINDIR)/checkmodule
58
59clean:
60	-rm -f $(TARGETS) $(CHECKPOLOBJS) $(CHECKMODOBJS) y.tab.c y.tab.h lex.yy.c
61	$(MAKE) -C test clean
62
63indent:
64	../scripts/Lindent $(filter-out $(GENERATED),$(wildcard *.[ch]))
65