forked from motioneye-project/motioneyeos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·156 lines (121 loc) · 4.59 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
#!/bin/bash
if [ -z "$1" ]; then
echo "Usage: $0 <{board}|all|boards> [mkimage|mkrelease|clean-target|initramfs|make-targets...]"
echo " mkimage - creates the OS image (.img)"
echo " mkrelease - creates the compressed OS image (.img.gz, .img.xz)"
echo " clean-target - removes the target dir, preserving the package build dirs"
echo " initramfs - builds the initramfs image; extra arguments will be passed internally to BuildRoot"
echo ""
echo " for other make targets, see the BuildRoot manual"
exit 1
fi
set -e # exit at first error
board=$1
target=${*:2}
cd $(dirname $0)
basedir=$(pwd)
gzip=$(which pigz 2> /dev/null || which gzip 2> /dev/null)
# extra environment from local file
test -f $basedir/.build-env && source $basedir/.build-env
# OS name
if [ -n "$THINGOS_SHORT_NAME" ]; then
osname=$THINGOS_SHORT_NAME
else
osname=$(source $basedir/board/common/overlay/etc/version && echo $OS_SHORT_NAME)
fi
# OS version
if [ -n "$THINGOS_VERSION" ]; then
osversion=$THINGOS_VERSION
else
osversion=$(source $basedir/board/common/overlay/etc/version && echo $OS_VERSION)
fi
# when the special "boards" keyword is used for board, simply list all known boards
if [ "$board" == "boards" ]; then
boards=$(ls $basedir/configs/*_defconfig | grep -v initramfs | grep -oE '\w+_defconfig$' | cut -d '_' -f 1)
for b in $boards; do
echo $b
done
exit 0
fi
# when the special "all" keyword is used for board, all boards are processed, in turn
if [ "$board" == "all" ]; then
boards=$(ls $basedir/configs/*_defconfig | grep -v initramfs | grep -oE '\w+_defconfig$' | cut -d '_' -f 1)
for b in $boards; do
if ! $0 $b $target; then
exit 1
fi
done
exit 0
fi
outputdir=$basedir/output/$board
boarddir=$basedir/board/$board
if ! [ -f $basedir/configs/${board}_defconfig ]; then
echo "unknown board: $board"
exit 1
fi
function prepare_target_dir() {
if [ -L $outputdir/target/var/lib ]; then
rm $outputdir/target/var/lib
mkdir $outputdir/target/var/lib
fi
}
mkdir -p $outputdir
if ! [ -f $outputdir/.config ]; then
make O=$outputdir ${board}_defconfig
fi
if [ "$target" == "mkimage" ]; then
$boarddir/mkimage.sh
elif [ "$target" == "mkrelease" ]; then
test -f $outputdir/images/$osname-$board.img || $boarddir/mkimage.sh
cp $outputdir/images/$osname-$board.img $outputdir/images/$osname-$board-$osversion.img
echo "preparing compressed xz image"
rm -f $outputdir/images/$osname-$board-$osversion.img.xz
xz -6ek -T 0 $outputdir/images/$osname-$board-$osversion.img
echo "your xz image is ready at $outputdir/images/$osname-$board-$osversion.img.xz"
echo "preparing compressed gz image"
rm -f $outputdir/images/$osname-$board-$osversion.img.gz
$gzip $outputdir/images/$osname-$board-$osversion.img
echo "your gz image is ready at $outputdir/images/$osname-$board-$osversion.img.gz"
rm -f $outputdir/images/$osname-$board-$osversion.img
elif [ "$target" == "clean-target" ]; then
if [ -d $outputdir/target ]; then
echo "removing target directory"
rm -rf $outputdir/target/*
echo "removing staging directory"
rm -rf $outputdir/staging/*
echo "removing images directory"
rm -rf $outputdir/images/*
fi
if [ -d $outputdir/build ]; then
echo "removing .stamp_target_installed files"
find $outputdir/build -name .stamp_target_installed | xargs -r rm
echo "removing .stamp_staging_installed files"
find $outputdir/build -name .stamp_staging_installed | xargs -r rm
echo "removing .stamp_host_installed files"
find $outputdir/build -name .stamp_host_installed | xargs -r rm
echo "removing .stamp_images_installed files"
find $outputdir/build -name .stamp_images_installed | xargs -r rm
echo "removing linux kernel build dir"
make O=$outputdir linux-dirclean
fi
if [ -f $outputdir/.config ]; then
echo "removing .config file"
rm -f $outputdir/.config
fi
echo "target is clean"
elif [[ "$target" == initramfs* ]]; then
extra_args=${target:10}
$0 ${board}_initramfs $extra_args
if [ -z "$extra_args" ] && [ -x $boarddir/cpinitramfs.sh ]; then
IMG_DIR=$basedir/output/${board}_initramfs/images/ BOARD_DIR=$boarddir $boarddir/cpinitramfs.sh
fi
elif [ "$target" == "all" ]; then
prepare_target_dir
make O=$outputdir all
elif [ -n "$target" ]; then
prepare_target_dir
make O=$outputdir $target
else # if [ -z "$target ]
$0 $board all
echo "build successful"
fi