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