[Feature][ZXW-65]merged P49 base code

Change-Id: I3e09c0c3d47483bc645f02310380ecb7fc6f4041
diff --git a/cap/zx297520v3/sources/meta-selinux/classes/enable-audit.bbclass b/cap/zx297520v3/sources/meta-selinux/classes/enable-audit.bbclass
new file mode 100755
index 0000000..4538b0b
--- /dev/null
+++ b/cap/zx297520v3/sources/meta-selinux/classes/enable-audit.bbclass
@@ -0,0 +1,4 @@
+# There is still no audit DISTRO_FEATURE, so enable audit when selinux feature enabled.
+inherit selinux
+
+PACKAGECONFIG_append = " ${@target_selinux(d, 'audit')}"
diff --git a/cap/zx297520v3/sources/meta-selinux/classes/enable-selinux.bbclass b/cap/zx297520v3/sources/meta-selinux/classes/enable-selinux.bbclass
new file mode 100755
index 0000000..de2a124
--- /dev/null
+++ b/cap/zx297520v3/sources/meta-selinux/classes/enable-selinux.bbclass
@@ -0,0 +1,4 @@
+inherit selinux
+
+PACKAGECONFIG_append = " ${@target_selinux(d)}"
+PACKAGECONFIG[selinux] = "--enable-selinux,--disable-selinux,libselinux,"
diff --git a/cap/zx297520v3/sources/meta-selinux/classes/meson-enable-selinux.bbclass b/cap/zx297520v3/sources/meta-selinux/classes/meson-enable-selinux.bbclass
new file mode 100755
index 0000000..91c2a2b
--- /dev/null
+++ b/cap/zx297520v3/sources/meta-selinux/classes/meson-enable-selinux.bbclass
@@ -0,0 +1,4 @@
+inherit selinux
+
+PACKAGECONFIG_append = " ${@target_selinux(d)}"
+PACKAGECONFIG[selinux] = "-Dselinux=enabled,-Dselinux=disabled,libselinux,"
diff --git a/cap/zx297520v3/sources/meta-selinux/classes/meson-selinux.bbclass b/cap/zx297520v3/sources/meta-selinux/classes/meson-selinux.bbclass
new file mode 100755
index 0000000..77a763a
--- /dev/null
+++ b/cap/zx297520v3/sources/meta-selinux/classes/meson-selinux.bbclass
@@ -0,0 +1,4 @@
+inherit selinux
+
+PACKAGECONFIG_append = " ${@target_selinux(d)}"
+PACKAGECONFIG[selinux] = "-Dselinux=true,-Dselinux=false,libselinux,"
diff --git a/cap/zx297520v3/sources/meta-selinux/classes/selinux-image.bbclass b/cap/zx297520v3/sources/meta-selinux/classes/selinux-image.bbclass
new file mode 100755
index 0000000..7f157d3
--- /dev/null
+++ b/cap/zx297520v3/sources/meta-selinux/classes/selinux-image.bbclass
@@ -0,0 +1,15 @@
+selinux_set_labels () {
+    POL_TYPE=$(sed -n -e "s&^SELINUXTYPE[[:space:]]*=[[:space:]]*\([0-9A-Za-z_]\+\)&\1&p" ${IMAGE_ROOTFS}/${sysconfdir}/selinux/config)
+    if ! setfiles -m -r ${IMAGE_ROOTFS} ${IMAGE_ROOTFS}/${sysconfdir}/selinux/${POL_TYPE}/contexts/files/file_contexts ${IMAGE_ROOTFS}
+    then
+        echo WARNING: Unable to set filesystem context, setfiles / restorecon must be run on the live image.
+        touch ${IMAGE_ROOTFS}/.autorelabel
+        exit 0
+    fi
+}
+
+DEPENDS += "policycoreutils-native"
+
+IMAGE_PREPROCESS_COMMAND_append = " selinux_set_labels ;"
+
+inherit core-image
diff --git a/cap/zx297520v3/sources/meta-selinux/classes/selinux.bbclass b/cap/zx297520v3/sources/meta-selinux/classes/selinux.bbclass
new file mode 100755
index 0000000..13256d5
--- /dev/null
+++ b/cap/zx297520v3/sources/meta-selinux/classes/selinux.bbclass
@@ -0,0 +1,12 @@
+def target_selinux(d, truevar = 'selinux', falsevar = ''):
+    if not bb.utils.contains("DISTRO_FEATURES", "selinux", True, False, d):
+        return falsevar
+
+    pn = d.getVar("PN")
+    type = pn.replace(d.getVar("BPN"), "")
+    if type in ("-native", "nativesdk-", "-cross", "-crosssdk"):
+        return falsevar
+
+    return truevar 
+
+LIBSELINUX = "${@target_selinux(d, 'libselinux')}"
diff --git a/cap/zx297520v3/sources/meta-selinux/classes/with-audit.bbclass b/cap/zx297520v3/sources/meta-selinux/classes/with-audit.bbclass
new file mode 100755
index 0000000..0c15312
--- /dev/null
+++ b/cap/zx297520v3/sources/meta-selinux/classes/with-audit.bbclass
@@ -0,0 +1,5 @@
+# There is still no audit DISTRO_FEATURE, so enable audit when selinux feature enabled.
+inherit selinux
+
+PACKAGECONFIG_append = " ${@target_selinux(d, 'audit')}"
+PACKAGECONFIG[audit] = "--with-audit,--without-audit,audit,"
diff --git a/cap/zx297520v3/sources/meta-selinux/classes/with-selinux.bbclass b/cap/zx297520v3/sources/meta-selinux/classes/with-selinux.bbclass
new file mode 100755
index 0000000..7873d9b
--- /dev/null
+++ b/cap/zx297520v3/sources/meta-selinux/classes/with-selinux.bbclass
@@ -0,0 +1,4 @@
+inherit selinux
+
+PACKAGECONFIG_append = " ${@target_selinux(d)}"
+PACKAGECONFIG[selinux] = "--with-selinux,--without-selinux,libselinux,"