blob: 1c2383f351970d4ede4e4ca8229ade6024f21cf8 [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.
Bernhard Reutner-Fischere15d7572006-06-02 20:56:16 +000019Make 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.
Glenn L McGrath9c91e412003-10-01 11:33:46 +000021
22For a new applet mu, here is the code that would go in mu.c:
Mark Whitleyeac26362000-12-19 17:35:24 +000023
24----begin example code------
25
26/* vi: set sw=4 ts=4: */
27/*
28 * Mini mu implementation for busybox
29 *
Mark Whitleyeac26362000-12-19 17:35:24 +000030 * Copyright (C) [YEAR] by [YOUR NAME] <YOUR EMAIL>
31 *
Bernhard Reutner-Fischerdac7ff12006-04-12 17:55:51 +000032 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
Mark Whitleyeac26362000-12-19 17:35:24 +000033 */
34
35#include "busybox.h"
Bernhard Reutner-Fischere15d7572006-06-02 20:56:16 +000036#include <other.h>
Mark Whitleyeac26362000-12-19 17:35:24 +000037
38int mu_main(int argc, char **argv)
39{
40 int fd;
41 char mu;
42
Bernhard Reutner-Fischer8c1eda52006-08-28 23:39:36 +000043 fd = xopen("/dev/random", O_RDONLY);
Mark Whitleyeac26362000-12-19 17:35:24 +000044
45 if ((n = safe_read(fd, &mu, 1)) < 1)
Mike Frysinger0ea3a6f2005-04-23 01:43:45 +000046 bb_perror_msg_and_die("/dev/random");
Mark Whitleyeac26362000-12-19 17:35:24 +000047
48 return mu;
49}
50
51----end example code------
52
Mark Whitley8a6b6192000-12-19 17:54:38 +000053
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
Glenn L McGrath2e6d3cf2001-06-24 12:36:54 +000062Some Words on libbb
63-------------------
Mark Whitley8a6b6192000-12-19 17:54:38 +000064
Mark Whitleyeac26362000-12-19 17:35:24 +000065As you are writing your applet, please be aware of the body of pre-existing
Glenn L McGrath2e6d3cf2001-06-24 12:36:54 +000066useful functions in libbb. Use these instead of reinventing the wheel.
Mark Whitley8a6b6192000-12-19 17:54:38 +000067
Mark Whitleyeac26362000-12-19 17:35:24 +000068Additionally, if you have any useful, general-purpose functions in your
Mike Frysinger9754b912005-09-02 23:06:30 +000069applet that could be useful in other applets, consider putting them in libbb.
Mark Whitleyeac26362000-12-19 17:35:24 +000070
Mark Whitleyeac26362000-12-19 17:35:24 +000071
Matt Kraai3b1cbd72002-03-18 16:03:00 +000072Placement / Directory
73---------------------
74
75Find the appropriate directory for your new applet.
76
Glenn L McGrath9c91e412003-10-01 11:33:46 +000077Make sure you find the appropriate places in the files, the applets are
78sorted alphabetically.
79
Mike Frysinger9754b912005-09-02 23:06:30 +000080Add the applet to Makefile.in in the chosen directory:
Matt Kraai3b1cbd72002-03-18 16:03:00 +000081
82obj-$(CONFIG_MU) += mu.o
83
Mike Frysinger9754b912005-09-02 23:06:30 +000084Add the applet to Config.in in the chosen directory:
Matt Kraai3b1cbd72002-03-18 16:03:00 +000085
Glenn L McGrath9c91e412003-10-01 11:33:46 +000086config CONFIG_MU
87 bool "MU"
88 default n
89 help
90 Returns an indeterminate value.
Matt Kraai3b1cbd72002-03-18 16:03:00 +000091
92
Mark Whitleyeac26362000-12-19 17:35:24 +000093Usage String(s)
94---------------
95
Eric Andersenc7bda1c2004-03-15 08:29:22 +000096Next, add usage information for you applet to include/usage.h.
Matt Kraai3b1cbd72002-03-18 16:03:00 +000097This should look like the following:
Mark Whitleyeac26362000-12-19 17:35:24 +000098
Glenn L McGrath2e6d3cf2001-06-24 12:36:54 +000099 #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" \
Mike Frysinger9754b912005-09-02 23:06:30 +0000106 ...
Mark Whitleyeac26362000-12-19 17:35:24 +0000107
108If your program supports flags, the flags should be mentioned on the first
Glenn L McGrath2e6d3cf2001-06-24 12:36:54 +0000109line (-[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.)
Mark Whitleyeac26362000-12-19 17:35:24 +0000112
113
114Header Files
115------------
116
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000117Next, 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
Matt Kraai3b1cbd72002-03-18 16:03:00 +0000119algorithm in busybox.c and the Gods of BusyBox smite you. Yea, verily:
Mark Whitleyeac26362000-12-19 17:35:24 +0000120
121 /* all programs above here are alphabetically "less than" 'mu' */
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000122 #ifdef CONFIG_MU
Mark Whitleyeac26362000-12-19 17:35:24 +0000123 APPLET("mu", mu_main, _BB_DIR_USR_BIN, mu_usage)
124 #endif
125 /* all programs below here are alphabetically "greater than" 'mu' */
126
127
Mark Whitleyeac26362000-12-19 17:35:24 +0000128Documentation
129-------------
130
131If you're feeling especially nice, you should also document your applet in the
132docs directory (but nobody ever does that).
133
Matt Kraai3b1cbd72002-03-18 16:03:00 +0000134Adding some text to docs/Configure.help is a nice start.
135
Mark Whitleyeac26362000-12-19 17:35:24 +0000136
137The Grand Announcement
138----------------------
139
Mike Frysinger9754b912005-09-02 23:06:30 +0000140Then 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
Glenn L McGrath9c91e412003-10-01 11:33:46 +0000146and send it to the mailing list:
Mike Frysinger9754b912005-09-02 23:06:30 +0000147 busybox@busybox.net
148 http://busybox.net/mailman/listinfo/busybox
Mark Whitleyeac26362000-12-19 17:35:24 +0000149
Glenn L McGrath9c91e412003-10-01 11:33:46 +0000150Sending patches as attachments is preferred, but not required.