blob: d252e7784504348403f1398050262b55bb5103ac [file] [log] [blame]
xjb04a4022021-11-25 15:01:52 +08001#!/bin/bash
2###############################################################################
3# This script provides the customer a quick way to build Tiny System from
4# source.
5###############################################################################
6
7PROG=$(basename ${0})
8
9usage() {
10 cat >&2 <<- EOF
11USAGE
12 ${PROG} [-h] [...]
13
14 This script provides a quicker way to build tinysys.
15
16PREREQUISITE
17 The Android environment must be initialize.
18 That is, you need to run those steps at least once:
19 $ cd <ANDROID_ROOT_DIR>
20 $ . buid/envsetup.sh
21 $ lunch
22
23 This script must be executed in Android top directory.
24
25OPTIONS
26 -h Print this help message
27
28Other options for GNU make or build targets can be provided.
29For example:
30 clean Clean up all built directories and objects
31 configheader Generate C header that contains all config options
32 -jN Run N parallel build tasks
33EOF
34
35exit 1
36}
37
38info() {
39 echo "${PROG}: [INFO] ${*}"
40}
41
42error() {
43 echo "${PROG}: [ERROR] ${*}"
44 exit 1
45}
46
47check_Android_env() {
48 if [ -z "${ANDROID_PRODUCT_OUT}" ] || [ -z "${TARGET_PRODUCT}" ] ; then
49 cat >&2 <<- EOF
50[ERROR] Android environment is not ready yet.
51
52Please make sure build/envsetup.sh is sourced and lunch is executed.
53EOF
54 return 1
55 fi
56
57 return 0
58}
59
60run_build_cmd() {
61 echo "Build command: ${*}"
62 eval "${*}" || exit 1
63}
64
65#######################################
66# Main
67#######################################
68TINYSYS_ROOT='tinysys/medmcu'
69TINYSYS_TARGET='tinysys-medmcu'
70#ADSP_TARGET='tinysys-adsp'
71CLEAN_TINYSYS_TARGET="clean-${TINYSYS_TARGET}"
72#CLEAN_ADSP_TARGET="clean-${ADSP_TARGET}"
73TINYSYS_ANDROID_MK="${TINYSYS_ROOT}/Android.mk"
74CLEAN_TARGET=0
75
76# Categorize options
77for i in "${@}"; do
78 case "${i}" in
79 'clean')
80 KEYWORDS="${KEYWORDS} ${i}"
81 CLEAN_TARGET=1
82 ;;
83 '-h')
84 usage
85 ;;
86 *) CMD_ARGS="${CMD_ARGS} ${i}"
87 esac
88done
89
90check_Android_env || exit 1
91
92# This script must be run in Android root directory
93[ -f 'build/envsetup.sh' ] || \
94 error "Please execute this command in Android top directory"
95
96#######################################
97# Here we build
98#######################################
99BUILD_CMD="ONE_SHOT_MAKEFILE=${TINYSYS_ANDROID_MK} make ${TINYSYS_TARGET} ${CMD_ARGS}"
100CLEAN_CMD="ONE_SHOT_MAKEFILE=${TINYSYS_ANDROID_MK} make ${CLEAN_TINYSYS_TARGET} ${CMD_ARGS}"
101
102
103if [ ${CLEAN_TARGET} -eq 1 ]; then
104 run_build_cmd "${CLEAN_CMD}"
105else
106 run_build_cmd "${BUILD_CMD}"
107fi
108
109exit ${?}