#!/bin/bash
#------------------------------------------------------------------------------
#
#
#
#------------------------------------------------------------------------------


if [ -d "libs/libstm" ]; then
. libs/libstm/tools/build.sh
else
. libstm/tools/build.sh
fi

TCBASE=/opt/tcb/tcb-stm32/usr/bin/arm-none-eabi/arm-none-eabi-
TCPOSTFIX=
list="stm32l151c6 stm32l011f4 stm32l151c6 stm32l152c8 stm32l431rc stm32f103c6 stm32l443cc stm32f042g6 stm32g030c8 stm32g441kb"
# list=stm32f042g6

# arm-linux-gnueabihf-gcc-12

# buildType=Release
buildType=Debug
memory=flash

# arenaBoard="st_discovery_f072"
# arenaBoard="stm32f072cx"
arenaBoard="st_nucleo_f303"
mcuBoard="st_nucleo_f303"
# arenaBoard="st_nucleo_f072"
# mcuBoard="st_nucleo_f072"
subApp=foo
targetApp=sthello
arenaApp=sthello

      # set ( ARENA_BOARD "st_nucleo_f303" )
      # set ( ARENA_BOARD "stm32l011f4" )
      # set ( ARENA_BOARD "stm32l151c6" )
      # set ( ARENA_BOARD "stm32l152c8" )
      # set ( ARENA_BOARD "stm32l152r6" )
      # set ( ARENA_BOARD "stm32l431rc" )
      # set ( ARENA_BOARD "stm32f303" )
      # set ( ARENA_BOARD "stm32f103c6" )
      # set ( ARENA_BOARD "stm32l443cc" )
      # set ( ARENA_BOARD "stm32l031f6" )
      # set ( ARENA_BOARD "stm32f042f6" )
      # set ( ARENA_BOARD "stm32f042g4" )
      # set ( ARENA_BOARD "stm32f042g6" )
      # set ( ARENA_BOARD "stm32g030c8" )
      # set ( ARENA_BOARD "stm32g441kb" )

for BOARD in $list; do
   B=build-${BOARD}
   rm -rf $B
   mkdir -p $B
   cd $B
   cmake \
    .. \
    -DHOST=OFF \
    -DCMAKE_BUILD_TYPE=Debug \
    -DCMAKE_C_COMPILER:STRING=${TCBASE}gcc${TCPOSTFIX} \
    -DCMAKE_CXX_COMPILER_AR:STRING=ar \
    -DCMAKE_CXX_COMPILER_RANLIB:STRING=ranlib \
    -DCMAKE_CXX_COMPILER:STRING=${TCBASE}g++${TCPOSTFIX} \
    -DCROSS_GDB=/usr/bin/gdb \
    -DARENA_BOARD=$BOARD
   make
   cd ..
done

#     -DARENA_BOARD=stm32l011f4
#     -DARENA_BOARD=stm32l151c6
#     -DARENA_BOARD=stm32l152c8
#     -DARENA_BOARD=stm32l431rc
#     -DARENA_BOARD=stm32f103c6
#    -DARENA_BOARD=stm32l443cc
#     -DARENA_BOARD=stm32f042g6
#     -DARENA_BOARD=stm32g030c8
#     -DARENA_BOARD=stm32g441kb
# make

echo
echo "[$0] fin."


#---fin------------------------------------------------------------------------
