libselinux: upgraded package to upstream

Upgraded sys-libs/libselinux to version 2.4 on amd64
(actually adding rather than upgrading)

BUG=b:25408463
TEST=emerge

Change-Id: Iadad198a254ee3d82d189c598f4c8f08056ccadc
Reviewed-on: https://chromium-review.googlesource.com/324793
Commit-Ready: Ricky Zhou <rickyz@chromium.org>
Tested-by: Luigi Semenzato <semenzato@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
diff --git a/metadata/md5-cache/sys-libs/libselinux-2.4 b/metadata/md5-cache/sys-libs/libselinux-2.4
new file mode 100644
index 0000000..3154025
--- /dev/null
+++ b/metadata/md5-cache/sys-libs/libselinux-2.4
@@ -0,0 +1,13 @@
+DEFINED_PHASES=compile configure install postinst prepare test
+DEPEND=>=sys-libs/libsepol-2.4[abi_x86_32(-)?,abi_x86_64(-)?,abi_x86_x32(-)?,abi_mips_n32(-)?,abi_mips_n64(-)?,abi_mips_o32(-)?,abi_ppc_32(-)?,abi_ppc_64(-)?,abi_s390_32(-)?,abi_s390_64(-)?] >=dev-libs/libpcre-8.33-r1[static-libs?,abi_x86_32(-)?,abi_x86_64(-)?,abi_x86_x32(-)?,abi_mips_n32(-)?,abi_mips_n64(-)?,abi_mips_o32(-)?,abi_ppc_32(-)?,abi_ppc_64(-)?,abi_s390_32(-)?,abi_s390_64(-)?] python? ( python_targets_python2_7? ( >=dev-lang/python-2.7.3-r2:2.7 ) python_targets_python3_3? ( >=dev-lang/python-3.3.2-r2:3.3 ) python_targets_python3_4? ( dev-lang/python:3.4 ) python_targets_python3_5? ( dev-lang/python:3.5 ) >=dev-lang/python-exec-2:=[python_targets_python2_7(-)?,python_targets_python3_3(-)?,python_targets_python3_4(-)?,python_targets_python3_5(-)?,-python_single_target_python2_7(-),-python_single_target_python3_3(-),-python_single_target_python3_4(-),-python_single_target_python3_5(-)] ) ruby? ( ruby_targets_ruby19? ( dev-lang/ruby:1.9 ) ruby_targets_ruby20? ( dev-lang/ruby:2.0 ) ) virtual/pkgconfig python? ( >=dev-lang/swig-2.0.9 )
+DESCRIPTION=SELinux userland library
+EAPI=5
+HOMEPAGE=https://github.com/SELinuxProject/selinux/wiki
+IUSE=python ruby static-libs ruby_targets_ruby19 ruby_targets_ruby20 python_targets_python2_7 python_targets_python3_3 python_targets_python3_4 python_targets_python3_5 abi_x86_32 abi_x86_64 abi_x86_x32 abi_mips_n32 abi_mips_n64 abi_mips_o32 abi_ppc_32 abi_ppc_64 abi_s390_32 abi_s390_64
+KEYWORDS=*
+LICENSE=public-domain
+RDEPEND=>=sys-libs/libsepol-2.4[abi_x86_32(-)?,abi_x86_64(-)?,abi_x86_x32(-)?,abi_mips_n32(-)?,abi_mips_n64(-)?,abi_mips_o32(-)?,abi_ppc_32(-)?,abi_ppc_64(-)?,abi_s390_32(-)?,abi_s390_64(-)?] >=dev-libs/libpcre-8.33-r1[static-libs?,abi_x86_32(-)?,abi_x86_64(-)?,abi_x86_x32(-)?,abi_mips_n32(-)?,abi_mips_n64(-)?,abi_mips_o32(-)?,abi_ppc_32(-)?,abi_ppc_64(-)?,abi_s390_32(-)?,abi_s390_64(-)?] python? ( python_targets_python2_7? ( >=dev-lang/python-2.7.3-r2:2.7 ) python_targets_python3_3? ( >=dev-lang/python-3.3.2-r2:3.3 ) python_targets_python3_4? ( dev-lang/python:3.4 ) python_targets_python3_5? ( dev-lang/python:3.5 ) >=dev-lang/python-exec-2:=[python_targets_python2_7(-)?,python_targets_python3_3(-)?,python_targets_python3_4(-)?,python_targets_python3_5(-)?,-python_single_target_python2_7(-),-python_single_target_python3_3(-),-python_single_target_python3_4(-),-python_single_target_python3_5(-)] ) ruby? ( ruby_targets_ruby19? ( dev-lang/ruby:1.9 ) ruby_targets_ruby20? ( dev-lang/ruby:2.0 ) )
+SLOT=0
+SRC_URI=https://raw.githubusercontent.com/wiki/SELinuxProject/selinux/files/releases/20150202/libselinux-2.4.tar.gz
+_eclasses_=eutils	06133990e861be0fe60c2b428fd025d9	multibuild	6d4858dc00f8bc51caf3f957f8430eb0	multilib	3bf24e6abb9b76d9f6c20600f0b716bf	multilib-build	0983c7893df461213a05f791cc7dea6d	multilib-minimal	13dd976916c35a1e2c8d170e840c7018	python-r1	331701099758706863819fe3ff6ddc8a	python-utils-r1	9500a9740660edfcbc0b3b0b491ef307	toolchain-funcs	48b38a216afb92db6314d6c3187abea3
+_md5_=20f62d0cf10509d6411b0dd12d184e0b
diff --git a/sys-libs/libselinux/Manifest b/sys-libs/libselinux/Manifest
new file mode 100644
index 0000000..530bd3d
--- /dev/null
+++ b/sys-libs/libselinux/Manifest
@@ -0,0 +1 @@
+DIST libselinux-2.4.tar.gz 165931 SHA256 46043091f4c5ba4f43e8d3715f30d665a2d571c9126c1f03945c9ea4ed380f7b SHA512 f7c7ceabcc6ca7bb5cb24fd04b8ea4771af7e509a11ce601fb50d52bd14b291ab6136b7f5193912d02b61b132a2fdd1666f229478598d0b20b99bdea0f5e69d6 WHIRLPOOL d1499818fc885c3bd07785d41466b4ea4bcf56fafe8cbc9bd1a517fe0d2d528b10911fa6df08756ca63aebc411fd69c7f01283685c8a858a81301e203dfd3ec2
diff --git a/sys-libs/libselinux/files/0005-use-ruby-include-with-rubylibver.patch b/sys-libs/libselinux/files/0005-use-ruby-include-with-rubylibver.patch
new file mode 100644
index 0000000..0fc8414
--- /dev/null
+++ b/sys-libs/libselinux/files/0005-use-ruby-include-with-rubylibver.patch
@@ -0,0 +1,12 @@
+diff -uNr libselinux-2.2.2.orig/src/Makefile libselinux-2.2.2/src/Makefile
+--- libselinux-2.2.2.orig/src/Makefile	2013-11-06 20:56:30.000000000 +0100
++++ libselinux-2.2.2/src/Makefile	2013-11-25 21:02:05.327561766 +0100
+@@ -16,7 +16,7 @@
+ PYLIBDIR ?= $(LIBDIR)/$(PYLIBVER)
+ RUBYLIBVER ?= $(shell $(RUBY) -e 'print RUBY_VERSION.split(".")[0..1].join(".")')
+ RUBYPLATFORM ?= $(shell $(RUBY) -e 'print RUBY_PLATFORM')
+-RUBYINC ?= $(shell pkg-config --cflags ruby)
++RUBYINC ?= $(shell pkg-config --cflags ruby-$(RUBYLIBVER))
+ RUBYINSTALL ?= $(LIBDIR)/ruby/site_ruby/$(RUBYLIBVER)/$(RUBYPLATFORM)
+ LIBBASE ?= $(shell basename $(LIBDIR))
+ 
diff --git a/sys-libs/libselinux/files/0006-build-related-fixes-bug-500674.patch b/sys-libs/libselinux/files/0006-build-related-fixes-bug-500674.patch
new file mode 100644
index 0000000..cec91b1
--- /dev/null
+++ b/sys-libs/libselinux/files/0006-build-related-fixes-bug-500674.patch
@@ -0,0 +1,67 @@
+https://bugs.gentoo.org/500674
+
+random fixes:
+ - make sure PCRE_CFLAGS get used
+ - use PCRE_LIBS via pkg-config
+ - move LDFLAGS to before objects, not after
+ - do not hardcode -L$(LIBDIR) (let the toolchain handle it)
+ - do not hardcode -I$(INCLUDEDIR) (let the toolchain handle it)
+
+--- a/src/Makefile
++++ b/src/Makefile
+@@ -75,7 +75,7 @@ CFLAGS ?= -O -Wall -W -Wundef -Wformat-y2k -Wformat-security -Winit-self -Wmissi
+           -fipa-pure-const -Wno-suggest-attribute=pure -Wno-suggest-attribute=const \
+           -Werror -Wno-aggregate-return -Wno-redundant-decls
+ 
+-override CFLAGS += -I../include -I$(INCLUDEDIR) -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 $(EMFLAGS)
++override CFLAGS += -I../include $(PCRE_CFLAGS) -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 $(EMFLAGS)
+ 
+ SWIG_CFLAGS += -Wno-error -Wno-unused-variable -Wno-unused-but-set-variable -Wno-unused-parameter \
+ 		-Wno-shadow -Wno-uninitialized -Wno-missing-prototypes -Wno-missing-declarations
+@@ -104,17 +104,17 @@ $(SWIGRUBYLOBJ): $(SWIGRUBYCOUT)
+ 	$(CC) $(CFLAGS) $(SWIG_CFLAGS) $(RUBYINC) -fPIC -DSHARED -c -o $@ $<
+ 
+ $(SWIGSO): $(SWIGLOBJ)
+-	$(CC) $(CFLAGS) -shared -o $@ $< -L. -lselinux $(LDFLAGS) -L$(LIBDIR)
++	$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $< -L. -lselinux
+ 
+ $(SWIGRUBYSO): $(SWIGRUBYLOBJ)
+-	$(CC) $(CFLAGS) -shared -o $@ $^ -L. -lselinux $(LDFLAGS) -L$(LIBDIR)
++	$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $^ -L. -lselinux
+ 
+ $(LIBA): $(OBJS)
+ 	$(AR) rcs $@ $^
+ 	$(RANLIB) $@
+ 
+ $(LIBSO): $(LOBJS)
+-	$(CC) $(CFLAGS) -shared -o $@ $^ -lpcre -ldl $(LDFLAGS) -L$(LIBDIR) -Wl,-soname,$(LIBSO),-z,defs,-z,relro
++	$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $^ -ldl $(PCRE_LIBS) -Wl,-soname,$(LIBSO),-z,defs,-z,relro
+ 	ln -sf $@ $(TARGET) 
+ 
+ $(LIBPC): $(LIBPC).in ../VERSION
+@@ -127,7 +127,7 @@ $(AUDIT2WHYLOBJ): audit2why.c
+ 	$(CC) $(filter-out -Werror, $(CFLAGS)) $(PYINC) -fPIC -DSHARED -c -o $@ $<
+ 
+ $(AUDIT2WHYSO): $(AUDIT2WHYLOBJ)
+-	$(CC) $(CFLAGS) -shared -o $@ $^ -L. $(LDFLAGS) -lselinux $(LIBDIR)/libsepol.a -L$(LIBDIR)
++	$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $^ -L. -lselinux $(LIBDIR)/libsepol.a
+ 
+ %.o:  %.c policy.h
+ 	$(CC) $(CFLAGS) $(TLSFLAGS) -c -o $@ $<
+--- a/utils/Makefile
++++ b/utils/Makefile
+@@ -24,11 +24,12 @@ CFLAGS ?= -O -Wall -W -Wundef -Wformat-y2k -Wformat-security -Winit-self -Wmissi
+           -fipa-pure-const -Wno-suggest-attribute=pure -Wno-suggest-attribute=const \
+           -Werror -Wno-aggregate-return -Wno-redundant-decls
+ override CFLAGS += -I../include -D_GNU_SOURCE $(EMFLAGS)
+-LDLIBS += -L../src -lselinux -L$(LIBDIR)
++LDLIBS += -L../src -lselinux
+ 
+ TARGETS=$(patsubst %.c,%,$(wildcard *.c))
+ 
+-sefcontext_compile: LDLIBS += -lpcre
++sefcontext_compile: CFLAGS += $(PCRE_CFLAGS)
++sefcontext_compile: LDLIBS += $(PCRE_LIBS)
+ 
+ ifeq ($(DISABLE_AVC),y)
+ 	UNUSED_TARGETS+=compute_av compute_create compute_member compute_relabel
diff --git a/sys-libs/libselinux/libselinux-2.4.ebuild b/sys-libs/libselinux/libselinux-2.4.ebuild
new file mode 100644
index 0000000..e84c847
--- /dev/null
+++ b/sys-libs/libselinux/libselinux-2.4.ebuild
@@ -0,0 +1,145 @@
+# Copyright 1999-2015 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
+
+EAPI="5"
+PYTHON_COMPAT=( python2_7 python3_3 python3_4 python3_5 )
+USE_RUBY="ruby19 ruby20"
+
+# No, I am not calling ruby-ng
+inherit multilib python-r1 toolchain-funcs eutils multilib-minimal
+
+MY_P="${P//_/-}"
+SEPOL_VER="${PV}"
+
+DESCRIPTION="SELinux userland library"
+HOMEPAGE="https://github.com/SELinuxProject/selinux/wiki"
+SRC_URI="https://raw.githubusercontent.com/wiki/SELinuxProject/selinux/files/releases/20150202/${MY_P}.tar.gz"
+
+LICENSE="public-domain"
+SLOT="0"
+KEYWORDS="*"
+
+IUSE="python ruby static-libs ruby_targets_ruby19 ruby_targets_ruby20"
+
+RDEPEND=">=sys-libs/libsepol-${SEPOL_VER}[${MULTILIB_USEDEP}]
+	>=dev-libs/libpcre-8.33-r1[static-libs?,${MULTILIB_USEDEP}]
+	python? ( ${PYTHON_DEPS} )
+	ruby? (
+		ruby_targets_ruby19? ( dev-lang/ruby:1.9 )
+		ruby_targets_ruby20? ( dev-lang/ruby:2.0 )
+	)"
+DEPEND="${RDEPEND}
+	virtual/pkgconfig
+	python? ( >=dev-lang/swig-2.0.9 )"
+
+S="${WORKDIR}/${MY_P}"
+
+src_prepare() {
+	epatch "${FILESDIR}/0005-use-ruby-include-with-rubylibver.patch"
+	epatch "${FILESDIR}/0006-build-related-fixes-bug-500674.patch"
+
+	epatch_user
+
+	multilib_copy_sources
+}
+
+multilib_src_compile() {
+	tc-export PKG_CONFIG RANLIB
+	local PCRE_CFLAGS=$(${PKG_CONFIG} libpcre --cflags)
+	local PCRE_LIBS=$(${PKG_CONFIG} libpcre --libs)
+	export PCRE_{CFLAGS,LIBS}
+
+	emake \
+		AR="$(tc-getAR)" \
+		CC="$(tc-getCC)" \
+		LIBDIR="\$(PREFIX)/$(get_libdir)" \
+		SHLIBDIR="\$(DESTDIR)/$(get_libdir)" \
+		LDFLAGS="-fPIC ${LDFLAGS} -pthread" \
+		all
+
+	if multilib_is_native_abi && use python; then
+		building() {
+			python_export PYTHON_INCLUDEDIR PYTHON_LIBPATH
+			emake \
+				CC="$(tc-getCC)" \
+				PYINC="-I${PYTHON_INCLUDEDIR}" \
+				PYTHONLIBDIR="${PYTHON_LIBPATH}" \
+				PYPREFIX="${EPYTHON##*/}" \
+				LDFLAGS="-fPIC ${LDFLAGS} -lpthread" \
+				LIBDIR="\$(PREFIX)/$(get_libdir)" \
+				SHLIBDIR="\$(DESTDIR)/$(get_libdir)" \
+				pywrap
+		}
+		python_foreach_impl building
+	fi
+
+	if multilib_is_native_abi && use ruby; then
+		building() {
+			einfo "Calling rubywrap for ${1}"
+			# Clean up .lo file to force rebuild
+			rm -f src/selinuxswig_ruby_wrap.lo || die
+			emake \
+				CC="$(tc-getCC)" \
+				RUBY=${1} \
+				RUBYINSTALL=$(${1} -e 'print RbConfig::CONFIG["vendorarchdir"]') \
+				LDFLAGS="-fPIC ${LDFLAGS} -lpthread" \
+				LIBDIR="\$(PREFIX)/$(get_libdir)" \
+				SHLIBDIR="\$(DESTDIR)/$(get_libdir)" \
+				rubywrap
+		}
+		for RUBYTARGET in ${USE_RUBY}; do
+			use ruby_targets_${RUBYTARGET} || continue
+
+			building ${RUBYTARGET}
+		done
+	fi
+}
+
+multilib_src_install() {
+	LIBDIR="\$(PREFIX)/$(get_libdir)" SHLIBDIR="\$(DESTDIR)/$(get_libdir)" \
+		emake DESTDIR="${D}" install
+
+	if multilib_is_native_abi && use python; then
+		installation() {
+			LIBDIR="\$(PREFIX)/$(get_libdir)" emake DESTDIR="${D}" install-pywrap
+			python_optimize # bug 531638
+		}
+		python_foreach_impl installation
+	fi
+
+	if multilib_is_native_abi && use ruby; then
+		installation() {
+			einfo "Calling install-rubywrap for ${1}"
+			# Forcing (re)build here as otherwise the resulting SO file is used for all ruby versions
+			rm src/selinuxswig_ruby_wrap.lo
+			LIBDIR="\$(PREFIX)/$(get_libdir)" emake DESTDIR="${D}" \
+				RUBY=${1} \
+				RUBYINSTALL="${D}/$(${1} -e 'print RbConfig::CONFIG["vendorarchdir"]')" \
+				install-rubywrap
+		}
+		for RUBYTARGET in ${USE_RUBY}; do
+			use ruby_targets_${RUBYTARGET} || continue
+
+			installation ${RUBYTARGET}
+		done
+	fi
+
+	use static-libs || rm "${D}"/usr/lib*/*.a || die
+}
+
+pkg_postinst() {
+	# Fix bug 473502
+	for POLTYPE in ${POLICY_TYPES};
+	do
+		mkdir -p /etc/selinux/${POLTYPE}/contexts/files || die
+		touch /etc/selinux/${POLTYPE}/contexts/files/file_contexts.local || die
+		# Fix bug 516608
+		for EXPRFILE in file_contexts file_contexts.homedirs file_contexts.local ; do
+			if [[ -f ${EXPRFILE} ]]; then
+				sefcontext_compile /etc/selinux/${POLTYPE}/contexts/files/${EXPRFILE} \
+				|| die "Failed to recompile contexts"
+			fi
+		done
+	done
+}
diff --git a/sys-libs/libselinux/metadata.xml b/sys-libs/libselinux/metadata.xml
new file mode 100644
index 0000000..66f6800
--- /dev/null
+++ b/sys-libs/libselinux/metadata.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
+<pkgmetadata>
+	<maintainer>
+		<email>selinux@gentoo.org</email>
+		<name>SELinux Team</name>
+	</maintainer>
+	<longdescription>
+		Libselinux provides an API for SELinux applications to get and set
+		process and file security contexts and to obtain security policy
+		decisions.  Required for any applications that use the SELinux API.
+	</longdescription>
+	<upstream>
+		<remote-id type="github">SELinuxProject/selinux</remote-id>
+	</upstream>
+</pkgmetadata>