Skip to content

Commit 744cd4f

Browse files
committed
#8 Working on adding configuration scripts to build a debian container that will compile arm libraries that are openpandora compatible
1 parent 2f6a418 commit 744cd4f

File tree

3 files changed

+332
-0
lines changed

3 files changed

+332
-0
lines changed
+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/usr/bin/env bash
2+
3+
# This is the script that installs the required dependencies and runs the final setups on the system
4+
5+
set -x
6+
set -e
7+
8+
: ${OPENSSL_DIR:=/build/openssl}
9+
: ${OPENSSL_SRC:=$OPENSSL_DIR/openssl_src}
10+
: ${CMAKE_SRC:=/build/cmake}
11+
: ${CMAKE_TAG:=v3.3.2}
12+
: ${LLVM_SRC:=/build/llvm}
13+
: ${LLVM_BUILD:=/build/llvm_build}
14+
15+
if [ $(($(nprocs) / 2)) >= 1 ]; then
16+
MAKE_JOBS=$(($(nprocs) / 2))
17+
if [ $(($(nprocs) % 2)) == 1 ] && [ $(nprocs) > 2 ]; then
18+
MAKE_JOBS=$(($MAKE_JOBS + 1))
19+
fi
20+
else
21+
MAKE_JOBS=1
22+
fi
23+
24+
# Set the sources correctly
25+
echo "deb http://mirrordirector.raspbian.org/raspbian/ wheezy main contrib non-free rpi" > /etc/apt/sources.list
26+
echo "deb http://httpredir.debian.org/debian wheezy-backports main" >> /etc/apt/sources.list
27+
echo "deb http://archive.raspberrypi.org/debian/ wheezy main" >> /etc/apt/sources.list
28+
29+
cd /
30+
apt-key add raspbian.public.key
31+
rm raspbian.public.key
32+
33+
apt-key add raspberrypi.gpg.key
34+
rm raspberrypi.gpg.key
35+
36+
apt-key add archive-key-7.0.asc
37+
rm archive-key-7.0.asc
38+
39+
apt-get update
40+
# GCC-4.8 and G++-4.8
41+
apt-get install --allow-unauthenticated -qq openssl zlib1g-dev git curl python ccache gcc-4.8 g++-4.8 file build-essential pkg-config subversion
42+
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 50 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8
43+
44+
cd ~
45+
# Set the container tag if it wasn't properly inherited
46+
if [ -z $CONTAINER_TAG ]; then
47+
if [ -f CONTAINER_TAG ]; then
48+
CONTAINER_TAG=$(cat CONTAINER_TAG)
49+
fi
50+
fi
51+
52+
# Print a file with system info
53+
echo "$(uname -a)" > SYSTEM_INFO
54+
echo "$(dpkg -l | grep libc6)" >> SYSTEM_INFO
55+
echo "$(ldd --version | head -n 1)" >> SYSTEM_INFO
56+
echo "$(ld --version | head -n 1)" >> SYSTEM_INFO
57+
echo "$(gcc --version | head -n 1)" >> SYSTEM_INFO
58+
echo "$(g++ --version | head -n 1)" >> SYSTEM_INFO
59+
echo "$(clang --version | tr '\\n' '|' | head -n 1)" >> SYSTEM_INFO
60+
echo "$(clang++ --version | tr '\\n' '|' | head -n 1)" >> SYSTEM_INFO
61+
echo "$(ccache --version | head -n 1)" >> SYSTEM_INFO
62+
63+
# Echo settings to the Build Configuration file
64+
echo "USE_CLANG=true" > BUILD_CONFIGURATION
65+
66+
# Run the dropbox uploader configuration script
67+
bash dropbox_uploader.sh
68+
69+
# Make sure our dropbox root directory exists
70+
bash dropbox_uploader.sh mkdir ${CONTAINER_TAG}
71+
72+
# Build OpenSSL with the required information for use in building cargo
73+
cd $OPENSSL_SRC
74+
# configure for armv4 minimum, with an arch of armv6, fPIC so it can be included
75+
# as a static library, produce shared libraries and install it into the openssl/dist directory
76+
./Configure linux-armv4 -march=armv6 -fPIC shared --prefix=$OPENSSL_DIR/dist
77+
make -j $MAKE_JOBS
78+
make install
79+
80+
# Build a newer cmake through the boostrapping process
81+
cd ${CMAKE_SRC}
82+
./bootstrap
83+
make -j $MAKE_JOBS
84+
make install
85+
86+
# Build a new clang to use :D
87+
cd ${LLVM_BUILD}
88+
cmake \
89+
-DCMAKE_BUILD_TYPE=Release \
90+
-DCMAKE_CROSSCOMPILING=True \
91+
-DLLVM_DEFAULT_TARGET_TRIPLE=arm-unknown-linux-gnueabihf \
92+
-DLLVM_TARGETS_TO_BUILD=ARM \
93+
-DLLVM_TARGET_ARCH=ARM \
94+
-DCMAKE_C_FLAGS="-O2 -march=armv6 -mfloat-abi=hard -mfpu=vfp" \
95+
-DCMAKE_CXX_FLAGS="-O2 -march=armv6 -mfloat-abi=hard -mfpu=vfp" \
96+
-G "Unix Makefiles" \
97+
${LLVM_SRC}
98+
make -j $MAKE_JOBS
99+
make install
+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/usr/bin/env bash
2+
3+
#
4+
# debootstrap, curl, and git need to be installed for this script
5+
# This script needs to be run with root privleges
6+
#
7+
# It expects no argurments, but supports two inputs
8+
# 1: An optional name for the container
9+
# 2: An optional arch other then the default arch of armhf
10+
#
11+
# If you are planning on cross compiling, you'll need binfmt and qemu-static
12+
# properly configured for the arch you chose for this to work.
13+
#
14+
# I suggest reading https://wiki.debian.org/QemuUserEmulation and customizing
15+
# it to your host linux distribution. I use ArchLinux as the host for my
16+
# systems, and it has reasonable support in the AUR to get the configured
17+
# quickly.
18+
#
19+
# For example on my Arch machine, if I want to cross compile an container.
20+
# I install binfmt-support and qemu-user-static from AUR with the following
21+
# command: (I use yaourt for package management)
22+
#
23+
# yaourt -S binfmt-support qemu-user-static
24+
#
25+
# Then I use 'update-binfmts --display' to show the architectures available
26+
#
27+
# Finally for arm i run 'binfmt-update --enable qemu-arm' to enable binfmt
28+
# to expose the static qemu for arm to my system for those binaries. This
29+
# process can be followed for any of the architectures supported under the
30+
# 'binfmt-update --display' command.
31+
#
32+
# Note!: In order for systemd-nspawn (or chroot) to support the new binfmt,
33+
# we'll need an additional configuration file and a system service restarted.
34+
#
35+
# Copy the etc/binfmt.d/qemu-arm.conf file to your /etc/binfmt.d/
36+
# Then run 'systemctl restart systemd-binfmt' to register the binfmt
37+
# Now, before you can run a container you'll need to copy over the applicable
38+
# qemu-<something>-static to the /bin folder of the new container.
39+
# Then you can run this creation script which will boostrap the container
40+
# creation and prepare everything for you.
41+
#
42+
# NOTE!: Emulation in this manner will be slower than running natively on a
43+
# powerful system of the desired architecture. However, this will be much
44+
# faster than trying to compile on an embedded system.
45+
#
46+
47+
set -x
48+
set -e
49+
50+
# enables pattern lists like +(...|...)
51+
shopt -s extglob
52+
53+
: ${CHROOT_DIR:=/chroots}
54+
: ${DEBIAN_VERSION:=lenny}
55+
: ${CHROOT_NAME:=RustBuild-openpandora}
56+
: ${ARCH_NAME:="--arch=armel"}
57+
# List of supported architectures
58+
: ${SUPPORTED_ARCHITECTURE:="[armel]"}
59+
: ${SUPPORTED_ARCHITECTURE_LIST:="+(armel)"}
60+
61+
# Check that the required software is installed before we procede
62+
command -v curl >/dev/null 2>&1 || { echo >&2 "I require curl but it's not installed. Aborting."; exit 1; }
63+
command -v git >/dev/null 2>&1 || { echo >&2 "I require git but it's not installed. Aborting."; exit 1; }
64+
command -v debootstrap >/dev/null 2>&1 || { echo >&2 "I require debootstrap but it's not installed. Aborting."; exit 1; }
65+
66+
# Optional custom name for the chroot
67+
if [ ! -z "$1" ]; then
68+
CHROOT_NAME=$1
69+
fi
70+
71+
if [ -d $CHROOT_DIR/$CHROOT_NAME ]; then
72+
read -p "$CHROOT_NAME already exists. Are you sure you want to continue? [y/N]: " -n 1 -r
73+
if [[ ! $REPLY =~ ^[Yy]$ ]]
74+
then
75+
exit 1;
76+
fi
77+
fi
78+
79+
# Allow the user to indicate a specified architecture
80+
# This requires the a custom name be specified
81+
if [ ! -z "$2" ]; then
82+
ARCH_NAME="--arch=$2"
83+
case $2 in
84+
$SUPPORTED_ARCHITECTURE_LIST)
85+
echo "Set container architecture to: $2"
86+
;;
87+
*)
88+
echo "$2 is not recognized as a supported architecture: $SUPPORTED_ARCHITECTURE"
89+
exit 1
90+
;;
91+
esac
92+
fi
93+
94+
mkdir -p $CHROOT_DIR
95+
cd $CHROOT_DIR
96+
debootstrap $ARCH_NAME $DEBIAN_VERSION $CHROOT_NAME
97+
98+
echo "Run 'openpandora_root_setup.sh $CHROOT_NAME' to configure the CHROOT with the required files and links."
+135
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
#!/usr/bin/env bash
2+
3+
#
4+
# Setup script to prepare a new debian instance for building rust on arm
5+
#
6+
7+
set -x
8+
set -e
9+
10+
: ${CHROOT_NAME:=RustBuild-openpandora}
11+
: ${CHROOT_TAG:=ARMv7-armel}
12+
# trunk is the latest development
13+
# branches/release_XY is the release of LLVM/CLang coresponding to X.Y
14+
# so branches/release_37 is LLVM/Clang 3.7
15+
: ${LLVM_RELEASE:="branches/release_37"}
16+
# Tag to grab for CMAKE
17+
: ${CMAKE_TAG:="v3.3.2"}
18+
19+
# Allow custom names
20+
if [ ! -z "$1" ]; then
21+
CHROOT_NAME="$1"
22+
fi
23+
24+
# Allow custom tags
25+
if [ ! -z "$2" ]; then
26+
CHROOT_TAG="$2"
27+
fi
28+
29+
: ${ROOT:=/chroots/$CHROOT_NAME}
30+
: ${CHROOT_HOME:=$ROOT/root}
31+
: ${BUILD:=$ROOT/build}
32+
: ${OPT:=$ROOT/opt}
33+
: ${OPENSSL_DIR:=$BUILD/openssl}
34+
: ${OPENSSL_VER:=OpenSSL_1_0_2d}
35+
: ${OPENSSL_SRC_DIR:=$OPENSSL_DIR/openssl_src}
36+
37+
cd $ROOT
38+
mkdir -p $BUILD
39+
mkdir -p $BUILD/{snapshot,patches}
40+
mkdir -p $BUILD/openssl/{dist,openssl_src}
41+
42+
# Make the opt directories for our cargo and rust builds
43+
mkdir -p $OPT/rust_{nightly,beta,stable}/{cargo,rust}
44+
45+
# Get the Rust and Cargo projects
46+
cd $BUILD
47+
if [ -d rust ]; then
48+
cd rust
49+
git checkout .
50+
git pull
51+
cd ..
52+
else
53+
git clone --recursive https://github.com/rust-lang/rust.git
54+
fi
55+
mkdir -p rust/build
56+
if [ -d cargo ]; then
57+
cd cargo
58+
git checkout .
59+
git pull
60+
cd ..
61+
else
62+
git clone --recursive https://github.com/rust-lang/cargo.git
63+
fi
64+
65+
# Get openssl
66+
cd $OPENSSL_DIR
67+
if [ ! -d $OPENSSL_SRC_DIR ]; then
68+
curl -L "https://github.com/openssl/openssl/archive/${OPENSSL_VER}.tar.gz" -o ${OPENSSL_VER}.tar.gz
69+
tar xzf ${OPENSSL_VER}.tar.gz
70+
mv $OPENSSL_DIR/openssl-$OPENSSL_VER/* $OPENSSL_SRC_DIR
71+
rm -r $OPENSSL_DIR/openssl-$OPENSSL_VER
72+
fi
73+
74+
# Make the distributable directory
75+
cd $CHROOT_HOME
76+
mkdir -p dist
77+
78+
#We're going to store the container tag in the bash shell configuration
79+
echo "export CONTAINER_TAG=${CHROOT_TAG}" >> .bashrc
80+
# And in a file in the root home directory
81+
echo "${CHROOT_TAG}" > CONTAINER_TAG
82+
83+
# Get the dropbox_uploader project script
84+
if [ -d Dropbox-Uploader ]; then
85+
cd Dropbox-Uploader
86+
git checkout .
87+
git pull
88+
cd ..
89+
else
90+
git clone https://github.com/andreafabrizi/Dropbox-Uploader.git
91+
fi
92+
chmod +x Dropbox-Uploader/dropbox_uploader.sh
93+
ln -sf Dropbox-Uploader/dropbox_uploader.sh dropbox_uploader.sh
94+
95+
# Get the project scripts and save them in the root
96+
if [ -d RustBuild ]; then
97+
cd RustBuild
98+
git checkout .
99+
git pull
100+
cd ..
101+
else
102+
git clone https://github.com/WarrickSothr/RustBuild.git
103+
fi
104+
105+
# link the project scripts to the appropriate directories
106+
chmod +x RustBuild/scripts/build/*.sh
107+
ln -sf RustBuild/scripts/build/*.sh .
108+
chmod +x RustBuild/scripts/setup/raspbian_configure.sh
109+
ln -sf RustBuild/scripts/setup/raspbian_configure.sh .
110+
111+
# Copy the patches
112+
cp RustBuild/patches/* ${BUILD}/patches
113+
114+
opwd=$pwd
115+
# clone Cmake
116+
mkdir ${BUILD}/cmake
117+
cd ${BUILD}/cmake
118+
git clone https://cmake.org/cmake.git .
119+
git checkout tags/$CMAKE_TAG
120+
121+
# clone LLVM/Clang
122+
mkdir ${BUILD}
123+
svn co http://llvm.org/svn/llvm-project/llvm/$LLVM_RELEASE llvm
124+
cd llvm/tools
125+
svn co http://llvm.org/svn/llvm-project/cfe/$LLVM_RELEASE clang
126+
cd clang/tools
127+
svn co http://llvm.org/svn/llvm-project/clang-tools-extra/$LLVM_RELEASE extra
128+
cd ../../../projects
129+
svn co http://llvm.org/svn/llvm-project/compiler-rt/$LLVM_RELEASE compiler-rt
130+
cd $opwd
131+
132+
mkdir ${BUILD}/llvm_build
133+
134+
# Run the configuration script in in a systemd nspawn
135+
systemd-nspawn -D ${ROOT} /bin/bash ~/raspbian_configure.sh

0 commit comments

Comments
 (0)