aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorBartosz Golaszewski <bartekgola@gmail.com>2014-03-12 22:43:50 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2014-03-16 18:47:44 +0100
commit9dbe4d054703ac96355c90bd7794d14d206e10c5 (patch)
tree4cf5830acd7a6fe4fd9dff6dac127a624e29250d /docs
parent109ee5d33694a03cda3424b4846584250832ba8e (diff)
downloadbusybox-w32-9dbe4d054703ac96355c90bd7794d14d206e10c5.tar.gz
busybox-w32-9dbe4d054703ac96355c90bd7794d14d206e10c5.tar.bz2
busybox-w32-9dbe4d054703ac96355c90bd7794d14d206e10c5.zip
docs: update new-applet-HOWTO.txt
This patch adds some information about the gen_build_files.sh script and how it allows to keep the Kbuild, Config.in etc. declarations in .c files. Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'docs')
-rw-r--r--docs/new-applet-HOWTO.txt97
1 files changed, 62 insertions, 35 deletions
diff --git a/docs/new-applet-HOWTO.txt b/docs/new-applet-HOWTO.txt
index 6a8054d0e..28970a50a 100644
--- a/docs/new-applet-HOWTO.txt
+++ b/docs/new-applet-HOWTO.txt
@@ -16,10 +16,10 @@ Initial Write
16 16
17First, write your applet. Be sure to include copyright information at the top, 17First, write your applet. Be sure to include copyright information at the top,
18such as who you stole the code from and so forth. Also include the mini-GPL 18such as who you stole the code from and so forth. Also include the mini-GPL
19boilerplate. Be sure to name the main function <applet>_main instead of main. 19boilerplate and Config.in/Kbuild/usage/applet.h snippets (more on that below
20And be sure to put it in <applet>.c. Usage does not have to be taken care of by 20in this document). Be sure to name the main function <applet>_main instead
21your applet. 21of main. And be sure to put it in <applet>.c. Make sure to #include "libbb.h"
22Make sure to #include "libbb.h" as the first include file in your applet. 22as the first include file in your applet.
23 23
24For a new applet mu, here is the code that would go in mu.c: 24For a new applet mu, here is the code that would go in mu.c:
25 25
@@ -41,6 +41,23 @@ For a new applet mu, here is the code that would go in mu.c:
41#include "libbb.h" 41#include "libbb.h"
42#include "other.h" 42#include "other.h"
43 43
44//config:config MU
45//config: bool "MU"
46//config: default n
47//config: help
48//config: Returns an indeterminate value.
49
50//kbuild:lib-$(CONFIG_MU) += mu.o
51//applet:IF_MU(APPLET(mu, BB_DIR_USR_BIN, BB_SUID_DROP))
52
53//usage:#define mu_trivial_usage
54//usage: "-[abcde] FILES"
55//usage:#define mu_full_usage
56//usage: "Returns an indeterminate value.\n\n"
57//usage: "Options:\n"
58//usage: "\t-a\t\tfirst function\n"
59//usage: "\t-b\t\tsecond function\n"
60
44int mu_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 61int mu_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
45int mu_main(int argc, char **argv) 62int mu_main(int argc, char **argv)
46{ 63{
@@ -90,6 +107,8 @@ Make a new file named <function_name>.c
90#include "libbb.h" 107#include "libbb.h"
91#include "other.h" 108#include "other.h"
92 109
110//kbuild:lib-y += function.o
111
93int function(char *a) 112int function(char *a)
94{ 113{
95 return *a; 114 return *a;
@@ -97,9 +116,7 @@ int function(char *a)
97 116
98----end example code------ 117----end example code------
99 118
100Add <function_name>.o in the right alphabetically sorted place 119Remember about the kbuild snippet.
101in libbb/Kbuild.src. You should look at the conditional part of
102libbb/Kbuild.src as well.
103 120
104You should also try to find a suitable place in include/libbb.h for 121You should also try to find a suitable place in include/libbb.h for
105the function declaration. If not, add it somewhere anyway, with or without 122the function declaration. If not, add it somewhere anyway, with or without
@@ -109,41 +126,55 @@ You can look at libbb/Config.src and try to find out if the function is
109tunable and add it there if it is. 126tunable and add it there if it is.
110 127
111 128
129Kbuild/Config.in/usage/applets.h snippets in .c files
130-----------------------------------------------------
131
132The old way of adding new applets was to put all the information needed by the
133configuration and build system into appropriate files (namely: Kbuild.src and
134Config.src in new applet's directory) and to add the applet declaration and
135usage info text to include/applets.src.h and include/usage.src.h respectively.
136
137Since the scripts/gen_build_files.sh script had been introduced, the preferred
138way is to have all these declarations contained within the applet .c files.
139
140Every line intended to be processed by gen_build_files.sh should start as a
141comment without any preceding whitespaces and be followed by an appropriate
142keyword - kbuild, config, usage or applet - and a colon, just like shown in the
143first example above.
144
145
112Placement / Directory 146Placement / Directory
113--------------------- 147---------------------
114 148
115Find the appropriate directory for your new applet. 149Find the appropriate directory for your new applet.
116 150
117Make sure you find the appropriate places in the files, the applets are 151Add the kbuild snippet to the .c file:
118sorted alphabetically.
119 152
120Add the applet to Kbuild.src in the chosen directory: 153//kbuild:lib-$(CONFIG_MU) += mu.o
121 154
122lib-$(CONFIG_MU) += mu.o 155Add the config snippet to the .c file:
123 156
124Add the applet to Config.src in the chosen directory: 157//config:config MU
125 158//config: bool "MU"
126config MU 159//config: default n
127 bool "MU" 160//config: help
128 default n 161//config: Returns an indeterminate value.
129 help
130 Returns an indeterminate value.
131 162
132 163
133Usage String(s) 164Usage String(s)
134--------------- 165---------------
135 166
136Next, add usage information for you applet to include/usage.src.h. 167Next, add usage information for your applet to the .c file.
137This should look like the following: 168This should look like the following:
138 169
139 #define mu_trivial_usage \ 170//usage:#define mu_trivial_usage
140 "-[abcde] FILES" 171//usage: "-[abcde] FILES"
141 #define mu_full_usage \ 172//usage:#define mu_full_usage
142 "Returns an indeterminate value.\n\n" \ 173//usage: "Returns an indeterminate value.\n\n"
143 "Options:\n" \ 174//usage: "Options:\n"
144 "\t-a\t\tfirst function\n" \ 175//usage: "\t-a\t\tfirst function\n"
145 "\t-b\t\tsecond function\n" \ 176//usage: "\t-b\t\tsecond function\n"
146 ... 177//usage: ...
147 178
148If your program supports flags, the flags should be mentioned on the first 179If your program supports flags, the flags should be mentioned on the first
149line (-[abcde]) and a detailed description of each flag should go in the 180line (-[abcde]) and a detailed description of each flag should go in the
@@ -154,15 +185,11 @@ currently exist in usage.src.h.)
154Header Files 185Header Files
155------------ 186------------
156 187
157Next, add an entry to include/applets.src.h. Be *sure* to keep the list 188Finally add the applet declaration snippet. Be sure to read the top of
158in alphabetical order, or else it will break the binary-search lookup 189applets.src.h before adding your applet - it contains important info
159algorithm in busybox.c and the Gods of BusyBox smite you. Yea, verily: 190on applet macros and conventions.
160
161Be sure to read the top of applets.src.h before adding your applet.
162 191
163 /* all programs above here are alphabetically "less than" 'mu' */ 192//applet:IF_MU(APPLET(mu, BB_DIR_USR_BIN, BB_SUID_DROP))
164 IF_MU(APPLET(mu, BB_DIR_USR_BIN, BB_SUID_DROP))
165 /* all programs below here are alphabetically "greater than" 'mu' */
166 193
167 194
168The Grand Announcement 195The Grand Announcement