Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (7 years ago)
Author:
Bruno Cornec
Message:

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

Location:
branches/3.3
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/docs/new-applet-HOWTO.txt

    r3232 r3621  
    77Matt Kraai - initial writeup
    88Mark Whitley - the remix
    9 Thomas Lundquist - Trying to keep it updated.
     9Thomas Lundquist - trying to keep it updated
    1010
    1111When doing this you should consider using the latest git HEAD.
     
    1717First, write your applet.  Be sure to include copyright information at the top,
    1818such as who you stole the code from and so forth. Also include the mini-GPL
    19 boilerplate. Be sure to name the main function <applet>_main instead of main.
    20 And be sure to put it in <applet>.c. Usage does not have to be taken care of by
    21 your applet.
    22 Make sure to #include "libbb.h" as the first include file in your applet.
     19boilerplate and Config.in/Kbuild/usage/applet.h snippets (more on that below
     20in this document). Be sure to name the main function <applet>_main instead
     21of main. And be sure to put it in <applet>.c. Make sure to #include "libbb.h"
     22as the first include file in your applet.
    2323
    2424For a new applet mu, here is the code that would go in mu.c:
    2525
    26 (busybox.h already includes most usual header files. You do not need
     26(libbb.h already includes most usual header files. You do not need
    2727#include <stdio.h> etc...)
    2828
     
    4242#include "other.h"
    4343
     44//config:config MU
     45//config:   bool "MU"
     46//config:   default y
     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] FILE..."
     55//usage:#define mu_full_usage
     56//usage:    "Returns an indeterminate value\n"
     57//usage:     "\n    -a  First function"
     58//usage:     "\n    -b  Second function"
     59
    4460int mu_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
    4561int mu_main(int argc, char **argv)
     
    91107#include "other.h"
    92108
     109//kbuild:lib-y += function.o
     110
    93111int function(char *a)
    94112{
     
    98116----end example code------
    99117
    100 Add <function_name>.o in the right alphabetically sorted place
    101 in libbb/Kbuild.src. You should look at the conditional part of
    102 libbb/Kbuild.src as well.
     118Remember about the kbuild snippet.
    103119
    104120You should also try to find a suitable place in include/libbb.h for
     
    110126
    111127
     128Kbuild/Config.in/usage/applets.h snippets in .c files
     129-----------------------------------------------------
     130
     131The old way of adding new applets was to put all the information needed by the
     132configuration and build system into appropriate files (namely: Kbuild.src and
     133Config.src in new applet's directory) and to add the applet declaration and
     134usage info text to include/applets.src.h and include/usage.src.h respectively.
     135
     136Since the scripts/gen_build_files.sh script had been introduced, the preferred
     137way is to have all these declarations contained within the applet .c files.
     138
     139Every line intended to be processed by gen_build_files.sh should start as a
     140comment without any preceding whitespaces and be followed by an appropriate
     141keyword - kbuild, config, usage or applet - and a colon, just like shown in the
     142first example above.
     143
     144
    112145Placement / Directory
    113146---------------------
     
    115148Find the appropriate directory for your new applet.
    116149
    117 Make sure you find the appropriate places in the files, the applets are
    118 sorted alphabetically.
    119 
    120 Add the applet to Kbuild.src in the chosen directory:
    121 
    122 lib-$(CONFIG_MU)               += mu.o
    123 
    124 Add the applet to Config.src in the chosen directory:
    125 
    126 config MU
    127     bool "MU"
    128     default n
    129     help
    130       Returns an indeterminate value.
     150Add the kbuild snippet to the .c file:
     151
     152//kbuild:lib-$(CONFIG_MU) += mu.o
     153
     154Add the config snippet to the .c file:
     155
     156//config:config MU
     157//config:   bool "MU"
     158//config:   default y
     159//config:   help
     160//config:     Returns an indeterminate value.
    131161
    132162
     
    134164---------------
    135165
    136 Next, add usage information for you applet to include/usage.src.h.
     166Next, add usage information for your applet to the .c file.
    137167This should look like the following:
    138168
    139     #define mu_trivial_usage \
    140         "-[abcde] FILES"
    141     #define mu_full_usage \
    142         "Returns an indeterminate value.\n\n" \
    143         "Options:\n" \
    144         "\t-a\t\tfirst function\n" \
    145         "\t-b\t\tsecond function\n" \
    146         ...
     169//usage:#define mu_trivial_usage
     170//usage:    "[-abcde] FILE..."
     171//usage:#define mu_full_usage
     172//usage:    "Returns an indeterminate value\n"
     173//usage:     "\n    -a  First function"
     174//usage:     "\n    -b  Second function"
     175//usage:    ...
    147176
    148177If your program supports flags, the flags should be mentioned on the first
    149 line (-[abcde]) and a detailed description of each flag should go in the
    150 mu_full_usage section, one flag per line. (Numerous examples of this
    151 currently exist in usage.src.h.)
     178line ([-abcde]) and a detailed description of each flag should go in the
     179mu_full_usage section, one flag per line.
    152180
    153181
     
    155183------------
    156184
    157 Next, add an entry to include/applets.src.h.  Be *sure* to keep the list
    158 in alphabetical order, or else it will break the binary-search lookup
    159 algorithm in busybox.c and the Gods of BusyBox smite you. Yea, verily:
    160 
    161 Be sure to read the top of applets.src.h before adding your applet.
    162 
    163     /* all programs above here are alphabetically "less than" 'mu' */
    164     IF_MU(APPLET(mu, BB_DIR_USR_BIN, BB_SUID_DROP))
    165     /* all programs below here are alphabetically "greater than" 'mu' */
     185Finally add the applet declaration snippet. Be sure to read the top of
     186applets.src.h before adding your applet - it contains important info
     187on applet macros and conventions.
     188
     189//applet:IF_MU(APPLET(mu, BB_DIR_USR_BIN, BB_SUID_DROP))
    166190
    167191
Note: See TracChangeset for help on using the changeset viewer.