new-applet-HOWTO.txt 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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
  11. top, such as who you stole the code from and so forth. Also include the
  12. mini-GPL boilerplate. Be sure to name the main function <applet>_main instead
  13. of main. And be sure to put it in <applet>.c. Usage do not have to be taken care of by your applet.
  14. For a new applet mu, here is the code that would go in mu.c:
  15. ----begin example code------
  16. /* vi: set sw=4 ts=4: */
  17. /*
  18. * Mini mu implementation for busybox
  19. *
  20. *
  21. * Copyright (C) [YEAR] by [YOUR NAME] <YOUR EMAIL>
  22. *
  23. * This program is free software; you can redistribute it and/or modify
  24. * it under the terms of the GNU General Public License as published by
  25. * the Free Software Foundation; either version 2 of the License, or
  26. * (at your option) any later version.
  27. *
  28. * This program is distributed in the hope that it will be useful,
  29. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  30. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  31. * General Public License for more details.
  32. *
  33. * You should have received a copy of the GNU General Public License
  34. * along with this program; if not, write to the Free Software
  35. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  36. * 02111-1307 USA
  37. *
  38. */
  39. #include "busybox.h"
  40. int mu_main(int argc, char **argv)
  41. {
  42. int fd;
  43. char mu;
  44. if ((fd = open("/dev/random", O_RDONLY)) < 0)
  45. bb_perror_msg_and_die("/dev/random");
  46. if ((n = safe_read(fd, &mu, 1)) < 1)
  47. bb_perror_msg_and_die("/dev/random");
  48. return mu;
  49. }
  50. ----end example code------
  51. Coding Style
  52. ------------
  53. Before you submit your applet for inclusion in BusyBox, (or better yet, before
  54. you _write_ your applet) please read through the style guide in the docs
  55. directory and make your program compliant.
  56. Some Words on libbb
  57. -------------------
  58. As you are writing your applet, please be aware of the body of pre-existing
  59. useful functions in libbb. Use these instead of reinventing the wheel.
  60. Additionally, if you have any useful, general-purpose functions in your
  61. program that could be useful in another program, consider putting them in
  62. libbb.
  63. Placement / Directory
  64. ---------------------
  65. Find the appropriate directory for your new applet.
  66. Make sure you find the appropriate places in the files, the applets are
  67. sorted alphabetically.
  68. Add the applet to Makefile.in in the chosen applet directory:
  69. obj-$(CONFIG_MU) += mu.o
  70. Add the applet to Config.in in the chosen applet directory:
  71. config CONFIG_MU
  72. bool "MU"
  73. default n
  74. help
  75. Returns an indeterminate value.
  76. Usage String(s)
  77. ---------------
  78. Next, add usage information for you applet to include/usage.h.
  79. This should look like the following:
  80. #define mu_trivial_usage \
  81. "-[abcde] FILES"
  82. #define mu_full_usage \
  83. "Returns an indeterminate value.\n\n" \
  84. "Options:\n" \
  85. "\t-a\t\tfirst function\n" \
  86. "\t-b\t\tsecond function\n" \
  87. If your program supports flags, the flags should be mentioned on the first
  88. line (-[abcde]) and a detailed description of each flag should go in the
  89. mu_full_usage section, one flag per line. (Numerous examples of this
  90. currently exist in usage.h.)
  91. Header Files
  92. ------------
  93. Next, add an entry to include/applets.h. Be *sure* to keep the list
  94. in alphabetical order, or else it will break the binary-search lookup
  95. algorithm in busybox.c and the Gods of BusyBox smite you. Yea, verily:
  96. /* all programs above here are alphabetically "less than" 'mu' */
  97. #ifdef CONFIG_MU
  98. APPLET("mu", mu_main, _BB_DIR_USR_BIN, mu_usage)
  99. #endif
  100. /* all programs below here are alphabetically "greater than" 'mu' */
  101. Documentation
  102. -------------
  103. If you're feeling especially nice, you should also document your applet in the
  104. docs directory (but nobody ever does that).
  105. Adding some text to docs/Configure.help is a nice start.
  106. The Grand Announcement
  107. ----------------------
  108. Then create a diff -urN of the files you added (<appletdir/><applet>.c,
  109. include/usage.c, include/applets.h, include/config.h, <appletdir>/Makefile.in, <appletdir>/config.in)
  110. and send it to the mailing list:
  111. busybox@busybox.net.
  112. Sending patches as attachments is preferred, but not required.