LingYun open library local/cross compile shell scripts
guowenxue
18 hours ago 000034a74bd306535c4c4ca715587c08142c6b55
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/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