1#!/bin/bash 2# Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved. 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14set -e 15function dl_ohos_sdk() { 16 if [ ! -d "tools/ohos-sdk" ];then 17 echo "you need ohos-sdk to compile ohos" 18 if [ ! -d "tools" ];then 19 mkdir tools 20 fi 21 if [ ! -d "tools/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu" ];then 22 curl https://repo.huaweicloud.com/openharmony/compiler/prebuilts_gcc_linux-x86_arm_gcc-linaro-7.5.0-arm-linux-gnueabi/1.0/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu.tar.xz --output gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu.tar.xz 23 tar Jxvf gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu.tar.xz --directory=tools/ 24 fi 25 if [ ! -d "tools/prebuilts_gcc_linux-x86_arm_gcc-linaro-7.5.0-arm-linux-gnueabi" ];then 26 curl https://repo.huaweicloud.com/openharmony/compiler/prebuilts_gcc_linux-x86_arm_gcc-linaro-7.5.0-arm-linux-gnueabi/1.0/prebuilts_gcc_linux-x86_arm_gcc-linaro-7.5.0-arm-linux-gnueabi.tar.gz --output gcc-linaro-7.5.0-arm-linux-gnueabi.tar.gz 27 tar zxvf gcc-linaro-7.5.0-arm-linux-gnueabi.tar.gz --directory=tools/ 28 fi 29 if [ ! -d "tools/ohos-sdk" ];then 30 curl http://download.ci.openharmony.cn/version/Daily_Version/ohos-sdk-full-linux/20250623_041115/version-Daily_Version-ohos-sdk-full-linux-20250623_041115-ohos-sdk-full-linux.tar.gz --output ohos-sdk.tar.gz 31 tar -xvf ohos-sdk.tar.gz --directory=tools/ 32 cd tools/ohos-sdk/linux 33 for zipfile in *.zip; do 34 echo "unzip:$zipfile" 35 unzip -o "$zipfile" 36 done 37 cd - 38 cp tools/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/lib/gcc/aarch64-linux-gnu/7.5.0/libgcc.a tools/ohos-sdk/linux/native/sysroot/usr/lib/aarch64-linux-ohos 39 cp tools/prebuilts_gcc_linux-x86_arm_gcc-linaro-7.5.0-arm-linux-gnueabi/lib/gcc/arm-linux-gnueabi/7.5.0/libgcc.a tools/ohos-sdk/linux/native/sysroot/usr/lib/arm-linux-ohos 40 fi 41 fi 42} 43function prepare_ohos() { 44 if [ ! -e "out/linux/protoc" ]; then 45 echo "out/linux/protoc not found, need to build:" 46 ./build.sh linux -m addr2line 47 fi 48 if [ ! -d "out/ohos" ]; then 49 mkdir -p out/ohos 50 fi 51 if [ ! -d "out/ohos_debug" ]; then 52 mkdir -p out/ohos_debug 53 fi 54 rm -rf out/ohos/gen out/ohos_debug/gen/ 55 cp -rf out/linux/gen out/ohos/ 56 cp -rf out/linux/gen out/ohos_debug/ 57 dl_ohos_sdk 58}