summaryrefslogtreecommitdiff
path: root/build_cross.sh
blob: 6689c50861495613b2120f88749c2eed9a75125f (plain)
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
#!/bin/sh

. "./default.conf"

# Prepare the cross-compiler for the destination platform, in our
# case i486.

if test ! "$(getent group cross)"; then
	groupadd cross
fi

if test ! "$(getent passwd cross)"; then
	useradd -m -g cross cross
fi

# add 'cross' user as sudoer without password
if test ! -f /etc/sudoers.d/cross; then
	echo "cross ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/cross
fi

# we need the github keys
if test ! -d $CROSS_HOME/.ssh; then
	mkdir $CROSS_HOME/.ssh
	chown cross:cross $CROSS_HOME/.ssh
fi
if test ! -f $CROSS_HOME/.ssh/id_rsa.pub; then
	cp $HOME/.ssh/id_rsa.pub $CROSS_HOME/.ssh/.
	cp $HOME/.ssh/id_rsa $CROSS_HOME/.ssh/.
	chown cross:cross $CROSS_HOME/.ssh/id_rsa*
fi

if test ! -x /usr/local/bin/ct-ng; then
	echo "Installing crosstool-ng:"
	su - cross <<EOF
mkdir cross
cd cross
git clone https://github.com/crosstool-ng/crosstool-ng.git
cd crosstool-ng
./bootstrap
./configure --prefix=/usr/local
make
sudo make install
cd ..
EOF
	echo "Done crosstool-ng."
fi

if test ! -x $CROSS_HOME/x-tools/${TARGET_ARCH}/bin/${TARGET_ARCH}-gcc; then
	echo "Building cross compiler for ${TARGET_ARCH}=gcc:"
	rm -rf $CROSS_HOME/{x-tools,.build,build.log,.wget-hsts,.config,.config.old}
	cp ct-ng.config $CROSS_HOME/.config
	CPUS=$(nproc)
	sed -i "s/^CT_PARALLEL_JOBS=.*/CT_PARALLEL_JOBS=$CPUS/" $CROSS_HOME/.config
	chown cross:cross $CROSS_HOME/.config
	su - cross <<EOF
ct-ng build
EOF
	echo "Done creating the cross compiler."
fi

echo -n "Cross-compiler ready: "
CROSS_MSG="$($CROSS_HOME/x-tools/${TARGET_ARCH}/bin/${TARGET_ARCH}-gcc --version | head -n 1)"
echo $CROSS_MSG