Skip to content

Commit

Permalink
some spruce-ups and simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
jprjr committed Mar 1, 2018
1 parent dd792f8 commit b802b9f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 119 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
This script builds a small busybox-based chroot, useful
for compiling software that has a hard time with cross-compilation.

The arm/aarch64 chroots have `/bin/sh` replaced with a static program
to load and run qemu (included in the chroot). This way you can just run
something like:
The arm/aarch64 chroots have `qemu-[arm|aarch64]-static` installed
under `/bin`, and these have been patched to allow intercepting execve calls
(so you don't need to change your `binfmt_misc` entries).

You should be able to run them with a command like:

```
chroot /path/to/chroot /bin/sh
chroot chroots/arm-linux-musleabihf /bin/qemu-arm-static -execve /bin/sh
```

And everything should just work. No special kernel requirements needed!

See the releases tab for downloadable tarballs.

## Usage
Expand Down
34 changes: 14 additions & 20 deletions build
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ mkdir -p $CHROOTDIR/${TARGET}/tmp
mkdir -p $CHROOTDIR/${TARGET}/var
mkdir -p $CHROOTDIR/${TARGET}/etc

case "$TARGET" in
arm*)
tar xf $DOWNLOADDIR/qemu-2.9.0-arm.tar.gz -C $CHROOTDIR/${TARGET}/bin --strip-components=1
;;
aarch64*)
tar xf $DOWNLOADDIR/qemu-2.9.0-aarch64.tar.gz -C $CHROOTDIR/${TARGET}/bin --strip-components=1
;;
esac


if [[ ! -f "$DOWNLOADDIR/gcc-${GCC_VER}-${TARGET}.tar.xz" ]] ; then
printf 'Downloading cross-compiler\n'
Expand All @@ -91,7 +100,7 @@ echo "Building busybox"

CFLAGS="-g0 -Os" \
CXXFLAGS="-g0 -Os" \
LDFLAGS="-s -static" \
LDFLAGS="-s" \
PATH="$TOOLDIR/${TARGET}/bin:$PATH" \
$DOWNLOADDIR/bin/runlog -l $LOGDIR/busybox-${TARGET}-configure.txt -- \
make -C $BUILDDIR/${TARGET}/busybox-${BUSYBOX_VER} \
Expand All @@ -102,18 +111,20 @@ make -C $BUILDDIR/${TARGET}/busybox-${BUSYBOX_VER} \

CFLAGS="-g0 -Os" \
CXXFLAGS="-g0 -Os" \
LDFLAGS="-s -static" \
LDFLAGS="-s" \
PATH="$TOOLDIR/${TARGET}/bin:$PATH" \
$DOWNLOADDIR/bin/runlog -l $LOGDIR/busybox-${TARGET}-build.txt -- \
make -C $BUILDDIR/${TARGET}/busybox-${BUSYBOX_VER} \
-j$(nproc) \
CONFIG_PREFIX=$CHROOTDIR/${TARGET} \
CROSS_COMPILE=${TARGET}- \
VERBOSE=1 \
V=1 \
>/dev/null

CFLAGS="-g0 -Os" \
CXXFLAGS="-g0 -Os" \
LDFLAGS="-s -static" \
LDFLAGS="-s" \
PATH="$TOOLDIR/${TARGET}/bin:$PATH" \
$DOWNLOADDIR/bin/runlog -l $LOGDIR/busybox-${TARGET}-install.txt -- \
make -C $BUILDDIR/${TARGET}/busybox-${BUSYBOX_VER} \
Expand Down Expand Up @@ -267,23 +278,6 @@ cd $BUILDDIR
rm -rf $BUILDDIR/${TARGET}/make-${MAKE_VER}
rm -rf $TOOLDIR/${TARGET}

case "$TARGET" in
arm*)
tar xf $DOWNLOADDIR/qemu-2.9.0-arm.tar.gz -C $CHROOTDIR/${TARGET}/bin --strip-components=1
mv $CHROOTDIR/${TARGET}/bin/qemu-arm-static $CHROOTDIR/${TARGET}/bin/qemu-static
gcc -Wall -Wextra -s -static -o $CHROOTDIR/${TARGET}/bin/sh.fake ${THISDIR}/fakesh.c
rm $CHROOTDIR/${TARGET}/bin/sh
ln -s sh.fake $CHROOTDIR/${TARGET}/bin/sh
;;
aarch64*)
tar xf $DOWNLOADDIR/qemu-2.9.0-aarch64.tar.gz -C $CHROOTDIR/${TARGET}/bin --strip-components=1
mv $CHROOTDIR/${TARGET}/bin/qemu-aarch64-static $CHROOTDIR/${TARGET}/bin/qemu-static
gcc -Wall -Wextra -s -static -o $CHROOTDIR/${TARGET}/bin/sh.fake ${THISDIR}/fakesh.c
rm $CHROOTDIR/${TARGET}/bin/sh
ln -s sh.fake $CHROOTDIR/${TARGET}/bin/sh
;;
esac

tar -czf $DISTDIR/chroot-${short_arches[${TARGET}]}.tar.gz \
--owner 0 \
--group 0 \
Expand Down
2 changes: 1 addition & 1 deletion clean
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
set -e
set -x

rm -rf builds chroots dist downloads logs tools
rm -rf builds chroots dist logs tools
92 changes: 0 additions & 92 deletions fakesh.c

This file was deleted.

0 comments on commit b802b9f

Please sign in to comment.