blob: 2fc95d36df4834a360ee43f01f9b1d3b6ebd8b64 [file] [log] [blame]
Mark Whitleyeac26362000-12-19 17:35:24 +00001How to Add a New Applet to BusyBox
2==================================
3
4This document details the steps you must take to add a new applet to BusyBox.
5
6Credits:
7Matt Kraai - initial writeup
8Mark Whitley - the remix
Matt Kraai3b1cbd72002-03-18 16:03:00 +00009Thomas Lundquist - Added stuff for the new directory layout.
Mark Whitleyeac26362000-12-19 17:35:24 +000010
11Initial Write
12-------------
13
14First, write your applet. Be sure to include copyright information at the
15top, such as who you stole the code from and so forth. Also include the
16mini-GPL boilerplate. Be sure to name the main function <applet>_main instead
Glenn L McGrath9c91e412003-10-01 11:33:46 +000017of main. And be sure to put it in <applet>.c. Usage do not have to be taken care of by your applet.
18
19For a new applet mu, here is the code that would go in mu.c:
Mark Whitleyeac26362000-12-19 17:35:24 +000020
21----begin example code------
22
23/* vi: set sw=4 ts=4: */
24/*
25 * Mini mu implementation for busybox
26 *
27 *
28 * Copyright (C) [YEAR] by [YOUR NAME] <YOUR EMAIL>
29 *
30 * This program is free software; you can redistribute it and/or modify
31 * it under the terms of the GNU General Public License as published by
32 * the Free Software Foundation; either version 2 of the License, or
33 * (at your option) any later version.
34 *
35 * This program is distributed in the hope that it will be useful,
36 * but WITHOUT ANY WARRANTY; without even the implied warranty of
37 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
38 * General Public License for more details.
39 *
40 * You should have received a copy of the GNU General Public License
41 * along with this program; if not, write to the Free Software
42 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
43 * 02111-1307 USA
44 *
45 */
46
47#include "busybox.h"
48
49int mu_main(int argc, char **argv)
50{
51 int fd;
52 char mu;
53
54 if ((fd = open("/dev/random", O_RDONLY)) < 0)
55 perror_msg_and_die("/dev/random");
56
57 if ((n = safe_read(fd, &mu, 1)) < 1)
58 perror_msg_and_die("/dev/random");
59
60 return mu;
61}
62
63----end example code------
64
Mark Whitley8a6b6192000-12-19 17:54:38 +000065
66Coding Style
67------------
68
69Before you submit your applet for inclusion in BusyBox, (or better yet, before
70you _write_ your applet) please read through the style guide in the docs
71directory and make your program compliant.
72
73
Glenn L McGrath2e6d3cf2001-06-24 12:36:54 +000074Some Words on libbb
75-------------------
Mark Whitley8a6b6192000-12-19 17:54:38 +000076
Mark Whitleyeac26362000-12-19 17:35:24 +000077As you are writing your applet, please be aware of the body of pre-existing
Glenn L McGrath2e6d3cf2001-06-24 12:36:54 +000078useful functions in libbb. Use these instead of reinventing the wheel.
Mark Whitley8a6b6192000-12-19 17:54:38 +000079
Mark Whitleyeac26362000-12-19 17:35:24 +000080Additionally, if you have any useful, general-purpose functions in your
81program that could be useful in another program, consider putting them in
Glenn L McGrath2e6d3cf2001-06-24 12:36:54 +000082libbb.
Mark Whitleyeac26362000-12-19 17:35:24 +000083
Mark Whitleyeac26362000-12-19 17:35:24 +000084
Matt Kraai3b1cbd72002-03-18 16:03:00 +000085Placement / Directory
86---------------------
87
88Find the appropriate directory for your new applet.
89
Glenn L McGrath9c91e412003-10-01 11:33:46 +000090Make sure you find the appropriate places in the files, the applets are
91sorted alphabetically.
92
93Add the applet to Makefile.in in the chosen applet directory:
Matt Kraai3b1cbd72002-03-18 16:03:00 +000094
95obj-$(CONFIG_MU) += mu.o
96
Glenn L McGrath9c91e412003-10-01 11:33:46 +000097Add the applet to Config.in in the chosen applet directory:
Matt Kraai3b1cbd72002-03-18 16:03:00 +000098
Glenn L McGrath9c91e412003-10-01 11:33:46 +000099config CONFIG_MU
100 bool "MU"
101 default n
102 help
103 Returns an indeterminate value.
Matt Kraai3b1cbd72002-03-18 16:03:00 +0000104
105
Mark Whitleyeac26362000-12-19 17:35:24 +0000106Usage String(s)
107---------------
108
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000109Next, add usage information for you applet to include/usage.h.
Matt Kraai3b1cbd72002-03-18 16:03:00 +0000110This should look like the following:
Mark Whitleyeac26362000-12-19 17:35:24 +0000111
Glenn L McGrath2e6d3cf2001-06-24 12:36:54 +0000112 #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" \
Mark Whitleyeac26362000-12-19 17:35:24 +0000119
120If your program supports flags, the flags should be mentioned on the first
Glenn L McGrath2e6d3cf2001-06-24 12:36:54 +0000121line (-[abcde]) and a detailed description of each flag should go in the
122mu_full_usage section, one flag per line. (Numerous examples of this
123currently exist in usage.h.)
Mark Whitleyeac26362000-12-19 17:35:24 +0000124
125
126Header Files
127------------
128
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000129Next, add an entry to include/applets.h. Be *sure* to keep the list
130in alphabetical order, or else it will break the binary-search lookup
Matt Kraai3b1cbd72002-03-18 16:03:00 +0000131algorithm in busybox.c and the Gods of BusyBox smite you. Yea, verily:
Mark Whitleyeac26362000-12-19 17:35:24 +0000132
133 /* all programs above here are alphabetically "less than" 'mu' */
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000134 #ifdef CONFIG_MU
Mark Whitleyeac26362000-12-19 17:35:24 +0000135 APPLET("mu", mu_main, _BB_DIR_USR_BIN, mu_usage)
136 #endif
137 /* all programs below here are alphabetically "greater than" 'mu' */
138
139
Glenn L McGrath9c91e412003-10-01 11:33:46 +0000140Finally, add a define for your applet to include/config.h
Mark Whitleyeac26362000-12-19 17:35:24 +0000141
Glenn L McGrath9c91e412003-10-01 11:33:46 +0000142 #undef CONFIG_MU
Mark Whitleyeac26362000-12-19 17:35:24 +0000143
144
145Documentation
146-------------
147
148If you're feeling especially nice, you should also document your applet in the
149docs directory (but nobody ever does that).
150
Matt Kraai3b1cbd72002-03-18 16:03:00 +0000151Adding some text to docs/Configure.help is a nice start.
152
Mark Whitleyeac26362000-12-19 17:35:24 +0000153
154The Grand Announcement
155----------------------
156
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000157Then create a diff -urN of the files you added (<appletdir/><applet>.c,
158include/usage.c, include/applets.h, include/config.h, <appletdir>/Makefile.in, <appletdir>/config.in)
Glenn L McGrath9c91e412003-10-01 11:33:46 +0000159and send it to the mailing list:
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000160busybox@busybox.net.
Mark Whitleyeac26362000-12-19 17:35:24 +0000161
Glenn L McGrath9c91e412003-10-01 11:33:46 +0000162Sending patches as attachments is preferred, but not required.
Mark Whitleyeac26362000-12-19 17:35:24 +0000163