1# Installation directories.
2PREFIX ?= $(DESTDIR)/usr
3LIBDIR ?= $(PREFIX)/lib
4USRSBINDIR ?= $(PREFIX)/sbin
5INCLUDEDIR ?= $(PREFIX)/include
6
7OS ?= $(shell uname)
8
9ifeq ($(shell $(CC) -v 2>&1 | grep "clang"),)
10COMPILER ?= gcc
11else
12COMPILER ?= clang
13endif
14
15MAX_STACK_SIZE=8192
16CFLAGS ?= -O -Wall -W -Wundef -Wformat-y2k -Wformat-security -Winit-self -Wmissing-include-dirs \
17          -Wunused -Wunknown-pragmas -Wstrict-aliasing -Wshadow -Wpointer-arith \
18          -Wbad-function-cast -Wcast-align -Wwrite-strings -Waggregate-return \
19          -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes \
20          -Wmissing-declarations -Wmissing-noreturn -Wmissing-format-attribute \
21          -Wredundant-decls -Wnested-externs -Winline -Winvalid-pch -Wvolatile-register-var \
22          -Wdisabled-optimization -Wbuiltin-macro-redefined \
23          -Wattributes -Wmultichar \
24          -Wdeprecated-declarations -Wdiv-by-zero -Wdouble-promotion -Wendif-labels -Wextra \
25          -Wformat-extra-args -Wformat-zero-length -Wformat=2 -Wmultichar \
26          -Woverflow -Wpointer-to-int-cast -Wpragmas \
27          -Wno-missing-field-initializers -Wno-sign-compare \
28          -Wno-format-nonliteral -Wframe-larger-than=$(MAX_STACK_SIZE) -Wp,-D_FORTIFY_SOURCE=2 \
29          -fstack-protector-all --param=ssp-buffer-size=4 -fexceptions \
30          -fasynchronous-unwind-tables -fdiagnostics-show-option -funit-at-a-time \
31          -Werror -Wno-aggregate-return -Wno-redundant-decls
32
33LD_SONAME_FLAGS=-soname,$(LIBSO),-z,defs,-z,relro
34
35ifeq ($(COMPILER), gcc)
36CFLAGS += -fipa-pure-const -Wpacked-bitfield-compat -Wsync-nand -Wcoverage-mismatch \
37	-Wcpp -Wformat-contains-nul -Wnormalized=nfc -Wsuggest-attribute=const \
38	-Wsuggest-attribute=noreturn -Wsuggest-attribute=pure -Wtrampolines -Wjump-misses-init \
39	-Wno-suggest-attribute=pure -Wno-suggest-attribute=const
40endif
41
42ifeq ($(OS), Darwin)
43override CFLAGS += -I/opt/local/include -I../../libsepol/include
44override LDFLAGS += -L../../libsepol/src -undefined dynamic_lookup
45endif
46
47override CFLAGS += -I../include -I$(INCLUDEDIR) -D_GNU_SOURCE $(DISABLE_FLAGS) $(PCRE_CFLAGS)
48LDLIBS += -L../src -lselinux -L$(LIBDIR)
49PCRE_LDFLAGS ?= -lpcre
50
51ifeq ($(ANDROID_HOST),y)
52TARGETS=sefcontext_compile
53else
54TARGETS=$(patsubst %.c,%,$(wildcard *.c))
55endif
56
57sefcontext_compile: LDLIBS += $(PCRE_LDFLAGS) ../src/libselinux.a -lsepol
58
59sefcontext_compile: sefcontext_compile.o ../src/regex.o
60
61selinux_restorecon: LDLIBS += -lsepol
62
63all: $(TARGETS)
64
65install: all
66	-mkdir -p $(USRSBINDIR)
67	install -m 755 $(TARGETS) $(USRSBINDIR)
68
69clean:
70	rm -f $(TARGETS) *.o *~
71
72distclean: clean
73
74indent:
75	../../scripts/Lindent $(wildcard *.[ch])
76
77relabel:
78
79