-
Notifications
You must be signed in to change notification settings - Fork 44
/
create.buildroot
411 lines (372 loc) · 19.9 KB
/
create.buildroot
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
##
## Copyright (C) 2012 - 2024 XBian
##
## Find us at: http://www.xbian.org http://github.com/xbianonpi/xbian
##
## This Program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2, or (at your option)
## any later version.
##
## 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 XBMC; see the file COPYING. If not, see
## <http://www.gnu.org/licenses/>.
##
##
[ -n "$XBIANROOT" ] || export XBIANROOT=$(readlink -f ./)
if [ -e $XBIANROOT/common.functions ]; then
. $XBIANROOT/common.functions
else
echo "Wrong setup. Open folder containing xbianonpi/xbian clone and rerun \"./run.me prepare\""
exit 500
fi
do_wipe()
{
dir="$1"
do_run rm -fr "$dir/working"
}
do_prepare()
{
### CentOS doesn't have /sbin and /bin in $PATH by default
echo "Writing loader file /etc/profile.d/xbiangit.sh"
cat<<EOF>/etc/profile.d/xbiangit.sh
export xbiangit=$(pwd)/run.me
export XBIANROOT=$(pwd)
export PATH=/usr/lib/ccache:/sbin:/bin:\$PATH
export MAKEFLAGS="-j\$(grep -c processor /proc/cpuinfo )"
EOF
echo "Installing $config_deb_base"
if [ -f /etc/centos-release ]; then
VERSION_ID=0
if grep -q "5." /etc/centos-release; then VERSION_ID=5; fi
if grep -q "6." /etc/centos-release; then VERSION_ID=6; fi
if grep -q "7." /etc/centos-release; then VERSION_ID=7; fi
if [ $VERSION_ID -eq 5 ]; then
wget -q http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
rpm --quiet -Uvh epel-release-5*.rpm
rm epel-release-5*.rpm
elif [ $VERSION_ID -eq 6 ]; then
wget -q http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm --quiet -Uvh epel-release-6*.rpm
rm epel-release-6*.rpm
elif [ $VERSION_ID -eq 7 ]; then
wget -q http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
rpm --quiet -Uvh epel-release-7*.rpm
rm epel-release-7*.rpm
else
echo "Cannot install EPEL repository in CentOS"
exit 500;
fi
yum install -y $config_yum_base 2>/dev/null 1>/dev/null
else
apt-get install -y --force-yes -o Acquire::Languages=none -o APT::Install-Suggests=0 -o APT::Install-Recommends=0 -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" $config_deb_base 1>/dev/null
fi
echo "Installing done..."
}
do_deps()
{
dir=$(readlink -f "$1")
cp "$dir/extra-files/$config_platform.conf" /etc/schroot/chroot.d
sed -i "s%__DIR__%$config_root_prefix/$config_platform%" /etc/schroot/chroot.d/$config_platform.conf
mkdir -p $config_root_prefix/$config_platform
mkdir -p $config_root_prefix/$config_platform/etc/apt/apt.conf.d
cp "$dir/extra-files/04autoremove" $config_root_prefix/$config_platform/etc/apt/apt.conf.d
cp "$dir/extra-files/05xbian" $config_root_prefix/$config_platform/etc/apt/apt.conf.d
cp "$dir/extra-files/schroot-fstab" /etc/schroot/schroot-fstab-$config_platform
sed -i "s%__DIR__%$(readlink -f $fstabbind)%g" /etc/schroot/schroot-fstab-$config_platform
}
do_prep()
{
[ -e $config_root_prefix/$config_platform/debootstrap ] && return
dir=$(readlink -f "$1")
debootstrap --no-check-gpg --include=eatmydata,wget --arch $config_distro_arch --foreign $config_distro_name $dir $config_distro_url
mkdir -p $dir/usr/bin; cp /usr/bin/qemu-arm-static $dir/usr/bin
eatmydata=($(grep eatmydata $config_root_prefix/$config_platform/debootstrap/debpaths | awk '{print $2}'))
for pkg in ${eatmydata[@]}; do
dpkg -x $config_root_prefix/$config_platform/$pkg $config_root_prefix/$config_platform
done
schroot --directory / -p -c $config_platform -- debootstrap/debootstrap --second-stage || (
# As it was written (for Debian Stretch) we have to do this ugly workaround
schroot --directory / -p -c $config_platform -- debootstrap/debootstrap --second-stage || (
systemdsysv=($(grep systemd-sysv $config_root_prefix/$config_platform/debootstrap/debpaths | awk '{print $2}'))
for pkg in ${systemdsysv[@]}; do
schroot --directory / -p -c $config_platform -- dpkg -i $pkg
done
schroot --directory / -p -c $config_platform -- debootstrap/debootstrap --second-stage
)
)
echo "deb $config_distro_url $config_distro_name main" > $dir/etc/apt/sources.list
### Since apt-get version > 1.0.* --force-yes option is depreciated we have to use --allow options
[ "$(schroot --directory / -p -c $config_platform -- apt-get --version | grep ^apt | awk '{ print $2 }')" \< "1.1" ] && FORCE="--yes --force-yes" || FORCE="--yes --allow-downgrades --allow-remove-essential"
case "$config_platform" in
"amd64jessie")
echo "deb http://emdebian.org/tools/debian/ jessie main" >> $dir/etc/apt/sources.list
schroot -c $config_platform --directory / -p -- wget -qO- http://emdebian.org/tools/debian/emdebian-toolchain-archive.key | schroot -c $config_platform -p -- apt-key add -
schroot -c $config_platform --directory / -p -- dpkg --add-architecture armhf
LC_ALL=C schroot -c $config_platform --directory / -p -- apt-get update
LC_ALL=C schroot -c $config_platform --directory / -p -- apt-get install $FORCE crossbuild-essential-armhf
;;
amd64stretch|amd64buster|amd64bullseye|amd64bookworm)
echo $config_install_deb | grep -q -m1 :armhf && schroot -c $config_platform --directory / -p -- dpkg --add-architecture armhf && crossbuilds=crossbuild-essential-armhf
echo $config_install_deb | grep -q -m1 :arm64 && schroot -c $config_platform --directory / -p -- dpkg --add-architecture arm64 && crossbuilds="$crossbuilds crossbuild-essential-arm64"
LC_ALL=C schroot -c $config_platform --directory / -p -- apt-get update
LC_ALL=C schroot -c $config_platform --directory / -p -- apt-get install $FORCE $crossbuilds
;;
esac
LC_ALL=C schroot --directory / -p -c $config_platform -- apt-get clean
}
do_other()
{
### Since apt-get version > 1.0.* --force-yes option is depreciated we have to use --allow options
[ "$(schroot --directory / -p -c $config_platform -- apt-get --version | grep ^apt | awk '{ print $2 }')" \< "1.1" ] && FORCE="--yes --force-yes" || FORCE="--yes --allow-downgrades --allow-remove-essential --allow-change-held-packages"
dir=$(readlink -f "$1")
printf "#!/bin/sh\n\necho $config_xbian_arch\n" > $dir/usr/local/bin/xbian-arch; chmod +x $dir/usr/local/bin/xbian-arch
LC_ALL=C schroot --directory / -p -c $config_platform -- apt-get update
LC_ALL=C schroot --directory /tmp -p -c $config_platform -- apt-get install $FORCE lsb-release
schroot --directory /tmp -p -c $config_platform -- rm -rf apt.xbian.org
schroot --directory /tmp -p -c $config_platform -- wget -r -l1 -q --no-parent $config_package_repo
repofile="$(schroot --directory /tmp -p -c $config_platform -- find ./ -name 'xbian-package-repo*.deb' 2>/dev/null | sort -r | grep -m1 xbian-package-repo)"
echo "Latest repo file is $repofile"
schroot --directory /tmp -p -c $config_platform -- dpkg -i --force-confdef --force-confnew $repofile
schroot --directory / -p -c $config_platform -- sed -i 's/curl/notcurl/g' /etc/apt/preferences.d/xbian
case $config_xbian_arch in
RPI) rpref="rpi"; mpref="armv6l" ;;
RPI2) rpref="rpi2"; mpref="armv7l" ;;
iMX6) rpref="imx6"; mpref="armv7l" ;;
*) rpref=''; mpref='' ;;
esac
[ -z $rpref ] || schroot --directory / -p -c $config_platform -- sed -i "s/unknown-/$rpref-/g" /etc/apt/sources.list.d/xbian.list
[ -z $mpref ] || schroot --directory / -p -c $config_platform -- sed -i "s/x86_64-/$mpref-/g" /etc/apt/sources.list.d/xbian.list
[ -z $mpref ] || schroot --directory / -p -c $config_platform -- sed -i "s/armv7l-/$mpref-/g" /etc/apt/sources.list.d/xbian.list
schroot --directory / -p -c $config_platform -- sed -i 's/### //g' /etc/apt/sources.list.d/xbian.list
case "$config_platform" in
amd64*)
schroot --directory / -c $config_platform -p -- sed -i -e 's/^deb m/deb [arch=armhf] m/g' /etc/apt/sources.list.d/xbian.list
#distri="$(echo $config_platform | sed 's/amd64//g')"
distri="$(lsb_release -cs 2>/dev/null)"
#echo $distri
schroot --directory / -c $config_platform -p -- sed -i "s/ -$distri/ /g;s/\(^deb.*\)$/\1\ armv7l-$distri arm64-$distri/g" /etc/apt/sources.list.d/xbian.list
myarch=armhf # Eeek
;;
*)
myarch=$config_distro_arch
;;
esac
case "$config_platform" in
*stretch*|*jessie*|*buster*|*bullseye*|*bookworm*)
# As it was written (for Debian Stretch) apt-get does not work with method mirror://
schroot --directory / -c $config_platform -p -- sed -i -e 's%mirror://apt.xbian.org/mirror.txt%http://apt.xbian.org/%g' /etc/apt/sources.list.d/xbian.list
;;
*)
echo "FIXME: apt-get update fails"
exit 1
;;
esac
schroot --directory / -p -c $config_platform -- cat /etc/apt/sources.list.d/xbian.list
LC_ALL=C schroot --directory / -p -c $config_platform -- apt-get update 2>/dev/null
LIBCDEV=''
case "$config_platform" in
*v6)
;;
*)
### Since Debian's linux-libc-dev package breaks XBian's (as it was written for Debian Stetch), we have to install files manually later
schroot --directory / -c $config_platform -p -- rm -f /etc/apt/preferences.d/01_linux-libc-dev_$myarch
LC_ALL=C schroot --directory / -p -c $config_platform -- apt-get update
schroot --directory /tmp -c $config_platform -p -- find ./ -name 'linux-libc-dev*.deb' -delete
schroot --directory /tmp -c $config_platform -p -- apt-get download linux-libc-dev:$myarch
LIBCDEV="$(schroot --directory /tmp -c $config_platform -p -- find ./ -maxdepth 1 -name 'linux-libc-dev*.deb' 2>/dev/null | sort -r | grep -m1 linux-libc-dev)"
cat<<EOF>/tmp/01_libc6_$myarch
Package: linux-libc-dev:$myarch libc6:$myarch libc6-dev:$myarch libc-dev-bin:$myarch libc-l10n locales
Pin: release o=XBian
Pin-Priority: -1
Package: linux-libc-dev:$myarch libc6:$myarch libc6-dev:$myarch libc-dev-bin:$myarch libc-l10n locales
Pin: release o=Debian
Pin-Priority: 1001
EOF
schroot --directory / -c $config_platform -p -- mv /tmp/01_libc6_$myarch /etc/apt/preferences.d/
;;
esac
LC_ALL=C schroot --directory / -p -c $config_platform -- apt-get update
LC_ALL=C schroot --directory / -p -c $config_platform -- apt-get install $FORCE -o Acquire::Languages=none -o APT::Install-Suggests=0 -o APT::Install-Recommends=0 -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" $config_install_deb
[ -z "$config_install_deb_s2" ] || LC_ALL=C schroot --directory / -p -c $config_platform -- apt-get install $FORCE -o Acquire::Languages=none -o APT::Install-Suggests=0 -o APT::Install-Recommends=0 -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" $config_install_deb_s2
[ -z "$config_install_deb_s3" ] || {
LC_ALL=C schroot --directory /tmp/apt.xbian.org -p -c $config_platform -- apt-get download $config_install_deb_s3
( cd /tmp/apt.xbian.org; $XBIANROOT/modify-debs Multi-Arch:\ same; LC_ALL=C schroot --directory /tmp/apt.xbian.org -p -c $config_platform -- dpkg -i --force-all repacked/*.deb; )
LC_ALL=C schroot --directory /tmp/apt.xbian.org -p -c $config_platform -- apt-mark hold $config_install_deb_s3 || :
}
[ -z "$config_install_deb_s4" ] || LC_ALL=C schroot --directory / -p -c $config_platform -- apt-get install $FORCE -o Acquire::Languages=none -o APT::Install-Suggests=0 -o APT::Install-Recommends=0 -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" $config_install_deb_s4
L1=$(schroot --directory / -p -c $config_platform -- locale 2>/dev/null | grep "LANG=" | cut -d '=' -f 2)
L2=$(echo $L1 | sed -e "s/UTF-8/utf8/g")
schroot --directory / -p -c $config_platform -- locale -a 2>/dev/null | grep -qE "$L1|$L2" || { \
schroot --directory / -p -c $config_platform -- sed -i -e "s/# $L1/$L1/g" /etc/locale.gen; \
schroot --directory / -p -c $config_platform -- locale-gen;
}
case "$config_xbian_arch" in
"iMX6")
# Install firmware files for RPi manually if not already there
if ! schroot --directory / -c $config_platform -p -- dpkg-query -s xbian-package-firmware &>/dev/null; then
schroot --directory /tmp -c $config_platform -p -- wget -r -l1 -q --no-parent $config_package_firmware
FW="$(schroot --directory /tmp -c $config_platform -p -- find ./ -name 'xbian-package-firmware*.deb' 2>/dev/null | sort -r | grep -m1 xbian-package-firmware)"
echo "Latest firmware is $FW"
schroot --directory /tmp -c $config_platform -p -- dpkg -x $FW /
schroot --directory /tmp -c $config_platform -p -- rm -f $FW
fi
# Copy OpenGLES libs for i.MX6 to the right place
if schroot --directory / -c $config_platform -p -- dpkg-query -s firmware-imx &>/dev/null; then
schroot --directory / -c $config_platform -p -- find /usr/lib/xbmc -name "*" -exec cp -av {} /usr/lib/ \; || :
fi
# Copy some .pc files to the correct place
schroot --directory / -c $config_platform -p -- [ -e /usr/lib/pkgconfig/libcdio.pc ] && \
schroot --directory / -c $config_platform -p -- cp -a /usr/lib/pkgconfig/libcdio.pc /usr/lib/arm-linux-gnueabihf/pkgconfig || :
schroot --directory / -c $config_platform -p -- [ -e /usr/lib/pkgconfig/libcec.pc ] && \
schroot --directory / -c $config_platform -p -- cp -a /usr/lib/pkgconfig/libcec.pc /usr/lib/arm-linux-gnueabihf/pkgconfig || :
;;
esac
case "$config_platform" in
amd64*)
### Set for some stupid configure scripts the correct compiler we use
cat<<EOF>/tmp/gcc
#!/bin/bash
BASENAME=${0##*/}
echo $BASENAME: $@ >&2
env | grep -wE "CROSS_COMPILE|CPP" >&2
if [ -n "$CROSS_COMPILE" ]; then
case $BASENAME in
cc|gcc) exec /usr/bin/x86_64-linux-gnu-gcc $@ ;;
g++) exec /usr/bin/x86_64-linux-gnu-g++ $@ ;;
esac
fi
case $BASENAME in
gcc) cxx=$(echo $CPP | sed "s/ .*//g") ;;
g++) cxx=$(echo $CPP | sed "s/gcc .*/g++/g") ;;
esac
[ -n "$cxx" ] && exec $cxx $@
echo "$BASENAME: $@" > /tmp/gcc-hook.err
env >> /tmp/gcc-hook.err
echo "No $BASENAME"
exit 1
EOF
chmod +x /tmp/gcc
schroot --directory /usr/bin -c $config_platform -p -- rm -f gcc g++ || :
schroot --directory /usr/bin -c $config_platform -p -- mv /tmp/gcc . || :
schroot --directory /usr/bin -c $config_platform -p -- ln -s gcc g++ || :
### Install libtool if still needed. Unfortunately because of wrong dependencies can't do it in the normal way
schroot --directory / -c $config_platform -p -- dpkg-query -s libtool &>/dev/null || { \
schroot --directory /tmp -c $config_platform -p -- rm -f libtool*.deb; \
schroot --directory /tmp -c $config_platform -p -- apt-get download libtool; \
LIBTOOL="$(schroot --directory /tmp -c $config_platform -p -- find ./ -maxdepth 1 -name 'libtool*.deb' 2>/dev/null | sort -r | grep -m1 libtool)"; \
echo "Have to install libtool package files manually from $LIBTOOL"; \
schroot --directory /tmp -c $config_platform -p -- dpkg -x $LIBTOOL /; \
schroot --directory /tmp -c $config_platform -p -- rm -f libtool*.deb; \
}
### Tell some stupid configure scripts that we are building for armXX architecture
cat << \EOF > /tmp/uname
#!/bin/bash
BASENAME=${0##*/}
if [ "$1" = '-m' ] ; then
cxx=$(echo $CPP | sed "s/gcc .*/g++/g")
case "$cxx" in
arm*) echo armv7l; exit 0 ;;
aarch64*) echo aarch64; exit 0 ;;
esac
cxx=$(echo $CROSS_COMPILE | sed "s/gcc .*/g++/g")
case "$cxx" in
arm*) echo armv7l; exit 0 ;;
aarch64*) echo aarch64; exit 0 ;;
*) echo "$BASENAME: $@" > /tmp/uname-hook.err; env >> /tmp/uname-hook.err; exit 1 ;;
esac
fi
exec /usr/bin/uname $@
EOF
chmod +x /tmp/uname
schroot --directory / -c $config_platform -p -- mv /tmp/uname /usr/local/bin
;;
esac
[ -n "$LIBCDEV" ] && { \
echo "Installing linux-libc-dev package files manually from $LIBCDEV"; \
schroot --directory /tmp -c $config_platform -p -- dpkg -x $LIBCDEV /; \
}
schroot --directory / -p -c $config_platform -- apt-get clean
### Install links for that f...... TexturePacker
schroot --directory /usr/lib -c $config_platform -p -- ln -s /opt/vc/lib/libvchiq_arm.so
schroot --directory /usr/lib -c $config_platform -p -- ln -s /opt/vc/lib/libvcos.so
schroot --directory /usr/lib -c $config_platform -p -- ln -s /opt/vc/lib/libbcm_host.so
### Let ldd work for arm binaries in schroot
schroot --directory / -c $config_platform -p -- sed -i 's%RTLDLIST="/lib/ld-linux.so.2%RTLDLIST="/lib/ld-linux.so.2 /lib/ld-linux-$myarch.so.3%g' /usr/bin/ldd
}
# ----------------------
[ $(id -u) -ne 0 ] && do_exit "for buildroot preparation run again with root privileges" 20
if [ $1 = prepare ]; then
[ -e xbian-prep-root/build/config ] && rexp build/config || :
do_prepare
exit $?
fi
GETOPT=$(getopt \
--longoptions=action:,arch:,config_source_refresh:,help,debug \
--options=a:m:h \
-- "$@" ) \
|| exit 128
for dir in $(find build/ -mindepth 1 -maxdepth 1 -type d | sort); do
unset $(env | grep config_ | awk -F'=' '{print $1}')
result=0
[ -e build/config ] && rexp build/config
[ -e "$dir/config" ] && rexp "$dir/config"
eval set -- ${GETOPT}
while [ "$#" -gt '0' ]; do
case "$1" in
(--debug)
set -x
shift 1
;;
(--action|-a)
opt_action=$2
shift 2
;;
(--arch|-m)
opt_arch=$2
shift 2
;;
(--config_*)
param=$1
param="${param##--}=$2"
do_run export $param
shift 2
;;
(--help|-h)
do_show_help
exit 0
;;
*)
shift 1
;;
esac
done
[ -n "$opt_arch" -a "$opt_arch" != $(basename "$dir") ] && continue
[ -z "$opt_arch" ] && opt_arch=$(basename "$dir")
export config_platform=${opt_arch%%-*}
export config_platform_branch=$opt_arch
export config_branch=${opt_arch##*-}
if [ -z "$config_root_prefix" ]; then
export config_root_prefix=$(readlink -f $XBIANROOT/build-root-dirs)
else
mkdir -p $(readlink -f $XBIANROOT/build-root-dirs)
ln -s $config_root_prefix/$config_platform $(readlink -f $XBIANROOT/build-root-dirs)/$config_platform
fi
export fstabbind=$(readlink -f $(dirname $0))
case $opt_action in
other)
( do_other "$config_root_prefix/$config_platform" )
;;
""|build)
( do_deps "$XBIANROOT/xbian-prep-root" )
( do_prep "$config_root_prefix/$config_platform" )
( do_other "$config_root_prefix/$config_platform" )
;;
esac
done
printf "\n-------------------------------\nFINISHED OK\n-------------------------------\n"