From 009cabf1031db42271a1e05980965a129cbbfe1d Mon Sep 17 00:00:00 2001
From: siahl <slyimo@us.ibm.com>
Date: Tue, 29 Jul 2014 16:39:37 -0500
Subject: [PATCH] Add support for compiling on AIX

Closes #1900
---
 deps/hiredis/fmacros.h | 4 ++++
 deps/hiredis/net.h     | 2 +-
 src/Makefile           | 8 +++++++-
 src/anet.h             | 6 +++++-
 src/fmacros.h          | 4 ++++
 src/redis.h            | 5 +++++
 6 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/deps/hiredis/fmacros.h b/deps/hiredis/fmacros.h
index 9e5fec0ce..6a41aa176 100644
--- a/deps/hiredis/fmacros.h
+++ b/deps/hiredis/fmacros.h
@@ -5,6 +5,10 @@
 #define _BSD_SOURCE
 #endif
 
+#if defined(_AIX)
+#define _ALL_SOURCE
+#endif
+
 #if defined(__sun__)
 #define _POSIX_C_SOURCE 200112L
 #elif defined(__linux__) || defined(__OpenBSD__) || defined(__NetBSD__)
diff --git a/deps/hiredis/net.h b/deps/hiredis/net.h
index 5e742f577..3763ab089 100644
--- a/deps/hiredis/net.h
+++ b/deps/hiredis/net.h
@@ -35,7 +35,7 @@
 
 #include "hiredis.h"
 
-#if defined(__sun)
+#if defined(__sun) || defined(_AIX)
 #define AF_LOCAL AF_UNIX
 #endif
 
diff --git a/src/Makefile b/src/Makefile
index 4ccc6d367..901104b27 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -62,13 +62,19 @@ ifeq ($(uname_S),SunOS)
 else
 ifeq ($(uname_S),Darwin)
 	# Darwin (nothing to do)
+else
+ifeq ($(uname_S),AIX)
+        # AIX
+        FINAL_LDFLAGS+= -Wl,-bexpall
+        FINAL_LIBS+= -pthread -lcrypt -lbsd
+
 else
 	# All the other OSes (notably Linux)
 	FINAL_LDFLAGS+= -rdynamic
 	FINAL_LIBS+= -pthread
 endif
 endif
-
+endif
 # Include paths to dependencies
 FINAL_CFLAGS+= -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src
 
diff --git a/src/anet.h b/src/anet.h
index c4659cd35..5191c4b69 100644
--- a/src/anet.h
+++ b/src/anet.h
@@ -39,10 +39,14 @@
 #define ANET_NONE 0
 #define ANET_IP_ONLY (1<<0)
 
-#if defined(__sun)
+#if defined(__sun) || defined(_AIX)
 #define AF_LOCAL AF_UNIX
 #endif
 
+#ifdef _AIX
+#undef ip_len
+#endif
+
 int anetTcpConnect(char *err, char *addr, int port);
 int anetTcpNonBlockConnect(char *err, char *addr, int port);
 int anetTcpNonBlockBindConnect(char *err, char *addr, int port, char *source_addr);
diff --git a/src/fmacros.h b/src/fmacros.h
index 44e378a68..e49735ce5 100644
--- a/src/fmacros.h
+++ b/src/fmacros.h
@@ -36,6 +36,10 @@
 #define _GNU_SOURCE
 #endif
 
+#if defined(_AIX)
+#define _ALL_SOURCE
+#endif
+
 #if defined(__linux__) || defined(__OpenBSD__)
 #define _XOPEN_SOURCE 700
 /*
diff --git a/src/redis.h b/src/redis.h
index d2b00bff5..b049dbee8 100644
--- a/src/redis.h
+++ b/src/redis.h
@@ -626,6 +626,11 @@ typedef struct redisOpArray {
 
 struct clusterState;
 
+#ifdef _AIX
+#undef hz
+#endif
+
+
 struct redisServer {
     /* General */
     pid_t pid;                  /* Main process pid. */