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
15ifeq ($(COMPILER), gcc)
16EXTRA_CFLAGS = -fipa-pure-const -Wpacked-bitfield-compat -Wsync-nand -Wcoverage-mismatch \
17	-Wcpp -Wformat-contains-nul -Wnormalized=nfc -Wsuggest-attribute=const \
18	-Wsuggest-attribute=noreturn -Wsuggest-attribute=pure -Wtrampolines -Wjump-misses-init \
19	-Wno-suggest-attribute=pure -Wno-suggest-attribute=const
20endif
21
22MAX_STACK_SIZE=8192
23CFLAGS ?= -O -Wall -W -Wundef -Wformat-y2k -Wformat-security -Winit-self -Wmissing-include-dirs \
24          -Wunused -Wunknown-pragmas -Wstrict-aliasing -Wshadow -Wpointer-arith \
25          -Wbad-function-cast -Wcast-align -Wwrite-strings -Waggregate-return \
26          -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes \
27          -Wmissing-declarations -Wmissing-noreturn -Wmissing-format-attribute \
28          -Wredundant-decls -Wnested-externs -Winline -Winvalid-pch -Wvolatile-register-var \
29          -Wdisabled-optimization -Wbuiltin-macro-redefined \
30          -Wattributes -Wmultichar \
31          -Wdeprecated-declarations -Wdiv-by-zero -Wdouble-promotion -Wendif-labels -Wextra \
32          -Wformat-extra-args -Wformat-zero-length -Wformat=2 -Wmultichar \
33          -Woverflow -Wpointer-to-int-cast -Wpragmas \
34          -Wno-missing-field-initializers -Wno-sign-compare \
35          -Wno-format-nonliteral -Wframe-larger-than=$(MAX_STACK_SIZE) -Wp,-D_FORTIFY_SOURCE=2 \
36          -fstack-protector-all --param=ssp-buffer-size=4 -fexceptions \
37          -fasynchronous-unwind-tables -fdiagnostics-show-option -funit-at-a-time \
38          -Werror -Wno-aggregate-return -Wno-redundant-decls \
39          $(EXTRA_CFLAGS)
40
41LD_SONAME_FLAGS=-soname,$(LIBSO),-z,defs,-z,relro
42
43ifeq ($(OS), Darwin)
44override CFLAGS += -I/opt/local/include -I../../libsepol/include
45override LDFLAGS += -L../../libsepol/src -undefined dynamic_lookup
46endif
47
48override CFLAGS += -I../include -D_GNU_SOURCE $(DISABLE_FLAGS) $(PCRE_CFLAGS)
49LDFLAGS += -L../src
50LDLIBS += -lselinux
51PCRE_LDLIBS ?= -lpcre
52
53ifeq ($(ANDROID_HOST),y)
54TARGETS=sefcontext_compile
55else
56TARGETS=$(patsubst %.c,%,$(wildcard *.c))
57endif
58
59sefcontext_compile: LDLIBS += $(PCRE_LDLIBS) ../src/libselinux.a -lsepol
60
61sefcontext_compile: sefcontext_compile.o ../src/regex.o
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