From 3e2f06a74066cc37f56859f05cb943f599786107 Mon Sep 17 00:00:00 2001 From: ApexLiu Date: Wed, 13 Sep 2017 21:33:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E5=9C=A8MacOS=E4=B8=8A?= =?UTF-8?q?=E7=BC=96=E8=AF=91tp=5Fcore=E5=92=8Clibtpssh=E4=BA=86=20=20:)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + build/builder/build-external.py | 37 +++++++++++----------- build/builder/build-server.py | 27 ++++++++++++++++ build/builder/core/colorconsole.py | 2 +- build/builder/core/env.py | 2 +- build/builder/core/utils.py | 6 ++-- common/libex/include/ex/ex_platform.h | 3 ++ common/libex/src/ex_path.cpp | 4 +-- common/libex/src/ex_str.cpp | 8 ++--- common/libex/src/ex_thread.cpp | 2 +- common/libex/src/ex_util.cpp | 2 +- server/CMakeLists.txt | 18 +++++++++-- server/tp_core/core/CMakeLists.txt | 35 +++++++++++++++++--- server/tp_core/core/ts_main.cpp | 6 +++- server/tp_core/protocol/ssh/CMakeLists.txt | 32 ++++++++++++++++--- 15 files changed, 143 insertions(+), 42 deletions(-) diff --git a/.gitignore b/.gitignore index b801dff..ae106da 100644 --- a/.gitignore +++ b/.gitignore @@ -35,6 +35,7 @@ __pycache__ /out /external/_download_ /external/linux +/external/macos /external/jsoncpp /external/mongoose /external/openssl diff --git a/build/builder/build-external.py b/build/builder/build-external.py index 64a5855..918ba21 100644 --- a/build/builder/build-external.py +++ b/build/builder/build-external.py @@ -521,7 +521,7 @@ class BuilderMacOS(BuilderBase): def _init_path(self): self.PATH_TMP = os.path.join(PATH_EXTERNAL, 'macos', 'tmp') self.PATH_RELEASE = os.path.join(PATH_EXTERNAL, 'macos', 'release') - self.OPENSSL_PATH_SRC = os.path.join(self.PATH_TMP, 'openssl-{}'.format(env.ver_openssl)) + self.OPENSSL_PATH_SRC = os.path.join(self.PATH_TMP, 'openssl-OpenSSL_{}'.format(env.ver_openssl.replace('.', '_'))) self.LIBUV_PATH_SRC = os.path.join(self.PATH_TMP, 'libuv-{}'.format(env.ver_libuv)) self.MBEDTLS_PATH_SRC = os.path.join(self.PATH_TMP, 'mbedtls-mbedtls-{}'.format(env.ver_mbedtls)) self.LIBSSH_PATH_SRC = os.path.join(self.PATH_TMP, 'libssh-{}'.format(env.ver_libssh)) @@ -552,23 +552,24 @@ class BuilderMacOS(BuilderBase): cc.w('already exists, skip.') def _build_openssl(self, file_name): - pass # we do not need build openssl anymore, because first time run build.sh we built Python, it include openssl. + # we do not need build openssl anymore, because first time run build.sh we built Python, it include openssl. - # if not os.path.exists(self.OPENSSL_PATH_SRC): - # os.system('tar -zxvf "{}/{}" -C "{}"'.format(PATH_DOWNLOAD, file_name, self.PATH_TMP)) - # - # cc.n('build openssl static...') - # if os.path.exists(os.path.join(self.PATH_RELEASE, 'lib', 'libssl.a')): - # cc.w('already exists, skip.') - # return - # - # old_p = os.getcwd() - # os.chdir(self.OPENSSL_PATH_SRC) - # #os.system('./config --prefix={} --openssldir={}/openssl no-zlib no-shared'.format(self.PATH_RELEASE, self.PATH_RELEASE)) - # os.system('./config --prefix={} --openssldir={}/openssl -fPIC no-zlib no-shared'.format(self.PATH_RELEASE, self.PATH_RELEASE)) - # os.system('make') - # os.system('make install') - # os.chdir(old_p) + if not os.path.exists(self.OPENSSL_PATH_SRC): + os.system('tar -zxvf "{}/{}" -C "{}"'.format(PATH_DOWNLOAD, file_name, self.PATH_TMP)) + + cc.n('build openssl static...') + if os.path.exists(os.path.join(self.PATH_RELEASE, 'lib', 'libssl.a')): + cc.w('already exists, skip.') + return + + old_p = os.getcwd() + os.chdir(self.OPENSSL_PATH_SRC) + #os.system('./config --prefix={} --openssldir={}/openssl no-zlib no-shared'.format(self.PATH_RELEASE, self.PATH_RELEASE)) + # os.system('./Configure darwin64-x86_64-cc') + os.system('./Configure darwin64-x86_64-cc --prefix={} --openssldir={}/openssl -fPIC no-zlib no-shared'.format(self.PATH_RELEASE, self.PATH_RELEASE)) + os.system('make') + os.system('make install') + os.chdir(old_p) def _build_libuv(self, file_name): cc.w('build libuv...skip') @@ -735,7 +736,7 @@ class BuilderMacOS(BuilderBase): ' -DWITH_EXAMPLES=OFF' \ ' -DWITH_BENCHMARKS=OFF' \ ' -DWITH_NACL=OFF' \ - ' ..'.format(self.PATH_RELEASE, env.ver_openssl_number, self.PATH_RELEASE, self.PATH_RELEASE) + ''.format(self.PATH_RELEASE, env.ver_openssl_number, self.PATH_RELEASE, self.PATH_RELEASE) try: utils.cmake(build_path, 'Release', False, cmake_define) diff --git a/build/builder/build-server.py b/build/builder/build-server.py index a0dcf4d..ab45c57 100644 --- a/build/builder/build-server.py +++ b/build/builder/build-server.py @@ -87,11 +87,38 @@ class BuilderLinux(BuilderBase): utils.ensure_file_exists(f) +class BuilderMacOS(BuilderBase): + def __init__(self): + super().__init__() + + def build_server(self): + cc.n('build server app (tp_core/libtpssh/tp_web)...') + + out_path = os.path.join(env.root_path, 'out', 'server', ctx.bits_path, 'bin') + out_files = [os.path.join(out_path, 'tp_core'), os.path.join(out_path, 'libtpssh.so'), + os.path.join(out_path, 'tp_web')] + + for f in out_files: + if os.path.exists(f): + utils.remove(f) + + utils.makedirs(out_path) + + utils.cmake(os.path.join(env.root_path, 'server', 'cmake-build'), ctx.target_path, False) + # utils.strip(out_file) + + for f in out_files: + if os.path.exists(f): + utils.ensure_file_exists(f) + + def gen_builder(dist): if dist == 'windows': builder = BuilderWin() elif dist == 'linux': builder = BuilderLinux() + elif dist == 'macos': + builder = BuilderMacOS() else: raise RuntimeError('unsupported platform.') diff --git a/build/builder/core/colorconsole.py b/build/builder/core/colorconsole.py index 86f2f10..9f3839e 100644 --- a/build/builder/core/colorconsole.py +++ b/build/builder/core/colorconsole.py @@ -32,7 +32,7 @@ CR_LIGHT_MAGENTA = 15 # 亮紫色 - 警告 CR_LIGHT_CYAN = 16 # 亮青色 CR_VERBOSE = CR_LIGHT_GRAY -CR_NORMAL = CR_WHITE +CR_NORMAL = CR_RESTORE CR_INFO = CR_GREEN CR_WARN = CR_LIGHT_YELLOW CR_ERROR = CR_LIGHT_RED diff --git a/build/builder/core/env.py b/build/builder/core/env.py index 4b2923e..c1765d4 100644 --- a/build/builder/core/env.py +++ b/build/builder/core/env.py @@ -143,7 +143,7 @@ class Env(object): if warn_miss_tool: cc.w(' - can not locate `nsis`, so I can not make installer.') - elif self.is_linux: + elif self.is_linux or self.is_macos: if 'cmake' in _tmp: self.cmake = _tmp['cmake'] else: diff --git a/build/builder/core/utils.py b/build/builder/core/utils.py index 3b942d0..3131b41 100644 --- a/build/builder/core/utils.py +++ b/build/builder/core/utils.py @@ -63,9 +63,10 @@ def download_file(desc, url, target_path, file_name): if env.is_win: cmd = '""{}" --no-check-certificate {} -O "{}""'.format(env.wget, url, local_file_name) os.system(cmd) - elif env.is_linux: + elif env.is_linux or env.is_macos: os.system('wget --no-check-certificate {} -O "{}"'.format(url, local_file_name)) else: + cc.e('can not download, no download tool.') return False if not os.path.exists(local_file_name) or not _check_download_file(local_file_name): @@ -278,7 +279,7 @@ def sys_exec(cmd, direct_output=False, output_codec=None): line = line.rstrip('\r\n') if direct_output: - cc.o((cc.CR_GRAY, line), end='\n') + cc.o((cc.CR_CYAN, line), end='\n') output.append(line) @@ -334,6 +335,7 @@ def cmake(work_path, target, force_rebuild, cmake_define=''): else: target = 'Release' cmd = '"{}" -DCMAKE_BUILD_TYPE={} {} ..;make'.format(env.cmake, target, cmake_define) + cc.o(cmd) ret, _ = sys_exec(cmd, direct_output=True) os.chdir(old_p) if ret != 0: diff --git a/common/libex/include/ex/ex_platform.h b/common/libex/include/ex/ex_platform.h index f73ecdd..67e0150 100644 --- a/common/libex/include/ex/ex_platform.h +++ b/common/libex/include/ex/ex_platform.h @@ -64,6 +64,9 @@ # include # include #endif +#ifdef EX_OS_MACOS +# include // for _NSGetExecutablePath +#endif /* diff --git a/common/libex/src/ex_path.cpp b/common/libex/src/ex_path.cpp index b841316..b192845 100644 --- a/common/libex/src/ex_path.cpp +++ b/common/libex/src/ex_path.cpp @@ -174,7 +174,7 @@ bool ex_exec_file(ex_wstr& out_filename) uint32_t length = EX_PATH_MAX; memset(buffer, 0, EX_PATH_MAX); - memset(out_path, 0, EX_PATH_MAX); + //memset(out_filename, 0, EX_PATH_MAX); /* Mac OS X has special function to obtain path to executable. * This may return a symlink. @@ -182,7 +182,7 @@ bool ex_exec_file(ex_wstr& out_filename) if (_NSGetExecutablePath(buffer, &length) != 0) return false; - if (!ex_astr2wstr(out_filename, buffer)) + if (!ex_astr2wstr(buffer, out_filename)) return false; return ex_abspath(out_filename); diff --git a/common/libex/src/ex_str.cpp b/common/libex/src/ex_str.cpp index 560d6df..a3fac76 100644 --- a/common/libex/src/ex_str.cpp +++ b/common/libex/src/ex_str.cpp @@ -99,7 +99,7 @@ wchar_t* ex_str2wcs_alloc(const char* in_buffer, int code_page) #else size_t wlen = 0; wlen = mbstowcs(NULL, in_buffer, 0); - if (wlen < 0) + if (wlen <= 0) return NULL; out_buffer = (wchar_t*)calloc(wlen + 1, sizeof(wchar_t)); @@ -107,7 +107,7 @@ wchar_t* ex_str2wcs_alloc(const char* in_buffer, int code_page) return NULL; wlen = mbstowcs(out_buffer, in_buffer, wlen); - if (wlen < 0) + if (wlen <= 0) { free(out_buffer); return NULL; @@ -152,7 +152,7 @@ char* ex_wcs2str_alloc(const wchar_t* in_buffer, int code_page) #else size_t len = 0; len = wcstombs(NULL, in_buffer, 0); - if (len < 0) + if (len <= 0) return NULL; out_buffer = (char*)calloc(len + 1, sizeof(char)); @@ -160,7 +160,7 @@ char* ex_wcs2str_alloc(const wchar_t* in_buffer, int code_page) return NULL; len = wcstombs(out_buffer, in_buffer, len); - if (len < 0) + if (len <= 0) { free(out_buffer); return NULL; diff --git a/common/libex/src/ex_thread.cpp b/common/libex/src/ex_thread.cpp index cd289ea..4239cd2 100644 --- a/common/libex/src/ex_thread.cpp +++ b/common/libex/src/ex_thread.cpp @@ -236,6 +236,6 @@ ex_u64 ex_get_thread_id(void) #ifdef EX_OS_WIN32 return GetCurrentThreadId(); #else - return pthread_self(); + return (ex_u64)pthread_self(); #endif } diff --git a/common/libex/src/ex_util.cpp b/common/libex/src/ex_util.cpp index 4c6c297..d2c1315 100644 --- a/common/libex/src/ex_util.cpp +++ b/common/libex/src/ex_util.cpp @@ -171,7 +171,7 @@ EX_BOOL ex_localtime_now(int* t, struct tm* dt) time(&timep); _tmp = localtime(&timep); //get server's time if (_tmp == NULL) - return NULL; + return EX_FALSE; if(NULL != dt) memcpy(dt, _tmp, sizeof(struct tm)); #endif diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index 5733eb9..6b68e93 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -1,3 +1,5 @@ +MESSAGE(STATUS "operation system is ${CMAKE_SYSTEM}") + cmake_minimum_required(VERSION 3.5) #project(teleport) @@ -7,8 +9,18 @@ cmake_minimum_required(VERSION 3.5) #add_executable(teleport ${SOURCE_FILES}) #set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${teleport_SOURCE_DIR}/../out/server/x64/bin") -add_subdirectory(tp_web/src) + +IF (CMAKE_SYSTEM_NAME MATCHES "Linux") + MESSAGE(STATUS "build on Linux...") + add_subdirectory(tp_web/src) +ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Windows") + MESSAGE(FATAL_ERROR "unsupported platform: Windows") +ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Darwin") + MESSAGE(STATUS "build on MacOS...") +ELSE () + MESSAGE(FATAL_ERROR "unsupported platform: ${CMAKE_SYSTEM_NAME}") +ENDIF (CMAKE_SYSTEM_NAME MATCHES "Linux") + add_subdirectory(tp_core/core) add_subdirectory(tp_core/protocol/ssh) -add_subdirectory(tp_core/protocol/rdp) - +#add_subdirectory(tp_core/protocol/rdp) diff --git a/server/tp_core/core/CMakeLists.txt b/server/tp_core/core/CMakeLists.txt index 05cc6ab..cf659d0 100644 --- a/server/tp_core/core/CMakeLists.txt +++ b/server/tp_core/core/CMakeLists.txt @@ -16,24 +16,51 @@ ADD_DEFINITIONS( -DDISABLE_MD5 ) -set(CMAKE_EXE_LINKER_FLAGS "-export-dynamic") +#set(CMAKE_EXE_LINKER_FLAGS "-export-dynamic") aux_source_directory(. DIR_SRCS) aux_source_directory(../../../common/libex/src DIR_SRCS) aux_source_directory(../../../external/mongoose DIR_SRCS) aux_source_directory(../../../external/jsoncpp/src/lib_json DIR_SRCS) + #list(REMOVE_ITEM DIR_SRCS "./src/ts_win_service_helper.cpp") include_directories( ../../../common/libex/include + ../../../common/teleport ../../../external/mongoose ../../../external/jsoncpp/include - ../../../external/linux/release/include ) -link_directories(../../../external/linux/release/lib) +IF (CMAKE_SYSTEM_NAME MATCHES "Linux") + set(CMAKE_EXE_LINKER_FLAGS "-export-dynamic") + include_directories( + ../../../external/linux/release/include + ) + link_directories(../../../external/linux/release/lib) +ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Darwin") + include_directories( + ../../../external/macos/release/include + ) + link_directories(../../../external/macos/release/lib) +ENDIF (CMAKE_SYSTEM_NAME MATCHES "Linux") + + +#include_directories( +# ../../../common/libex/include +# ../../../external/mongoose +# ../../../external/jsoncpp/include +# ../../../external/linux/release/include +#) +#link_directories(../../../external/linux/release/lib) add_executable(tp_core ${DIR_SRCS}) #target_link_libraries(tp_core ssl crypto mbedx509 mbedtls mbedcrypto sqlite3 dl pthread rt util) -target_link_libraries(tp_core ssl crypto mbedx509 mbedtls mbedcrypto dl pthread rt util) +#target_link_libraries(tp_core ssl crypto mbedx509 mbedtls mbedcrypto dl pthread rt util) + +IF (CMAKE_SYSTEM_NAME MATCHES "Linux") + target_link_libraries(tp_core ssl crypto mbedx509 mbedtls mbedcrypto dl pthread rt util) +ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Darwin") + target_link_libraries(tp_core ssl crypto mbedx509 mbedtls mbedcrypto dl pthread util) +ENDIF (CMAKE_SYSTEM_NAME MATCHES "Linux") diff --git a/server/tp_core/core/ts_main.cpp b/server/tp_core/core/ts_main.cpp index 386bb63..15d844a 100644 --- a/server/tp_core/core/ts_main.cpp +++ b/server/tp_core/core/ts_main.cpp @@ -150,10 +150,14 @@ bool TppManager::load_tpp(const ex_wstr& libname) ex_wstr filename; #ifdef EX_OS_WIN32 filename = libname + L".dll"; -#else +#elif defined (EX_OS_LINUX) filename = L"lib"; filename += libname; filename += L".so"; +#elif defined (EX_OS_MACOS) + filename = L"lib"; + filename += libname; + filename += L".dylib"; #endif ex_wstr libfile = g_env.m_exec_path; diff --git a/server/tp_core/protocol/ssh/CMakeLists.txt b/server/tp_core/protocol/ssh/CMakeLists.txt index b35d1e6..2d8983a 100644 --- a/server/tp_core/protocol/ssh/CMakeLists.txt +++ b/server/tp_core/protocol/ssh/CMakeLists.txt @@ -14,12 +14,36 @@ aux_source_directory(../../../../common/libex/src DIR_SSH_SRCS) list(REMOVE_ITEM DIR_SSH_SRCS "./dllmain.cpp") list(REMOVE_ITEM DIR_SSH_SRCS "./stdafx.cpp") + include_directories( - ../../../../common/libex/include - ../../../../external/linux/release/include + ../../../../common/libex/include + ../../../../common/teleport ) -link_directories(../../../../external/linux/release/lib) +IF (CMAKE_SYSTEM_NAME MATCHES "Linux") + include_directories( + ../../../../external/linux/release/include + ) + link_directories(../../../../external/linux/release/lib) +ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Darwin") + include_directories( + ../../../../external/macos/release/include + ) + link_directories(../../../../external/macos/release/lib) +ENDIF (CMAKE_SYSTEM_NAME MATCHES "Linux") + + +#include_directories( +# ../../../../common/libex/include +# ../../../../external/linux/release/include +#) +#link_directories(../../../../external/linux/release/lib) add_library(tpssh SHARED ${DIR_SSH_SRCS}) -target_link_libraries(tpssh ssh ssh_threads ssl crypto mbedx509 mbedtls mbedcrypto dl pthread rt util) +#target_link_libraries(tpssh ssh ssh_threads ssl crypto mbedx509 mbedtls mbedcrypto dl pthread rt util) + +IF (CMAKE_SYSTEM_NAME MATCHES "Linux") + target_link_libraries(tpssh ssh ssh_threads ssl crypto mbedx509 mbedtls mbedcrypto dl pthread rt util) +ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Darwin") + target_link_libraries(tpssh ssh ssh_threads ssl crypto mbedx509 mbedtls mbedcrypto dl pthread util) +ENDIF (CMAKE_SYSTEM_NAME MATCHES "Linux")