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
15. build/build_base_func.sh
16function prepare_windows() {
17    if [ "$target_os" == "windows" ];then
18        cp .gn_win .gn
19    else
20        cp .gn_unix .gn
21    fi
22    if [ "$1" == "windows" ] && [ "$2" == "release" ];then
23        echo "gn only support linux and wasm build currently"
24        if [ ! -d "out/windows" ];then
25            mkdir out/windows
26        fi
27        touch out/windows/trace_streamer.exe
28        exit
29    fi
30}
31function prepare_proto() {
32    TARGET_DIR=$1
33    if [[ "$PARAMS" == *"debug"* ]]; then
34        TARGET_DIR=$1"_debug"
35    fi
36    if [ ! -f "out/$TARGET_DIR/protoc" ];then
37        ./build.sh protoc
38        mkdir -p out/"$TARGET_DIR"
39        cp out/$target_os/protoc out/"$TARGET_DIR"/protoc
40    fi
41    if [ ! -f "out/$TARGET_DIR/protoreader_plugin" ] && [ -f "out/$TARGET_DIR/protoc" ];then
42        ./build.sh spb
43        mkdir -p out/"$TARGET_DIR"
44        cp out/$target_os/protoreader_plugin out/"$TARGET_DIR"/protoreader_plugin
45    fi
46}
47function check_params() {
48    if [[ "$1" == "" || "$1" == -* ]]; then
49        echo "Option '$1' is not reasonable." >&2
50        exit 1
51    fi
52}