2017-01-11 12:04:11 +00:00
# -*- coding: utf-8 -*-
2018-09-23 20:04:09 +00:00
import time
2017-01-11 12:04:11 +00:00
from core import colorconsole as cc
from core import utils
from core . context import *
2017-03-08 20:04:01 +00:00
from core . env import env
2017-01-11 12:04:11 +00:00
ctx = BuildContext ( )
2017-03-09 09:33:41 +00:00
PATH_EXTERNAL = os . path . join ( env . root_path , ' external ' )
2017-01-11 12:04:11 +00:00
PATH_DOWNLOAD = os . path . join ( PATH_EXTERNAL , ' _download_ ' )
class BuilderBase :
def __init__ ( self ) :
self . out_dir = ' '
if not os . path . exists ( PATH_DOWNLOAD ) :
utils . makedirs ( PATH_DOWNLOAD )
self . _init_path ( )
def _init_path ( self ) :
cc . e ( " this is a pure-virtual function. " )
2017-03-06 17:46:05 +00:00
def build_jsoncpp ( self ) :
2017-03-09 09:33:41 +00:00
file_name = ' jsoncpp- {} .zip ' . format ( env . ver_jsoncpp )
if not utils . download_file ( ' jsoncpp source tarball ' , ' https://github.com/open-source-parsers/jsoncpp/archive/ {} .zip ' . format ( env . ver_jsoncpp ) , PATH_DOWNLOAD , file_name ) :
2017-03-06 17:46:05 +00:00
return
self . _build_jsoncpp ( file_name )
def _build_jsoncpp ( self , file_name ) :
cc . e ( " this is a pure-virtual function. " )
def build_mongoose ( self ) :
2017-03-09 09:33:41 +00:00
file_name = ' mongoose- {} .zip ' . format ( env . ver_mongoose )
if not utils . download_file ( ' mongoose source tarball ' , ' https://github.com/cesanta/mongoose/archive/ {} .zip ' . format ( env . ver_mongoose ) , PATH_DOWNLOAD , file_name ) :
2017-03-06 17:46:05 +00:00
return
self . _build_mongoose ( file_name )
def _build_mongoose ( self , file_name ) :
cc . e ( " this is a pure-virtual function. " )
2018-09-21 18:12:53 +00:00
def build_openssl ( self ) :
file_name = ' openssl- {} .zip ' . format ( env . ver_ossl )
self . _build_openssl ( file_name )
def _build_openssl ( self , file_name ) :
2018-09-26 20:38:29 +00:00
_alt_ver = ' _ ' . join ( env . ver_ossl . split ( ' . ' ) )
2018-09-18 15:41:26 +00:00
if not utils . download_file ( ' openssl source tarball ' , ' https://github.com/openssl/openssl/archive/OpenSSL_ {} .zip ' . format ( _alt_ver ) , PATH_DOWNLOAD , file_name ) :
2018-09-26 20:38:29 +00:00
cc . e ( " can not download openssl source tarball. " )
2018-09-18 15:41:26 +00:00
return False
else :
return True
2017-01-11 12:04:11 +00:00
def build_libuv ( self ) :
2017-03-09 09:33:41 +00:00
file_name = ' libuv- {} .zip ' . format ( env . ver_libuv )
if not utils . download_file ( ' libuv source tarball ' , ' https://github.com/libuv/libuv/archive/v {} .zip ' . format ( env . ver_libuv ) , PATH_DOWNLOAD , file_name ) :
2017-01-11 12:04:11 +00:00
return
self . _build_libuv ( file_name )
def _build_libuv ( self , file_name ) :
cc . e ( " this is a pure-virtual function. " )
def build_mbedtls ( self ) :
2017-03-09 09:33:41 +00:00
file_name = ' mbedtls-mbedtls- {} .zip ' . format ( env . ver_mbedtls )
if not utils . download_file ( ' mbedtls source tarball ' , ' https://github.com/ARMmbed/mbedtls/archive/mbedtls- {} .zip ' . format ( env . ver_mbedtls ) , PATH_DOWNLOAD , file_name ) :
2017-01-11 12:04:11 +00:00
return
self . _build_mbedtls ( file_name )
def _build_mbedtls ( self , file_name ) :
cc . e ( " this is a pure-virtual function. " )
def build_libssh ( self ) :
2017-03-09 09:33:41 +00:00
file_name = ' libssh- {} .zip ' . format ( env . ver_libssh )
if not utils . download_file ( ' libssh source tarball ' , ' https://git.libssh.org/projects/libssh.git/snapshot/libssh- {} .zip ' . format ( env . ver_libssh ) , PATH_DOWNLOAD , file_name ) :
2017-01-11 12:04:11 +00:00
return
self . _build_libssh ( file_name )
def _build_libssh ( self , file_name ) :
cc . e ( " this is a pure-virtual function. " )
2018-09-16 13:52:10 +00:00
def prepare_python ( self ) :
self . _prepare_python ( )
2018-09-11 18:40:32 +00:00
2018-09-16 13:52:10 +00:00
def _prepare_python ( self ) :
2018-09-11 18:40:32 +00:00
cc . e ( " this is a pure-virtual function. " )
2017-01-11 12:04:11 +00:00
def fix_output ( self ) :
pass
2017-03-06 17:46:05 +00:00
2017-01-11 12:04:11 +00:00
class BuilderWin ( BuilderBase ) :
def __init__ ( self ) :
super ( ) . __init__ ( )
def _init_path ( self ) :
2018-09-21 18:12:53 +00:00
self . OPENSSL_PATH_SRC = os . path . join ( PATH_EXTERNAL , ' openssl ' )
2017-03-09 09:33:41 +00:00
self . JSONCPP_PATH_SRC = os . path . join ( PATH_EXTERNAL , ' jsoncpp ' )
self . MONGOOSE_PATH_SRC = os . path . join ( PATH_EXTERNAL , ' mongoose ' )
self . MBEDTLS_PATH_SRC = os . path . join ( PATH_EXTERNAL , ' mbedtls ' )
2017-04-07 03:54:02 +00:00
self . LIBUV_PATH_SRC = os . path . join ( PATH_EXTERNAL , ' libuv ' )
2018-09-21 18:12:53 +00:00
self . LIBSSH_PATH_SRC = os . path . join ( PATH_EXTERNAL , ' libssh ' )
2017-03-09 19:28:43 +00:00
2018-09-16 13:52:10 +00:00
def _prepare_python ( self ) :
2017-03-16 10:45:31 +00:00
cc . n ( ' prepare python header files ... ' , end = ' ' )
2018-09-16 13:52:10 +00:00
if os . path . exists ( os . path . join ( PATH_EXTERNAL , ' python ' , ' include ' , ' Python.h ' ) ) :
2017-03-16 10:45:31 +00:00
cc . w ( ' already exists, skip. ' )
return
cc . v ( ' ' )
2017-03-26 16:24:23 +00:00
2018-09-21 18:12:53 +00:00
_header_path = None
for p in sys . path :
if os . path . exists ( os . path . join ( p , ' include ' , ' Python.h ' ) ) :
_header_path = os . path . join ( p , ' include ' )
if _header_path is None :
cc . e ( ' \n can not locate python development include path in: ' )
for p in sys . path :
cc . e ( ' ' , p )
raise RuntimeError ( )
utils . copy_ex ( _header_path , os . path . join ( PATH_EXTERNAL , ' python ' , ' include ' ) )
def _build_openssl ( self , file_name ) :
2018-09-23 20:04:09 +00:00
cc . n ( ' build openssl static library from source code... ' )
2018-09-21 18:12:53 +00:00
2018-09-26 20:38:29 +00:00
if not super ( ) . _build_openssl ( file_name ) :
2017-03-09 09:33:41 +00:00
return
2017-03-26 16:24:23 +00:00
2018-09-21 18:12:53 +00:00
_chk_output = [
os . path . join ( self . OPENSSL_PATH_SRC , ' out32 ' , ' libeay32.lib ' ) ,
os . path . join ( self . OPENSSL_PATH_SRC , ' out32 ' , ' ssleay32.lib ' ) ,
os . path . join ( self . OPENSSL_PATH_SRC , ' inc32 ' , ' openssl ' , ' opensslconf.h ' ) ,
]
2017-03-09 19:28:43 +00:00
need_build = False
2018-09-21 18:12:53 +00:00
for f in _chk_output :
if not os . path . exists ( f ) :
need_build = True
break
2017-03-09 19:28:43 +00:00
if not need_build :
2018-09-26 20:38:29 +00:00
cc . n ( ' build openssl static library from source code... ' , end = ' ' )
2017-03-09 19:28:43 +00:00
cc . w ( ' already exists, skip. ' )
return
2017-03-26 16:24:23 +00:00
cc . v ( ' ' )
2017-03-09 19:28:43 +00:00
2018-09-21 18:12:53 +00:00
cc . n ( ' prepare openssl source code... ' )
_alt_ver = ' _ ' . join ( env . ver_ossl . split ( ' . ' ) )
if not os . path . exists ( self . OPENSSL_PATH_SRC ) :
utils . unzip ( os . path . join ( PATH_DOWNLOAD , file_name ) , PATH_EXTERNAL )
os . rename ( os . path . join ( PATH_EXTERNAL , ' openssl-OpenSSL_ {} ' . format ( _alt_ver ) ) , self . OPENSSL_PATH_SRC )
if not os . path . exists ( self . OPENSSL_PATH_SRC ) :
raise RuntimeError ( ' can not prepare openssl source code. ' )
else :
cc . w ( ' already exists, skip. ' )
2017-03-09 19:28:43 +00:00
2018-09-21 18:12:53 +00:00
os . chdir ( self . OPENSSL_PATH_SRC )
os . system ( ' " " {} " Configure VC-WIN32 " ' . format ( env . perl ) )
os . system ( r ' ms \ do_nasm ' )
2019-01-04 18:39:33 +00:00
# for vs2015
# utils.sys_exec(r'"{}\VC\bin\vcvars32.bat" && nmake -f ms\nt.mak'.format(env.visual_studio_path), direct_output=True)
# for vs2017 community
utils . sys_exec ( r ' " {} VC \ Auxiliary \ Build \ vcvars32.bat " && nmake -f ms \ nt.mak ' . format ( env . visual_studio_path ) , direct_output = True )
2018-09-21 18:12:53 +00:00
for f in _chk_output :
if not os . path . exists ( f ) :
raise RuntimeError ( ' build openssl static library from source code failed. ' )
def _build_libssh ( self , file_name ) :
cc . n ( ' build libssh static library from source code... ' , end = ' ' )
if not os . path . exists ( self . LIBSSH_PATH_SRC ) :
cc . v ( ' ' )
2017-03-09 19:28:43 +00:00
utils . unzip ( os . path . join ( PATH_DOWNLOAD , file_name ) , PATH_EXTERNAL )
2018-09-21 18:12:53 +00:00
os . rename ( os . path . join ( PATH_EXTERNAL , ' libssh- {} ' . format ( env . ver_libssh ) ) , self . LIBSSH_PATH_SRC )
2017-03-09 19:28:43 +00:00
2019-01-04 18:39:33 +00:00
# cc.n('fix libssh source code... ', end='')
# utils.ensure_file_exists(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', 'src', 'sftp.c'))
# utils.copy_file(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', 'src'), os.path.join(self.LIBSSH_PATH_SRC, 'src'), 'sftp.c')
2019-06-30 20:12:47 +00:00
cc . n ( ' fix libssh source code... ' , end = ' ' )
s_name = ' libssh- {} ' . format ( env . ver_libssh )
2019-06-29 10:57:59 +00:00
# utils.ensure_file_exists(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src', 'session.c'))
# utils.ensure_file_exists(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src', 'libcrypto.c'))
2019-06-30 20:12:47 +00:00
utils . ensure_file_exists ( os . path . join ( PATH_EXTERNAL , ' fix-external ' , ' libssh ' , s_name , ' src ' , ' libcrypto-compat.c ' ) )
2019-06-29 10:57:59 +00:00
# utils.copy_file(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src'), os.path.join(self.LIBSSH_PATH_SRC, 'src'), 'session.c')
# utils.copy_file(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src'), os.path.join(self.LIBSSH_PATH_SRC, 'src'), 'libcrypto.c')
2019-06-30 20:12:47 +00:00
utils . copy_file ( os . path . join ( PATH_EXTERNAL , ' fix-external ' , ' libssh ' , s_name , ' src ' ) , os . path . join ( self . LIBSSH_PATH_SRC , ' src ' ) , ' libcrypto-compat.c ' )
2017-03-09 19:28:43 +00:00
2018-09-21 18:12:53 +00:00
out_file_lib = os . path . join ( self . LIBSSH_PATH_SRC , ' lib ' , ctx . target_path , ' ssh.lib ' )
out_file_dll = os . path . join ( self . LIBSSH_PATH_SRC , ' lib ' , ctx . target_path , ' ssh.dll ' )
2017-03-09 19:28:43 +00:00
2018-09-26 20:38:29 +00:00
if os . path . exists ( out_file_lib ) and os . path . exists ( out_file_dll ) :
2017-03-09 19:28:43 +00:00
cc . w ( ' already exists, skip. ' )
2018-09-21 18:12:53 +00:00
return
cc . v ( ' ' )
2018-09-23 20:04:09 +00:00
cc . w ( ' On Windows, when build libssh, need you use cmake-gui.exe to generate solution file ' )
2018-12-27 18:58:59 +00:00
cc . w ( ' for Visual Studio 2017. Visit https://docs.tp4a.com for more details. ' )
2018-09-21 18:12:53 +00:00
cc . w ( ' \n Once the libssh.sln generated, press Enter to continue or Q to quit... ' , end = ' ' )
try :
x = env . input ( )
except EOFError :
x = ' q '
if x == ' q ' :
return
2017-03-09 19:28:43 +00:00
cc . i ( ' build libssh... ' )
2018-09-21 18:12:53 +00:00
sln_file = os . path . join ( self . LIBSSH_PATH_SRC , ' build ' , ' libssh.sln ' )
utils . msvc_build ( sln_file , ' ssh_shared ' , ctx . target_path , ' win32 ' , False )
utils . ensure_file_exists ( os . path . join ( self . LIBSSH_PATH_SRC , ' build ' , ' src ' , ctx . target_path , ' ssh.lib ' ) )
utils . ensure_file_exists ( os . path . join ( self . LIBSSH_PATH_SRC , ' build ' , ' src ' , ctx . target_path , ' ssh.dll ' ) )
utils . copy_file ( os . path . join ( self . LIBSSH_PATH_SRC , ' build ' , ' src ' , ctx . target_path ) , os . path . join ( self . LIBSSH_PATH_SRC , ' lib ' , ctx . target_path ) , ' ssh.lib ' )
utils . copy_file ( os . path . join ( self . LIBSSH_PATH_SRC , ' build ' , ' src ' , ctx . target_path ) , os . path . join ( self . LIBSSH_PATH_SRC , ' lib ' , ctx . target_path ) , ' ssh.dll ' )
utils . ensure_file_exists ( out_file_lib )
utils . ensure_file_exists ( out_file_dll )
2017-03-09 19:28:43 +00:00
2017-03-09 09:33:41 +00:00
def _build_jsoncpp ( self , file_name ) :
2017-03-09 19:28:43 +00:00
cc . n ( ' prepare jsoncpp source code... ' , end = ' ' )
2017-03-09 09:33:41 +00:00
if not os . path . exists ( self . JSONCPP_PATH_SRC ) :
2017-03-26 16:24:23 +00:00
cc . v ( ' ' )
2017-03-09 09:33:41 +00:00
utils . unzip ( os . path . join ( PATH_DOWNLOAD , file_name ) , PATH_EXTERNAL )
os . rename ( os . path . join ( PATH_EXTERNAL , ' jsoncpp- {} ' . format ( env . ver_jsoncpp ) ) , self . JSONCPP_PATH_SRC )
else :
cc . w ( ' already exists, skip. ' )
def _build_mongoose ( self , file_name ) :
2017-03-16 10:45:31 +00:00
cc . n ( ' prepare mongoose source code... ' , end = ' ' )
2017-03-09 09:33:41 +00:00
if not os . path . exists ( self . MONGOOSE_PATH_SRC ) :
2017-03-16 10:45:31 +00:00
cc . v ( ' ' )
2017-03-09 09:33:41 +00:00
utils . unzip ( os . path . join ( PATH_DOWNLOAD , file_name ) , PATH_EXTERNAL )
os . rename ( os . path . join ( PATH_EXTERNAL , ' mongoose- {} ' . format ( env . ver_mongoose ) ) , self . MONGOOSE_PATH_SRC )
else :
cc . w ( ' already exists, skip. ' )
def _build_mbedtls ( self , file_name ) :
2017-03-16 10:45:31 +00:00
cc . n ( ' prepare mbedtls source code... ' , end = ' ' )
2017-03-09 09:33:41 +00:00
if not os . path . exists ( self . MBEDTLS_PATH_SRC ) :
2017-03-16 10:45:31 +00:00
cc . v ( ' ' )
2017-03-09 09:33:41 +00:00
utils . unzip ( os . path . join ( PATH_DOWNLOAD , file_name ) , PATH_EXTERNAL )
os . rename ( os . path . join ( PATH_EXTERNAL , ' mbedtls-mbedtls- {} ' . format ( env . ver_mbedtls ) ) , self . MBEDTLS_PATH_SRC )
else :
cc . w ( ' already exists, skip. ' )
2017-04-07 03:54:02 +00:00
return
cc . v ( ' ' )
# fix source file
utils . ensure_file_exists ( os . path . join ( PATH_EXTERNAL , ' fix-external ' , ' mbedtls ' , ' include ' , ' mbedtls ' , ' config.h ' ) )
utils . copy_file ( os . path . join ( PATH_EXTERNAL , ' fix-external ' , ' mbedtls ' , ' include ' , ' mbedtls ' ) , os . path . join ( self . MBEDTLS_PATH_SRC , ' include ' , ' mbedtls ' ) , ' config.h ' )
2018-09-21 18:12:53 +00:00
# utils.ensure_file_exists(os.path.join(PATH_EXTERNAL, 'fix-external', 'mbedtls', 'library', 'rsa.c'))
# utils.copy_file(os.path.join(PATH_EXTERNAL, 'fix-external', 'mbedtls', 'library'), os.path.join(self.MBEDTLS_PATH_SRC, 'library'), 'rsa.c')
2017-04-07 03:54:02 +00:00
def _build_libuv ( self , file_name ) :
cc . n ( ' prepare libuv source code... ' , end = ' ' )
if not os . path . exists ( self . LIBUV_PATH_SRC ) :
cc . v ( ' ' )
utils . unzip ( os . path . join ( PATH_DOWNLOAD , file_name ) , PATH_EXTERNAL )
2018-09-23 20:04:09 +00:00
time . sleep ( 1 ) # wait for a while, otherwise rename may fail.
2017-04-07 03:54:02 +00:00
os . rename ( os . path . join ( PATH_EXTERNAL , ' libuv- {} ' . format ( env . ver_libuv ) ) , self . LIBUV_PATH_SRC )
else :
cc . w ( ' already exists, skip. ' )
2017-01-11 12:04:11 +00:00
def fix_output ( self ) :
pass
class BuilderLinux ( BuilderBase ) :
def __init__ ( self ) :
super ( ) . __init__ ( )
def _init_path ( self ) :
self . PATH_TMP = os . path . join ( PATH_EXTERNAL , ' linux ' , ' tmp ' )
self . PATH_RELEASE = os . path . join ( PATH_EXTERNAL , ' linux ' , ' release ' )
2017-03-09 09:33:41 +00:00
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 ) )
2017-01-11 12:04:11 +00:00
2017-03-06 17:46:05 +00:00
self . JSONCPP_PATH_SRC = os . path . join ( PATH_EXTERNAL , ' jsoncpp ' )
self . MONGOOSE_PATH_SRC = os . path . join ( PATH_EXTERNAL , ' mongoose ' )
2017-01-11 12:04:11 +00:00
if not os . path . exists ( self . PATH_TMP ) :
utils . makedirs ( self . PATH_TMP )
2018-09-16 13:52:10 +00:00
def _prepare_python ( self ) :
cc . n ( ' prepare python header and lib files ... ' )
if os . path . exists ( os . path . join ( self . PATH_RELEASE , ' include ' , ' python ' , ' Python.h ' ) ) :
cc . w ( ' - header file already exists, skip. ' )
else :
2018-09-23 09:38:13 +00:00
utils . ensure_file_exists ( os . path . join ( self . PATH_RELEASE , ' include ' , ' python {} m ' . format ( ctx . py_dot_ver ) , ' Python.h ' ) )
utils . sys_exec ( ' ln -s " {} " " {} " ' . format (
os . path . join ( self . PATH_RELEASE , ' include ' , ' python {} m ' . format ( ctx . py_dot_ver ) ) ,
os . path . join ( self . PATH_RELEASE , ' include ' , ' python ' )
) )
2018-09-16 13:52:10 +00:00
lib_file = ' libpython {} m.a ' . format ( env . py_ver_dot )
2018-09-23 09:38:13 +00:00
utils . ensure_file_exists ( os . path . join ( self . PATH_RELEASE , ' lib ' , lib_file ) )
2018-09-16 13:52:10 +00:00
2017-03-06 17:46:05 +00:00
def _build_jsoncpp ( self , file_name ) :
2017-03-26 16:24:23 +00:00
cc . n ( ' prepare jsoncpp source code... ' , end = ' ' )
2017-03-06 17:46:05 +00:00
if not os . path . exists ( self . JSONCPP_PATH_SRC ) :
2017-03-26 16:24:23 +00:00
cc . v ( ' ' )
2017-03-06 17:46:05 +00:00
os . system ( ' unzip " {} / {} " -d " {} " ' . format ( PATH_DOWNLOAD , file_name , PATH_EXTERNAL ) )
2017-03-09 09:33:41 +00:00
os . rename ( os . path . join ( PATH_EXTERNAL , ' jsoncpp- {} ' . format ( env . ver_jsoncpp ) ) , self . JSONCPP_PATH_SRC )
2017-03-06 17:46:05 +00:00
else :
cc . w ( ' already exists, skip. ' )
2017-01-11 12:04:11 +00:00
2017-03-06 17:46:05 +00:00
def _build_mongoose ( self , file_name ) :
2017-03-26 16:24:23 +00:00
cc . n ( ' prepare mongoose source code... ' , end = ' ' )
2017-03-06 17:46:05 +00:00
if not os . path . exists ( self . MONGOOSE_PATH_SRC ) :
2017-03-26 16:24:23 +00:00
cc . v ( ' ' )
2017-03-06 17:46:05 +00:00
os . system ( ' unzip " {} / {} " -d " {} " ' . format ( PATH_DOWNLOAD , file_name , PATH_EXTERNAL ) )
2017-03-09 09:33:41 +00:00
os . rename ( os . path . join ( PATH_EXTERNAL , ' mongoose- {} ' . format ( env . ver_mongoose ) ) , self . MONGOOSE_PATH_SRC )
2017-03-06 17:46:05 +00:00
else :
2017-01-11 12:04:11 +00:00
cc . w ( ' already exists, skip. ' )
2018-09-21 18:12:53 +00:00
def _build_openssl ( self , file_name ) :
2019-01-29 12:18:48 +00:00
# we do not need build openssl anymore, because first time run build.sh we built Python with openssl included.
pass
2017-03-08 20:04:01 +00:00
2017-01-11 12:04:11 +00:00
def _build_libuv ( self , file_name ) :
if not os . path . exists ( self . LIBUV_PATH_SRC ) :
os . system ( ' unzip " {} / {} " -d " {} " ' . format ( PATH_DOWNLOAD , file_name , self . PATH_TMP ) )
2017-03-26 16:24:23 +00:00
cc . n ( ' build libuv... ' , end = ' ' )
2017-01-11 12:04:11 +00:00
if os . path . exists ( os . path . join ( self . PATH_RELEASE , ' lib ' , ' libuv.a ' ) ) :
cc . w ( ' already exists, skip. ' )
return
2017-03-26 16:24:23 +00:00
cc . v ( ' ' )
2017-01-11 12:04:11 +00:00
# we need following...
# apt-get install autoconf aptitude libtool gcc-c++
old_p = os . getcwd ( )
os . chdir ( self . LIBUV_PATH_SRC )
os . system ( ' sh autogen.sh ' )
2017-04-12 11:02:03 +00:00
os . system ( ' ./configure --prefix= {} --with-pic ' . format ( self . PATH_RELEASE ) )
2017-01-11 12:04:11 +00:00
os . system ( ' make ' )
os . system ( ' make install ' )
os . chdir ( old_p )
2018-09-23 09:38:13 +00:00
files = os . listdir ( os . path . join ( self . PATH_RELEASE , ' lib ' ) )
for i in files :
if i . startswith ( ' libuv.so ' ) or i . startswith ( ' libuv.la ' ) :
# use os.unlink() because some file should be a link.
os . unlink ( os . path . join ( self . PATH_RELEASE , ' lib ' , i ) )
2019-01-29 12:18:48 +00:00
utils . ensure_file_exists ( os . path . join ( self . PATH_RELEASE , ' lib ' , ' libuv.a ' ) )
2017-01-11 12:04:11 +00:00
def _build_mbedtls ( self , file_name ) :
if not os . path . exists ( self . MBEDTLS_PATH_SRC ) :
os . system ( ' unzip " {} / {} " -d " {} " ' . format ( PATH_DOWNLOAD , file_name , self . PATH_TMP ) )
2017-03-26 16:24:23 +00:00
cc . n ( ' build mbedtls... ' , end = ' ' )
2017-01-11 12:04:11 +00:00
if os . path . exists ( os . path . join ( self . PATH_RELEASE , ' lib ' , ' libmbedtls.a ' ) ) :
cc . w ( ' already exists, skip. ' )
return
2017-03-26 16:24:23 +00:00
cc . v ( ' ' )
2017-01-11 12:04:11 +00:00
# fix the Makefile
mkfile = os . path . join ( self . MBEDTLS_PATH_SRC , ' Makefile ' )
f = open ( mkfile )
fl = f . readlines ( )
f . close ( )
fixed = False
for i in range ( len ( fl ) ) :
x = fl [ i ] . split ( ' = ' )
if x [ 0 ] == ' DESTDIR ' :
fl [ i ] = ' DESTDIR= {} \n ' . format ( self . PATH_RELEASE )
fixed = True
break
if not fixed :
cc . e ( ' can not fix Makefile of mbedtls. ' )
return
f = open ( mkfile , ' w ' )
f . writelines ( fl )
f . close ( )
# fix source file
2017-04-07 03:54:02 +00:00
utils . ensure_file_exists ( os . path . join ( PATH_EXTERNAL , ' fix-external ' , ' mbedtls ' , ' include ' , ' mbedtls ' , ' config.h ' ) )
utils . copy_file ( os . path . join ( PATH_EXTERNAL , ' fix-external ' , ' mbedtls ' , ' include ' , ' mbedtls ' ) , os . path . join ( self . MBEDTLS_PATH_SRC , ' include ' , ' mbedtls ' ) , ' config.h ' )
2017-01-11 12:04:11 +00:00
old_p = os . getcwd ( )
os . chdir ( self . MBEDTLS_PATH_SRC )
2017-04-12 11:02:03 +00:00
os . system ( ' make CFLAGS= " -fPIC " lib ' )
2017-01-11 12:04:11 +00:00
os . system ( ' make install ' )
os . chdir ( old_p )
def _build_libssh ( self , file_name ) :
if not os . path . exists ( self . LIBSSH_PATH_SRC ) :
os . system ( ' unzip " {} / {} " -d " {} " ' . format ( PATH_DOWNLOAD , file_name , self . PATH_TMP ) )
2017-03-26 16:24:23 +00:00
cc . n ( ' build libssh... ' , end = ' ' )
2018-09-23 09:38:13 +00:00
if os . path . exists ( os . path . join ( self . PATH_RELEASE , ' lib ' , ' libssh.a ' ) ) :
2017-01-11 12:04:11 +00:00
cc . w ( ' already exists, skip. ' )
return
2017-03-26 16:24:23 +00:00
cc . v ( ' ' )
2017-01-11 12:04:11 +00:00
2019-06-30 20:12:47 +00:00
cc . n ( ' fix libssh source code... ' , end = ' ' )
s_name = ' libssh- {} ' . format ( env . ver_libssh )
2019-06-29 10:57:59 +00:00
# utils.ensure_file_exists(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src', 'session.c'))
# utils.ensure_file_exists(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src', 'libcrypto.c'))
2019-06-30 20:12:47 +00:00
utils . ensure_file_exists ( os . path . join ( PATH_EXTERNAL , ' fix-external ' , ' libssh ' , s_name , ' src ' , ' libcrypto-compat.c ' ) )
2019-06-29 10:57:59 +00:00
# utils.copy_file(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src'), os.path.join(self.LIBSSH_PATH_SRC, 'src'), 'session.c')
# utils.copy_file(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src'), os.path.join(self.LIBSSH_PATH_SRC, 'src'), 'libcrypto.c')
2019-06-30 20:12:47 +00:00
utils . copy_file ( os . path . join ( PATH_EXTERNAL , ' fix-external ' , ' libssh ' , s_name , ' src ' ) , os . path . join ( self . LIBSSH_PATH_SRC , ' src ' ) , ' libcrypto-compat.c ' )
2019-01-03 08:10:44 +00:00
2017-01-11 12:04:11 +00:00
build_path = os . path . join ( self . LIBSSH_PATH_SRC , ' build ' )
2018-09-23 09:38:13 +00:00
cmake_define = ' -DCMAKE_INSTALL_PREFIX= {path_release} ' \
' -DOPENSSL_INCLUDE_DIR= {path_release} /include ' \
' -DOPENSSL_LIBRARIES= {path_release} /lib ' \
2017-12-27 19:34:43 +00:00
' -DWITH_SFTP=ON ' \
' -DWITH_SERVER=ON ' \
' -DWITH_STATIC_LIB=ON ' \
2017-03-08 20:04:01 +00:00
' -DWITH_GSSAPI=OFF ' \
' -DWITH_ZLIB=OFF ' \
' -DWITH_PCAP=OFF ' \
2018-09-23 09:38:13 +00:00
' -DUNIT_TESTING=OFF ' \
2017-03-08 20:04:01 +00:00
' -DWITH_EXAMPLES=OFF ' \
' -DWITH_BENCHMARKS=OFF ' \
' -DWITH_NACL=OFF ' \
2018-09-23 09:38:13 +00:00
' .. ' . format ( path_release = self . PATH_RELEASE )
2017-03-08 20:04:01 +00:00
2018-09-23 09:38:13 +00:00
old_p = os . getcwd ( )
2017-03-15 10:17:02 +00:00
try :
2018-09-23 18:47:50 +00:00
utils . cmake ( build_path , ' Release ' , False , cmake_define = cmake_define , cmake_pre_define = ' CFLAGS= " -fPIC " ' )
2018-09-23 09:38:13 +00:00
os . chdir ( build_path )
utils . sys_exec ( ' make install ' )
2017-03-15 10:17:02 +00:00
except :
pass
2018-09-23 09:38:13 +00:00
os . chdir ( old_p )
2017-01-11 12:04:11 +00:00
2018-09-23 09:38:13 +00:00
utils . ensure_file_exists ( os . path . join ( self . PATH_RELEASE , ' lib ' , ' libssh.a ' ) )
files = os . listdir ( os . path . join ( self . PATH_RELEASE , ' lib ' ) )
for i in files :
if i . startswith ( ' libssh.so ' ) :
# use os.unlink() because some file should be a link.
os . unlink ( os . path . join ( self . PATH_RELEASE , ' lib ' , i ) )
2017-01-11 12:04:11 +00:00
def fix_output ( self ) :
2018-09-23 09:38:13 +00:00
pass
2017-01-11 12:04:11 +00:00
2017-06-05 18:22:52 +00:00
class BuilderMacOS ( BuilderBase ) :
def __init__ ( self ) :
super ( ) . __init__ ( )
def _init_path ( self ) :
self . PATH_TMP = os . path . join ( PATH_EXTERNAL , ' macos ' , ' tmp ' )
self . PATH_RELEASE = os . path . join ( PATH_EXTERNAL , ' macos ' , ' release ' )
2018-09-26 20:38:29 +00:00
self . OPENSSL_PATH_SRC = os . path . join ( self . PATH_TMP , ' openssl-OpenSSL_ {} ' . format ( env . ver_ossl . replace ( ' . ' , ' _ ' ) ) )
2017-06-05 18:22:52 +00:00
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 ) )
self . JSONCPP_PATH_SRC = os . path . join ( PATH_EXTERNAL , ' jsoncpp ' )
self . MONGOOSE_PATH_SRC = os . path . join ( PATH_EXTERNAL , ' mongoose ' )
if not os . path . exists ( self . PATH_TMP ) :
utils . makedirs ( self . PATH_TMP )
def _build_jsoncpp ( self , file_name ) :
cc . n ( ' prepare jsoncpp source code... ' , end = ' ' )
if not os . path . exists ( self . JSONCPP_PATH_SRC ) :
cc . v ( ' ' )
os . system ( ' unzip " {} / {} " -d " {} " ' . format ( PATH_DOWNLOAD , file_name , PATH_EXTERNAL ) )
os . rename ( os . path . join ( PATH_EXTERNAL , ' jsoncpp- {} ' . format ( env . ver_jsoncpp ) ) , self . JSONCPP_PATH_SRC )
else :
cc . w ( ' already exists, skip. ' )
def _build_mongoose ( self , file_name ) :
cc . n ( ' prepare mongoose source code... ' , end = ' ' )
if not os . path . exists ( self . MONGOOSE_PATH_SRC ) :
cc . v ( ' ' )
os . system ( ' unzip " {} / {} " -d " {} " ' . format ( PATH_DOWNLOAD , file_name , PATH_EXTERNAL ) )
os . rename ( os . path . join ( PATH_EXTERNAL , ' mongoose- {} ' . format ( env . ver_mongoose ) ) , self . MONGOOSE_PATH_SRC )
else :
cc . w ( ' already exists, skip. ' )
2018-09-21 18:12:53 +00:00
def _build_openssl ( self , file_name ) :
2018-09-26 20:38:29 +00:00
if not super ( ) . _build_openssl ( file_name ) :
return
2018-12-20 13:11:32 +00:00
cc . n ( ' prepare openssl source code... ' , end = ' ' )
2018-09-26 20:38:29 +00:00
if not os . path . exists ( self . OPENSSL_PATH_SRC ) :
os . system ( ' unzip " {} / {} " -d " {} " ' . format ( PATH_DOWNLOAD , file_name , self . PATH_TMP ) )
if not os . path . exists ( self . OPENSSL_PATH_SRC ) :
raise RuntimeError ( ' can not prepare openssl source code. ' )
else :
cc . w ( ' already exists, skip. ' )
cc . n ( ' build openssl static... ' , end = ' ' )
out_file_lib = os . path . join ( self . PATH_RELEASE , ' lib ' , ' libssl.a ' )
if os . path . exists ( out_file_lib ) :
cc . w ( ' already exists, skip. ' )
return
cc . v ( ' ' )
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 )
2017-06-05 18:22:52 +00:00
def _build_libuv ( self , file_name ) :
2018-03-01 01:07:49 +00:00
cc . n ( ' prepare libuv source code... ' , end = ' ' )
2017-06-05 18:22:52 +00:00
if not os . path . exists ( self . LIBUV_PATH_SRC ) :
os . system ( ' unzip " {} / {} " -d " {} " ' . format ( PATH_DOWNLOAD , file_name , self . PATH_TMP ) )
cc . n ( ' build libuv... ' , end = ' ' )
if os . path . exists ( os . path . join ( self . PATH_RELEASE , ' lib ' , ' libuv.a ' ) ) :
cc . w ( ' already exists, skip. ' )
return
cc . v ( ' ' )
# we need following...
2018-02-16 07:40:02 +00:00
# brew install automake libtool
2017-06-05 18:22:52 +00:00
old_p = os . getcwd ( )
os . chdir ( self . LIBUV_PATH_SRC )
os . system ( ' sh autogen.sh ' )
os . system ( ' ./configure --prefix= {} --with-pic ' . format ( self . PATH_RELEASE ) )
os . system ( ' make ' )
os . system ( ' make install ' )
os . chdir ( old_p )
def _build_mbedtls ( self , file_name ) :
if not os . path . exists ( self . MBEDTLS_PATH_SRC ) :
os . system ( ' unzip " {} / {} " -d " {} " ' . format ( PATH_DOWNLOAD , file_name , self . PATH_TMP ) )
cc . n ( ' build mbedtls... ' , end = ' ' )
if os . path . exists ( os . path . join ( self . PATH_RELEASE , ' lib ' , ' libmbedtls.a ' ) ) :
cc . w ( ' already exists, skip. ' )
return
cc . v ( ' ' )
# fix the Makefile
mkfile = os . path . join ( self . MBEDTLS_PATH_SRC , ' Makefile ' )
f = open ( mkfile )
fl = f . readlines ( )
f . close ( )
fixed = False
for i in range ( len ( fl ) ) :
x = fl [ i ] . split ( ' = ' )
if x [ 0 ] == ' DESTDIR ' :
fl [ i ] = ' DESTDIR= {} \n ' . format ( self . PATH_RELEASE )
fixed = True
break
if not fixed :
cc . e ( ' can not fix Makefile of mbedtls. ' )
return
f = open ( mkfile , ' w ' )
f . writelines ( fl )
f . close ( )
# fix source file
utils . ensure_file_exists ( os . path . join ( PATH_EXTERNAL , ' fix-external ' , ' mbedtls ' , ' include ' , ' mbedtls ' , ' config.h ' ) )
utils . copy_file ( os . path . join ( PATH_EXTERNAL , ' fix-external ' , ' mbedtls ' , ' include ' , ' mbedtls ' ) , os . path . join ( self . MBEDTLS_PATH_SRC , ' include ' , ' mbedtls ' ) , ' config.h ' )
2018-09-16 13:52:10 +00:00
# utils.ensure_file_exists(os.path.join(PATH_EXTERNAL, 'fix-external', 'mbedtls', 'library', 'rsa.c'))
# utils.copy_file(os.path.join(PATH_EXTERNAL, 'fix-external', 'mbedtls', 'library'), os.path.join(self.MBEDTLS_PATH_SRC, 'library'), 'rsa.c')
2017-06-05 18:22:52 +00:00
old_p = os . getcwd ( )
os . chdir ( self . MBEDTLS_PATH_SRC )
os . system ( ' make CFLAGS= " -fPIC " lib ' )
os . system ( ' make install ' )
os . chdir ( old_p )
def _build_libssh ( self , file_name ) :
if not os . path . exists ( self . LIBSSH_PATH_SRC ) :
os . system ( ' unzip " {} / {} " -d " {} " ' . format ( PATH_DOWNLOAD , file_name , self . PATH_TMP ) )
cc . n ( ' build libssh... ' , end = ' ' )
2018-12-20 13:11:32 +00:00
# if os.path.exists(os.path.join(self.PATH_RELEASE, 'lib', 'libssh.a')) and os.path.exists(os.path.join(self.PATH_RELEASE, 'lib', 'libssh_threads.a')):
if os . path . exists ( os . path . join ( self . PATH_RELEASE , ' lib ' , ' libssh.a ' ) ) :
2017-06-05 18:22:52 +00:00
cc . w ( ' already exists, skip. ' )
return
cc . v ( ' ' )
build_path = os . path . join ( self . LIBSSH_PATH_SRC , ' build ' )
2018-09-26 20:38:29 +00:00
cmake_define = ' -DCMAKE_INSTALL_PREFIX= {path_release} ' \
' -DOPENSSL_INCLUDE_DIR= {path_release} /include ' \
' -DOPENSSL_LIBRARIES= {path_release} /lib ' \
' -DWITH_SFTP=ON ' \
' -DWITH_SERVER=ON ' \
' -DWITH_STATIC_LIB=ON ' \
2017-06-05 18:22:52 +00:00
' -DWITH_GSSAPI=OFF ' \
' -DWITH_ZLIB=OFF ' \
' -DWITH_PCAP=OFF ' \
2018-09-26 20:38:29 +00:00
' -DUNIT_TESTING=OFF ' \
2017-06-05 18:22:52 +00:00
' -DWITH_EXAMPLES=OFF ' \
' -DWITH_BENCHMARKS=OFF ' \
' -DWITH_NACL=OFF ' \
2018-09-26 20:38:29 +00:00
' ' . format ( path_release = self . PATH_RELEASE )
2017-06-05 18:22:52 +00:00
try :
utils . cmake ( build_path , ' Release ' , False , cmake_define )
except :
pass
# because make install will fail because we can not disable ssh_shared target,
# so we copy necessary files ourselves.
utils . ensure_file_exists ( os . path . join ( self . LIBSSH_PATH_SRC , ' build ' , ' src ' , ' libssh.a ' ) )
2018-09-26 20:38:29 +00:00
# utils.ensure_file_exists(os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', 'threads', 'libssh_threads.a'))
2017-06-05 18:22:52 +00:00
utils . copy_file ( os . path . join ( self . LIBSSH_PATH_SRC , ' build ' , ' src ' ) , os . path . join ( self . PATH_RELEASE , ' lib ' ) , ' libssh.a ' )
2018-09-26 20:38:29 +00:00
# utils.copy_file(os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', 'threads'), os.path.join(self.PATH_RELEASE, 'lib'), 'libssh_threads.a')
2017-06-05 18:22:52 +00:00
utils . copy_ex ( os . path . join ( self . LIBSSH_PATH_SRC , ' include ' ) , os . path . join ( self . PATH_RELEASE , ' include ' ) , ' libssh ' )
2018-09-26 20:38:29 +00:00
def _prepare_python ( self ) :
pass
2018-09-11 18:40:32 +00:00
2017-06-05 18:22:52 +00:00
def fix_output ( self ) :
# remove .so files, otherwise will link to .so but not .a in default.
# rm = ['libsqlite3.la', 'libsqlite3.so.0', 'libsqlite3.so', 'libsqlite3.so.0.8.6', 'libuv.la', 'libuv.so.1', 'libuv.so', 'libuv.so.1.0.0']
2018-09-26 20:38:29 +00:00
rm = [ ' libuv.la ' , ' libuv.dylib ' , ' libuv.so.1 ' , ' libuv.so ' , ' libuv.so.1.0.0 ' ]
2017-06-05 18:22:52 +00:00
for i in rm :
_path = os . path . join ( self . PATH_RELEASE , ' lib ' , i )
if os . path . exists ( _path ) :
utils . remove ( _path )
2017-01-11 12:04:11 +00:00
def gen_builder ( dist ) :
if dist == ' windows ' :
builder = BuilderWin ( )
elif dist == ' linux ' :
builder = BuilderLinux ( )
2017-06-05 18:22:52 +00:00
elif dist == ' macos ' :
builder = BuilderMacOS ( )
2017-01-11 12:04:11 +00:00
else :
raise RuntimeError ( ' unsupported platform. ' )
ctx . set_dist ( dist )
return builder
def main ( ) :
2017-03-08 20:04:01 +00:00
if not env . init ( ) :
return
2017-01-11 12:04:11 +00:00
builder = None
argv = sys . argv [ 1 : ]
for i in range ( len ( argv ) ) :
if ' debug ' == argv [ i ] :
ctx . set_target ( TARGET_DEBUG )
elif ' x86 ' == argv [ i ] :
ctx . set_bits ( BITS_32 )
elif ' x64 ' == argv [ i ] :
ctx . set_bits ( BITS_64 )
elif argv [ i ] in ctx . dist_all :
builder = gen_builder ( argv [ i ] )
if builder is None :
builder = gen_builder ( ctx . host_os )
2018-09-16 13:52:10 +00:00
builder . prepare_python ( )
2017-03-06 17:46:05 +00:00
builder . build_jsoncpp ( )
builder . build_mongoose ( )
2018-09-21 18:12:53 +00:00
builder . build_openssl ( )
2017-04-07 03:54:02 +00:00
builder . build_libuv ( )
2017-01-11 12:04:11 +00:00
builder . build_mbedtls ( )
builder . build_libssh ( )
2017-04-30 17:46:11 +00:00
2017-04-12 18:08:33 +00:00
builder . fix_output ( )
2017-01-11 12:04:11 +00:00
if __name__ == ' __main__ ' :
try :
main ( )
except KeyboardInterrupt :
pass
except RuntimeError as e :
cc . e ( e . __str__ ( ) )
except :
cc . f ( ' got exception. ' )