1#!/bin/bash
2# Copyright (c) Huawei Technologies Co., Ltd. 2023. 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
15echo "target_operator = $target_operator"
16if [ "$target" != "trace" ] && [ "$target" != "linux" ] && [ "$target" != "windows" ] &&
17    [ "$target" != "macx" ] && [ "$target" != "trace_streamer" ] && [ "$target" != "wasm" ] &&
18    [ "$target" != "test" ] && [ "$target" != "spb" ] && [ "$target" != "fuzz" ] &&
19    [ "$target" != "protoc" ] && [ "$target" != "sdkdemo" ] && [ "$target" != "sdkdemotest" ];then
20    echo "failed"
21    exit
22fi
23if [ "$target_operator" != "" ] && [ "$target_operator" != "debug" ] && [ "$target_operator" != "release" ] && [ "$target_operator" != "clean" ];then
24    if [ "$target_operator" == "protoc" ];then
25    target=$target_operator
26    else
27    echo "failed"
28    exit
29    fi
30fi
31if [ "$target_operator" == "debug" ];then
32    is_debug="true"
33elif [ "$target_operator" == "clean" ];then
34    is_clean="true"
35else
36    is_debug="false"
37fi
38echo "platform is $target_os"
39echo "isdebug: $is_debug"
40echo "isclean: $is_clean"
41if [ "$is_debug" != "false" ];then
42    ext="_debug"
43fi
44
45if [ "$target" == "test" ] || [ "$target" == "fuzz" ] || [ "$target" == "wasm" ] || [ "$target" == "sdkdemo" ] || [ "$target" == "sdkdemotest" ];then
46    target_dir=$target
47else
48    target_dir=$target_os
49fi
50if [ "$target" == "trace_streamer" ] || [ "$target" == "trace" ] || [ "$target" == "spb" ] || [ "$target" == "protoc" ];then
51    target_dir=$target_os
52fi
53echo "target_dir:" "$target_dir"
54echo "target:" "$target"
55
56out_dir=out/$target_dir$ext
57if [ "$is_clean" == "true" ];then
58    prebuilts/"$gn_path"/"$gn" gen "$out_dir" --clean
59    prebuilts/"$gn_path"/"$ninja" -C "$out_dir" -t clean
60else
61    prebuilts/"$gn_path"/"$gn" gen "$out_dir" --args='is_debug='"$is_debug"' target="'"$target"'" target_os="'"$target_os"'" is_independent_compile=true'' use_local_emsdk='"$use_local_emsdk"" $enable_all_plugins_str"
62    echo "begin to build ..."
63    prebuilts/"$gn_path"/"$ninja" -C "$out_dir"
64fi
65if [ "$out_dir" == "macx" ];then
66    ./mac_depend.sh
67fi