From 98b290e9b8221b7d7ffbf47da1e8ecce62a75369 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Wed, 6 Apr 2016 10:26:27 +0100 Subject: mingw: enable busybox --install by default Allow FEATURE_INSTALLER to be configured and enable it in the default configuration. The behaviour is slightly different from upstream BusyBox: symbolic links are not permitted; if no target directory is provided the directory containing the busybox binary is used as the target. --- applets/applet_tables.c | 2 +- configs/mingw32_defconfig | 2 +- configs/mingw64_defconfig | 2 +- libbb/appletlib.c | 42 ++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 43 insertions(+), 5 deletions(-) diff --git a/applets/applet_tables.c b/applets/applet_tables.c index 843f2ec08..7894b2c33 100644 --- a/applets/applet_tables.c +++ b/applets/applet_tables.c @@ -177,7 +177,7 @@ int main(int argc, char **argv) printf("};\n\n"); #endif -#if ENABLE_FEATURE_INSTALLER +#if ENABLE_FEATURE_INSTALLER && !ENABLE_PLATFORM_MINGW32 printf("const uint8_t applet_install_loc[] ALIGN1 = {\n"); i = 0; while (i < NUM_APPLETS) { diff --git a/configs/mingw32_defconfig b/configs/mingw32_defconfig index c06369b2e..ae07ca620 100644 --- a/configs/mingw32_defconfig +++ b/configs/mingw32_defconfig @@ -25,7 +25,7 @@ CONFIG_FEATURE_BUFFERS_USE_MALLOC=y CONFIG_SHOW_USAGE=y CONFIG_FEATURE_VERBOSE_USAGE=y CONFIG_FEATURE_COMPRESS_USAGE=y -# CONFIG_FEATURE_INSTALLER is not set +CONFIG_FEATURE_INSTALLER=y # CONFIG_INSTALL_NO_USR is not set # CONFIG_LOCALE_SUPPORT is not set # CONFIG_UNICODE_SUPPORT is not set diff --git a/configs/mingw64_defconfig b/configs/mingw64_defconfig index 04e6ac070..60788ab83 100644 --- a/configs/mingw64_defconfig +++ b/configs/mingw64_defconfig @@ -25,7 +25,7 @@ CONFIG_FEATURE_BUFFERS_USE_MALLOC=y CONFIG_SHOW_USAGE=y CONFIG_FEATURE_VERBOSE_USAGE=y CONFIG_FEATURE_COMPRESS_USAGE=y -# CONFIG_FEATURE_INSTALLER is not set +CONFIG_FEATURE_INSTALLER=y # CONFIG_INSTALL_NO_USR is not set # CONFIG_LOCALE_SUPPORT is not set # CONFIG_UNICODE_SUPPORT is not set diff --git a/libbb/appletlib.c b/libbb/appletlib.c index b71f2dd7e..4a9d363dd 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c @@ -662,6 +662,7 @@ static void check_suid(int applet_no) # if ENABLE_FEATURE_INSTALLER +# if !ENABLE_PLATFORM_MINGW32 static const char usr_bin [] ALIGN1 = "/usr/bin/"; static const char usr_sbin[] ALIGN1 = "/usr/sbin/"; static const char *const install_dir[] = { @@ -706,6 +707,29 @@ static void install_links(const char *busybox, int use_symbolic_links, continue; } } +# else /* ENABLE_PLATFORM_MINGW32 */ +static void install_links(const char *busybox, + int use_symbolic_links UNUSED_PARAM, char *custom_install_dir) +{ + char *fpc; + const char *appname = applet_names; + int rc; + + if (!is_directory(custom_install_dir, FALSE)) + bb_error_msg_and_die("'%s' is not a directory", custom_install_dir); + + while (*appname) { + fpc = xasprintf("%s/%s.exe", custom_install_dir, appname); + rc = link(busybox, fpc); + if (rc != 0 && errno != EEXIST) { + bb_simple_perror_msg(fpc); + } + free(fpc); + while (*appname++ != '\0') + continue; + } +} +# endif # else static void install_links(const char *busybox UNUSED_PARAM, int use_symbolic_links UNUSED_PARAM, @@ -743,9 +767,14 @@ static int busybox_main(char **argv) "copyright notices.\n" "\n" "Usage: busybox [function [arguments]...]\n" + IF_NOT_PLATFORM_MINGW32( " or: busybox --list"IF_FEATURE_INSTALLER("[-full]")"\n" + ) + IF_PLATFORM_MINGW32( + " or: busybox --list\n" + ) IF_FEATURE_INSTALLER( - " or: busybox --install [-s] [DIR]\n" + " or: busybox --install "IF_NOT_PLATFORM_MINGW32("[-s] ")"[DIR]\n" ) " or: function [arguments]...\n" "\n" @@ -799,7 +828,7 @@ static int busybox_main(char **argv) const char *a = applet_names; dup2(1, 2); while (*a) { -# if ENABLE_FEATURE_INSTALLER +# if ENABLE_FEATURE_INSTALLER && !ENABLE_PLATFORM_MINGW32 if (argv[1][6]) /* --list-full? */ full_write2_str(install_dir[APPLET_INSTALL_LOC(i)] + 1); # endif @@ -812,6 +841,7 @@ static int busybox_main(char **argv) } if (ENABLE_FEATURE_INSTALLER && strcmp(argv[1], "--install") == 0) { +#if !ENABLE_PLATFORM_MINGW32 int use_symbolic_links; const char *busybox; @@ -832,6 +862,14 @@ static int busybox_main(char **argv) */ use_symbolic_links = (argv[2] && strcmp(argv[2], "-s") == 0 && ++argv); install_links(busybox, use_symbolic_links, argv[2]); +#else + /* busybox --install [DIR] + * where DIR is the directory to install to. If DIR is not + * provided put the links in the same directory as busybox. + */ + install_links(bb_busybox_exec_path, FALSE, argv[2] ? argv[2] : + dirname(xstrdup(bb_busybox_exec_path))); +#endif return 0; } -- cgit v1.2.3-55-g6feb