Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 558868 - sys-apps/toybox - should allow building with static linking, CONFIG_SH
Summary: sys-apps/toybox - should allow building with static linking, CONFIG_SH
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: Low enhancement (vote)
Assignee: Patrick Lauer
Depends on:
Reported: 2015-08-27 02:19 UTC by Steve Gilberd
Modified: 2015-08-27 20:04 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Note You need to log in before you can comment on or make changes to this bug.
Description Steve Gilberd 2015-08-27 02:19:37 UTC
The ebuild for sys-apps/toybox lacks a 'static' USE flag. Additionally, toybox cannot be statically linked against glibc.

This bug is a request to add a 'static' USE flag to sys-apps/toybox, which results in a statically linked binary suitable for e.g. initramfs usage.

Reproducible: Always

Instructions for static build using musl:
1. Create temp root for build ($TEMP)
2. Build & install musl to $TEMP:
  a) ./configure --prefix=$TEMP --disable-shared
  b) make
  c) make install
3. Symlink /usr/include/linux to $TEMP/include/linux
4. Symlink /usr/include/asm to $TEMP/include/asm
5. Symlink /usr/include/asm-generic to $TEMP/include/asm-generic
6. Configure toybox (make menuconfig), or provide existing .config file
7. Build toybox: CC="$TEMP/bin/musl-gcc" LDFLAGS="-L$TEMP/lib --static" CFLAGS="-I$TEMP/include" make

Sample build script:

# set up directory tree and extract source
mkdir -p "$WDIR"/{root,build,build/toybox-$TOYBOX_VERSION}
tar -C "$WDIR/build" -xf "$DISTFILES/musl-$MUSL_VERSION.tar.gz"
tar -C "$WDIR/build/toybox-$TOYBOX_VERSION" -xf "$DISTFILES/toybox-$TOYBOX_VERSION.tar.gz"

# build musl
cd "$WDIR/build/musl-$MUSL_VERSION"
./configure --prefix="$WDIR/root" --disable-shared
make install

# symlink toybox-required headers
ln -s "$INCLUDEDIR/linux" "$WDIR/root/include/"
ln -s "$INCLUDEDIR/asm" "$WDIR/root/include/"
ln -s "$INCLUDEDIR/asm-generic" "$WDIR/root/include"

# configure & build toybox
cd "$WDIR/build/toybox-$TOYBOX_VERSION"
make menuconfig
CC="$WDIR/root/bin/musl-gcc" CFLAGS="-I$WDIR/root/include" LDFLAGS="-L$WDIR/root/lib --static" make
PREFIX="$WDIR/root" make install

# cleanup
cd "$CDIR"
Comment 1 Steve Gilberd 2015-08-27 02:24:01 UTC
Note that the default config for toybox does not include a shell.

As that the expected use for a statically-linked toybox is things like initramfs, enabling the shell (CONFIG_SH) when building with USE=static is probably a good idea.