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. |
Glenn L McGrath | 9c91e41 | 2003-10-01 11:33:46 +0000 | [diff] [blame] | 19 | |
| 20 | 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] | 21 | |
| 22 | ----begin example code------ |
| 23 | |
| 24 | /* vi: set sw=4 ts=4: */ |
| 25 | /* |
| 26 | * Mini mu implementation for busybox |
| 27 | * |
| 28 | * |
| 29 | * Copyright (C) [YEAR] by [YOUR NAME] <YOUR EMAIL> |
| 30 | * |
| 31 | * This program is free software; you can redistribute it and/or modify |
| 32 | * it under the terms of the GNU General Public License as published by |
| 33 | * the Free Software Foundation; either version 2 of the License, or |
| 34 | * (at your option) any later version. |
| 35 | * |
| 36 | * This program is distributed in the hope that it will be useful, |
| 37 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 38 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 39 | * General Public License for more details. |
| 40 | * |
| 41 | * You should have received a copy of the GNU General Public License |
| 42 | * along with this program; if not, write to the Free Software |
| 43 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 44 | * 02111-1307 USA |
| 45 | * |
| 46 | */ |
| 47 | |
| 48 | #include "busybox.h" |
| 49 | |
| 50 | int mu_main(int argc, char **argv) |
| 51 | { |
| 52 | int fd; |
| 53 | char mu; |
| 54 | |
| 55 | if ((fd = open("/dev/random", O_RDONLY)) < 0) |
Mike Frysinger | 0ea3a6f | 2005-04-23 01:43:45 +0000 | [diff] [blame] | 56 | bb_perror_msg_and_die("/dev/random"); |
Mark Whitley | eac2636 | 2000-12-19 17:35:24 +0000 | [diff] [blame] | 57 | |
| 58 | if ((n = safe_read(fd, &mu, 1)) < 1) |
Mike Frysinger | 0ea3a6f | 2005-04-23 01:43:45 +0000 | [diff] [blame] | 59 | bb_perror_msg_and_die("/dev/random"); |
Mark Whitley | eac2636 | 2000-12-19 17:35:24 +0000 | [diff] [blame] | 60 | |
| 61 | return mu; |
| 62 | } |
| 63 | |
| 64 | ----end example code------ |
| 65 | |
Mark Whitley | 8a6b619 | 2000-12-19 17:54:38 +0000 | [diff] [blame] | 66 | |
| 67 | Coding Style |
| 68 | ------------ |
| 69 | |
| 70 | Before you submit your applet for inclusion in BusyBox, (or better yet, before |
| 71 | you _write_ your applet) please read through the style guide in the docs |
| 72 | directory and make your program compliant. |
| 73 | |
| 74 | |
Glenn L McGrath | 2e6d3cf | 2001-06-24 12:36:54 +0000 | [diff] [blame] | 75 | Some Words on libbb |
| 76 | ------------------- |
Mark Whitley | 8a6b619 | 2000-12-19 17:54:38 +0000 | [diff] [blame] | 77 | |
Mark Whitley | eac2636 | 2000-12-19 17:35:24 +0000 | [diff] [blame] | 78 | 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] | 79 | useful functions in libbb. Use these instead of reinventing the wheel. |
Mark Whitley | 8a6b619 | 2000-12-19 17:54:38 +0000 | [diff] [blame] | 80 | |
Mark Whitley | eac2636 | 2000-12-19 17:35:24 +0000 | [diff] [blame] | 81 | Additionally, if you have any useful, general-purpose functions in your |
Mike Frysinger | 9754b91 | 2005-09-02 23:06:30 +0000 | [diff] [blame] | 82 | 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] | 83 | |
Mark Whitley | eac2636 | 2000-12-19 17:35:24 +0000 | [diff] [blame] | 84 | |
Matt Kraai | 3b1cbd7 | 2002-03-18 16:03:00 +0000 | [diff] [blame] | 85 | Placement / Directory |
| 86 | --------------------- |
| 87 | |
| 88 | Find the appropriate directory for your new applet. |
| 89 | |
Glenn L McGrath | 9c91e41 | 2003-10-01 11:33:46 +0000 | [diff] [blame] | 90 | Make sure you find the appropriate places in the files, the applets are |
| 91 | sorted alphabetically. |
| 92 | |
Mike Frysinger | 9754b91 | 2005-09-02 23:06:30 +0000 | [diff] [blame] | 93 | Add the applet to Makefile.in in the chosen directory: |
Matt Kraai | 3b1cbd7 | 2002-03-18 16:03:00 +0000 | [diff] [blame] | 94 | |
| 95 | obj-$(CONFIG_MU) += mu.o |
| 96 | |
Mike Frysinger | 9754b91 | 2005-09-02 23:06:30 +0000 | [diff] [blame] | 97 | Add the applet to Config.in in the chosen directory: |
Matt Kraai | 3b1cbd7 | 2002-03-18 16:03:00 +0000 | [diff] [blame] | 98 | |
Glenn L McGrath | 9c91e41 | 2003-10-01 11:33:46 +0000 | [diff] [blame] | 99 | config CONFIG_MU |
| 100 | bool "MU" |
| 101 | default n |
| 102 | help |
| 103 | Returns an indeterminate value. |
Matt Kraai | 3b1cbd7 | 2002-03-18 16:03:00 +0000 | [diff] [blame] | 104 | |
| 105 | |
Mark Whitley | eac2636 | 2000-12-19 17:35:24 +0000 | [diff] [blame] | 106 | Usage String(s) |
| 107 | --------------- |
| 108 | |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 109 | Next, add usage information for you applet to include/usage.h. |
Matt Kraai | 3b1cbd7 | 2002-03-18 16:03:00 +0000 | [diff] [blame] | 110 | This should look like the following: |
Mark Whitley | eac2636 | 2000-12-19 17:35:24 +0000 | [diff] [blame] | 111 | |
Glenn L McGrath | 2e6d3cf | 2001-06-24 12:36:54 +0000 | [diff] [blame] | 112 | #define mu_trivial_usage \ |
| 113 | "-[abcde] FILES" |
| 114 | #define mu_full_usage \ |
| 115 | "Returns an indeterminate value.\n\n" \ |
| 116 | "Options:\n" \ |
| 117 | "\t-a\t\tfirst function\n" \ |
| 118 | "\t-b\t\tsecond function\n" \ |
Mike Frysinger | 9754b91 | 2005-09-02 23:06:30 +0000 | [diff] [blame] | 119 | ... |
Mark Whitley | eac2636 | 2000-12-19 17:35:24 +0000 | [diff] [blame] | 120 | |
| 121 | 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] | 122 | line (-[abcde]) and a detailed description of each flag should go in the |
| 123 | mu_full_usage section, one flag per line. (Numerous examples of this |
| 124 | currently exist in usage.h.) |
Mark Whitley | eac2636 | 2000-12-19 17:35:24 +0000 | [diff] [blame] | 125 | |
| 126 | |
| 127 | Header Files |
| 128 | ------------ |
| 129 | |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 130 | Next, add an entry to include/applets.h. Be *sure* to keep the list |
| 131 | in alphabetical order, or else it will break the binary-search lookup |
Matt Kraai | 3b1cbd7 | 2002-03-18 16:03:00 +0000 | [diff] [blame] | 132 | 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] | 133 | |
| 134 | /* all programs above here are alphabetically "less than" 'mu' */ |
Eric Andersen | bdfd0d7 | 2001-10-24 05:00:29 +0000 | [diff] [blame] | 135 | #ifdef CONFIG_MU |
Mark Whitley | eac2636 | 2000-12-19 17:35:24 +0000 | [diff] [blame] | 136 | APPLET("mu", mu_main, _BB_DIR_USR_BIN, mu_usage) |
| 137 | #endif |
| 138 | /* all programs below here are alphabetically "greater than" 'mu' */ |
| 139 | |
| 140 | |
Mark Whitley | eac2636 | 2000-12-19 17:35:24 +0000 | [diff] [blame] | 141 | Documentation |
| 142 | ------------- |
| 143 | |
| 144 | If you're feeling especially nice, you should also document your applet in the |
| 145 | docs directory (but nobody ever does that). |
| 146 | |
Matt Kraai | 3b1cbd7 | 2002-03-18 16:03:00 +0000 | [diff] [blame] | 147 | Adding some text to docs/Configure.help is a nice start. |
| 148 | |
Mark Whitley | eac2636 | 2000-12-19 17:35:24 +0000 | [diff] [blame] | 149 | |
| 150 | The Grand Announcement |
| 151 | ---------------------- |
| 152 | |
Mike Frysinger | 9754b91 | 2005-09-02 23:06:30 +0000 | [diff] [blame] | 153 | Then create a diff -urN of the files you added and/or modified. Typically: |
| 154 | <appletdir>/<applet>.c |
| 155 | include/usage.c |
| 156 | include/applets.h |
| 157 | <appletdir>/Makefile.in |
| 158 | <appletdir>/config.in |
Glenn L McGrath | 9c91e41 | 2003-10-01 11:33:46 +0000 | [diff] [blame] | 159 | and send it to the mailing list: |
Mike Frysinger | 9754b91 | 2005-09-02 23:06:30 +0000 | [diff] [blame] | 160 | busybox@busybox.net |
| 161 | http://busybox.net/mailman/listinfo/busybox |
Mark Whitley | eac2636 | 2000-12-19 17:35:24 +0000 | [diff] [blame] | 162 | |
Glenn L McGrath | 9c91e41 | 2003-10-01 11:33:46 +0000 | [diff] [blame] | 163 | Sending patches as attachments is preferred, but not required. |