浏览代码

update for OS_DARWIN

ithewei 5 年之前
父节点
当前提交
8e7c41eb8b
共有 3 个文件被更改,包括 14 次插入11 次删除
  1. 5 0
      Makefile.in
  2. 2 8
      base/hplatform.h
  3. 7 3
      utils/hmain.cpp

+ 5 - 0
Makefile.in

@@ -54,6 +54,9 @@ endif
 ifneq ($(findstring android, $(TARGET_PLATFORM)), )
 	OS=Android
 endif
+ifneq ($(findstring apple, $(TARGET_PLATFORM)), )
+	OS=Apple
+endif
 ifndef OS
 	OS=Linux
 endif
@@ -234,6 +237,8 @@ $(TARGET): $(OBJS)
 ifneq ($(findstring SHARED, $(TARGET_TYPE)), )
 ifeq ($(OS), Windows)
 	$(CC) -shared $^ -o $(LIBDIR)/$@.dll $(LDFLAGS) -Wl,--output-def,$(LIBDIR)/$(@).def
+else ifeq($(OS), Apple)
+	$(CC) -shared $^ -o $(LIBDIR)/$@.dylib $(LDFLAGS)
 else
 	$(CC) -shared $^ -o $(LIBDIR)/$@.so $(LDFLAGS)
 endif

+ 2 - 8
base/hplatform.h

@@ -18,17 +18,11 @@
     #include <TargetConditionals.h>
     #if defined(TARGET_OS_MAC) && TARGET_OS_MAC
         #define OS_MAC
-        #define OS_DARWIN
-        #ifdef __LP64__
-            #define OS_DARWIN64
-        #else
-            #define OS_DARWIN32
-        #endif
     #elif defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
         #define OS_IOS
-    #else
-        #define OS_MACOS
     #endif
+    #define OS_APPLE
+    #define OS_DARWIN
 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
     #define OS_FREEBSD
     #define OS_BSD

+ 7 - 3
utils/hmain.cpp

@@ -1,11 +1,15 @@
 #include "hmain.h"
 
-#include "hplatform.h"
 #include "hlog.h"
-#include "htime.h"
 #include "herr.h"
+#include "htime.h"
 #include "hthread.h"
 
+#ifdef OS_DARWIN
+#include <crt_externs.h>
+#define environ (*_NSGetEnviron())
+#endif
+
 main_ctx_t  g_main_ctx;
 int         g_worker_processes_num = 0;
 int         g_worker_threads_num = 0;
@@ -101,7 +105,7 @@ int main_ctx_init(int argc, char** argv) {
     g_main_ctx.save_argv[g_main_ctx.argc] = NULL;
     g_main_ctx.cmdline[g_main_ctx.arg_len-1] = '\0';
 
-#if defined(OS_WIN) || defined(OS_LINUX)
+#if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_DARWIN)
     // save env
     g_main_ctx.os_envp = environ;
     g_main_ctx.envc = 0;