Support for building on MacOS X as part of Android.
diff --git a/Android.mk b/Android.mk
new file mode 100644
index 0000000..e193765
--- /dev/null
+++ b/Android.mk
@@ -0,0 +1,97 @@
+LOCAL_PATH:= $(call my-dir)
+
+common_src_files := \
+ src/assertion.c \
+ src/avrule_block.c \
+ src/avtab.c \
+ src/boolean_record.c \
+ src/booleans.c \
+ src/conditional.c \
+ src/constraint.c \
+ src/context.c \
+ src/context_record.c \
+ src/debug.c \
+ src/ebitmap.c \
+ src/expand.c \
+ src/genbools.c \
+ src/genusers.c \
+ src/handle.c \
+ src/hashtab.c \
+ src/hierarchy.c \
+ src/iface_record.c \
+ src/interfaces.c \
+ src/link.c \
+ src/mls.c \
+ src/module.c \
+ src/node_record.c \
+ src/nodes.c \
+ src/polcaps.c \
+ src/policydb.c \
+ src/policydb_convert.c \
+ src/policydb_public.c \
+ src/port_record.c \
+ src/ports.c \
+ src/roles.c \
+ src/services.c \
+ src/sidtab.c \
+ src/symtab.c \
+ src/user_record.c \
+ src/users.c \
+ src/util.c \
+ src/write.c
+
+common_cflags := \
+ -Wall -W -Wundef \
+ -Wshadow -Wmissing-noreturn \
+ -Wmissing-format-attribute
+
+ifeq ($(HOST_OS), darwin)
+common_cflags += -DDARWIN
+endif
+
+common_includes := \
+ $(LOCAL_PATH)/include/ \
+ $(LOCAL_PATH)/src/
+
+##
+# libsepol.so
+#
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := libsepol
+LOCAL_MODULE_TAGS := optional
+LOCAL_C_INCLUDES := $(common_includes)
+LOCAL_CFLAGS := $(common_cflags)
+LOCAL_SRC_FILES := $(common_src_files)
+LOCAL_MODULE_CLASS := SHARED_LIBRARIES
+
+include $(BUILD_HOST_SHARED_LIBRARY)
+
+##
+# libsepol.a
+#
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := libsepol
+LOCAL_MODULE_TAGS := optional
+LOCAL_C_INCLUDES := $(common_includes)
+LOCAL_CFLAGS := $(common_cflags)
+LOCAL_SRC_FILES := $(common_src_files)
+LOCAL_MODULE_CLASS := STATIC_LIBRARIES
+
+include $(BUILD_HOST_STATIC_LIBRARY)
+
+##
+# chkcon
+#
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := chkcon
+LOCAL_MODULE_TAGS := optional
+LOCAL_C_INCLUDES := $(common_includes)
+LOCAL_CFLAGS := $(common_cflags)
+LOCAL_SRC_FILES := utils/chkcon.c
+LOCAL_SHARED_LIBRARIES := libsepol
+LOCAL_MODULE_CLASS := EXECUTABLES
+
+include $(BUILD_HOST_EXECUTABLE)
diff --git a/src/genbools.c b/src/genbools.c
index e353ef3..612ff9a 100644
--- a/src/genbools.c
+++ b/src/genbools.c
@@ -79,7 +79,16 @@
if (boolf == NULL)
goto localbool;
+#ifdef DARWIN
+ if ((buffer = (char *)malloc(255 * sizeof(char))) == NULL) {
+ ERR(NULL, "out of memory");
+ return -1;
+ }
+
+ while(fgets(buffer, 255, boolf) != NULL) {
+#else
while (getline(&buffer, &size, boolf) > 0) {
+#endif
int ret = process_boolean(buffer, name, sizeof(name), &val);
if (ret == -1)
errors++;
@@ -101,7 +110,14 @@
snprintf(localbools, sizeof(localbools), "%s.local", path);
boolf = fopen(localbools, "r");
if (boolf != NULL) {
- while (getline(&buffer, &size, boolf) > 0) {
+
+#ifdef DARWIN
+
+ while(fgets(buffer, 255, boolf) != NULL) {
+#else
+
+ while (getline(&buffer, &size, boolf) > 0) {
+#endif
int ret =
process_boolean(buffer, name, sizeof(name), &val);
if (ret == -1)
diff --git a/src/genusers.c b/src/genusers.c
index 44f94e9..37528e2 100644
--- a/src/genusers.c
+++ b/src/genusers.c
@@ -1,11 +1,16 @@
#include <stdio.h>
-#include <stdio_ext.h>
+
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <sepol/policydb/policydb.h>
+
+#ifndef DARWIN
+#include <stdio_ext.h>
+#endif
+
#include <stdarg.h>
#include "debug.h"
@@ -41,9 +46,19 @@
fp = fopen(path, "r");
if (fp == NULL)
return -1;
- __fsetlocking(fp, FSETLOCKING_BYCALLER);
+#ifdef DARWIN
+ if ((buffer = (char *)malloc(255 * sizeof(char))) == NULL) {
+ ERR(NULL, "out of memory");
+ return -1;
+ }
+
+ while(fgets(buffer, 255, fp) != NULL) {
+#else
+ __fsetlocking(fp, FSETLOCKING_BYCALLER);
while ((nread = getline(&buffer, &len, fp)) > 0) {
+#endif
+
lineno++;
if (buffer[nread - 1] == '\n')
buffer[nread - 1] = 0;
diff --git a/src/node_record.c b/src/node_record.c
index b1bd370..bd48ba0 100644
--- a/src/node_record.c
+++ b/src/node_record.c
@@ -70,7 +70,11 @@
return STATUS_ERR;
}
+#ifdef DARWIN
+ memcpy(addr_bytes, in_addr.s6_addr, 16);
+#else
memcpy(addr_bytes, in_addr.s6_addr32, 16);
+#endif
break;
}
default:
@@ -158,8 +162,11 @@
{
struct in6_addr addr;
memset(&addr, 0, sizeof(struct in6_addr));
+#ifdef DARWIN
+ memcpy(&addr.s6_addr[0], addr_bytes, 16);
+#else
memcpy(&addr.s6_addr32[0], addr_bytes, 16);
-
+#endif
if (inet_ntop(AF_INET6, &addr, addr_str,
INET6_ADDRSTRLEN) == NULL) {
diff --git a/src/private.h b/src/private.h
index b2b247e..fd6cf33 100644
--- a/src/private.h
+++ b/src/private.h
@@ -4,11 +4,23 @@
#include <sepol/policydb/policydb.h>
+
+#ifdef DARWIN
+#include <sys/types.h>
+#include <machine/endian.h>
+#else
#include <byteswap.h>
#include <endian.h>
+#endif
+
#include <errno.h>
#include <dso.h>
+#ifdef DARWIN
+#define __BYTE_ORDER BYTE_ORDER
+#define __LITTLE_ENDIAN LITTLE_ENDIAN
+#endif
+
#if __BYTE_ORDER == __LITTLE_ENDIAN
#define cpu_to_le16(x) (x)
#define le16_to_cpu(x) (x)
diff --git a/utils/chkcon.c b/utils/chkcon.c
index 4c23d4c..baa5117 100644
--- a/utils/chkcon.c
+++ b/utils/chkcon.c
@@ -6,6 +6,8 @@
#include <string.h>
#include <errno.h>
+void usage(char*) __attribute__((noreturn));
+
void usage(char *progname)
{
printf("usage: %s policy context\n", progname);