-
-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathprepare-build.sh
executable file
·210 lines (187 loc) · 6.85 KB
/
prepare-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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/bin/bash
# Copyright (C) 2015 Florent Revest <revestflo@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
declare -a devices=("anthias" "bass" "beluga" "catfish" "dory" "firefish" "harmony" "hoki" "koi" "inharmony" "lenok" "minnow" "mooneye" "narwhal" "nemo" "pike" "qemux86" "ray" "smelt" "sparrow" "sparrow-mainline" "sprat" "sturgeon" "sawfish" "skipjack" "swift" "tetra" "triggerfish" "wren")
declare -a layers=(
"src/oe-core https://github.com/openembedded/openembedded-core.git scarthgap"
"src/oe-core/bitbake https://github.com/openembedded/bitbake.git 2.8.1"
"src/meta-openembedded https://github.com/openembedded/meta-openembedded.git scarthgap"
"src/meta-qt5 https://github.com/meta-qt5/meta-qt5 scarthgap"
"src/meta-smartphone https://github.com/shr-distribution/meta-smartphone scarthgap"
"src/meta-asteroid https://github.com/AsteroidOS/meta-asteroid master"
"src/meta-asteroid-community https://github.com/AsteroidOS/meta-asteroid-community master"
"src/meta-smartwatch https://github.com/AsteroidOS/meta-smartwatch.git master"
)
declare -a layers_conf=(
"meta-qt5"
"oe-core/meta"
"meta-asteroid"
"meta-asteroid-community"
"meta-openembedded/meta-oe"
"meta-openembedded/meta-multimedia"
"meta-openembedded/meta-gnome"
"meta-openembedded/meta-networking"
"meta-smartphone/meta-android"
"meta-openembedded/meta-python"
"meta-openembedded/meta-filesystems"
)
function printNoDeviceInfo {
echo "Usage:"
echo -e "Updating the sources:\t$ . ./prepare-build.sh update"
echo -e "Building AsteroidOS:\t$ . ./prepare-build.sh device\n"
echo -e "Available devices:\n"
for device in ${devices[*]}; do
echo "$device"
done
echo -e "\nWiki - Building AsteroidOS: https://asteroidos.org/wiki/building-asteroidos/"
return 1
}
# When updating, if the user has a personal fork of the subproject, and has set the
# upstream URL, this will fetch updates from the upstream repository
function pull_dir {
if [ -d $1/.git/ ] ; then
[ "$1" != "." ] && pushd $1 > /dev/null
git symbolic-ref HEAD &> /dev/null
if [ $? -eq 0 ] ; then
echo -e "\e[32mPulling $1\e[39m"
if git remote get-url upstream &> /dev/null
then
git pull upstream --rebase "$2"
else
git pull --rebase
fi
[ $? -ne 0 ] && echo -e "\e[91mError pulling $1\e[39m"
git checkout "$2"
else
echo -e "\e[35mSkipping $1\e[39m"
fi
[ "$1" != "." ] && popd > /dev/null
fi
}
function clone_dir {
if [ ! -d $1 ] ; then
echo -e "\e[32mCloning branch $3 of $2 in $1\e[39m"
git clone -b $3 $2 $1
[ $? -ne 0 ] && echo -e "\e[91mError cloning $1\e[39m"
if [ $# -eq 4 ]
then
pushd $1
git checkout $4
popd
fi
fi
}
function update_layer_config() {
if [ ! -e build/conf/bblayers.conf ]; then
return
fi
# Find all layers under src/meta-smartwatch, remove the src/ prefix, sort alphabetically, and store it in an array.
layers_smartwatch=($(find src/meta-smartwatch -mindepth 1 -name "*meta-*" -type d | sed -e 's|src/||' | sort))
layers=("${layers_conf[@]}" "${layers_smartwatch[@]}")
tmpfile=$(mktemp)
for l in "${layers[@]}"; do
cp build/conf/bblayers.conf "${tmpfile}"
layer_line=" \${SRCDIR}/${l} \\\\"
# Check if layer exists, insert if it doesn't.
awk -v line="$layer_line" -v l="$l" "
FNR==NR {
if(\$0~l){ found=1 }
next
}
/BBLAYERS/ && found==\"\" {
print \$0 ORS line
next
}
1
" "${tmpfile}" "${tmpfile}" > build/conf/bblayers.conf
done
rm "${tmpfile}"
}
# Update layers in src/
if [[ "$1" == "update" ]]; then
pull_dir . master
for l in "${layers[@]}"; do
if [ -n "$ZSH_VERSION" ]; then
read -A layer <<< "$l"
else
read -a layer <<< "$l"
fi
if [ -d "${layer[@]:0:1}" ]; then
pull_dir "${layer[@]:0:1}" "${layer[@]:2:1}"
fi
done
update_layer_config
elif [[ "$1" == "git-"* ]]; then
base=$(dirname $0)
gitcmd=${1:4} # drop git-
shift
for d in $base $base/src/* $base/src/oe-core/bitbake; do
if [ $(git -C $d $gitcmd "$@" | wc -c) -ne 0 ]; then
echo -e "\e[35mgit -C $d $gitcmd $@ \e[39m"
git -C $d $gitcmd "$@"
fi
done
# Prepare bitbake
else
mkdir -p src build/conf
if [ "$#" -gt 0 ]; then
# checking if the device is supported
valid=false
for device in ${devices[*]}; do
[[ "${1}" == "$device" ]] && valid=true
done
if [[ "$valid" = true ]]; then
export MACHINE=${1}
else
printNoDeviceInfo
return 1
fi
else
printNoDeviceInfo
return 1
fi
# Fetch all the needed layers in src/
for l in "${layers[@]}"; do
if [ -n "$ZSH_VERSION" ]; then
read -A layer <<< "$l"
else
read -a layer <<< "$l"
fi
clone_dir "${layer[@]:0:1}" "${layer[@]:1:1}" "${layer[@]:2:1}" "${layer[@]:3:1}"
done
# Create local.conf and bblayers.conf on first run
if [ ! -e build/conf/local.conf ]; then
echo -e "\e[32mWriting build/conf/local.conf\e[39m"
echo 'DISTRO = "asteroid"
PACKAGE_CLASSES = "package_ipk"' >> build/conf/local.conf
fi
if [ ! -e build/conf/bblayers.conf ]; then
echo -e "\e[32mWriting build/conf/bblayers.conf\e[39m"
echo 'BBPATH = "${TOPDIR}"
SRCDIR = "${@os.path.abspath(os.path.join("${TOPDIR}", "../src/"))}"
BBLAYERS = " \
"' > build/conf/bblayers.conf
update_layer_config
fi
# Init build env
cd src/oe-core
. ./oe-init-build-env ../../build > /dev/null
echo "Welcome to the Asteroid compilation script.
If you meet any issue you can report it to the project's github page:
https://github.com/AsteroidOS
You can now run the following command to get started with the compilation:
bitbake asteroid-image
Have fun!"
fi