build-bootenv

reproducible boot environment with LVM2 and cryptsetup
git clone https://ccx.te2000.cz/git/build-bootenv
Log | Files | Refs | Submodules

busybox (3515B)


      1 [mirrors]
      2 http://www.busybox.net/downloads/busybox-1.27.2.tar.bz2
      3 
      4 [vars]
      5 filesize=2216527
      6 sha512=d99e86b652562ebe1a5d50e1ba3877a1d1612997c17cb8d8e4212da181211a9b741a881cb051f14cb3ee8aea40226cf2cde80a076baed265d3bc0a4e96a5031c
      7 pkgver=6
      8 no_unlink=1
      9 
     10 [deps]
     11 kernel-headers
     12 
     13 [deps.stage0]
     14 patch
     15 stage0-musl
     16 
     17 [build]
     18 
     19 if [ "$STAGE" = "0" ] ; then
     20 	CC="$butch_root_dir"/bin/musl-gcc
     21 	PATCH="$butch_root_dir"/bin/patch
     22 else
     23 	PATCH=patch
     24 fi
     25 
     26 dopatch() {
     27 	echo "applying patch $1"
     28 	"$PATCH" -p1 < "$1"
     29 }
     30 
     31 dopatch "$K"/busybox-blowfish.patch
     32 dopatch "$K"/busybox-fdisk-sector-size.patch
     33 dopatch "$K"/busybox-libbb-make-unicode-printable.patch
     34 dopatch "$K"/busybox-ping.patch
     35 
     36 #__inline seems to get activated when -std=gnu99 is used, causing havoc
     37 sed -i 's,__inline,,' ./scripts/kconfig/zconf.hash.c_shipped
     38 
     39 sed -i 's/-DBB_BT=AUTOCONF_TIMESTAMP/-DBB_BT=\\"reproducible-build\\"/' Makefile.flags
     40 cp "$K/"busybox.stage1.config config.stage1
     41 sed -i 's/# CONFIG_PIVOT_ROOT is not set/CONFIG_PIVOT_ROOT=y/' config.stage1
     42 
     43 if [ "$DEBUGBUILD" = "1" ] ; then
     44 	debugcflags="-O0 -g"
     45 	sed -e 's/# CONFIG_DEBUG is not set/CONFIG_DEBUG=y/' \
     46 	    -e 's/# CONFIG_DEBUG_PESSIMIZE is not set/CONFIG_DEBUG_PESSIMIZE=y/' \
     47 	    -e 's/CONFIG_NO_DEBUG_LIB=y/# CONFIG_NO_DEBUG_LIB is not set/' \
     48 	    -i config.stage1
     49 fi
     50 
     51 make KCONFIG_ALLCONFIG=config.stage1 allnoconfig
     52 
     53 # alternative:
     54 # make KBUILD_VERBOSE=1 CC="$CC" HOSTCC="$HOSTCC" \
     55 # HOSTCFLAGS=-D_GNU_SOURCE -j$MAKE_THREADS
     56 
     57 [ -z "$HOSTCC" ] && HOSTCC="$CC"
     58 
     59 make V=1 LDFLAGS=-static HOSTLDFLAGS=-static \
     60 CFLAGS_busybox="$debugcflags -Wl,-z,muldefs -Werror-implicit-function-declaration" \
     61 HOSTCC="$HOSTCC -static" CC="$CC -static" HOSTCFLAGS=-D_GNU_SOURCE  -j$MAKE_THREADS
     62 echo busybox build complete
     63 
     64 # make true and false binaries so scripts using it are faster
     65 # than when using several layers of indirection including a shell
     66 # script
     67 cat << EOF > true.c
     68 int main() { return 0; }
     69 EOF
     70 cat << EOF > false.c
     71 int main() { return 1; }
     72 EOF
     73 
     74 for p in true false ; do
     75 $CC -static $optcflags "$p".c -o "$p" $optldflags
     76 done
     77 # done, continue with "make install" equivalent
     78 
     79 dest=$butch_install_dir$butch_prefix
     80 mkdir -p "$dest"/bin
     81 
     82 busybox_bin=busybox
     83 [ "$DEBUGBUILD" = "1" ] && busybox_bin=busybox_unstripped
     84 # on armv4tl and mips, the stripped busybox binary is buggy - argv parsing is broken somehow:
     85 # this manifests when trying to use enter-chroot script which fails.
     86 #[ "$A" = "arm" ] || [ "$A" = "mips" ] && busybox_bin=busybox_unstripped
     87 
     88 echo cp "$busybox_bin" "$dest"/bin/busybox
     89 cp "$busybox_bin" "$dest"/bin/busybox
     90 
     91 echo check if busybox works:
     92 if [ -z $CROSS_COMPILE ] ; then
     93 	"$dest"/bin/busybox --list >/dev/null
     94 fi
     95 
     96 trylink() {
     97 	if [ ! -e bb-link ] ; then
     98 		printf '#!%s/bin/busybox\n' "$butch_prefix" > bb-link
     99 		chmod +x bb-link
    100 	fi
    101 	printf "trying to link busybox to %s ... " "$1"
    102 	if ! cp -f bb-link "$1" ; then
    103 		echo FAIL
    104 		exit 1
    105 	else
    106 		echo OK
    107 	fi
    108 }
    109 
    110 $HOSTCC -E -include include/autoconf.h -DMAKE_LINKS include/applets.h | sed -e 's/^LINK BB_DIR_BIN //' -e 's/^LINK BB_DIR_SBIN //' -e 's/LINK BB_DIR_ROOT //' -e '/^#/d' -e '/^}/d' -e '/^[ ]*$/d' | sort -u > applet.lst
    111 for f in `cat applet.lst` ; do
    112 	trylink "$dest"/bin/"$f"
    113 done
    114 
    115 ln -sf busybox "$dest"/bin/sh
    116 
    117 echo symlinks done.
    118 
    119 for p in true false ; do
    120 	# in case a symlink from one of the above program names to busybox
    121 	#  already exists, we need to delete it
    122 	# before copying. otherwise the *busybox binary* gets replaced
    123 	# through the symlink...
    124 	rm -f "$dest"/bin/"$p"
    125 	cp -f "$p" "$dest"/bin/
    126 done