blob: b1e1035726f7e6af5c39e84fa84d1b503963a39c [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
Denis Vlasenko06af2162007-02-03 17:28:39 +000038int mu_main(int argc, char **argv);
Mark Whitleyeac26362000-12-19 17:35:24 +000039int mu_main(int argc, char **argv)
40{
41 int fd;
42 char mu;
43
Bernhard Reutner-Fischer8c1eda52006-08-28 23:39:36 +000044 fd = xopen("/dev/random", O_RDONLY);
Mark Whitleyeac26362000-12-19 17:35:24 +000045
46 if ((n = safe_read(fd, &mu, 1)) < 1)
Mike Frysinger0ea3a6f2005-04-23 01:43:45 +000047 bb_perror_msg_and_die("/dev/random");
Mark Whitleyeac26362000-12-19 17:35:24 +000048
49 return mu;
50}
51
52----end example code------
53
Mark Whitley8a6b6192000-12-19 17:54:38 +000054
55Coding Style
56------------
57
58Before you submit your applet for inclusion in BusyBox, (or better yet, before
59you _write_ your applet) please read through the style guide in the docs
60directory and make your program compliant.
61
62
Glenn L McGrath2e6d3cf2001-06-24 12:36:54 +000063Some Words on libbb
64-------------------
Mark Whitley8a6b6192000-12-19 17:54:38 +000065
Mark Whitleyeac26362000-12-19 17:35:24 +000066As you are writing your applet, please be aware of the body of pre-existing
Glenn L McGrath2e6d3cf2001-06-24 12:36:54 +000067useful functions in libbb. Use these instead of reinventing the wheel.
Mark Whitley8a6b6192000-12-19 17:54:38 +000068
Mark Whitleyeac26362000-12-19 17:35:24 +000069Additionally, if you have any useful, general-purpose functions in your
Mike Frysinger9754b912005-09-02 23:06:30 +000070applet that could be useful in other applets, consider putting them in libbb.
Mark Whitleyeac26362000-12-19 17:35:24 +000071
Mark Whitleyeac26362000-12-19 17:35:24 +000072
Matt Kraai3b1cbd72002-03-18 16:03:00 +000073Placement / Directory
74---------------------
75
76Find the appropriate directory for your new applet.
77
Glenn L McGrath9c91e412003-10-01 11:33:46 +000078Make sure you find the appropriate places in the files, the applets are
79sorted alphabetically.
80
Mike Frysinger9754b912005-09-02 23:06:30 +000081Add the applet to Makefile.in in the chosen directory:
Matt Kraai3b1cbd72002-03-18 16:03:00 +000082
83obj-$(CONFIG_MU) += mu.o
84
Mike Frysinger9754b912005-09-02 23:06:30 +000085Add the applet to Config.in in the chosen directory:
Matt Kraai3b1cbd72002-03-18 16:03:00 +000086
Glenn L McGrath9c91e412003-10-01 11:33:46 +000087config CONFIG_MU
88 bool "MU"
89 default n
90 help
91 Returns an indeterminate value.
Matt Kraai3b1cbd72002-03-18 16:03:00 +000092
93
Mark Whitleyeac26362000-12-19 17:35:24 +000094Usage String(s)
95---------------
96
Eric Andersenc7bda1c2004-03-15 08:29:22 +000097Next, add usage information for you applet to include/usage.h.
Matt Kraai3b1cbd72002-03-18 16:03:00 +000098This should look like the following:
Mark Whitleyeac26362000-12-19 17:35:24 +000099
Glenn L McGrath2e6d3cf2001-06-24 12:36:54 +0000100 #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" \
Mike Frysinger9754b912005-09-02 23:06:30 +0000107 ...
Mark Whitleyeac26362000-12-19 17:35:24 +0000108
109If your program supports flags, the flags should be mentioned on the first
Glenn L McGrath2e6d3cf2001-06-24 12:36:54 +0000110line (-[abcde]) and a detailed description of each flag should go in the
111mu_full_usage section, one flag per line. (Numerous examples of this
112currently exist in usage.h.)
Mark Whitleyeac26362000-12-19 17:35:24 +0000113
114
115Header Files
116------------
117
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000118Next, add an entry to include/applets.h. Be *sure* to keep the list
119in alphabetical order, or else it will break the binary-search lookup
Matt Kraai3b1cbd72002-03-18 16:03:00 +0000120algorithm in busybox.c and the Gods of BusyBox smite you. Yea, verily:
Mark Whitleyeac26362000-12-19 17:35:24 +0000121
122 /* all programs above here are alphabetically "less than" 'mu' */
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000123 #ifdef CONFIG_MU
Mark Whitleyeac26362000-12-19 17:35:24 +0000124 APPLET("mu", mu_main, _BB_DIR_USR_BIN, mu_usage)
125 #endif
126 /* all programs below here are alphabetically "greater than" 'mu' */
127
128
Mark Whitleyeac26362000-12-19 17:35:24 +0000129Documentation
130-------------
131
132If you're feeling especially nice, you should also document your applet in the
133docs directory (but nobody ever does that).
134
Matt Kraai3b1cbd72002-03-18 16:03:00 +0000135Adding some text to docs/Configure.help is a nice start.
136
Mark Whitleyeac26362000-12-19 17:35:24 +0000137
138The Grand Announcement
139----------------------
140
Mike Frysinger9754b912005-09-02 23:06:30 +0000141Then 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
Glenn L McGrath9c91e412003-10-01 11:33:46 +0000147and send it to the mailing list:
Mike Frysinger9754b912005-09-02 23:06:30 +0000148 busybox@busybox.net
149 http://busybox.net/mailman/listinfo/busybox
Mark Whitleyeac26362000-12-19 17:35:24 +0000150
Glenn L McGrath9c91e412003-10-01 11:33:46 +0000151Sending patches as attachments is preferred, but not required.