1#!/bin/bash
2# Copyright (C) 2022 Intel Corporation.
3# SPDX-License-Identifier: BSD-3-Clause
4
5set -e
6
7usage() {
8  echo "Usage: $0 [--board_list ACRN_BOARDLIST] [--scenario_list ACRN_SCENARIOLIST] [--config_path CONFIGDIRS] [--release n|y] [acrn | board_inspector | clean]"
9  echo "Optional arguments:"
10  echo "  -h, --help           show this help message and exit"
11  echo "  -v, --verbose        show verbose output"
12  echo "  -b, --board_list     list the boards to build, seperated by blank; build all scanned boards in the config path if specified as \"\"; build the default boards in debian rules if not specified"
13  echo "  -s, --scenario_list  list the scenarios to build, seperated by blank; build all scanned scenarios in the config path if specified as \"\"; build the default scenarios in debian rules if not specified"
14  echo "  -c, --config_path    specify the config path for the board and scenario configuration files, default use misc/config_tools/data if not specified"
15  echo "  -r, --release        build debug version with n, release version with y; default defined in debian rules if not specified"
16  echo "  acrn|board_inspector|clean    specify the build target, default value is acrn if not specified"
17  echo "Examples: "
18  echo "  $0"
19  echo "  $0 -b nuc11tnbi5 -s shared"
20  echo "  $0 -b \"nuc11tnbi5 tgl-vecow-spc-7100-Corei7\" -s \"shared hybrid\" -c misc/config_tools/data -r y"
21  echo "  $0 -b \"\" -s shared"
22  echo "  $0 board_inspector"
23}
24
25invalid() {
26  echo "ERROR: Unrecognized argument: $1" >&2
27  usage
28  exit 1
29}
30
31verify_cmd() {
32  command -v $@ >/dev/null 2>&1 || { echo >&2 "ERROR: $@ is not installed which is required for running this script. Aborting."; exit 1; }
33}
34
35verify_cmd readlink
36verify_cmd debuild
37verify_cmd "gbp dch"
38
39POSITIONAL_ARGS=()
40
41board_list="default"
42scenario_list="default"
43config_path="misc/config_tools/data"
44release="default"
45while [[ $# -gt 0 ]]; do
46  case $1 in
47    -b|--board_list)
48      board_list="$2"
49      shift 2
50      ;;
51    -s|--scenario_list)
52      scenario_list="$2"
53      shift 2
54      ;;
55    -c|--config_path)
56      config_path="$2"
57      shift 2
58      ;;
59    -r|--release)
60      release="$2"
61      shift 2
62      ;;
63    -v|--verbose)
64      verbose=1
65      shift
66      ;;
67    -h|--help)
68      usage
69      exit 0
70      ;;
71    -*|--*)
72      invalid $1
73      ;;
74    *)
75      POSITIONAL_ARGS+=("$1")
76      shift
77      ;;
78  esac
79done
80
81set -- "${POSITIONAL_ARGS[@]}"
82
83cmd="debuild"
84if [ -n "$verbose" ]; then
85  cmd="$cmd -eDH_VERBOSE=1"
86fi
87if [ "$board_list" != "default" ]; then
88  echo "ACRN_BOARDLIST    = ${board_list@Q}"
89  cmd="$cmd -eACRN_BOARDLIST=${board_list@Q}"
90fi
91if [ "$scenario_list" != "default" ]; then
92  echo "ACRN_SCENARIOLIST = ${scenario_list@Q}"
93  cmd="$cmd -eACRN_SCENARIOLIST=${scenario_list@Q}"
94fi
95cmd="$cmd -eCONFIGDIRS=${config_path@Q}"
96echo "CONFIGDIRS        = ${config_path@Q}"
97if [ "$release" != "default" ]; then
98  echo "RELEASE           = ${release@Q}"
99  if [ "$release" != "n" ] && [ "$release" != "y" ]; then
100    echo "ERROR: the release argument can only be n or y."
101    exit 1
102  fi
103  cmd="$cmd -eRELEASE=${release@Q}"
104fi
105if [ -z $1 ] || [ "$1" == "acrn" ]; then
106  cmd="$cmd -- binary"
107elif [ "$1" == "board_inspector"  ]; then
108  cmd="$cmd -- binary-indep"
109elif [ "$1" == "clean"  ]; then
110  cmd="$cmd -- clean"
111fi
112
113SCRIPT=$(readlink -f "$0")
114SCRIPT_PATH=$(dirname "$SCRIPT")
115cd $SCRIPT_PATH/../
116source VERSION
117
118rm -rf debian/changelog
119if [ -z $EMAIL ] && [ -z $DEBEMAIL]; then
120  export DEBEMAIL=$(git config --get user.email)
121  if [ -z $DEBEMAIL ]; then
122    export DEBEMAIL="projectacrn@gmail.com"
123  fi
124fi
125gbp dch -S --git-log="-n 10" --id-length=10 --ignore-branch
126sed -i "s/unknown/$MAJOR_VERSION.$MINOR_VERSION$EXTRA_VERSION/g" debian/changelog
127
128echo $cmd
129echo $cmd | bash -
130
131cd -
132