示例#1
0
    def _build_libuv(self, file_name):
        cc.w('build libuv...skip')
        return
        if not os.path.exists(self.LIBUV_PATH_SRC):
            # os.system('tar -zxvf "{}/{}" -C "{}"'.format(PATH_DOWNLOAD, file_name, PATH_TMP))
            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...
        # apt-get install autoconf aptitude libtool gcc-c++

        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)
示例#2
0
    def _prompt_choice(message, choices):
        cc.v('{} ['.format(message), end='')

        def_choice = ''

        for i in range(len(choices)):
            if i > 0:
                cc.v('/', end='')
            msg = choices[i][0]
            idx = choices[i][1]
            if choices[i][2]:
                msg = msg.upper()
                def_choice = msg[idx].lower()
                cc.w(msg[:idx], end='')
                cc.n(msg[idx], end='')
                cc.w(msg[idx + 1:], end='')
            else:
                msg = msg.lower()
                cc.v(msg[:idx], end='')
                cc.n(msg[idx], end='')
                cc.v(msg[idx + 1:], end='')

        cc.v(']: ', end='')
        try:
            x = input().strip()
            if len(x) == 0:
                x = def_choice
        except EOFError:
            x = def_choice

        return x
示例#3
0
    def _build_openssl(self, file_name):
        cc.n('prepare OpenSSL pre-built package ... ', end='')
        if os.path.exists(self.OPENSSL_PATH_SRC):
            cc.w('already exists, skip.')
            return
        cc.v('')

        _alt_ver = '_'.join(env.ver_ossl.split('.'))

        file_name = 'Win32OpenSSL-{}.msi'.format(_alt_ver)
        installer = os.path.join(PATH_DOWNLOAD, file_name)

        if not os.path.exists(installer):
            if not utils.download_file(
                    'openssl installer',
                    'http://slproweb.com/download/{}'.format(filename),
                    PATH_DOWNLOAD, file_name):
                cc.e('can not download pre-built installer of OpenSSL.')
                return

        utils.ensure_file_exists(installer)

        cc.w('On Windows, we use pre-built package of OpenSSL.')
        cc.w('The installer have been downloaded at "{}".'.format(installer))
        cc.w('please install OpenSSL into "{}".'.format(self.OPENSSL_PATH_SRC))
        cc.w(
            '\nOnce the OpenSSL installed, press Enter to continue or Q to quit...',
            end='')
        try:
            x = env.input()
        except EOFError:
            x = 'q'
        if x == 'q':
            return
示例#4
0
    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))

        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...
        # apt-get install autoconf aptitude libtool gcc-c++

        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)

        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))
示例#5
0
    def _build_libuv(self, file_name):
        if not self._download_libuv(file_name):
            return
        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...
        # apt-get install autoconf aptitude libtool gcc-c++

        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)

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

        utils.ensure_file_exists(
            os.path.join(self.PATH_RELEASE, 'lib', 'libuv.a'))
示例#6
0
    def _build_openssl(self, file_name):
        if not super()._build_openssl(file_name):
            return

        cc.n('prepare openssl source code...', end='')
        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)
示例#7
0
    def _build_libuv(self, file_name):
        if not self._download_libuv(file_name):
            return
        cc.n('prepare libuv source code...', end='')
        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...
        # brew install automake libtool

        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)

        rm = [
            'libuv.la', 'libuv.dylib', 'libuv.so.1', 'libuv.so',
            'libuv.so.1.0.0'
        ]
        for i in rm:
            _path = os.path.join(self.PATH_RELEASE, 'lib', i)
            if os.path.exists(_path):
                utils.remove(_path)
示例#8
0
    def _prepare_python(self):
        cc.n('prepare python header files ...', end='')

        if os.path.exists(
                os.path.join(PATH_EXTERNAL, 'python', 'include', 'Python.h')):
            cc.w('already exists, skip.')
            return
        cc.v('')

        # if os.path.exists(os.path.join(env.path_py_inc, 'Python.h')):
        #     cc.e('can not locate python development include path, make sure miniconda installed.')
        #     return
        # cc.v('')
        # utils.copy_ex(env.path_py_inc, os.path.join(PATH_EXTERNAL, 'python', 'include'))

        _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('\ncan 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'))
示例#9
0
    def _build_openssl(self, file_name):
        if not super()._build_openssl(file_name):
            return

        cc.n('prepare openssl source code...', end='')
        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)
示例#10
0
    def _build_mbedtls(self, file_name):
        cc.n('prepare mbedtls source code... ', end='')
        if not os.path.exists(self.MBEDTLS_PATH_SRC):
            cc.v('')
            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.')
            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')
        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')
示例#11
0
 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.')
示例#12
0
 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.')
示例#13
0
 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)
         time.sleep(1)   # wait for a while, otherwise rename may fail.
         os.rename(os.path.join(PATH_EXTERNAL, 'libuv-{}'.format(env.ver_libuv)), self.LIBUV_PATH_SRC)
     else:
         cc.w('already exists, skip.')
示例#14
0
    def _build_mbedtls(self, file_name):
        if not os.path.exists(self.MBEDTLS_PATH_SRC):
            # os.system('tar -zxvf "{}/{}" -C "{}"'.format(PATH_DOWNLOAD, file_name, PATH_TMP))
            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')
        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')

        old_p = os.getcwd()
        os.chdir(self.MBEDTLS_PATH_SRC)
        os.system('make CFLAGS="-fPIC" lib')
        os.system('make install')
        os.chdir(old_p)
示例#15
0
 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)
         os.rename(
             os.path.join(PATH_EXTERNAL, 'libuv-{}'.format(env.ver_libuv)),
             self.LIBUV_PATH_SRC)
     else:
         cc.w('already exists, skip.')
示例#16
0
    def _build_openssl(self, file_name):
        cc.n('prepare OpenSSL pre-built package ... ', end='')
        if os.path.exists(self.OPENSSL_PATH_SRC):
            cc.w('already exists, skip.')
            return
        cc.v('')

        _alt_ver = '_'.join(env.ver_ossl.split('.'))

        file_name = 'Win32OpenSSL-{}.msi'.format(_alt_ver)
        installer = os.path.join(PATH_DOWNLOAD, file_name)

        if not os.path.exists(installer):
            if not utils.download_file(
                    'openssl installer',
                    'http://slproweb.com/download/{}'.format(filename),
                    PATH_DOWNLOAD, file_name):
                cc.e('can not download pre-built installer of OpenSSL.')
                return

        utils.ensure_file_exists(installer)

        cc.w('On Windows, we use pre-built package of OpenSSL.')
        cc.w('The installer have been downloaded at "{}".'.format(installer))
        cc.w('please install OpenSSL into "{}".'.format(self.OPENSSL_PATH_SRC))
        cc.w(
            '\nOnce the OpenSSL installed, press Enter to continue or Q to quit...',
            end='')
        try:
            x = input()
        except EOFError:
            x = 'q'
        if x == 'q':
            return

        _chk_output = [
            os.path.join(self.OPENSSL_PATH_SRC, 'include', 'openssl', 'aes.h'),
            os.path.join(self.OPENSSL_PATH_SRC, 'include', 'openssl',
                         'opensslv.h'),
            os.path.join(self.OPENSSL_PATH_SRC, 'lib', 'VC',
                         'libcrypto32MT.lib'),
            os.path.join(self.OPENSSL_PATH_SRC, 'lib', 'VC', 'libeay32MT.lib'),
            os.path.join(self.OPENSSL_PATH_SRC, 'lib', 'VC', 'ssleay32MT.lib'),
            os.path.join(self.OPENSSL_PATH_SRC, 'lib', 'VC', 'static',
                         'libcrypto32MT.lib'),
            os.path.join(self.OPENSSL_PATH_SRC, 'lib', 'VC', 'static',
                         'libeay32MT.lib'),
            os.path.join(self.OPENSSL_PATH_SRC, 'lib', 'VC', 'static',
                         'ssleay32MT.lib'),
        ]

        for f in _chk_output:
            if not os.path.exists(f):
                raise RuntimeError(
                    'build openssl static library from source code failed.')
示例#17
0
 def _build_jsoncpp(self, file_name):
     cc.n('prepare jsoncpp source code... ', end='')
     if not os.path.exists(self.JSONCPP_PATH_SRC):
         cc.v('')
         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.')
示例#18
0
 def _build_mongoose(self, file_name):
     cc.n('prepare mongoose source code... ', end='')
     if not os.path.exists(self.MONGOOSE_PATH_SRC):
         cc.v('')
         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.')
示例#19
0
    def build_server(self):
        cc.n('build web server ...')
        # notice: now we can not build debug version of tp_web.exe
        if ctx.target_path == 'debug':
            cc.w('cannot build debug version of tp_web, skip.')
        else:
            sln_file = os.path.join(env.root_path, 'server', 'tp_web', 'src',
                                    'tp_web.vs2015.sln')
            out_file = os.path.join(env.root_path, 'out', 'server',
                                    ctx.bits_path, ctx.target_path,
                                    'tp_web.exe')
            if os.path.exists(out_file):
                utils.remove(out_file)
            utils.msvc_build(sln_file, 'tp_web', ctx.target_path,
                             ctx.bits_path, False)
            utils.ensure_file_exists(out_file)

        cc.n('build core server ...')
        sln_file = os.path.join(env.root_path, 'server', 'tp_core', 'core',
                                'tp_core.vs2015.sln')
        out_file = os.path.join(env.root_path, 'out', 'server', ctx.bits_path,
                                ctx.target_path, 'tp_core.exe')
        if os.path.exists(out_file):
            utils.remove(out_file)
        utils.msvc_build(sln_file, 'tp_core', ctx.target_path, ctx.bits_path,
                         False)
        utils.ensure_file_exists(out_file)

        cc.n('build SSH protocol ...')
        sln_file = os.path.join(env.root_path, 'server', 'tp_core', 'protocol',
                                'ssh', 'tpssh.vs2015.sln')
        out_file = os.path.join(env.root_path, 'out', 'server', ctx.bits_path,
                                ctx.target_path, 'tpssh.dll')
        if os.path.exists(out_file):
            utils.remove(out_file)
        utils.msvc_build(sln_file, 'tpssh', ctx.target_path, ctx.bits_path,
                         False)
        utils.ensure_file_exists(out_file)

        if os.path.exists(
                os.path.join(env.root_path, 'server', 'tp_core', 'protocol',
                             'ssh', 'tpssh.vs2015.sln')):
            cc.n('build RDP protocol ...')
            sln_file = os.path.join(env.root_path, 'server', 'tp_core',
                                    'protocol', 'rdp', 'tprdp.vs2015.sln')
            out_file = os.path.join(env.root_path, 'out', 'server',
                                    ctx.bits_path, ctx.target_path,
                                    'tprdp.dll')
            if os.path.exists(out_file):
                utils.remove(out_file)
            utils.msvc_build(sln_file, 'tprdp', ctx.target_path, ctx.bits_path,
                             False)
            utils.ensure_file_exists(out_file)
示例#20
0
    def _build_libssh(self, file_name):
        # cc.n('skip build libssh on macOS.')
        # return

        if not self._download_libssh(file_name):
            return
        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='')
        # 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')):
            cc.w('already exists, skip.')
            return
        cc.v('')

        build_path = os.path.join(self.LIBSSH_PATH_SRC, 'build')

        cmake_define = ' -DCMAKE_INSTALL_PREFIX={path_release}' \
                       ' -DOPENSSL_INCLUDE_DIR=/usr/local/opt/openssl/include' \
                       ' -DOPENSSL_LIBRARIES=/usr/local/opt/openssl/lib' \
                       ' -DWITH_GCRYPT=OFF' \
                       ' -DWITH_GEX=OFF' \
                       ' -DWITH_SFTP=ON' \
                       ' -DWITH_SERVER=ON' \
                       ' -DWITH_GSSAPI=OFF' \
                       ' -DWITH_ZLIB=ON' \
                       ' -DWITH_PCAP=OFF' \
                       ' -DBUILD_SHARED_LIBS=OFF' \
                       ' -DUNIT_TESTING=OFF' \
                       ' -DWITH_EXAMPLES=OFF' \
                       ' -DWITH_BENCHMARKS=OFF' \
                       ' -DWITH_NACL=OFF' \
                       ''.format(path_release=self.PATH_RELEASE)

        # ' -DWITH_STATIC_LIB=ON'

        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'))
        # utils.ensure_file_exists(os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', 'threads', 'libssh_threads.a'))
        utils.copy_file(os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src'),
                        os.path.join(self.PATH_RELEASE, 'lib'), 'libssh.a')
        # utils.copy_file(os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', 'threads'), os.path.join(self.PATH_RELEASE, 'lib'), 'libssh_threads.a')
        utils.copy_ex(os.path.join(self.LIBSSH_PATH_SRC, 'include'),
                      os.path.join(self.PATH_RELEASE, 'include'), 'libssh')
示例#21
0
    def _build_openssl(self, file_name):
        cc.n('build openssl static library from source code... ')

        if not super()._build_openssl(file_name):
            return

        _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'),
        ]

        need_build = False
        for f in _chk_output:
            if not os.path.exists(f):
                need_build = True
                break

        if not need_build:
            cc.n('build openssl static library from source code... ', end='')
            cc.w('already exists, skip.')
            return
        cc.v('')

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

        os.chdir(self.OPENSSL_PATH_SRC)
        os.system('""{}" Configure VC-WIN32"'.format(env.perl))
        os.system(r'ms\do_nasm')
        # 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)

        for f in _chk_output:
            if not os.path.exists(f):
                raise RuntimeError(
                    'build openssl static library from source code failed.')
示例#22
0
    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='')
        if os.path.exists(os.path.join(self.PATH_RELEASE, 'lib', 'libssh.a')):
            cc.w('already exists, skip.')
            return
        cc.v('')

        build_path = os.path.join(self.LIBSSH_PATH_SRC, 'build')

        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' \
                       ' -DWITH_GSSAPI=OFF' \
                       ' -DWITH_ZLIB=OFF' \
                       ' -DWITH_PCAP=OFF' \
                       ' -DUNIT_TESTING=OFF' \
                       ' -DWITH_EXAMPLES=OFF' \
                       ' -DWITH_BENCHMARKS=OFF' \
                       ' -DWITH_NACL=OFF' \
                       ' ..'.format(path_release=self.PATH_RELEASE)

        old_p = os.getcwd()
        try:
            utils.cmake(build_path,
                        'Release',
                        False,
                        cmake_define=cmake_define,
                        cmake_pre_define='CFLAGS="-fPIC"')
            os.chdir(build_path)
            utils.sys_exec('make install')
        except:
            pass
        os.chdir(old_p)

        # utils.ensure_file_exists(os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', 'libssh.a'))
        # utils.copy_file(os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src'), os.path.join(self.PATH_RELEASE, 'lib'), 'libssh.a')
        # utils.copy_ex(os.path.join(self.LIBSSH_PATH_SRC, 'include'), os.path.join(self.PATH_RELEASE, 'include'), 'libssh')

        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))
示例#23
0
文件: main.py 项目: eomsoft/teleport
    def _prompt_input(message, def_value):
        cc.v('{} ['.format(message), end='')

        cc.w(def_value, end='')
        cc.v(']: ', end='')
        try:
            x = input().strip()
            if len(x) == 0:
                x = def_value
        except EOFError:
            x = def_value

        return x
示例#24
0
文件: main.py 项目: zydudu/teleport
    def _prompt_input(message, def_value):
        cc.v('{} ['.format(message), end='')

        cc.w(def_value, end='')
        cc.v(']: ', end='')
        try:
            x = input().strip()
            if len(x) == 0:
                x = def_value
        except EOFError:
            x = def_value

        return x
示例#25
0
 def _build_libuv(self, file_name):
     if not self._download_libuv(file_name):
         return
     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)
         time.sleep(1)  # wait for a while, otherwise rename may fail.
         os.rename(
             os.path.join(PATH_EXTERNAL, 'libuv-{}'.format(env.ver_libuv)),
             self.LIBUV_PATH_SRC)
     else:
         cc.w('already exists, skip.')
示例#26
0
    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='')
        if os.path.exists(os.path.join(self.PATH_RELEASE, 'lib', 'libssh.a')):
            cc.w('already exists, skip.')
            return
        cc.v('')

        cc.n('fix libssh source code... ', end='')
        s_name = 'libssh-{}'.format(env.ver_libssh)
        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'))
        utils.ensure_file_exists(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src', 'libcrypto-compat.c'))
        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')
        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')

        build_path = os.path.join(self.LIBSSH_PATH_SRC, 'build')

        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' \
                       ' -DWITH_GSSAPI=OFF' \
                       ' -DWITH_ZLIB=OFF' \
                       ' -DWITH_PCAP=OFF' \
                       ' -DUNIT_TESTING=OFF' \
                       ' -DWITH_EXAMPLES=OFF' \
                       ' -DWITH_BENCHMARKS=OFF' \
                       ' -DWITH_NACL=OFF' \
                       ' ..'.format(path_release=self.PATH_RELEASE)

        old_p = os.getcwd()
        try:
            utils.cmake(build_path, 'Release', False, cmake_define=cmake_define, cmake_pre_define='CFLAGS="-fPIC"')
            os.chdir(build_path)
            utils.sys_exec('make install')
        except:
            pass
        os.chdir(old_p)

        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))
示例#27
0
 def _build_jsoncpp(self, file_name):
     if not self._download_jsoncpp(file_name):
         return
     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.')
示例#28
0
 def _build_mongoose(self, file_name):
     if not self._download_mongoose(file_name):
         return
     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.')
示例#29
0
    def _build_mbedtls(self, file_name):
        cc.n('prepare mbedtls source code... ', end='')
        if not os.path.exists(self.MBEDTLS_PATH_SRC):
            cc.v('')
            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.')
            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')
示例#30
0
    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:
            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')
            ))

        lib_file = 'libpython{}m.a'.format(env.py_ver_dot)
        utils.ensure_file_exists(os.path.join(self.PATH_RELEASE, 'lib', lib_file))
示例#31
0
    def build_server(self):
        cc.n('build web server ...')
        # notice: now we can not build debug version of tp_web.exe
        if ctx.target_path == 'debug':
            cc.w('cannot build debug version of tp_web, skip.')
        else:
            sln_file = os.path.join(env.root_path, 'server', 'tp_web', 'src', 'tp_web.vs2017.sln')
            out_file = os.path.join(env.root_path, 'out', 'server', ctx.bits_path, ctx.target_path, 'tp_web.exe')
            if os.path.exists(out_file):
                utils.remove(out_file)
            utils.msvc_build(sln_file, 'tp_web', ctx.target_path, ctx.bits_path, False)
            utils.ensure_file_exists(out_file)

        cc.n('build core server ...')
        sln_file = os.path.join(env.root_path, 'server', 'tp_core', 'core', 'tp_core.vs2017.sln')
        out_file = os.path.join(env.root_path, 'out', 'server', ctx.bits_path, ctx.target_path, 'tp_core.exe')
        if os.path.exists(out_file):
            utils.remove(out_file)
        utils.msvc_build(sln_file, 'tp_core', ctx.target_path, ctx.bits_path, False)
        utils.ensure_file_exists(out_file)

        cc.n('build SSH protocol ...')
        sln_file = os.path.join(env.root_path, 'server', 'tp_core', 'protocol', 'ssh', 'tpssh.vs2017.sln')
        out_file = os.path.join(env.root_path, 'out', 'server', ctx.bits_path, ctx.target_path, 'tpssh.dll')
        if os.path.exists(out_file):
            utils.remove(out_file)
        utils.msvc_build(sln_file, 'tpssh', ctx.target_path, ctx.bits_path, False)
        utils.ensure_file_exists(out_file)
        utils.copy_file(os.path.join(env.root_path, 'external', 'libssh', 'lib', ctx.target_path), os.path.join(env.root_path, 'out', 'server', ctx.bits_path, ctx.target_path), 'ssh.dll')

        cc.n('build TELNET protocol ...')
        sln_file = os.path.join(env.root_path, 'server', 'tp_core', 'protocol', 'telnet', 'tptelnet.vs2017.sln')
        out_file = os.path.join(env.root_path, 'out', 'server', ctx.bits_path, ctx.target_path, 'tptelnet.dll')
        if os.path.exists(out_file):
            utils.remove(out_file)
        utils.msvc_build(sln_file, 'tptelnet', ctx.target_path, ctx.bits_path, False)
        utils.ensure_file_exists(out_file)

        if with_rdp:
            cc.n('build RDP protocol ...')
            sln_file = os.path.join(env.root_path, 'server', 'tp_core', 'protocol', 'rdp', 'tprdp.vs2017.sln')
            out_file = os.path.join(env.root_path, 'out', 'server', ctx.bits_path, ctx.target_path, 'tprdp.dll')
            if os.path.exists(out_file):
                utils.remove(out_file)
            utils.msvc_build(sln_file, 'tprdp', ctx.target_path, ctx.bits_path, False)
            utils.ensure_file_exists(out_file)
示例#32
0
    def _build_openssl(self, file_name):
        cc.n('build openssl static library from source code... ')

        if not super()._build_openssl(file_name):
            return

        _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'),
            ]

        need_build = False
        for f in _chk_output:
            if not os.path.exists(f):
                need_build = True
                break

        if not need_build:
            cc.n('build openssl static library from source code... ', end='')
            cc.w('already exists, skip.')
            return
        cc.v('')

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

        os.chdir(self.OPENSSL_PATH_SRC)
        os.system('""{}" Configure VC-WIN32"'.format(env.perl))
        os.system(r'ms\do_nasm')
        # 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)

        for f in _chk_output:
            if not os.path.exists(f):
                raise RuntimeError('build openssl static library from source code failed.')
示例#33
0
    def _build_sqlite(self, file_name):
        if not os.path.exists(self.SQLITE_PATH_SRC):
            os.system('tar -zxvf "{}/{}" -C "{}"'.format(
                PATH_DOWNLOAD, file_name, self.PATH_TMP))

        cc.n('build sqlite static...', end='')
        if os.path.exists(
                os.path.join(self.PATH_RELEASE, 'lib', 'libsqlite3.a')):
            cc.w('already exists, skip.')
            return
        cc.v('')

        old_p = os.getcwd()
        os.chdir(self.SQLITE_PATH_SRC)
        os.system('./configure --prefix={}'.format(self.PATH_RELEASE))
        os.system('make')
        os.system('make install')
        os.chdir(old_p)
示例#34
0
    def _prepare_python(self):
        cc.n('prepare python header files ...', end='')

        if os.path.exists(os.path.join(PATH_EXTERNAL, 'python', 'include', 'Python.h')):
            cc.w('already exists, skip.')
            return
        cc.v('')

        _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('\ncan 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'))
示例#35
0
    def _build_zlib(self, file_name):
        if not self._download_zlib(file_name):
            return
        cc.n('build zlib library from source code... ', end='')

        if not os.path.exists(self.ZLIB_PATH_SRC):
            cc.v('')
            utils.unzip(os.path.join(PATH_DOWNLOAD, file_name), PATH_EXTERNAL)
            os.rename(
                os.path.join(PATH_EXTERNAL, 'zlib-{}'.format(env.ver_zlib)),
                self.ZLIB_PATH_SRC)

        if ctx.target_path == 'debug':
            olib = 'zlibd.lib'
            odll = 'zlibd.dll'
        else:
            olib = 'zlib.lib'
            odll = 'zlib.dll'
        out_file_lib = os.path.join(self.ZLIB_PATH_SRC, 'build',
                                    ctx.target_path, olib)
        out_file_dll = os.path.join(self.ZLIB_PATH_SRC, 'build',
                                    ctx.target_path, odll)

        if os.path.exists(out_file_lib) and os.path.exists(out_file_dll):
            cc.w('already exists, skip.')
            return
        cc.v('')

        cc.w(
            'On Windows, when build zlib, need you use cmake-gui.exe to generate solution file'
        )
        cc.w(
            'for Visual Studio 2017. Visit https://docs.tp4a.com for more details.'
        )
        cc.w(
            '\nOnce the zlib.sln generated, press Enter to continue or Q to quit...',
            end='')
        try:
            x = input()
        except EOFError:
            x = 'q'
        if x == 'q':
            return

        cc.i('build zlib...')
        sln_file = os.path.join(self.ZLIB_PATH_SRC, 'build', 'zlib.sln')
        utils.msvc_build(sln_file, 'zlib', ctx.target_path, 'win32', False)
        # utils.ensure_file_exists(os.path.join(self.ZLIB_PATH_SRC, 'build', ctx.target_path, 'zlib.lib'))
        # utils.ensure_file_exists(os.path.join(self.ZLIB_PATH_SRC, 'build', ctx.target_path, 'zlib.dll'))
        # utils.copy_file(os.path.join(self.ZLIB_PATH_SRC, 'build', ctx.target_path), os.path.join(self.ZLIB_PATH_SRC, 'lib', ctx.target_path), 'zlib.lib')
        # utils.copy_file(os.path.join(self.ZLIB_PATH_SRC, 'build', ctx.target_path), os.path.join(self.ZLIB_PATH_SRC, 'lib', ctx.target_path), 'zlib.dll')
        utils.ensure_file_exists(out_file_lib)
        utils.ensure_file_exists(out_file_dll)
示例#36
0
    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')
        # 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')

        old_p = os.getcwd()
        os.chdir(self.MBEDTLS_PATH_SRC)
        os.system('make CFLAGS="-fPIC" lib')
        os.system('make install')
        os.chdir(old_p)
示例#37
0
    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('python header file already exists, skip.')
        else:
            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')))

        lib_file = 'libpython{}m.a'.format(env.py_ver_dot)
        utils.ensure_file_exists(
            os.path.join(self.PATH_RELEASE, 'lib', lib_file))
示例#38
0
    def _build_libuv(self, file_name):
        cc.n('prepare libuv source code...', end='')
        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...
        # brew install automake libtool

        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)
示例#39
0
    def _prepare_python_header(self):
        cc.n('prepare python header files ...', end='')

        if os.path.exists(
                os.path.join(PATH_EXTERNAL, 'python', 'include', 'pyctype.h')):
            cc.w('already exists, skip.')
            return
        cc.v('')

        _header_path = None
        for p in sys.path:
            if os.path.exists(os.path.join(p, 'include', 'pyctype.h')):
                _header_path = os.path.join(p, 'include')
        if _header_path is None:
            cc.e('\ncan 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'))
示例#40
0
    def _build_libssh(self, file_name):
        cc.n('build libssh static library from source code... ', end='')
        out_file = os.path.join(self.LIBSSH_PATH_SRC, 'lib', 'libsshMT.lib')

        need_build = False
        if not os.path.exists(out_file):
            need_build = True

        if not need_build:
            cc.w('already exists, skip.')
            return
        cc.v('')

        cc.n('prepare libssh source code... ', end='')
        _include = os.path.join(self.LIBSSH_PATH_SRC, 'include', 'libssh')
        _src = os.path.join(self.LIBSSH_PATH_SRC, 'src')

        if not os.path.exists(_include) or not os.path.exists(_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)

            _unzipped_path = os.path.join(PATH_EXTERNAL,
                                          'libssh-{}'.format(env.ver_libssh))

            utils.copy_ex(os.path.join(_unzipped_path, 'include', 'libssh'),
                          _include)
            utils.copy_ex(os.path.join(_unzipped_path, 'src'), _src)

            utils.remove(_unzipped_path)

            if not os.path.exists(_include) or not os.path.exists(_src):
                raise RuntimeError('\ncan not prepare libssh source code.')
        else:
            cc.w('already exists, skip.')

        cc.i('build libssh...')
        sln_file = os.path.join(self.LIBSSH_PATH_SRC, 'libssh.vs2015.sln')
        utils.msvc_build(sln_file, 'libssh', ctx.target_path, ctx.bits_path,
                         False)
        utils.ensure_file_exists(out_file)
示例#41
0
    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='')
        # 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')):
            cc.w('already exists, skip.')
            return
        cc.v('')

        build_path = os.path.join(self.LIBSSH_PATH_SRC, 'build')

        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' \
                       ' -DWITH_GSSAPI=OFF' \
                       ' -DWITH_ZLIB=OFF' \
                       ' -DWITH_PCAP=OFF' \
                       ' -DUNIT_TESTING=OFF' \
                       ' -DWITH_EXAMPLES=OFF' \
                       ' -DWITH_BENCHMARKS=OFF' \
                       ' -DWITH_NACL=OFF' \
                       ''.format(path_release=self.PATH_RELEASE)

        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'))
        # utils.ensure_file_exists(os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', 'threads', 'libssh_threads.a'))
        utils.copy_file(os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src'), os.path.join(self.PATH_RELEASE, 'lib'), 'libssh.a')
        # utils.copy_file(os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', 'threads'), os.path.join(self.PATH_RELEASE, 'lib'), 'libssh_threads.a')
        utils.copy_ex(os.path.join(self.LIBSSH_PATH_SRC, 'include'), os.path.join(self.PATH_RELEASE, 'include'), 'libssh')
示例#42
0
    def _build_zlib(self, file_name):
        # cc.w('skip build zlib again.')
        if not self._download_zlib(file_name):
            return
        if not os.path.exists(self.ZLIB_PATH_SRC):
            os.system('unzip "{}/{}" -d "{}"'.format(PATH_DOWNLOAD, file_name,
                                                     self.PATH_TMP))

        cc.n('build zlib...', end='')
        out_file = os.path.join(self.PATH_RELEASE, 'lib', 'libz.a')
        if os.path.exists(out_file):
            cc.w('already exists, skip.')
            return
        cc.v('')

        build_path = os.path.join(self.ZLIB_PATH_SRC, 'build')

        cmake_define = ' -DCMAKE_INSTALL_PREFIX={path_release}' \
                       ' ..'.format(path_release=self.PATH_RELEASE)

        old_p = os.getcwd()
        try:
            utils.cmake(build_path,
                        'Release',
                        False,
                        cmake_define=cmake_define,
                        cmake_pre_define='CFLAGS="-fPIC"')
            os.chdir(build_path)
            utils.sys_exec('make')
            utils.sys_exec('make install')
        except:
            pass
        os.chdir(old_p)

        utils.ensure_file_exists(out_file)
        files = os.listdir(os.path.join(self.PATH_RELEASE, 'lib'))
        for i in files:
            if i.startswith('libz.so'):
                # use os.unlink() because some file should be a link.
                os.unlink(os.path.join(self.PATH_RELEASE, 'lib', i))
示例#43
0
    def _build_openssl(self, file_name):
        # 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...', end='')
        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)
示例#44
0
    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('')
            utils.unzip(os.path.join(PATH_DOWNLOAD, file_name), PATH_EXTERNAL)
            os.rename(os.path.join(PATH_EXTERNAL, 'libssh-{}'.format(env.ver_libssh)), self.LIBSSH_PATH_SRC)

            # 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')
            cc.n('fix libssh source code... ', end='')
            s_name = 'libssh-{}'.format(env.ver_libssh)
            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'))
            utils.ensure_file_exists(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src', 'libcrypto-compat.c'))
            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')
            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')

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

        if os.path.exists(out_file_lib) and os.path.exists(out_file_dll):
            cc.w('already exists, skip.')
            return
        cc.v('')

        cc.w('On Windows, when build libssh, need you use cmake-gui.exe to generate solution file')
        cc.w('for Visual Studio 2017. Visit https://docs.tp4a.com for more details.')
        cc.w('\nOnce 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

        cc.i('build libssh...')
        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)
示例#45
0
    def _build_libssh(self, file_name):
        if not os.path.exists(self.LIBSSH_PATH_SRC):
            # os.system('tar -zxvf "{}/{}" -C "{}"'.format(PATH_DOWNLOAD, file_name, PATH_TMP))
            os.system('unzip "{}/{}" -d "{}"'.format(PATH_DOWNLOAD, file_name,
                                                     self.PATH_TMP))
            # os.rename(os.path.join(self.PATH_TMP, 'master'), os.path.join(self.PATH_TMP, 'libssh-{}'.format(LIBSSH_VER)))

        cc.n('build libssh...', end='')
        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')):
            cc.w('already exists, skip.')
            return
        cc.v('')

        build_path = os.path.join(self.LIBSSH_PATH_SRC, 'build')
        # utils.makedirs(build_path)

        # here is a bug in cmake v2.8.11 (default on ubuntu14), in FindOpenSSL.cmake,
        # it parse opensslv.h, use regex like this:
        #   REGEX "^#define[\t ]+OPENSSL_VERSION_NUMBER[\t ]+0x([0-9a-fA-F])+.*")
        # but in openssl-1.0.2h, the version define line is:
        #   # define OPENSSL_VERSION_NUMBER  0x1000208fL
        # notice there is a space char between # and define, so find openssl always fail.

        # old_p = os.getcwd()
        # os.chdir(build_path)
        # cmd = 'cmake' \
        #       ' -DCMAKE_INSTALL_PREFIX={}' \
        #       ' -D_OPENSSL_VERSION={}' \
        #       ' -DOPENSSL_INCLUDE_DIR={}/include' \
        #       ' -DOPENSSL_LIBRARIES={}/lib' \
        #       ' -DCMAKE_BUILD_TYPE=Release' \
        #       ' -DWITH_GSSAPI=OFF' \
        #       ' -DWITH_ZLIB=OFF' \
        #       ' -DWITH_STATIC_LIB=ON' \
        #       ' -DWITH_PCAP=OFF' \
        #       ' -DWITH_EXAMPLES=OFF' \
        #       ' -DWITH_NACL=OFF' \
        #       ' ..'.format(self.PATH_RELEASE, OPENSSL_VER, self.PATH_RELEASE, self.PATH_RELEASE)
        # cc.n(cmd)
        # os.system(cmd)
        # # os.system('make ssh_static ssh_threads_static')
        # os.system('make ssh_static')
        # # os.system('make install')
        # os.chdir(old_p)

        cmake_define = ' -DCMAKE_INSTALL_PREFIX={}' \
                       ' -D_OPENSSL_VERSION={}' \
                       ' -DOPENSSL_INCLUDE_DIR={}/include' \
                       ' -DOPENSSL_LIBRARIES={}/lib' \
                       ' -DWITH_GSSAPI=OFF' \
                       ' -DWITH_ZLIB=OFF' \
                       ' -DWITH_STATIC_LIB=ON' \
                       ' -DWITH_PCAP=OFF' \
                       ' -DWITH_TESTING=OFF' \
                       ' -DWITH_CLIENT_TESTING=OFF' \
                       ' -DWITH_EXAMPLES=OFF' \
                       ' -DWITH_BENCHMARKS=OFF' \
                       ' -DWITH_NACL=OFF' \
                       ' ..'.format(self.PATH_RELEASE, env.ver_openssl_number, self.PATH_RELEASE, self.PATH_RELEASE)

        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'))
        utils.ensure_file_exists(
            os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', 'threads',
                         'libssh_threads.a'))
        utils.copy_file(os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src'),
                        os.path.join(self.PATH_RELEASE, 'lib'), 'libssh.a')
        utils.copy_file(
            os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', 'threads'),
            os.path.join(self.PATH_RELEASE, 'lib'), 'libssh_threads.a')
        utils.copy_ex(os.path.join(self.LIBSSH_PATH_SRC, 'include'),
                      os.path.join(self.PATH_RELEASE, 'include'), 'libssh')
示例#46
0
    def _build_mbedtls(self, file_name):
        if not os.path.exists(self.MBEDTLS_PATH_SRC):
            # os.system('tar -zxvf "{}/{}" -C "{}"'.format(PATH_DOWNLOAD, file_name, PATH_TMP))
            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 config.h
        # mkfile = os.path.join(self.MBEDTLS_PATH_SRC, 'include', 'mbedtls', 'config.h')
        # f = open(mkfile)
        # fl = f.readlines()
        # f.close()
        #
        # for i in range(len(fl)):
        #     if fl[i].find('#define MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED') >= 0:
        #         fl[i] = '//#define MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED\n'
        #     elif fl[i].find('#define MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED') >= 0:
        #         fl[i] = '//#define MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED\n'
        #     elif fl[i].find('#define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED') >= 0:
        #         fl[i] = '//#define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED\n'
        #     elif fl[i].find('#define MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED') >= 0:
        #         fl[i] = '//#define MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED\n'
        #     elif fl[i].find('#define MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED') >= 0:
        #         fl[i] = '//#define MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED\n'
        #     elif fl[i].find('#define MBEDTLS_SELF_TEST') >= 0:
        #         fl[i] = '//#define MBEDTLS_SELF_TEST\n'
        #     elif fl[i].find('#define MBEDTLS_SSL_RENEGOTIATION') >= 0:
        #         fl[i] = '//#define MBEDTLS_SSL_RENEGOTIATION\n'
        #     elif fl[i].find('#define MBEDTLS_ECDH_C') >= 0:
        #         fl[i] = '//#define MBEDTLS_ECDH_C\n'
        #     elif fl[i].find('#define MBEDTLS_ECDSA_C') >= 0:
        #         fl[i] = '//#define MBEDTLS_ECDSA_C\n'
        #     elif fl[i].find('#define MBEDTLS_ECP_C') >= 0:
        #         fl[i] = '//#define MBEDTLS_ECP_C\n'
        #     elif fl[i].find('#define MBEDTLS_NET_C') >= 0:
        #         fl[i] = '//#define MBEDTLS_NET_C\n'
        #
        #     elif fl[i].find('#define MBEDTLS_RSA_NO_CRT') >= 0:
        #         fl[i] = '#define MBEDTLS_RSA_NO_CRT\n'
        #     elif fl[i].find('#define MBEDTLS_SSL_PROTO_SSL3') >= 0:
        #         fl[i] = '#define MBEDTLS_SSL_PROTO_SSL3\n'
        #
        # 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')
        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')

        old_p = os.getcwd()
        os.chdir(self.MBEDTLS_PATH_SRC)
        os.system('make CFLAGS="-fPIC" lib')
        os.system('make install')
        os.chdir(old_p)