Infrastructure:

The toybox source code is in three directories. The top level directory contains the file main.c and the header file toys.h. The "lib" directory contains generic functions shared by multiple commands. The "toys" directory contains the implementations of individual commands.

Top level directory.

lib: llist, getmountlist(), error_msg/error_exit, xmalloc(), strlcpy(), xexec(), xopen()/xread(), xgetcwd(), xabspath(), find_in_path(), itoa().

main.c

Contains the main() function where execution starts, plus common infrastructure to initialize global variables and select which command to run.

Execution starts in main() which removes the path from the first command name and calls toybox_main(), which calls toy_exec(), which calls toy_find(), toy_init() and the appropriate command's function from toy_list.

The following global variables are defined here:

The following functions are defined here:

Config.in

Top level configuration file in a stylized variant of kconfig format. Includes toys/Config.in.

These files are directly used by "make menuconfig" to select which commands to build into toybox (thus generating a .config file), and by scripts/config2help.py to generate toys/help.h.

Temporary files:

toys/ directory.

toys/Config.in

Included from the top level Config.in, contains one or more configuration entries for each command.

Each command has a configuration entry matching the command name (except that configuration symbols are uppercase and command names are lower case). Options to commands start with the command name followed by an underscore and the option name. Global options are attachd to the "toybox" command, and thus use the prefix "TOYBOX_". This organization is used by scripts/cfg2files to select which

A commands with multiple names (or multiple similar commands implemented in the same .c file) should have config symbols prefixed with the name of their C file. I.E. config symbol prefixes are NEWTOY() names. If OLDTOY() names have config symbols they're options (symbols with an underscore and suffix) to the NEWTOY() name. (See toys/toylist.h)

toys/toylist.h

toys/help.h

#defines two help text strings for each command: a single line command_help and an additinal command_help_long. This is used by help_main() in toys/help.c to display help for commands.

Although this file is generated from Config.in help entries by scripts/config2help.py, it's shipped in release tarballs so you don't need python on the build system. (If you check code out of source control, or modify Config.in, then you'll need python installed to rebuild it.)

This file contains help for all commands, regardless of current configuration, but only the currently enabled ones are entered into help_data[] in toys/help.c.

lib/ directory.

scripts/ directory.

scripts/cfg2files.sh

Run .config through this filter to get a list of enabled commands, which is turned into a list of files in toys via a sed invocation in the top level Makefile.

kconfig/ directory.

Menuconfig infrastructure copied from the Linux kernel. See the Linux kernel's Documentation/kbuild/kconfig-language.txt