1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
5 PYTHON_COMPAT=( python{3_6,3_7,3_8} )
7 inherit multilib python-r1 toolchain-funcs multilib-minimal
10 MY_RELEASEDATE="20191204"
15 DESCRIPTION="SELinux kernel and policy management library"
16 HOMEPAGE="https://github.com/SELinuxProject/selinux/wiki"
18 if [[ ${PV} == 9999 ]]; then
20 EGIT_REPO_URI="https://github.com/SELinuxProject/selinux.git"
21 S="${WORKDIR}/${MY_P}/${PN}"
23 SRC_URI="https://github.com/SELinuxProject/selinux/releases/download/${MY_RELEASEDATE}/${MY_P}.tar.gz"
24 KEYWORDS="amd64 ~arm ~arm64 ~mips x86"
25 S="${WORKDIR}/${MY_P}"
31 REQUIRED_USE="python? ( ${PYTHON_REQUIRED_USE} )"
33 RDEPEND=">=sys-libs/libsepol-${SEPOL_VER}[${MULTILIB_USEDEP}]
34 >=sys-libs/libselinux-${SELNX_VER}[${MULTILIB_USEDEP}]
35 >=sys-process/audit-2.2.2[${MULTILIB_USEDEP}]
36 >=dev-libs/ustr-1.0.4-r2[${MULTILIB_USEDEP}]
37 python? ( ${PYTHON_DEPS} )"
42 >=dev-lang/swig-2.0.4-r1
46 # tests are not meant to be run outside of the
47 # full SELinux userland repo
53 echo >> "${S}/src/semanage.conf"
54 echo "# Set this to true to save the linked policy." >> "${S}/src/semanage.conf"
55 echo "# This is normally only useful for analysis" >> "${S}/src/semanage.conf"
56 echo "# or debugging of policy." >> "${S}/src/semanage.conf"
57 echo "save-linked=false" >> "${S}/src/semanage.conf"
58 echo >> "${S}/src/semanage.conf"
59 echo "# Set this to 0 to disable assertion checking." >> "${S}/src/semanage.conf"
60 echo "# This should speed up building the kernel policy" >> "${S}/src/semanage.conf"
61 echo "# from policy modules, but may leave you open to" >> "${S}/src/semanage.conf"
62 echo "# dangerous rules which assertion checking" >> "${S}/src/semanage.conf"
63 echo "# would catch." >> "${S}/src/semanage.conf"
64 echo "expand-check=1" >> "${S}/src/semanage.conf"
65 echo >> "${S}/src/semanage.conf"
66 echo "# Modules in the module store can be compressed" >> "${S}/src/semanage.conf"
67 echo "# with bzip2. Set this to the bzip2 blocksize" >> "${S}/src/semanage.conf"
68 echo "# 1-9 when compressing. The higher the number," >> "${S}/src/semanage.conf"
69 echo "# the more memory is traded off for disk space." >> "${S}/src/semanage.conf"
70 echo "# Set to 0 to disable bzip2 compression." >> "${S}/src/semanage.conf"
71 echo "bzip-blocksize=0" >> "${S}/src/semanage.conf"
72 echo >> "${S}/src/semanage.conf"
73 echo "# Reduce memory usage for bzip2 compression and" >> "${S}/src/semanage.conf"
74 echo "# decompression of modules in the module store." >> "${S}/src/semanage.conf"
75 echo "bzip-small=true" >> "${S}/src/semanage.conf"
80 multilib_src_compile() {
84 LIBDIR="${EPREFIX}/usr/$(get_libdir)" \
87 if multilib_is_native_abi && use python; then
92 LIBDIR="${EPREFIX}/usr/$(get_libdir)" \
95 python_foreach_impl building_py swigify
96 python_foreach_impl building_py pywrap
100 multilib_src_install() {
102 LIBDIR="${EPREFIX}/usr/$(get_libdir)" \
103 DESTDIR="${ED}" install
105 if multilib_is_native_abi && use python; then
107 emake DESTDIR="${ED}" \
108 LIBDIR="${EPREFIX}/usr/$(get_libdir)" \
110 python_optimize # bug 531638
112 python_foreach_impl installation_py
117 # Migrate the SELinux semanage configuration store if not done already
118 local selinuxtype=$(awk -F'=' '/SELINUXTYPE=/ {print $2}' "${EROOT}"/etc/selinux/config 2>/dev/null)
119 if [ -n "${selinuxtype}" ] && [ ! -d "${EROOT}"/var/lib/selinux/${selinuxtype}/active ] ; then
120 ewarn "Since the 2.4 SELinux userspace, the policy module store is moved"
121 ewarn "from /etc/selinux to /var/lib/selinux. The migration will be run now."
122 ewarn "If there are any issues, it can be done manually by running:"
123 ewarn "/usr/libexec/selinux/semanage_migrate_store"
124 ewarn "For more information, please see"
125 ewarn "- https://github.com/SELinuxProject/selinux/wiki/Policy-Store-Migration"
128 # Run the store migration without rebuilds
129 for POLICY_TYPE in ${POLICY_TYPES} ; do
130 if [ ! -d "${EROOT}/var/lib/selinux/${POLICY_TYPE}/active" ] ; then
131 einfo "Migrating store ${POLICY_TYPE} (without policy rebuild)."
132 "${EROOT}/usr/libexec/selinux/semanage_migrate_store" -n -s "${POLICY_TYPE}" || die "Failed to migrate store ${POLICY_TYPE}"