#!/bin/sh echo "*** BUILD BUSYBOX BEGIN ***" global SRC_DIR := $[pwd] # Read the 'JOB_FACTOR' property from '.config' global JOB_FACTOR := $[grep -i ^JOB_FACTOR .config | cut -f2 -d'=] # Find the number of available CPU cores. global NUM_CORES := $[grep ^processor /proc/cpuinfo | wc -l] # Calculate the number of 'make' jobs to be used later. global NUM_JOBS := $(NUM_CORES * JOB_FACTOR) # Remember the glibc installation area. global GLIBC_PREPARED := "$[pwd]/work/glibc/glibc_prepared" cd work/busybox # Remove the old BusyBox install area rm -rf busybox_installed # Change to the source directory ls finds, e.g. 'busybox-1.24.2'. cd $[ls -d busybox-*] # Remove previously generated artifacts. echo "Preparing BusyBox work area. This may take a while..." make distclean -j $NUM_JOBS # Read the 'USE_PREDEFINED_BUSYBOX_CONFIG' property from '.config' global USE_PREDEFINED_BUSYBOX_CONFIG := $[grep -i ^USE_PREDEFINED_BUSYBOX_CONFIG $SRC_DIR/.config | cut -f2 -d'=] if test $USE_PREDEFINED_BUSYBOX_CONFIG = "true" -a ! -f $SRC_DIR/minimal_config/busybox.config { echo "Config file $SRC_DIR/minimal_config/busybox.config does not exist." global USE_PREDEFINED_BUSYBOX_CONFIG := '"false'" } if test $USE_PREDEFINED_BUSYBOX_CONFIG = "true" { # Use predefined configuration file for Busybox. echo "Using config file $SRC_DIR/minimal_config/busybox.config" cp -f $SRC_DIR/minimal_config/busybox.config .config } else { # Create default configuration file. echo "Generating default BusyBox configuration..." make defconfig -j $NUM_JOBS # The 'inetd' applet fails to compile because we use the glibc installation area as # main pointer to the kernel headers (see 05_prepare_glibc.sh) and some headers are # not resolved. The easiest solution is to ignore this particular applet. sed -i "s/.*CONFIG_INETD.*/CONFIG_INETD=n/" .config } # This variable holds the full path to the glibc installation area as quoted string. # All back slashes are escaped (/ => \/) in order to keep the 'sed' command stable. global GLIBC_PREPARED_ESCAPED := $[echo '"'$GLIBC_PREPARED'"' | sed 's/\//\\\//g] # Now we tell BusyBox to use the glibc prepared area. sed -i "s/.*CONFIG_SYSROOT.*/CONFIG_SYSROOT=$GLIBC_PREPARED_ESCAPED/" .config # Compile busybox with optimization for "parallel jobs" = "number of processors". echo "Building BusyBox..." make \ EXTRA_CFLAGS="-Os -s -fno-stack-protector -U_FORTIFY_SOURCE" \ busybox -j $NUM_JOBS # Create the symlinks for busybox. The file 'busybox.links' is used for this. echo "Generating BusyBox based initramfs area..." make \ CONFIG_PREFIX="../busybox_installed" \ install -j $NUM_JOBS cd $SRC_DIR echo "*** BUILD BUSYBOX END ***" (CommandList children: [ (C {(echo)} {(DQ ("*** BUILD BUSYBOX BEGIN ***"))}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:SRC_DIR) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(pwd)})]) left_token: spids: [12 14] ) } spids: [11] ) ] spids: [11] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:JOB_FACTOR) op: Equal rhs: { (DQ (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(grep)} {(-i)} {(Lit_Other "^") (JOB_FACTOR)} {(.config)}) (C {(cut)} {(-f2)} {(-d) (SQ <"=">)}) ] negated: False ) ] ) left_token: spids: [22 42] ) ) } spids: [20] ) ] spids: [20] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:NUM_CORES) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(grep)} {(Lit_Other "^") (processor)} {(/proc/cpuinfo)}) (C {(wc)} {(-l)}) ] negated: False ) ] ) left_token: spids: [50 63] ) } spids: [49] ) ] spids: [49] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:NUM_JOBS) op: Equal rhs: { (ArithSubPart anode: (ArithBinary op_id: Arith_Star left: (ArithVarRef name:NUM_CORES) right: (ArithVarRef name:JOB_FACTOR) ) spids: [70 77] ) } spids: [69] ) ] spids: [69] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:GLIBC_PREPARED) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(pwd)})]) left_token: spids: [84 86] ) (/work/glibc/glibc_prepared) } spids: [83] ) ] spids: [83] ) (C {(cd)} {(work/busybox)}) (C {(rm)} {(-rf)} {(busybox_installed)}) (C {(cd)} { (CommandSubPart command_list: (CommandList children:[(C {(ls)} {(-d)} {(busybox-) (Lit_Other "*")})]) left_token: spids: [110 117] ) } ) (C {(echo)} {(DQ ("Preparing BusyBox work area. This may take a while..."))}) (C {(make)} {(distclean)} {(-j)} {($ VSub_Name "$NUM_JOBS")}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:USE_PREDEFINED_BUSYBOX_CONFIG) op: Equal rhs: { (DQ (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(grep)} {(-i)} {(Lit_Other "^") (USE_PREDEFINED_BUSYBOX_CONFIG)} {($ VSub_Name "$SRC_DIR") (/.config)} ) (C {(cut)} {(-f2)} {(-d) (SQ <"=">)}) ] negated: False ) ] ) left_token: spids: [143 164] ) ) } spids: [141] ) ] spids: [141] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$USE_PREDEFINED_BUSYBOX_CONFIG"))} {(Lit_Other "=")} {(DQ (true))} {(-a)} {(KW_Bang "!")} {(-f)} {($ VSub_Name "$SRC_DIR") (/minimal_config/busybox.config)} {(Lit_Other "]")} ) terminator: ) ] action: [ (C {(echo)} { (DQ ("Config file ") ($ VSub_Name "$SRC_DIR") ("/minimal_config/busybox.config does not exist.") ) } ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:USE_PREDEFINED_BUSYBOX_CONFIG) op: Equal rhs: {(DQ (false))} spids: [207] ) ] spids: [207] ) ] spids: [-1 195] ) ] spids: [-1 212] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$USE_PREDEFINED_BUSYBOX_CONFIG"))} {(Lit_Other "=")} {(DQ (true))} {(Lit_Other "]")} ) terminator: ) ] action: [ (C {(echo)} {(DQ ("Using config file ") ($ VSub_Name "$SRC_DIR") (/minimal_config/busybox.config))} ) (C {(cp)} {(-f)} {($ VSub_Name "$SRC_DIR") (/minimal_config/busybox.config)} {(.config)}) ] spids: [-1 233] ) ] else_action: [ (C {(echo)} {(DQ ("Generating default BusyBox configuration..."))}) (C {(make)} {(defconfig)} {(-j)} {($ VSub_Name "$NUM_JOBS")}) (C {(sed)} {(-i)} {(DQ ("s/.*CONFIG_INETD.*/CONFIG_INETD=n/"))} {(.config)}) ] spids: [259 307] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:GLIBC_PREPARED_ESCAPED) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {(EscapedLiteralPart token:) ($ VSub_Name "$GLIBC_PREPARED") (EscapedLiteralPart token:) } ) (C {(sed)} {(SQ <"s/\\//\\\\\\//g">)}) ] negated: False ) ] ) left_token: spids: [317 331] ) } spids: [316] ) ] spids: [316] ) (C {(sed)} {(-i)} {(DQ ("s/.*CONFIG_SYSROOT.*/CONFIG_SYSROOT=") ($ VSub_Name "$GLIBC_PREPARED_ESCAPED") (/))} {(.config)} ) (C {(echo)} {(DQ ("Building BusyBox..."))}) (C {(make)} {(Lit_VarLike "EXTRA_CFLAGS=") (DQ ("-Os -s -fno-stack-protector -U_FORTIFY_SOURCE"))} {(busybox)} {(-j)} {($ VSub_Name "$NUM_JOBS")} ) (C {(echo)} {(DQ ("Generating BusyBox based initramfs area..."))}) (C {(make)} {(Lit_VarLike "CONFIG_PREFIX=") (DQ (../busybox_installed))} {(install)} {(-j)} {($ VSub_Name "$NUM_JOBS")} ) (C {(cd)} {($ VSub_Name "$SRC_DIR")}) (C {(echo)} {(DQ ("*** BUILD BUSYBOX END ***"))}) ] )