From 588586f0f3086ee157ad78843b16339bdbdfa7f1 Mon Sep 17 00:00:00 2001
From: guowenxue <guowenxue@gmail.com>
Date: Thu, 25 Nov 2021 23:47:44 +0800
Subject: [PATCH] update top build shell script

---
 bsp/build.sh |   94 +++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 83 insertions(+), 11 deletions(-)

diff --git a/bsp/build.sh b/bsp/build.sh
index 461e261..0ad0a30 100755
--- a/bsp/build.sh
+++ b/bsp/build.sh
@@ -11,8 +11,8 @@
 TAR_PATH=${PRJ_PATH}/tarball
 BSP_BRANCH="lf-5.10.52-2.1.0"
 
-# rootfs should be buildroot or stretch/buster/bullseye for debian system
-ROOTFS=buildroot
+# rootfs should be buildroot/yocto or stretch/buster/bullseye for debian system
+ROOTFS=buster
 
 set -u
 set -e
@@ -42,18 +42,90 @@
     do_modify_build images
 }
 
-function do_build()
+function do_root()
 {
-    cd $PRJ_PATH/tarball && ./build.sh && cd -
-
-    cd $PRJ_PATH/bootloader && ./build.sh && cd -
-
-    cd $PRJ_PATH/kernel && ./build.sh && cd -
-
-    cd $PRJ_PATH/rootfs && ./build.sh && cd -
+    echo ""
+    if [[ $1 == "yes" ]] && [ `id -u` != 0 ] ; then
+        echo "ERROR: This action must run as root!"
+        echo ""
+        exit;
+    elif [[ $1 != "yes" ]] && [ `id -u` == 0 ] ; then
+        echo "ERROR: This action cannot run as root!"
+        echo ""
+        exit;
+    fi
 }
+
+function do_action()
+{
+    folder=$1 
+    action=$2
+
+    cd $PRJ_PATH/$folder
+
+    if [ $action == "build" ] ; then
+        ./build.sh -b
+    elif [ $action == "clean" ] ; then
+        ./build.sh -c
+    fi  
+
+    cd $PRJ_PATH
+}
+
+
+function do_usage()
+{
+    echo ""
+    echo "Usage:"
+    echo " $0 [-b] [-c] [-h] bsp/image"
+    echo "     -b bsp/image: build BSP or system image"
+    echo "     -c bsp/image: clean BSP or system image"
+    echo "     -h          : show this help message"
+    echo ""
+    echo " WARNNING: build/clean image need run as sudo"
+    echo ""
+    echo "  Example: $0 -b bsp && sudo $0 -b image"
+    echo ""
+    exit;
+}
+
+
+action="usage"
+
+while getopts "b:c:h" OPTNAME
+do
+    case "${OPTNAME}" in
+        "b")
+            action="build"
+            shift
+            ;;
+
+        "c")
+            action="clean"
+            shift
+            ;;
+
+        "*")
+            action="usage"
+            ;;
+    esac
+done
+
+if [ $action == "usage" ] ; then
+    do_usage
+fi
 
 do_modify
 
-do_build
+if [ $1 == "bsp" ] ; then
+    if [ $action == "build" ] ; then
+        do_root "no"
+    fi
+    do_action bootloader $action
+    do_action kernel $action
+elif [ $1 == "image" ] ; then
+    do_root "yes"
+    do_action rootfs $action
+    do_action images $action
+fi
 

--
Gitblit v1.9.1