1#!/usr/bin/env bash
2# Copyright (c) 2021-2024 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
16TOP=$(pwd)
17CMD=${TOP}/panda/isa/gen.rb
18ISA_DATA=${TOP}/panda/isa/isa.yaml
19ISA_REQUIRE=${TOP}/panda/isa/isapi.rb
20
21# generated file with multiple template files
22# getopts:
23# -O: output directory
24# -D: date file
25# -R: require files
26# -I: use ISA_DATA, ISA_REQUIRE as default
27
28if [ $? != 0  ] ; then
29    echo "Terminating..." >&2
30    exit 1
31fi
32
33while getopts "O:D:R:I" arg; do
34    case "$arg" in
35        O)
36            OUTPUT=${OPTARG}
37            ;;
38        D)
39            DATA=${OPTARG}
40            ;;
41        R)
42            REQUIRE=${OPTARG}
43            ;;
44        I)
45            HAS_ISA=true
46            ;;
47        *)
48            echo "unkonw argument"
49            exit 1
50            ;;
51    esac
52done
53shift $(($OPTIND - 1))
54
55if [ "${HAS_ISA}" ];then
56    DATA=${ISA_DATA}
57    REQUIRE=${ISA_REQUIRE},${REQUIRE}
58fi
59
60for TEMPLATE_ARG in "$@"; do
61    TARGET_FILE=$(basename "$TEMPLATE_ARG" .erb)
62    ${CMD} --template "${TEMPLATE_ARG}" --data "${DATA}" --output "${OUTPUT}/${TARGET_FILE}" --require "${REQUIRE}"
63done
64