diff --git a/llvm-build/build.py b/llvm-build/build.py index ee12969b8e24e5aed27446f043eecf5cbe131618..dce619e0b006cf9caddd632495994010672f6365 100755 --- a/llvm-build/build.py +++ b/llvm-build/build.py @@ -89,6 +89,8 @@ class BuildConfig(): self.ARCHIVE_EXTENSION = '.tar.' + self.compression_format self.ARCHIVE_OPTION = '-c' + ('j' if self.compression_format == "bz2" else 'z') self.LIBXML2_VERSION = None + self.NCURSES_VERSION = None + self.LIBEDIT_VERSION = None self.LZMA_VERSION = '22.0' logging.basicConfig(level=logging.INFO) @@ -588,6 +590,37 @@ class BuildUtils(object): return None + def get_ncurses_source_path(self): + return self.merge_out_path('third_party', 'ncurses', ('ncurses-' + self.build_config.NCURSES_VERSION)) + + def get_ncurses_install_path(self, triple): + return self.merge_out_path('third_party', 'ncurses', 'install', triple) + + def get_ncurses_build_path(self, triple): + return self.merge_out_path('third_party', 'ncurses', 'build', triple) + + def get_libedit_version(self): + libedit_spec = os.path.join(self.build_config.REPOROOT_DIR, 'third_party', 'libedit', 'libedit.spec') + if os.path.exists(libedit_spec): + with open(libedit_spec, 'r') as file: + lines = file.readlines() + prog = re.compile(r'Version:\s*(\S+)') + for line in lines: + version_match = prog.match(line) + if version_match: + return version_match.group(1) + + return None + + def get_libedit_source_path(self): + return self.merge_out_path('third_party', 'libedit', ('libedit-' + self.build_config.LIBEDIT_VERSION)) + + def get_libedit_install_path(self, triple): + return self.merge_out_path('third_party', 'libedit', 'install', triple) + + def get_libedit_build_path(self, triple): + return self.merge_out_path('third_party', 'libedit', 'build', triple) + def get_libxml2_version(self): version_file = os.path.join(self.build_config.REPOROOT_DIR, 'third_party', 'libxml2', 'libxml2.spec') if os.path.isfile(version_file): @@ -674,9 +707,9 @@ class LlvmCore(BuildUtils): llvm_defines['LLVM_ENABLE_ZSTD'] = 'OFF' llvm_defines['LLDB_PYTHON_EXT_SUFFIX'] = '.dylib' if self.build_config.build_ncurses: - libncurse = os.path.join(self.get_prebuilts_dir('ncurses'), 'lib', 'libncurses.6.dylib') - libpanel = os.path.join(self.get_prebuilts_dir('ncurses'), 'lib', 'libpanel.6.dylib') - libform = os.path.join(self.get_prebuilts_dir('ncurses'), 'lib', 'libform.6.dylib') + libncurse = os.path.join(self.get_ncurses_install_path(self.use_platform()), 'lib', 'libncurses.6.dylib') + libpanel = os.path.join(self.get_ncurses_install_path(self.use_platform()), 'lib', 'libpanel.6.dylib') + libform = os.path.join(self.get_ncurses_install_path(self.use_platform()), 'lib', 'libform.6.dylib') ncurses_libs = ';'.join([libncurse, libpanel, libform]) llvm_defines['CURSES_LIBRARIES'] = ncurses_libs llvm_defines['PANEL_LIBRARIES'] = ncurses_libs @@ -685,7 +718,7 @@ class LlvmCore(BuildUtils): llvm_defines['LIBLZMA_LIBRARIES'] = self.merge_out_path('lzma', 'lib', self.use_platform(), f'liblzma.{self.build_config.LZMA_VERSION}.dylib') if self.build_config.build_libedit: - llvm_defines['LibEdit_LIBRARIES'] = os.path.join(self.get_prebuilts_dir('libedit'), 'lib', 'libedit.0.dylib') + llvm_defines['LibEdit_LIBRARIES'] = os.path.join(self.get_libedit_install_path(self.use_platform()), 'lib', 'libedit.0.dylib') if self.build_config.build_libxml2: llvm_defines['LIBXML2_LIBRARIES'] = os.path.join(self.get_libxml2_install_path(self.use_platform()), 'lib', f'libxml2.{self.build_config.LIBXML2_VERSION}.dylib') @@ -713,12 +746,11 @@ class LlvmCore(BuildUtils): llvm_defines['LIBUNWIND_USE_COMPILER_RT'] = 'ON' llvm_defines['LLVM_BINUTILS_INCDIR'] = '/usr/include' llvm_defines['LLDB_PYTHON_EXT_SUFFIX'] = '.so' - ncurses_version = self.get_ncurses_version() - if self.build_config.build_ncurses and ncurses_version is not None: + if self.build_config.build_ncurses: ncurses_libs = [] - prebuilts_dir = self.get_prebuilts_dir('ncurses') + prebuilts_dir = self.get_ncurses_install_path(self.use_platform()) for library in ['libncurses', 'libpanel', 'libform']: - library_path = os.path.join(prebuilts_dir, 'lib', f'{library}.so.%s' % ncurses_version) + library_path = os.path.join(prebuilts_dir, 'lib', f'{library}.so.%s' % self.build_config.NCURSES_VERSION) ncurses_libs.append(library_path) ncurses_libs = ';'.join(ncurses_libs) llvm_defines['CURSES_LIBRARIES'] = ncurses_libs @@ -728,7 +760,7 @@ class LlvmCore(BuildUtils): llvm_defines['LIBLZMA_LIBRARIES'] = self.merge_out_path('lzma', 'lib', 'linux-x86_64', 'liblzma.so') if self.build_config.build_libedit: - llvm_defines['LibEdit_LIBRARIES'] = os.path.join(self.get_prebuilts_dir('libedit'), 'lib', 'libedit.so.0.0.68') + llvm_defines['LibEdit_LIBRARIES'] = os.path.join(self.get_libedit_install_path(self.use_platform()), 'lib', 'libedit.so.0.0.68') if not build_instrumented and not no_lto and not debug_build: llvm_defines['LLVM_ENABLE_LTO'] = 'Thin' @@ -768,9 +800,9 @@ class LlvmCore(BuildUtils): llvm_defines['SWIG_EXECUTABLE'] = self.find_program('swig') llvm_defines['LLDB_ENABLE_CURSES'] = 'OFF' - if self.build_config.build_ncurses and self.get_ncurses_version() is not None: + if self.build_config.build_ncurses: llvm_defines['LLDB_ENABLE_CURSES'] = 'ON' - llvm_defines['CURSES_INCLUDE_DIRS'] = os.path.join(self.get_prebuilts_dir('ncurses'), 'include') + llvm_defines['CURSES_INCLUDE_DIRS'] = os.path.join(self.get_ncurses_install_path(self.use_platform()), 'include') if self.build_config.enable_lzma_7zip: llvm_defines['LLDB_ENABLE_LZMA'] = 'ON' @@ -779,7 +811,7 @@ class LlvmCore(BuildUtils): if self.build_config.build_libedit: llvm_defines['LLDB_ENABLE_LIBEDIT'] = 'ON' - llvm_defines['LibEdit_INCLUDE_DIRS'] = os.path.join(self.get_prebuilts_dir('libedit'), 'include') + llvm_defines['LibEdit_INCLUDE_DIRS'] = os.path.join(self.get_libedit_install_path(self.use_platform()), 'include') if self.build_config.build_libxml2: llvm_defines['LLDB_ENABLE_LIBXML2'] = 'ON' @@ -1694,6 +1726,27 @@ class LlvmLibs(BuildUtils): lldb_defines['LIBLLDB_BUILD_STATIC'] = 'ON' lldb_target.append('lldb') + if self.build_config.build_ncurses: + self.build_ncurses(llvm_triple, None, llvm_install) + lldb_defines['LLDB_ENABLE_CURSES'] = 'ON' + ncurses_install_path = self.get_ncurses_install_path(llvm_triple) + lldb_defines['CURSES_INCLUDE_DIRS'] = os.path.join(ncurses_install_path, 'include') + lldb_defines['CURSES_HAVE_NCURSES_CURSES_H'] = 'ON' + ncurses_lib_path = os.path.join(ncurses_install_path, 'lib') + ncurses_libs = [] + for library in ['libncurses', 'libpanel', 'libform']: + ncurses_libs.append(os.path.join(ncurses_lib_path, f'{library}.a')) + ncurses_libs = ';'.join(ncurses_libs) + lldb_defines['CURSES_LIBRARIES'] = ncurses_libs + lldb_defines['PANEL_LIBRARIES'] = ncurses_libs + + if self.build_config.build_libedit: + self.build_libedit(llvm_triple, None, llvm_install) + lldb_defines['LLDB_ENABLE_LIBEDIT'] = 'ON' + libedit_install_path = self.get_libedit_install_path(llvm_triple) + lldb_defines['LibEdit_INCLUDE_DIRS'] = os.path.join(libedit_install_path, 'include') + lldb_defines['LibEdit_LIBRARIES'] = os.path.join(libedit_install_path, 'lib', 'libedit.a') + if self.build_config.build_libxml2: self.build_libxml2(llvm_triple, None, llvm_install) lldb_defines['LLDB_ENABLE_LIBXML2'] = 'ON' @@ -1764,32 +1817,34 @@ class LlvmLibs(BuildUtils): env=dict(self.build_config.ORIG_ENV), install=True) - def build_ncurses(self, llvm_make, llvm_install): - self.logger().info('Building ncurses.') - - libncurses_src_dir = os.path.abspath(os.path.join(self.build_config.REPOROOT_DIR, 'third_party', 'ncurses')) - libncurses_build_path = self.merge_out_path('ncurses') - libncurses_install_path = self.get_prebuilts_dir('ncurses') - prebuilts_path = os.path.join(self.build_config.REPOROOT_DIR, 'prebuilts') + def build_ncurses(self, triple, llvm_make, llvm_install): + self.logger().info('Building ncurses for %s', triple) + cur_dir = os.getcwd() - self.check_rm_tree(libncurses_build_path) - self.rm_cmake_cache(libncurses_build_path) - self.check_rm_tree(libncurses_install_path) - self.rm_cmake_cache(libncurses_install_path) + package_path = os.path.join(self.build_config.REPOROOT_DIR, 'third_party', 'ncurses') + src_path = self.get_ncurses_source_path() + build_path = self.get_ncurses_build_path(triple) + install_path = self.get_ncurses_install_path(triple) + toolchain_path = os.path.join(self.build_config.REPOROOT_DIR, + 'prebuilts', 'clang', 'ohos', self.use_platform(), + 'clang-%s' % self.build_config.CLANG_VERSION, 'bin') + self.check_rm_tree(build_path) + self.check_rm_tree(install_path) - cur_dir = os.getcwd() os.chdir(self.build_config.LLVM_BUILD_DIR) - clang_version = self.build_config.CLANG_VERSION + if triple == self.use_platform(): + args = ['./build_ncurses.sh', src_path, build_path, install_path, package_path, toolchain_path, triple] + self.check_call(args) - ncurses_version = self.get_ncurses_version() - if ncurses_version is not None: - args = ['./build_ncurses.sh', libncurses_src_dir, libncurses_build_path, libncurses_install_path, - prebuilts_path, clang_version, ncurses_version] + self.llvm_package.copy_ncurses_to_llvm(triple, llvm_make) + self.llvm_package.copy_ncurses_to_llvm(triple, llvm_install) + else: + sysroot_path = self.merge_out_path('sysroot', triple) + args = ['./build_ncurses.sh', src_path, build_path, install_path, package_path, toolchain_path, triple, + sysroot_path, self.get_ncurses_install_path(self.use_platform())] self.check_call(args) - os.chdir(cur_dir) - self.llvm_package.copy_ncurses_to_llvm(llvm_make) - self.llvm_package.copy_ncurses_to_llvm(llvm_install) + os.chdir(cur_dir) def build_lzma(self, llvm_make, llvm_install): self.logger().info('Building lzma') @@ -1827,31 +1882,37 @@ class LlvmLibs(BuildUtils): self.check_create_dir(lib_dst_path) self.check_copy_file(lzma_file, lib_dst_path + '/liblzma' + shlib_ext) - def build_libedit(self, llvm_make, llvm_install): - self.logger().info('Building libedit') + def build_libedit(self, triple, llvm_make, llvm_install): + self.logger().info('Building libedit for %s', triple) + cur_dir = os.getcwd() - libedit_src_dir = os.path.abspath(os.path.join(self.build_config.REPOROOT_DIR, 'third_party', 'libedit')) - libedit_build_path = self.merge_out_path('libedit') - libedit_install_path = self.get_prebuilts_dir('libedit') - prebuilts_path = os.path.join(self.build_config.REPOROOT_DIR, 'prebuilts') + package_path = os.path.join(self.build_config.REPOROOT_DIR, 'third_party', 'libedit') + src_path = self.get_libedit_source_path() + ncurses_path = self.get_ncurses_install_path(triple) + build_path = self.get_libedit_build_path(triple) + install_path = self.get_libedit_install_path(triple) + toolchain_path = os.path.join(self.build_config.REPOROOT_DIR, + 'prebuilts', 'clang', 'ohos', self.use_platform(), + 'clang-%s' % self.build_config.CLANG_VERSION, 'bin') + self.check_rm_tree(build_path) + self.check_rm_tree(install_path) - self.check_rm_tree(libedit_build_path) - self.rm_cmake_cache(libedit_build_path) - self.check_rm_tree(libedit_install_path) - self.rm_cmake_cache(libedit_install_path) + os.chdir(self.build_config.LLVM_BUILD_DIR) + if triple == self.use_platform(): + args = ['./build_libedit.sh', src_path, build_path, install_path, package_path, + ncurses_path, toolchain_path, triple] + self.check_call(args) - libncurses_path = self.get_prebuilts_dir('ncurses') + self.llvm_package.copy_libedit_to_llvm(triple, llvm_make) + self.llvm_package.copy_libedit_to_llvm(triple, llvm_install) + else: + sysroot_path = self.merge_out_path('sysroot', triple) + args = ['./build_libedit.sh', src_path, build_path, install_path, package_path, + ncurses_path, toolchain_path, triple, sysroot_path] + self.check_call(args) - cur_dir = os.getcwd() - os.chdir(self.build_config.LLVM_BUILD_DIR) - clang_version = self.build_config.CLANG_VERSION - args = ['./build_libedit.sh', libedit_src_dir, libedit_build_path , libedit_install_path, libncurses_path, prebuilts_path, clang_version] - self.check_call(args) os.chdir(cur_dir) - self.llvm_package.copy_libedit_to_llvm(llvm_make) - self.llvm_package.copy_libedit_to_llvm(llvm_install) - def build_libxml2_defines(self): libxml2_defines = {} libxml2_defines['LIBXML2_WITH_PYTHON'] = 'OFF' @@ -2347,7 +2408,7 @@ class LlvmPackage(BuildUtils): if index_link != -1: subprocess.check_call(["install_name_tool", "-change", dependency, "@loader_path/../lib/%s" % lib_name, lib]) - def copy_ncurses_to_llvm(self, install_dir): + def copy_ncurses_to_llvm(self, triple, install_dir): self.logger().info('copy_ncurses_to_llvm install_dir is %s', install_dir) if self.host_is_darwin(): @@ -2357,7 +2418,7 @@ class LlvmPackage(BuildUtils): lib_dst_path = os.path.join(install_dir, 'lib') - lib_src_path = self.merge_out_path('../prebuilts', 'ncurses', 'lib') + lib_src_path = os.path.join(self.get_ncurses_install_path(triple), 'lib') libncurses_src = os.path.join(lib_src_path, 'libncurses%s' % shlib_ext) libpanel_src = os.path.join(lib_src_path, 'libpanel%s' % shlib_ext) libform_src = os.path.join(lib_src_path, 'libform%s' % shlib_ext) @@ -2380,7 +2441,7 @@ class LlvmPackage(BuildUtils): for lib_src in (libncurses_src, libpanel_src, libform_src): self.check_copy_file(lib_src, lib_dst_path) - def copy_libedit_to_llvm(self, install_dir): + def copy_libedit_to_llvm(self, triple, install_dir): self.logger().info('LlvmPackage copy_libedit_to_llvm install_dir is %s', install_dir) if self.host_is_darwin(): @@ -2388,7 +2449,7 @@ class LlvmPackage(BuildUtils): if self.host_is_linux(): shlib_ext = '.so.0' - libedit_lib_path = self.merge_out_path('../prebuilts', 'libedit', 'lib') + libedit_lib_path = os.path.join(self.get_libedit_install_path(triple), 'lib') libedit_src = os.path.join(libedit_lib_path, 'libedit%s' % shlib_ext) lib_dst_path = os.path.join(install_dir, 'lib') @@ -2559,14 +2620,22 @@ def main(): if not build_config.no_build_x86_64: configs.append(('x86_64', build_utils.open_ohos_triple('x86_64'))) + build_config.NCURSES_VERSION = build_utils.get_ncurses_version() + if build_config.NCURSES_VERSION is None: + build_config.build_ncurses = False + if build_config.build_ncurses: - llvm_libs.build_ncurses(llvm_make, llvm_install) + llvm_libs.build_ncurses(build_utils.use_platform(), llvm_make, llvm_install) if build_config.enable_lzma_7zip: llvm_libs.build_lzma(llvm_make, llvm_install) + build_config.LIBEDIT_VERSION = build_utils.get_libedit_version() + if build_config.LIBEDIT_VERSION is None: + build_config.build_libedit = False + if build_config.build_libedit: - llvm_libs.build_libedit(llvm_make, llvm_install) + llvm_libs.build_libedit(build_utils.use_platform(), llvm_make, llvm_install) build_config.LIBXML2_VERSION = build_utils.get_libxml2_version() if build_config.LIBXML2_VERSION is None: diff --git a/llvm-build/build_libedit.sh b/llvm-build/build_libedit.sh index 5d046197a8874edd4ee453928fa8e68c72edd108..a7270a5cd97a0592f87c128cbb51f2e28378fc41 100755 --- a/llvm-build/build_libedit.sh +++ b/llvm-build/build_libedit.sh @@ -4,24 +4,17 @@ set -xe # This script is used to create libedit SCRIPT_PATH="${PWD}" -LIBEDIT_SRC_DIR=$1 +LIBEDIT_SRC_PATH=$1 LIBEDIT_BUILD_PATH=$2 LIBEDIT_INSTALL_PATH=$3 -NCURSES_PATH=$4 -PREBUILT_PATH=$5 -CLANG_VERSION=$6 - -# Get version and date form libedit.spec (Compatible with Linux and Mac) -# The format in the libedit.spec is as follows: -# Version: 3.1 -# %global _date 20210910 -SPECFILE="${LIBEDIT_SRC_DIR}/libedit.spec" -LIBEDIT_VERSION=$(grep -E '^Version:*' ${SPECFILE} | awk '{print $2}') -DATE=$(grep -E '^%global _date' ${SPECFILE} | sed 's/^.*\(20[0-9]\{6\}\).*$/\1/') +LIBEDIT_PACKAGE_PATH=$4 +NCURSES_PATH=$5 +TOOLCHAIN_PATH=$6 +TARGET=$7 +SYSROOT_PATH=$8 case $(uname -s) in Linux) - host_platform=linux ;; Darwin) @@ -32,49 +25,76 @@ case $(uname -s) in exit 1 esac -case $(uname -m) in - arm64) +# # untar source files when LIBEDIT_SRC_PATH does not exist +if [ ! -e ${LIBEDIT_SRC_PATH} ]; then + SPECFILE="${LIBEDIT_PACKAGE_PATH}/libedit.spec" + LIBEDIT_VERSION=$(grep -E '^Version:*' ${SPECFILE} | awk '{print $2}') + DATE=$(grep -E '^%global _date' ${SPECFILE} | sed 's/^.*\(20[0-9]\{6\}\).*$/\1/') + libedit_package=${LIBEDIT_PACKAGE_PATH}/libedit-${DATE}-${LIBEDIT_VERSION}.tar.gz + if [ ! -e ${libedit_package} ]; then + echo "Not found package:${libedit_package}" + exit 1 + fi - host_cpu=arm64 - ;; - *) - host_cpu=x86_64 -esac + mkdir -p ${LIBEDIT_SRC_PATH} + tar -xzvf ${libedit_package} --strip-components 1 -C ${LIBEDIT_SRC_PATH} -CC_PATH=${PREBUILT_PATH}/clang/ohos/${host_platform}-${host_cpu}/clang-${CLANG_VERSION}/bin/clang -CXX_PATH=${PREBUILT_PATH}/clang/ohos/${host_platform}-${host_cpu}/clang-${CLANG_VERSION}/bin/clang++ + cd ${LIBEDIT_SRC_PATH} + patches=($(grep -E '^Patch[0-9]+:' "${SPECFILE}" | sed 's/^[^:]*: *//')) + # Apply patches in order + for patch in "${patches[@]}" + do + patch -Np1 < ${LIBEDIT_PACKAGE_PATH}/$patch + done +fi -libedit_package=${LIBEDIT_SRC_DIR}/libedit-${DATE}-${LIBEDIT_VERSION}.tar.gz -if [ -e ${libedit_package} ]; then - tar -xzvf ${libedit_package} --strip-components 1 -C ${LIBEDIT_SRC_DIR} +CC_PATH=${TOOLCHAIN_PATH}/clang +CXX_PATH=${TOOLCHAIN_PATH}/clang++ - if [ ! -b ${LIBEDIT_BUILD_PATH} ]; then - mkdir -p ${LIBEDIT_BUILD_PATH} - fi +# build libedit +if [ ! -b ${LIBEDIT_BUILD_PATH} ]; then + mkdir -p ${LIBEDIT_BUILD_PATH} +fi +cd ${LIBEDIT_BUILD_PATH} - # build libedit - cd ${LIBEDIT_BUILD_PATH} - ldflags="-L${NCURSES_PATH}/lib" - ncuses_flags="-I${NCURSES_PATH}/include" - if [ "${host_platform}" = "darwin" ]; then - ncurses_libs="-Wl,-rpath,@loader_path/../lib:${NCURSES_PATH}/lib" - SDKROOT=$(xcrun --sdk macosx --show-sdk-path) - sdk_flags="-I${SDKROOT}/usr/include" - export LDFLAGS="$LDFLAGS $sdk_flags $ldflags $ncurses_libs" - export CFLAGS="$CFLAGS -isysroot$SDKROOT $ncuses_flags" - fi +ncuses_ldflags="-L${NCURSES_PATH}/lib" +ncuses_cflags="-I${NCURSES_PATH}/include -I${NCURSES_PATH}/include/ncurses" - if [ "${host_platform}" = "linux" ]; then - ncurses_libs="-Wl,-rpath,\$$ORIGIN/../lib:${NCURSES_PATH}/lib" - export LDFLAGS="$LDFLAGS $ldflags $ncuses_flags $ncurses_libs" - export CFLAGS="$CFLAGS $ncuses_flags" - fi +if [ "${host_platform}" = "darwin" ]; then + ncurses_rpath="-Wl,-rpath,@loader_path/../lib:${NCURSES_PATH}/lib" + SDKROOT=$(xcrun --sdk macosx --show-sdk-path) + sdk_flags="-I${SDKROOT}/usr/include" + export LDFLAGS="$LDFLAGS $sdk_flags $ncuses_ldflags $ncurses_rpath" + export CFLAGS="$CFLAGS -isysroot$SDKROOT $ncuses_cflags" - ${LIBEDIT_SRC_DIR}/configure \ + ${LIBEDIT_SRC_PATH}/configure \ --prefix=${LIBEDIT_INSTALL_PATH} \ CC=${CC_PATH} \ CXX=${CXX_PATH} make -j$(nproc --all) install | tee build_libedit.log -fi +else + export LDFLAGS="$LDFLAGS $ncuses_ldflags" + export CFLAGS="$CFLAGS $ncuses_cflags" + if [[ "${TARGET}" != *-ohos ]]; then + ${LIBEDIT_SRC_PATH}/configure \ + --prefix=${LIBEDIT_INSTALL_PATH} \ + CC=${CC_PATH} \ + CXX=${CXX_PATH} + make -j$(nproc --all) install | tee build_libedit.log + else + # arm-ohos or aarch64-ohos + export CFLAGS="$CFLAGS -D__STDC_ISO_10646__=201103L -fPIC --sysroot=${SYSROOT_PATH}" + if [ "${TARGET}" == 'arm-linux-ohos' ]; then + export CFLAGS="$CFLAGS -march=armv7-a -mfloat-abi=soft" + fi + ${LIBEDIT_SRC_PATH}/configure \ + --prefix=${LIBEDIT_INSTALL_PATH} \ + --host=${TARGET} \ + --enable-shared \ + CC="${CC_PATH} --target=${TARGET}" \ + CXX=${CXX_PATH} + make -j$(nproc --all) install | tee build_libedit.log + fi +fi diff --git a/llvm-build/build_ncurses.sh b/llvm-build/build_ncurses.sh index df4f7b1ed45cf568f7c9e49d325186f0aa16b77e..228e24015f4d0310de508fd0bea883034abf17ac 100755 --- a/llvm-build/build_ncurses.sh +++ b/llvm-build/build_ncurses.sh @@ -4,18 +4,17 @@ set -xe # This script is used to create ncurses SCRIPT_PATH="${PWD}" -NCURSES_SRC_DIR=$1 +NCURSES_SRC_PATH=$1 NCURSES_BUILD_PATH=$2 NCURSES_INSTALL_PATH=$3 -PREBUILT_PATH=$4 -CLANG_VERSION=$5 -NCURSES_VERSION=$6 - -SPECFILE="${NCURSES_SRC_DIR}/ncurses.spec" +NCURSES_PACKAGE_PATH=$4 +TOOLCHAIN_PATH=$5 +TARGET=$6 +SYSROOT_PATH=$7 +NCURSES_HOST_INSTALL_PATH=$8 case $(uname -s) in Linux) - host_platform=linux ;; Darwin) @@ -26,23 +25,20 @@ case $(uname -s) in exit 1 esac -case $(uname -m) in - arm64) - - host_cpu=arm64 - ;; - *) - host_cpu=x86_64 -esac - -CC_PATH=${PREBUILT_PATH}/clang/ohos/${host_platform}-${host_cpu}/clang-${CLANG_VERSION}/bin/clang -CXX_PATH=${PREBUILT_PATH}/clang/ohos/${host_platform}-${host_cpu}/clang-${CLANG_VERSION}/bin/clang++ +# untar source files when NCURSES_SRC_DIR does not exist +if [ ! -e ${NCURSES_SRC_PATH} ]; then + SPECFILE="${NCURSES_PACKAGE_PATH}/ncurses.spec" + NCURSES_VERSION=$(grep -E '^Version:*' ${SPECFILE} | awk '{print $2}') + ncurses_package=${NCURSES_PACKAGE_PATH}/ncurses-${NCURSES_VERSION}.tar.gz + if [ ! -e ${ncurses_package} ]; then + echo "Not found package:${ncurses_package}" + exit 1 + fi -ncurses_package=${NCURSES_SRC_DIR}/ncurses-${NCURSES_VERSION}.tar.gz -if [ -e ${ncurses_package} ]; then - tar -xvzf ${ncurses_package} --strip-components 1 -C ${NCURSES_SRC_DIR} - cd ${NCURSES_SRC_DIR} + mkdir -p ${NCURSES_SRC_PATH} + tar -xvzf ${ncurses_package} --strip-components 1 -C ${NCURSES_SRC_PATH} + cd ${NCURSES_SRC_PATH} # Get the list of patch files for ncurses.spec # The format in the ncurses.spec is as follows: # Patch8: ncurses-config.patch @@ -52,39 +48,64 @@ if [ -e ${ncurses_package} ]; then # Apply patches in order for patch in "${patches[@]}" do - patch -Np1 < $patch + patch -Np1 < ${NCURSES_PACKAGE_PATH}/$patch done +fi - if [ ! -b ${NCURSES_BUILD_PATH} ]; then - mkdir -p ${NCURSES_BUILD_PATH} - fi - cd ${NCURSES_BUILD_PATH} - # build ncurses - if [ "${host_platform}" == "darwin" ]; then - export LDFLAGS="-Wl,-rpath,@loader_path/../lib" - SDKROOT=$(xcrun --sdk macosx --show-sdk-path) - flags="-Wl,-syslibroot,${SDKROOT}" - export CPPFLAGS="$CPPFALGS -I${SDKROOT}/usr/include -I${SDKROOT}/usr/include/i368" - export CFLAGS="$CFLAGS -isysroot${SDKROOT} $flags" +CC_PATH=${TOOLCHAIN_PATH}/clang +CXX_PATH=${TOOLCHAIN_PATH}/clang++ - ${NCURSES_SRC_DIR}/configure \ +# build ncurses +if [ ! -e ${NCURSES_BUILD_PATH} ]; then + mkdir -p ${NCURSES_BUILD_PATH} +fi +cd ${NCURSES_BUILD_PATH} +if [ "${host_platform}" == "darwin" ]; then + export LDFLAGS="-Wl,-rpath,@loader_path/../lib" + SDKROOT=$(xcrun --sdk macosx --show-sdk-path) + flags="-Wl,-syslibroot,${SDKROOT}" + export CPPFLAGS="$CPPFALGS -I${SDKROOT}/usr/include -I${SDKROOT}/usr/include/i368" + export CFLAGS="$CFLAGS -isysroot${SDKROOT} $flags" + + ${NCURSES_SRC_PATH}/configure \ + --with-shared \ + --with-default-terminfo-dir=/usr/lib/terminfo:/lib/terminfo:/usr/share/terminfo \ + --disable-mixed-case \ + --prefix=${NCURSES_INSTALL_PATH} \ + CC=${CC_PATH} \ + CXX=${CXX_PATH} + make -j$(nproc --all) install | tee build_ncurses.log + +else + export LDFLAGS="-Wl,-rpath,\$$ORIGIN/../lib" + if [[ "${TARGET}" != *-ohos ]]; then + ${NCURSES_SRC_PATH}/configure \ --with-shared \ --with-default-terminfo-dir=/usr/lib/terminfo:/lib/terminfo:/usr/share/terminfo \ - --disable-mixed-case \ --prefix=${NCURSES_INSTALL_PATH} \ CC=${CC_PATH} \ CXX=${CXX_PATH} make -j$(nproc --all) install | tee build_ncurses.log - fi - if [ "${host_platform}" == "linux" ]; then - export LDFLAGS="-Wl,-rpath,\$$ORIGIN/../lib" - ${NCURSES_SRC_DIR}/configure \ - --with-shared \ - --with-default-terminfo-dir=/usr/lib/terminfo:/lib/terminfo:/usr/share/terminfo \ + else + # arm-ohos or aarch64-ohos + export LD_LIBRARY_PATH="${NCURSES_HOST_INSTALL_PATH}/lib:$LD_LIBRARY_PATH" + export CFLAGS="$CFLAGS -fPIC --sysroot=${SYSROOT_PATH}" + if [[ "${TARGET}" =~ 'arm' ]]; then + export CFLAGS="$CFLAGS -march=armv7-a -mfloat-abi=soft" + fi + ${NCURSES_SRC_PATH}/configure \ --prefix=${NCURSES_INSTALL_PATH} \ - CC=${CC_PATH} \ + --host=${TARGET} \ + --with-shared \ + --without-cxx-binding \ + --without-cxx \ + --with-fallbacks=linux,vt100,xterm \ + --with-tic-path=${NCURSES_HOST_INSTALL_PATH}/bin/tic \ + --with-infocmp-path=${NCURSES_HOST_INSTALL_PATH}/bin/infocmp \ + CC="${CC_PATH} --target=${TARGET}"\ CXX=${CXX_PATH} - make -j$(nproc --all) install | tee build_ncurses.log + + make -j$(nproc --all) install.libs | tee build_ncurses.log fi fi