1#!/bin/bash
2# Copyright (c) 2023 Huawei Device Co., Ltd.
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.
14
15set -e
16
17declare SCRIPT_PATCH
18declare SYSROOT
19declare PREFIX
20declare TARGET_CPU
21declare TARGET_GEN_DIR
22
23export SCRIPT_PATCH=$(dirname $(readlink -f "$0"))
24
25source ${SCRIPT_PATCH}/build_jsvm_inter.sh
26
27options="$(getopt -o h "help,sysroot:,node_path:,prefix:,target_cpu:,base_path:" -- "$@")" || usage
28
29eval set -- "$options"
30
31usage() {
32    echo "Tool $(basename "$0") Usage"
33    echo "Options:"
34    echo "-h|--help"
35    echo "--sysroot <path>            Sysroot path."
36    echo "--prefix <perfix>           Cross-compiler prefix."
37    echo "--target_cpu <arm/arm64>    Cross-compile CPU types."
38    echo "--target_gen_dir <output path>"
39    echo "          if target_gen_dir not set, will install only to the default path."
40    exit 0
41}
42
43die() {
44    echo $@
45    exit 0
46}
47
48do_man_process() {
49    do_opt_process $@
50    do_env 0
51    do_fetch     > ${out_dir}/log.do_fetch
52    do_patch     > ${out_dir}/log.do_patch
53    do_configure > ${out_dir}/log.do_configure
54    do_compile   > ${out_dir}/log.do_compile
55    do_install   > ${out_dir}/log.do_install
56    do_strip
57    do_env 1
58    do_fetch     > ${out_dir}/log.do_fetch_unstripped
59    do_patch     > ${out_dir}/log.do_patch_unstripped
60    do_configure > ${out_dir}/log.do_configure_unstripped
61    do_compile   > ${out_dir}/log.do_compile_unstripped
62    do_unstripped_copy
63}
64
65do_opt_process() {
66    while [[ $# -gt 0 ]]; do
67        case "$1" in
68        -h|--help)
69            usage
70            ;;
71        --sysroot)
72            export SYSROOT=$2
73            shift
74            ;;
75        --node_path)
76            export NODE_PATH=$2
77            shift
78            ;;
79        --prefix)
80            export PREFIX=$2
81            shift
82            ;;
83        --target_cpu)
84            export TARGET_CPU=$2
85            shift
86            ;;
87        --target_gen_dir)
88            export TARGET_GEN_DIR=$2
89            shift
90            ;;
91        --target_clang_coverage)
92            export TARGET_CLANG_COVERAGE=$2
93            shift
94            ;;
95        *)
96            ;;
97        esac
98        shift
99    done
100}
101
102do_man_process $@
103