From 816f1c81f7e394663c55f013ba797bcd6dd58cac Mon Sep 17 00:00:00 2001
From: Damiano Amatruda <damiano.amatruda@skywarder.eu>
Date: Sat, 13 Nov 2021 19:32:36 +0100
Subject: [PATCH] [SBS] Allow to list all available boards

---
 cmake/sbs.cmake | 17 +++++++++--------
 sbs             | 13 +++++++++----
 2 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/cmake/sbs.cmake b/cmake/sbs.cmake
index f2a25c086..94686ef08 100644
--- a/cmake/sbs.cmake
+++ b/cmake/sbs.cmake
@@ -37,16 +37,17 @@ endif()
 
 include(dependencies)
 
-function(sbs_mxgui TARGET)
-    get_target_property(OPT_BOARD ${TARGET} OPT_BOARD)
-    if(NOT OPT_BOARD)
-        message(FATAL_ERROR "No board selected")
-    endif()
+include(${KPATH}/config/boards.cmake)
 
-    target_link_libraries(${TARGET} mxgui::mxgui-${OPT_BOARD})
-endfunction()
+string(REPLACE ";" "\\n" BOARDS_STR "${BOARDS}")
+add_custom_target(
+    help-boards
+    COMMAND printf ${BOARDS_STR}
+    COMMENT "All boards available:"
+    VERBATIM
+)
 
-function(sbs_target TARGET)
+function(sbs_get_board TARGET)
     get_target_property(OPT_BOARD ${TARGET} OPT_BOARD)
     if(NOT OPT_BOARD)
         message(FATAL_ERROR "No board selected")
diff --git a/sbs b/sbs
index abd068c07..dd56f8e00 100755
--- a/sbs
+++ b/sbs
@@ -1,7 +1,7 @@
 #!/bin/sh
 
 # Copyright (c) 2021 Skyward Experimental Rocketry
-# Authors: Damiano Amatruda
+# Author: Damiano Amatruda
 #
 # Permission is hereby granted, free of charge, to any person obtaining a copy
 # of this software and associated documentation files (the "Software"), to deal
@@ -64,9 +64,11 @@ build_all() { check_configured && cmake --build "$build_dir" $build_jobs; }
 
 build() { check_configured && cmake --build "$build_dir" $build_jobs --target "$1"; }
 
-list() { check_configured && echo "All SBS targets available:" && \
+list() { check_configured && echo "[1/1] All SBS targets available:" && \
     cmake --build "$build_dir" $build_jobs --target help | grep -o '^[^/]*\.bin' | cut -f 1 -d '.'; }
 
+boards() { check_configured && cmake --build "$build_dir" $build_jobs --target help-boards; }
+
 lint() { "$sbs_base/scripts/linter.sh" "$source_dir/src/shared"; }
 
 check_configured() { ([ ! -d "$build_dir" ] || [ ! -f "$build_dir/CMakeCache.txt" ] && rm -rf "$build_dir") && configure && echo || true; }
@@ -84,7 +86,8 @@ OPTIONS:
   -c, --clean           Clean the working tree
   -b TARGET, --build TARGET
                         Build a specific target
-  -l, --list            List all possible configurations
+  -l, --list            List all possible targets
+  -r, --boards          List all possible boards
   -v, --verbose         Print a verbose output
   -n, --lint            Run the linter
   -j JOBS, --jobs JOBS  Build in parallel using the given number of jobs
@@ -109,6 +112,7 @@ for arg in "$@"; do
         --clean)    set -- "$@" "-c";;
         --build)    set -- "$@" "-b";;
         --list)     set -- "$@" "-l";;
+        --boards)   set -- "$@" "-r";;
         --verbose)  set -- "$@" "-v";;
         --lint)     set -- "$@" "-n";;
         --jobs)     set -- "$@" "-j";;
@@ -116,12 +120,13 @@ for arg in "$@"; do
     esac
 done
 
-while getopts hcb:lvnj: opt; do
+while getopts hcb:lrvnj: opt; do
     case "$opt" in
         h)  usage; exit 0;;
         c)  clean; exit 0;;
         b)  build "$OPTARG"; exit 0;;
         l)  list; exit 0;;
+        r)  boards; exit 0;;
         v)  set_verbose;;
         n)  lint; exit 0;;
         j)  set_jobs "$OPTARG";;
-- 
GitLab