#!/bin/bash
|
|
# Cross compiler for cross compile on Linux server
|
CROSS_COMPILE=/opt/gcc-aarch32-10.3-2021.07/bin/arm-none-linux-gnueabihf-
|
|
# this project absolute path
|
PRJ_PATH=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)
|
|
# binaries install path
|
PREFIX_PATH=$PRJ_PATH/install
|
|
# shell script will exit once get command error
|
set -e
|
|
#+-------------------------+
|
#| Shell script functions |
|
#+-------------------------+
|
|
function pr_error() {
|
echo -e "\033[40;31m $1 \033[0m"
|
}
|
|
function pr_warn() {
|
echo -e "\033[40;33m $1 \033[0m"
|
}
|
|
function pr_info() {
|
echo -e "\033[40;32m $1 \033[0m"
|
}
|
|
function check_result()
|
{
|
if [ $? != 0 ] ; then
|
pr_error $1
|
fi
|
}
|
|
do_build()
|
{
|
pr_warn "build all the project..."
|
|
for dir in */; do
|
[ -d "$dir" ] || continue
|
|
if [ -x "$dir/build.sh" ]; then
|
(
|
cd "$dir" || exit 1
|
./build.sh
|
)
|
fi
|
done
|
|
pr_info "==== Build: done ===="
|
}
|
|
do_clean()
|
{
|
pr_warn "clean all the project..."
|
|
for dir in */; do
|
[ -d "$dir" ] || continue
|
|
if [ -x "$dir/build.sh" ]; then
|
(
|
cd "$dir" || exit 1
|
./build.sh -c
|
)
|
fi
|
done
|
|
pr_info "==== Clean: install ===="
|
rm -rf $PREFIX_PATH
|
}
|
|
do_cross()
|
{
|
pr_warn "update crosstool $CROSS_COMPILE..."
|
|
for dir in */; do
|
[ -d "$dir" ] || continue
|
|
if [ -x "$dir/build.sh" ]; then
|
echo "==== update: ${dir%/} ===="
|
(
|
cd "$dir" || exit 1
|
sed -i "s|^CROSS_COMPILE=.*|CROSS_COMPILE=${CROSS_COMPILE}|g" build.sh
|
)
|
fi
|
done
|
}
|
|
case "$1" in
|
build)
|
do_build
|
;;
|
clean)
|
do_clean
|
;;
|
cross)
|
do_cross
|
;;
|
*)
|
echo "Usage: $0 {build|clean|cross}"
|
exit 1
|
;;
|
esac
|