libselinux: fix subdir build and usage of cmdline CFLAGS

commit 16c123f4b1 ("libselinux:
support ANDROID_HOST=1 on Mac") broke the ability to run make
in the src subdirectory of libselinux (because OS and COMPILER
were not defined) and also caused some warning flags that could
be overridden via command-line CFLAGS to be mandatory.  Fix it.

Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
This commit is contained in:
Stephen Smalley 2016-11-14 13:05:09 -05:00
parent a0149f6f4f
commit bbc930c756
2 changed files with 19 additions and 3 deletions

View file

@ -23,6 +23,14 @@ LIBSEPOLA ?= $(LIBDIR)/libsepol.a
VERSION = $(shell cat ../VERSION) VERSION = $(shell cat ../VERSION)
LIBVERSION = 1 LIBVERSION = 1
OS ?= $(shell uname)
ifeq ($(shell $(CC) -v 2>&1 | grep "clang"),)
COMPILER ?= gcc
else
COMPILER ?= clang
endif
LIBA=libselinux.a LIBA=libselinux.a
TARGET=libselinux.so TARGET=libselinux.so
LIBPC=libselinux.pc LIBPC=libselinux.pc
@ -67,12 +75,12 @@ CFLAGS ?= -O -Wall -W -Wundef -Wformat-y2k -Wformat-security -Winit-self -Wmissi
LD_SONAME_FLAGS=-soname,$(LIBSO),-z,defs,-z,relro LD_SONAME_FLAGS=-soname,$(LIBSO),-z,defs,-z,relro
ifeq ($(COMPILER), gcc) ifeq ($(COMPILER), gcc)
override CFLAGS += -fipa-pure-const -Wlogical-op -Wpacked-bitfield-compat -Wsync-nand \ CFLAGS += -fipa-pure-const -Wlogical-op -Wpacked-bitfield-compat -Wsync-nand \
-Wcoverage-mismatch -Wcpp -Wformat-contains-nul -Wnormalized=nfc -Wsuggest-attribute=const \ -Wcoverage-mismatch -Wcpp -Wformat-contains-nul -Wnormalized=nfc -Wsuggest-attribute=const \
-Wsuggest-attribute=noreturn -Wsuggest-attribute=pure -Wtrampolines -Wjump-misses-init \ -Wsuggest-attribute=noreturn -Wsuggest-attribute=pure -Wtrampolines -Wjump-misses-init \
-Wno-suggest-attribute=pure -Wno-suggest-attribute=const -Wp,-D_FORTIFY_SOURCE=2 -Wno-suggest-attribute=pure -Wno-suggest-attribute=const -Wp,-D_FORTIFY_SOURCE=2
else else
override CFLAGS += -Wunused-command-line-argument CFLAGS += -Wunused-command-line-argument
endif endif
ifeq ($(OS), Darwin) ifeq ($(OS), Darwin)

View file

@ -5,6 +5,14 @@ USRBINDIR ?= $(PREFIX)/sbin
SBINDIR ?= $(DESTDIR)/sbin SBINDIR ?= $(DESTDIR)/sbin
INCLUDEDIR ?= $(PREFIX)/include INCLUDEDIR ?= $(PREFIX)/include
OS ?= $(shell uname)
ifeq ($(shell $(CC) -v 2>&1 | grep "clang"),)
COMPILER ?= gcc
else
COMPILER ?= clang
endif
MAX_STACK_SIZE=8192 MAX_STACK_SIZE=8192
CFLAGS ?= -O -Wall -W -Wundef -Wformat-y2k -Wformat-security -Winit-self -Wmissing-include-dirs \ CFLAGS ?= -O -Wall -W -Wundef -Wformat-y2k -Wformat-security -Winit-self -Wmissing-include-dirs \
-Wunused -Wunknown-pragmas -Wstrict-aliasing -Wshadow -Wpointer-arith \ -Wunused -Wunknown-pragmas -Wstrict-aliasing -Wshadow -Wpointer-arith \
@ -26,7 +34,7 @@ CFLAGS ?= -O -Wall -W -Wundef -Wformat-y2k -Wformat-security -Winit-self -Wmissi
LD_SONAME_FLAGS=-soname,$(LIBSO),-z,defs,-z,relro LD_SONAME_FLAGS=-soname,$(LIBSO),-z,defs,-z,relro
ifeq ($(COMPILER), gcc) ifeq ($(COMPILER), gcc)
override CFLAGS += -fipa-pure-const -Wpacked-bitfield-compat -Wsync-nand -Wcoverage-mismatch \ CFLAGS += -fipa-pure-const -Wpacked-bitfield-compat -Wsync-nand -Wcoverage-mismatch \
-Wcpp -Wformat-contains-nul -Wnormalized=nfc -Wsuggest-attribute=const \ -Wcpp -Wformat-contains-nul -Wnormalized=nfc -Wsuggest-attribute=const \
-Wsuggest-attribute=noreturn -Wsuggest-attribute=pure -Wtrampolines -Wjump-misses-init \ -Wsuggest-attribute=noreturn -Wsuggest-attribute=pure -Wtrampolines -Wjump-misses-init \
-Wno-suggest-attribute=pure -Wno-suggest-attribute=const -Wno-suggest-attribute=pure -Wno-suggest-attribute=const