package/bash: add option to keep or remove loadable examples
authorThomas Petazzoni <thomas.petazzoni@bootlin.com>
Fri, 23 Apr 2021 20:23:54 +0000 (22:23 +0200)
committerYann E. MORIN <yann.morin.1998@free.fr>
Sat, 24 Apr 2021 07:42:04 +0000 (09:42 +0200)
bash has a concept of "loadables", which are "plugins" that can be
loaded at runtime by bash to add new builtin. For example:

    # type whoami
    whoami is hashed (/usr/bin/whoami)
    # whoami
    root

    # enable -f /usr/lib/bash/whoami whoami
    # type whoami
    whoami is a shell builtin
    # whoami
    root

    # enable -d whoami
    # type whoami
    whoami is hashed (/usr/bin/whoami)
    # whoami
    root

bash comes with a set of example loadables, installed in
/usr/lib/bash/. They take 312 KB on ARM32, and are by default not
used, and provide builtins that are for the most part already
available as external commands in Busybox/coreutils:

    Makefile.inc  finfo         mkfifo        realpath      sync
    accept        head          mktemp        rm            tee
    basename      id            mypid         rmdir         truefalse
    csv           ln            pathchk       seq           tty
    cut           loadables.h   print         setpgid       uname
    dirname       logname       printenv      sleep         unlink
    fdflags       mkdir         push          strftime      whoami

So instead of having them unconditionally installed, add an option to
enable/disable their installation (their build apparently cannot be
disabled via a configure option).

Normally, we try to keep backward compatibility by preserving the
existing behavior. In this case, this would have meant making this
option "default y". But this also breaks our principle of "being
minimal by default", and in this case, it feels preferable to be
"minimal by default" than preserving existing behavior.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Cc: Nicolas Cavallari <nicolas.cavallari@green-communications.fr>
Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
package/bash/Config.in
package/bash/bash.mk

index 5a9ebb8d02fc9faf77028a169f9d984a000b6556..0212df6bfd47734ca43b9ef2a98f7e2f1b3b9e9f 100644 (file)
@@ -9,3 +9,17 @@ config BR2_PACKAGE_BASH
          The standard GNU Bourne again shell.
 
          http://tiswww.case.edu/php/chet/bash/bashtop.html
+
+if BR2_PACKAGE_BASH
+
+config BR2_PACKAGE_BASH_LOADABLE_EXAMPLES
+       bool "loadable examples"
+       depends on !BR2_STATIC_LIBS
+       help
+         This option will enable the installation of the "loadable"
+         examples, which are dynamically loadable extension providing
+         additional built-ins commands to bash. There are typically
+         not needed as they are provided as regular, external
+         commands.
+
+endif
index 31cb1f50a3fe9479195a2f8e8b5d4228b0f7db0f..7b853ece083c042f090157d0599d2aa5c7ed51cb 100644 (file)
@@ -47,6 +47,19 @@ define BASH_REMOVE_UNUSED_FILES
 endef
 BASH_POST_INSTALL_TARGET_HOOKS += BASH_REMOVE_UNUSED_FILES
 
+ifeq ($(BR2_PACKAGE_BASH_LOADABLE_EXAMPLES),y)
+define BASH_REMOVE_LOADABLE_UNUSED_FILES
+       rm -f $(TARGET_DIR)/usr/lib/bash/Makefile.inc
+       rm -f $(TARGET_DIR)/usr/lib/bash/loadables.h
+endef
+BASH_POST_INSTALL_TARGET_HOOKS += BASH_REMOVE_LOADABLE_UNUSED_FILES
+else
+define BASH_REMOVE_LOADABLE_EXAMPLES
+       rm -rf $(TARGET_DIR)/usr/lib/bash
+endef
+BASH_POST_INSTALL_TARGET_HOOKS += BASH_REMOVE_LOADABLE_EXAMPLES
+endif
+
 # Add /bin/bash to /etc/shells otherwise some login tools like dropbear
 # can reject the user connection. See man shells.
 define BASH_ADD_MKSH_TO_SHELLS