[Toybox] FreeBSD porting, removing bashisms

Rob Landley rob at landley.net
Wed Jan 9 15:28:05 PST 2019


On 1/8/19 8:39 PM, Ed Maste wrote:
> On Tue, 8 Jan 2019 at 20:54, Rob Landley <rob at landley.net> wrote:
>>
>>   make allnoconfig KCONFIG_ALLCONFIG=mini.config
> 
> Yep, that seems to work (a few cosmetic build issues):
> 
> % gmake allnoconfig KCONFIG_ALLCONFIG=mini.config
> % gmake
> scripts/make.sh
> scripts/make.sh: line 18: nproc: command not found

Yeah, make.sh does:

  [ -z "$CPUS" ] && CPUS=$(($(nproc)+1))

If nproc isn't found it becomes $((+1)) which is 1.  That said, possibly it
should be nproc 2>/dev/null inside the $( ) . (Being unable to detect SMP in the
BSD build isn't fatal...)

> Generate headers from toys/*/*.c...
> Make generated/config.h from .config.
> generated/flags.h

Hmmm, possibly that should just be more "." output when we don't export V=1.

> Compiletoybox....................................................................................................................

> strip: open toybox failed: Permission denied

The toybox binary is chmod -r because "cp file symlink" can overwrite what the
symlink points to, and overwriting the toybox binary kills _all_ the toybox
commands (with all the other symlinks that now point to, last time a build's
install failed that way for me, "bzip2").

That said I'm not sure why it failed here? I'm guessing your "strip -o" isn't
deleting the target file, but overwriting it in place? (Which is bad, and
setting the permissions like that catches that?)

> strip failed, using unstripped
> .
> volta% ./toybox
> acpi ascii base64 basename bunzip2 bzcat cal cat catv chgrp chmod
> chown chroot chrt chvt cksum clear cmp comm count cpio crc32 cut date
> dirname dos2unix du echo egrep expand factor fallocate false fgrep
> file find flock fmt fsync grep groups head help hexedit hostname iconv
> id kill killall killall5 link ln logger logname ls lsmod lspci lsusb
> makedevs mkdir mkfifo mknod mkpasswd mkswap mktemp modinfo mountpoint
> nice nl nohup od paste patch pidof pmap printenv printf pwd pwdx readlink
> realpath renice reset rev rm rmdir sed seq setsid shred sleep sort
> split strings sync sysctl tac tee test time timeout touch true truncate
> tty uname uniq unix2dos unlink usleep uudecode uuencode uuidgen vmstat
> w watch wc which who whoami xargs xxd yes
> 
> We don't have an nproc command; sysctl -n hw.ncpu will return the # of
> CPUs on FreeBSD.

Which is not the same as the _active_ CPUS: taskset 1 nproc

> I'm not sure how to plumb that into scripts/make.sh
> in a nice way. It ends up as CPUS=1 though and thus works fine.

Intentional! :)

> And the strip failure is due to the existing toybox (from previous build)
> being installed r-x.

Also intentional, explained above.

> Anyhow, mini.config looks good.

Cool. Thanks.

Rob



More information about the Toybox mailing list