blob: 2f5702bd62382fe3137069723929a2eabbe58ad3 [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
Mike Frysinger9754b912005-09-02 23:06:30 +000014First, 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.
Glenn L McGrath9c91e412003-10-01 11:33:46 +000019
20For a new applet mu, here is the code that would go in mu.c:
Mark Whitleyeac26362000-12-19 17:35:24 +000021
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 *
Bernhard Reutner-Fischerdac7ff12006-04-12 17:55:51 +000031 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
Mark Whitleyeac26362000-12-19 17:35:24 +000032 */
33
34#include "busybox.h"
35
36int mu_main(int argc, char **argv)
37{
38 int fd;
39 char mu;
40
Bernhard Reutner-Fischerdac7ff12006-04-12 17:55:51 +000041 fd = bb_xopen("/dev/random", O_RDONLY);
Mark Whitleyeac26362000-12-19 17:35:24 +000042
43 if ((n = safe_read(fd, &mu, 1)) < 1)
Mike Frysinger0ea3a6f2005-04-23 01:43:45 +000044 bb_perror_msg_and_die("/dev/random");
Mark Whitleyeac26362000-12-19 17:35:24 +000045
46 return mu;
47}
48
49----end example code------
50
Mark Whitley8a6b6192000-12-19 17:54:38 +000051
52Coding Style
53------------
54
55Before you submit your applet for inclusion in BusyBox, (or better yet, before
56you _write_ your applet) please read through the style guide in the docs
57directory and make your program compliant.
58
59
Glenn L McGrath2e6d3cf2001-06-24 12:36:54 +000060Some Words on libbb
61-------------------
Mark Whitley8a6b6192000-12-19 17:54:38 +000062
Mark Whitleyeac26362000-12-19 17:35:24 +000063As you are writing your applet, please be aware of the body of pre-existing
Glenn L McGrath2e6d3cf2001-06-24 12:36:54 +000064useful functions in libbb. Use these instead of reinventing the wheel.
Mark Whitley8a6b6192000-12-19 17:54:38 +000065
Mark Whitleyeac26362000-12-19 17:35:24 +000066Additionally, if you have any useful, general-purpose functions in your
Mike Frysinger9754b912005-09-02 23:06:30 +000067applet that could be useful in other applets, consider putting them in libbb.
Mark Whitleyeac26362000-12-19 17:35:24 +000068
Mark Whitleyeac26362000-12-19 17:35:24 +000069
Matt Kraai3b1cbd72002-03-18 16:03:00 +000070Placement / Directory
71---------------------
72
73Find the appropriate directory for your new applet.
74
Glenn L McGrath9c91e412003-10-01 11:33:46 +000075Make sure you find the appropriate places in the files, the applets are
76sorted alphabetically.
77
Mike Frysinger9754b912005-09-02 23:06:30 +000078Add the applet to Makefile.in in the chosen directory:
Matt Kraai3b1cbd72002-03-18 16:03:00 +000079
80obj-$(CONFIG_MU) += mu.o
81
Mike Frysinger9754b912005-09-02 23:06:30 +000082Add the applet to Config.in in the chosen directory:
Matt Kraai3b1cbd72002-03-18 16:03:00 +000083
Glenn L McGrath9c91e412003-10-01 11:33:46 +000084config CONFIG_MU
85 bool "MU"
86 default n
87 help
88 Returns an indeterminate value.
Matt Kraai3b1cbd72002-03-18 16:03:00 +000089
90
Mark Whitleyeac26362000-12-19 17:35:24 +000091Usage String(s)
92---------------
93
Eric Andersenc7bda1c2004-03-15 08:29:22 +000094Next, add usage information for you applet to include/usage.h.
Matt Kraai3b1cbd72002-03-18 16:03:00 +000095This should look like the following:
Mark Whitleyeac26362000-12-19 17:35:24 +000096
Glenn L McGrath2e6d3cf2001-06-24 12:36:54 +000097 #define mu_trivial_usage \
98 "-[abcde] FILES"
99 #define mu_full_usage \
100 "Returns an indeterminate value.\n\n" \
101 "Options:\n" \
102 "\t-a\t\tfirst function\n" \
103 "\t-b\t\tsecond function\n" \
Mike Frysinger9754b912005-09-02 23:06:30 +0000104 ...
Mark Whitleyeac26362000-12-19 17:35:24 +0000105
106If your program supports flags, the flags should be mentioned on the first
Glenn L McGrath2e6d3cf2001-06-24 12:36:54 +0000107line (-[abcde]) and a detailed description of each flag should go in the
108mu_full_usage section, one flag per line. (Numerous examples of this
109currently exist in usage.h.)
Mark Whitleyeac26362000-12-19 17:35:24 +0000110
111
112Header Files
113------------
114
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000115Next, add an entry to include/applets.h. Be *sure* to keep the list
116in alphabetical order, or else it will break the binary-search lookup
Matt Kraai3b1cbd72002-03-18 16:03:00 +0000117algorithm in busybox.c and the Gods of BusyBox smite you. Yea, verily:
Mark Whitleyeac26362000-12-19 17:35:24 +0000118
119 /* all programs above here are alphabetically "less than" 'mu' */
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000120 #ifdef CONFIG_MU
Mark Whitleyeac26362000-12-19 17:35:24 +0000121 APPLET("mu", mu_main, _BB_DIR_USR_BIN, mu_usage)
122 #endif
123 /* all programs below here are alphabetically "greater than" 'mu' */
124
125
Mark Whitleyeac26362000-12-19 17:35:24 +0000126Documentation
127-------------
128
129If you're feeling especially nice, you should also document your applet in the
130docs directory (but nobody ever does that).
131
Matt Kraai3b1cbd72002-03-18 16:03:00 +0000132Adding some text to docs/Configure.help is a nice start.
133
Mark Whitleyeac26362000-12-19 17:35:24 +0000134
135The Grand Announcement
136----------------------
137
Mike Frysinger9754b912005-09-02 23:06:30 +0000138Then create a diff -urN of the files you added and/or modified. Typically:
139 <appletdir>/<applet>.c
140 include/usage.c
141 include/applets.h
142 <appletdir>/Makefile.in
143 <appletdir>/config.in
Glenn L McGrath9c91e412003-10-01 11:33:46 +0000144and send it to the mailing list:
Mike Frysinger9754b912005-09-02 23:06:30 +0000145 busybox@busybox.net
146 http://busybox.net/mailman/listinfo/busybox
Mark Whitleyeac26362000-12-19 17:35:24 +0000147
Glenn L McGrath9c91e412003-10-01 11:33:46 +0000148Sending patches as attachments is preferred, but not required.