diff --git a/llvm-build/build.py b/llvm-build/build.py index f6e465e41f14b4f8e0f9d44a4eebd2d370feede7..c3784098eb180d87db5a70ed00513740323648be 100755 --- a/llvm-build/build.py +++ b/llvm-build/build.py @@ -622,6 +622,20 @@ class BuildUtils(object): def merge_libxml2_build_dir(self, platform_triple, *args): return self.merge_out_path('third_party', 'libxml2', 'build', platform_triple, *args) + 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 merge_libedit_install_dir(self, platform_triple, *args): return self.merge_out_path('third_party', 'libedit', 'install', platform_triple, *args) @@ -1726,6 +1740,27 @@ class LlvmLibs(BuildUtils): lldb_defines['LIBLLDB_BUILD_STATIC'] = 'ON' lldb_target.append('lldb') + if self.build_config.build_ncurses: + self.build_ncurses(None, llvm_install, llvm_triple) + lldb_defines['LLDB_ENABLE_CURSES'] = 'ON' + ncurses_install_path = self.merge_ncurses_install_dir(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 self.get_ncurses_dependence_libs(llvm_triple): + 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(None, llvm_install, llvm_triple) + lldb_defines['LLDB_ENABLE_LIBEDIT'] = 'ON' + libedit_install_path = self.merge_libedit_install_dir(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, True) lldb_defines['LLDB_ENABLE_LIBXML2'] = 'ON' @@ -1814,11 +1849,14 @@ class LlvmLibs(BuildUtils): ncurses_version = self.get_ncurses_version() if ncurses_version is not None: + libncurses_untar_path = self.merge_out_path('third_party', 'ncurses', 'ncurses-' + ncurses_version) args = ['./build_ncurses.sh', libncurses_src_dir, libncurses_build_path, libncurses_install_path, - prebuilts_path, clang_version, ncurses_version, platform_triple] + prebuilts_path, clang_version, ncurses_version, platform_triple, libncurses_untar_path, + self.merge_ncurses_install_dir(self.use_platform())] self.check_call(args) os.chdir(cur_dir) + if platform_triple == self.use_platform(): self.llvm_package.copy_ncurses_to_llvm(platform_triple, llvm_make) self.llvm_package.copy_ncurses_to_llvm(platform_triple, llvm_install) @@ -1876,12 +1914,14 @@ class LlvmLibs(BuildUtils): 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, platform_triple] + libedit_untar_path = self.merge_out_path('third_party', 'libedit', 'libedit-' + self.get_libedit_version()) + args = ['./build_libedit.sh', libedit_src_dir, libedit_build_path , libedit_install_path, libncurses_path, prebuilts_path, clang_version, platform_triple, libedit_untar_path] self.check_call(args) os.chdir(cur_dir) - self.llvm_package.copy_libedit_to_llvm(platform_triple, llvm_make) - self.llvm_package.copy_libedit_to_llvm(platform_triple, llvm_install) + if platform_triple == self.use_platform(): + self.llvm_package.copy_libedit_to_llvm(platform_triple, llvm_make) + self.llvm_package.copy_libedit_to_llvm(platform_triple, llvm_install) def build_libxml2_defines(self): libxml2_defines = {} diff --git a/llvm-build/build_libedit.sh b/llvm-build/build_libedit.sh index 357ebea760221b1e61b5b526d8a3119ff7ffc72b..becfc48fb9699fe4566d01d793114586b06f150d 100755 --- a/llvm-build/build_libedit.sh +++ b/llvm-build/build_libedit.sh @@ -10,6 +10,8 @@ LIBEDIT_INSTALL_PATH=$3 NCURSES_PATH=$4 PREBUILT_PATH=$5 CLANG_VERSION=$6 +TARGET=$7 +LIBEDIT_UNTAR_PATH=$8 # Get version and date form libedit.spec (Compatible with Linux and Mac) # The format in the libedit.spec is as follows: @@ -46,8 +48,11 @@ CXX_PATH=${PREBUILT_PATH}/clang/ohos/${host_platform}-${host_cpu}/clang-${CLANG_ 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} - cd ${LIBEDIT_SRC_DIR} + if [ ! -b ${LIBEDIT_UNTAR_PATH} ]; then + mkdir -p ${LIBEDIT_UNTAR_PATH} + fi + tar -xzvf ${libedit_package} --strip-components 1 -C ${LIBEDIT_UNTAR_PATH} + cd ${LIBEDIT_UNTAR_PATH} if [ ! -b ${LIBEDIT_BUILD_PATH} ]; then mkdir -p ${LIBEDIT_BUILD_PATH} @@ -56,13 +61,13 @@ if [ -e ${libedit_package} ]; then # Apply patches in order for patch in "${patches[@]}" do - patch -Np1 < $patch + patch -Np1 < ${LIBEDIT_SRC_DIR}/$patch done # build libedit cd ${LIBEDIT_BUILD_PATH} ohos_suffix='-ohos' - if [[ ${7} != *${ohos_suffix} ]]; then + if [[ ${TARGET} != *${ohos_suffix} ]]; then ldflags="-L${NCURSES_PATH}/lib" ncuses_flags="-I${NCURSES_PATH}/include" if [ "${host_platform}" = "darwin" ]; then @@ -79,24 +84,24 @@ if [ -e ${libedit_package} ]; then export CFLAGS="$CFLAGS $ncuses_flags" fi - ${LIBEDIT_SRC_DIR}/configure \ + ${LIBEDIT_UNTAR_PATH}/configure \ --prefix=${LIBEDIT_INSTALL_PATH} \ CC=${CC_PATH} \ CXX=${CXX_PATH} make -j$(nproc --all) install | tee build_libedit.log else C_FLAGS="-I${NCURSES_PATH}/include/ -I${NCURSES_PATH}/include/ncurses -D__STDC_ISO_10646__=201103L -fPIC" - if [[ $7 =~ 'arm' ]]; then + if [[ ${TARGET} =~ 'arm' ]]; then C_FLAGS="$C_FLAGS -march=armv7-a -mfloat-abi=soft" fi - ${LIBEDIT_SRC_DIR}/configure \ + ${LIBEDIT_UNTAR_PATH}/configure \ --prefix=${LIBEDIT_INSTALL_PATH} \ - --host="$7" \ - CC="${PREBUILT_PATH}/../out/llvm-install/bin/clang --target=$7" \ + --host="${TARGET}" \ + CC="${PREBUILT_PATH}/../out/llvm-install/bin/clang --target=${TARGET}" \ CFLAGS="${C_FLAGS}" \ LDFLAGS="-L${NCURSES_PATH}/lib" - make -j$(nproc --all) install | tee build_libedit_$7.log + make -j$(nproc --all) install | tee build_libedit_${TARGET}.log fi fi diff --git a/llvm-build/build_ncurses.sh b/llvm-build/build_ncurses.sh index 91a995440498543c27e115bdcaf5a64e92ea854b..e97163f64fb8cc3a14dc1aa5db5b643ac102ba3b 100755 --- a/llvm-build/build_ncurses.sh +++ b/llvm-build/build_ncurses.sh @@ -10,6 +10,8 @@ NCURSES_INSTALL_PATH=$3 PREBUILT_PATH=$4 CLANG_VERSION=$5 NCURSES_VERSION=$6 +TARGET=$7 +NCURSES_UNTAR_PATH=$8 SPECFILE="${NCURSES_SRC_DIR}/ncurses.spec" @@ -40,8 +42,11 @@ CXX_PATH=${PREBUILT_PATH}/clang/ohos/${host_platform}-${host_cpu}/clang-${CLANG_ 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} + if [ ! -b ${NCURSES_UNTAR_PATH} ]; then + mkdir -p ${NCURSES_UNTAR_PATH} + fi + tar -xvzf ${ncurses_package} --strip-components 1 -C ${NCURSES_UNTAR_PATH} + cd ${NCURSES_UNTAR_PATH} # Get the list of patch files for ncurses.spec # The format in the ncurses.spec is as follows: @@ -52,7 +57,7 @@ if [ -e ${ncurses_package} ]; then # Apply patches in order for patch in "${patches[@]}" do - patch -Np1 < $patch + patch -Np1 < ${NCURSES_SRC_DIR}/$patch done if [ ! -b ${NCURSES_BUILD_PATH} ]; then @@ -69,7 +74,7 @@ if [ -e ${ncurses_package} ]; then export CPPFLAGS="$CPPFALGS -I${SDKROOT}/usr/include -I${SDKROOT}/usr/include/i368" export CFLAGS="$CFLAGS -isysroot${SDKROOT} $flags" - ${NCURSES_SRC_DIR}/configure \ + ${NCURSES_UNTAR_PATH}/configure \ --with-shared \ --with-default-terminfo-dir=/usr/lib/terminfo:/lib/terminfo:/usr/share/terminfo \ --disable-mixed-case \ @@ -80,7 +85,7 @@ if [ -e ${ncurses_package} ]; then fi if [ "${host_platform}" == "linux" ]; then export LDFLAGS="-Wl,-rpath,\$$ORIGIN/../lib" - ${NCURSES_SRC_DIR}/configure \ + ${NCURSES_UNTAR_PATH}/configure \ --with-shared \ --with-default-terminfo-dir=/usr/lib/terminfo:/lib/terminfo:/usr/share/terminfo \ --prefix=${NCURSES_INSTALL_PATH} \ @@ -89,21 +94,26 @@ if [ -e ${ncurses_package} ]; then make -j$(nproc --all) install | tee build_ncurses.log fi else - C_FLAGS="--target=$7 -fPIC" - if [[ $7 =~ 'arm' ]]; then + C_FLAGS="--target=${TARGET} -fPIC" + if [[ ${TARGET} =~ 'arm' ]]; then C_FLAGS="$C_FLAGS -march=armv7-a -mfloat-abi=soft" fi + NCURSES_HOST_INSTALL_PATH=$9 + export LD_LIBRARY_PATH="${NCURSES_HOST_INSTALL_PATH}/lib:$LD_LIBRARY_PATH" ${NCURSES_SRC_DIR}/configure \ - --host="$7" \ + --host="${TARGET}" \ --with-shared \ --prefix=${NCURSES_INSTALL_PATH} \ --with-termlib \ --without-manpages \ --with-strip-program="${PREBUILT_PATH}/../out/llvm-install/bin/llvm-strip" \ + --with-fallbacks=linux,vt100,xterm \ + --with-tic-path=${NCURSES_HOST_INSTALL_PATH}/bin/tic \ + --with-infocmp-path=${NCURSES_HOST_INSTALL_PATH}/bin/infocmp \ CC=${PREBUILT_PATH}/../out/llvm-install/bin/clang \ CXX=${PREBUILT_PATH}/../out/llvm-install/bin/clang++ \ CFLAGS="${C_FLAGS}" - make -j$(nproc --all) install | tee build_ncurses_$7.log + make -j$(nproc --all) install | tee build_ncurses_${TARGET}.log fi fi