Makefiles: drop -L/-I to system paths

The toolchain automatically handles them and they break cross compiling.

LDFLAGS should also come before object files, some flags (eg,
-Wl,as-needed) can break things if they are in the wrong place)

Gentoo-Bug: https://bugs.gentoo.org/500674

Signed-off-by: Jason Zaman <jason@perfinion.com>
This commit is contained in:
Jason Zaman 2017-04-25 01:59:56 +08:00 committed by Stephen Smalley
parent b5fe48da20
commit fcb5d5cc72
27 changed files with 48 additions and 57 deletions

View File

@ -14,7 +14,7 @@ YACC = bison -y
CFLAGS ?= -g -Wall -Werror -Wshadow -O2 -pipe -fno-strict-aliasing
override CFLAGS += -I. -I${INCLUDEDIR}
override CFLAGS += -I.
CHECKOBJS = y.tab.o lex.yy.o queue.o module_compiler.o parse_util.o \
policy_define.o

View File

@ -8,7 +8,6 @@ INCLUDEDIR ?= $(PREFIX)/include
LIBSEPOLA ?= $(LIBDIR)/libsepol.a
CFLAGS ?= -g -Wall -W -Werror -O2 -pipe
override CFLAGS += -I$(INCLUDEDIR)
all: dispol dismod

View File

@ -93,7 +93,7 @@ endif
PCRE_LDLIBS ?= -lpcre
override CFLAGS += -I../include -I$(INCLUDEDIR) -D_GNU_SOURCE $(DISABLE_FLAGS) $(PCRE_CFLAGS)
override CFLAGS += -I../include -D_GNU_SOURCE $(DISABLE_FLAGS) $(PCRE_CFLAGS)
SWIG_CFLAGS += -Wno-error -Wno-unused-variable -Wno-unused-but-set-variable -Wno-unused-parameter \
-Wno-shadow -Wno-uninitialized -Wno-missing-prototypes -Wno-missing-declarations
@ -133,17 +133,17 @@ $(SWIGRUBYLOBJ): $(SWIGRUBYCOUT)
$(CC) $(CFLAGS) $(SWIG_CFLAGS) $(RUBYINC) -fPIC -DSHARED -c -o $@ $<
$(SWIGSO): $(SWIGLOBJ)
$(CC) $(CFLAGS) -shared -o $@ $< -L. -lselinux $(LDFLAGS) $(PYLIBS) -L$(LIBDIR)
$(CC) $(CFLAGS) $(LDFLAGS) -L. -shared -o $@ $< -lselinux $(PYLIBS)
$(SWIGRUBYSO): $(SWIGRUBYLOBJ)
$(CC) $(CFLAGS) -shared -o $@ $^ -L. -lselinux $(LDFLAGS) $(RUBYLIBS) -L$(LIBDIR)
$(CC) $(CFLAGS) $(LDFLAGS) -L. -shared -o $@ $^ -lselinux $(RUBYLIBS)
$(LIBA): $(OBJS)
$(AR) rcs $@ $^
$(RANLIB) $@
$(LIBSO): $(LOBJS)
$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $^ $(PCRE_LDLIBS) -ldl -L$(LIBDIR) -Wl,$(LD_SONAME_FLAGS)
$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $^ $(PCRE_LDLIBS) -ldl -Wl,$(LD_SONAME_FLAGS)
ln -sf $@ $(TARGET)
$(LIBPC): $(LIBPC).in ../VERSION
@ -156,7 +156,7 @@ $(AUDIT2WHYLOBJ): audit2why.c
$(CC) $(filter-out -Werror, $(CFLAGS)) $(PYINC) -fPIC -DSHARED -c -o $@ $<
$(AUDIT2WHYSO): $(AUDIT2WHYLOBJ) $(LIBSEPOLA)
$(CC) $(CFLAGS) -shared -o $@ $^ -L. $(LDFLAGS) -lselinux $(PYLIBS) -L$(LIBDIR)
$(CC) $(CFLAGS) $(LDFLAGS) -L. -shared -o $@ $^ -lselinux $(PYLIBS)
%.o: %.c policy.h
$(CC) $(CFLAGS) $(TLSFLAGS) -c -o $@ $<

View File

@ -44,8 +44,9 @@ override CFLAGS += -I/opt/local/include -I../../libsepol/include
override LDFLAGS += -L../../libsepol/src -undefined dynamic_lookup
endif
override CFLAGS += -I../include -I$(INCLUDEDIR) -D_GNU_SOURCE $(DISABLE_FLAGS) $(PCRE_CFLAGS)
LDLIBS += -L../src -lselinux -L$(LIBDIR)
override CFLAGS += -I../include -D_GNU_SOURCE $(DISABLE_FLAGS) $(PCRE_CFLAGS)
LDFLAGS += -L../src
LDLIBS += -lselinux
PCRE_LDLIBS ?= -lpcre
ifeq ($(ANDROID_HOST),y)

View File

@ -61,7 +61,7 @@ CFLAGS ?= -Werror -Wall -W -Wundef -Wshadow -Wmissing-noreturn -Wmissing-format-
SWIG_CFLAGS += -Wno-error -Wno-unused-but-set-variable -Wno-unused-variable -Wno-shadow \
-Wno-unused-parameter
override CFLAGS += -I../include -I$(INCLUDEDIR) -D_GNU_SOURCE
override CFLAGS += -I../include -D_GNU_SOURCE
RANLIB ?= ranlib
SWIG = swig -Wall -python -o $(SWIGCOUT) -outdir ./
@ -81,17 +81,17 @@ $(SWIGRUBYLOBJ): $(SWIGRUBYCOUT)
$(CC) $(CFLAGS) $(SWIG_CFLAGS) $(RUBYINC) -fPIC -DSHARED -c -o $@ $<
$(SWIGSO): $(SWIGLOBJ)
$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $< -L. -lsemanage $(PYLIBS) -L$(LIBDIR)
$(CC) $(CFLAGS) $(LDFLAGS) -L. -shared -o $@ $< -lsemanage $(PYLIBS)
$(SWIGRUBYSO): $(SWIGRUBYLOBJ)
$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $^ -L. -lsemanage $(RUBYLIBS) -L$(LIBDIR)
$(CC) $(CFLAGS) $(LDFLAGS) -L. -shared -o $@ $^ -lsemanage $(RUBYLIBS)
$(LIBA): $(OBJS)
$(AR) rcs $@ $^
$(RANLIB) $@
$(LIBSO): $(LOBJS)
$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $^ -lsepol -laudit -lselinux -lbz2 -L$(LIBDIR) -Wl,-soname,$(LIBSO),--version-script=libsemanage.map,-z,defs
$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $^ -lsepol -laudit -lselinux -lbz2 -Wl,-soname,$(LIBSO),--version-script=libsemanage.map,-z,defs
ln -sf $@ $(TARGET)
$(LIBPC): $(LIBPC).in ../VERSION

View File

@ -5,20 +5,20 @@ LIBDIR ?= $(PREFIX)/lib
SOURCES = $(wildcard *.c)
# Add the required external object files here:
LIBS = ../src/libsemanage.a -L$(LIBDIR) -lselinux -lsepol
LIBS = ../src/libsemanage.a -lselinux -lsepol
###########################################################################
EXECUTABLE = libsemanage-tests
CFLAGS += -g -O0 -Wall -W -Wundef -Wmissing-noreturn -Wmissing-format-attribute -Wno-unused-parameter
INCLUDE = -I../src -I../include -I$(PREFIX)/include
LDFLAGS += -lcunit -lbz2 -laudit
INCLUDE = -I../src -I../include
LDLIBS += -lcunit -lbz2 -laudit
OBJECTS = $(SOURCES:.c=.o)
all: $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS) ../src/libsemanage.a
$(CC) $(OBJECTS) $(LIBS) $(LDFLAGS) -o $@
$(CC) $(OBJECTS) $(LIBS) $(LDFLAGS) -o $@ $(LDLIBS)
%.o: %.c
$(CC) $(CFLAGS) $(INCLUDE) -c $*.c -o $*.o

View File

@ -3,8 +3,8 @@ PREFIX ?= $(DESTDIR)/usr
BINDIR ?= $(PREFIX)/bin
CFLAGS ?= -Wall -Werror
override CFLAGS += -I../include
LDLIBS += -L../src -lsepol
LDFLAGS += -L../src
LDLIBS += -lsepol
TARGETS=$(patsubst %.c,%,$(wildcard *.c))

View File

@ -10,12 +10,12 @@ PROG_OBJS= $(patsubst %.c,%.o,$(PROG_SRC))
PROG=mcstransd
INITSCRIPT=mcstrans
CFLAGS ?= -Wall -W -Wundef -Wmissing-noreturn -Wmissing-format-attribute
override CFLAGS += -I$(PREFIX)/include -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
override CFLAGS += -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
all: $(PROG)
$(PROG): $(PROG_OBJS)
$(CC) $(LDFLAGS) -pie -o $@ $^ -lselinux -lcap -lpcre $(LIBDIR)/libsepol.a -L$(LIBDIR)
$(CC) $(LDFLAGS) -pie -o $@ $^ -lselinux -lcap -lpcre $(LIBDIR)/libsepol.a
%.o: %.c
$(CC) $(CFLAGS) -fPIE -c -o $@ $<

View File

@ -5,8 +5,8 @@ BINDIR ?= $(PREFIX)/sbin
LIBSEPOLA ?= $(LIBDIR)/libsepol.a
CFLAGS ?= -Wall
override CFLAGS += -I../src -I$(PREFIX)/include -D_GNU_SOURCE
LDLIBS += -L$(LIBDIR) -lselinux -lpcre
override CFLAGS += -I../src -D_GNU_SOURCE
LDLIBS += -lselinux -lpcre
TARGETS=$(patsubst %.c,%,$(wildcard *.c))

View File

@ -8,8 +8,7 @@ LIBEXECDIR ?= $(PREFIX)/libexec
HLLDIR ?= $(LIBEXECDIR)/selinux/hll
CFLAGS ?= -Werror -Wall -W
override CFLAGS += -I$(INCLUDEDIR)
LDLIBS = -lsepol -L$(LIBDIR)
LDLIBS = -lsepol
PP_SRCS = $(wildcard *.c)
PP_OBJS = $(patsubst %.c,%.o,$(PP_SRCS))

View File

@ -6,8 +6,8 @@ MANDIR ?= $(PREFIX)/share/man
LOCALEDIR ?= /usr/share/locale
CFLAGS ?= -Werror -Wall -W
override CFLAGS += $(LDFLAGS) -I$(PREFIX)/include -DUSE_NLS -DLOCALEDIR="\"$(LOCALEDIR)\"" -DPACKAGE="\"policycoreutils\""
LDLIBS += -lsepol -lselinux -L$(PREFIX)/lib
override CFLAGS += $(LDFLAGS) -DUSE_NLS -DLOCALEDIR="\"$(LOCALEDIR)\"" -DPACKAGE="\"policycoreutils\""
LDLIBS += -lsepol -lselinux
TARGETS=$(patsubst %.c,%,$(wildcard *.c))

View File

@ -22,8 +22,8 @@ VERSION = $(shell cat ../VERSION)
CFLAGS ?= -Werror -Wall -W
EXTRA_OBJS =
override CFLAGS += -DVERSION=\"$(VERSION)\" -I$(PREFIX)/include -DUSE_NLS -DLOCALEDIR="\"$(LOCALEDIR)\"" -DPACKAGE="\"policycoreutils\""
LDLIBS += -lselinux -L$(PREFIX)/lib
override CFLAGS += -DVERSION=\"$(VERSION)\" -DUSE_NLS -DLOCALEDIR="\"$(LOCALEDIR)\"" -DPACKAGE="\"policycoreutils\""
LDLIBS += -lselinux
ifeq ($(PAMH), /usr/include/security/pam_appl.h)
override CFLAGS += -DUSE_PAM
EXTRA_OBJS += hashtab.o

View File

@ -9,8 +9,8 @@ PAMH = $(shell ls /usr/include/security/pam_appl.h 2>/dev/null)
AUDITH = $(shell ls /usr/include/libaudit.h 2>/dev/null)
CFLAGS ?= -Werror -Wall -W
override CFLAGS += -I$(PREFIX)/include -DUSE_NLS -DLOCALEDIR="\"$(LOCALEDIR)\"" -DPACKAGE="\"policycoreutils\""
LDLIBS += -lselinux -L$(PREFIX)/lib
override CFLAGS += -DUSE_NLS -DLOCALEDIR="\"$(LOCALEDIR)\"" -DPACKAGE="\"policycoreutils\""
LDLIBS += -lselinux
ifeq ($(PAMH), /usr/include/security/pam_appl.h)
override CFLAGS += -DUSE_PAM
LDLIBS += -lpam -lpam_misc

View File

@ -8,8 +8,8 @@ LIBDIR ?= $(PREFIX)/lib
WARNS=-Werror -W -Wall -Wundef -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -Wno-format-zero-length -Wformat-nonliteral -Wformat-security -Wfloat-equal
VERSION = $(shell cat ../VERSION)
CFLAGS ?= $(WARNS) -O1
override CFLAGS += -DVERSION=\"$(VERSION)\" -I$(INCLUDEDIR)
LDLIBS = -lselinux -L$(LIBDIR)
override CFLAGS += -DVERSION=\"$(VERSION)\"
LDLIBS = -lselinux
all: secon

View File

@ -6,8 +6,7 @@ MANDIR = $(PREFIX)/share/man
LIBDIR ?= $(PREFIX)/lib
CFLAGS ?= -Werror -Wall -W
override CFLAGS += -I$(INCLUDEDIR)
LDLIBS = -lsepol -lselinux -lsemanage -L$(LIBDIR)
LDLIBS = -lsepol -lselinux -lsemanage
SEMODULE_OBJS = semodule.o
all: semodule genhomedircon

View File

@ -6,8 +6,8 @@ ETCDIR ?= $(DESTDIR)/etc
LIBDIR ?= $(PREFIX)/lib
CFLAGS ?= -Werror -Wall -W
override CFLAGS += -I$(PREFIX)/include -D_FILE_OFFSET_BITS=64
LDLIBS = -lselinux -L$(LIBDIR)
override CFLAGS += -D_FILE_OFFSET_BITS=64
LDLIBS = -lselinux
all: sestatus

View File

@ -8,8 +8,7 @@ AUDITH = $(shell ls /usr/include/libaudit.h 2>/dev/null)
ABORT_ON_ERRORS=$(shell grep "^\#define ABORT_ON_ERRORS" setfiles.c | awk -S '{ print $$3 }')
CFLAGS ?= -g -Werror -Wall -W
override CFLAGS += -I$(PREFIX)/include
LDLIBS = -lselinux -lsepol -L$(LIBDIR)
LDLIBS = -lselinux -lsepol
ifeq ($(AUDITH), /usr/include/libaudit.h)
override CFLAGS += -DUSE_AUDIT

View File

@ -7,8 +7,7 @@ LIBDIR ?= $(PREFIX)/lib
BASHCOMPLETIONDIR ?= $(DESTDIR)/usr/share/bash-completion/completions
CFLAGS ?= -Werror -Wall -W
override CFLAGS += -I$(INCLUDEDIR)
LDLIBS = -lsepol -lselinux -lsemanage -L$(LIBDIR)
LDLIBS = -lsepol -lselinux -lsemanage
SETSEBOOL_OBJS = setsebool.o
BASHCOMPLETIONS=setsebool-bash-completion.sh

View File

@ -10,7 +10,6 @@ INCLUDEDIR ?= $(PREFIX)/include
LIBSEPOLA ?= $(LIBDIR)/libsepol.a
CFLAGS ?= -Werror -Wall -W
override CFLAGS += -I$(INCLUDEDIR)
all: audit2why sepolgen-ifgen-attr-helper

View File

@ -12,7 +12,7 @@ LOCALEDIR ?= /usr/share/locale
BASHCOMPLETIONDIR ?= $(DESTDIR)/usr/share/bash-completion/completions
SHAREDIR ?= $(PREFIX)/share/sandbox
CFLAGS ?= -Wall -Werror -Wextra -W
override CFLAGS += -I$(PREFIX)/include -DPACKAGE="policycoreutils" -DSHARED -shared
override CFLAGS += -DPACKAGE="policycoreutils" -DSHARED -shared
BASHCOMPLETIONS=sepolicy-bash-completion.sh

View File

@ -17,7 +17,7 @@ DBUSFLAGS = -DHAVE_DBUS $(shell $(PKG_CONFIG) --cflags dbus-glib-1)
DBUSLIB = $(shell $(PKG_CONFIG) --libs dbus-glib-1)
CFLAGS ?= -g -Werror -Wall -W
override CFLAGS += -I$(PREFIX)/include $(DBUSFLAGS)
override CFLAGS += $(DBUSFLAGS)
USE_PCRE2 ?= n
ifeq ($(USE_PCRE2),y)

View File

@ -9,8 +9,8 @@ SBINDIR ?= $(PREFIX)/sbin
MANDIR ?= $(PREFIX)/share/man
LOCALEDIR ?= /usr/share/locale
SHAREDIR ?= $(PREFIX)/share/sandbox
override CFLAGS += -I$(PREFIX)/include -DPACKAGE="\"policycoreutils\"" -Wall -Werror -Wextra -W
LDLIBS += -lselinux -lcap-ng -L$(LIBDIR)
override CFLAGS += -DPACKAGE="\"policycoreutils\"" -Wall -Werror -Wextra -W
LDLIBS += -lselinux -lcap-ng
SEUNSHARE_OBJS = seunshare.o
all: sandbox seunshare sandboxX.sh start

View File

@ -4,7 +4,7 @@ MANDIR ?= $(PREFIX)/share/man
LIBDIR ?= $(PREFIX)/lib
INCLUDEDIR ?= $(PREFIX)/include
LDLIBS = -lsepol -L$(LIBDIR)
LDLIBS = -lsepol
SECILC = secilc
SECILC_SRCS := secilc.c
@ -20,18 +20,18 @@ XMLTO = xmlto
CFLAGS ?= -Wall -Wshadow -Wextra -Wundef -Wmissing-format-attribute -Wcast-align -Wstrict-prototypes -Wpointer-arith -Wunused
override CFLAGS += -I$(INCLUDEDIR) -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
override CFLAGS += -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
all: $(SECILC) $(SECIL2CONF) man
$(SECILC): $(SECILC_OBJS)
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LDLIBS)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
test: $(SECILC)
./$(SECILC) test/policy.cil
$(SECIL2CONF): $(SECIL2CONF_OBJS)
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LDLIBS)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
man: $(SECILC_MANPAGE) $(SECIL2CONF_MANPAGE)

View File

@ -7,7 +7,6 @@ MANDIR ?= $(PREFIX)/share/man
LIBSEPOLA ?= $(LIBDIR)/libsepol.a
CFLAGS ?= -Werror -Wall -W
override CFLAGS += -I$(INCLUDEDIR)
all: semodule_deps

View File

@ -6,8 +6,7 @@ LIBDIR ?= $(PREFIX)/lib
MANDIR ?= $(PREFIX)/share/man
CFLAGS ?= -Werror -Wall -W
override CFLAGS += -I$(INCLUDEDIR)
LDLIBS = -lsepol -L$(LIBDIR)
LDLIBS = -lsepol
all: semodule_expand

View File

@ -6,8 +6,7 @@ MANDIR ?= $(PREFIX)/share/man
LIBDIR ?= $(PREFIX)/lib
CFLAGS ?= -Werror -Wall -W
override CFLAGS += -I$(INCLUDEDIR)
LDLIBS = -lsepol -L$(LIBDIR)
LDLIBS = -lsepol
all: semodule_link

View File

@ -6,8 +6,7 @@ LIBDIR ?= $(PREFIX)/lib
MANDIR ?= $(PREFIX)/share/man
CFLAGS ?= -Werror -Wall -W
override CFLAGS += -I$(INCLUDEDIR)
LDLIBS = -lsepol -L$(LIBDIR)
LDLIBS = -lsepol
all: semodule_package semodule_unpackage