summaryrefslogtreecommitdiff
path: root/scripts/bootstrap.sh
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/bootstrap.sh')
-rwxr-xr-xscripts/bootstrap.sh164
1 files changed, 105 insertions, 59 deletions
diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh
index 206eab750..3617a0c74 100755
--- a/scripts/bootstrap.sh
+++ b/scripts/bootstrap.sh
@@ -1,7 +1,7 @@
#!/bin/sh -e
#===============================================================
-# Filename : scripts/bootstrap.sh (part of Adélie package repo).
+# Filename : bootstrap.sh
# Purpose : Bootstraps Adélie from source for any architecture.
# Authors : Zach van Rijn <me@zv.io>
# License : MIT
@@ -37,7 +37,7 @@
#
# * One-click bootstrap. Just start the script and walk away.
#
-# $ ./scripts/bootstrap.sh ppc64 /path/to/new/scratch/dir
+# $ ./bootstrap.sh ppc64 /path/to/new/scratch/dir
#
# * Can be done without root privileges: no 'chroot(8)'.
#
@@ -51,12 +51,72 @@
# * Minimal dependencies. Nothing fancy. Shell scripts only.
#
# * Can be adapted to assist with porting Adélie to new target
-# architectures. TODO: write a tool to automatically do it.
+# architectures. TODO: write a tool to automatically do so.
#
# (*) We don't count binaries in your starting environment, and
# recommend https://www.gnu.org/software/mes/ for the brave.
#
#
+# design
+# ------
+#
+# The goal of this script is to support as wide a range of uses
+# as possible. For example, a full cross-platform bootstrap that
+# needs to be done without target hardware or virtual machines.
+#
+# There are a few different strategies, depending on your needs
+# and what type of privileges/hardware you have access to.
+#
+# In this diagram, indentation refers to an output product, and
+# moving down vertically refers to an input step. CPU A is the
+# build architecture, and CPU B is the target architecture. Your
+# mileage may vary, and you can mix/match other approaches..
+#
+# * CPU A --> CPU B (slowest: no privilege, no CPU B hardware)
+# --> Bootstrap 1 (Cross Libc + Partial Cross CPU B)
+# --> CPU A + CPU B Mixed Rootfs
+# --> Partial Emulation (PRoot)
+# --> Bootstrap 2 (Full Cross CPU B)
+# --> CPU B Host Rootfs
+# --> Full Emulation (PRoot)
+# --> Adélie Bootstrap
+# --> Adélie Rootfs for CPU B
+#
+# * CPU A --> CPU B (slower: privilege, no CPU B hardware)
+# --> Bootstrap 1 (Cross Libc + Partial Cross CPU B)
+# --> CPU A + CPU B Mixed Rootfs
+# --> Partial Emulation (registered binfmt_misc)
+# --> Bootstrap 2 (Full Cross CPU B)
+# --> CPU B Host Rootfs
+# --> Full Emulation (registered binfmt_misc)
+# --> Adélie Bootstrap
+# --> Adélie Rootfs for CPU B
+#
+# * CPU A --> CPU B (faster; no privilege, CPU B hardware)
+# --> Bootstrap 1 (Cross Libc + Partial Cross CPU B)
+# --> CPU A + CPU B Mixed Rootfs
+# --> Partial Emulation (PRoot)
+# --> Bootstrap 2 (Full Cross CPU B)
+# --> CPU B Host Rootfs
+# --> Copy to Native CPU B Hardware
+# --> Adélie Bootstrap
+# --> Adélie Rootfs for CPU B
+#
+# * CPU B --> CPU B (fastest; QEMU-system or native hardware)
+# --> Bootstrap 1 (Cross Libc)
+# --> CPU B Mixed Rootfs
+# --> Bootstrap 2 (Remove Contamination)
+# --> CPU B Host Rootfs
+# --> Adélie Bootstrap
+# --> Adélie Rootfs for CPU B
+#
+# The resulting Adélie Rootfs is capable of building the entire
+# Adélie Linux distribution from source. We use it to seed our
+# official build servers. This removes the dependency on using
+# previous binary releases of our distribution, which had been
+# manually bootstrapped way back from Gentoo and/or on a G5.
+#
+#
# requirements
# ------------
#
@@ -68,6 +128,9 @@
# and the decision to emulate a native environment instead of to
# force explicit cross-compilation at each step in the process.
#
+# Targeting an architecture of opposite endianness will be even
+# slower; this is a QEMU limitation.
+#
# If you wish to bootstrap to the same target CPU architecture,
# or a compatible mode (e.g. i686 on x86_64), it will be faster.
#
@@ -87,38 +150,6 @@
# To do this, you'd essentially comment out the first stages or
# copy the results of the first stages elsewhere and continue.
#
-# There are a few different sequences, depending on your needs.
-# In this diagram, indentation refers to an output product, and
-# moving down vertically refers to an input step.
-#
-# * CPU A --> CPU B (slow; no access to CPU B hardware)
-# --> Bootstrap 1 (Cross Libc + Partial Cross CPU B)
-# --> CPU A + CPU B Mixed Rootfs
-# --> Partial Emulation
-# --> Bootstrap 2 (Full Cross CPU B)
-# --> CPU B Host Rootfs
-# --> Full Emulation
-# --> Adélie Bootstrap
-# --> Adélie Rootfs for CPU B
-#
-# * CPU A --> CPU B (faster; access to CPU B hardware)
-# --> Bootstrap 1 (Cross Libc + Partial Cross CPU B)
-# --> CPU A + CPU B Mixed Rootfs
-# --> Partial Emulation
-# --> Bootstrap 2 (Full Cross CPU B)
-# --> CPU B Host Rootfs
-# --> Copy to Native CPU B Hardware
-# --> Adélie Bootstrap
-# --> Adélie Rootfs for CPU B
-#
-# * CPU A --> CPU A (fastest)
-# --> Bootstrap 1 (Cross Libc)
-# --> CPU A Mixed Rootfs
-# --> Bootstrap 2 (Remove Contamination)
-# --> CPU A Host Rootfs
-# --> Adélie Bootstrap
-# --> Adélie Rootfs for CPU A
-#
# Other requirements that you should be aware of, estimated:
#
# * As many CPU cores as you can throw at it;
@@ -289,14 +320,15 @@ EOF
# ARCH is translated to canonical GCC and QEMU machine types.
#
case "${1}" in
-# adelie gcc qemu
-# ------ --- ----
- aarch64) m=aarch64 ; q=aarch64 ; ;;
- armv7) m=armv7l ; q=arm ; ;;
- ppc) m=powerpc ; q=ppc ; ;;
- ppc64) m=powerpc64 ; q=ppc64 ; ;;
- x86_64) m=x86_64 ; q=x86_64 ; ;;
- pmmx) m=i586 ; q=i386 ; ;;
+# adelie gcc qemu
+# ------ --- ----
+ aarch64) m=aarch64: ; q=aarch64 ; ;;
+ armv7) m=armv7l:eabihf ; q=arm ; ;;
+ ppc) m=powerpc: ; q=ppc ; ;;
+ ppc64) m=powerpc64: ; q=ppc64 ; ;;
+ riscv64) m=riscv64: ; q=riscv64 ; ;;
+ x86_64) m=x86_64: ; q=x86_64 ; ;;
+ pmmx) m=i586: ; q=i386 ; ;;
*) usage ;;
esac
shift;
@@ -317,6 +349,7 @@ case "${1}" in
exit 1;
;;
esac
+shift;
##
@@ -325,7 +358,7 @@ esac
CHAINS=https://git.zv.io/toolchains;
printf "CHAINS=%s\n" "${CHAINS}";
-SYSTEM="-linux-musl"; # we only target musl on Linux
+SYSTEM="-adelie-linux-musl"; # we only target musl on Linux
printf "SYSTEM=%s\n" "${SYSTEM}";
NATIVE=$(cc -dumpmachine); # host arch, host libc
@@ -334,7 +367,7 @@ printf "NATIVE=%s\n" "${NATIVE}";
BUILDS="${NATIVE%%-*}${SYSTEM}"; # host arch, musl libc
printf "BUILDS=%s\n" "${BUILDS}";
-TARGET="${m}${SYSTEM}"; # ultimate Adélie Linux target
+TARGET="${m%:*}${SYSTEM}${m#*:}"; # ultimate Adélie Linux target
printf "TARGET=%s\n" "${TARGET}";
MTOOLS=${MCMTOOLS:-"${BASE}/mcmtools"}; # CAREFUL! MAY CAUSE DATA LOSS!
@@ -345,6 +378,8 @@ printf "MTOOLS=%s\n" "${MTOOLS}";
#
DEF_PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin";
+mkdir -p "${BASE}";
+
#---------------------------------------------------------------
# mcmtools (seed)
@@ -363,7 +398,7 @@ if ! test -d "${MTOOLS}/sys/emus/bin"; then # FIXME: no hard code
test -d bootstrap \
|| git clone ${CHAINS}/bootstrap.git;
cd bootstrap;
- git checkout 2a79c1e5ea43e6fab23cf1e18b8a4104cfb9cef1;
+ git checkout a7c0a77976484755650932d1b6070bb7003c5025;
## seed rootfs
#
@@ -373,27 +408,35 @@ if ! test -d "${MTOOLS}/sys/emus/bin"; then # FIXME: no hard code
# We copy 'config.mak' from mcmtools bootstrap to the rootfs
# so that when we build "real" toolchain they are the same.
#
- test -d "${MTOOLS}" || \
DEST="${MTOOLS}" \
ARCH=${BUILDS} \
./bootstrap \
;
+ # cleaning
+ (
+ cd "${MTOOLS}";
+ rm -fr tmp; # save 10 GB
+ )
test -f "${MTOOLS}"/config.mak || \
cp "${MTOOLS}"/tmp/musl-cross-make/config.mak \
"${MTOOLS}"/config.mak \
;
# cleaning
- cd "${MTOOLS}";
- rm -fr tmp; # save 10 GB
+ (
+ cd "${MTOOLS}";
+ rm -fr tmp; # save 10 GB
+ )
# is any of this actually needed?
- cd "${MTOOLS}"/sys;
- mkdir -p dev;
- mkdir -p proc;
- mkdir -p sys;
- rm -fr usr;
- ln -s . usr;
+ (
+ cd "${MTOOLS}"/sys;
+ mkdir -p dev;
+ mkdir -p proc;
+ mkdir -p sys;
+ rm -fr usr;
+ ln -s . usr;
+ )
## emulators
#
@@ -453,7 +496,7 @@ if ! test -d "${MTOOLS}"/sys/tc/native; then # FIXME: no hard code
#
# Note: "native" is for the foreign target CPU architecture.
#
- PATH="${MTOOLS}/musl/bin:${MTOOLS}/sys/bin" \
+ MCMTOOLS="${MTOOLS}" \
./scripts/build ${TARGET} \
;
for k in cross native; do
@@ -478,7 +521,6 @@ PATH="/tc/cross/bin:${DEF_PATH}" \
SHELL=/bin/sh \
DEST=/usr/local \
CURL_CA_BUNDLE=/cacert.pem \
-CROSS_COMPILE=${TARGET}- \
CC=${TARGET}-gcc \
CXX=${TARGET}-g++ \
AR=${TARGET}-ar \
@@ -533,8 +575,6 @@ fi
#
# FIXME: is Linux 3.2.0 really appropriate here?
#
-# TODO: add 'if' gate for whether to execute this ... don't want
-# to run it every time.
if ! test -d "${BASE}"/mcmtools-${TARGET}/sys/tc/musl/bin; then # FIXME: no hard code
PROOT_NO_SECCOMP=1 \
PATH="/tc/native/bin:${DEF_PATH}" \
@@ -553,6 +593,12 @@ ${MTOOLS}/sys/emus/bin/proot \
;
fi
+# cleaning
+(
+ cd "${BASE}"/mcmtools-${TARGET};
+ rm -fr tmp; # save 10 GB
+)
+
##
# Install the native static toolchain over the native rootfs for
# a quick way to have the dynamic loader. Overwrite the symlink!