Support for OSX build; tested using OSX 10.9/clang-500.2.79
diff --git a/brotli/enc/entropy_encode.cc b/brotli/enc/entropy_encode.cc
index 5d53da7..ad9f0f5 100644
--- a/brotli/enc/entropy_encode.cc
+++ b/brotli/enc/entropy_encode.cc
@@ -20,6 +20,7 @@
 #include <algorithm>
 #include <limits>
 #include <vector>
+#include <cstdlib>
 
 #include "./histogram.h"
 
diff --git a/brotli/enc/hash.h b/brotli/enc/hash.h
index c11e3a5..b45d71c 100644
--- a/brotli/enc/hash.h
+++ b/brotli/enc/hash.h
@@ -23,6 +23,7 @@
 #include <string.h>
 #include <sys/types.h>
 #include <algorithm>
+#include <cstdlib>
 
 #include "./fast_log.h"
 #include "./find_match_length.h"
diff --git a/brotli/enc/write_bits.h b/brotli/enc/write_bits.h
index ce888e6..cf6f53e 100644
--- a/brotli/enc/write_bits.h
+++ b/brotli/enc/write_bits.h
@@ -18,7 +18,11 @@
 #define BROTLI_ENC_WRITE_BITS_H_
 
 #include <assert.h>
-#include <endian.h>
+#if defined(OS_MACOSX)
+  #include <machine/endian.h>
+#else
+  #include <endian.h>
+#endif
 #include <stdint.h>
 #include <stdio.h>
 
diff --git a/shared.mk b/shared.mk
index ecb6edf..15dca18 100644
--- a/shared.mk
+++ b/shared.mk
@@ -1,10 +1,17 @@
+OS := $(shell uname)
 IDIRS=-I../brotli/dec/ -I../brotli/enc/ -I../
 
-GFLAGS=-no-canonical-prefixes -fno-omit-frame-pointer -fno-tree-vrp -m64
+GFLAGS=-no-canonical-prefixes -fno-omit-frame-pointer -m64
 
 CPP = g++
 LFLAGS =
 CPPFLAGS = -c $(IDIRS) -std=c++0x $(GFLAGS)
 
+ifeq ($(OS), Darwin)
+  CPPFLAGS += -DOS_MACOSX
+else
+  CPPFLAGS += -fno-tree-vrp
+endif
+
 %.o : %.c
 	$(CPP) $(CPPFLAGS) $< -o $@
diff --git a/woff2/ots.h b/woff2/ots.h
index 65b0d8c..4eac1cb 100644
--- a/woff2/ots.h
+++ b/woff2/ots.h
@@ -18,31 +18,14 @@
 #ifndef BROTLI_WOFF2_OTS_H_
 #define BROTLI_WOFF2_OTS_H_
 
+#include <stdint.h>
+#include <arpa/inet.h>
 #include <cstdlib>
 #include <cstring>
 #include <limits>
 
 namespace ots {
 
-#if defined(_WIN32)
-#include <stdlib.h>
-typedef signed char int8_t;
-typedef unsigned char uint8_t;
-typedef short int16_t;
-typedef unsigned short uint16_t;
-typedef int int32_t;
-typedef unsigned int uint32_t;
-typedef __int64 int64_t;
-typedef unsigned __int64 uint64_t;
-#define ntohl(x) _byteswap_ulong (x)
-#define ntohs(x) _byteswap_ushort (x)
-#define htonl(x) _byteswap_ulong (x)
-#define htons(x) _byteswap_ushort (x)
-#else
-#include <arpa/inet.h>
-#include <stdint.h>
-#endif
-
 #if defined(_MSC_VER) || !defined(OTS_DEBUG)
 #define OTS_FAILURE() false
 #else