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