suppress warnings about easch <applet>_main() having
[oweals/busybox.git] / docs / new-applet-HOWTO.txt
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
9 Thomas Lundquist - Added stuff for the new directory layout.
10
11 Initial Write
12 -------------
13
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.
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.
21
22 For a new applet mu, here is the code that would go in mu.c:
23
24 ----begin example code------
25
26 /* vi: set sw=4 ts=4: */
27 /*
28  * Mini mu implementation for busybox
29  *
30  * Copyright (C) [YEAR] by [YOUR NAME] <YOUR EMAIL>
31  *
32  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
33  */
34
35 #include "busybox.h"
36 #include <other.h>
37
38 int mu_main(int argc, char **argv);
39 int mu_main(int argc, char **argv)
40 {
41         int fd;
42         char mu;
43
44         fd = xopen("/dev/random", O_RDONLY);
45
46         if ((n = safe_read(fd, &mu, 1)) < 1)
47                 bb_perror_msg_and_die("/dev/random");
48
49         return mu;
50 }
51
52 ----end example code------
53
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
63 Some Words on libbb
64 -------------------
65
66 As you are writing your applet, please be aware of the body of pre-existing
67 useful functions in libbb. Use these instead of reinventing the wheel.
68
69 Additionally, if you have any useful, general-purpose functions in your
70 applet that could be useful in other applets, consider putting them in libbb.
71
72
73 Placement / Directory
74 ---------------------
75
76 Find the appropriate directory for your new applet.
77
78 Make sure you find the appropriate places in the files, the applets are
79 sorted alphabetically.
80
81 Add the applet to Makefile.in in the chosen directory:
82
83 obj-$(CONFIG_MU)               += mu.o
84
85 Add the applet to Config.in in the chosen directory:
86
87 config CONFIG_MU
88         bool "MU"
89         default n
90         help
91           Returns an indeterminate value.
92
93
94 Usage String(s)
95 ---------------
96
97 Next, add usage information for you applet to include/usage.h.
98 This should look like the following:
99
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" \
107                 ...
108
109 If your program supports flags, the flags should be mentioned on the first
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.)
113
114
115 Header Files
116 ------------
117
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
120 algorithm in busybox.c and the Gods of BusyBox smite you. Yea, verily:
121
122         /* all programs above here are alphabetically "less than" 'mu' */
123         #ifdef CONFIG_MU
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
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
135 Adding some text to docs/Configure.help is a nice start.
136
137
138 The Grand Announcement
139 ----------------------
140
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
147 and send it to the mailing list:
148         busybox@busybox.net
149         http://busybox.net/mailman/listinfo/busybox
150
151 Sending patches as attachments is preferred, but not required.