2008-08-19 19:30:36 +00:00
|
|
|
# Installation directories.
|
|
|
|
PREFIX ?= $(DESTDIR)/usr
|
|
|
|
LIBDIR ?= $(PREFIX)/lib
|
2017-06-20 14:49:57 +00:00
|
|
|
SBINDIR ?= $(PREFIX)/sbin
|
2016-08-04 12:44:06 +00:00
|
|
|
INCLUDEDIR ?= $(PREFIX)/include
|
2008-08-19 19:30:36 +00:00
|
|
|
|
2016-11-14 18:05:09 +00:00
|
|
|
OS ?= $(shell uname)
|
|
|
|
|
|
|
|
ifeq ($(shell $(CC) -v 2>&1 | grep "clang"),)
|
|
|
|
COMPILER ?= gcc
|
|
|
|
else
|
|
|
|
COMPILER ?= clang
|
|
|
|
endif
|
|
|
|
|
2017-05-09 14:47:39 +00:00
|
|
|
ifeq ($(COMPILER), gcc)
|
|
|
|
EXTRA_CFLAGS = -fipa-pure-const -Wpacked-bitfield-compat -Wsync-nand -Wcoverage-mismatch \
|
|
|
|
-Wcpp -Wformat-contains-nul -Wnormalized=nfc -Wsuggest-attribute=const \
|
|
|
|
-Wsuggest-attribute=noreturn -Wsuggest-attribute=pure -Wtrampolines -Wjump-misses-init \
|
|
|
|
-Wno-suggest-attribute=pure -Wno-suggest-attribute=const
|
|
|
|
endif
|
|
|
|
|
2012-01-23 15:41:21 +00:00
|
|
|
MAX_STACK_SIZE=8192
|
2012-05-25 11:11:51 +00:00
|
|
|
CFLAGS ?= -O -Wall -W -Wundef -Wformat-y2k -Wformat-security -Winit-self -Wmissing-include-dirs \
|
2012-01-23 15:41:21 +00:00
|
|
|
-Wunused -Wunknown-pragmas -Wstrict-aliasing -Wshadow -Wpointer-arith \
|
2016-10-17 20:24:08 +00:00
|
|
|
-Wbad-function-cast -Wcast-align -Wwrite-strings -Waggregate-return \
|
2012-01-23 15:41:21 +00:00
|
|
|
-Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes \
|
|
|
|
-Wmissing-declarations -Wmissing-noreturn -Wmissing-format-attribute \
|
|
|
|
-Wredundant-decls -Wnested-externs -Winline -Winvalid-pch -Wvolatile-register-var \
|
2016-10-17 20:24:08 +00:00
|
|
|
-Wdisabled-optimization -Wbuiltin-macro-redefined \
|
|
|
|
-Wattributes -Wmultichar \
|
2012-01-23 15:41:21 +00:00
|
|
|
-Wdeprecated-declarations -Wdiv-by-zero -Wdouble-promotion -Wendif-labels -Wextra \
|
2016-10-17 20:24:08 +00:00
|
|
|
-Wformat-extra-args -Wformat-zero-length -Wformat=2 -Wmultichar \
|
|
|
|
-Woverflow -Wpointer-to-int-cast -Wpragmas \
|
|
|
|
-Wno-missing-field-initializers -Wno-sign-compare \
|
libselinux: avoid redefining _FORTIFY_SOURCE
Two makefiles of ours pass `-D_FORTIFY_SOURCE=2` directly to the
preprocessor. While this does not pose any problems when the value has
not been previously set, it can break the build if it is part of the
standard build flags.
The issue can easily be fixed by instead defining `_FORTIFY_SOURCE`
without specifying a concrete value. In this case, gcc will not error
out and simply keep using the previously defined value. On the other
hand, if no value has been defined, we will now compile with
`_FORTIFY_SOURCE=1`. From feature_test_macros(7):
If _FORTIFY_SOURCE is set to 1, with compiler optimization level 1
(gcc -O1) and above, checks that shouldn't change the behavior of
conforming programs are performed. With _FORTIFY_SOURCE set to 2,
some more checking is added, but some conforming programs might
fail.
While this leaves us with less checks for buffer overflows, it will only
enable checks that should not change behaviour of conforming programs.
With _FORTIFY_SOURCE=2, the compiler may even unintentionally change
behaviour of conforming programs. So in fact, one could even argue that
we should only be setting the value to 1 anyway to avoid surprising side
effects.
So this patch changes our CFLAGS to only pass `-D_FORTIFY_SOURCE`
without any concrete value, fixing the build issue.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
2017-06-22 09:45:57 +00:00
|
|
|
-Wno-format-nonliteral -Wframe-larger-than=$(MAX_STACK_SIZE) -Wp,-D_FORTIFY_SOURCE \
|
2012-01-23 15:41:21 +00:00
|
|
|
-fstack-protector-all --param=ssp-buffer-size=4 -fexceptions \
|
|
|
|
-fasynchronous-unwind-tables -fdiagnostics-show-option -funit-at-a-time \
|
2017-05-09 14:47:39 +00:00
|
|
|
-Werror -Wno-aggregate-return -Wno-redundant-decls \
|
|
|
|
$(EXTRA_CFLAGS)
|
2016-10-17 20:24:08 +00:00
|
|
|
|
|
|
|
LD_SONAME_FLAGS=-soname,$(LIBSO),-z,defs,-z,relro
|
|
|
|
|
|
|
|
ifeq ($(OS), Darwin)
|
|
|
|
override CFLAGS += -I/opt/local/include -I../../libsepol/include
|
|
|
|
override LDFLAGS += -L../../libsepol/src -undefined dynamic_lookup
|
|
|
|
endif
|
|
|
|
|
2017-04-24 17:59:56 +00:00
|
|
|
override CFLAGS += -I../include -D_GNU_SOURCE $(DISABLE_FLAGS) $(PCRE_CFLAGS)
|
2017-06-18 07:41:49 +00:00
|
|
|
override LDFLAGS += -L../src
|
|
|
|
override LDLIBS += -lselinux
|
2017-04-24 17:59:55 +00:00
|
|
|
PCRE_LDLIBS ?= -lpcre
|
2008-08-19 19:30:36 +00:00
|
|
|
|
2016-09-28 16:17:59 +00:00
|
|
|
ifeq ($(ANDROID_HOST),y)
|
|
|
|
TARGETS=sefcontext_compile
|
|
|
|
else
|
2017-05-30 14:21:32 +00:00
|
|
|
TARGETS=$(patsubst %.c,%,$(sort $(wildcard *.c)))
|
2016-09-28 16:17:59 +00:00
|
|
|
endif
|
2009-05-07 20:05:05 +00:00
|
|
|
|
2017-04-24 17:59:55 +00:00
|
|
|
sefcontext_compile: LDLIBS += $(PCRE_LDLIBS) ../src/libselinux.a -lsepol
|
2016-09-15 16:14:33 +00:00
|
|
|
|
|
|
|
sefcontext_compile: sefcontext_compile.o ../src/regex.o
|
2009-05-07 20:05:05 +00:00
|
|
|
|
2012-01-27 19:41:58 +00:00
|
|
|
all: $(TARGETS)
|
2008-08-19 19:30:36 +00:00
|
|
|
|
|
|
|
install: all
|
2017-06-20 14:49:57 +00:00
|
|
|
-mkdir -p $(SBINDIR)
|
|
|
|
install -m 755 $(TARGETS) $(SBINDIR)
|
2016-12-21 21:09:51 +00:00
|
|
|
|
2008-08-19 19:30:36 +00:00
|
|
|
clean:
|
2012-01-27 19:41:58 +00:00
|
|
|
rm -f $(TARGETS) *.o *~
|
2008-08-19 19:30:36 +00:00
|
|
|
|
2012-01-27 19:00:34 +00:00
|
|
|
distclean: clean
|
|
|
|
|
2008-08-19 19:30:36 +00:00
|
|
|
indent:
|
|
|
|
../../scripts/Lindent $(wildcard *.[ch])
|
|
|
|
|
|
|
|
relabel:
|
|
|
|
|