source: MondoRescue/trunk/mindi-busybox/docs/new-applet-HOWTO.txt@ 904

Last change on this file since 904 was 821, checked in by Bruno Cornec, 18 years ago

Addition of busybox 1.2.1 as a mindi-busybox new package
This should avoid delivering binary files in mindi not built there (Fedora and Debian are quite serious about that)

File size: 3.9 KB
Line 
1How 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
9Thomas Lundquist - Added stuff for the new directory layout.
10
11Initial Write
12-------------
13
14First, write your applet. Be sure to include copyright information at the top,
15such as who you stole the code from and so forth. Also include the mini-GPL
16boilerplate. Be sure to name the main function <applet>_main instead of main.
17And be sure to put it in <applet>.c. Usage does not have to be taken care of by
18your applet.
19Make sure to #include "busybox.h" as the first include file in your applet so
20the bb_config.h and appropriate platform specific files are included properly.
21
22For 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
38int mu_main(int argc, char **argv)
39{
40 int fd;
41 char mu;
42
43 fd = bb_xopen("/dev/random", O_RDONLY);
44
45 if ((n = safe_read(fd, &mu, 1)) < 1)
46 bb_perror_msg_and_die("/dev/random");
47
48 return mu;
49}
50
51----end example code------
52
53
54Coding Style
55------------
56
57Before you submit your applet for inclusion in BusyBox, (or better yet, before
58you _write_ your applet) please read through the style guide in the docs
59directory and make your program compliant.
60
61
62Some Words on libbb
63-------------------
64
65As you are writing your applet, please be aware of the body of pre-existing
66useful functions in libbb. Use these instead of reinventing the wheel.
67
68Additionally, if you have any useful, general-purpose functions in your
69applet that could be useful in other applets, consider putting them in libbb.
70
71
72Placement / Directory
73---------------------
74
75Find the appropriate directory for your new applet.
76
77Make sure you find the appropriate places in the files, the applets are
78sorted alphabetically.
79
80Add the applet to Makefile.in in the chosen directory:
81
82obj-$(CONFIG_MU) += mu.o
83
84Add the applet to Config.in in the chosen directory:
85
86config CONFIG_MU
87 bool "MU"
88 default n
89 help
90 Returns an indeterminate value.
91
92
93Usage String(s)
94---------------
95
96Next, add usage information for you applet to include/usage.h.
97This should look like the following:
98
99 #define mu_trivial_usage \
100 "-[abcde] FILES"
101 #define mu_full_usage \
102 "Returns an indeterminate value.\n\n" \
103 "Options:\n" \
104 "\t-a\t\tfirst function\n" \
105 "\t-b\t\tsecond function\n" \
106 ...
107
108If your program supports flags, the flags should be mentioned on the first
109line (-[abcde]) and a detailed description of each flag should go in the
110mu_full_usage section, one flag per line. (Numerous examples of this
111currently exist in usage.h.)
112
113
114Header Files
115------------
116
117Next, add an entry to include/applets.h. Be *sure* to keep the list
118in alphabetical order, or else it will break the binary-search lookup
119algorithm in busybox.c and the Gods of BusyBox smite you. Yea, verily:
120
121 /* all programs above here are alphabetically "less than" 'mu' */
122 #ifdef CONFIG_MU
123 APPLET("mu", mu_main, _BB_DIR_USR_BIN, mu_usage)
124 #endif
125 /* all programs below here are alphabetically "greater than" 'mu' */
126
127
128Documentation
129-------------
130
131If you're feeling especially nice, you should also document your applet in the
132docs directory (but nobody ever does that).
133
134Adding some text to docs/Configure.help is a nice start.
135
136
137The Grand Announcement
138----------------------
139
140Then create a diff -urN of the files you added and/or modified. Typically:
141 <appletdir>/<applet>.c
142 include/usage.c
143 include/applets.h
144 <appletdir>/Makefile.in
145 <appletdir>/config.in
146and send it to the mailing list:
147 busybox@busybox.net
148 http://busybox.net/mailman/listinfo/busybox
149
150Sending patches as attachments is preferred, but not required.
Note: See TracBrowser for help on using the repository browser.