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
15PARAMS=$*
16SOURCE="${BASH_SOURCE[0]}"
17cd "$(dirname "${SOURCE}")"
18. build/build_stanalone_plugins.sh
19set_enable_plugin_array "true"
20set_enable_extend_plugin_array "false"
21./pare_third_party.sh
22choose_os_type
23./dl_tools.sh $gn_path
24while [[ $# -gt 0 ]]; do
25    case "$1" in
26        -e)
27            enable_plugin "$2"
28            shift 2;;
29        -d)
30            enable_extend_plugin "$2"
31            shift 2;;
32        -h)
33            help $0
34            shift;;
35        -l)
36            list_all_plugins
37            shift;;
38        *)
39            other_params+=("$1")
40            shift;;
41    esac
42done
43set -- "${other_params[@]}"
44if [ "$#" -ne 0 ] && { [ "$1" == "sdkdemo" ] || [ "$1" == "wasm" ] || [ "$1" == "test" ] || [ "$1" == "fuzz" ]; };then
45    prepare_proto $1
46fi
47prepare_windows $1 $2
48target_operator="$2"
49if [ "$#" -ne "0" ];then
50    if [ "$1" == "wasm" ] || [ "$1" == "sdkdemo" ];then
51        if command -v em++ &> /dev/null; then
52            use_local_emsdk="true"
53        else
54            ./dl_emsdk.sh
55            use_local_emsdk="false"
56        fi
57        target="$1"
58    fi
59    if [ "$1" == "test" ];then
60        target="test"
61        set_enable_plugin_array "true"
62    fi
63    if [ "$1" == "fuzz" ];then
64        target="fuzz"
65    fi
66    if [ "$1" == "protoc" ];then
67        target="protoc"
68    fi
69    if [ "$1" == "sdkdemotest" ];then
70        target="sdkdemotest"
71    fi
72    if [ "$1" == "spb" ];then
73        target="spb"
74    fi
75fi
76if [ "$target" == "wasm" ] && [ "$target_os" == "windows" ];then
77    echo "!!!build wasm on winows will occur unknown error, strongly suggest you build wasm on linux(Ubuntu)"
78    exit
79fi
80set_enable_all_plugins_str
81. ./build_operator.sh