libsepol: build: follow standard semantics for DESTDIR and PREFIX

This patch solves the following issues:
- The pkg-config files generates odd paths when using DESTDIR without PREFIX
- DESTDIR is needed during compile time to compute library and header paths which it should not.
- Installing with both DESTDIR and PREFIX set gives us odd paths
- Make usage of DESTDIR and PREFIX more standard

Signed-off-by: Marcus Folkesson <marcus.folkesson@gmail.com>
This commit is contained in:
Marcus Folkesson 2018-02-14 10:57:03 +01:00 committed by Nicolas Iooss
parent f281fc5219
commit f8532f1773
6 changed files with 31 additions and 31 deletions

2
README
View File

@ -19,6 +19,6 @@ lacks library functions or other dependencies relied upon by your
distribution. If it breaks, you get to keep both pieces. distribution. If it breaks, you get to keep both pieces.
To install libsepol on macOS (mainly for policy analysis): To install libsepol on macOS (mainly for policy analysis):
cd libsepol; make DESTDIR=/usr/local PREFIX=/usr/local install cd libsepol; make PREFIX=/usr/local install
This requires GNU coreutils (brew install coreutils). This requires GNU coreutils (brew install coreutils).

View File

@ -1,17 +1,17 @@
# Installation directories. # Installation directories.
PREFIX ?= $(DESTDIR)/usr PREFIX ?= /usr
INCDIR ?= $(PREFIX)/include/sepol INCDIR = $(PREFIX)/include/sepol
CILDIR ?= ../cil CILDIR ?= ../cil
all: all:
install: all install: all
test -d $(INCDIR) || install -m 755 -d $(INCDIR) test -d $(DESTDIR)$(INCDIR) || install -m 755 -d $(DESTDIR)$(INCDIR)
test -d $(INCDIR)/policydb || install -m 755 -d $(INCDIR)/policydb test -d $(DESTDIR)$(INCDIR)/policydb || install -m 755 -d $(DESTDIR)$(INCDIR)/policydb
test -d $(INCDIR)/cil || install -m 755 -d $(INCDIR)/cil test -d $(DESTDIR)$(INCDIR)/cil || install -m 755 -d $(DESTDIR)$(INCDIR)/cil
install -m 644 $(wildcard sepol/*.h) $(INCDIR) install -m 644 $(wildcard sepol/*.h) $(DESTDIR)$(INCDIR)
install -m 644 $(wildcard sepol/policydb/*.h) $(INCDIR)/policydb install -m 644 $(wildcard sepol/policydb/*.h) $(DESTDIR)$(INCDIR)/policydb
install -m 644 $(wildcard $(CILDIR)/include/cil/*.h) $(INCDIR)/cil install -m 644 $(wildcard $(CILDIR)/include/cil/*.h) $(DESTDIR)$(INCDIR)/cil
indent: indent:
../../scripts/Lindent $(wildcard sepol/*.h) ../../scripts/Lindent $(wildcard sepol/*.h)

View File

@ -1,12 +1,13 @@
# Installation directories. # Installation directories.
MAN8DIR ?= $(DESTDIR)/usr/share/man/man8 PREFIX ?= /usr
MAN3DIR ?= $(DESTDIR)/usr/share/man/man3 MAN8DIR ?= $(PREFIX)/share/man/man8
MAN3DIR ?= $(PREFIX)/share/man/man3
all: all:
install: all install: all
mkdir -p $(MAN3DIR) mkdir -p $(DESTDIR)$(MAN3DIR)
mkdir -p $(MAN8DIR) mkdir -p $(DESTDIR)$(MAN8DIR)
install -m 644 man3/*.3 $(MAN3DIR) install -m 644 man3/*.3 $(DESTDIR)$(MAN3DIR)
install -m 644 man8/*.8 $(MAN8DIR) install -m 644 man8/*.8 $(DESTDIR)$(MAN8DIR)

View File

@ -1,10 +1,9 @@
# Installation directories. # Installation directories.
PREFIX ?= $(DESTDIR)/usr PREFIX ?= /usr
INCLUDEDIR ?= $(PREFIX)/include INCLUDEDIR ?= $(PREFIX)/include
LIBDIR ?= $(PREFIX)/lib LIBDIR ?= $(PREFIX)/lib
SHLIBDIR ?= $(DESTDIR)/lib SHLIBDIR ?= /lib
RANLIB ?= ranlib RANLIB ?= ranlib
LIBBASE ?= $(shell basename $(LIBDIR))
CILDIR ?= ../cil CILDIR ?= ../cil
VERSION = $(shell cat ../VERSION) VERSION = $(shell cat ../VERSION)
@ -52,7 +51,7 @@ $(LIBSO): $(LOBJS) $(LIBMAP)
ln -sf $@ $(TARGET) ln -sf $@ $(TARGET)
$(LIBPC): $(LIBPC).in ../VERSION $(LIBPC): $(LIBPC).in ../VERSION
sed -e 's/@VERSION@/$(VERSION)/; s:@prefix@:$(PREFIX):; s:@libdir@:$(LIBBASE):; s:@includedir@:$(INCLUDEDIR):' < $< > $@ sed -e 's/@VERSION@/$(VERSION)/; s:@prefix@:$(PREFIX):; s:@libdir@:$(LIBDIR):; s:@includedir@:$(INCLUDEDIR):' < $< > $@
$(LIBMAP): $(LIBMAP).in $(LIBMAP): $(LIBMAP).in
ifneq ($(DISABLE_CIL),y) ifneq ($(DISABLE_CIL),y)
@ -80,16 +79,16 @@ endif
$(CC) $(CFLAGS) -fPIC -DSHARED -c -o $@ $< $(CC) $(CFLAGS) -fPIC -DSHARED -c -o $@ $<
install: all install: all
test -d $(LIBDIR) || install -m 755 -d $(LIBDIR) test -d $(DESTDIR)$(LIBDIR) || install -m 755 -d $(DESTDIR)$(LIBDIR)
install -m 644 $(LIBA) $(LIBDIR) install -m 644 $(LIBA) $(DESTDIR)$(LIBDIR)
test -d $(SHLIBDIR) || install -m 755 -d $(SHLIBDIR) test -d $(DESTDIR)$(SHLIBDIR) || install -m 755 -d $(DESTDIR)$(SHLIBDIR)
install -m 755 $(LIBSO) $(SHLIBDIR) install -m 755 $(LIBSO) $(DESTDIR)$(SHLIBDIR)
test -d $(LIBDIR)/pkgconfig || install -m 755 -d $(LIBDIR)/pkgconfig test -d $(DESTDIR)$(LIBDIR)/pkgconfig || install -m 755 -d $(DESTDIR)$(LIBDIR)/pkgconfig
install -m 644 $(LIBPC) $(LIBDIR)/pkgconfig install -m 644 $(LIBPC) $(DESTDIR)$(LIBDIR)/pkgconfig
$(LN) -sf --relative $(SHLIBDIR)/$(LIBSO) $(LIBDIR)/$(TARGET) $(LN) -sf --relative $(DESTDIR)$(SHLIBDIR)/$(LIBSO) $(DESTDIR)$(LIBDIR)/$(TARGET)
relabel: relabel:
/sbin/restorecon $(SHLIBDIR)/$(LIBSO) /sbin/restorecon $(DESTDIR)$(SHLIBDIR)/$(LIBSO)
clean: clean:
-rm -f $(LIBPC) $(LIBMAP) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(TARGET) $(CIL_GENERATED) -rm -f $(LIBPC) $(LIBMAP) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(TARGET) $(CIL_GENERATED)

View File

@ -1,6 +1,6 @@
prefix=@prefix@ prefix=@prefix@
exec_prefix=${prefix} exec_prefix=${prefix}
libdir=${exec_prefix}/@libdir@ libdir=@libdir@
includedir=@includedir@ includedir=@includedir@
Name: libsepol Name: libsepol

View File

@ -1,5 +1,5 @@
# Installation directories. # Installation directories.
PREFIX ?= $(DESTDIR)/usr PREFIX ?= /usr
BINDIR ?= $(PREFIX)/bin BINDIR ?= $(PREFIX)/bin
CFLAGS ?= -Wall -Werror CFLAGS ?= -Wall -Werror
@ -12,8 +12,8 @@ TARGETS=$(patsubst %.c,%,$(sort $(wildcard *.c)))
all: $(TARGETS) all: $(TARGETS)
install: all install: all
-mkdir -p $(BINDIR) -mkdir -p $(DESTDIR)$(BINDIR)
install -m 755 $(TARGETS) $(BINDIR) install -m 755 $(TARGETS) $(DESTDIR)$(BINDIR)
clean: clean:
-rm -f $(TARGETS) *.o -rm -f $(TARGETS) *.o