Re: Rework of makefiles v5

2018-02-22 Thread Marcus Folkesson
On Wed, Feb 21, 2018 at 10:46:45PM +0100, Nicolas Iooss wrote:
> On Thu, Feb 15, 2018 at 2:04 PM, Marcus Folkesson
> <marcus.folkes...@gmail.com> wrote:
> > Hi Nicolas,
> >
> > First of all, thank you for your review.
> >
> > On Wed, Feb 14, 2018 at 08:19:44PM +0100, Nicolas Iooss wrote:
> >> On Wed, Feb 14, 2018 at 10:57 AM, Marcus Folkesson
> >> <marcus.folkes...@gmail.com> wrote:
> >> > I have updated the patchset.
> >> >
> >> > The biggest change is that $(DESTDIR) is now used in the
> >> > install stage only.
> >> >
> >> > Also some overidden CFLAGS/LDFLAGS has been removed since we now have
> >> > explicit build rules.
> >> >
> >> > I have moved the changelog into patches.
> >> >
> >> > Please test to compile with:
> >> > make DESTDIR=/tmp/myroot PREFIX=/myusr install
> >> > or
> >> > make DESTDIR=/tmp/myroot install
> >> >
> >> > Thanks for all feedback.
> >> >
> >> > Best regards
> >> > Marcus Folkesson
> >> >
> >>
> >> Hi,
> >> Thanks for this update! Here are three comments on this patchset:
> >>
> >> * you forgot a $(DESTDIR) occurrence in patch 7.
> >
> > Good catch!
> >
> >> * .travis.yml needs a simple patch to fix the value of PYSITEDIR. I
> >> will send it later.
> >
> > Please do.
> >
> >> * While reading the Makefile after patch 15, I have been surprised by
> >> "LIBDIR ?= $(DESTDIR)$(PREFIX)/lib", with DESTDIR. As this variable is
> >> not exported, it works fine as it is, but it might be cleaner to
> >> define it as "LIBDIR ?= $(PREFIX)/lib" and to use $(DESTDIR) in the
> >> following lines. This point may be addressed in a follow-up commit
> >> after the patchset has been merged.
> >
> > I agree.
> > I also think it could be part of a follow-up commit. I will take a note.
> >
> >>
> >> As the patchset looks almost ready to be merged, I have created
> >> https://github.com/SELinuxProject/selinux/pull/79 with a modified
> >> patch 7 and my patch for .travis.yml. This pull request holds the
> >> commits I plan to apply in a few days if no other maintainer disagrees
> >> with this.
> >
> > Ok, then I will not come up with a v6 that fixes your feedback for patch
> > #7.
> 
> I have merged this patchset. Thanks!

Thank you.

Do you know when the next release is planned?
> 
> Nicolas
> 

Best regards
Marcus Folkesson




signature.asc
Description: PGP signature


Re: Rework of makefiles v5

2018-02-15 Thread Marcus Folkesson
Hi Nicolas,

First of all, thank you for your review.

On Wed, Feb 14, 2018 at 08:19:44PM +0100, Nicolas Iooss wrote:
> On Wed, Feb 14, 2018 at 10:57 AM, Marcus Folkesson
> <marcus.folkes...@gmail.com> wrote:
> > I have updated the patchset.
> >
> > The biggest change is that $(DESTDIR) is now used in the
> > install stage only.
> >
> > Also some overidden CFLAGS/LDFLAGS has been removed since we now have
> > explicit build rules.
> >
> > I have moved the changelog into patches.
> >
> > Please test to compile with:
> > make DESTDIR=/tmp/myroot PREFIX=/myusr install
> > or
> > make DESTDIR=/tmp/myroot install
> >
> > Thanks for all feedback.
> >
> > Best regards
> > Marcus Folkesson
> >
> 
> Hi,
> Thanks for this update! Here are three comments on this patchset:
> 
> * you forgot a $(DESTDIR) occurrence in patch 7.

Good catch!

> * .travis.yml needs a simple patch to fix the value of PYSITEDIR. I
> will send it later.

Please do.

> * While reading the Makefile after patch 15, I have been surprised by
> "LIBDIR ?= $(DESTDIR)$(PREFIX)/lib", with DESTDIR. As this variable is
> not exported, it works fine as it is, but it might be cleaner to
> define it as "LIBDIR ?= $(PREFIX)/lib" and to use $(DESTDIR) in the
> following lines. This point may be addressed in a follow-up commit
> after the patchset has been merged.

I agree.
I also think it could be part of a follow-up commit. I will take a note.

> 
> As the patchset looks almost ready to be merged, I have created
> https://github.com/SELinuxProject/selinux/pull/79 with a modified
> patch 7 and my patch for .travis.yml. This pull request holds the
> commits I plan to apply in a few days if no other maintainer disagrees
> with this.

Ok, then I will not come up with a v6 that fixes your feedback for patch
#7.

> 
> Best,
> Nicolas
> 

Best regards
Marcus Folkesson


signature.asc
Description: PGP signature


[PATCH v5 12/15] secilc: build: follow standard semantics for DESTDIR and PREFIX

2018-02-14 Thread Marcus Folkesson
Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
---

Notes:
v5:
- Only use $(DESTDIR) in install
v2:
- Rework all packages (not just selinux/sepol/semanage)

 secilc/Makefile | 16 +++-
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/secilc/Makefile b/secilc/Makefile
index 1cac53e4..dfd79cef 100644
--- a/secilc/Makefile
+++ b/secilc/Makefile
@@ -1,8 +1,6 @@
-PREFIX ?= $(DESTDIR)/usr
+PREFIX ?= /usr
 BINDIR ?= $(PREFIX)/bin
 MANDIR ?= $(PREFIX)/share/man
-LIBDIR ?= $(PREFIX)/lib
-INCLUDEDIR ?= $(PREFIX)/include
 
 SECILC = secilc
 SECILC_SRCS := secilc.c
@@ -41,12 +39,12 @@ $(SECIL2CONF_MANPAGE): $(SECIL2CONF_MANPAGE).xml
$(XMLTO) man $(SECIL2CONF_MANPAGE).xml
 
 install: all man
-   -mkdir -p $(BINDIR)
-   -mkdir -p $(MANDIR)/man8
-   install -m 755 $(SECILC) $(BINDIR)
-   install -m 755 $(SECIL2CONF) $(BINDIR)
-   install -m 644 $(SECILC_MANPAGE) $(MANDIR)/man8
-   install -m 644 $(SECIL2CONF_MANPAGE) $(MANDIR)/man8
+   -mkdir -p $(DESTDIR)$(BINDIR)
+   -mkdir -p $(DESTDIR)$(MANDIR)/man8
+   install -m 755 $(SECILC) $(DESTDIR)$(BINDIR)
+   install -m 755 $(SECIL2CONF) $(DESTDIR)$(BINDIR)
+   install -m 644 $(SECILC_MANPAGE) $(DESTDIR)$(MANDIR)/man8
+   install -m 644 $(SECIL2CONF_MANPAGE) $(DESTDIR)$(MANDIR)/man8
 
 doc:
$(MAKE) -C docs
-- 
2.15.1




[PATCH v5 01/15] libsepol: build: follow standard semantics for DESTDIR and PREFIX

2018-02-14 Thread Marcus Folkesson
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.folkes...@gmail.com>
---

Notes:
v5:
- Only use $(DESTDIR) in install
v4:
- Introduce LDLIBS_LIBSEPOLA if LIBSEPOLA is not defined.
v2:
- Use separate directories for shared libraries as before( Comment from 
Stephen Smalley)
- Rework all packages (not just selinux/sepol/semanage)

 README  |  2 +-
 libsepol/include/Makefile   | 16 
 libsepol/man/Makefile   | 13 +++--
 libsepol/src/Makefile   | 23 +++
 libsepol/src/libsepol.pc.in |  2 +-
 libsepol/utils/Makefile |  6 +++---
 6 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/README b/README
index 7fc7b17b..174551a1 100644
--- a/README
+++ b/README
@@ -19,6 +19,6 @@ lacks library functions or other dependencies relied upon by 
your
 distribution.  If it breaks, you get to keep both pieces.
 
 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).
diff --git a/libsepol/include/Makefile b/libsepol/include/Makefile
index 56b7a114..1ad4ecab 100644
--- a/libsepol/include/Makefile
+++ b/libsepol/include/Makefile
@@ -1,17 +1,17 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-INCDIR ?= $(PREFIX)/include/sepol
+PREFIX ?= /usr
+INCDIR = $(PREFIX)/include/sepol
 CILDIR ?= ../cil
 
 all:
 
 install: all
-   test -d $(INCDIR) || install -m 755 -d $(INCDIR)
-   test -d $(INCDIR)/policydb || install -m 755 -d $(INCDIR)/policydb
-   test -d $(INCDIR)/cil || install -m 755 -d $(INCDIR)/cil
-   install -m 644 $(wildcard sepol/*.h) $(INCDIR)
-   install -m 644 $(wildcard sepol/policydb/*.h) $(INCDIR)/policydb
-   install -m 644 $(wildcard $(CILDIR)/include/cil/*.h) $(INCDIR)/cil
+   test -d $(DESTDIR)$(INCDIR) || install -m 755 -d $(DESTDIR)$(INCDIR)
+   test -d $(DESTDIR)$(INCDIR)/policydb || install -m 755 -d 
$(DESTDIR)$(INCDIR)/policydb
+   test -d $(DESTDIR)$(INCDIR)/cil || install -m 755 -d 
$(DESTDIR)$(INCDIR)/cil
+   install -m 644 $(wildcard sepol/*.h) $(DESTDIR)$(INCDIR)
+   install -m 644 $(wildcard sepol/policydb/*.h) 
$(DESTDIR)$(INCDIR)/policydb
+   install -m 644 $(wildcard $(CILDIR)/include/cil/*.h) 
$(DESTDIR)$(INCDIR)/cil
 
 indent:
../../scripts/Lindent $(wildcard sepol/*.h)
diff --git a/libsepol/man/Makefile b/libsepol/man/Makefile
index 11924334..9b754548 100644
--- a/libsepol/man/Makefile
+++ b/libsepol/man/Makefile
@@ -1,12 +1,13 @@
 # Installation directories.
-MAN8DIR ?= $(DESTDIR)/usr/share/man/man8
-MAN3DIR ?= $(DESTDIR)/usr/share/man/man3
+PREFIX ?= /usr
+MAN8DIR ?= $(PREFIX)/share/man/man8
+MAN3DIR ?= $(PREFIX)/share/man/man3
 
 all:
 
 install: all
-   mkdir -p $(MAN3DIR)
-   mkdir -p $(MAN8DIR)
-   install -m 644 man3/*.3 $(MAN3DIR)
-   install -m 644 man8/*.8 $(MAN8DIR)
+   mkdir -p $(DESTDIR)$(MAN3DIR)
+   mkdir -p $(DESTDIR)$(MAN8DIR)
+   install -m 644 man3/*.3 $(DESTDIR)$(MAN3DIR)
+   install -m 644 man8/*.8 $(DESTDIR)$(MAN8DIR)
 
diff --git a/libsepol/src/Makefile b/libsepol/src/Makefile
index 819d261b..ccb70233 100644
--- a/libsepol/src/Makefile
+++ b/libsepol/src/Makefile
@@ -1,10 +1,9 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
+PREFIX ?= /usr
 INCLUDEDIR ?= $(PREFIX)/include
 LIBDIR ?= $(PREFIX)/lib
-SHLIBDIR ?= $(DESTDIR)/lib
+SHLIBDIR ?= /lib
 RANLIB ?= ranlib
-LIBBASE ?= $(shell basename $(LIBDIR))
 CILDIR ?= ../cil
 
 VERSION = $(shell cat ../VERSION)
@@ -52,7 +51,7 @@ $(LIBSO): $(LOBJS) $(LIBMAP)
ln -sf $@ $(TARGET) 
 
 $(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
 ifneq ($(DISABLE_CIL),y)
@@ -80,16 +79,16 @@ endif
$(CC) $(CFLAGS) -fPIC -DSHARED -c -o $@ $<
 
 install: all
-   test -d $(LIBDIR) || install -m 755 -d $(LIBDIR)
-   install -m 644 $(LIBA) $(LIBDIR)
-   test -d $(SHLIBDIR) || install -m 755 -d $(SHLIBDIR)
-   install -m 755 $(LIBSO) $(SHLIBDIR)
-   test -d $(LIBDIR)/pkgconfig || install -m 755 -d $(LIBDIR)/pkgconfig
-   install -m 644 $(LIBPC) $(LIBDIR)/pkgconfig
-   $(LN) -sf --relative $(SHLIBDIR)/$(LIBSO) $(LIBDIR)/$(TARGET)
+   test -d $(DESTDIR)$(LIBDIR) || install -m 755 -d $(DESTDIR)$(LIBDIR)
+ 

[PATCH v5 15/15] build: setup buildpaths if DESTDIR is specified

2018-02-14 Thread Marcus Folkesson
Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
---

Notes:
v4:
- add LIBDIR to LDFLAGS if DESTDIR is specified
- export LIBSEPOLA  if DESTDIR is specified

v3:
- Add default prefix

 Makefile | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 6da7f7b7..c238dbc8 100644
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,4 @@
+PREFIX ?= /usr
 OPT_SUBDIRS ?= dbus gui mcstrans python restorecond sandbox semodule-utils
 SUBDIRS=libsepol libselinux libsemanage checkpolicy secilc policycoreutils 
$(OPT_SUBDIRS)
 PYSUBDIRS=libselinux libsemanage
@@ -19,10 +20,14 @@ else
 endif
 
 ifneq ($(DESTDIR),)
-   CFLAGS += -I$(DESTDIR)/usr/include
-   LDFLAGS += -L$(DESTDIR)/usr/lib
+   LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
+   LIBSEPOLA ?= $(LIBDIR)/libsepol.a
+
+   CFLAGS += -I$(DESTDIR)$(PREFIX)/include
+   LDFLAGS += -L$(DESTDIR)$(PREFIX)/lib -L$(LIBDIR)
export CFLAGS
export LDFLAGS
+   export LIBSEPOLA
 endif
 
 all install relabel clean test indent:
-- 
2.15.1




[PATCH v5 14/15] dbus: build: follow standard semantics for DESTDIR and PREFIX

2018-02-14 Thread Marcus Folkesson
Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
---
 dbus/Makefile | 14 --
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/dbus/Makefile b/dbus/Makefile
index 9a6cc90e..53143aff 100644
--- a/dbus/Makefile
+++ b/dbus/Makefile
@@ -1,3 +1,5 @@
+PREFIX ?= /usr
+
 all:
 
 clean:
@@ -5,12 +7,12 @@ clean:
 install:
-mkdir -p $(DESTDIR)/etc/dbus-1/system.d/
install -m 644 org.selinux.conf $(DESTDIR)/etc/dbus-1/system.d/
-   -mkdir -p $(DESTDIR)/usr/share/dbus-1/system-services
-   install -m 644 org.selinux.service 
$(DESTDIR)/usr/share/dbus-1/system-services
-   -mkdir -p $(DESTDIR)/usr/share/polkit-1/actions/
-   install -m 644 org.selinux.policy $(DESTDIR)/usr/share/polkit-1/actions/
-   -mkdir -p $(DESTDIR)/usr/share/system-config-selinux
-   install -m 755 selinux_server.py 
$(DESTDIR)/usr/share/system-config-selinux
+   -mkdir -p $(DESTDIR)$(PREFIX)/share/dbus-1/system-services
+   install -m 644 org.selinux.service 
$(DESTDIR)$(PREFIX)/share/dbus-1/system-services
+   -mkdir -p $(DESTDIR)$(PREFIX)/share/polkit-1/actions/
+   install -m 644 org.selinux.policy 
$(DESTDIR)$(PREFIX)/share/polkit-1/actions/
+   -mkdir -p $(DESTDIR)$(PREFIX)/share/system-config-selinux
+   install -m 755 selinux_server.py 
$(DESTDIR)$(PREFIX)/share/system-config-selinux
 
 relabel:
 
-- 
2.15.1




[PATCH v5 09/15] python: build: move modules from platform-specific to platform-shared

2018-02-14 Thread Marcus Folkesson
Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
---
 python/semanage/Makefile  | 2 +-
 python/sepolgen/src/sepolgen/Makefile | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/python/semanage/Makefile b/python/semanage/Makefile
index a8465e62..5fc1998e 100644
--- a/python/semanage/Makefile
+++ b/python/semanage/Makefile
@@ -4,7 +4,7 @@ PYTHON ?= python
 PREFIX ?= /usr
 SBINDIR ?= $(PREFIX)/sbin
 MANDIR = $(PREFIX)/share/man
-PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import *; 
print(get_python_lib(plat_specific=1, prefix='$(PREFIX)'))")
+PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import *; 
print(get_python_lib(prefix='$(PREFIX)'))")
 PACKAGEDIR ?= $(PYTHONLIBDIR)
 BASHCOMPLETIONDIR ?= $(PREFIX)/share/bash-completion/completions
 
diff --git a/python/sepolgen/src/sepolgen/Makefile 
b/python/sepolgen/src/sepolgen/Makefile
index 6d392f5d..c75809ad 100644
--- a/python/sepolgen/src/sepolgen/Makefile
+++ b/python/sepolgen/src/sepolgen/Makefile
@@ -1,6 +1,6 @@
 PREFIX ?= /usr
 PYTHON ?= python
-PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import *; 
print(get_python_lib(plat_specific=1, prefix='$(PREFIX)'))")
+PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import *; 
print(get_python_lib(prefix='$(PREFIX)'))")
 PACKAGEDIR ?= /$(PYTHONLIBDIR)/sepolgen
 
 all:
-- 
2.15.1




[PATCH v5 13/15] semodule-utils: build: follow standard semantics for DESTDIR and PREFIX

2018-02-14 Thread Marcus Folkesson
Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
---

Notes:
v5:
- Only use $(DESTDIR) in install
v2:
- Rework all packages (not just selinux/sepol/semanage)

 semodule-utils/semodule_expand/Makefile  | 12 +---
 semodule-utils/semodule_link/Makefile| 12 +---
 semodule-utils/semodule_package/Makefile | 16 +++-
 3 files changed, 17 insertions(+), 23 deletions(-)

diff --git a/semodule-utils/semodule_expand/Makefile 
b/semodule-utils/semodule_expand/Makefile
index 072f2137..f1a1c8f3 100644
--- a/semodule-utils/semodule_expand/Makefile
+++ b/semodule-utils/semodule_expand/Makefile
@@ -1,8 +1,6 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-INCLUDEDIR ?= $(PREFIX)/include
+PREFIX ?= /usr
 BINDIR ?= $(PREFIX)/bin
-LIBDIR ?= $(PREFIX)/lib
 MANDIR ?= $(PREFIX)/share/man
 
 CFLAGS ?= -Werror -Wall -W
@@ -13,10 +11,10 @@ all: semodule_expand
 semodule_expand:  semodule_expand.o 
 
 install: all
-   -mkdir -p $(BINDIR)
-   install -m 755 semodule_expand $(BINDIR)
-   test -d $(MANDIR)/man8 || install -m 755 -d $(MANDIR)/man8
-   install -m 644 semodule_expand.8 $(MANDIR)/man8/
+   -mkdir -p $(DESTDIR)$(BINDIR)
+   install -m 755 semodule_expand $(DESTDIR)$(BINDIR)
+   test -d $(DESTDIR)$(MANDIR)/man8 || install -m 755 -d 
$(DESTDIR)$(MANDIR)/man8
+   install -m 644 semodule_expand.8 $(DESTDIR)$(MANDIR)/man8/
 
 relabel:
 
diff --git a/semodule-utils/semodule_link/Makefile 
b/semodule-utils/semodule_link/Makefile
index cc4687bd..692cb026 100644
--- a/semodule-utils/semodule_link/Makefile
+++ b/semodule-utils/semodule_link/Makefile
@@ -1,9 +1,7 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-INCLUDEDIR ?= $(PREFIX)/include
+PREFIX ?= /usr
 BINDIR ?= $(PREFIX)/bin
 MANDIR ?= $(PREFIX)/share/man
-LIBDIR ?= $(PREFIX)/lib
 
 CFLAGS ?= -Werror -Wall -W
 override LDLIBS += -lsepol
@@ -13,10 +11,10 @@ all: semodule_link
 semodule_link:  semodule_link.o 
 
 install: all
-   -mkdir -p $(BINDIR)
-   install -m 755 semodule_link $(BINDIR)
-   test -d $(MANDIR)/man8 || install -m 755 -d $(MANDIR)/man8
-   install -m 644 semodule_link.8 $(MANDIR)/man8/
+   -mkdir -p $(DESTDIR)$(BINDIR)
+   install -m 755 semodule_link $(DESTDIR)$(BINDIR)
+   test -d $(DESTDIR)$(MANDIR)/man8 || install -m 755 -d 
$(DESTDIR)$(MANDIR)/man8
+   install -m 644 semodule_link.8 $(DESTDIR)$(MANDIR)/man8/
 
 relabel:
 
diff --git a/semodule-utils/semodule_package/Makefile 
b/semodule-utils/semodule_package/Makefile
index 96dd7c4f..da170267 100644
--- a/semodule-utils/semodule_package/Makefile
+++ b/semodule-utils/semodule_package/Makefile
@@ -1,8 +1,6 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-INCLUDEDIR ?= $(PREFIX)/include
+PREFIX ?= /usr
 BINDIR ?= $(PREFIX)/bin
-LIBDIR ?= $(PREFIX)/lib
 MANDIR ?= $(PREFIX)/share/man
 
 CFLAGS ?= -Werror -Wall -W
@@ -13,12 +11,12 @@ all: semodule_package semodule_unpackage
 semodule_package:  semodule_package.o 
 
 install: all
-   -mkdir -p $(BINDIR)
-   install -m 755 semodule_package $(BINDIR)
-   install -m 755 semodule_unpackage $(BINDIR)
-   test -d $(MANDIR)/man8 || install -m 755 -d $(MANDIR)/man8
-   install -m 644 semodule_package.8 $(MANDIR)/man8/
-   install -m 644 semodule_unpackage.8 $(MANDIR)/man8/
+   -mkdir -p $(DESTDIR)$(BINDIR)
+   install -m 755 semodule_package $(DESTDIR)$(BINDIR)
+   install -m 755 semodule_unpackage $(DESTDIR)$(BINDIR)
+   test -d $(DESTDIR)$(MANDIR)/man8 || install -m 755 -d 
$(DESTDIR)$(MANDIR)/man8
+   install -m 644 semodule_package.8 $(DESTDIR)$(MANDIR)/man8/
+   install -m 644 semodule_unpackage.8 $(DESTDIR)$(MANDIR)/man8/
 
 relabel:
 
-- 
2.15.1




[PATCH v5 07/15] policycoreutils: build: follow standard semantics for DESTDIR and PREFIX

2018-02-14 Thread Marcus Folkesson
Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
---

Notes:
v5:
- Only use $(DESTDIR) in install
v2:
- Rework all packages (not just selinux/sepol/semanage)

 policycoreutils/hll/pp/Makefile  |  9 +++--
 policycoreutils/load_policy/Makefile | 16 
 policycoreutils/man/Makefile |  7 ---
 policycoreutils/newrole/Makefile | 24 
 policycoreutils/po/Makefile  |  7 ---
 policycoreutils/run_init/Makefile| 22 +++---
 policycoreutils/scripts/Makefile | 13 ++---
 policycoreutils/secon/Makefile   | 12 +---
 policycoreutils/semodule/Makefile| 16 +++-
 policycoreutils/sestatus/Makefile| 21 ++---
 policycoreutils/setfiles/Makefile| 23 +++
 policycoreutils/setsebool/Makefile   | 18 --
 12 files changed, 89 insertions(+), 99 deletions(-)

diff --git a/policycoreutils/hll/pp/Makefile b/policycoreutils/hll/pp/Makefile
index 3401dcc9..fc8d3c4a 100644
--- a/policycoreutils/hll/pp/Makefile
+++ b/policycoreutils/hll/pp/Makefile
@@ -1,8 +1,5 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-INCLUDEDIR ?= $(PREFIX)/include
-MANDIR = $(PREFIX)/share/man
-LIBDIR ?= $(PREFIX)/lib
+PREFIX ?= /usr
 LIBEXECDIR ?= $(PREFIX)/libexec
 HLLDIR ?= $(LIBEXECDIR)/selinux/hll
 
@@ -21,8 +18,8 @@ pp: $(PP_OBJS)
$(CC) $(CFLAGS) -c -o $@ $^
 
 install: all
-   -mkdir -p $(HLLDIR)
-   install -m 755 pp $(HLLDIR)
+   -mkdir -p $(DESTDIR)$(HLLDIR)
+   install -m 755 pp $(DESTDIR)$(HLLDIR)
 
 relabel:
 
diff --git a/policycoreutils/load_policy/Makefile 
b/policycoreutils/load_policy/Makefile
index b85833c2..568d5d49 100644
--- a/policycoreutils/load_policy/Makefile
+++ b/policycoreutils/load_policy/Makefile
@@ -1,8 +1,8 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-SBINDIR ?= $(DESTDIR)/sbin
+PREFIX ?= /usr
+SBINDIR ?= $(PREFIX)/sbin
 MANDIR ?= $(PREFIX)/share/man
-LOCALEDIR ?= /usr/share/locale
+LOCALEDIR ?= $(DESTDIR)$(PREFIX)/share/locale
 
 CFLAGS ?= -Werror -Wall -W
 override CFLAGS += $(LDFLAGS) -DUSE_NLS -DLOCALEDIR="\"$(LOCALEDIR)\"" 
-DPACKAGE="\"policycoreutils\""
@@ -13,10 +13,10 @@ TARGETS=$(patsubst %.c,%,$(sort $(wildcard *.c)))
 all: $(TARGETS)
 
 install: all
-   -mkdir -p $(SBINDIR)
-   install -m 755 $(TARGETS) $(SBINDIR)
-   test -d $(MANDIR)/man8 || install -m 755 -d $(MANDIR)/man8
-   install -m 644 load_policy.8 $(MANDIR)/man8/
+   -mkdir -p $(DESTDIR)$(SBINDIR)
+   install -m 755 $(TARGETS) $(DESTDIR)$(SBINDIR)
+   test -d $(DESTDIR)$(MANDIR)/man8 || install -m 755 -d 
$(DESTDIR)$(MANDIR)/man8
+   install -m 644 load_policy.8 $(DESTDIR)$(MANDIR)/man8/
 
 clean:
-rm -f $(TARGETS) *.o 
@@ -25,4 +25,4 @@ indent:
../../scripts/Lindent $(wildcard *.[ch])
 
 relabel:
-   /sbin/restorecon $(SBINDIR)/load_policy 
+   /sbin/restorecon $(DESTDIR)$(SBINDIR)/load_policy 
diff --git a/policycoreutils/man/Makefile b/policycoreutils/man/Makefile
index 0d91cd46..8af1520c 100644
--- a/policycoreutils/man/Makefile
+++ b/policycoreutils/man/Makefile
@@ -1,12 +1,13 @@
 # Installation directories.
-MAN5DIR ?= $(DESTDIR)/usr/share/man/man5
+PREFIX ?= /usr
+MAN5DIR ?= $(PREFIX)/share/man/man5
 
 all:
 
 clean:
 
 install: all
-   mkdir -p $(MAN5DIR)
-   install -m 644 man5/*.5 $(MAN5DIR)
+   mkdir -p $(DESTDIR)$(MAN5DIR)
+   install -m 644 man5/*.5 $(DESTDIR)$(MAN5DIR)
 
 relabel:
diff --git a/policycoreutils/newrole/Makefile b/policycoreutils/newrole/Makefile
index 196af926..a1bfe1a6 100644
--- a/policycoreutils/newrole/Makefile
+++ b/policycoreutils/newrole/Makefile
@@ -1,9 +1,9 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
+PREFIX ?= /usr
 BINDIR ?= $(PREFIX)/bin
 MANDIR ?= $(PREFIX)/share/man
-ETCDIR ?= $(DESTDIR)/etc
-LOCALEDIR = /usr/share/locale
+ETCDIR ?= /etc
+LOCALEDIR = $(DESTDIR)$(PREFIX)/share/locale
 PAMH ?= $(shell test -f /usr/include/security/pam_appl.h && echo y)
 AUDITH ?= $(shell test -f /usr/include/libaudit.h && echo y)
 # Enable capabilities to permit newrole to generate audit records.
@@ -61,17 +61,17 @@ newrole: newrole.o $(EXTRA_OBJS)
$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS)
 
 install: all
-   test -d $(BINDIR)  || install -m 755 -d $(BINDIR)
-   test -d $(ETCDIR)/pam.d || install -m 755 -d $(ETCDIR)/pam.d
-   test -d $(MANDIR)/man1 || install -m 755 -d $(MANDIR)/man1
-   install -m $(MODE) newrole $(BINDIR)
-   install -m 644 newrole.1 $(MANDIR)/man1/
+   test -d $(DESTDIR)$(BINDIR)  || install -m 755 -d 
$(DESTDIR)$(BINDIR)
+   test -d $(DESTDIR)$(ETCDIR)/pam.d || install -m 755 -d 
$(DESTDIR)$(ETCDIR)/pam.d
+   test -d $(DESTDIR)$(MANDIR)/man1 || install -m 755 -d 
$(DESTDIR)$(MANDIR)/man1
+   install -m $(MODE) newrole $(DESTDIR)$(BINDIR)
+   instal

[PATCH v5 08/15] python: build: follow standard semantics for DESTDIR and PREFIX

2018-02-14 Thread Marcus Folkesson
Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
---

Notes:
v5:
- Only use $(DESTDIR) in install
- Remove CFLAGS from linking rule

v4:
-  move platform from platform specific to platform shared installation 
directory

v3:
- Add missing slash
- keep the possibility to specify LIBSEPOLA to
  make depending component recompile on change. If not specified, fall 
back to
  libsepola in LDFLAGS path.

v2:
- Rework all packages (not just selinux/sepol/semanage)

 python/audit2allow/Makefile   | 30 +-
 python/chcat/Makefile | 11 +--
 python/semanage/Makefile  | 25 -
 python/sepolgen/src/sepolgen/Makefile |  9 +
 python/sepolgen/src/share/Makefile|  8 
 python/sepolicy/Makefile  | 24 ++--
 6 files changed, 53 insertions(+), 54 deletions(-)

diff --git a/python/audit2allow/Makefile b/python/audit2allow/Makefile
index 8db8075f..513bb2b6 100644
--- a/python/audit2allow/Makefile
+++ b/python/audit2allow/Makefile
@@ -1,19 +1,23 @@
 PYTHON ?= python
 
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
+PREFIX ?= /usr
 BINDIR ?= $(PREFIX)/bin
-LIBDIR ?= $(PREFIX)/lib
 MANDIR ?= $(PREFIX)/share/man
-LOCALEDIR ?= /usr/share/locale
-INCLUDEDIR ?= $(PREFIX)/include
-LIBSEPOLA ?= $(LIBDIR)/libsepol.a
 
 CFLAGS ?= -Werror -Wall -W
 
+# If no specific libsepol.a is specified, fall back on LDFLAGS search path
+# Otherwise, as $(LIBSEPOLA) already appears in the dependencies, there
+# is no need to define a value for LDLIBS_LIBSEPOLA
+ifeq ($(LIBSEPOLA),)
+LDLIBS_LIBSEPOLA := -l:libsepol.a
+endif
+
 all: audit2why sepolgen-ifgen-attr-helper
 
 sepolgen-ifgen-attr-helper: sepolgen-ifgen-attr-helper.o $(LIBSEPOLA)
+   $(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS_LIBSEPOLA)
 
 audit2why:
ln -sf audit2allow audit2why
@@ -22,14 +26,14 @@ test: all
@$(PYTHON) test_audit2allow.py -v
 
 install: all
-   -mkdir -p $(BINDIR)
-   install -m 755 audit2allow $(BINDIR)
-   (cd $(BINDIR); ln -sf audit2allow audit2why)
-   install -m 755 sepolgen-ifgen-attr-helper $(BINDIR)
-   install -m 755 sepolgen-ifgen $(BINDIR)
-   -mkdir -p $(MANDIR)/man1
-   install -m 644 audit2allow.1 $(MANDIR)/man1/
-   install -m 644 audit2why.1 $(MANDIR)/man1/
+   -mkdir -p $(DESTDIR)$(BINDIR)
+   install -m 755 audit2allow $(DESTDIR)$(BINDIR)
+   (cd $(DESTDIR)$(BINDIR); ln -sf audit2allow audit2why)
+   install -m 755 sepolgen-ifgen-attr-helper $(DESTDIR)$(BINDIR)
+   install -m 755 sepolgen-ifgen $(DESTDIR)$(BINDIR)
+   -mkdir -p $(DESTDIR)$(MANDIR)/man1
+   install -m 644 audit2allow.1 $(DESTDIR)$(MANDIR)/man1/
+   install -m 644 audit2why.1 $(DESTDIR)$(MANDIR)/man1/
 
 clean:
rm -f *~ *.o sepolgen-ifgen-attr-helper
diff --git a/python/chcat/Makefile b/python/chcat/Makefile
index 0fd12d6d..290b9a6e 100644
--- a/python/chcat/Makefile
+++ b/python/chcat/Makefile
@@ -1,17 +1,16 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
+PREFIX ?= /usr
 BINDIR ?= $(PREFIX)/bin
 MANDIR ?= $(PREFIX)/share/man
-LOCALEDIR ?= $(PREFIX)/share/locale
 
 .PHONY: all
 all: chcat
 
 install: all
-   -mkdir -p $(BINDIR)
-   install -m 755 chcat $(BINDIR)
-   -mkdir -p $(MANDIR)/man8
-   install -m 644 chcat.8 $(MANDIR)/man8/
+   -mkdir -p $(DESTDIR)$(BINDIR)
+   install -m 755 chcat $(DESTDIR)$(BINDIR)
+   -mkdir -p $(DESTDIR)$(MANDIR)/man8
+   install -m 644 chcat.8 $(DESTDIR)$(MANDIR)/man8/
 
 clean:
 
diff --git a/python/semanage/Makefile b/python/semanage/Makefile
index 132162bc..a8465e62 100644
--- a/python/semanage/Makefile
+++ b/python/semanage/Makefile
@@ -1,13 +1,12 @@
 PYTHON ?= python
 
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-LIBDIR ?= $(PREFIX)/lib
+PREFIX ?= /usr
 SBINDIR ?= $(PREFIX)/sbin
 MANDIR = $(PREFIX)/share/man
-PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import *; 
print(get_python_lib(1))")
-PACKAGEDIR ?= $(DESTDIR)/$(PYTHONLIBDIR)
-BASHCOMPLETIONDIR ?= $(DESTDIR)/usr/share/bash-completion/completions
+PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import *; 
print(get_python_lib(plat_specific=1, prefix='$(PREFIX)'))")
+PACKAGEDIR ?= $(PYTHONLIBDIR)
+BASHCOMPLETIONDIR ?= $(PREFIX)/share/bash-completion/completions
 
 TARGETS=semanage
 
@@ -16,14 +15,14 @@ BASHCOMPLETIONS=semanage-bash-completion.sh
 all: $(TARGETS)
 
 install: all
-   [ -d $(MANDIR)/man8 ] || mkdir -p $(MANDIR)/man8
-   -mkdir -p $(SBINDIR)
-   install -m 755 semanage $(SBINDIR)
-   install -m 644 *.8 $(MANDIR)/man8
-   test -d $(PACKAGEDIR) || install -m 755 -d $(PACKAGEDIR)
-   install -m 755 seobject.py $(PACKAGEDIR)
-   -mkdir -p $(BASHCOMPLETIONDIR)
-   install -m 644 $(BASHCOMPLETIONS) $(BASHCOMPLETION

[PATCH v5 06/15] mcstrans: build: follow standard semantics for DESTDIR and PREFIX

2018-02-14 Thread Marcus Folkesson
Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
---

Notes:
v5:
- Only use $(DESTDIR) in install
- Remove CFLAGS from linking rule
- Do not override CFLAGS

v3:
- keep the possibility to specify LIBSEPOLA to
make depending component recompile on change. If not specified, fall 
back to
libsepola in LDFLAGS path.

v2:
- Rework all packages (not just selinux/sepol/semanage)

 mcstrans/man/Makefile   |  7 ---
 mcstrans/src/Makefile   | 36 
 mcstrans/utils/Makefile | 28 ++--
 3 files changed, 42 insertions(+), 29 deletions(-)

diff --git a/mcstrans/man/Makefile b/mcstrans/man/Makefile
index 8e971192..645f6286 100644
--- a/mcstrans/man/Makefile
+++ b/mcstrans/man/Makefile
@@ -1,11 +1,12 @@
 # Installation directories.
-MAN8DIR ?= $(DESTDIR)/usr/share/man/man8
+PREFIX ?= /usr
+MAN8DIR ?= $(PREFIX)/share/man/man8
 
 all:
 
 install: all
-   mkdir -p $(MAN8DIR)
-   install -m 644 man8/*.8 $(MAN8DIR)
+   mkdir -p $(DESTDIR)$(MAN8DIR)
+   install -m 644 man8/*.8 $(DESTDIR)$(MAN8DIR)
 
 clean:
-rm -f *~ \#*
diff --git a/mcstrans/src/Makefile b/mcstrans/src/Makefile
index 3f4a89c3..76ef0557 100644
--- a/mcstrans/src/Makefile
+++ b/mcstrans/src/Makefile
@@ -1,33 +1,37 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-LIBDIR ?= $(PREFIX)/lib
-SBINDIR ?= $(DESTDIR)/sbin
-INITDIR ?= $(DESTDIR)/etc/rc.d/init.d
-SYSTEMDDIR ?= $(DESTDIR)/usr/lib/systemd
-LIBSEPOLA ?= $(LIBDIR)/libsepol.a
+PREFIX ?= /usr
+SBINDIR ?= /sbin
+INITDIR ?= /etc/rc.d/init.d
+SYSTEMDDIR ?= $(PREFIX)/lib/systemd
+
+# If no specific libsepol.a is specified, fall back on LDFLAGS search path
+# Otherwise, as $(LIBSEPOLA) already appears in the dependencies, there
+# is no need to define a value for LDLIBS_LIBSEPOLA
+ifeq ($(LIBSEPOLA),)
+LDLIBS_LIBSEPOLA := -l:libsepol.a
+endif
 
 PROG_SRC=mcstrans.c  mcscolor.c  mcstransd.c  mls_level.c
 PROG_OBJS= $(patsubst %.c,%.o,$(PROG_SRC))
 PROG=mcstransd
 INITSCRIPT=mcstrans
 CFLAGS ?= -Wall -W -Wundef -Wmissing-noreturn -Wmissing-format-attribute
-override CFLAGS += -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
 
 all: $(PROG)
 
-$(PROG): $(PROG_OBJS)
-   $(CC) $(LDFLAGS) -pie -o $@ $^ -lselinux -lcap -lpcre $(LIBSEPOLA)
+$(PROG): $(PROG_OBJS) $(LIBSEPOLA)
+   $(CC) $(LDFLAGS) -pie -o $@ $^ -lselinux -lcap -lpcre 
$(LDLIBS_LIBSEPOLA)
 
 %.o:  %.c 
-   $(CC) $(CFLAGS) -fPIE -c -o $@ $<
+   $(CC) $(CFLAGS) -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -fPIE -c -o $@ $<
 
 install: all
-   test -d $(SBINDIR) || install -m 755 -d $(SBINDIR)
-   install -m 755 $(PROG) $(SBINDIR)
-   test -d $(INITDIR) || install -m 755 -d $(INITDIR)
-   install -m 755 $(INITSCRIPT).init $(INITDIR)/$(INITSCRIPT)
-   test -d $(SYSTEMDDIR)/system || install -m 755 -d $(SYSTEMDDIR)/system
-   install -m 644 mcstrans.service $(SYSTEMDDIR)/system/
+   test -d $(DESTDIR)$(SBINDIR) || install -m 755 -d $(DESTDIR)$(SBINDIR)
+   install -m 755 $(PROG) $(DESTDIR)$(SBINDIR)
+   test -d $(DESTDIR)$(INITDIR) || install -m 755 -d $(DESTDIR)$(INITDIR)
+   install -m 755 $(INITSCRIPT).init $(DESTDIR)$(INITDIR)/$(INITSCRIPT)
+   test -d $(DESTDIR)$(SYSTEMDDIR)/system || install -m 755 -d 
$(DESTDIR)$(SYSTEMDDIR)/system
+   install -m 644 mcstrans.service $(DESTDIR)$(SYSTEMDDIR)/system/
 
 clean: 
-rm -f $(OBJS) $(LOBJS) $(TARGET) $(PROG) $(PROG_OBJS) *~ \#*
diff --git a/mcstrans/utils/Makefile b/mcstrans/utils/Makefile
index 4d3cbfcb..9dfe7723 100644
--- a/mcstrans/utils/Makefile
+++ b/mcstrans/utils/Makefile
@@ -1,22 +1,30 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-LIBDIR ?= $(PREFIX)/lib
+PREFIX ?= /usr
 SBINDIR ?= $(PREFIX)/sbin
-LIBSEPOLA ?= $(LIBDIR)/libsepol.a
 
-CFLAGS ?= -Wall
-override CFLAGS += -I../src -D_GNU_SOURCE
-override LDLIBS += -lselinux -lpcre
+TARGETS=transcon untranscon
 
-TARGETS=$(patsubst %.c,%,$(sort $(wildcard *.c)))
+# If no specific libsepol.a is specified, fall back on LDFLAGS search path
+# Otherwise, as $(LIBSEPOLA) already appears in the dependencies, there
+# is no need to define a value for LDLIBS_LIBSEPOLA
+ifeq ($(LIBSEPOLA),)
+LDLIBS_LIBSEPOLA := -l:libsepol.a
+endif
 
 all: $(TARGETS)
 
-$(TARGETS): ../src/mcstrans.o ../src/mls_level.o $(LIBSEPOLA)
+transcon: transcon.o ../src/mcstrans.o ../src/mls_level.o $(LIBSEPOLA)
+   $(CC) $(LDFLAGS) -o $@ $^ -lpcre -lselinux $(LDLIBS_LIBSEPOLA)
+
+untranscon: untranscon.o ../src/mcstrans.o ../src/mls_level.o $(LIBSEPOLA)
+   $(CC) $(LDFLAGS) -o $@ $^ -lpcre -lselinux $(LDLIBS_LIBSEPOLA)
+
+%.o:  %.c 
+   $(CC) $(CFLAGS) -D_GNU_SOURCE -I../src -fPIE -c -o $@ $<
 
 install: all
-   -mkdir -p $(SBINDIR)
-   install -m 755 $(TARGETS) $(SBINDIR)
+   -mkdir -p $(DESTDIR)$(SBINDIR)
+   install -m 755 $(TARGETS) $(DESTDIR)$(SBINDIR)
 
 test:
./mlstrans-test-ru

Rework of makefiles v5

2018-02-14 Thread Marcus Folkesson
I have updated the patchset.

The biggest change is that $(DESTDIR) is now used in the
install stage only.

Also some overidden CFLAGS/LDFLAGS has been removed since we now have
explicit build rules.

I have moved the changelog into patches.

Please test to compile with:
make DESTDIR=/tmp/myroot PREFIX=/myusr install
or
make DESTDIR=/tmp/myroot install

Thanks for all feedback.

Best regards
Marcus Folkesson




[PATCH v5 04/15] checkpolicy: build: follow standard semantics for DESTDIR and PREFIX

2018-02-14 Thread Marcus Folkesson
This patch solves the following issues:
- 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.folkes...@gmail.com>
---

Notes:
v5:
- Only use $(DESTDIR) in install
- Remove CFLAGS from linking rule
- Do not override CFLAGS
v4:
- Introduce LDLIBS_LIBSEPOLA if LIBSEPOLA is not defined.

v2:
- Rework all packages (not just selinux/sepol/semanage)

 checkpolicy/Makefile  | 28 
 checkpolicy/test/Makefile | 15 +--
 2 files changed, 25 insertions(+), 18 deletions(-)

diff --git a/checkpolicy/Makefile b/checkpolicy/Makefile
index 68e11f2a..4c817cd6 100644
--- a/checkpolicy/Makefile
+++ b/checkpolicy/Makefile
@@ -1,12 +1,9 @@
 #
 # Makefile for building the checkpolicy program
 #
-PREFIX ?= $(DESTDIR)/usr
+PREFIX ?= /usr
 BINDIR ?= $(PREFIX)/bin
 MANDIR ?= $(PREFIX)/share/man
-LIBDIR ?= $(PREFIX)/lib
-INCLUDEDIR ?= $(PREFIX)/include
-LIBSEPOLA ?= $(LIBDIR)/libsepol.a
 TARGETS = checkpolicy checkmodule
 
 LEX = flex
@@ -14,7 +11,12 @@ YACC = bison -y
 
 CFLAGS ?= -g -Wall -Werror -Wshadow -O2 -pipe -fno-strict-aliasing
 
-override CFLAGS += -I.
+# If no specific libsepol.a is specified, fall back on LDFLAGS search path
+# Otherwise, as $(LIBSEPOLA) already appears in the dependencies, there
+# is no need to define a value for LDLIBS_LIBSEPOLA
+ifeq ($(LIBSEPOLA),)
+LDLIBS_LIBSEPOLA := -l:libsepol.a
+endif
 
 CHECKOBJS = y.tab.o lex.yy.o queue.o module_compiler.o parse_util.o \
policy_define.o
@@ -27,8 +29,10 @@ all:  $(TARGETS)
$(MAKE) -C test
 
 checkpolicy: $(CHECKPOLOBJS) $(LIBSEPOLA)
+   $(CC) -o $@ $^ $(LDFLAGS) $(LDLIBS_LIBSEPOLA)
 
 checkmodule: $(CHECKMODOBJS) $(LIBSEPOLA)
+   $(CC) -o $@ $^ $(LDFLAGS) $(LDLIBS_LIBSEPOLA)
 
 %.o: %.c 
$(CC) $(CFLAGS) -o $@ -c $<
@@ -46,15 +50,15 @@ lex.yy.c: policy_scan.l y.tab.c
$(LEX) policy_scan.l
 
 install: all
-   -mkdir -p $(BINDIR)
-   -mkdir -p $(MANDIR)/man8
-   install -m 755 $(TARGETS) $(BINDIR) 
-   install -m 644 checkpolicy.8 $(MANDIR)/man8
-   install -m 644 checkmodule.8 $(MANDIR)/man8
+   -mkdir -p $(DESTDIR)$(BINDIR)
+   -mkdir -p $(DESTDIR)$(MANDIR)/man8
+   install -m 755 $(TARGETS) $(DESTDIR)$(BINDIR)   
+   install -m 644 checkpolicy.8 $(DESTDIR)$(MANDIR)/man8
+   install -m 644 checkmodule.8 $(DESTDIR)$(MANDIR)/man8
 
 relabel: install
-   /sbin/restorecon $(BINDIR)/checkpolicy
-   /sbin/restorecon $(BINDIR)/checkmodule
+   /sbin/restorecon $(DESTDIR)$(BINDIR)/checkpolicy
+   /sbin/restorecon $(DESTDIR)$(BINDIR)/checkmodule
 
 clean:
-rm -f $(TARGETS) $(CHECKPOLOBJS) $(CHECKMODOBJS) y.tab.c y.tab.h 
lex.yy.c
diff --git a/checkpolicy/test/Makefile b/checkpolicy/test/Makefile
index 59fa4460..89e7557c 100644
--- a/checkpolicy/test/Makefile
+++ b/checkpolicy/test/Makefile
@@ -1,19 +1,22 @@
 #
 # Makefile for building the dispol program
 #
-PREFIX ?= $(DESTDIR)/usr
-BINDIR ?= $(PREFIX)/bin
-LIBDIR ?= $(PREFIX)/lib
-INCLUDEDIR ?= $(PREFIX)/include
-LIBSEPOLA ?= $(LIBDIR)/libsepol.a
-
 CFLAGS ?= -g -Wall -W -Werror -O2 -pipe
 
+# If no specific libsepol.a is specified, fall back on LDFLAGS search path
+# Otherwise, as $(LIBSEPOLA) already appears in the dependencies, there
+# is no need to define a value for LDLIBS_LIBSEPOLA
+ifeq ($(LIBSEPOLA),)
+LDLIBS_LIBSEPOLA := -l:libsepol.a
+endif
+
 all: dispol dismod
 
 dispol: dispol.o $(LIBSEPOLA)
+   $(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS_LIBSEPOLA)
 
 dismod: dismod.o $(LIBSEPOLA)
+   $(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS_LIBSEPOLA)
 
 clean:
-rm -f dispol dismod *.o 
-- 
2.15.1




[PATCH v5 02/15] libselinux: build: follow standard semantics for DESTDIR and PREFIX

2018-02-14 Thread Marcus Folkesson
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.folkes...@gmail.com>
---

Notes:
v5:
-  Only use $(DESTDIR) in install
v4:
- move platform from platform specific to platform shared installation 
directory
- Introduce LDLIBS_LIBSEPOLA if LIBSEPOLA is not defined.

v3:
- keep the possibility to specify LIBSEPOLA to
  make depending component recompile on change. If not specified, fall 
back to
  libsepola in LDFLAGS path.

v2:
- Use separate directories for shared libraries as before( Comment from 
Stephen Smalley)
- Rework all packages (not just selinux/sepol/semanage)

 libselinux/include/Makefile |  8 +++
 libselinux/man/Makefile | 19 
 libselinux/src/Makefile | 49 +++--
 libselinux/src/libselinux.pc.in |  2 +-
 libselinux/utils/Makefile   |  8 +++
 5 files changed, 45 insertions(+), 41 deletions(-)

diff --git a/libselinux/include/Makefile b/libselinux/include/Makefile
index 757a6c9c..8ab9ce92 100644
--- a/libselinux/include/Makefile
+++ b/libselinux/include/Makefile
@@ -1,12 +1,12 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-INCDIR ?= $(PREFIX)/include/selinux
+PREFIX ?= /usr
+INCDIR = $(PREFIX)/include/selinux
 
 all:
 
 install: all
-   test -d $(INCDIR) || install -m 755 -d $(INCDIR)
-   install -m 644 $(wildcard selinux/*.h) $(INCDIR)
+   test -d $(DESTDIR)$(INCDIR) || install -m 755 -d $(DESTDIR)$(INCDIR)
+   install -m 644 $(wildcard selinux/*.h) $(DESTDIR)$(INCDIR)
 
 relabel:
 
diff --git a/libselinux/man/Makefile b/libselinux/man/Makefile
index 0643e6af..f634d1fe 100644
--- a/libselinux/man/Makefile
+++ b/libselinux/man/Makefile
@@ -1,17 +1,18 @@
 # Installation directories.
-MAN8DIR ?= $(DESTDIR)/usr/share/man/man8
-MAN5DIR ?= $(DESTDIR)/usr/share/man/man5
-MAN3DIR ?= $(DESTDIR)/usr/share/man/man3
+PREFIX ?= /usr
+MAN8DIR ?= $(PREFIX)/share/man/man8
+MAN5DIR ?= $(PREFIX)/share/man/man5
+MAN3DIR ?= $(PREFIX)/share/man/man3
 
 all:
 
 install: all
-   mkdir -p $(MAN3DIR)
-   mkdir -p $(MAN5DIR)
-   mkdir -p $(MAN8DIR)
-   install -m 644 man3/*.3 $(MAN3DIR)
-   install -m 644 man5/*.5 $(MAN5DIR)
-   install -m 644 man8/*.8 $(MAN8DIR)
+   mkdir -p $(DESTDIR)$(MAN3DIR)
+   mkdir -p $(DESTDIR)$(MAN5DIR)
+   mkdir -p $(DESTDIR)$(MAN8DIR)
+   install -m 644 man3/*.3 $(DESTDIR)$(MAN3DIR)
+   install -m 644 man5/*.5 $(DESTDIR)$(MAN5DIR)
+   install -m 644 man8/*.8 $(DESTDIR)$(MAN8DIR)
 
 relabel:
 
diff --git a/libselinux/src/Makefile b/libselinux/src/Makefile
index 18df75c8..18588da5 100644
--- a/libselinux/src/Makefile
+++ b/libselinux/src/Makefile
@@ -8,19 +8,17 @@ RUBYPREFIX ?= $(notdir $(RUBY))
 PKG_CONFIG ?= pkg-config
 
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
+PREFIX ?= /usr
 LIBDIR ?= $(PREFIX)/lib
-SHLIBDIR ?= $(DESTDIR)/lib
+SHLIBDIR ?= /lib
 INCLUDEDIR ?= $(PREFIX)/include
 PYINC ?= $(shell $(PKG_CONFIG) --cflags $(PYPREFIX))
 PYLIBS ?= $(shell $(PKG_CONFIG) --libs $(PYPREFIX))
-PYSITEDIR ?= $(DESTDIR)$(shell $(PYTHON) -c 'import site; 
print(site.getsitepackages()[0])')
+PYSITEDIR ?= $(shell $(PYTHON) -c 'import site; 
print(site.getsitepackages()[0])')
 PYCEXT ?= $(shell $(PYTHON) -c 'import imp;print([s for s,m,t in 
imp.get_suffixes() if t == imp.C_EXTENSION][0])')
 RUBYINC ?= $(shell $(RUBY) -e 'puts "-I" + RbConfig::CONFIG["rubyarchhdrdir"] 
+ " -I" + RbConfig::CONFIG["rubyhdrdir"]')
 RUBYLIBS ?= $(shell $(RUBY) -e 'puts "-L" + RbConfig::CONFIG["libdir"] + " -L" 
+ RbConfig::CONFIG["archlibdir"] + " " + RbConfig::CONFIG["LIBRUBYARG_SHARED"]')
-RUBYINSTALL ?= $(DESTDIR)$(shell $(RUBY) -e 'puts 
RbConfig::CONFIG["vendorarchdir"]')
-LIBBASE ?= $(shell basename $(LIBDIR))
-LIBSEPOLA ?= $(LIBDIR)/libsepol.a
+RUBYINSTALL ?= $(shell $(RUBY) -e 'puts RbConfig::CONFIG["vendorarchdir"]')
 
 VERSION = $(shell cat ../VERSION)
 LIBVERSION = 1
@@ -50,6 +48,13 @@ LIBSO=$(TARGET).$(LIBVERSION)
 AUDIT2WHYLOBJ=$(PYPREFIX)audit2why.lo
 AUDIT2WHYSO=$(PYPREFIX)audit2why.so
 
+# If no specific libsepol.a is specified, fall back on LDFLAGS search path
+# Otherwise, as $(LIBSEPOLA) already appears in the dependencies, there
+# is no need to define a value for LDLIBS_LIBSEPOLA
+ifeq ($(LIBSEPOLA),)
+LDLIBS_LIBSEPOLA := -l:libsepol.a
+endif
+
 GENERATED=$(SWIGCOUT) $(SWIGRUBYCOUT) selinuxswig_python_exception.i
 SRCS= $(filter-out $(GENERATED) audit2why.c, $(sort $(wildcard *.c)))
 
@@ -148,7 +153,7 @@

Re: [PATCH v4 01/15] libsepol: build: follow standard semantics for DESTDIR and PREFIX

2018-01-31 Thread Marcus Folkesson
On Wed, Jan 24, 2018 at 10:29:07PM +0100, Nicolas Iooss wrote:
> On Wed, Jan 24, 2018 at 10:27 AM, Marcus Folkesson
> <marcus.folkes...@gmail.com> wrote:
> > 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.folkes...@gmail.com>
> > ---
> >  README  | 2 +-
> >  libsepol/include/Makefile   | 4 ++--
> >  libsepol/man/Makefile   | 5 +++--
> >  libsepol/src/Makefile   | 7 +++
> >  libsepol/src/libsepol.pc.in | 2 +-
> >  libsepol/utils/Makefile | 4 ++--
> >  6 files changed, 12 insertions(+), 12 deletions(-)
> >
> > diff --git a/README b/README
> > index 7fc7b17b..174551a1 100644
> > --- a/README
> > +++ b/README
> > @@ -19,6 +19,6 @@ lacks library functions or other dependencies relied upon 
> > by your
> >  distribution.  If it breaks, you get to keep both pieces.
> >
> >  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).
> > diff --git a/libsepol/include/Makefile b/libsepol/include/Makefile
> > index 56b7a114..ad5c34a4 100644
> > --- a/libsepol/include/Makefile
> > +++ b/libsepol/include/Makefile
> > @@ -1,6 +1,6 @@
> >  # Installation directories.
> > -PREFIX ?= $(DESTDIR)/usr
> > -INCDIR ?= $(PREFIX)/include/sepol
> > +PREFIX ?= /usr
> > +INCDIR = $(DESTDIR)$(PREFIX)/include/sepol
> >  CILDIR ?= ../cil
> >
> >  all:
> > diff --git a/libsepol/man/Makefile b/libsepol/man/Makefile
> > index 11924334..4f3d9fa2 100644
> > --- a/libsepol/man/Makefile
> > +++ b/libsepol/man/Makefile
> > @@ -1,6 +1,7 @@
> >  # Installation directories.
> > -MAN8DIR ?= $(DESTDIR)/usr/share/man/man8
> > -MAN3DIR ?= $(DESTDIR)/usr/share/man/man3
> > +PREFIX ?= /usr
> > +MAN8DIR ?= $(DESTDIR)$(PREFIX)/share/man/man8
> > +MAN3DIR ?= $(DESTDIR)$(PREFIX)/share/man/man3
> >
> >  all:
> >
> > diff --git a/libsepol/src/Makefile b/libsepol/src/Makefile
> > index 819d261b..d158398f 100644
> > --- a/libsepol/src/Makefile
> > +++ b/libsepol/src/Makefile
> > @@ -1,10 +1,9 @@
> >  # Installation directories.
> > -PREFIX ?= $(DESTDIR)/usr
> > +PREFIX ?= /usr
> >  INCLUDEDIR ?= $(PREFIX)/include
> > -LIBDIR ?= $(PREFIX)/lib
> > +LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
> >  SHLIBDIR ?= $(DESTDIR)/lib
> >  RANLIB ?= ranlib
> > -LIBBASE ?= $(shell basename $(LIBDIR))
> >  CILDIR ?= ../cil
> >
> >  VERSION = $(shell cat ../VERSION)
> > @@ -52,7 +51,7 @@ $(LIBSO): $(LOBJS) $(LIBMAP)
> > ln -sf $@ $(TARGET)
> >
> >  $(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
> >  ifneq ($(DISABLE_CIL),y)
> > diff --git a/libsepol/src/libsepol.pc.in b/libsepol/src/libsepol.pc.in
> > index e52f5892..f807fec6 100644
> > --- a/libsepol/src/libsepol.pc.in
> > +++ b/libsepol/src/libsepol.pc.in
> > @@ -1,6 +1,6 @@
> >  prefix=@prefix@
> >  exec_prefix=${prefix}
> > -libdir=${exec_prefix}/@libdir@
> > +libdir=@libdir@
> >  includedir=@includedir@
> >
> >  Name: libsepol
> 
> So this patch results in producing libsepol.pc with the value of
> $(DESTDIR) in libdir (because "s:@libdir@:$(LIBDIR):" in the sed
> command, and "LIBDIR ?= $(DESTDIR)$(PREFIX)/lib" in the Makefile). Is
> this intended? I supposed the point of these patches was to craft
> pkg-config files without references to $(DESTDIR), like the first
> version of this patch did. What did I miss?
> 

This is a regression between v2 and v3 I think.
Maybe we should remove DESTDIR from all variables and only use it in the
install target.

e.g.
SHLIBDIR ?= /lib
...
install:
install -m 755 $(LIBSO) $(DESTDIR)$(SHLIBDIR)


> Best,
> Nicolas
> 


signature.asc
Description: PGP signature


[PATCH v4 08/15] python: build: follow standard semantics for DESTDIR and PREFIX

2018-01-24 Thread Marcus Folkesson
Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
---
 python/audit2allow/Makefile   | 19 ---
 python/chcat/Makefile |  8 
 python/semanage/Makefile  | 11 +--
 python/sepolgen/src/sepolgen/Makefile |  3 ++-
 python/sepolicy/Makefile  | 18 +-
 5 files changed, 32 insertions(+), 27 deletions(-)

diff --git a/python/audit2allow/Makefile b/python/audit2allow/Makefile
index 8db8075f..7463ed85 100644
--- a/python/audit2allow/Makefile
+++ b/python/audit2allow/Makefile
@@ -1,19 +1,24 @@
 PYTHON ?= python
 
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-BINDIR ?= $(PREFIX)/bin
-LIBDIR ?= $(PREFIX)/lib
-MANDIR ?= $(PREFIX)/share/man
-LOCALEDIR ?= /usr/share/locale
-INCLUDEDIR ?= $(PREFIX)/include
-LIBSEPOLA ?= $(LIBDIR)/libsepol.a
+PREFIX ?= /usr
+BINDIR ?= $(DESTDIR)$(PREFIX)/bin
+LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
+MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
 
 CFLAGS ?= -Werror -Wall -W
 
+# If no specific libsepol.a is specified, fall back on LDFLAGS search path
+# Otherwise, as $(LIBSEPOLA) already appears in the dependencies, there
+# is no need to define a value for LDLIBS_LIBSEPOLA
+ifeq ($(LIBSEPOLA),)
+LDLIBS_LIBSEPOLA := -l:libsepol.a
+endif
+
 all: audit2why sepolgen-ifgen-attr-helper
 
 sepolgen-ifgen-attr-helper: sepolgen-ifgen-attr-helper.o $(LIBSEPOLA)
+   $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS_LIBSEPOLA)
 
 audit2why:
ln -sf audit2allow audit2why
diff --git a/python/chcat/Makefile b/python/chcat/Makefile
index 0fd12d6d..947734a0 100644
--- a/python/chcat/Makefile
+++ b/python/chcat/Makefile
@@ -1,8 +1,8 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-BINDIR ?= $(PREFIX)/bin
-MANDIR ?= $(PREFIX)/share/man
-LOCALEDIR ?= $(PREFIX)/share/locale
+PREFIX ?= /usr
+BINDIR ?= $(DESTDIR)$(PREFIX)/bin
+MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
+LOCALEDIR ?= $(DESTDIR)$(PREFIX)/share/locale
 
 .PHONY: all
 all: chcat
diff --git a/python/semanage/Makefile b/python/semanage/Makefile
index 132162bc..3e48b673 100644
--- a/python/semanage/Makefile
+++ b/python/semanage/Makefile
@@ -1,13 +1,12 @@
 PYTHON ?= python
 
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-LIBDIR ?= $(PREFIX)/lib
-SBINDIR ?= $(PREFIX)/sbin
-MANDIR = $(PREFIX)/share/man
-PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import *; 
print(get_python_lib(1))")
+PREFIX ?= /usr
+SBINDIR ?= $(DESTDIR)$(PREFIX)/sbin
+MANDIR = $(DESTDIR)$(PREFIX)/share/man
+PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import *; 
print(get_python_lib(plat_specific=1, prefix='$(PREFIX)'))")
 PACKAGEDIR ?= $(DESTDIR)/$(PYTHONLIBDIR)
-BASHCOMPLETIONDIR ?= $(DESTDIR)/usr/share/bash-completion/completions
+BASHCOMPLETIONDIR ?= $(DESTDIR)$(PREFIX)/share/bash-completion/completions
 
 TARGETS=semanage
 
diff --git a/python/sepolgen/src/sepolgen/Makefile 
b/python/sepolgen/src/sepolgen/Makefile
index d3aa7715..84548e98 100644
--- a/python/sepolgen/src/sepolgen/Makefile
+++ b/python/sepolgen/src/sepolgen/Makefile
@@ -1,5 +1,6 @@
+PREFIX ?= /usr
 PYTHON ?= python
-PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import *; 
print(get_python_lib(1))")
+PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import *; 
print(get_python_lib(plat_specific=1, prefix='$(PREFIX)'))")
 PACKAGEDIR ?= $(DESTDIR)/$(PYTHONLIBDIR)/sepolgen
 
 all:
diff --git a/python/sepolicy/Makefile b/python/sepolicy/Makefile
index 5a56e6c8..1c02ee06 100644
--- a/python/sepolicy/Makefile
+++ b/python/sepolicy/Makefile
@@ -1,14 +1,14 @@
 PYTHON ?= python
 
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-LIBDIR ?= $(PREFIX)/lib
-BINDIR ?= $(PREFIX)/bin
-DATADIR ?= $(PREFIX)/share
-MANDIR ?= $(PREFIX)/share/man
-LOCALEDIR ?= /usr/share/locale
-BASHCOMPLETIONDIR ?= $(DESTDIR)/usr/share/bash-completion/completions
-SHAREDIR ?= $(PREFIX)/share/sandbox
+PREFIX ?= /usr
+LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
+BINDIR ?= $(DESTDIR)$(PREFIX)/bin
+DATADIR ?= $(DESTDIR)$(PREFIX)/share
+MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
+LOCALEDIR ?= $(DESTDIR)$(PREFIX)/share/locale
+BASHCOMPLETIONDIR ?= $(DESTDIR)$(PREFIX)/share/bash-completion/completions
+SHAREDIR ?= $(DESTDIR)$(PREFIX)/share/sandbox
 CFLAGS ?= -Wall -Werror -Wextra -W
 override CFLAGS += -DPACKAGE="policycoreutils" -DSHARED -shared
 
@@ -30,7 +30,7 @@ test:
@$(PYTHON) test_sepolicy.py -v
 
 install:
-   $(PYTHON) setup.py install `test -n "$(DESTDIR)" && echo --root 
$(DESTDIR)`
+   $(PYTHON) setup.py install --prefix=$(PREFIX) `test -n "$(DESTDIR)" && 
echo --root $(DESTDIR)`
[ -d $(BINDIR) ] || mkdir -p $(BINDIR)
install -m 755 sepolicy.py $(BINDIR)/sepolicy
(cd $(BINDIR); ln -sf sepolicy sepolgen)
-- 
2.15.1




[PATCH v4 15/15] build: setup buildpaths if DESTDIR is specified

2018-01-24 Thread Marcus Folkesson
Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
---
 Makefile | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 6da7f7b7..c238dbc8 100644
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,4 @@
+PREFIX ?= /usr
 OPT_SUBDIRS ?= dbus gui mcstrans python restorecond sandbox semodule-utils
 SUBDIRS=libsepol libselinux libsemanage checkpolicy secilc policycoreutils 
$(OPT_SUBDIRS)
 PYSUBDIRS=libselinux libsemanage
@@ -19,10 +20,14 @@ else
 endif
 
 ifneq ($(DESTDIR),)
-   CFLAGS += -I$(DESTDIR)/usr/include
-   LDFLAGS += -L$(DESTDIR)/usr/lib
+   LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
+   LIBSEPOLA ?= $(LIBDIR)/libsepol.a
+
+   CFLAGS += -I$(DESTDIR)$(PREFIX)/include
+   LDFLAGS += -L$(DESTDIR)$(PREFIX)/lib -L$(LIBDIR)
export CFLAGS
export LDFLAGS
+   export LIBSEPOLA
 endif
 
 all install relabel clean test indent:
-- 
2.15.1




[PATCH v4 12/15] secilc: build: follow standard semantics for DESTDIR and PREFIX

2018-01-24 Thread Marcus Folkesson
Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
---
 secilc/Makefile | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/secilc/Makefile b/secilc/Makefile
index 1cac53e4..5b0a4852 100644
--- a/secilc/Makefile
+++ b/secilc/Makefile
@@ -1,8 +1,6 @@
-PREFIX ?= $(DESTDIR)/usr
-BINDIR ?= $(PREFIX)/bin
-MANDIR ?= $(PREFIX)/share/man
-LIBDIR ?= $(PREFIX)/lib
-INCLUDEDIR ?= $(PREFIX)/include
+PREFIX ?= /usr
+BINDIR ?= $(DESTDIR)$(PREFIX)/bin
+MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
 
 SECILC = secilc
 SECILC_SRCS := secilc.c
-- 
2.15.1




[PATCH v4 13/15] semodule-utils: build: follow standard semantics for DESTDIR and PREFIX

2018-01-24 Thread Marcus Folkesson
Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
---
 semodule-utils/semodule_expand/Makefile  | 8 +++-
 semodule-utils/semodule_link/Makefile| 8 +++-
 semodule-utils/semodule_package/Makefile | 8 +++-
 3 files changed, 9 insertions(+), 15 deletions(-)

diff --git a/semodule-utils/semodule_expand/Makefile 
b/semodule-utils/semodule_expand/Makefile
index 072f2137..c2ab3f65 100644
--- a/semodule-utils/semodule_expand/Makefile
+++ b/semodule-utils/semodule_expand/Makefile
@@ -1,9 +1,7 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-INCLUDEDIR ?= $(PREFIX)/include
-BINDIR ?= $(PREFIX)/bin
-LIBDIR ?= $(PREFIX)/lib
-MANDIR ?= $(PREFIX)/share/man
+PREFIX ?= /usr
+BINDIR ?= $(DESTDIR)$(PREFIX)/bin
+MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
 
 CFLAGS ?= -Werror -Wall -W
 override LDLIBS += -lsepol
diff --git a/semodule-utils/semodule_link/Makefile 
b/semodule-utils/semodule_link/Makefile
index cc4687bd..bcf98765 100644
--- a/semodule-utils/semodule_link/Makefile
+++ b/semodule-utils/semodule_link/Makefile
@@ -1,9 +1,7 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-INCLUDEDIR ?= $(PREFIX)/include
-BINDIR ?= $(PREFIX)/bin
-MANDIR ?= $(PREFIX)/share/man
-LIBDIR ?= $(PREFIX)/lib
+PREFIX ?= /usr
+BINDIR ?= $(DESTDIR)$(PREFIX)/bin
+MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
 
 CFLAGS ?= -Werror -Wall -W
 override LDLIBS += -lsepol
diff --git a/semodule-utils/semodule_package/Makefile 
b/semodule-utils/semodule_package/Makefile
index 96dd7c4f..33a95e16 100644
--- a/semodule-utils/semodule_package/Makefile
+++ b/semodule-utils/semodule_package/Makefile
@@ -1,9 +1,7 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-INCLUDEDIR ?= $(PREFIX)/include
-BINDIR ?= $(PREFIX)/bin
-LIBDIR ?= $(PREFIX)/lib
-MANDIR ?= $(PREFIX)/share/man
+PREFIX ?= /usr
+BINDIR ?= $(DESTDIR)$(PREFIX)/bin
+MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
 
 CFLAGS ?= -Werror -Wall -W
 override LDLIBS += -lsepol
-- 
2.15.1




[PATCH v4 07/15] policycoreutils: build: follow standard semantics for DESTDIR and PREFIX

2018-01-24 Thread Marcus Folkesson
Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
---
 policycoreutils/hll/pp/Makefile  |  7 ++-
 policycoreutils/load_policy/Makefile |  8 
 policycoreutils/man/Makefile |  3 ++-
 policycoreutils/newrole/Makefile |  8 
 policycoreutils/po/Makefile  |  3 ++-
 policycoreutils/run_init/Makefile|  8 
 policycoreutils/scripts/Makefile |  8 
 policycoreutils/secon/Makefile   |  9 -
 policycoreutils/semodule/Makefile|  8 +++-
 policycoreutils/sestatus/Makefile|  8 
 policycoreutils/setfiles/Makefile|  5 ++---
 policycoreutils/setsebool/Makefile   | 10 --
 12 files changed, 39 insertions(+), 46 deletions(-)

diff --git a/policycoreutils/hll/pp/Makefile b/policycoreutils/hll/pp/Makefile
index 3401dcc9..ce58e0cf 100644
--- a/policycoreutils/hll/pp/Makefile
+++ b/policycoreutils/hll/pp/Makefile
@@ -1,9 +1,6 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-INCLUDEDIR ?= $(PREFIX)/include
-MANDIR = $(PREFIX)/share/man
-LIBDIR ?= $(PREFIX)/lib
-LIBEXECDIR ?= $(PREFIX)/libexec
+PREFIX ?= /usr
+LIBEXECDIR ?= $(DESTDIR)$(PREFIX)/libexec
 HLLDIR ?= $(LIBEXECDIR)/selinux/hll
 
 CFLAGS ?= -Werror -Wall -W
diff --git a/policycoreutils/load_policy/Makefile 
b/policycoreutils/load_policy/Makefile
index b85833c2..720bf45f 100644
--- a/policycoreutils/load_policy/Makefile
+++ b/policycoreutils/load_policy/Makefile
@@ -1,8 +1,8 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-SBINDIR ?= $(DESTDIR)/sbin
-MANDIR ?= $(PREFIX)/share/man
-LOCALEDIR ?= /usr/share/locale
+PREFIX ?= /usr
+SBINDIR ?= $(DESTDIR)$(PREFIX)/sbin
+MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
+LOCALEDIR ?= $(DESTDIR)$(PREFIX)/share/locale
 
 CFLAGS ?= -Werror -Wall -W
 override CFLAGS += $(LDFLAGS) -DUSE_NLS -DLOCALEDIR="\"$(LOCALEDIR)\"" 
-DPACKAGE="\"policycoreutils\""
diff --git a/policycoreutils/man/Makefile b/policycoreutils/man/Makefile
index 0d91cd46..8a8fbd49 100644
--- a/policycoreutils/man/Makefile
+++ b/policycoreutils/man/Makefile
@@ -1,5 +1,6 @@
 # Installation directories.
-MAN5DIR ?= $(DESTDIR)/usr/share/man/man5
+PREFIX ?= /usr
+MAN5DIR ?= $(DESTDIR)$(PREFIX)/share/man/man5
 
 all:
 
diff --git a/policycoreutils/newrole/Makefile b/policycoreutils/newrole/Makefile
index 196af926..4dbe6f52 100644
--- a/policycoreutils/newrole/Makefile
+++ b/policycoreutils/newrole/Makefile
@@ -1,9 +1,9 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-BINDIR ?= $(PREFIX)/bin
-MANDIR ?= $(PREFIX)/share/man
+PREFIX ?= /usr
+BINDIR ?= $(DESTDIR)$(PREFIX)/bin
+MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
 ETCDIR ?= $(DESTDIR)/etc
-LOCALEDIR = /usr/share/locale
+LOCALEDIR = $(DESTDIR)$(PREFIX)/share/locale
 PAMH ?= $(shell test -f /usr/include/security/pam_appl.h && echo y)
 AUDITH ?= $(shell test -f /usr/include/libaudit.h && echo y)
 # Enable capabilities to permit newrole to generate audit records.
diff --git a/policycoreutils/po/Makefile b/policycoreutils/po/Makefile
index 58148613..c583d23a 100644
--- a/policycoreutils/po/Makefile
+++ b/policycoreutils/po/Makefile
@@ -2,6 +2,7 @@
 # Makefile for the PO files (translation) catalog
 #
 
+PREFIX ?= /usr
 TOP = ../..
 
 # What is this package?
@@ -12,7 +13,7 @@ INSTALL_DATA  = $(INSTALL) -m 644
 INSTALL_DIR= /usr/bin/install -d
 
 # destination directory
-INSTALL_NLS_DIR = $(DESTDIR)/usr/share/locale
+INSTALL_NLS_DIR = $(DESTDIR)$(PREFIX)/share/locale
 
 # PO catalog handling
 MSGMERGE   = msgmerge
diff --git a/policycoreutils/run_init/Makefile 
b/policycoreutils/run_init/Makefile
index 921f0b07..4178493e 100644
--- a/policycoreutils/run_init/Makefile
+++ b/policycoreutils/run_init/Makefile
@@ -1,10 +1,10 @@
 
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-SBINDIR ?= $(PREFIX)/sbin
-MANDIR ?= $(PREFIX)/share/man
+PREFIX ?= /usr
+SBINDIR ?= $(DESTDIR)$(PREFIX)/sbin
+MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
 ETCDIR ?= $(DESTDIR)/etc
-LOCALEDIR ?= /usr/share/locale
+LOCALEDIR ?= $(DESTDIR)$(PREFIX)/share/locale
 PAMH ?= $(shell test -f /usr/include/security/pam_appl.h && echo y)
 AUDITH ?= $(shell test -f /usr/include/libaudit.h && echo y)
 
diff --git a/policycoreutils/scripts/Makefile b/policycoreutils/scripts/Makefile
index d9e86ffe..cfd841ec 100644
--- a/policycoreutils/scripts/Makefile
+++ b/policycoreutils/scripts/Makefile
@@ -1,8 +1,8 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-SBINDIR ?= $(DESTDIR)/sbin
-MANDIR ?= $(PREFIX)/share/man
-LOCALEDIR ?= $(PREFIX)/share/locale
+PREFIX ?= /usr
+SBINDIR ?= $(DESTDIR)$(PREFIX)/sbin
+MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
+LOCALEDIR ?= $(DESTDIR)$(PREFIX)/share/locale
 
 .PHONY: all
 all: fixfiles
diff --git a/policycoreutils/secon/Makefile b/policycoreutils/secon/Makefile
index 8e491d74..4ecbd57d 100644
--- a/policycoreutils/secon/Makefile
+++ b/policycoreutils/secon/Makefile
@@ -1,9 +1,8 @@
 # secon tool - command-l

Rework of Makefiles

2018-01-24 Thread Marcus Folkesson
Hello,

I have updated the patchset.

We had a problem with overriding LIBDIR.

Please test to compile with:
make DESTDIR=/tmp/myroot PREFIX=/myusr install
or
make DESTDIR=/tmp/myroot install

Thanks to Nicolas and Petr for feedback.

Changes:
v4:
- top Makefile: add LIBDIR to LDFLAGS if DESTDIR is specified
- top Makefile: export LIBSEPOLA  if DESTDIR is specified
- python: move platform from platform specific to platform shared 
installation directory
- Introduce LDLIBS_LIBSEPOLA if LIBSEPOLA is not defined. 

v3:
- python: Add missing slash 
- Top makefile: Add default prefix
- python, mcstrans, selinux: keep the possibility to specify LIBSEPOLA 
to
  make depending component recompile on change. If not specified, fall 
back to
  libsepola in LDFLAGS path.

v2:
- Use separate directories for shared libraries as before( Comment from 
Stephen Smalley)
- Rework all packages (not just selinux/sepol/semanage)





[PATCH v4 14/15] dbus: build: follow standard semantics for DESTDIR and PREFIX

2018-01-24 Thread Marcus Folkesson
Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
---
 dbus/Makefile | 14 --
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/dbus/Makefile b/dbus/Makefile
index 9a6cc90e..53143aff 100644
--- a/dbus/Makefile
+++ b/dbus/Makefile
@@ -1,3 +1,5 @@
+PREFIX ?= /usr
+
 all:
 
 clean:
@@ -5,12 +7,12 @@ clean:
 install:
-mkdir -p $(DESTDIR)/etc/dbus-1/system.d/
install -m 644 org.selinux.conf $(DESTDIR)/etc/dbus-1/system.d/
-   -mkdir -p $(DESTDIR)/usr/share/dbus-1/system-services
-   install -m 644 org.selinux.service 
$(DESTDIR)/usr/share/dbus-1/system-services
-   -mkdir -p $(DESTDIR)/usr/share/polkit-1/actions/
-   install -m 644 org.selinux.policy $(DESTDIR)/usr/share/polkit-1/actions/
-   -mkdir -p $(DESTDIR)/usr/share/system-config-selinux
-   install -m 755 selinux_server.py 
$(DESTDIR)/usr/share/system-config-selinux
+   -mkdir -p $(DESTDIR)$(PREFIX)/share/dbus-1/system-services
+   install -m 644 org.selinux.service 
$(DESTDIR)$(PREFIX)/share/dbus-1/system-services
+   -mkdir -p $(DESTDIR)$(PREFIX)/share/polkit-1/actions/
+   install -m 644 org.selinux.policy 
$(DESTDIR)$(PREFIX)/share/polkit-1/actions/
+   -mkdir -p $(DESTDIR)$(PREFIX)/share/system-config-selinux
+   install -m 755 selinux_server.py 
$(DESTDIR)$(PREFIX)/share/system-config-selinux
 
 relabel:
 
-- 
2.15.1




[PATCH v4 06/15] mcstrans: build: follow standard semantics for DESTDIR and PREFIX

2018-01-24 Thread Marcus Folkesson
Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
---
 mcstrans/man/Makefile   |  3 ++-
 mcstrans/src/Makefile   | 18 --
 mcstrans/utils/Makefile | 22 --
 3 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/mcstrans/man/Makefile b/mcstrans/man/Makefile
index 8e971192..5030fa81 100644
--- a/mcstrans/man/Makefile
+++ b/mcstrans/man/Makefile
@@ -1,5 +1,6 @@
 # Installation directories.
-MAN8DIR ?= $(DESTDIR)/usr/share/man/man8
+PREFIX ?= /usr
+MAN8DIR ?= $(DESTDIR)$(PREFIX)/share/man/man8
 
 all:
 
diff --git a/mcstrans/src/Makefile b/mcstrans/src/Makefile
index 3f4a89c3..8a8743f1 100644
--- a/mcstrans/src/Makefile
+++ b/mcstrans/src/Makefile
@@ -1,10 +1,16 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-LIBDIR ?= $(PREFIX)/lib
+PREFIX ?= /usr
+LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
 SBINDIR ?= $(DESTDIR)/sbin
 INITDIR ?= $(DESTDIR)/etc/rc.d/init.d
-SYSTEMDDIR ?= $(DESTDIR)/usr/lib/systemd
-LIBSEPOLA ?= $(LIBDIR)/libsepol.a
+SYSTEMDDIR ?= $(DESTDIR)$(PREFIX)/lib/systemd
+
+# If no specific libsepol.a is specified, fall back on LDFLAGS search path
+# Otherwise, as $(LIBSEPOLA) already appears in the dependencies, there
+# is no need to define a value for LDLIBS_LIBSEPOLA
+ifeq ($(LIBSEPOLA),)
+LDLIBS_LIBSEPOLA := -l:libsepol.a
+endif
 
 PROG_SRC=mcstrans.c  mcscolor.c  mcstransd.c  mls_level.c
 PROG_OBJS= $(patsubst %.c,%.o,$(PROG_SRC))
@@ -15,8 +21,8 @@ override CFLAGS += -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
 
 all: $(PROG)
 
-$(PROG): $(PROG_OBJS)
-   $(CC) $(LDFLAGS) -pie -o $@ $^ -lselinux -lcap -lpcre $(LIBSEPOLA)
+$(PROG): $(PROG_OBJS) $(LIBSEPOLA)
+   $(CC) $(LDFLAGS) -pie -o $@ $^ -lselinux -lcap -lpcre 
$(LDLIBS_LIBSEPOLA)
 
 %.o:  %.c 
$(CC) $(CFLAGS) -fPIE -c -o $@ $<
diff --git a/mcstrans/utils/Makefile b/mcstrans/utils/Makefile
index 4d3cbfcb..9d740617 100644
--- a/mcstrans/utils/Makefile
+++ b/mcstrans/utils/Makefile
@@ -1,18 +1,28 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-LIBDIR ?= $(PREFIX)/lib
-SBINDIR ?= $(PREFIX)/sbin
-LIBSEPOLA ?= $(LIBDIR)/libsepol.a
+PREFIX ?= /usr
+LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
+SBINDIR ?= $(DESTDIR)$(PREFIX)/sbin
 
 CFLAGS ?= -Wall
 override CFLAGS += -I../src -D_GNU_SOURCE
 override LDLIBS += -lselinux -lpcre
 
-TARGETS=$(patsubst %.c,%,$(sort $(wildcard *.c)))
+TARGETS=transcon untranscon
+
+# If no specific libsepol.a is specified, fall back on LDFLAGS search path
+# Otherwise, as $(LIBSEPOLA) already appears in the dependencies, there
+# is no need to define a value for LDLIBS_LIBSEPOLA
+ifeq ($(LIBSEPOLA),)
+LDLIBS_LIBSEPOLA := -l:libsepol.a
+endif
 
 all: $(TARGETS)
 
-$(TARGETS): ../src/mcstrans.o ../src/mls_level.o $(LIBSEPOLA)
+transcon: transcon.o ../src/mcstrans.o ../src/mls_level.o $(LIBSEPOLA)
+   $(CC) $(CFLAGS) -o $@ $^ -lpcre -lselinux $(LDLIBS_LIBSEPOLA)
+
+untranscon: untranscon.o ../src/mcstrans.o ../src/mls_level.o $(LIBSEPOLA)
+   $(CC) $(CFLAGS) -o $@ $^ -lpcre -lselinux $(LDLIBS_LIBSEPOLA)
 
 install: all
-mkdir -p $(SBINDIR)
-- 
2.15.1




[PATCH v4 03/15] libsemanage: build: follow standard semantics for DESTDIR and PREFIX

2018-01-24 Thread Marcus Folkesson
This patch solves the following issues:
- 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.folkes...@gmail.com>
---
 libsemanage/include/Makefile  | 4 ++--
 libsemanage/man/Makefile  | 5 +++--
 libsemanage/src/Makefile  | 9 +++--
 libsemanage/src/libsemanage.pc.in | 2 +-
 libsemanage/tests/Makefile| 3 ---
 libsemanage/utils/Makefile| 4 ++--
 6 files changed, 11 insertions(+), 16 deletions(-)

diff --git a/libsemanage/include/Makefile b/libsemanage/include/Makefile
index b660660e..f4234b9e 100644
--- a/libsemanage/include/Makefile
+++ b/libsemanage/include/Makefile
@@ -1,6 +1,6 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-INCDIR ?= $(PREFIX)/include/semanage
+PREFIX ?= /usr
+INCDIR ?= $(DESTDIR)$(PREFIX)/include/semanage
 
 all:
 
diff --git a/libsemanage/man/Makefile b/libsemanage/man/Makefile
index 852043d4..43c2b3f6 100644
--- a/libsemanage/man/Makefile
+++ b/libsemanage/man/Makefile
@@ -1,6 +1,7 @@
 # Installation directories.
-MAN3DIR ?= $(DESTDIR)/usr/share/man/man3
-MAN5DIR ?= $(DESTDIR)/usr/share/man/man5
+PREFIX ?= /usr
+MAN3DIR ?= $(DESTDIR)$(PREFIX)/share/man/man3
+MAN5DIR ?= $(DESTDIR)$(PREFIX)/share/man/man5
 
 all:
 
diff --git a/libsemanage/src/Makefile b/libsemanage/src/Makefile
index fdb178f5..f66d1b73 100644
--- a/libsemanage/src/Makefile
+++ b/libsemanage/src/Makefile
@@ -8,9 +8,8 @@ RUBYPREFIX ?= $(notdir $(RUBY))
 PKG_CONFIG ?= pkg-config
 
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-LIBDIR ?= $(PREFIX)/lib
-SHLIBDIR ?= $(DESTDIR)/lib
+PREFIX ?= /usr
+LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
 INCLUDEDIR ?= $(PREFIX)/include
 PYINC ?= $(shell $(PKG_CONFIG) --cflags $(PYPREFIX))
 PYLIBS ?= $(shell $(PKG_CONFIG) --libs $(PYPREFIX))
@@ -20,8 +19,6 @@ RUBYINC ?= $(shell $(RUBY) -e 'puts "-I" + 
RbConfig::CONFIG["rubyarchhdrdir"] +
 RUBYLIBS ?= $(shell $(RUBY) -e 'puts "-L" + RbConfig::CONFIG["libdir"] + " -L" 
+ RbConfig::CONFIG["archlibdir"] + " " + RbConfig::CONFIG["LIBRUBYARG_SHARED"]')
 RUBYINSTALL ?= $(DESTDIR)$(shell $(RUBY) -e 'puts 
RbConfig::CONFIG["vendorarchdir"]')
 
-LIBBASE=$(shell basename $(LIBDIR))
-
 DEFAULT_SEMANAGE_CONF_LOCATION=$(DESTDIR)/etc/selinux/semanage.conf
 
 ifeq ($(DEBUG),1)
@@ -95,7 +92,7 @@ $(LIBSO): $(LOBJS)
ln -sf $@ $(TARGET)
 
 $(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):' < $< > $@
 
 semanageswig_python_exception.i: ../include/semanage/semanage.h
bash -e exception.sh > $@ || (rm -f $@ ; false)
diff --git a/libsemanage/src/libsemanage.pc.in 
b/libsemanage/src/libsemanage.pc.in
index d3eaa062..43681ddb 100644
--- a/libsemanage/src/libsemanage.pc.in
+++ b/libsemanage/src/libsemanage.pc.in
@@ -1,6 +1,6 @@
 prefix=@prefix@
 exec_prefix=${prefix}
-libdir=${exec_prefix}/@libdir@
+libdir=@libdir@
 includedir=@includedir@
 
 Name: libsemanage
diff --git a/libsemanage/tests/Makefile b/libsemanage/tests/Makefile
index 2ef8d30d..324766a0 100644
--- a/libsemanage/tests/Makefile
+++ b/libsemanage/tests/Makefile
@@ -1,6 +1,3 @@
-PREFIX ?= $(DESTDIR)/usr
-LIBDIR ?= $(PREFIX)/lib
-
 # Add your test source files here:
 SOURCES = $(sort $(wildcard *.c))
 
diff --git a/libsemanage/utils/Makefile b/libsemanage/utils/Makefile
index 725f0eec..f527ad07 100644
--- a/libsemanage/utils/Makefile
+++ b/libsemanage/utils/Makefile
@@ -1,6 +1,6 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-LIBEXECDIR ?= $(PREFIX)/libexec
+PREFIX ?= /usr
+LIBEXECDIR ?= $(DESTDIR)$(PREFIX)/libexec
 SELINUXEXECDIR ?= $(LIBEXECDIR)/selinux/
 
 all:
-- 
2.15.1




[PATCH v4 10/15] restorecond: build: follow standard semantics for DESTDIR and PREFIX

2018-01-24 Thread Marcus Folkesson
Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
---
 restorecond/Makefile | 11 +--
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/restorecond/Makefile b/restorecond/Makefile
index ada94aeb..a2316947 100644
--- a/restorecond/Makefile
+++ b/restorecond/Makefile
@@ -1,13 +1,12 @@
 PKG_CONFIG ?= pkg-config
 
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-SBINDIR ?= $(PREFIX)/sbin
-LIBDIR ?= $(PREFIX)/lib
-MANDIR = $(PREFIX)/share/man
+PREFIX ?= /usr
+SBINDIR ?= $(DESTDIR)$(PREFIX)/sbin
+MANDIR = $(DESTDIR)$(PREFIX)/share/man
 AUTOSTARTDIR = $(DESTDIR)/etc/xdg/autostart
-DBUSSERVICEDIR = $(DESTDIR)/usr/share/dbus-1/services
-SYSTEMDDIR ?= $(DESTDIR)/usr/lib/systemd
+DBUSSERVICEDIR = $(DESTDIR)$(PREFIX)/share/dbus-1/services
+SYSTEMDDIR ?= $(DESTDIR)$(PREFIX)/lib/systemd
 
 autostart_DATA = sealertauto.desktop
 INITDIR ?= $(DESTDIR)/etc/rc.d/init.d
-- 
2.15.1




[PATCH v4 02/15] libselinux: build: follow standard semantics for DESTDIR and PREFIX

2018-01-24 Thread Marcus Folkesson
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.folkes...@gmail.com>
---
 libselinux/include/Makefile |  4 ++--
 libselinux/man/Makefile |  7 ---
 libselinux/src/Makefile | 17 +++--
 libselinux/src/libselinux.pc.in |  2 +-
 libselinux/utils/Makefile   |  6 ++
 5 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/libselinux/include/Makefile b/libselinux/include/Makefile
index 757a6c9c..3b51f5ce 100644
--- a/libselinux/include/Makefile
+++ b/libselinux/include/Makefile
@@ -1,6 +1,6 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-INCDIR ?= $(PREFIX)/include/selinux
+PREFIX ?= /usr
+INCDIR = $(DESTDIR)$(PREFIX)/include/selinux
 
 all:
 
diff --git a/libselinux/man/Makefile b/libselinux/man/Makefile
index 0643e6af..233bfaa9 100644
--- a/libselinux/man/Makefile
+++ b/libselinux/man/Makefile
@@ -1,7 +1,8 @@
 # Installation directories.
-MAN8DIR ?= $(DESTDIR)/usr/share/man/man8
-MAN5DIR ?= $(DESTDIR)/usr/share/man/man5
-MAN3DIR ?= $(DESTDIR)/usr/share/man/man3
+PREFIX ?= /usr
+MAN8DIR ?= $(DESTDIR)$(PREFIX)/share/man/man8
+MAN5DIR ?= $(DESTDIR)$(PREFIX)/share/man/man5
+MAN3DIR ?= $(DESTDIR)$(PREFIX)/share/man/man3
 
 all:
 
diff --git a/libselinux/src/Makefile b/libselinux/src/Makefile
index 18df75c8..bd9980db 100644
--- a/libselinux/src/Makefile
+++ b/libselinux/src/Makefile
@@ -8,8 +8,8 @@ RUBYPREFIX ?= $(notdir $(RUBY))
 PKG_CONFIG ?= pkg-config
 
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-LIBDIR ?= $(PREFIX)/lib
+PREFIX ?= /usr
+LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
 SHLIBDIR ?= $(DESTDIR)/lib
 INCLUDEDIR ?= $(PREFIX)/include
 PYINC ?= $(shell $(PKG_CONFIG) --cflags $(PYPREFIX))
@@ -19,8 +19,6 @@ PYCEXT ?= $(shell $(PYTHON) -c 'import imp;print([s for s,m,t 
in imp.get_suffixe
 RUBYINC ?= $(shell $(RUBY) -e 'puts "-I" + RbConfig::CONFIG["rubyarchhdrdir"] 
+ " -I" + RbConfig::CONFIG["rubyhdrdir"]')
 RUBYLIBS ?= $(shell $(RUBY) -e 'puts "-L" + RbConfig::CONFIG["libdir"] + " -L" 
+ RbConfig::CONFIG["archlibdir"] + " " + RbConfig::CONFIG["LIBRUBYARG_SHARED"]')
 RUBYINSTALL ?= $(DESTDIR)$(shell $(RUBY) -e 'puts 
RbConfig::CONFIG["vendorarchdir"]')
-LIBBASE ?= $(shell basename $(LIBDIR))
-LIBSEPOLA ?= $(LIBDIR)/libsepol.a
 
 VERSION = $(shell cat ../VERSION)
 LIBVERSION = 1
@@ -50,6 +48,13 @@ LIBSO=$(TARGET).$(LIBVERSION)
 AUDIT2WHYLOBJ=$(PYPREFIX)audit2why.lo
 AUDIT2WHYSO=$(PYPREFIX)audit2why.so
 
+# If no specific libsepol.a is specified, fall back on LDFLAGS search path
+# Otherwise, as $(LIBSEPOLA) already appears in the dependencies, there
+# is no need to define a value for LDLIBS_LIBSEPOLA
+ifeq ($(LIBSEPOLA),)
+LDLIBS_LIBSEPOLA := -l:libsepol.a
+endif
+
 GENERATED=$(SWIGCOUT) $(SWIGRUBYCOUT) selinuxswig_python_exception.i
 SRCS= $(filter-out $(GENERATED) audit2why.c, $(sort $(wildcard *.c)))
 
@@ -148,7 +153,7 @@ $(LIBSO): $(LOBJS)
ln -sf $@ $(TARGET)
 
 $(LIBPC): $(LIBPC).in ../VERSION
-   sed -e 's/@VERSION@/$(VERSION)/; s:@prefix@:$(PREFIX):; 
s:@libdir@:$(LIBBASE):; s:@includedir@:$(INCLUDEDIR):; 
s:@PCRE_MODULE@:$(PCRE_MODULE):' < $< > $@
+   sed -e 's/@VERSION@/$(VERSION)/; s:@prefix@:$(PREFIX):; 
s:@libdir@:$(LIBDIR):; s:@includedir@:$(INCLUDEDIR):; 
s:@PCRE_MODULE@:$(PCRE_MODULE):' < $< > $@
 
 selinuxswig_python_exception.i: ../include/selinux/selinux.h
bash -e exception.sh > $@ || (rm -f $@ ; false)
@@ -157,7 +162,7 @@ $(AUDIT2WHYLOBJ): audit2why.c
$(CC) $(filter-out -Werror, $(CFLAGS)) $(PYINC) -fPIC -DSHARED -c -o $@ 
$<
 
 $(AUDIT2WHYSO): $(AUDIT2WHYLOBJ) $(LIBSEPOLA)
-   $(CC) $(CFLAGS) $(LDFLAGS) -L. -shared -o $@ $^ -lselinux $(PYLIBS)
+   $(CC) $(CFLAGS) $(LDFLAGS) -L. -shared -o $@ $^ -lselinux 
$(LDLIBS_LIBSEPOLA) $(PYLIBS)
 
 %.o:  %.c policy.h
$(CC) $(CFLAGS) $(TLSFLAGS) -c -o $@ $<
diff --git a/libselinux/src/libselinux.pc.in b/libselinux/src/libselinux.pc.in
index 2e90a844..7c66b1fa 100644
--- a/libselinux/src/libselinux.pc.in
+++ b/libselinux/src/libselinux.pc.in
@@ -1,6 +1,6 @@
 prefix=@prefix@
 exec_prefix=${prefix}
-libdir=${exec_prefix}/@libdir@
+libdir=@libdir@
 includedir=@includedir@
 
 Name: libselinux
diff --git a/libselinux/utils/Makefile b/libselinux/utils/Makefile
index eb4851a9..9adce6d3 100644
--- a/libselinux/utils/Makefile
+++ b/libselinux/utils/Makefile
@@ -1,8 +1,6 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-LIBDIR ?= $(PREFIX)/lib
-SBINDIR ?= $(PREFIX)/sbin
-INCLUDEDIR ?= $(PREFIX)/include
+PREFIX ?= /usr
+SBINDIR ?= $(DESTDIR)$(PREFIX)/sbin
 
 OS ?= $(shell uname)
 
-- 
2.15.1




[PATCH v4 09/15] python: build: move modules from platform-specific to platform-shared

2018-01-24 Thread Marcus Folkesson
Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
---
 python/semanage/Makefile  | 2 +-
 python/sepolgen/src/sepolgen/Makefile | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/python/semanage/Makefile b/python/semanage/Makefile
index 3e48b673..0218222d 100644
--- a/python/semanage/Makefile
+++ b/python/semanage/Makefile
@@ -4,7 +4,7 @@ PYTHON ?= python
 PREFIX ?= /usr
 SBINDIR ?= $(DESTDIR)$(PREFIX)/sbin
 MANDIR = $(DESTDIR)$(PREFIX)/share/man
-PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import *; 
print(get_python_lib(plat_specific=1, prefix='$(PREFIX)'))")
+PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import *; 
print(get_python_lib(prefix='$(PREFIX)'))")
 PACKAGEDIR ?= $(DESTDIR)/$(PYTHONLIBDIR)
 BASHCOMPLETIONDIR ?= $(DESTDIR)$(PREFIX)/share/bash-completion/completions
 
diff --git a/python/sepolgen/src/sepolgen/Makefile 
b/python/sepolgen/src/sepolgen/Makefile
index 84548e98..2121a955 100644
--- a/python/sepolgen/src/sepolgen/Makefile
+++ b/python/sepolgen/src/sepolgen/Makefile
@@ -1,6 +1,6 @@
 PREFIX ?= /usr
 PYTHON ?= python
-PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import *; 
print(get_python_lib(plat_specific=1, prefix='$(PREFIX)'))")
+PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import *; 
print(get_python_lib(prefix='$(PREFIX)'))")
 PACKAGEDIR ?= $(DESTDIR)/$(PYTHONLIBDIR)/sepolgen
 
 all:
-- 
2.15.1




[PATCH v4 04/15] checkpolicy: build: follow standard semantics for DESTDIR and PREFIX

2018-01-24 Thread Marcus Folkesson
This patch solves the following issues:
- 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.folkes...@gmail.com>
---
 checkpolicy/Makefile  | 19 +--
 checkpolicy/test/Makefile | 17 -
 2 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/checkpolicy/Makefile b/checkpolicy/Makefile
index 68e11f2a..9a55b968 100644
--- a/checkpolicy/Makefile
+++ b/checkpolicy/Makefile
@@ -1,12 +1,10 @@
 #
 # Makefile for building the checkpolicy program
 #
-PREFIX ?= $(DESTDIR)/usr
-BINDIR ?= $(PREFIX)/bin
-MANDIR ?= $(PREFIX)/share/man
-LIBDIR ?= $(PREFIX)/lib
-INCLUDEDIR ?= $(PREFIX)/include
-LIBSEPOLA ?= $(LIBDIR)/libsepol.a
+PREFIX ?= /usr
+BINDIR ?= $(DESTDIR)$(PREFIX)/bin
+MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
+LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
 TARGETS = checkpolicy checkmodule
 
 LEX = flex
@@ -14,6 +12,13 @@ YACC = bison -y
 
 CFLAGS ?= -g -Wall -Werror -Wshadow -O2 -pipe -fno-strict-aliasing
 
+# If no specific libsepol.a is specified, fall back on LDFLAGS search path
+# Otherwise, as $(LIBSEPOLA) already appears in the dependencies, there
+# is no need to define a value for LDLIBS_LIBSEPOLA
+ifeq ($(LIBSEPOLA),)
+LDLIBS_LIBSEPOLA := -l:libsepol.a
+endif
+
 override CFLAGS += -I.
 
 CHECKOBJS = y.tab.o lex.yy.o queue.o module_compiler.o parse_util.o \
@@ -27,8 +32,10 @@ all:  $(TARGETS)
$(MAKE) -C test
 
 checkpolicy: $(CHECKPOLOBJS) $(LIBSEPOLA)
+   $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LDLIBS_LIBSEPOLA)
 
 checkmodule: $(CHECKMODOBJS) $(LIBSEPOLA)
+   $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LDLIBS_LIBSEPOLA)
 
 %.o: %.c 
$(CC) $(CFLAGS) -o $@ -c $<
diff --git a/checkpolicy/test/Makefile b/checkpolicy/test/Makefile
index 59fa4460..094e7ee2 100644
--- a/checkpolicy/test/Makefile
+++ b/checkpolicy/test/Makefile
@@ -1,19 +1,26 @@
 #
 # Makefile for building the dispol program
 #
-PREFIX ?= $(DESTDIR)/usr
-BINDIR ?= $(PREFIX)/bin
-LIBDIR ?= $(PREFIX)/lib
-INCLUDEDIR ?= $(PREFIX)/include
-LIBSEPOLA ?= $(LIBDIR)/libsepol.a
+PREFIX ?= /usr
+BINDIR ?= $(DESTDIR)$(PREFIX)/bin
+LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
 
 CFLAGS ?= -g -Wall -W -Werror -O2 -pipe
 
+# If no specific libsepol.a is specified, fall back on LDFLAGS search path
+# Otherwise, as $(LIBSEPOLA) already appears in the dependencies, there
+# is no need to define a value for LDLIBS_LIBSEPOLA
+ifeq ($(LIBSEPOLA),)
+LDLIBS_LIBSEPOLA := -l:libsepol.a
+endif
+
 all: dispol dismod
 
 dispol: dispol.o $(LIBSEPOLA)
+   $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS_LIBSEPOLA)
 
 dismod: dismod.o $(LIBSEPOLA)
+   $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS_LIBSEPOLA)
 
 clean:
-rm -f dispol dismod *.o 
-- 
2.15.1




[PATCH v4 05/15] gui: build: follow standard semantics for DESTDIR and PREFIX

2018-01-24 Thread Marcus Folkesson
Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
---
 gui/Makefile | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/gui/Makefile b/gui/Makefile
index cfe47405..5efd17d7 100644
--- a/gui/Makefile
+++ b/gui/Makefile
@@ -1,9 +1,9 @@
 # Installation directories.
-PREFIX ?= ${DESTDIR}/usr
-BINDIR ?= $(PREFIX)/bin
-SHAREDIR ?= $(PREFIX)/share/system-config-selinux
-DATADIR ?= $(PREFIX)/share
-MANDIR ?= $(PREFIX)/share/man
+PREFIX ?= /usr
+BINDIR ?= $(DESTDIR)$(PREFIX)/bin
+SHAREDIR ?= $(DESTDIR)$(PREFIX)/share/system-config-selinux
+DATADIR ?= $(DESTDIR)$(PREFIX)/share
+MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
 
 TARGETS= \
 booleansPage.py \
-- 
2.15.1




[PATCH v4 01/15] libsepol: build: follow standard semantics for DESTDIR and PREFIX

2018-01-24 Thread Marcus Folkesson
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.folkes...@gmail.com>
---
 README  | 2 +-
 libsepol/include/Makefile   | 4 ++--
 libsepol/man/Makefile   | 5 +++--
 libsepol/src/Makefile   | 7 +++
 libsepol/src/libsepol.pc.in | 2 +-
 libsepol/utils/Makefile | 4 ++--
 6 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/README b/README
index 7fc7b17b..174551a1 100644
--- a/README
+++ b/README
@@ -19,6 +19,6 @@ lacks library functions or other dependencies relied upon by 
your
 distribution.  If it breaks, you get to keep both pieces.
 
 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).
diff --git a/libsepol/include/Makefile b/libsepol/include/Makefile
index 56b7a114..ad5c34a4 100644
--- a/libsepol/include/Makefile
+++ b/libsepol/include/Makefile
@@ -1,6 +1,6 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-INCDIR ?= $(PREFIX)/include/sepol
+PREFIX ?= /usr
+INCDIR = $(DESTDIR)$(PREFIX)/include/sepol
 CILDIR ?= ../cil
 
 all:
diff --git a/libsepol/man/Makefile b/libsepol/man/Makefile
index 11924334..4f3d9fa2 100644
--- a/libsepol/man/Makefile
+++ b/libsepol/man/Makefile
@@ -1,6 +1,7 @@
 # Installation directories.
-MAN8DIR ?= $(DESTDIR)/usr/share/man/man8
-MAN3DIR ?= $(DESTDIR)/usr/share/man/man3
+PREFIX ?= /usr
+MAN8DIR ?= $(DESTDIR)$(PREFIX)/share/man/man8
+MAN3DIR ?= $(DESTDIR)$(PREFIX)/share/man/man3
 
 all:
 
diff --git a/libsepol/src/Makefile b/libsepol/src/Makefile
index 819d261b..d158398f 100644
--- a/libsepol/src/Makefile
+++ b/libsepol/src/Makefile
@@ -1,10 +1,9 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
+PREFIX ?= /usr
 INCLUDEDIR ?= $(PREFIX)/include
-LIBDIR ?= $(PREFIX)/lib
+LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
 SHLIBDIR ?= $(DESTDIR)/lib
 RANLIB ?= ranlib
-LIBBASE ?= $(shell basename $(LIBDIR))
 CILDIR ?= ../cil
 
 VERSION = $(shell cat ../VERSION)
@@ -52,7 +51,7 @@ $(LIBSO): $(LOBJS) $(LIBMAP)
ln -sf $@ $(TARGET) 
 
 $(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
 ifneq ($(DISABLE_CIL),y)
diff --git a/libsepol/src/libsepol.pc.in b/libsepol/src/libsepol.pc.in
index e52f5892..f807fec6 100644
--- a/libsepol/src/libsepol.pc.in
+++ b/libsepol/src/libsepol.pc.in
@@ -1,6 +1,6 @@
 prefix=@prefix@
 exec_prefix=${prefix}
-libdir=${exec_prefix}/@libdir@
+libdir=@libdir@
 includedir=@includedir@
 
 Name: libsepol
diff --git a/libsepol/utils/Makefile b/libsepol/utils/Makefile
index fba1d8a0..8ce4bf47 100644
--- a/libsepol/utils/Makefile
+++ b/libsepol/utils/Makefile
@@ -1,6 +1,6 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-BINDIR ?= $(PREFIX)/bin
+PREFIX ?= /usr
+BINDIR ?= $(DESTDIR)$(PREFIX)/bin
 
 CFLAGS ?= -Wall -Werror
 override CFLAGS += -I../include
-- 
2.15.1




Re: [PATCH v2 02/14] libselinux: build: follow standard semantics for DESTDIR and PREFIX

2018-01-23 Thread Marcus Folkesson
On Mon, Jan 22, 2018 at 09:50:36PM +0100, Nicolas Iooss wrote:
> On 19/01/18 13:07, Marcus Folkesson wrote:
> > Hi Nicolas!
> > 
> > On Wed, Jan 17, 2018 at 11:12:56PM +0100, Nicolas Iooss wrote:
> >> On Tue, Jan 16, 2018 at 9:23 PM, Marcus Folkesson
> >> <marcus.folkes...@gmail.com> wrote:
> >>> 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.folkes...@gmail.com>
> >>> ---
> >>>  libselinux/include/Makefile |  4 ++--
> >>>  libselinux/man/Makefile |  7 ---
> >>>  libselinux/src/Makefile | 12 +---
> >>>  libselinux/src/libselinux.pc.in |  2 +-
> >>>  libselinux/utils/Makefile   |  6 ++
> >>>  5 files changed, 14 insertions(+), 17 deletions(-)
> >>>
> >>> diff --git a/libselinux/include/Makefile b/libselinux/include/Makefile
> >>> index 757a6c9c..3b51f5ce 100644
> >>> --- a/libselinux/include/Makefile
> >>> +++ b/libselinux/include/Makefile
> >>> @@ -1,6 +1,6 @@
> >>>  # Installation directories.
> >>> -PREFIX ?= $(DESTDIR)/usr
> >>> -INCDIR ?= $(PREFIX)/include/selinux
> >>> +PREFIX ?= /usr
> >>> +INCDIR = $(DESTDIR)$(PREFIX)/include/selinux
> >>>
> >>>  all:
> >>>
> >>> diff --git a/libselinux/man/Makefile b/libselinux/man/Makefile
> >>> index 0643e6af..233bfaa9 100644
> >>> --- a/libselinux/man/Makefile
> >>> +++ b/libselinux/man/Makefile
> >>> @@ -1,7 +1,8 @@
> >>>  # Installation directories.
> >>> -MAN8DIR ?= $(DESTDIR)/usr/share/man/man8
> >>> -MAN5DIR ?= $(DESTDIR)/usr/share/man/man5
> >>> -MAN3DIR ?= $(DESTDIR)/usr/share/man/man3
> >>> +PREFIX ?= /usr
> >>> +MAN8DIR ?= $(DESTDIR)$(PREFIX)/share/man/man8
> >>> +MAN5DIR ?= $(DESTDIR)$(PREFIX)/share/man/man5
> >>> +MAN3DIR ?= $(DESTDIR)$(PREFIX)/share/man/man3
> >>>
> >>>  all:
> >>>
> >>> diff --git a/libselinux/src/Makefile b/libselinux/src/Makefile
> >>> index 18df75c8..18a58164 100644
> >>> --- a/libselinux/src/Makefile
> >>> +++ b/libselinux/src/Makefile
> >>> @@ -8,8 +8,8 @@ RUBYPREFIX ?= $(notdir $(RUBY))
> >>>  PKG_CONFIG ?= pkg-config
> >>>
> >>>  # Installation directories.
> >>> -PREFIX ?= $(DESTDIR)/usr
> >>> -LIBDIR ?= $(PREFIX)/lib
> >>> +PREFIX ?= /usr
> >>> +LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
> >>>  SHLIBDIR ?= $(DESTDIR)/lib
> >>>  INCLUDEDIR ?= $(PREFIX)/include
> >>>  PYINC ?= $(shell $(PKG_CONFIG) --cflags $(PYPREFIX))
> >>> @@ -19,8 +19,6 @@ PYCEXT ?= $(shell $(PYTHON) -c 'import imp;print([s for 
> >>> s,m,t in imp.get_suffixe
> >>>  RUBYINC ?= $(shell $(RUBY) -e 'puts "-I" + 
> >>> RbConfig::CONFIG["rubyarchhdrdir"] + " -I" + 
> >>> RbConfig::CONFIG["rubyhdrdir"]')
> >>>  RUBYLIBS ?= $(shell $(RUBY) -e 'puts "-L" + RbConfig::CONFIG["libdir"] + 
> >>> " -L" + RbConfig::CONFIG["archlibdir"] + " " + 
> >>> RbConfig::CONFIG["LIBRUBYARG_SHARED"]')
> >>>  RUBYINSTALL ?= $(DESTDIR)$(shell $(RUBY) -e 'puts 
> >>> RbConfig::CONFIG["vendorarchdir"]')
> >>> -LIBBASE ?= $(shell basename $(LIBDIR))
> >>> -LIBSEPOLA ?= $(LIBDIR)/libsepol.a
> >>>
> >>>  VERSION = $(shell cat ../VERSION)
> >>>  LIBVERSION = 1
> >>> @@ -148,7 +146,7 @@ $(LIBSO): $(LOBJS)
> >>> ln -sf $@ $(TARGET)
> >>>
> >>>  $(LIBPC): $(LIBPC).in ../VERSION
> >>> -   sed -e 's/@VERSION@/$(VERSION)/; s:@prefix@:$(PREFIX):; 
> >>> s:@libdir@:$(LIBBASE):; s:@includedir@:$(INCLUDEDIR):; 
> >>> s:@PCRE_MODULE@:$(PCRE_MODULE):' < $< > $@
> >>> +   sed -e 's/@VERSION@/$(VERSION)/; s:@prefix@:$(PREFIX):; 
> >>> s:@libdir@:$(LIBDIR):; s:@includedir@:$(INCLUDEDIR):; 
> >>> s:@PCRE_MODU

Re: [PATCH v3 08/14] python: build: follow standard semantics for DESTDIR and PREFIX

2018-01-23 Thread Marcus Folkesson
Hi Petr,

On Tue, Jan 23, 2018 at 11:24:47AM +0100, Petr Lautrbach wrote:
> On Sun, Jan 21, 2018 at 10:46:11PM +0100, Marcus Folkesson wrote:
> > Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
> > ---
> >  python/audit2allow/Makefile   | 17 ++---
> >  python/chcat/Makefile |  8 
> >  python/semanage/Makefile  | 11 +--
> >  python/sepolgen/src/sepolgen/Makefile |  3 ++-
> >  python/sepolicy/Makefile  | 18 +-
> >  5 files changed, 30 insertions(+), 27 deletions(-)
> > 
> > diff --git a/python/audit2allow/Makefile b/python/audit2allow/Makefile
> > index 8db8075f..d1d4ca8d 100644
> > --- a/python/audit2allow/Makefile
> > +++ b/python/audit2allow/Makefile
> > @@ -1,19 +1,22 @@
> >  PYTHON ?= python
> >  
> >  # Installation directories.
> > -PREFIX ?= $(DESTDIR)/usr
> > -BINDIR ?= $(PREFIX)/bin
> > -LIBDIR ?= $(PREFIX)/lib
> > -MANDIR ?= $(PREFIX)/share/man
> > -LOCALEDIR ?= /usr/share/locale
> > -INCLUDEDIR ?= $(PREFIX)/include
> > -LIBSEPOLA ?= $(LIBDIR)/libsepol.a
> > +PREFIX ?= /usr
> > +BINDIR ?= $(DESTDIR)$(PREFIX)/bin
> > +LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
> > +MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
> >  
> >  CFLAGS ?= -Werror -Wall -W
> >  
> > +# If no specific libsepol.a is specified, fall back on LDFLAGS search path
> > +ifeq ($(LIBSEPOLA),)
> > +   LDFLAGS += -l:libsepol.a
> > +endif
> > +
> >  all: audit2why sepolgen-ifgen-attr-helper
> >  
> >  sepolgen-ifgen-attr-helper: sepolgen-ifgen-attr-helper.o $(LIBSEPOLA)
> > +   $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
> >  
> >  audit2why:
> > ln -sf audit2allow audit2why
> > diff --git a/python/chcat/Makefile b/python/chcat/Makefile
> > index 0fd12d6d..947734a0 100644
> > --- a/python/chcat/Makefile
> > +++ b/python/chcat/Makefile
> > @@ -1,8 +1,8 @@
> >  # Installation directories.
> > -PREFIX ?= $(DESTDIR)/usr
> > -BINDIR ?= $(PREFIX)/bin
> > -MANDIR ?= $(PREFIX)/share/man
> > -LOCALEDIR ?= $(PREFIX)/share/locale
> > +PREFIX ?= /usr
> > +BINDIR ?= $(DESTDIR)$(PREFIX)/bin
> > +MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
> > +LOCALEDIR ?= $(DESTDIR)$(PREFIX)/share/locale
> >  
> >  .PHONY: all
> >  all: chcat
> > diff --git a/python/semanage/Makefile b/python/semanage/Makefile
> > index 132162bc..0218222d 100644
> > --- a/python/semanage/Makefile
> > +++ b/python/semanage/Makefile
> > @@ -1,13 +1,12 @@
> >  PYTHON ?= python
> >  
> >  # Installation directories.
> > -PREFIX ?= $(DESTDIR)/usr
> > -LIBDIR ?= $(PREFIX)/lib
> > -SBINDIR ?= $(PREFIX)/sbin
> > -MANDIR = $(PREFIX)/share/man
> > -PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import *; 
> > print(get_python_lib(1))")
> > +PREFIX ?= /usr
> > +SBINDIR ?= $(DESTDIR)$(PREFIX)/sbin
> > +MANDIR = $(DESTDIR)$(PREFIX)/share/man
> > +PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import *; 
> > print(get_python_lib(prefix='$(PREFIX)'))")
> 
> Note that this change move paths for modules from platform-specific to
> platform-shared:
> 
> - /home/vagrant/build/usr/lib64/python3.6/site-packages/seobject.py
> + /home/vagrant/build/usr/lib/python3.6/site-packages/seobject.py
> 
> I think it's a good change given that there's only pure python
> modules, but it would be good to document it in the commit message.
> 
> 

I will split up the logical changes and make it to a seperate commit in
v4.

Thanks you!

> >  PACKAGEDIR ?= $(DESTDIR)/$(PYTHONLIBDIR)
> > -BASHCOMPLETIONDIR ?= $(DESTDIR)/usr/share/bash-completion/completions
> > +BASHCOMPLETIONDIR ?= $(DESTDIR)$(PREFIX)/share/bash-completion/completions
> >  
> >  TARGETS=semanage
> >  
> > diff --git a/python/sepolgen/src/sepolgen/Makefile 
> > b/python/sepolgen/src/sepolgen/Makefile
> > index d3aa7715..2121a955 100644
> > --- a/python/sepolgen/src/sepolgen/Makefile
> > +++ b/python/sepolgen/src/sepolgen/Makefile
> > @@ -1,5 +1,6 @@
> > +PREFIX ?= /usr
> >  PYTHON ?= python
> > -PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import *; 
> > print(get_python_lib(1))")
> > +PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import *; 
> > print(get_python_lib(prefix='$(PREFIX)'))")
> >  PACKAGEDIR ?= $(DESTDIR)/$(PYTHONLIBDIR)/sepolgen
> >  
> >  all:
> > diff --git a/python/sepolicy/Makefile b/python/sepolicy/M

[PATCH v3 12/14] semodule-utils: build: follow standard semantics for DESTDIR and PREFIX

2018-01-22 Thread Marcus Folkesson
Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
---
 semodule-utils/semodule_expand/Makefile  | 8 +++-
 semodule-utils/semodule_link/Makefile| 8 +++-
 semodule-utils/semodule_package/Makefile | 8 +++-
 3 files changed, 9 insertions(+), 15 deletions(-)

diff --git a/semodule-utils/semodule_expand/Makefile 
b/semodule-utils/semodule_expand/Makefile
index 072f2137..c2ab3f65 100644
--- a/semodule-utils/semodule_expand/Makefile
+++ b/semodule-utils/semodule_expand/Makefile
@@ -1,9 +1,7 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-INCLUDEDIR ?= $(PREFIX)/include
-BINDIR ?= $(PREFIX)/bin
-LIBDIR ?= $(PREFIX)/lib
-MANDIR ?= $(PREFIX)/share/man
+PREFIX ?= /usr
+BINDIR ?= $(DESTDIR)$(PREFIX)/bin
+MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
 
 CFLAGS ?= -Werror -Wall -W
 override LDLIBS += -lsepol
diff --git a/semodule-utils/semodule_link/Makefile 
b/semodule-utils/semodule_link/Makefile
index cc4687bd..bcf98765 100644
--- a/semodule-utils/semodule_link/Makefile
+++ b/semodule-utils/semodule_link/Makefile
@@ -1,9 +1,7 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-INCLUDEDIR ?= $(PREFIX)/include
-BINDIR ?= $(PREFIX)/bin
-MANDIR ?= $(PREFIX)/share/man
-LIBDIR ?= $(PREFIX)/lib
+PREFIX ?= /usr
+BINDIR ?= $(DESTDIR)$(PREFIX)/bin
+MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
 
 CFLAGS ?= -Werror -Wall -W
 override LDLIBS += -lsepol
diff --git a/semodule-utils/semodule_package/Makefile 
b/semodule-utils/semodule_package/Makefile
index 96dd7c4f..33a95e16 100644
--- a/semodule-utils/semodule_package/Makefile
+++ b/semodule-utils/semodule_package/Makefile
@@ -1,9 +1,7 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-INCLUDEDIR ?= $(PREFIX)/include
-BINDIR ?= $(PREFIX)/bin
-LIBDIR ?= $(PREFIX)/lib
-MANDIR ?= $(PREFIX)/share/man
+PREFIX ?= /usr
+BINDIR ?= $(DESTDIR)$(PREFIX)/bin
+MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
 
 CFLAGS ?= -Werror -Wall -W
 override LDLIBS += -lsepol
-- 
2.15.1




[PATCH v3 09/14] restorecond: build: follow standard semantics for DESTDIR and PREFIX

2018-01-22 Thread Marcus Folkesson
Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
---
 restorecond/Makefile | 11 +--
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/restorecond/Makefile b/restorecond/Makefile
index ada94aeb..a2316947 100644
--- a/restorecond/Makefile
+++ b/restorecond/Makefile
@@ -1,13 +1,12 @@
 PKG_CONFIG ?= pkg-config
 
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-SBINDIR ?= $(PREFIX)/sbin
-LIBDIR ?= $(PREFIX)/lib
-MANDIR = $(PREFIX)/share/man
+PREFIX ?= /usr
+SBINDIR ?= $(DESTDIR)$(PREFIX)/sbin
+MANDIR = $(DESTDIR)$(PREFIX)/share/man
 AUTOSTARTDIR = $(DESTDIR)/etc/xdg/autostart
-DBUSSERVICEDIR = $(DESTDIR)/usr/share/dbus-1/services
-SYSTEMDDIR ?= $(DESTDIR)/usr/lib/systemd
+DBUSSERVICEDIR = $(DESTDIR)$(PREFIX)/share/dbus-1/services
+SYSTEMDDIR ?= $(DESTDIR)$(PREFIX)/lib/systemd
 
 autostart_DATA = sealertauto.desktop
 INITDIR ?= $(DESTDIR)/etc/rc.d/init.d
-- 
2.15.1




[PATCH v3 10/14] sandbox: build: follow standard semantics for DESTDIR and PREFIX

2018-01-22 Thread Marcus Folkesson
Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
---
 sandbox/Makefile | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/sandbox/Makefile b/sandbox/Makefile
index 05c3d658..5a6b707a 100644
--- a/sandbox/Makefile
+++ b/sandbox/Makefile
@@ -1,14 +1,14 @@
 PYTHON ?= python
 
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
+PREFIX ?= /usr
 SYSCONFDIR ?= $(DESTDIR)/etc/sysconfig
-LIBDIR ?= $(PREFIX)/lib
-BINDIR ?= $(PREFIX)/bin
-SBINDIR ?= $(PREFIX)/sbin
-MANDIR ?= $(PREFIX)/share/man
+LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
+BINDIR ?= $(DESTDIR)$(PREFIX)/bin
+SBINDIR ?= $(DESTDIR)$(PREFIX)/sbin
+MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
 LOCALEDIR ?= /usr/share/locale
-SHAREDIR ?= $(PREFIX)/share/sandbox
+SHAREDIR ?= $(DESTDIR)$(PREFIX)/share/sandbox
 override CFLAGS += -DPACKAGE="\"policycoreutils\"" -Wall -Werror -Wextra -W
 override LDLIBS += -lselinux -lcap-ng
 SEUNSHARE_OBJS = seunshare.o
-- 
2.15.1




Rework of Makefiles v3

2018-01-22 Thread Marcus Folkesson
Hi all,

I have updated the patchset.

Please test to compile with:
make DESTDIR=/tmp/myroot PREFIX=/myusr install
or
make DESTDIR=/tmp/myroot install

As said before, the goal with this patchset is to clean up the
Makefiles on unused symbols, use standard semantics and keep all
the old functionality.

Changes:
v3:
- python: Add missing slash 
- Top makefile: Add default prefix
- python, mcstrans, selinux: keep the possibility to specify LIBSEPOLA 
to
  make depending component recompile on change. If not specified, fall 
back to
  libsepola in LDFLAGS path.

v2:
- Use separate directories for shared libraries as before( Comment from 
Stephen Smalley)
- Rework all packages (not just selinux/sepol/semanage)







[PATCH v3 11/14] secilc: build: follow standard semantics for DESTDIR and PREFIX

2018-01-22 Thread Marcus Folkesson
Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
---
 secilc/Makefile | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/secilc/Makefile b/secilc/Makefile
index 1cac53e4..5b0a4852 100644
--- a/secilc/Makefile
+++ b/secilc/Makefile
@@ -1,8 +1,6 @@
-PREFIX ?= $(DESTDIR)/usr
-BINDIR ?= $(PREFIX)/bin
-MANDIR ?= $(PREFIX)/share/man
-LIBDIR ?= $(PREFIX)/lib
-INCLUDEDIR ?= $(PREFIX)/include
+PREFIX ?= /usr
+BINDIR ?= $(DESTDIR)$(PREFIX)/bin
+MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
 
 SECILC = secilc
 SECILC_SRCS := secilc.c
-- 
2.15.1




[PATCH v3 08/14] python: build: follow standard semantics for DESTDIR and PREFIX

2018-01-22 Thread Marcus Folkesson
Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
---
 python/audit2allow/Makefile   | 17 ++---
 python/chcat/Makefile |  8 
 python/semanage/Makefile  | 11 +--
 python/sepolgen/src/sepolgen/Makefile |  3 ++-
 python/sepolicy/Makefile  | 18 +-
 5 files changed, 30 insertions(+), 27 deletions(-)

diff --git a/python/audit2allow/Makefile b/python/audit2allow/Makefile
index 8db8075f..d1d4ca8d 100644
--- a/python/audit2allow/Makefile
+++ b/python/audit2allow/Makefile
@@ -1,19 +1,22 @@
 PYTHON ?= python
 
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-BINDIR ?= $(PREFIX)/bin
-LIBDIR ?= $(PREFIX)/lib
-MANDIR ?= $(PREFIX)/share/man
-LOCALEDIR ?= /usr/share/locale
-INCLUDEDIR ?= $(PREFIX)/include
-LIBSEPOLA ?= $(LIBDIR)/libsepol.a
+PREFIX ?= /usr
+BINDIR ?= $(DESTDIR)$(PREFIX)/bin
+LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
+MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
 
 CFLAGS ?= -Werror -Wall -W
 
+# If no specific libsepol.a is specified, fall back on LDFLAGS search path
+ifeq ($(LIBSEPOLA),)
+   LDFLAGS += -l:libsepol.a
+endif
+
 all: audit2why sepolgen-ifgen-attr-helper
 
 sepolgen-ifgen-attr-helper: sepolgen-ifgen-attr-helper.o $(LIBSEPOLA)
+   $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
 
 audit2why:
ln -sf audit2allow audit2why
diff --git a/python/chcat/Makefile b/python/chcat/Makefile
index 0fd12d6d..947734a0 100644
--- a/python/chcat/Makefile
+++ b/python/chcat/Makefile
@@ -1,8 +1,8 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-BINDIR ?= $(PREFIX)/bin
-MANDIR ?= $(PREFIX)/share/man
-LOCALEDIR ?= $(PREFIX)/share/locale
+PREFIX ?= /usr
+BINDIR ?= $(DESTDIR)$(PREFIX)/bin
+MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
+LOCALEDIR ?= $(DESTDIR)$(PREFIX)/share/locale
 
 .PHONY: all
 all: chcat
diff --git a/python/semanage/Makefile b/python/semanage/Makefile
index 132162bc..0218222d 100644
--- a/python/semanage/Makefile
+++ b/python/semanage/Makefile
@@ -1,13 +1,12 @@
 PYTHON ?= python
 
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-LIBDIR ?= $(PREFIX)/lib
-SBINDIR ?= $(PREFIX)/sbin
-MANDIR = $(PREFIX)/share/man
-PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import *; 
print(get_python_lib(1))")
+PREFIX ?= /usr
+SBINDIR ?= $(DESTDIR)$(PREFIX)/sbin
+MANDIR = $(DESTDIR)$(PREFIX)/share/man
+PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import *; 
print(get_python_lib(prefix='$(PREFIX)'))")
 PACKAGEDIR ?= $(DESTDIR)/$(PYTHONLIBDIR)
-BASHCOMPLETIONDIR ?= $(DESTDIR)/usr/share/bash-completion/completions
+BASHCOMPLETIONDIR ?= $(DESTDIR)$(PREFIX)/share/bash-completion/completions
 
 TARGETS=semanage
 
diff --git a/python/sepolgen/src/sepolgen/Makefile 
b/python/sepolgen/src/sepolgen/Makefile
index d3aa7715..2121a955 100644
--- a/python/sepolgen/src/sepolgen/Makefile
+++ b/python/sepolgen/src/sepolgen/Makefile
@@ -1,5 +1,6 @@
+PREFIX ?= /usr
 PYTHON ?= python
-PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import *; 
print(get_python_lib(1))")
+PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import *; 
print(get_python_lib(prefix='$(PREFIX)'))")
 PACKAGEDIR ?= $(DESTDIR)/$(PYTHONLIBDIR)/sepolgen
 
 all:
diff --git a/python/sepolicy/Makefile b/python/sepolicy/Makefile
index 5a56e6c8..1c02ee06 100644
--- a/python/sepolicy/Makefile
+++ b/python/sepolicy/Makefile
@@ -1,14 +1,14 @@
 PYTHON ?= python
 
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-LIBDIR ?= $(PREFIX)/lib
-BINDIR ?= $(PREFIX)/bin
-DATADIR ?= $(PREFIX)/share
-MANDIR ?= $(PREFIX)/share/man
-LOCALEDIR ?= /usr/share/locale
-BASHCOMPLETIONDIR ?= $(DESTDIR)/usr/share/bash-completion/completions
-SHAREDIR ?= $(PREFIX)/share/sandbox
+PREFIX ?= /usr
+LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
+BINDIR ?= $(DESTDIR)$(PREFIX)/bin
+DATADIR ?= $(DESTDIR)$(PREFIX)/share
+MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
+LOCALEDIR ?= $(DESTDIR)$(PREFIX)/share/locale
+BASHCOMPLETIONDIR ?= $(DESTDIR)$(PREFIX)/share/bash-completion/completions
+SHAREDIR ?= $(DESTDIR)$(PREFIX)/share/sandbox
 CFLAGS ?= -Wall -Werror -Wextra -W
 override CFLAGS += -DPACKAGE="policycoreutils" -DSHARED -shared
 
@@ -30,7 +30,7 @@ test:
@$(PYTHON) test_sepolicy.py -v
 
 install:
-   $(PYTHON) setup.py install `test -n "$(DESTDIR)" && echo --root 
$(DESTDIR)`
+   $(PYTHON) setup.py install --prefix=$(PREFIX) `test -n "$(DESTDIR)" && 
echo --root $(DESTDIR)`
[ -d $(BINDIR) ] || mkdir -p $(BINDIR)
install -m 755 sepolicy.py $(BINDIR)/sepolicy
(cd $(BINDIR); ln -sf sepolicy sepolgen)
-- 
2.15.1




[PATCH v3 07/14] policycoreutils: build: follow standard semantics for DESTDIR and PREFIX

2018-01-22 Thread Marcus Folkesson
Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
---
 policycoreutils/hll/pp/Makefile  |  7 ++-
 policycoreutils/load_policy/Makefile |  8 
 policycoreutils/man/Makefile |  3 ++-
 policycoreutils/newrole/Makefile |  8 
 policycoreutils/po/Makefile  |  3 ++-
 policycoreutils/run_init/Makefile|  8 
 policycoreutils/scripts/Makefile |  8 
 policycoreutils/secon/Makefile   |  9 -
 policycoreutils/semodule/Makefile|  8 +++-
 policycoreutils/sestatus/Makefile|  8 
 policycoreutils/setfiles/Makefile|  5 ++---
 policycoreutils/setsebool/Makefile   | 10 --
 12 files changed, 39 insertions(+), 46 deletions(-)

diff --git a/policycoreutils/hll/pp/Makefile b/policycoreutils/hll/pp/Makefile
index 3401dcc9..ce58e0cf 100644
--- a/policycoreutils/hll/pp/Makefile
+++ b/policycoreutils/hll/pp/Makefile
@@ -1,9 +1,6 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-INCLUDEDIR ?= $(PREFIX)/include
-MANDIR = $(PREFIX)/share/man
-LIBDIR ?= $(PREFIX)/lib
-LIBEXECDIR ?= $(PREFIX)/libexec
+PREFIX ?= /usr
+LIBEXECDIR ?= $(DESTDIR)$(PREFIX)/libexec
 HLLDIR ?= $(LIBEXECDIR)/selinux/hll
 
 CFLAGS ?= -Werror -Wall -W
diff --git a/policycoreutils/load_policy/Makefile 
b/policycoreutils/load_policy/Makefile
index b85833c2..720bf45f 100644
--- a/policycoreutils/load_policy/Makefile
+++ b/policycoreutils/load_policy/Makefile
@@ -1,8 +1,8 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-SBINDIR ?= $(DESTDIR)/sbin
-MANDIR ?= $(PREFIX)/share/man
-LOCALEDIR ?= /usr/share/locale
+PREFIX ?= /usr
+SBINDIR ?= $(DESTDIR)$(PREFIX)/sbin
+MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
+LOCALEDIR ?= $(DESTDIR)$(PREFIX)/share/locale
 
 CFLAGS ?= -Werror -Wall -W
 override CFLAGS += $(LDFLAGS) -DUSE_NLS -DLOCALEDIR="\"$(LOCALEDIR)\"" 
-DPACKAGE="\"policycoreutils\""
diff --git a/policycoreutils/man/Makefile b/policycoreutils/man/Makefile
index 0d91cd46..8a8fbd49 100644
--- a/policycoreutils/man/Makefile
+++ b/policycoreutils/man/Makefile
@@ -1,5 +1,6 @@
 # Installation directories.
-MAN5DIR ?= $(DESTDIR)/usr/share/man/man5
+PREFIX ?= /usr
+MAN5DIR ?= $(DESTDIR)$(PREFIX)/share/man/man5
 
 all:
 
diff --git a/policycoreutils/newrole/Makefile b/policycoreutils/newrole/Makefile
index 196af926..4dbe6f52 100644
--- a/policycoreutils/newrole/Makefile
+++ b/policycoreutils/newrole/Makefile
@@ -1,9 +1,9 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-BINDIR ?= $(PREFIX)/bin
-MANDIR ?= $(PREFIX)/share/man
+PREFIX ?= /usr
+BINDIR ?= $(DESTDIR)$(PREFIX)/bin
+MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
 ETCDIR ?= $(DESTDIR)/etc
-LOCALEDIR = /usr/share/locale
+LOCALEDIR = $(DESTDIR)$(PREFIX)/share/locale
 PAMH ?= $(shell test -f /usr/include/security/pam_appl.h && echo y)
 AUDITH ?= $(shell test -f /usr/include/libaudit.h && echo y)
 # Enable capabilities to permit newrole to generate audit records.
diff --git a/policycoreutils/po/Makefile b/policycoreutils/po/Makefile
index 58148613..c583d23a 100644
--- a/policycoreutils/po/Makefile
+++ b/policycoreutils/po/Makefile
@@ -2,6 +2,7 @@
 # Makefile for the PO files (translation) catalog
 #
 
+PREFIX ?= /usr
 TOP = ../..
 
 # What is this package?
@@ -12,7 +13,7 @@ INSTALL_DATA  = $(INSTALL) -m 644
 INSTALL_DIR= /usr/bin/install -d
 
 # destination directory
-INSTALL_NLS_DIR = $(DESTDIR)/usr/share/locale
+INSTALL_NLS_DIR = $(DESTDIR)$(PREFIX)/share/locale
 
 # PO catalog handling
 MSGMERGE   = msgmerge
diff --git a/policycoreutils/run_init/Makefile 
b/policycoreutils/run_init/Makefile
index 921f0b07..4178493e 100644
--- a/policycoreutils/run_init/Makefile
+++ b/policycoreutils/run_init/Makefile
@@ -1,10 +1,10 @@
 
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-SBINDIR ?= $(PREFIX)/sbin
-MANDIR ?= $(PREFIX)/share/man
+PREFIX ?= /usr
+SBINDIR ?= $(DESTDIR)$(PREFIX)/sbin
+MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
 ETCDIR ?= $(DESTDIR)/etc
-LOCALEDIR ?= /usr/share/locale
+LOCALEDIR ?= $(DESTDIR)$(PREFIX)/share/locale
 PAMH ?= $(shell test -f /usr/include/security/pam_appl.h && echo y)
 AUDITH ?= $(shell test -f /usr/include/libaudit.h && echo y)
 
diff --git a/policycoreutils/scripts/Makefile b/policycoreutils/scripts/Makefile
index d9e86ffe..cfd841ec 100644
--- a/policycoreutils/scripts/Makefile
+++ b/policycoreutils/scripts/Makefile
@@ -1,8 +1,8 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-SBINDIR ?= $(DESTDIR)/sbin
-MANDIR ?= $(PREFIX)/share/man
-LOCALEDIR ?= $(PREFIX)/share/locale
+PREFIX ?= /usr
+SBINDIR ?= $(DESTDIR)$(PREFIX)/sbin
+MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
+LOCALEDIR ?= $(DESTDIR)$(PREFIX)/share/locale
 
 .PHONY: all
 all: fixfiles
diff --git a/policycoreutils/secon/Makefile b/policycoreutils/secon/Makefile
index 8e491d74..4ecbd57d 100644
--- a/policycoreutils/secon/Makefile
+++ b/policycoreutils/secon/Makefile
@@ -1,9 +1,8 @@
 # secon tool - command-l

[PATCH v3 06/14] mcstrans: build: follow standard semantics for DESTDIR and PREFIX

2018-01-22 Thread Marcus Folkesson
Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
---
 mcstrans/man/Makefile   |  3 ++-
 mcstrans/src/Makefile   | 18 +++---
 mcstrans/utils/Makefile | 20 ++--
 3 files changed, 27 insertions(+), 14 deletions(-)

diff --git a/mcstrans/man/Makefile b/mcstrans/man/Makefile
index 8e971192..5030fa81 100644
--- a/mcstrans/man/Makefile
+++ b/mcstrans/man/Makefile
@@ -1,5 +1,6 @@
 # Installation directories.
-MAN8DIR ?= $(DESTDIR)/usr/share/man/man8
+PREFIX ?= /usr
+MAN8DIR ?= $(DESTDIR)$(PREFIX)/share/man/man8
 
 all:
 
diff --git a/mcstrans/src/Makefile b/mcstrans/src/Makefile
index 3f4a89c3..09551d63 100644
--- a/mcstrans/src/Makefile
+++ b/mcstrans/src/Makefile
@@ -1,10 +1,14 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-LIBDIR ?= $(PREFIX)/lib
+PREFIX ?= /usr
+LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
 SBINDIR ?= $(DESTDIR)/sbin
 INITDIR ?= $(DESTDIR)/etc/rc.d/init.d
-SYSTEMDDIR ?= $(DESTDIR)/usr/lib/systemd
-LIBSEPOLA ?= $(LIBDIR)/libsepol.a
+SYSTEMDDIR ?= $(DESTDIR)$(PREFIX)/lib/systemd
+
+# If no specific libsepol.a is specified, fall back on LDFLAGS search path
+ifeq ($(LIBSEPOLA),)
+   LDFLAGS += -l:libsepol.a
+endif
 
 PROG_SRC=mcstrans.c  mcscolor.c  mcstransd.c  mls_level.c
 PROG_OBJS= $(patsubst %.c,%.o,$(PROG_SRC))
@@ -15,11 +19,11 @@ override CFLAGS += -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
 
 all: $(PROG)
 
-$(PROG): $(PROG_OBJS)
-   $(CC) $(LDFLAGS) -pie -o $@ $^ -lselinux -lcap -lpcre $(LIBSEPOLA)
+$(PROG): $(PROG_OBJS) $(LIBSEPOLA)
+   $(CC) -pie -o $@ $^ -lselinux -lcap -lpcre $(LDFLAGS)
 
 %.o:  %.c 
-   $(CC) $(CFLAGS) -fPIE -c -o $@ $<
+   $(CC) $(CFLAGS) -fPIE -c -o $@ $< $(LDFLAGS)
 
 install: all
test -d $(SBINDIR) || install -m 755 -d $(SBINDIR)
diff --git a/mcstrans/utils/Makefile b/mcstrans/utils/Makefile
index 4d3cbfcb..0a0452a4 100644
--- a/mcstrans/utils/Makefile
+++ b/mcstrans/utils/Makefile
@@ -1,18 +1,26 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-LIBDIR ?= $(PREFIX)/lib
-SBINDIR ?= $(PREFIX)/sbin
-LIBSEPOLA ?= $(LIBDIR)/libsepol.a
+PREFIX ?= /usr
+LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
+SBINDIR ?= $(DESTDIR)$(PREFIX)/sbin
 
 CFLAGS ?= -Wall
 override CFLAGS += -I../src -D_GNU_SOURCE
 override LDLIBS += -lselinux -lpcre
 
-TARGETS=$(patsubst %.c,%,$(sort $(wildcard *.c)))
+TARGETS=transcon untranscon
+
+# If no specific libsepol.a is specified, fall back on LDFLAGS search path
+ifeq ($(LIBSEPOLA),)
+   LDFLAGS += -l:libsepol.a
+endif
 
 all: $(TARGETS)
 
-$(TARGETS): ../src/mcstrans.o ../src/mls_level.o $(LIBSEPOLA)
+transcon: transcon.o ../src/mcstrans.o ../src/mls_level.o $(LIBSEPOLA)
+   $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) -lpcre -lselinux
+
+untranscon: untranscon.o ../src/mcstrans.o ../src/mls_level.o $(LIBSEPOLA)
+   $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) -lpcre -lselinux
 
 install: all
-mkdir -p $(SBINDIR)
-- 
2.15.1




[PATCH v3 03/14] libsemanage: build: follow standard semantics for DESTDIR and PREFIX

2018-01-22 Thread Marcus Folkesson
This patch solves the following issues:
- 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.folkes...@gmail.com>
---
 libsemanage/include/Makefile  | 4 ++--
 libsemanage/man/Makefile  | 5 +++--
 libsemanage/src/Makefile  | 9 +++--
 libsemanage/src/libsemanage.pc.in | 2 +-
 libsemanage/tests/Makefile| 3 ---
 libsemanage/utils/Makefile| 4 ++--
 6 files changed, 11 insertions(+), 16 deletions(-)

diff --git a/libsemanage/include/Makefile b/libsemanage/include/Makefile
index b660660e..f4234b9e 100644
--- a/libsemanage/include/Makefile
+++ b/libsemanage/include/Makefile
@@ -1,6 +1,6 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-INCDIR ?= $(PREFIX)/include/semanage
+PREFIX ?= /usr
+INCDIR ?= $(DESTDIR)$(PREFIX)/include/semanage
 
 all:
 
diff --git a/libsemanage/man/Makefile b/libsemanage/man/Makefile
index 852043d4..43c2b3f6 100644
--- a/libsemanage/man/Makefile
+++ b/libsemanage/man/Makefile
@@ -1,6 +1,7 @@
 # Installation directories.
-MAN3DIR ?= $(DESTDIR)/usr/share/man/man3
-MAN5DIR ?= $(DESTDIR)/usr/share/man/man5
+PREFIX ?= /usr
+MAN3DIR ?= $(DESTDIR)$(PREFIX)/share/man/man3
+MAN5DIR ?= $(DESTDIR)$(PREFIX)/share/man/man5
 
 all:
 
diff --git a/libsemanage/src/Makefile b/libsemanage/src/Makefile
index fdb178f5..f66d1b73 100644
--- a/libsemanage/src/Makefile
+++ b/libsemanage/src/Makefile
@@ -8,9 +8,8 @@ RUBYPREFIX ?= $(notdir $(RUBY))
 PKG_CONFIG ?= pkg-config
 
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-LIBDIR ?= $(PREFIX)/lib
-SHLIBDIR ?= $(DESTDIR)/lib
+PREFIX ?= /usr
+LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
 INCLUDEDIR ?= $(PREFIX)/include
 PYINC ?= $(shell $(PKG_CONFIG) --cflags $(PYPREFIX))
 PYLIBS ?= $(shell $(PKG_CONFIG) --libs $(PYPREFIX))
@@ -20,8 +19,6 @@ RUBYINC ?= $(shell $(RUBY) -e 'puts "-I" + 
RbConfig::CONFIG["rubyarchhdrdir"] +
 RUBYLIBS ?= $(shell $(RUBY) -e 'puts "-L" + RbConfig::CONFIG["libdir"] + " -L" 
+ RbConfig::CONFIG["archlibdir"] + " " + RbConfig::CONFIG["LIBRUBYARG_SHARED"]')
 RUBYINSTALL ?= $(DESTDIR)$(shell $(RUBY) -e 'puts 
RbConfig::CONFIG["vendorarchdir"]')
 
-LIBBASE=$(shell basename $(LIBDIR))
-
 DEFAULT_SEMANAGE_CONF_LOCATION=$(DESTDIR)/etc/selinux/semanage.conf
 
 ifeq ($(DEBUG),1)
@@ -95,7 +92,7 @@ $(LIBSO): $(LOBJS)
ln -sf $@ $(TARGET)
 
 $(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):' < $< > $@
 
 semanageswig_python_exception.i: ../include/semanage/semanage.h
bash -e exception.sh > $@ || (rm -f $@ ; false)
diff --git a/libsemanage/src/libsemanage.pc.in 
b/libsemanage/src/libsemanage.pc.in
index d3eaa062..43681ddb 100644
--- a/libsemanage/src/libsemanage.pc.in
+++ b/libsemanage/src/libsemanage.pc.in
@@ -1,6 +1,6 @@
 prefix=@prefix@
 exec_prefix=${prefix}
-libdir=${exec_prefix}/@libdir@
+libdir=@libdir@
 includedir=@includedir@
 
 Name: libsemanage
diff --git a/libsemanage/tests/Makefile b/libsemanage/tests/Makefile
index 2ef8d30d..324766a0 100644
--- a/libsemanage/tests/Makefile
+++ b/libsemanage/tests/Makefile
@@ -1,6 +1,3 @@
-PREFIX ?= $(DESTDIR)/usr
-LIBDIR ?= $(PREFIX)/lib
-
 # Add your test source files here:
 SOURCES = $(sort $(wildcard *.c))
 
diff --git a/libsemanage/utils/Makefile b/libsemanage/utils/Makefile
index 725f0eec..f527ad07 100644
--- a/libsemanage/utils/Makefile
+++ b/libsemanage/utils/Makefile
@@ -1,6 +1,6 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-LIBEXECDIR ?= $(PREFIX)/libexec
+PREFIX ?= /usr
+LIBEXECDIR ?= $(DESTDIR)$(PREFIX)/libexec
 SELINUXEXECDIR ?= $(LIBEXECDIR)/selinux/
 
 all:
-- 
2.15.1




[PATCH v3 14/14] build: add prefix for includes in top Makefile

2018-01-22 Thread Marcus Folkesson
Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
---
 Makefile | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 6da7f7b7..6baea148 100644
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,4 @@
+PREFIX ?= /usr
 OPT_SUBDIRS ?= dbus gui mcstrans python restorecond sandbox semodule-utils
 SUBDIRS=libsepol libselinux libsemanage checkpolicy secilc policycoreutils 
$(OPT_SUBDIRS)
 PYSUBDIRS=libselinux libsemanage
@@ -19,8 +20,8 @@ else
 endif
 
 ifneq ($(DESTDIR),)
-   CFLAGS += -I$(DESTDIR)/usr/include
-   LDFLAGS += -L$(DESTDIR)/usr/lib
+   CFLAGS += -I$(DESTDIR)$(PREFIX)/include
+   LDFLAGS += -L$(DESTDIR)$(PREFIX)/lib
export CFLAGS
export LDFLAGS
 endif
-- 
2.15.1




[PATCH v3 01/14] libsepol: build: follow standard semantics for DESTDIR and PREFIX

2018-01-22 Thread Marcus Folkesson
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.folkes...@gmail.com>
---
 README  | 2 +-
 libsepol/include/Makefile   | 4 ++--
 libsepol/man/Makefile   | 5 +++--
 libsepol/src/Makefile   | 7 +++
 libsepol/src/libsepol.pc.in | 2 +-
 libsepol/utils/Makefile | 4 ++--
 6 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/README b/README
index 7fc7b17b..174551a1 100644
--- a/README
+++ b/README
@@ -19,6 +19,6 @@ lacks library functions or other dependencies relied upon by 
your
 distribution.  If it breaks, you get to keep both pieces.
 
 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).
diff --git a/libsepol/include/Makefile b/libsepol/include/Makefile
index 56b7a114..ad5c34a4 100644
--- a/libsepol/include/Makefile
+++ b/libsepol/include/Makefile
@@ -1,6 +1,6 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-INCDIR ?= $(PREFIX)/include/sepol
+PREFIX ?= /usr
+INCDIR = $(DESTDIR)$(PREFIX)/include/sepol
 CILDIR ?= ../cil
 
 all:
diff --git a/libsepol/man/Makefile b/libsepol/man/Makefile
index 11924334..4f3d9fa2 100644
--- a/libsepol/man/Makefile
+++ b/libsepol/man/Makefile
@@ -1,6 +1,7 @@
 # Installation directories.
-MAN8DIR ?= $(DESTDIR)/usr/share/man/man8
-MAN3DIR ?= $(DESTDIR)/usr/share/man/man3
+PREFIX ?= /usr
+MAN8DIR ?= $(DESTDIR)$(PREFIX)/share/man/man8
+MAN3DIR ?= $(DESTDIR)$(PREFIX)/share/man/man3
 
 all:
 
diff --git a/libsepol/src/Makefile b/libsepol/src/Makefile
index 819d261b..d158398f 100644
--- a/libsepol/src/Makefile
+++ b/libsepol/src/Makefile
@@ -1,10 +1,9 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
+PREFIX ?= /usr
 INCLUDEDIR ?= $(PREFIX)/include
-LIBDIR ?= $(PREFIX)/lib
+LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
 SHLIBDIR ?= $(DESTDIR)/lib
 RANLIB ?= ranlib
-LIBBASE ?= $(shell basename $(LIBDIR))
 CILDIR ?= ../cil
 
 VERSION = $(shell cat ../VERSION)
@@ -52,7 +51,7 @@ $(LIBSO): $(LOBJS) $(LIBMAP)
ln -sf $@ $(TARGET) 
 
 $(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
 ifneq ($(DISABLE_CIL),y)
diff --git a/libsepol/src/libsepol.pc.in b/libsepol/src/libsepol.pc.in
index e52f5892..f807fec6 100644
--- a/libsepol/src/libsepol.pc.in
+++ b/libsepol/src/libsepol.pc.in
@@ -1,6 +1,6 @@
 prefix=@prefix@
 exec_prefix=${prefix}
-libdir=${exec_prefix}/@libdir@
+libdir=@libdir@
 includedir=@includedir@
 
 Name: libsepol
diff --git a/libsepol/utils/Makefile b/libsepol/utils/Makefile
index fba1d8a0..8ce4bf47 100644
--- a/libsepol/utils/Makefile
+++ b/libsepol/utils/Makefile
@@ -1,6 +1,6 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-BINDIR ?= $(PREFIX)/bin
+PREFIX ?= /usr
+BINDIR ?= $(DESTDIR)$(PREFIX)/bin
 
 CFLAGS ?= -Wall -Werror
 override CFLAGS += -I../include
-- 
2.15.1




[PATCH v3 02/14] libselinux: build: follow standard semantics for DESTDIR and PREFIX

2018-01-22 Thread Marcus Folkesson
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.folkes...@gmail.com>
---
 libselinux/include/Makefile |  4 ++--
 libselinux/man/Makefile |  7 ---
 libselinux/src/Makefile | 14 +-
 libselinux/src/libselinux.pc.in |  2 +-
 libselinux/utils/Makefile   |  6 ++
 5 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/libselinux/include/Makefile b/libselinux/include/Makefile
index 757a6c9c..3b51f5ce 100644
--- a/libselinux/include/Makefile
+++ b/libselinux/include/Makefile
@@ -1,6 +1,6 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-INCDIR ?= $(PREFIX)/include/selinux
+PREFIX ?= /usr
+INCDIR = $(DESTDIR)$(PREFIX)/include/selinux
 
 all:
 
diff --git a/libselinux/man/Makefile b/libselinux/man/Makefile
index 0643e6af..233bfaa9 100644
--- a/libselinux/man/Makefile
+++ b/libselinux/man/Makefile
@@ -1,7 +1,8 @@
 # Installation directories.
-MAN8DIR ?= $(DESTDIR)/usr/share/man/man8
-MAN5DIR ?= $(DESTDIR)/usr/share/man/man5
-MAN3DIR ?= $(DESTDIR)/usr/share/man/man3
+PREFIX ?= /usr
+MAN8DIR ?= $(DESTDIR)$(PREFIX)/share/man/man8
+MAN5DIR ?= $(DESTDIR)$(PREFIX)/share/man/man5
+MAN3DIR ?= $(DESTDIR)$(PREFIX)/share/man/man3
 
 all:
 
diff --git a/libselinux/src/Makefile b/libselinux/src/Makefile
index 18df75c8..e18c00f2 100644
--- a/libselinux/src/Makefile
+++ b/libselinux/src/Makefile
@@ -8,8 +8,8 @@ RUBYPREFIX ?= $(notdir $(RUBY))
 PKG_CONFIG ?= pkg-config
 
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-LIBDIR ?= $(PREFIX)/lib
+PREFIX ?= /usr
+LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
 SHLIBDIR ?= $(DESTDIR)/lib
 INCLUDEDIR ?= $(PREFIX)/include
 PYINC ?= $(shell $(PKG_CONFIG) --cflags $(PYPREFIX))
@@ -19,8 +19,6 @@ PYCEXT ?= $(shell $(PYTHON) -c 'import imp;print([s for s,m,t 
in imp.get_suffixe
 RUBYINC ?= $(shell $(RUBY) -e 'puts "-I" + RbConfig::CONFIG["rubyarchhdrdir"] 
+ " -I" + RbConfig::CONFIG["rubyhdrdir"]')
 RUBYLIBS ?= $(shell $(RUBY) -e 'puts "-L" + RbConfig::CONFIG["libdir"] + " -L" 
+ RbConfig::CONFIG["archlibdir"] + " " + RbConfig::CONFIG["LIBRUBYARG_SHARED"]')
 RUBYINSTALL ?= $(DESTDIR)$(shell $(RUBY) -e 'puts 
RbConfig::CONFIG["vendorarchdir"]')
-LIBBASE ?= $(shell basename $(LIBDIR))
-LIBSEPOLA ?= $(LIBDIR)/libsepol.a
 
 VERSION = $(shell cat ../VERSION)
 LIBVERSION = 1
@@ -50,6 +48,12 @@ LIBSO=$(TARGET).$(LIBVERSION)
 AUDIT2WHYLOBJ=$(PYPREFIX)audit2why.lo
 AUDIT2WHYSO=$(PYPREFIX)audit2why.so
 
+
+# If no specific libsepol.a is specified, fall back on LDFLAGS search path
+ifeq ($(LIBSEPOLA),)
+   LDFLAGS += -l:libsepol.a
+endif
+
 GENERATED=$(SWIGCOUT) $(SWIGRUBYCOUT) selinuxswig_python_exception.i
 SRCS= $(filter-out $(GENERATED) audit2why.c, $(sort $(wildcard *.c)))
 
@@ -148,7 +152,7 @@ $(LIBSO): $(LOBJS)
ln -sf $@ $(TARGET)
 
 $(LIBPC): $(LIBPC).in ../VERSION
-   sed -e 's/@VERSION@/$(VERSION)/; s:@prefix@:$(PREFIX):; 
s:@libdir@:$(LIBBASE):; s:@includedir@:$(INCLUDEDIR):; 
s:@PCRE_MODULE@:$(PCRE_MODULE):' < $< > $@
+   sed -e 's/@VERSION@/$(VERSION)/; s:@prefix@:$(PREFIX):; 
s:@libdir@:$(LIBDIR):; s:@includedir@:$(INCLUDEDIR):; 
s:@PCRE_MODULE@:$(PCRE_MODULE):' < $< > $@
 
 selinuxswig_python_exception.i: ../include/selinux/selinux.h
bash -e exception.sh > $@ || (rm -f $@ ; false)
diff --git a/libselinux/src/libselinux.pc.in b/libselinux/src/libselinux.pc.in
index 2e90a844..7c66b1fa 100644
--- a/libselinux/src/libselinux.pc.in
+++ b/libselinux/src/libselinux.pc.in
@@ -1,6 +1,6 @@
 prefix=@prefix@
 exec_prefix=${prefix}
-libdir=${exec_prefix}/@libdir@
+libdir=@libdir@
 includedir=@includedir@
 
 Name: libselinux
diff --git a/libselinux/utils/Makefile b/libselinux/utils/Makefile
index eb4851a9..9adce6d3 100644
--- a/libselinux/utils/Makefile
+++ b/libselinux/utils/Makefile
@@ -1,8 +1,6 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-LIBDIR ?= $(PREFIX)/lib
-SBINDIR ?= $(PREFIX)/sbin
-INCLUDEDIR ?= $(PREFIX)/include
+PREFIX ?= /usr
+SBINDIR ?= $(DESTDIR)$(PREFIX)/sbin
 
 OS ?= $(shell uname)
 
-- 
2.15.1




[PATCH v3 04/14] checkpolicy: build: follow standard semantics for DESTDIR and PREFIX

2018-01-22 Thread Marcus Folkesson
This patch solves the following issues:
- 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.folkes...@gmail.com>
---
 checkpolicy/Makefile  | 19 ---
 checkpolicy/test/Makefile | 15 ++-
 2 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/checkpolicy/Makefile b/checkpolicy/Makefile
index 68e11f2a..78a8a43b 100644
--- a/checkpolicy/Makefile
+++ b/checkpolicy/Makefile
@@ -1,12 +1,10 @@
 #
 # Makefile for building the checkpolicy program
 #
-PREFIX ?= $(DESTDIR)/usr
-BINDIR ?= $(PREFIX)/bin
-MANDIR ?= $(PREFIX)/share/man
-LIBDIR ?= $(PREFIX)/lib
-INCLUDEDIR ?= $(PREFIX)/include
-LIBSEPOLA ?= $(LIBDIR)/libsepol.a
+PREFIX ?= /usr
+BINDIR ?= $(DESTDIR)$(PREFIX)/bin
+MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
+LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
 TARGETS = checkpolicy checkmodule
 
 LEX = flex
@@ -14,6 +12,11 @@ YACC = bison -y
 
 CFLAGS ?= -g -Wall -Werror -Wshadow -O2 -pipe -fno-strict-aliasing
 
+# If no specific libsepol.a is specified, fall back on LDFLAGS search path
+ifeq ($(LIBSEPOLA),)
+   LDFLAGS += -l:libsepol.a
+endif
+
 override CFLAGS += -I.
 
 CHECKOBJS = y.tab.o lex.yy.o queue.o module_compiler.o parse_util.o \
@@ -27,11 +30,13 @@ all:  $(TARGETS)
$(MAKE) -C test
 
 checkpolicy: $(CHECKPOLOBJS) $(LIBSEPOLA)
+   $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
 
 checkmodule: $(CHECKMODOBJS) $(LIBSEPOLA)
+   $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
 
 %.o: %.c 
-   $(CC) $(CFLAGS) -o $@ -c $<
+   $(CC) $(CFLAGS) $(LDFLAGS) -o $@ -c $<
 
 y.tab.o: y.tab.c
$(CC) $(filter-out -Werror, $(CFLAGS)) -o $@ -c $<
diff --git a/checkpolicy/test/Makefile b/checkpolicy/test/Makefile
index 59fa4460..3eb1c512 100644
--- a/checkpolicy/test/Makefile
+++ b/checkpolicy/test/Makefile
@@ -1,19 +1,24 @@
 #
 # Makefile for building the dispol program
 #
-PREFIX ?= $(DESTDIR)/usr
-BINDIR ?= $(PREFIX)/bin
-LIBDIR ?= $(PREFIX)/lib
-INCLUDEDIR ?= $(PREFIX)/include
-LIBSEPOLA ?= $(LIBDIR)/libsepol.a
+PREFIX ?= /usr
+BINDIR ?= $(DESTDIR)$(PREFIX)/bin
+LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
 
 CFLAGS ?= -g -Wall -W -Werror -O2 -pipe
 
+# If no specific libsepol.a is specified, fall back on LDFLAGS search path
+ifeq ($(LIBSEPOLA),)
+   LDFLAGS += -l:libsepol.a
+endif
+
 all: dispol dismod
 
 dispol: dispol.o $(LIBSEPOLA)
+   $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
 
 dismod: dismod.o $(LIBSEPOLA)
+   $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
 
 clean:
-rm -f dispol dismod *.o 
-- 
2.15.1




[PATCH v3 05/14] gui: build: follow standard semantics for DESTDIR and PREFIX

2018-01-22 Thread Marcus Folkesson
Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
---
 gui/Makefile | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/gui/Makefile b/gui/Makefile
index cfe47405..5efd17d7 100644
--- a/gui/Makefile
+++ b/gui/Makefile
@@ -1,9 +1,9 @@
 # Installation directories.
-PREFIX ?= ${DESTDIR}/usr
-BINDIR ?= $(PREFIX)/bin
-SHAREDIR ?= $(PREFIX)/share/system-config-selinux
-DATADIR ?= $(PREFIX)/share
-MANDIR ?= $(PREFIX)/share/man
+PREFIX ?= /usr
+BINDIR ?= $(DESTDIR)$(PREFIX)/bin
+SHAREDIR ?= $(DESTDIR)$(PREFIX)/share/system-config-selinux
+DATADIR ?= $(DESTDIR)$(PREFIX)/share
+MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
 
 TARGETS= \
 booleansPage.py \
-- 
2.15.1




Re: [PATCH v2 02/14] libselinux: build: follow standard semantics for DESTDIR and PREFIX

2018-01-19 Thread Marcus Folkesson
Hi Nicolas!

On Wed, Jan 17, 2018 at 11:12:56PM +0100, Nicolas Iooss wrote:
> On Tue, Jan 16, 2018 at 9:23 PM, Marcus Folkesson
> <marcus.folkes...@gmail.com> wrote:
> > 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.folkes...@gmail.com>
> > ---
> >  libselinux/include/Makefile |  4 ++--
> >  libselinux/man/Makefile |  7 ---
> >  libselinux/src/Makefile | 12 +---
> >  libselinux/src/libselinux.pc.in |  2 +-
> >  libselinux/utils/Makefile   |  6 ++
> >  5 files changed, 14 insertions(+), 17 deletions(-)
> >
> > diff --git a/libselinux/include/Makefile b/libselinux/include/Makefile
> > index 757a6c9c..3b51f5ce 100644
> > --- a/libselinux/include/Makefile
> > +++ b/libselinux/include/Makefile
> > @@ -1,6 +1,6 @@
> >  # Installation directories.
> > -PREFIX ?= $(DESTDIR)/usr
> > -INCDIR ?= $(PREFIX)/include/selinux
> > +PREFIX ?= /usr
> > +INCDIR = $(DESTDIR)$(PREFIX)/include/selinux
> >
> >  all:
> >
> > diff --git a/libselinux/man/Makefile b/libselinux/man/Makefile
> > index 0643e6af..233bfaa9 100644
> > --- a/libselinux/man/Makefile
> > +++ b/libselinux/man/Makefile
> > @@ -1,7 +1,8 @@
> >  # Installation directories.
> > -MAN8DIR ?= $(DESTDIR)/usr/share/man/man8
> > -MAN5DIR ?= $(DESTDIR)/usr/share/man/man5
> > -MAN3DIR ?= $(DESTDIR)/usr/share/man/man3
> > +PREFIX ?= /usr
> > +MAN8DIR ?= $(DESTDIR)$(PREFIX)/share/man/man8
> > +MAN5DIR ?= $(DESTDIR)$(PREFIX)/share/man/man5
> > +MAN3DIR ?= $(DESTDIR)$(PREFIX)/share/man/man3
> >
> >  all:
> >
> > diff --git a/libselinux/src/Makefile b/libselinux/src/Makefile
> > index 18df75c8..18a58164 100644
> > --- a/libselinux/src/Makefile
> > +++ b/libselinux/src/Makefile
> > @@ -8,8 +8,8 @@ RUBYPREFIX ?= $(notdir $(RUBY))
> >  PKG_CONFIG ?= pkg-config
> >
> >  # Installation directories.
> > -PREFIX ?= $(DESTDIR)/usr
> > -LIBDIR ?= $(PREFIX)/lib
> > +PREFIX ?= /usr
> > +LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
> >  SHLIBDIR ?= $(DESTDIR)/lib
> >  INCLUDEDIR ?= $(PREFIX)/include
> >  PYINC ?= $(shell $(PKG_CONFIG) --cflags $(PYPREFIX))
> > @@ -19,8 +19,6 @@ PYCEXT ?= $(shell $(PYTHON) -c 'import imp;print([s for 
> > s,m,t in imp.get_suffixe
> >  RUBYINC ?= $(shell $(RUBY) -e 'puts "-I" + 
> > RbConfig::CONFIG["rubyarchhdrdir"] + " -I" + 
> > RbConfig::CONFIG["rubyhdrdir"]')
> >  RUBYLIBS ?= $(shell $(RUBY) -e 'puts "-L" + RbConfig::CONFIG["libdir"] + " 
> > -L" + RbConfig::CONFIG["archlibdir"] + " " + 
> > RbConfig::CONFIG["LIBRUBYARG_SHARED"]')
> >  RUBYINSTALL ?= $(DESTDIR)$(shell $(RUBY) -e 'puts 
> > RbConfig::CONFIG["vendorarchdir"]')
> > -LIBBASE ?= $(shell basename $(LIBDIR))
> > -LIBSEPOLA ?= $(LIBDIR)/libsepol.a
> >
> >  VERSION = $(shell cat ../VERSION)
> >  LIBVERSION = 1
> > @@ -148,7 +146,7 @@ $(LIBSO): $(LOBJS)
> > ln -sf $@ $(TARGET)
> >
> >  $(LIBPC): $(LIBPC).in ../VERSION
> > -   sed -e 's/@VERSION@/$(VERSION)/; s:@prefix@:$(PREFIX):; 
> > s:@libdir@:$(LIBBASE):; s:@includedir@:$(INCLUDEDIR):; 
> > s:@PCRE_MODULE@:$(PCRE_MODULE):' < $< > $@
> > +   sed -e 's/@VERSION@/$(VERSION)/; s:@prefix@:$(PREFIX):; 
> > s:@libdir@:$(LIBDIR):; s:@includedir@:$(INCLUDEDIR):; 
> > s:@PCRE_MODULE@:$(PCRE_MODULE):' < $< > $@
> >
> >  selinuxswig_python_exception.i: ../include/selinux/selinux.h
> > bash -e exception.sh > $@ || (rm -f $@ ; false)
> > @@ -156,8 +154,8 @@ selinuxswig_python_exception.i: 
> > ../include/selinux/selinux.h
> >  $(AUDIT2WHYLOBJ): audit2why.c
> > $(CC) $(filter-out -Werror, $(CFLAGS)) $(PYINC) -fPIC -DSHARED -c 
> > -o $@ $<
> >
> > -$(AUDIT2WHYSO): $(AUDIT2WHYLOBJ) $(LIBSEPOLA)
> > -   $(CC) $(CFLAGS) $(LDFLAGS) -L. -shared -o $@ $^ -lselinux $(PYLIBS)
> > +$(AUDIT2WHYSO): $(AUDIT2WHYLOBJ)
> > +   $(CC) $(CFLAGS) $(LDFLAGS) -L. -shared -o $@ $^ -lselinux $(PYLIBS) 
> > -l:libsepol.a
> 
> Hello,
> This change makes audit2why.so no longer being rebuilt when libsepol's
> code chang

Re: [PATCH v2 08/14] python: build: follow standard semantics for DESTDIR and PREFIX

2018-01-17 Thread Marcus Folkesson
On Wed, Jan 17, 2018 at 05:38:06PM +0100, Petr Lautrbach wrote:
> On Wed, Jan 17, 2018 at 11:43:58AM +0100, Marcus Folkesson wrote:
> > Hi,
> > 
> > On Wed, Jan 17, 2018 at 11:11:35AM +0100, Petr Lautrbach wrote:
> > > On Tue, Jan 16, 2018 at 09:23:21PM +0100, Marcus Folkesson wrote:
> > > > Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
> > > > ---
> > > >  python/audit2allow/Makefile   | 10 --
> > > >  python/chcat/Makefile |  8 
> > > >  python/semanage/Makefile  | 13 ++---
> > > >  python/sepolgen/src/sepolgen/Makefile |  3 ++-
> > > >  python/sepolicy/Makefile  | 18 +-
> > > >  5 files changed, 25 insertions(+), 27 deletions(-)
> > > > 
> > > > diff --git a/python/audit2allow/Makefile b/python/audit2allow/Makefile
> > > > index 8db8075f..a73c8c68 100644
> > > > --- a/python/audit2allow/Makefile
> > > > +++ b/python/audit2allow/Makefile
> > > > @@ -1,12 +1,10 @@
> > > >  PYTHON ?= python
> > > >  
> > > >  # Installation directories.
> > > > -PREFIX ?= $(DESTDIR)/usr
> > > > -BINDIR ?= $(PREFIX)/bin
> > > > -LIBDIR ?= $(PREFIX)/lib
> > > > -MANDIR ?= $(PREFIX)/share/man
> > > > -LOCALEDIR ?= /usr/share/locale
> > > > -INCLUDEDIR ?= $(PREFIX)/include
> > > > +PREFIX ?= /usr
> > > > +BINDIR ?= $(DESTDIR)$(PREFIX)/bin
> > > > +LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
> > > > +MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
> > > >  LIBSEPOLA ?= $(LIBDIR)/libsepol.a
> > > >  
> > > >  CFLAGS ?= -Werror -Wall -W
> > > > diff --git a/python/chcat/Makefile b/python/chcat/Makefile
> > > > index 0fd12d6d..947734a0 100644
> > > > --- a/python/chcat/Makefile
> > > > +++ b/python/chcat/Makefile
> > > > @@ -1,8 +1,8 @@
> > > >  # Installation directories.
> > > > -PREFIX ?= $(DESTDIR)/usr
> > > > -BINDIR ?= $(PREFIX)/bin
> > > > -MANDIR ?= $(PREFIX)/share/man
> > > > -LOCALEDIR ?= $(PREFIX)/share/locale
> > > > +PREFIX ?= /usr
> > > > +BINDIR ?= $(DESTDIR)$(PREFIX)/bin
> > > > +MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
> > > > +LOCALEDIR ?= $(DESTDIR)$(PREFIX)/share/locale
> > > >  
> > > >  .PHONY: all
> > > >  all: chcat
> > > > diff --git a/python/semanage/Makefile b/python/semanage/Makefile
> > > > index 132162bc..70759087 100644
> > > > --- a/python/semanage/Makefile
> > > > +++ b/python/semanage/Makefile
> > > > @@ -1,13 +1,12 @@
> > > >  PYTHON ?= python
> > > >  
> > > >  # Installation directories.
> > > > -PREFIX ?= $(DESTDIR)/usr
> > > > -LIBDIR ?= $(PREFIX)/lib
> > > > -SBINDIR ?= $(PREFIX)/sbin
> > > > -MANDIR = $(PREFIX)/share/man
> > > > -PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import 
> > > > *; print(get_python_lib(1))")
> > > > -PACKAGEDIR ?= $(DESTDIR)/$(PYTHONLIBDIR)
> > > > -BASHCOMPLETIONDIR ?= $(DESTDIR)/usr/share/bash-completion/completions
> > > > +PREFIX ?= /usr
> > > > +SBINDIR ?= $(DESTDIR)$(PREFIX)/sbin
> > > > +MANDIR = $(DESTDIR)$(PREFIX)/share/man
> > > > +PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import 
> > > > *; print(get_python_lib(prefix='$(PREFIX)'))")
> > > > +PACKAGEDIR ?= $(DESTDIR)$(PYTHONLIBDIR)
> > > > +BASHCOMPLETIONDIR ?= 
> > > > $(DESTDIR)$(PREFIX)/share/bash-completion/completions
> > > >  
> > > >  TARGETS=semanage
> > > >  
> > > > diff --git a/python/sepolgen/src/sepolgen/Makefile 
> > > > b/python/sepolgen/src/sepolgen/Makefile
> > > > index d3aa7715..2121a955 100644
> > > > --- a/python/sepolgen/src/sepolgen/Makefile
> > > > +++ b/python/sepolgen/src/sepolgen/Makefile
> > > > @@ -1,5 +1,6 @@
> > > > +PREFIX ?= /usr
> > > >  PYTHON ?= python
> > > > -PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import 
> > > > *; print(get_python_lib(1))")
> > > > +PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import 
> > > > *; print(get_python_lib(prefix='$(PREFIX)'))")
> > > >  PACKAGEDIR ?= $(DESTDIR)/$(PYTHONL

Re: [PATCH v2 08/14] python: build: follow standard semantics for DESTDIR and PREFIX

2018-01-17 Thread Marcus Folkesson
Hi,

On Wed, Jan 17, 2018 at 11:11:35AM +0100, Petr Lautrbach wrote:
> On Tue, Jan 16, 2018 at 09:23:21PM +0100, Marcus Folkesson wrote:
> > Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
> > ---
> >  python/audit2allow/Makefile   | 10 --
> >  python/chcat/Makefile |  8 
> >  python/semanage/Makefile  | 13 ++---
> >  python/sepolgen/src/sepolgen/Makefile |  3 ++-
> >  python/sepolicy/Makefile  | 18 +-
> >  5 files changed, 25 insertions(+), 27 deletions(-)
> > 
> > diff --git a/python/audit2allow/Makefile b/python/audit2allow/Makefile
> > index 8db8075f..a73c8c68 100644
> > --- a/python/audit2allow/Makefile
> > +++ b/python/audit2allow/Makefile
> > @@ -1,12 +1,10 @@
> >  PYTHON ?= python
> >  
> >  # Installation directories.
> > -PREFIX ?= $(DESTDIR)/usr
> > -BINDIR ?= $(PREFIX)/bin
> > -LIBDIR ?= $(PREFIX)/lib
> > -MANDIR ?= $(PREFIX)/share/man
> > -LOCALEDIR ?= /usr/share/locale
> > -INCLUDEDIR ?= $(PREFIX)/include
> > +PREFIX ?= /usr
> > +BINDIR ?= $(DESTDIR)$(PREFIX)/bin
> > +LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
> > +MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
> >  LIBSEPOLA ?= $(LIBDIR)/libsepol.a
> >  
> >  CFLAGS ?= -Werror -Wall -W
> > diff --git a/python/chcat/Makefile b/python/chcat/Makefile
> > index 0fd12d6d..947734a0 100644
> > --- a/python/chcat/Makefile
> > +++ b/python/chcat/Makefile
> > @@ -1,8 +1,8 @@
> >  # Installation directories.
> > -PREFIX ?= $(DESTDIR)/usr
> > -BINDIR ?= $(PREFIX)/bin
> > -MANDIR ?= $(PREFIX)/share/man
> > -LOCALEDIR ?= $(PREFIX)/share/locale
> > +PREFIX ?= /usr
> > +BINDIR ?= $(DESTDIR)$(PREFIX)/bin
> > +MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
> > +LOCALEDIR ?= $(DESTDIR)$(PREFIX)/share/locale
> >  
> >  .PHONY: all
> >  all: chcat
> > diff --git a/python/semanage/Makefile b/python/semanage/Makefile
> > index 132162bc..70759087 100644
> > --- a/python/semanage/Makefile
> > +++ b/python/semanage/Makefile
> > @@ -1,13 +1,12 @@
> >  PYTHON ?= python
> >  
> >  # Installation directories.
> > -PREFIX ?= $(DESTDIR)/usr
> > -LIBDIR ?= $(PREFIX)/lib
> > -SBINDIR ?= $(PREFIX)/sbin
> > -MANDIR = $(PREFIX)/share/man
> > -PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import *; 
> > print(get_python_lib(1))")
> > -PACKAGEDIR ?= $(DESTDIR)/$(PYTHONLIBDIR)
> > -BASHCOMPLETIONDIR ?= $(DESTDIR)/usr/share/bash-completion/completions
> > +PREFIX ?= /usr
> > +SBINDIR ?= $(DESTDIR)$(PREFIX)/sbin
> > +MANDIR = $(DESTDIR)$(PREFIX)/share/man
> > +PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import *; 
> > print(get_python_lib(prefix='$(PREFIX)'))")
> > +PACKAGEDIR ?= $(DESTDIR)$(PYTHONLIBDIR)
> > +BASHCOMPLETIONDIR ?= $(DESTDIR)$(PREFIX)/share/bash-completion/completions
> >  
> >  TARGETS=semanage
> >  
> > diff --git a/python/sepolgen/src/sepolgen/Makefile 
> > b/python/sepolgen/src/sepolgen/Makefile
> > index d3aa7715..2121a955 100644
> > --- a/python/sepolgen/src/sepolgen/Makefile
> > +++ b/python/sepolgen/src/sepolgen/Makefile
> > @@ -1,5 +1,6 @@
> > +PREFIX ?= /usr
> >  PYTHON ?= python
> > -PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import *; 
> > print(get_python_lib(1))")
> > +PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import *; 
> > print(get_python_lib(prefix='$(PREFIX)'))")
> >  PACKAGEDIR ?= $(DESTDIR)/$(PYTHONLIBDIR)/sepolgen
> >  
> >  all:
> > diff --git a/python/sepolicy/Makefile b/python/sepolicy/Makefile
> > index 5a56e6c8..c528ae43 100644
> > --- a/python/sepolicy/Makefile
> > +++ b/python/sepolicy/Makefile
> > @@ -1,14 +1,14 @@
> >  PYTHON ?= python
> >  
> >  # Installation directories.
> > -PREFIX ?= $(DESTDIR)/usr
> > -LIBDIR ?= $(PREFIX)/lib
> > -BINDIR ?= $(PREFIX)/bin
> > -DATADIR ?= $(PREFIX)/share
> > -MANDIR ?= $(PREFIX)/share/man
> > -LOCALEDIR ?= /usr/share/locale
> > -BASHCOMPLETIONDIR ?= $(DESTDIR)/usr/share/bash-completion/completions
> > -SHAREDIR ?= $(PREFIX)/share/sandbox
> > +PREFIX ?= /usr
> > +LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
> > +BINDIR ?= $(DESTDIR)$(PREFIX)/bin
> > +DATADIR ?= $(DESTDIR)$(PREFIX)/share
> > +MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
> > +LOCALEDIR ?= $(DESTDIR)$(PREFIX)/share/locale
> > +BASHCOMPLETIONDIR ?= $(DESTDIR)$(PREFIX)/share/bash-completion/c

[PATCH v2 07/14] policycoreutils: build: follow standard semantics for DESTDIR and PREFIX

2018-01-16 Thread Marcus Folkesson
Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
---
 policycoreutils/hll/pp/Makefile  |  7 ++-
 policycoreutils/load_policy/Makefile |  8 
 policycoreutils/man/Makefile |  3 ++-
 policycoreutils/newrole/Makefile |  8 
 policycoreutils/po/Makefile  |  3 ++-
 policycoreutils/run_init/Makefile|  8 
 policycoreutils/scripts/Makefile |  8 
 policycoreutils/secon/Makefile   |  9 -
 policycoreutils/semodule/Makefile|  8 +++-
 policycoreutils/sestatus/Makefile|  8 
 policycoreutils/setfiles/Makefile|  5 ++---
 policycoreutils/setsebool/Makefile   | 10 --
 12 files changed, 39 insertions(+), 46 deletions(-)

diff --git a/policycoreutils/hll/pp/Makefile b/policycoreutils/hll/pp/Makefile
index 3401dcc9..ce58e0cf 100644
--- a/policycoreutils/hll/pp/Makefile
+++ b/policycoreutils/hll/pp/Makefile
@@ -1,9 +1,6 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-INCLUDEDIR ?= $(PREFIX)/include
-MANDIR = $(PREFIX)/share/man
-LIBDIR ?= $(PREFIX)/lib
-LIBEXECDIR ?= $(PREFIX)/libexec
+PREFIX ?= /usr
+LIBEXECDIR ?= $(DESTDIR)$(PREFIX)/libexec
 HLLDIR ?= $(LIBEXECDIR)/selinux/hll
 
 CFLAGS ?= -Werror -Wall -W
diff --git a/policycoreutils/load_policy/Makefile 
b/policycoreutils/load_policy/Makefile
index b85833c2..720bf45f 100644
--- a/policycoreutils/load_policy/Makefile
+++ b/policycoreutils/load_policy/Makefile
@@ -1,8 +1,8 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-SBINDIR ?= $(DESTDIR)/sbin
-MANDIR ?= $(PREFIX)/share/man
-LOCALEDIR ?= /usr/share/locale
+PREFIX ?= /usr
+SBINDIR ?= $(DESTDIR)$(PREFIX)/sbin
+MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
+LOCALEDIR ?= $(DESTDIR)$(PREFIX)/share/locale
 
 CFLAGS ?= -Werror -Wall -W
 override CFLAGS += $(LDFLAGS) -DUSE_NLS -DLOCALEDIR="\"$(LOCALEDIR)\"" 
-DPACKAGE="\"policycoreutils\""
diff --git a/policycoreutils/man/Makefile b/policycoreutils/man/Makefile
index 0d91cd46..8a8fbd49 100644
--- a/policycoreutils/man/Makefile
+++ b/policycoreutils/man/Makefile
@@ -1,5 +1,6 @@
 # Installation directories.
-MAN5DIR ?= $(DESTDIR)/usr/share/man/man5
+PREFIX ?= /usr
+MAN5DIR ?= $(DESTDIR)$(PREFIX)/share/man/man5
 
 all:
 
diff --git a/policycoreutils/newrole/Makefile b/policycoreutils/newrole/Makefile
index 196af926..4dbe6f52 100644
--- a/policycoreutils/newrole/Makefile
+++ b/policycoreutils/newrole/Makefile
@@ -1,9 +1,9 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-BINDIR ?= $(PREFIX)/bin
-MANDIR ?= $(PREFIX)/share/man
+PREFIX ?= /usr
+BINDIR ?= $(DESTDIR)$(PREFIX)/bin
+MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
 ETCDIR ?= $(DESTDIR)/etc
-LOCALEDIR = /usr/share/locale
+LOCALEDIR = $(DESTDIR)$(PREFIX)/share/locale
 PAMH ?= $(shell test -f /usr/include/security/pam_appl.h && echo y)
 AUDITH ?= $(shell test -f /usr/include/libaudit.h && echo y)
 # Enable capabilities to permit newrole to generate audit records.
diff --git a/policycoreutils/po/Makefile b/policycoreutils/po/Makefile
index 58148613..c583d23a 100644
--- a/policycoreutils/po/Makefile
+++ b/policycoreutils/po/Makefile
@@ -2,6 +2,7 @@
 # Makefile for the PO files (translation) catalog
 #
 
+PREFIX ?= /usr
 TOP = ../..
 
 # What is this package?
@@ -12,7 +13,7 @@ INSTALL_DATA  = $(INSTALL) -m 644
 INSTALL_DIR= /usr/bin/install -d
 
 # destination directory
-INSTALL_NLS_DIR = $(DESTDIR)/usr/share/locale
+INSTALL_NLS_DIR = $(DESTDIR)$(PREFIX)/share/locale
 
 # PO catalog handling
 MSGMERGE   = msgmerge
diff --git a/policycoreutils/run_init/Makefile 
b/policycoreutils/run_init/Makefile
index 921f0b07..4178493e 100644
--- a/policycoreutils/run_init/Makefile
+++ b/policycoreutils/run_init/Makefile
@@ -1,10 +1,10 @@
 
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-SBINDIR ?= $(PREFIX)/sbin
-MANDIR ?= $(PREFIX)/share/man
+PREFIX ?= /usr
+SBINDIR ?= $(DESTDIR)$(PREFIX)/sbin
+MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
 ETCDIR ?= $(DESTDIR)/etc
-LOCALEDIR ?= /usr/share/locale
+LOCALEDIR ?= $(DESTDIR)$(PREFIX)/share/locale
 PAMH ?= $(shell test -f /usr/include/security/pam_appl.h && echo y)
 AUDITH ?= $(shell test -f /usr/include/libaudit.h && echo y)
 
diff --git a/policycoreutils/scripts/Makefile b/policycoreutils/scripts/Makefile
index d9e86ffe..cfd841ec 100644
--- a/policycoreutils/scripts/Makefile
+++ b/policycoreutils/scripts/Makefile
@@ -1,8 +1,8 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-SBINDIR ?= $(DESTDIR)/sbin
-MANDIR ?= $(PREFIX)/share/man
-LOCALEDIR ?= $(PREFIX)/share/locale
+PREFIX ?= /usr
+SBINDIR ?= $(DESTDIR)$(PREFIX)/sbin
+MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
+LOCALEDIR ?= $(DESTDIR)$(PREFIX)/share/locale
 
 .PHONY: all
 all: fixfiles
diff --git a/policycoreutils/secon/Makefile b/policycoreutils/secon/Makefile
index 8e491d74..4ecbd57d 100644
--- a/policycoreutils/secon/Makefile
+++ b/policycoreutils/secon/Makefile
@@ -1,9 +1,8 @@
 # secon tool - command-l

[PATCH v2 14/14] build: add prefix for includes in top Makefile

2018-01-16 Thread Marcus Folkesson
Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
---
 Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 6da7f7b7..74d662d4 100644
--- a/Makefile
+++ b/Makefile
@@ -19,8 +19,8 @@ else
 endif
 
 ifneq ($(DESTDIR),)
-   CFLAGS += -I$(DESTDIR)/usr/include
-   LDFLAGS += -L$(DESTDIR)/usr/lib
+   CFLAGS += -I$(DESTDIR)$(PREFIX)/include
+   LDFLAGS += -L$(DESTDIR)$(PREFIX)/lib
export CFLAGS
export LDFLAGS
 endif
-- 
2.15.1




[PATCH v2 06/14] mcstrans: build: follow standard semantics for DESTDIR and PREFIX

2018-01-16 Thread Marcus Folkesson
Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
---
 mcstrans/man/Makefile   | 3 ++-
 mcstrans/src/Makefile   | 6 +++---
 mcstrans/utils/Makefile | 6 +++---
 3 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/mcstrans/man/Makefile b/mcstrans/man/Makefile
index 8e971192..5030fa81 100644
--- a/mcstrans/man/Makefile
+++ b/mcstrans/man/Makefile
@@ -1,5 +1,6 @@
 # Installation directories.
-MAN8DIR ?= $(DESTDIR)/usr/share/man/man8
+PREFIX ?= /usr
+MAN8DIR ?= $(DESTDIR)$(PREFIX)/share/man/man8
 
 all:
 
diff --git a/mcstrans/src/Makefile b/mcstrans/src/Makefile
index 3f4a89c3..26423c29 100644
--- a/mcstrans/src/Makefile
+++ b/mcstrans/src/Makefile
@@ -1,9 +1,9 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-LIBDIR ?= $(PREFIX)/lib
+PREFIX ?= /usr
+LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
 SBINDIR ?= $(DESTDIR)/sbin
 INITDIR ?= $(DESTDIR)/etc/rc.d/init.d
-SYSTEMDDIR ?= $(DESTDIR)/usr/lib/systemd
+SYSTEMDDIR ?= $(DESTDIR)$(PREFIX)/lib/systemd
 LIBSEPOLA ?= $(LIBDIR)/libsepol.a
 
 PROG_SRC=mcstrans.c  mcscolor.c  mcstransd.c  mls_level.c
diff --git a/mcstrans/utils/Makefile b/mcstrans/utils/Makefile
index 4d3cbfcb..79eb8438 100644
--- a/mcstrans/utils/Makefile
+++ b/mcstrans/utils/Makefile
@@ -1,7 +1,7 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-LIBDIR ?= $(PREFIX)/lib
-SBINDIR ?= $(PREFIX)/sbin
+PREFIX ?= /usr
+LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
+SBINDIR ?= $(DESTDIR)$(PREFIX)/sbin
 LIBSEPOLA ?= $(LIBDIR)/libsepol.a
 
 CFLAGS ?= -Wall
-- 
2.15.1




[PATCH v2 09/14] restorecond: build: follow standard semantics for DESTDIR and PREFIX

2018-01-16 Thread Marcus Folkesson
Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
---
 restorecond/Makefile | 11 +--
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/restorecond/Makefile b/restorecond/Makefile
index ada94aeb..a2316947 100644
--- a/restorecond/Makefile
+++ b/restorecond/Makefile
@@ -1,13 +1,12 @@
 PKG_CONFIG ?= pkg-config
 
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-SBINDIR ?= $(PREFIX)/sbin
-LIBDIR ?= $(PREFIX)/lib
-MANDIR = $(PREFIX)/share/man
+PREFIX ?= /usr
+SBINDIR ?= $(DESTDIR)$(PREFIX)/sbin
+MANDIR = $(DESTDIR)$(PREFIX)/share/man
 AUTOSTARTDIR = $(DESTDIR)/etc/xdg/autostart
-DBUSSERVICEDIR = $(DESTDIR)/usr/share/dbus-1/services
-SYSTEMDDIR ?= $(DESTDIR)/usr/lib/systemd
+DBUSSERVICEDIR = $(DESTDIR)$(PREFIX)/share/dbus-1/services
+SYSTEMDDIR ?= $(DESTDIR)$(PREFIX)/lib/systemd
 
 autostart_DATA = sealertauto.desktop
 INITDIR ?= $(DESTDIR)/etc/rc.d/init.d
-- 
2.15.1




[PATCH v2 10/14] sandbox: build: follow standard semantics for DESTDIR and PREFIX

2018-01-16 Thread Marcus Folkesson
Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
---
 sandbox/Makefile | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/sandbox/Makefile b/sandbox/Makefile
index 05c3d658..5a6b707a 100644
--- a/sandbox/Makefile
+++ b/sandbox/Makefile
@@ -1,14 +1,14 @@
 PYTHON ?= python
 
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
+PREFIX ?= /usr
 SYSCONFDIR ?= $(DESTDIR)/etc/sysconfig
-LIBDIR ?= $(PREFIX)/lib
-BINDIR ?= $(PREFIX)/bin
-SBINDIR ?= $(PREFIX)/sbin
-MANDIR ?= $(PREFIX)/share/man
+LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
+BINDIR ?= $(DESTDIR)$(PREFIX)/bin
+SBINDIR ?= $(DESTDIR)$(PREFIX)/sbin
+MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
 LOCALEDIR ?= /usr/share/locale
-SHAREDIR ?= $(PREFIX)/share/sandbox
+SHAREDIR ?= $(DESTDIR)$(PREFIX)/share/sandbox
 override CFLAGS += -DPACKAGE="\"policycoreutils\"" -Wall -Werror -Wextra -W
 override LDLIBS += -lselinux -lcap-ng
 SEUNSHARE_OBJS = seunshare.o
-- 
2.15.1




[PATCH v2 11/14] secilc: build: follow standard semantics for DESTDIR and PREFIX

2018-01-16 Thread Marcus Folkesson
Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
---
 secilc/Makefile | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/secilc/Makefile b/secilc/Makefile
index 1cac53e4..5b0a4852 100644
--- a/secilc/Makefile
+++ b/secilc/Makefile
@@ -1,8 +1,6 @@
-PREFIX ?= $(DESTDIR)/usr
-BINDIR ?= $(PREFIX)/bin
-MANDIR ?= $(PREFIX)/share/man
-LIBDIR ?= $(PREFIX)/lib
-INCLUDEDIR ?= $(PREFIX)/include
+PREFIX ?= /usr
+BINDIR ?= $(DESTDIR)$(PREFIX)/bin
+MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
 
 SECILC = secilc
 SECILC_SRCS := secilc.c
-- 
2.15.1




[PATCH v2 12/14] semodule-utils: build: follow standard semantics for DESTDIR and PREFIX

2018-01-16 Thread Marcus Folkesson
Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
---
 semodule-utils/semodule_expand/Makefile  | 8 +++-
 semodule-utils/semodule_link/Makefile| 8 +++-
 semodule-utils/semodule_package/Makefile | 8 +++-
 3 files changed, 9 insertions(+), 15 deletions(-)

diff --git a/semodule-utils/semodule_expand/Makefile 
b/semodule-utils/semodule_expand/Makefile
index 072f2137..c2ab3f65 100644
--- a/semodule-utils/semodule_expand/Makefile
+++ b/semodule-utils/semodule_expand/Makefile
@@ -1,9 +1,7 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-INCLUDEDIR ?= $(PREFIX)/include
-BINDIR ?= $(PREFIX)/bin
-LIBDIR ?= $(PREFIX)/lib
-MANDIR ?= $(PREFIX)/share/man
+PREFIX ?= /usr
+BINDIR ?= $(DESTDIR)$(PREFIX)/bin
+MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
 
 CFLAGS ?= -Werror -Wall -W
 override LDLIBS += -lsepol
diff --git a/semodule-utils/semodule_link/Makefile 
b/semodule-utils/semodule_link/Makefile
index cc4687bd..bcf98765 100644
--- a/semodule-utils/semodule_link/Makefile
+++ b/semodule-utils/semodule_link/Makefile
@@ -1,9 +1,7 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-INCLUDEDIR ?= $(PREFIX)/include
-BINDIR ?= $(PREFIX)/bin
-MANDIR ?= $(PREFIX)/share/man
-LIBDIR ?= $(PREFIX)/lib
+PREFIX ?= /usr
+BINDIR ?= $(DESTDIR)$(PREFIX)/bin
+MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
 
 CFLAGS ?= -Werror -Wall -W
 override LDLIBS += -lsepol
diff --git a/semodule-utils/semodule_package/Makefile 
b/semodule-utils/semodule_package/Makefile
index 96dd7c4f..33a95e16 100644
--- a/semodule-utils/semodule_package/Makefile
+++ b/semodule-utils/semodule_package/Makefile
@@ -1,9 +1,7 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-INCLUDEDIR ?= $(PREFIX)/include
-BINDIR ?= $(PREFIX)/bin
-LIBDIR ?= $(PREFIX)/lib
-MANDIR ?= $(PREFIX)/share/man
+PREFIX ?= /usr
+BINDIR ?= $(DESTDIR)$(PREFIX)/bin
+MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
 
 CFLAGS ?= -Werror -Wall -W
 override LDLIBS += -lsepol
-- 
2.15.1




Rework of Makefiles v2

2018-01-16 Thread Marcus Folkesson
Hi,

I have updated the patchset.

Please test to compile with:
make DESTDIR=/tmp/myroot PREFIX=/myusr install


Changes:
v2:
- Use separate directories for shared libraries as before( Comment from
  Stephen Smalley)
- Rework all packages (not just selinux/sepol/semanage)


Best regards
Marcus Folkesson





[PATCH v2 02/14] libselinux: build: follow standard semantics for DESTDIR and PREFIX

2018-01-16 Thread Marcus Folkesson
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.folkes...@gmail.com>
---
 libselinux/include/Makefile |  4 ++--
 libselinux/man/Makefile |  7 ---
 libselinux/src/Makefile | 12 +---
 libselinux/src/libselinux.pc.in |  2 +-
 libselinux/utils/Makefile   |  6 ++
 5 files changed, 14 insertions(+), 17 deletions(-)

diff --git a/libselinux/include/Makefile b/libselinux/include/Makefile
index 757a6c9c..3b51f5ce 100644
--- a/libselinux/include/Makefile
+++ b/libselinux/include/Makefile
@@ -1,6 +1,6 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-INCDIR ?= $(PREFIX)/include/selinux
+PREFIX ?= /usr
+INCDIR = $(DESTDIR)$(PREFIX)/include/selinux
 
 all:
 
diff --git a/libselinux/man/Makefile b/libselinux/man/Makefile
index 0643e6af..233bfaa9 100644
--- a/libselinux/man/Makefile
+++ b/libselinux/man/Makefile
@@ -1,7 +1,8 @@
 # Installation directories.
-MAN8DIR ?= $(DESTDIR)/usr/share/man/man8
-MAN5DIR ?= $(DESTDIR)/usr/share/man/man5
-MAN3DIR ?= $(DESTDIR)/usr/share/man/man3
+PREFIX ?= /usr
+MAN8DIR ?= $(DESTDIR)$(PREFIX)/share/man/man8
+MAN5DIR ?= $(DESTDIR)$(PREFIX)/share/man/man5
+MAN3DIR ?= $(DESTDIR)$(PREFIX)/share/man/man3
 
 all:
 
diff --git a/libselinux/src/Makefile b/libselinux/src/Makefile
index 18df75c8..18a58164 100644
--- a/libselinux/src/Makefile
+++ b/libselinux/src/Makefile
@@ -8,8 +8,8 @@ RUBYPREFIX ?= $(notdir $(RUBY))
 PKG_CONFIG ?= pkg-config
 
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-LIBDIR ?= $(PREFIX)/lib
+PREFIX ?= /usr
+LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
 SHLIBDIR ?= $(DESTDIR)/lib
 INCLUDEDIR ?= $(PREFIX)/include
 PYINC ?= $(shell $(PKG_CONFIG) --cflags $(PYPREFIX))
@@ -19,8 +19,6 @@ PYCEXT ?= $(shell $(PYTHON) -c 'import imp;print([s for s,m,t 
in imp.get_suffixe
 RUBYINC ?= $(shell $(RUBY) -e 'puts "-I" + RbConfig::CONFIG["rubyarchhdrdir"] 
+ " -I" + RbConfig::CONFIG["rubyhdrdir"]')
 RUBYLIBS ?= $(shell $(RUBY) -e 'puts "-L" + RbConfig::CONFIG["libdir"] + " -L" 
+ RbConfig::CONFIG["archlibdir"] + " " + RbConfig::CONFIG["LIBRUBYARG_SHARED"]')
 RUBYINSTALL ?= $(DESTDIR)$(shell $(RUBY) -e 'puts 
RbConfig::CONFIG["vendorarchdir"]')
-LIBBASE ?= $(shell basename $(LIBDIR))
-LIBSEPOLA ?= $(LIBDIR)/libsepol.a
 
 VERSION = $(shell cat ../VERSION)
 LIBVERSION = 1
@@ -148,7 +146,7 @@ $(LIBSO): $(LOBJS)
ln -sf $@ $(TARGET)
 
 $(LIBPC): $(LIBPC).in ../VERSION
-   sed -e 's/@VERSION@/$(VERSION)/; s:@prefix@:$(PREFIX):; 
s:@libdir@:$(LIBBASE):; s:@includedir@:$(INCLUDEDIR):; 
s:@PCRE_MODULE@:$(PCRE_MODULE):' < $< > $@
+   sed -e 's/@VERSION@/$(VERSION)/; s:@prefix@:$(PREFIX):; 
s:@libdir@:$(LIBDIR):; s:@includedir@:$(INCLUDEDIR):; 
s:@PCRE_MODULE@:$(PCRE_MODULE):' < $< > $@
 
 selinuxswig_python_exception.i: ../include/selinux/selinux.h
bash -e exception.sh > $@ || (rm -f $@ ; false)
@@ -156,8 +154,8 @@ selinuxswig_python_exception.i: ../include/selinux/selinux.h
 $(AUDIT2WHYLOBJ): audit2why.c
$(CC) $(filter-out -Werror, $(CFLAGS)) $(PYINC) -fPIC -DSHARED -c -o $@ 
$<
 
-$(AUDIT2WHYSO): $(AUDIT2WHYLOBJ) $(LIBSEPOLA)
-   $(CC) $(CFLAGS) $(LDFLAGS) -L. -shared -o $@ $^ -lselinux $(PYLIBS)
+$(AUDIT2WHYSO): $(AUDIT2WHYLOBJ)
+   $(CC) $(CFLAGS) $(LDFLAGS) -L. -shared -o $@ $^ -lselinux $(PYLIBS) 
-l:libsepol.a
 
 %.o:  %.c policy.h
$(CC) $(CFLAGS) $(TLSFLAGS) -c -o $@ $<
diff --git a/libselinux/src/libselinux.pc.in b/libselinux/src/libselinux.pc.in
index 2e90a844..7c66b1fa 100644
--- a/libselinux/src/libselinux.pc.in
+++ b/libselinux/src/libselinux.pc.in
@@ -1,6 +1,6 @@
 prefix=@prefix@
 exec_prefix=${prefix}
-libdir=${exec_prefix}/@libdir@
+libdir=@libdir@
 includedir=@includedir@
 
 Name: libselinux
diff --git a/libselinux/utils/Makefile b/libselinux/utils/Makefile
index eb4851a9..9adce6d3 100644
--- a/libselinux/utils/Makefile
+++ b/libselinux/utils/Makefile
@@ -1,8 +1,6 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-LIBDIR ?= $(PREFIX)/lib
-SBINDIR ?= $(PREFIX)/sbin
-INCLUDEDIR ?= $(PREFIX)/include
+PREFIX ?= /usr
+SBINDIR ?= $(DESTDIR)$(PREFIX)/sbin
 
 OS ?= $(shell uname)
 
-- 
2.15.1




[PATCH v2 03/14] libsemanage: build: follow standard semantics for DESTDIR and PREFIX

2018-01-16 Thread Marcus Folkesson
This patch solves the following issues:
- 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.folkes...@gmail.com>
---
 libsemanage/include/Makefile  | 4 ++--
 libsemanage/man/Makefile  | 5 +++--
 libsemanage/src/Makefile  | 9 +++--
 libsemanage/src/libsemanage.pc.in | 2 +-
 libsemanage/tests/Makefile| 3 ---
 libsemanage/utils/Makefile| 4 ++--
 6 files changed, 11 insertions(+), 16 deletions(-)

diff --git a/libsemanage/include/Makefile b/libsemanage/include/Makefile
index b660660e..f4234b9e 100644
--- a/libsemanage/include/Makefile
+++ b/libsemanage/include/Makefile
@@ -1,6 +1,6 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-INCDIR ?= $(PREFIX)/include/semanage
+PREFIX ?= /usr
+INCDIR ?= $(DESTDIR)$(PREFIX)/include/semanage
 
 all:
 
diff --git a/libsemanage/man/Makefile b/libsemanage/man/Makefile
index 852043d4..43c2b3f6 100644
--- a/libsemanage/man/Makefile
+++ b/libsemanage/man/Makefile
@@ -1,6 +1,7 @@
 # Installation directories.
-MAN3DIR ?= $(DESTDIR)/usr/share/man/man3
-MAN5DIR ?= $(DESTDIR)/usr/share/man/man5
+PREFIX ?= /usr
+MAN3DIR ?= $(DESTDIR)$(PREFIX)/share/man/man3
+MAN5DIR ?= $(DESTDIR)$(PREFIX)/share/man/man5
 
 all:
 
diff --git a/libsemanage/src/Makefile b/libsemanage/src/Makefile
index fdb178f5..f66d1b73 100644
--- a/libsemanage/src/Makefile
+++ b/libsemanage/src/Makefile
@@ -8,9 +8,8 @@ RUBYPREFIX ?= $(notdir $(RUBY))
 PKG_CONFIG ?= pkg-config
 
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-LIBDIR ?= $(PREFIX)/lib
-SHLIBDIR ?= $(DESTDIR)/lib
+PREFIX ?= /usr
+LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
 INCLUDEDIR ?= $(PREFIX)/include
 PYINC ?= $(shell $(PKG_CONFIG) --cflags $(PYPREFIX))
 PYLIBS ?= $(shell $(PKG_CONFIG) --libs $(PYPREFIX))
@@ -20,8 +19,6 @@ RUBYINC ?= $(shell $(RUBY) -e 'puts "-I" + 
RbConfig::CONFIG["rubyarchhdrdir"] +
 RUBYLIBS ?= $(shell $(RUBY) -e 'puts "-L" + RbConfig::CONFIG["libdir"] + " -L" 
+ RbConfig::CONFIG["archlibdir"] + " " + RbConfig::CONFIG["LIBRUBYARG_SHARED"]')
 RUBYINSTALL ?= $(DESTDIR)$(shell $(RUBY) -e 'puts 
RbConfig::CONFIG["vendorarchdir"]')
 
-LIBBASE=$(shell basename $(LIBDIR))
-
 DEFAULT_SEMANAGE_CONF_LOCATION=$(DESTDIR)/etc/selinux/semanage.conf
 
 ifeq ($(DEBUG),1)
@@ -95,7 +92,7 @@ $(LIBSO): $(LOBJS)
ln -sf $@ $(TARGET)
 
 $(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):' < $< > $@
 
 semanageswig_python_exception.i: ../include/semanage/semanage.h
bash -e exception.sh > $@ || (rm -f $@ ; false)
diff --git a/libsemanage/src/libsemanage.pc.in 
b/libsemanage/src/libsemanage.pc.in
index d3eaa062..43681ddb 100644
--- a/libsemanage/src/libsemanage.pc.in
+++ b/libsemanage/src/libsemanage.pc.in
@@ -1,6 +1,6 @@
 prefix=@prefix@
 exec_prefix=${prefix}
-libdir=${exec_prefix}/@libdir@
+libdir=@libdir@
 includedir=@includedir@
 
 Name: libsemanage
diff --git a/libsemanage/tests/Makefile b/libsemanage/tests/Makefile
index 2ef8d30d..324766a0 100644
--- a/libsemanage/tests/Makefile
+++ b/libsemanage/tests/Makefile
@@ -1,6 +1,3 @@
-PREFIX ?= $(DESTDIR)/usr
-LIBDIR ?= $(PREFIX)/lib
-
 # Add your test source files here:
 SOURCES = $(sort $(wildcard *.c))
 
diff --git a/libsemanage/utils/Makefile b/libsemanage/utils/Makefile
index 725f0eec..f527ad07 100644
--- a/libsemanage/utils/Makefile
+++ b/libsemanage/utils/Makefile
@@ -1,6 +1,6 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-LIBEXECDIR ?= $(PREFIX)/libexec
+PREFIX ?= /usr
+LIBEXECDIR ?= $(DESTDIR)$(PREFIX)/libexec
 SELINUXEXECDIR ?= $(LIBEXECDIR)/selinux/
 
 all:
-- 
2.15.1




[PATCH v2 05/14] gui: build: follow standard semantics for DESTDIR and PREFIX

2018-01-16 Thread Marcus Folkesson
Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
---
 gui/Makefile | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/gui/Makefile b/gui/Makefile
index cfe47405..5efd17d7 100644
--- a/gui/Makefile
+++ b/gui/Makefile
@@ -1,9 +1,9 @@
 # Installation directories.
-PREFIX ?= ${DESTDIR}/usr
-BINDIR ?= $(PREFIX)/bin
-SHAREDIR ?= $(PREFIX)/share/system-config-selinux
-DATADIR ?= $(PREFIX)/share
-MANDIR ?= $(PREFIX)/share/man
+PREFIX ?= /usr
+BINDIR ?= $(DESTDIR)$(PREFIX)/bin
+SHAREDIR ?= $(DESTDIR)$(PREFIX)/share/system-config-selinux
+DATADIR ?= $(DESTDIR)$(PREFIX)/share
+MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
 
 TARGETS= \
 booleansPage.py \
-- 
2.15.1




[PATCH v2 04/14] checkpolicy: build: follow standard semantics for DESTDIR and PREFIX

2018-01-16 Thread Marcus Folkesson
This patch solves the following issues:
- 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.folkes...@gmail.com>
---
 checkpolicy/Makefile  | 9 -
 checkpolicy/test/Makefile | 7 +++
 2 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/checkpolicy/Makefile b/checkpolicy/Makefile
index 68e11f2a..0c341d02 100644
--- a/checkpolicy/Makefile
+++ b/checkpolicy/Makefile
@@ -1,11 +1,10 @@
 #
 # Makefile for building the checkpolicy program
 #
-PREFIX ?= $(DESTDIR)/usr
-BINDIR ?= $(PREFIX)/bin
-MANDIR ?= $(PREFIX)/share/man
-LIBDIR ?= $(PREFIX)/lib
-INCLUDEDIR ?= $(PREFIX)/include
+PREFIX ?= /usr
+BINDIR ?= $(DESTDIR)$(PREFIX)/bin
+MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
+LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
 LIBSEPOLA ?= $(LIBDIR)/libsepol.a
 TARGETS = checkpolicy checkmodule
 
diff --git a/checkpolicy/test/Makefile b/checkpolicy/test/Makefile
index 59fa4460..8f4393d2 100644
--- a/checkpolicy/test/Makefile
+++ b/checkpolicy/test/Makefile
@@ -1,10 +1,9 @@
 #
 # Makefile for building the dispol program
 #
-PREFIX ?= $(DESTDIR)/usr
-BINDIR ?= $(PREFIX)/bin
-LIBDIR ?= $(PREFIX)/lib
-INCLUDEDIR ?= $(PREFIX)/include
+PREFIX ?= /usr
+BINDIR ?= $(DESTDIR)$(PREFIX)/bin
+LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
 LIBSEPOLA ?= $(LIBDIR)/libsepol.a
 
 CFLAGS ?= -g -Wall -W -Werror -O2 -pipe
-- 
2.15.1




[PATCH v2 08/14] python: build: follow standard semantics for DESTDIR and PREFIX

2018-01-16 Thread Marcus Folkesson
Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
---
 python/audit2allow/Makefile   | 10 --
 python/chcat/Makefile |  8 
 python/semanage/Makefile  | 13 ++---
 python/sepolgen/src/sepolgen/Makefile |  3 ++-
 python/sepolicy/Makefile  | 18 +-
 5 files changed, 25 insertions(+), 27 deletions(-)

diff --git a/python/audit2allow/Makefile b/python/audit2allow/Makefile
index 8db8075f..a73c8c68 100644
--- a/python/audit2allow/Makefile
+++ b/python/audit2allow/Makefile
@@ -1,12 +1,10 @@
 PYTHON ?= python
 
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-BINDIR ?= $(PREFIX)/bin
-LIBDIR ?= $(PREFIX)/lib
-MANDIR ?= $(PREFIX)/share/man
-LOCALEDIR ?= /usr/share/locale
-INCLUDEDIR ?= $(PREFIX)/include
+PREFIX ?= /usr
+BINDIR ?= $(DESTDIR)$(PREFIX)/bin
+LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
+MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
 LIBSEPOLA ?= $(LIBDIR)/libsepol.a
 
 CFLAGS ?= -Werror -Wall -W
diff --git a/python/chcat/Makefile b/python/chcat/Makefile
index 0fd12d6d..947734a0 100644
--- a/python/chcat/Makefile
+++ b/python/chcat/Makefile
@@ -1,8 +1,8 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-BINDIR ?= $(PREFIX)/bin
-MANDIR ?= $(PREFIX)/share/man
-LOCALEDIR ?= $(PREFIX)/share/locale
+PREFIX ?= /usr
+BINDIR ?= $(DESTDIR)$(PREFIX)/bin
+MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
+LOCALEDIR ?= $(DESTDIR)$(PREFIX)/share/locale
 
 .PHONY: all
 all: chcat
diff --git a/python/semanage/Makefile b/python/semanage/Makefile
index 132162bc..70759087 100644
--- a/python/semanage/Makefile
+++ b/python/semanage/Makefile
@@ -1,13 +1,12 @@
 PYTHON ?= python
 
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-LIBDIR ?= $(PREFIX)/lib
-SBINDIR ?= $(PREFIX)/sbin
-MANDIR = $(PREFIX)/share/man
-PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import *; 
print(get_python_lib(1))")
-PACKAGEDIR ?= $(DESTDIR)/$(PYTHONLIBDIR)
-BASHCOMPLETIONDIR ?= $(DESTDIR)/usr/share/bash-completion/completions
+PREFIX ?= /usr
+SBINDIR ?= $(DESTDIR)$(PREFIX)/sbin
+MANDIR = $(DESTDIR)$(PREFIX)/share/man
+PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import *; 
print(get_python_lib(prefix='$(PREFIX)'))")
+PACKAGEDIR ?= $(DESTDIR)$(PYTHONLIBDIR)
+BASHCOMPLETIONDIR ?= $(DESTDIR)$(PREFIX)/share/bash-completion/completions
 
 TARGETS=semanage
 
diff --git a/python/sepolgen/src/sepolgen/Makefile 
b/python/sepolgen/src/sepolgen/Makefile
index d3aa7715..2121a955 100644
--- a/python/sepolgen/src/sepolgen/Makefile
+++ b/python/sepolgen/src/sepolgen/Makefile
@@ -1,5 +1,6 @@
+PREFIX ?= /usr
 PYTHON ?= python
-PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import *; 
print(get_python_lib(1))")
+PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import *; 
print(get_python_lib(prefix='$(PREFIX)'))")
 PACKAGEDIR ?= $(DESTDIR)/$(PYTHONLIBDIR)/sepolgen
 
 all:
diff --git a/python/sepolicy/Makefile b/python/sepolicy/Makefile
index 5a56e6c8..c528ae43 100644
--- a/python/sepolicy/Makefile
+++ b/python/sepolicy/Makefile
@@ -1,14 +1,14 @@
 PYTHON ?= python
 
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-LIBDIR ?= $(PREFIX)/lib
-BINDIR ?= $(PREFIX)/bin
-DATADIR ?= $(PREFIX)/share
-MANDIR ?= $(PREFIX)/share/man
-LOCALEDIR ?= /usr/share/locale
-BASHCOMPLETIONDIR ?= $(DESTDIR)/usr/share/bash-completion/completions
-SHAREDIR ?= $(PREFIX)/share/sandbox
+PREFIX ?= /usr
+LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
+BINDIR ?= $(DESTDIR)$(PREFIX)/bin
+DATADIR ?= $(DESTDIR)$(PREFIX)/share
+MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
+LOCALEDIR ?= $(DESTDIR)$(PREFIX)/share/locale
+BASHCOMPLETIONDIR ?= $(DESTDIR)$(PREFIX)/share/bash-completion/completions
+SHAREDIR ?= $(DESTDIR)$(PREFIX)/share/sandbox
 CFLAGS ?= -Wall -Werror -Wextra -W
 override CFLAGS += -DPACKAGE="policycoreutils" -DSHARED -shared
 
@@ -30,7 +30,7 @@ test:
@$(PYTHON) test_sepolicy.py -v
 
 install:
-   $(PYTHON) setup.py install `test -n "$(DESTDIR)" && echo --root 
$(DESTDIR)`
+   $(PYTHON) setup.py install --prefix=$(PREFIX) `test -n 
"$(DESTDIR)$(PREFIX)" && echo --root $(DESTDIR)$(PREFIX)`
[ -d $(BINDIR) ] || mkdir -p $(BINDIR)
install -m 755 sepolicy.py $(BINDIR)/sepolicy
(cd $(BINDIR); ln -sf sepolicy sepolgen)
-- 
2.15.1




[PATCH v2 01/14] libsepol: build: follow standard semantics for DESTDIR and PREFIX

2018-01-16 Thread Marcus Folkesson
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.folkes...@gmail.com>
---
 README  | 2 +-
 libsepol/include/Makefile   | 4 ++--
 libsepol/man/Makefile   | 5 +++--
 libsepol/src/Makefile   | 7 +++
 libsepol/src/libsepol.pc.in | 2 +-
 libsepol/utils/Makefile | 4 ++--
 6 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/README b/README
index 7fc7b17b..174551a1 100644
--- a/README
+++ b/README
@@ -19,6 +19,6 @@ lacks library functions or other dependencies relied upon by 
your
 distribution.  If it breaks, you get to keep both pieces.
 
 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).
diff --git a/libsepol/include/Makefile b/libsepol/include/Makefile
index 56b7a114..ad5c34a4 100644
--- a/libsepol/include/Makefile
+++ b/libsepol/include/Makefile
@@ -1,6 +1,6 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-INCDIR ?= $(PREFIX)/include/sepol
+PREFIX ?= /usr
+INCDIR = $(DESTDIR)$(PREFIX)/include/sepol
 CILDIR ?= ../cil
 
 all:
diff --git a/libsepol/man/Makefile b/libsepol/man/Makefile
index 11924334..4f3d9fa2 100644
--- a/libsepol/man/Makefile
+++ b/libsepol/man/Makefile
@@ -1,6 +1,7 @@
 # Installation directories.
-MAN8DIR ?= $(DESTDIR)/usr/share/man/man8
-MAN3DIR ?= $(DESTDIR)/usr/share/man/man3
+PREFIX ?= /usr
+MAN8DIR ?= $(DESTDIR)$(PREFIX)/share/man/man8
+MAN3DIR ?= $(DESTDIR)$(PREFIX)/share/man/man3
 
 all:
 
diff --git a/libsepol/src/Makefile b/libsepol/src/Makefile
index 819d261b..d158398f 100644
--- a/libsepol/src/Makefile
+++ b/libsepol/src/Makefile
@@ -1,10 +1,9 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
+PREFIX ?= /usr
 INCLUDEDIR ?= $(PREFIX)/include
-LIBDIR ?= $(PREFIX)/lib
+LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
 SHLIBDIR ?= $(DESTDIR)/lib
 RANLIB ?= ranlib
-LIBBASE ?= $(shell basename $(LIBDIR))
 CILDIR ?= ../cil
 
 VERSION = $(shell cat ../VERSION)
@@ -52,7 +51,7 @@ $(LIBSO): $(LOBJS) $(LIBMAP)
ln -sf $@ $(TARGET) 
 
 $(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
 ifneq ($(DISABLE_CIL),y)
diff --git a/libsepol/src/libsepol.pc.in b/libsepol/src/libsepol.pc.in
index e52f5892..f807fec6 100644
--- a/libsepol/src/libsepol.pc.in
+++ b/libsepol/src/libsepol.pc.in
@@ -1,6 +1,6 @@
 prefix=@prefix@
 exec_prefix=${prefix}
-libdir=${exec_prefix}/@libdir@
+libdir=@libdir@
 includedir=@includedir@
 
 Name: libsepol
diff --git a/libsepol/utils/Makefile b/libsepol/utils/Makefile
index fba1d8a0..8ce4bf47 100644
--- a/libsepol/utils/Makefile
+++ b/libsepol/utils/Makefile
@@ -1,6 +1,6 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-BINDIR ?= $(PREFIX)/bin
+PREFIX ?= /usr
+BINDIR ?= $(DESTDIR)$(PREFIX)/bin
 
 CFLAGS ?= -Wall -Werror
 override CFLAGS += -I../include
-- 
2.15.1




[PATCH 1/3] libsepol: build: follow standard semantics for DESTDIR and PREFIX

2018-01-12 Thread Marcus Folkesson
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.folkes...@gmail.com>
---
 README  |  2 +-
 libsepol/include/Makefile   |  4 ++--
 libsepol/man/Makefile   |  5 +++--
 libsepol/src/Makefile   | 23 +++
 libsepol/src/libsepol.pc.in |  2 +-
 libsepol/utils/Makefile |  4 ++--
 6 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/README b/README
index 7fc7b17b..174551a1 100644
--- a/README
+++ b/README
@@ -19,6 +19,6 @@ lacks library functions or other dependencies relied upon by 
your
 distribution.  If it breaks, you get to keep both pieces.
 
 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).
diff --git a/libsepol/include/Makefile b/libsepol/include/Makefile
index 56b7a114..ad5c34a4 100644
--- a/libsepol/include/Makefile
+++ b/libsepol/include/Makefile
@@ -1,6 +1,6 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-INCDIR ?= $(PREFIX)/include/sepol
+PREFIX ?= /usr
+INCDIR = $(DESTDIR)$(PREFIX)/include/sepol
 CILDIR ?= ../cil
 
 all:
diff --git a/libsepol/man/Makefile b/libsepol/man/Makefile
index 11924334..4f3d9fa2 100644
--- a/libsepol/man/Makefile
+++ b/libsepol/man/Makefile
@@ -1,6 +1,7 @@
 # Installation directories.
-MAN8DIR ?= $(DESTDIR)/usr/share/man/man8
-MAN3DIR ?= $(DESTDIR)/usr/share/man/man3
+PREFIX ?= /usr
+MAN8DIR ?= $(DESTDIR)$(PREFIX)/share/man/man8
+MAN3DIR ?= $(DESTDIR)$(PREFIX)/share/man/man3
 
 all:
 
diff --git a/libsepol/src/Makefile b/libsepol/src/Makefile
index 819d261b..35b7829d 100644
--- a/libsepol/src/Makefile
+++ b/libsepol/src/Makefile
@@ -1,11 +1,10 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
+PREFIX ?= /usr
 INCLUDEDIR ?= $(PREFIX)/include
 LIBDIR ?= $(PREFIX)/lib
-SHLIBDIR ?= $(DESTDIR)/lib
 RANLIB ?= ranlib
-LIBBASE ?= $(shell basename $(LIBDIR))
 CILDIR ?= ../cil
+LIBINSTALL = $(DESTDIR)$(LIBDIR)
 
 VERSION = $(shell cat ../VERSION)
 LIBVERSION = 1
@@ -52,7 +51,7 @@ $(LIBSO): $(LOBJS) $(LIBMAP)
ln -sf $@ $(TARGET) 
 
 $(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
 ifneq ($(DISABLE_CIL),y)
@@ -80,16 +79,16 @@ endif
$(CC) $(CFLAGS) -fPIC -DSHARED -c -o $@ $<
 
 install: all
-   test -d $(LIBDIR) || install -m 755 -d $(LIBDIR)
-   install -m 644 $(LIBA) $(LIBDIR)
-   test -d $(SHLIBDIR) || install -m 755 -d $(SHLIBDIR)
-   install -m 755 $(LIBSO) $(SHLIBDIR)
-   test -d $(LIBDIR)/pkgconfig || install -m 755 -d $(LIBDIR)/pkgconfig
-   install -m 644 $(LIBPC) $(LIBDIR)/pkgconfig
-   $(LN) -sf --relative $(SHLIBDIR)/$(LIBSO) $(LIBDIR)/$(TARGET)
+   test -d $(LIBINSTALL) || install -m 755 -d $(LIBINSTALL)
+   install -m 644 $(LIBA) $(LIBINSTALL)
+   test -d $(LIBINSTALL) || install -m 755 -d $(LIBINSTALL)
+   install -m 755 $(LIBSO) $(LIBINSTALL)
+   test -d $(LIBINSTALL)/pkgconfig || install -m 755 -d 
$(LIBINSTALL)/pkgconfig
+   install -m 644 $(LIBPC) $(LIBINSTALL)/pkgconfig
+   $(LN) -sf --relative $(LIBINSTALL)/$(LIBSO) $(LIBINSTALL)/$(TARGET)
 
 relabel:
-   /sbin/restorecon $(SHLIBDIR)/$(LIBSO)
+   /sbin/restorecon $(LIBINSTALL)/$(LIBSO)
 
 clean: 
-rm -f $(LIBPC) $(LIBMAP) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(TARGET) 
$(CIL_GENERATED)
diff --git a/libsepol/src/libsepol.pc.in b/libsepol/src/libsepol.pc.in
index e52f5892..f807fec6 100644
--- a/libsepol/src/libsepol.pc.in
+++ b/libsepol/src/libsepol.pc.in
@@ -1,6 +1,6 @@
 prefix=@prefix@
 exec_prefix=${prefix}
-libdir=${exec_prefix}/@libdir@
+libdir=@libdir@
 includedir=@includedir@
 
 Name: libsepol
diff --git a/libsepol/utils/Makefile b/libsepol/utils/Makefile
index fba1d8a0..8ce4bf47 100644
--- a/libsepol/utils/Makefile
+++ b/libsepol/utils/Makefile
@@ -1,6 +1,6 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-BINDIR ?= $(PREFIX)/bin
+PREFIX ?= /usr
+BINDIR ?= $(DESTDIR)$(PREFIX)/bin
 
 CFLAGS ?= -Wall -Werror
 override CFLAGS += -I../include
-- 
2.15.1




[PATCH 3/3] libsemanage: build: follow standard semantics for DESTDIR and PREFIX

2018-01-12 Thread Marcus Folkesson
This patch solves the following issues:
- 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.folkes...@gmail.com>
---
 libsemanage/include/Makefile  |  4 ++--
 libsemanage/man/Makefile  |  5 +++--
 libsemanage/src/Makefile  | 22 ++
 libsemanage/src/libsemanage.pc.in |  2 +-
 libsemanage/tests/Makefile|  3 ---
 5 files changed, 16 insertions(+), 20 deletions(-)

diff --git a/libsemanage/include/Makefile b/libsemanage/include/Makefile
index b660660e..f4234b9e 100644
--- a/libsemanage/include/Makefile
+++ b/libsemanage/include/Makefile
@@ -1,6 +1,6 @@
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
-INCDIR ?= $(PREFIX)/include/semanage
+PREFIX ?= /usr
+INCDIR ?= $(DESTDIR)$(PREFIX)/include/semanage
 
 all:
 
diff --git a/libsemanage/man/Makefile b/libsemanage/man/Makefile
index 852043d4..43c2b3f6 100644
--- a/libsemanage/man/Makefile
+++ b/libsemanage/man/Makefile
@@ -1,6 +1,7 @@
 # Installation directories.
-MAN3DIR ?= $(DESTDIR)/usr/share/man/man3
-MAN5DIR ?= $(DESTDIR)/usr/share/man/man5
+PREFIX ?= /usr
+MAN3DIR ?= $(DESTDIR)$(PREFIX)/share/man/man3
+MAN5DIR ?= $(DESTDIR)$(PREFIX)/share/man/man5
 
 all:
 
diff --git a/libsemanage/src/Makefile b/libsemanage/src/Makefile
index fdb178f5..e47518ba 100644
--- a/libsemanage/src/Makefile
+++ b/libsemanage/src/Makefile
@@ -8,10 +8,10 @@ RUBYPREFIX ?= $(notdir $(RUBY))
 PKG_CONFIG ?= pkg-config
 
 # Installation directories.
-PREFIX ?= $(DESTDIR)/usr
+PREFIX ?= /usr
 LIBDIR ?= $(PREFIX)/lib
-SHLIBDIR ?= $(DESTDIR)/lib
 INCLUDEDIR ?= $(PREFIX)/include
+LIBINSTALL = $(DESTDIR)$(LIBDIR)
 PYINC ?= $(shell $(PKG_CONFIG) --cflags $(PYPREFIX))
 PYLIBS ?= $(shell $(PKG_CONFIG) --libs $(PYPREFIX))
 PYSITEDIR ?= $(DESTDIR)$(shell $(PYTHON) -c 'import site; 
print(site.getsitepackages()[0])')
@@ -20,8 +20,6 @@ RUBYINC ?= $(shell $(RUBY) -e 'puts "-I" + 
RbConfig::CONFIG["rubyarchhdrdir"] +
 RUBYLIBS ?= $(shell $(RUBY) -e 'puts "-L" + RbConfig::CONFIG["libdir"] + " -L" 
+ RbConfig::CONFIG["archlibdir"] + " " + RbConfig::CONFIG["LIBRUBYARG_SHARED"]')
 RUBYINSTALL ?= $(DESTDIR)$(shell $(RUBY) -e 'puts 
RbConfig::CONFIG["vendorarchdir"]')
 
-LIBBASE=$(shell basename $(LIBDIR))
-
 DEFAULT_SEMANAGE_CONF_LOCATION=$(DESTDIR)/etc/selinux/semanage.conf
 
 ifeq ($(DEBUG),1)
@@ -95,7 +93,7 @@ $(LIBSO): $(LOBJS)
ln -sf $@ $(TARGET)
 
 $(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):' < $< > $@
 
 semanageswig_python_exception.i: ../include/semanage/semanage.h
bash -e exception.sh > $@ || (rm -f $@ ; false)
@@ -136,13 +134,13 @@ swigify: $(SWIGIF)
$(SWIG) $<
 
 install: all 
-   test -d $(LIBDIR) || install -m 755 -d $(LIBDIR)
-   install -m 644 $(LIBA) $(LIBDIR)
-   install -m 755 $(LIBSO) $(LIBDIR)
-   test -d $(LIBDIR)/pkgconfig || install -m 755 -d $(LIBDIR)/pkgconfig
-   install -m 644 $(LIBPC) $(LIBDIR)/pkgconfig
+   test -d $(LIBINSTALL) || install -m 755 -d $(LIBINSTALL)
+   install -m 644 $(LIBA) $(LIBINSTALL)
+   install -m 755 $(LIBSO) $(LIBINSTALL)
+   test -d $(LIBINSTALL)/pkgconfig || install -m 755 -d 
$(LIBINSTALL)/pkgconfig
+   install -m 644 $(LIBPC) $(LIBINSTALL)/pkgconfig
test -f $(DEFAULT_SEMANAGE_CONF_LOCATION) || install -m 644 -D 
semanage.conf $(DEFAULT_SEMANAGE_CONF_LOCATION)
-   cd $(LIBDIR) && ln -sf $(LIBSO) $(TARGET)
+   cd $(LIBINSTALL) && ln -sf $(LIBSO) $(TARGET)
 
 install-pywrap: pywrap 
test -d $(PYSITEDIR) || install -m 755 -d $(PYSITEDIR)
@@ -155,7 +153,7 @@ install-rubywrap: rubywrap
install -m 755 $(SWIGRUBYSO) $(RUBYINSTALL)/semanage.so
 
 relabel:
-   /sbin/restorecon $(LIBDIR)/$(LIBSO)
+   /sbin/restorecon $(LIBINSTALL)/$(LIBSO)
 
 clean: 
-rm -f $(LIBPC) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(SWIGLOBJ) $(SWIGSO) 
$(SWIGRUBYSO) $(TARGET) conf-parse.c conf-parse.h conf-scan.c *.o *.lo *~
diff --git a/libsemanage/src/libsemanage.pc.in 
b/libsemanage/src/libsemanage.pc.in
index d3eaa062..43681ddb 100644
--- a/libsemanage/src/libsemanage.pc.in
+++ b/libsemanage/src/libsemanage.pc.in
@@ -1,6 +1,6 @@
 prefix=@prefix@
 exec_prefix=${prefix}
-libdir=${exec_prefix}/@libdir@
+libdir=@libdir@
 includedir=@includedir@
 
 Name: libsemanage
diff --git a/libsemanage/tests/Makefile b/libsemanage/tests/Makefile
index 2ef8d30d..324766a0 100644
--- a/libsemanage/tests/Makefile
+++ b/libsemanage/tests/Makefile
@@ -1,6 +1,3 @@
-PREFIX ?= $(DESTDIR)/usr
-LIBDIR ?= $(PREFIX)/lib
-
 # Add your test source files here:
 SOURCES = $(sort $(wildcard *.c))
 
-- 
2.15.1




Rework of Makefiles

2018-01-12 Thread Marcus Folkesson
I have reworked the Makefiles a bit to make it more compatible with
the standard semantics for DESTDIR and PREFIX.

What made me look at this was a package I was working on in 
Buildroot[1] that was using the pkg-config file generated
from libselinux. The pkg-config file generated has bogus paths 
which results in that my package did not compile.

When looking further in our packages for libselinux/libsepol/libsemanage,
we allready do "tricks" to make it compile.
For example, we set DESTDIR during compilation to compute library and header 
paths.

DESTDIR should be supported only in the install* and uninstall* targets,
as those are the only targets where it is useful. [2]

PREFIX should be used to set a prefix for the installation.
This could be provided both in compile and install stages.


For example, consider the following line:
#make DESTDIR=/tmp/selinux install

It will generate a libselinux.pc file that looks like this:

prefix=/tmp/selinux/usr
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=/tmp/selinux/usr/include

The DESTDIR should not be part of the prefix. The correct output should be:

prefix=/usr
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=/usr/include

The following example do not compile at all:
#make DESTDIR=/tmp/myroot PREFIX=/selinux install

In this case, everything should be installed under /tmp/myroot/selinux.
The prefix in all generated pkg-files should have the path /selinux/x ( not 
/tmp/myroot/selinux/).

This patchsets tries to solve 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

However, DESTDIR is still needed in the "root" Makefile to make libsemanage to 
compile.
But all components (libselinux, libsepol and libsemanage) can be compiled 
separatly with
standard usage of DESTDIR and PREFIX.

Thanks,

Best regards
Marcus Folkesson

[1] https://buildroot.org/
[2] https://www.gnu.org/prep/standards/html_node/DESTDIR.html





Re: [PATCH v2] libselinux: introduce PCPREFIX substitute variable for .pc files

2018-01-08 Thread Marcus Folkesson
Hi,

On Sun, Jan 07, 2018 at 09:38:58PM +0100, Nicolas Iooss wrote:
> On Wed, Jan 3, 2018 at 10:13 PM, Marcus Folkesson
> <marcus.folkes...@gmail.com> wrote:
> > `prefix` in the .pc file may be messed up when using a buildsystem
> > that has specified a sysroot as DESTDIR.
> > We need to make it possible to override the default `libdir`
> > and `includedir`.
> >
> > `includedir` may be overridden by `INCLUDEDIR` but `libdir` is using
> > `PREFIX` to setup the path.
> >
> > Therefore, introduce PCPREFIX to make it possible to generate a more
> > customized .pc file.
> >
> > Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
> 
> Looks good to me. This patch does not seem to break the existing usage
> and adds more flexibility for packagers. By the way, I was worried by
> the modification on INCLUDEDIR, but as this variable is only used to
> generate pkg-config files, it is reasonable to use PCPREFIX instead of
> PREFIX in its definition.
> 
> Acked-by: Nicolas Iooss <nicolas.io...@m4x.org>


Thank you for your review Nicolas.

I'm currently reworking the Makefiles again.
After more digging I have came to the conclusion that the main problem
is that the Makefiles does not follow the standard semantic of DESTDIR
and PREFIX.
I will try to fix this.

I suggest that we drop this patch and wait for my new patchsets.

Thank you

Best regards
Marcus Folkesson






[PATCH v2] libselinux: introduce PCPREFIX substitute variable for .pc files

2018-01-03 Thread Marcus Folkesson
`prefix` in the .pc file may be messed up when using a buildsystem
that has specified a sysroot as DESTDIR.
We need to make it possible to override the default `libdir`
and `includedir`.

`includedir` may be overridden by `INCLUDEDIR` but `libdir` is using
`PREFIX` to setup the path.

Therefore, introduce PCPREFIX to make it possible to generate a more
customized .pc file.

Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
---

v2:
- Reword commit message to be easier to understand...

 libselinux/src/Makefile  | 5 +++--
 libsemanage/src/Makefile | 5 +++--
 libsepol/src/Makefile| 5 +++--
 3 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/libselinux/src/Makefile b/libselinux/src/Makefile
index 18df75c8..baa2ba0f 100644
--- a/libselinux/src/Makefile
+++ b/libselinux/src/Makefile
@@ -9,9 +9,10 @@ PKG_CONFIG ?= pkg-config
 
 # Installation directories.
 PREFIX ?= $(DESTDIR)/usr
+PCPREFIX ?= $(PREFIX)
 LIBDIR ?= $(PREFIX)/lib
 SHLIBDIR ?= $(DESTDIR)/lib
-INCLUDEDIR ?= $(PREFIX)/include
+INCLUDEDIR ?= $(PCPREFIX)/include
 PYINC ?= $(shell $(PKG_CONFIG) --cflags $(PYPREFIX))
 PYLIBS ?= $(shell $(PKG_CONFIG) --libs $(PYPREFIX))
 PYSITEDIR ?= $(DESTDIR)$(shell $(PYTHON) -c 'import site; 
print(site.getsitepackages()[0])')
@@ -148,7 +149,7 @@ $(LIBSO): $(LOBJS)
ln -sf $@ $(TARGET)
 
 $(LIBPC): $(LIBPC).in ../VERSION
-   sed -e 's/@VERSION@/$(VERSION)/; s:@prefix@:$(PREFIX):; 
s:@libdir@:$(LIBBASE):; s:@includedir@:$(INCLUDEDIR):; 
s:@PCRE_MODULE@:$(PCRE_MODULE):' < $< > $@
+   sed -e 's/@VERSION@/$(VERSION)/; s:@prefix@:$(PCPREFIX):; 
s:@libdir@:$(LIBBASE):; s:@includedir@:$(INCLUDEDIR):; 
s:@PCRE_MODULE@:$(PCRE_MODULE):' < $< > $@
 
 selinuxswig_python_exception.i: ../include/selinux/selinux.h
bash -e exception.sh > $@ || (rm -f $@ ; false)
diff --git a/libsemanage/src/Makefile b/libsemanage/src/Makefile
index fdb178f5..8fe2f6dd 100644
--- a/libsemanage/src/Makefile
+++ b/libsemanage/src/Makefile
@@ -9,9 +9,10 @@ PKG_CONFIG ?= pkg-config
 
 # Installation directories.
 PREFIX ?= $(DESTDIR)/usr
+PCPREFIX ?= $(PREFIX)
 LIBDIR ?= $(PREFIX)/lib
 SHLIBDIR ?= $(DESTDIR)/lib
-INCLUDEDIR ?= $(PREFIX)/include
+INCLUDEDIR ?= $(PCPREFIX)/include
 PYINC ?= $(shell $(PKG_CONFIG) --cflags $(PYPREFIX))
 PYLIBS ?= $(shell $(PKG_CONFIG) --libs $(PYPREFIX))
 PYSITEDIR ?= $(DESTDIR)$(shell $(PYTHON) -c 'import site; 
print(site.getsitepackages()[0])')
@@ -95,7 +96,7 @@ $(LIBSO): $(LOBJS)
ln -sf $@ $(TARGET)
 
 $(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@:$(PCPREFIX):; 
s:@libdir@:$(LIBBASE):; s:@includedir@:$(INCLUDEDIR):' < $< > $@
 
 semanageswig_python_exception.i: ../include/semanage/semanage.h
bash -e exception.sh > $@ || (rm -f $@ ; false)
diff --git a/libsepol/src/Makefile b/libsepol/src/Makefile
index 819d261b..59c287aa 100644
--- a/libsepol/src/Makefile
+++ b/libsepol/src/Makefile
@@ -1,6 +1,7 @@
 # Installation directories.
 PREFIX ?= $(DESTDIR)/usr
-INCLUDEDIR ?= $(PREFIX)/include
+PCPREFIX ?= $(PREFIX)
+INCLUDEDIR ?= $(PCPREFIX)/include
 LIBDIR ?= $(PREFIX)/lib
 SHLIBDIR ?= $(DESTDIR)/lib
 RANLIB ?= ranlib
@@ -52,7 +53,7 @@ $(LIBSO): $(LOBJS) $(LIBMAP)
ln -sf $@ $(TARGET) 
 
 $(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@:$(PCPREFIX):; 
s:@libdir@:$(LIBBASE):; s:@includedir@:$(INCLUDEDIR):' < $< > $@
 
 $(LIBMAP): $(LIBMAP).in
 ifneq ($(DISABLE_CIL),y)
-- 
2.15.1




[PATCH] libselinux: introduce PCPREFIX substitute variables for .pc files

2018-01-03 Thread Marcus Folkesson
Some environments (e.g. Buildroot [1] ) when using specified sysroot does
not expect `prefix` (or `exec_prefix`) to be an absolute paths including
sysroot directory.

`includedir` may be overridden by `INCLUDEDIR` but `libdir` is using
`PREFIX` that is used in other places than .pc-files.

Therefor, introduce PCPREFIX to make it possible to generate a more
customized .pc file.

[1] https://buildroot.org/

Signed-off-by: Marcus Folkesson <marcus.folkes...@gmail.com>
---
 libselinux/src/Makefile  | 5 +++--
 libsemanage/src/Makefile | 5 +++--
 libsepol/src/Makefile| 5 +++--
 3 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/libselinux/src/Makefile b/libselinux/src/Makefile
index 18df75c8..baa2ba0f 100644
--- a/libselinux/src/Makefile
+++ b/libselinux/src/Makefile
@@ -9,9 +9,10 @@ PKG_CONFIG ?= pkg-config
 
 # Installation directories.
 PREFIX ?= $(DESTDIR)/usr
+PCPREFIX ?= $(PREFIX)
 LIBDIR ?= $(PREFIX)/lib
 SHLIBDIR ?= $(DESTDIR)/lib
-INCLUDEDIR ?= $(PREFIX)/include
+INCLUDEDIR ?= $(PCPREFIX)/include
 PYINC ?= $(shell $(PKG_CONFIG) --cflags $(PYPREFIX))
 PYLIBS ?= $(shell $(PKG_CONFIG) --libs $(PYPREFIX))
 PYSITEDIR ?= $(DESTDIR)$(shell $(PYTHON) -c 'import site; 
print(site.getsitepackages()[0])')
@@ -148,7 +149,7 @@ $(LIBSO): $(LOBJS)
ln -sf $@ $(TARGET)
 
 $(LIBPC): $(LIBPC).in ../VERSION
-   sed -e 's/@VERSION@/$(VERSION)/; s:@prefix@:$(PREFIX):; 
s:@libdir@:$(LIBBASE):; s:@includedir@:$(INCLUDEDIR):; 
s:@PCRE_MODULE@:$(PCRE_MODULE):' < $< > $@
+   sed -e 's/@VERSION@/$(VERSION)/; s:@prefix@:$(PCPREFIX):; 
s:@libdir@:$(LIBBASE):; s:@includedir@:$(INCLUDEDIR):; 
s:@PCRE_MODULE@:$(PCRE_MODULE):' < $< > $@
 
 selinuxswig_python_exception.i: ../include/selinux/selinux.h
bash -e exception.sh > $@ || (rm -f $@ ; false)
diff --git a/libsemanage/src/Makefile b/libsemanage/src/Makefile
index fdb178f5..8fe2f6dd 100644
--- a/libsemanage/src/Makefile
+++ b/libsemanage/src/Makefile
@@ -9,9 +9,10 @@ PKG_CONFIG ?= pkg-config
 
 # Installation directories.
 PREFIX ?= $(DESTDIR)/usr
+PCPREFIX ?= $(PREFIX)
 LIBDIR ?= $(PREFIX)/lib
 SHLIBDIR ?= $(DESTDIR)/lib
-INCLUDEDIR ?= $(PREFIX)/include
+INCLUDEDIR ?= $(PCPREFIX)/include
 PYINC ?= $(shell $(PKG_CONFIG) --cflags $(PYPREFIX))
 PYLIBS ?= $(shell $(PKG_CONFIG) --libs $(PYPREFIX))
 PYSITEDIR ?= $(DESTDIR)$(shell $(PYTHON) -c 'import site; 
print(site.getsitepackages()[0])')
@@ -95,7 +96,7 @@ $(LIBSO): $(LOBJS)
ln -sf $@ $(TARGET)
 
 $(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@:$(PCPREFIX):; 
s:@libdir@:$(LIBBASE):; s:@includedir@:$(INCLUDEDIR):' < $< > $@
 
 semanageswig_python_exception.i: ../include/semanage/semanage.h
bash -e exception.sh > $@ || (rm -f $@ ; false)
diff --git a/libsepol/src/Makefile b/libsepol/src/Makefile
index 819d261b..59c287aa 100644
--- a/libsepol/src/Makefile
+++ b/libsepol/src/Makefile
@@ -1,6 +1,7 @@
 # Installation directories.
 PREFIX ?= $(DESTDIR)/usr
-INCLUDEDIR ?= $(PREFIX)/include
+PCPREFIX ?= $(PREFIX)
+INCLUDEDIR ?= $(PCPREFIX)/include
 LIBDIR ?= $(PREFIX)/lib
 SHLIBDIR ?= $(DESTDIR)/lib
 RANLIB ?= ranlib
@@ -52,7 +53,7 @@ $(LIBSO): $(LOBJS) $(LIBMAP)
ln -sf $@ $(TARGET) 
 
 $(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@:$(PCPREFIX):; 
s:@libdir@:$(LIBBASE):; s:@includedir@:$(INCLUDEDIR):' < $< > $@
 
 $(LIBMAP): $(LIBMAP).in
 ifneq ($(DISABLE_CIL),y)
-- 
2.15.1