123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- # Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA").
- # All rights reserved.
- #
- # This software is supplied "AS IS" without any warranties.
- # RDA assumes no responsibility or liability for the use of the software,
- # conveys no license or title under any patent, copyright, or mask work
- # right to the product. RDA reserves the right to make changes in the
- # software without notification. RDA also make no representation or
- # warranty that such application will be suitable for the specified use
- # without further testing or modification.
- export PROJECT_ROOT=$PWD
- function remove_from_var
- {
- local VAR=$1
- local VAL="$2"
- if test -n "$VAL"; then
- export $VAR="$(echo "${!VAR}" | tr ':' '\n' | grep -v "$VAL" | paste -d: -s)"
- fi
- }
- function prepend_var
- {
- local VAR=$1
- local VAL="$2"
- if test -n "$VAL"; then
- remove_from_var $VAR "$VAL"
- if test -n "${!VAR}"; then
- export $VAR="$VAL:${!VAR}"
- else
- export $VAR="$VAL"
- fi
- fi
- }
- case `uname` in
- Linux)
- prepend_var PATH $PROJECT_ROOT/prebuilts/linux/bin
- prepend_var PATH $PROJECT_ROOT/prebuilts/linux/cmake/bin
- prepend_var PATH $PROJECT_ROOT/prebuilts/linux/nanopb
- prepend_var PATH $PROJECT_ROOT/tools
- prepend_var PATH $PROJECT_ROOT/tools/linux
- COMPLIER_PATH=$PROJECT_ROOT/prebuilts/linux/gcc-arm-none-eabi
- ;;
- *_NT*)
- prepend_var PATH $PROJECT_ROOT/prebuilts/win32/bin
- prepend_var PATH $PROJECT_ROOT/prebuilts/win32/cmake/bin
- prepend_var PATH $PROJECT_ROOT/prebuilts/win32/python3
- prepend_var PATH $PROJECT_ROOT/prebuilts/win32/nanopb
- prepend_var PATH $PROJECT_ROOT/tools
- prepend_var PATH $PROJECT_ROOT/tools/win32
- COMPLIER_PATH=$PROJECT_ROOT/prebuilts/win32/gcc-arm-none-eabi
- ;;
- esac
- function project_select_from
- {
- local BAR="$1"
- local ITEMS="$2"
- local DEF=$3
- local VAR=$4
- echo
- echo "$BAR"
- local MENUS
- local i=0
- local item
- for item in $ITEMS; do
- echo " $i. $item"
- i=$(($i+1))
- MENUS=(${MENUS[@]} $item)
- done
- echo -n "which would you like? [$DEF] "
- local answer
- read answer
- local choice=$DEF
- if test -n "$answer"; then
- if (echo -n $answer | grep -q -e "^[0-9][0-9]*$"); then
- if [ $answer -lt ${#MENUS[@]} ]; then
- choice=${MENUS[$(($answer))]}
- fi
- fi
- fi
- export $VAR=$choice
- }
- function project_select
- {
- local target
- local TARGETS=
- for target in $(cd target; /bin/ls); do
- if test -f target/$target/target.config; then
- TARGETS="$TARGETS $target"
- fi
- done
- project_select_from "build target:" "$TARGETS" "" BUILD_TARGET
- }
- function release_type_select
- {
- local release_type
- local RELEASE_TYPES="debug release"
- project_select_from "build release type:" "$RELEASE_TYPES" "debug" BUILD_RELEASE_TYPE
- }
- function compiler_select
- {
- local compiler_version
- local COMPILER_VERSIONS=
- for compiler_version in $(cd $COMPLIER_PATH; /bin/ls); do
- COMPILER_VERSIONS="$COMPILER_VERSIONS $compiler_version"
- done
- if [[ $BUILD_TARGET =~ "8850" ]] || [[ $BUILD_TARGET =~ "8860" ]]; then
- COMPLIER_DEFAULT=gcc-arm-none-eabi-10.2.1
- else
- COMPLIER_DEFAULT=gcc-arm-none-eabi-9.2.1
- fi
- project_select_from "build compiler version:" "$COMPILER_VERSIONS" "$COMPLIER_DEFAULT" BUILD_COMPILER_VERSION
- }
- function tfm_depends_build
- {
- if [[ $BUILD_TARGET =~ "TFM" ]]; then
- echo
- echo "TFM build"
- mkdir -p $PROJECT_OUT && cd $PROJECT_OUT
- cmake ../.. -G Ninja
- cd $PROJECT_ROOT
- echo "cmake ../.. -G Ninja"
- else
- echo "no TFM build"
- fi
- }
- function project_show
- {
- echo
- echo "=========================="
- echo "PATH=$PATH"
- echo "PROJECT_ROOT=$PROJECT_ROOT"
- echo "PROJECT_OUT=$PROJECT_OUT"
- echo "BUILD_TARGET=$BUILD_TARGET"
- echo "BUILD_RELEASE_TYPE"="$BUILD_RELEASE_TYPE"
- echo "BUILD_COMPILER_VERSION"="$BUILD_COMPILER_VERSION"
- echo "KCONFIG_CONFIG=$KCONFIG_CONFIG"
- }
- if [ -z "$1" ]; then
- project_select
- release_type_select
- compiler_select
- else
- export BUILD_TARGET=$1
- if [[ $BUILD_TARGET =~ "8850" ]]; then
- COMPLIER_DEFAULT=gcc-arm-none-eabi-10.2.1
- else
- COMPLIER_DEFAULT=gcc-arm-none-eabi-9.2.1
- fi
- if [ -z "$2" ]; then
- export BUILD_RELEASE_TYPE=debug
- export BUILD_COMPILER_VERSION=$COMPLIER_DEFAULT
- else
- export BUILD_RELEASE_TYPE=$2
- if [ -z "$3" ]; then
- export BUILD_COMPILER_VERSION=$COMPLIER_DEFAULT
- else
- export BUILD_COMPILER_VERSION=$3
- fi
- fi
- fi
- export KCONFIG_CONFIG=$PROJECT_ROOT/target/$BUILD_TARGET/target.config
- export PROJECT_OUT=$PROJECT_ROOT/out/${BUILD_TARGET}_${BUILD_RELEASE_TYPE}
- prepend_var PATH $COMPLIER_PATH/$BUILD_COMPILER_VERSION/bin
- tfm_depends_build
- project_show
- unset -f project_select
- unset -f project_select_from
- unset -f release_type_select
- unset -f compiler_select
- unset -f tfm_depends_build
- cout() {
- mkdir -p $PROJECT_OUT && cd $PROJECT_OUT
- }
- croot() {
- cd $PROJECT_ROOT
- }
|