3
0

new-applet-HOWTO.txt 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. How to Add a New Applet to BusyBox
  2. ==================================
  3. This document details the steps you must take to add a new applet to BusyBox.
  4. Credits:
  5. Matt Kraai - initial writeup
  6. Mark Whitley - the remix
  7. Thomas Lundquist - Added stuff for the new directory layout.
  8. Initial Write
  9. -------------
  10. First, write your applet. Be sure to include copyright information at the top,
  11. such as who you stole the code from and so forth. Also include the mini-GPL
  12. boilerplate. Be sure to name the main function <applet>_main instead of main.
  13. And be sure to put it in <applet>.c. Usage does not have to be taken care of by
  14. your applet.
  15. Make sure to #include "busybox.h" as the first include file in your applet so
  16. the bb_config.h and appropriate platform specific files are included properly.
  17. For a new applet mu, here is the code that would go in mu.c:
  18. ----begin example code------
  19. /* vi: set sw=4 ts=4: */
  20. /*
  21. * Mini mu implementation for busybox
  22. *
  23. * Copyright (C) [YEAR] by [YOUR NAME] <YOUR EMAIL>
  24. *
  25. * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
  26. */
  27. #include "busybox.h"
  28. #include <other.h>
  29. int mu_main(int argc, char **argv)
  30. {
  31. int fd;
  32. char mu;
  33. fd = xopen("/dev/random", O_RDONLY);
  34. if ((n = safe_read(fd, &mu, 1)) < 1)
  35. bb_perror_msg_and_die("/dev/random");
  36. return mu;
  37. }
  38. ----end example code------
  39. Coding Style
  40. ------------
  41. Before you submit your applet for inclusion in BusyBox, (or better yet, before
  42. you _write_ your applet) please read through the style guide in the docs
  43. directory and make your program compliant.
  44. Some Words on libbb
  45. -------------------
  46. As you are writing your applet, please be aware of the body of pre-existing
  47. useful functions in libbb. Use these instead of reinventing the wheel.
  48. Additionally, if you have any useful, general-purpose functions in your
  49. applet that could be useful in other applets, consider putting them in libbb.
  50. Placement / Directory
  51. ---------------------
  52. Find the appropriate directory for your new applet.
  53. Make sure you find the appropriate places in the files, the applets are
  54. sorted alphabetically.
  55. Add the applet to Makefile.in in the chosen directory:
  56. obj-$(CONFIG_MU) += mu.o
  57. Add the applet to Config.in in the chosen directory:
  58. config CONFIG_MU
  59. bool "MU"
  60. default n
  61. help
  62. Returns an indeterminate value.
  63. Usage String(s)
  64. ---------------
  65. Next, add usage information for you applet to include/usage.h.
  66. This should look like the following:
  67. #define mu_trivial_usage \
  68. "-[abcde] FILES"
  69. #define mu_full_usage \
  70. "Returns an indeterminate value.\n\n" \
  71. "Options:\n" \
  72. "\t-a\t\tfirst function\n" \
  73. "\t-b\t\tsecond function\n" \
  74. ...
  75. If your program supports flags, the flags should be mentioned on the first
  76. line (-[abcde]) and a detailed description of each flag should go in the
  77. mu_full_usage section, one flag per line. (Numerous examples of this
  78. currently exist in usage.h.)
  79. Header Files
  80. ------------
  81. Next, add an entry to include/applets.h. Be *sure* to keep the list
  82. in alphabetical order, or else it will break the binary-search lookup
  83. algorithm in busybox.c and the Gods of BusyBox smite you. Yea, verily:
  84. /* all programs above here are alphabetically "less than" 'mu' */
  85. #ifdef CONFIG_MU
  86. APPLET("mu", mu_main, _BB_DIR_USR_BIN, mu_usage)
  87. #endif
  88. /* all programs below here are alphabetically "greater than" 'mu' */
  89. Documentation
  90. -------------
  91. If you're feeling especially nice, you should also document your applet in the
  92. docs directory (but nobody ever does that).
  93. Adding some text to docs/Configure.help is a nice start.
  94. The Grand Announcement
  95. ----------------------
  96. Then create a diff -urN of the files you added and/or modified. Typically:
  97. <appletdir>/<applet>.c
  98. include/usage.c
  99. include/applets.h
  100. <appletdir>/Makefile.in
  101. <appletdir>/config.in
  102. and send it to the mailing list:
  103. busybox@busybox.net
  104. http://busybox.net/mailman/listinfo/busybox
  105. Sending patches as attachments is preferred, but not required.