可以在MacOS上编译tp_core和libtpssh了 :)

pull/105/head
ApexLiu 2017-09-13 21:33:49 +08:00
parent b43fbc4382
commit 3e2f06a740
15 changed files with 143 additions and 42 deletions

1
.gitignore vendored
View File

@ -35,6 +35,7 @@ __pycache__
/out
/external/_download_
/external/linux
/external/macos
/external/jsoncpp
/external/mongoose
/external/openssl

View File

@ -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)

View File

@ -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.')

View File

@ -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

View File

@ -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:

View File

@ -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:

View File

@ -64,6 +64,9 @@
# include <sys/socket.h>
# include <netinet/in.h>
#endif
#ifdef EX_OS_MACOS
# include <mach-o/dyld.h> // for _NSGetExecutablePath
#endif
/*

View File

@ -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);

View File

@ -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;

View File

@ -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
}

View File

@ -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

View File

@ -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)

View File

@ -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")

View File

@ -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;

View File

@ -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")