-
Notifications
You must be signed in to change notification settings - Fork 7
/
build.sh
executable file
·160 lines (138 loc) · 3.27 KB
/
build.sh
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/bin/bash
set -eE
trap 'echo Error: in $0 on line $LINENO' ERR
cd "$(dirname -- "$(readlink -f -- "$0")")"
mkdir -p build/logs
exec > >(tee "build/logs/build-$(date +"%Y%m%d%H%M%S").log") 2>&1
usage() {
BOARD_LIST=$(ls conf | grep ".conf")
BOARD_LIST_SHOW=
for i in $BOARD_LIST
do
if [ -z "$BOARD_LIST_SHOW" ];then
BOARD_LIST_SHOW="${i%".conf"}"
else
BOARD_LIST_SHOW="${BOARD_LIST_SHOW}|${i%".conf"}"
fi
done
cat << HEREDOC
Usage: $0 --board=[$BOARD_LIST_SHOW]
Required arguments:
-b, --board=BOARD target board
Optional arguments:
-l, --list-board list all boards can build
-s, --show=BOARD show the details of boards configure
-h, --help show this help message and exit
-c, --clean clean the build directory
-v, --verbose increase the verbosity of the bash script
HEREDOC
}
list_board() {
count=0
for i in $(ls conf | grep ".conf")
do
count=`expr $count + 1`
echo "$count. ${i%".conf"}"
done
}
show_board(){
if [ -f "conf/$1" ];then
source conf/$1
else
if [ -f "conf/$1.conf" ];then
source conf/$1.conf
else
echo "--- no board ---"
echo " Please choose one to show"
list_board
exit 1
fi
fi
echo BOARD_NAME=$BOARD_NAME
echo UBOOT_SYSTEM=$UBOOT_SYSTEM
}
for i in "$@"; do
case $i in
-h|--help)
usage
exit 0
;;
-b=*|--board=*)
export BOARD="${i#*=}"
shift
;;
-b|--board)
export BOARD="${2}"
shift
;;
-c|--clean)
export CLEAN=Y
;;
-l|--list-board)
list_board
exit 0
;;
-s=*|--show=*)
export BOARD="${i#*=}"
show_board $BOARD
sleep 0.5
exit 0
;;
-s|--show)
export BOARD="${2}"
show_board $BOARD
sleep 0.5
exit 0
;;
-v|--verbose)
set -x
shift
;;
-*)
echo "Error: unknown argument \"$i\""
usage
exit 1
;;
*)
;;
esac
done
show_board $BOARD
sleep 0.5
export VENDOR=$UBOOT_SYSTEM
export BOARD=$BOARD_NAME
export BOARD_SOC=$BOARD_SOC
export K_DEVICE_TREE=$DEVICE_TREE
export OVERLAY_PREFIX=$OVERLAY_PREFIX
export ROOTFS_TYPE=$ROOTFS_TYPE
export ROOTFS_SCRIPT=$ROOTFS_SCRIPT
export OVERLAY_ROOTFS=$OVERLAY_ROOTFS
if [ $(ls build | grep "u-boot-${VENDOR}"| grep deb) ];then
echo "skip build uboot"
else
echo "build uboot ..."
./scripts/build-uboot.sh -f
fi
if [ $(ls build | grep "linux-image-") ];then
echo "skip build kernel"
else
echo "build kernel ..."
./scripts/build-kernel.sh
fi
if [ -d "build/rootfs" ]; then
rm -r build/rootfs
fi
if [ -d "images" ]; then
rm -r images
fi
# build base filesystem
echo ROOTFS_TYPE=$ROOTFS_TYPE
if [ -f "./scripts/build-rootfs-${ROOTFS_TYPE}.sh" ];then
echo ./scripts/build-rootfs-${ROOTFS_TYPE}.sh
./scripts/build-rootfs-${ROOTFS_TYPE}.sh
else
echo "please choose your filesystem : desktop or server"
exit 1
fi
./scripts/config-image.sh
exit 0