summaryrefslogtreecommitdiffstats
path: root/bootstrap-main.sh
diff options
context:
space:
mode:
Diffstat (limited to 'bootstrap-main.sh')
-rwxr-xr-xbootstrap-main.sh115
1 files changed, 115 insertions, 0 deletions
diff --git a/bootstrap-main.sh b/bootstrap-main.sh
new file mode 100755
index 0000000..88289cf
--- /dev/null
+++ b/bootstrap-main.sh
@@ -0,0 +1,115 @@
+#!/bin/sh
+
+set -e
+
+SCRIPT_DIR=
+ARCH=
+PLAT=
+
+main()
+{
+ SCRIPT_DIR="$(cd "${0%/*}" && pwd)"
+ setup_arch_plat
+ prepare_packages
+ stage1
+}
+
+setup_arch_plat()
+{
+ ARCH="$(cat /etc/proteanos_arch)"
+ PLAT="$(cat /etc/proteanos_plat)"
+}
+
+prepare_packages()
+{
+ local repo pkg src_opk path dir
+
+ [ -d pkg ] || mkdir pkg
+ cd pkg
+
+ for repo in zlib toolchains/binutils linux-libre eglibc \
+ gmp toolchains/gcc-4.7 toolchains/gcc-defaults \
+ busybox gmake; do
+ if [ ! -d "${repo##*/}" ]; then
+ git clone --depth 1 \
+ "git://git.proteanos.com/pkg/${repo}.git"
+ fi
+ cd "${repo##*/}"
+ git pull origin master
+ if [ -x config ]; then
+ ./config clean
+ PKG_TARGETS="${ARCH}" ./config
+ fi
+ if [ -f source.mk -a ! -f "${repo##*/}"*.orig.tar* ]; then
+ opkbuild -bCT source
+ fi
+ opkbuild -SC
+ cd ..
+ done
+
+ for pkg in mpc mpfr; do
+ if [ ! -d "${pkg}" ]; then
+ src_opk="src-${pkg}_*_src_all.opk"
+ path="pub/pkg/${pkg}/${src_opk}"
+ wget "ftp://files.proteanos.com/${path}"
+ tar -xzOf ${src_opk} data.tar.gz | tar -xz
+ mv "usr/src/${pkg}_"* "${pkg}"
+ fi
+ done
+ [ -d usr/src ] && rmdir usr/src
+ [ -d usr ] && rmdir usr
+
+ for dir in */; do
+ if [ -d "${SCRIPT_DIR}/patches/${dir}" ]; then
+ for patch in "${SCRIPT_DIR}/patches/${dir}"*; do
+ patch -N -p 1 -u -d "${dir}" -i "${patch}"
+ done
+ fi
+ done
+
+ cd ..
+}
+
+stage1()
+{
+ local dir opk elf_interp zlib_upstream_ver
+
+ cd pkg
+
+ for dir in */; do
+ cd "${dir}"
+ opkbuild -bC
+ cd ..
+ done
+
+ cd ..
+
+ [ -d "root_${ARCH}" ] && rm -Rf "root_${ARCH}"
+ mkdir "root_${ARCH}"
+ cd "root_${ARCH}"
+
+ for opk in ../pkg/*_${ARCH}_${PLAT}.opk ../pkg/*_${ARCH}_all.opk \
+ ../pkg/*_all_${PLAT}.opk ../pkg/*_all_all.opk; do
+ [ -f "${opk}" ] || continue
+ tar -xzOf "${opk}" data.tar.gz | tar -xz
+ done
+
+ elf_interp="$(readelf -l bin/busybox | sed -n \
+ 's|^.*\[Requesting program interpreter: /\(.*\)\].*$|\1|p')"
+ mkdir -p "${elf_interp%/*}"
+ ln -sf "/lib/${ARCH}/${elf_interp##*/}" "${elf_interp}"
+
+ sudo chroot . true
+ sudo chroot . readelf -hl /usr/bin/readelf
+
+ zlib_upstream_ver="$(printf '%s' ../pkg/zlib/zlib-*.orig.tar* | sed \
+ 's|^.*/zlib-\([a-z0-9.~]*\).*\.orig\.tar.*$|\1|')"
+ tar -xjOf ../pkg/zlib/zlib-*.orig.tar* \
+ "zlib-${zlib_upstream_ver}/examples/fitblk.c" >fitblk.c
+ sudo chroot . "${ARCH}-gcc" -lz -o /fitblk /fitblk.c
+ sudo chroot . /fitblk | grep -F 'fitblk abort' >/dev/null
+
+ cd ..
+}
+
+main "${@}"