{"id":688,"date":"2010-04-15T14:04:39","date_gmt":"2010-04-15T19:04:39","guid":{"rendered":"http:\/\/www.multitech.net\/developer\/?page_id=688"},"modified":"2018-03-22T14:27:40","modified_gmt":"2018-03-22T19:27:40","slug":"writing-bitbake-recipes","status":"publish","type":"page","link":"https:\/\/www.multitech.net\/developer\/software\/corecdp\/development\/writing-bitbake-recipes\/","title":{"rendered":"Writing BitBake Recipes"},"content":{"rendered":"<p>In order to package your application and include it in the root filesystem image, you must write a BitBake recipe for it.<\/p>\n<p>When starting from scratch, it is easiest to learn by example from existing recipes.<\/p>\n<h5>Example HelloWorld recipe using autotools<\/h5>\n<p>For software that uses autotools (.\/configure; make; make install), writing recipes can be very simple:<\/p>\n<pre class=\"brush:shell\">DESCRIPTION = \"Hello World Recipe using autotools\"\r\nHOMEPAGE = \"http:\/\/www.multitech.net\/\"\r\nSECTION = \"console\/utils\"\r\nPRIORITY = \"optional\"\r\nLICENSE = \"GPL\"\r\nPR = \"r0\"\r\n\r\nSRC_URI = \"git:\/\/git.multitech.net\/helloworld-autotools.git;protocol=git;tag=1.0.0\"\r\nS = \"${WORKDIR}\/git\"\r\n\r\ninherit autotools<\/pre>\n<p><code>SRC_URI<\/code> specifies the location to download the source from. It can take the form of any standard URL using http:\/\/, ftp:\/\/, etc. It can also fetch from SCM systems, such as git in the example above.<\/p>\n<p><code>PR<\/code> is the package revision variable. Any time a recipe is updated that should require the package to be rebuilt, this variable should be incremented.<\/p>\n<p><code>inherit autotools<\/code> brings in support for the package to be built using autotools, and thus no other instructions on how to compile and install the software are needed unless something needs to be customized.<\/p>\n<p><code>S<\/code> is the source directory variable. This specifies where the source code will exist after it is fetched from SRC_URI and unpacked. The default value is <code>${WORKDIR}\/${PN}-${PV}<\/code>, where <code>PN<\/code> is the package name and <code>PV<\/code> is the package version. Both <code>PN<\/code> and <code>PV<\/code> are set by default using the filename of the recipe, where the filename has the format <code>PN_PV.bb<\/code>.<\/p>\n<h5>Example HelloWorld recipe using a single source file<\/h5>\n<p>This example shows a simple case of building a helloworld.c file directly using the default compiler (gcc). Since it isn&#8217;t using autotools or make, we have to tell BitBake how to build it explicitly.<\/p>\n<pre class=\"brush:shell\">DESCRIPTION = \"HelloWorld\"\r\nSECTION = \"examples\"\r\nLICENSE = \"GPL\"\r\n\r\nSRC_URI = \"file:\/\/helloworld.c\"\r\n\r\nS = \"${WORKDIR}\"\r\n\r\ndo_compile() {\r\n\t${CC} ${CFLAGS} ${LDFLAGS} helloworld.c -o helloworld\r\n}\r\n\r\ndo_install() {\r\n\tinstall -d ${D}${bindir}\r\n\tinstall -m 0755 helloworld ${D}${bindir}\r\n}<\/pre>\n<p>In this case, <code>SRC_URI<\/code> specifies a file that must exist locally with the recipe. Since there is no code to download and unpack, we set <code>S<\/code> to<code> WORKDIR<\/code> since that is where helloworld.c will be copied to before it is built.<\/p>\n<p><code>WORKDIR<\/code> is located at <code>${OETREE}\/build\/tmp\/work\/armv5te-corecdp-linux-gnueabi\/&lt;package name and version&gt;<\/code> for most packages. If the package is machine-specific (rather than generic for the armv5te architecture), it may be located in the mtcdp-corecdp-linux-gnueabi or mt100eocg-corecdp-linux-gnueabi subdirectory depending on your hardware (this applies to kernel packages, images, etc).<\/p>\n<p><code>do_compile<\/code> defines how to compile the source. In this case, we just call gcc directly. If it isn&#8217;t defined, <code>do_compile<\/code> runs <code>make<\/code> in the source directory by default.<\/p>\n<p><code>do_install<\/code> defines how to install the application. This example runs <code>install<\/code> to create a bin directory where the application will be copied to and then copies the application there with permissions set to 755.<\/p>\n<p><code>D<\/code> is the destination directory where the application is installed to before it is packaged.<\/p>\n<p><code>${bindir}<\/code> is the directory where most binary applications are installed, typically <code>\/usr\/bin<\/code>.<\/p>\n<p>For more examples, see the Multi-Tech recipes in <a href=\"http:\/\/git.multitech.net\/cgi-bin\/cgit.cgi\/multitech-oe.git\/tree\/recipes\/multitech\">${OETREE}\/openembedded\/recipes\/multitech<\/a> and the many OpenEmbedded recipes in <a href=\"http:\/\/git.multitech.net\/cgi-bin\/cgit.cgi\/multitech-oe.git\/tree\/recipes\/\">${OETREE}\/openembedded\/recipes<\/a>.<\/p>\n<p>For a more in-depth explanation of BitBake recipes, syntax, and variables, see the <a href=\"http:\/\/www.yoctoproject.org\/docs\/current\/dev-manual\/dev-manual.html#new-recipe-writing-a-new-recipe\">Writing a New Recipe\u00a0<\/a>at <a href=\"http:\/\/www.yactoproject.org\/\">www.yactoproject.org<\/a>.<\/p>\n<p>Also see <a href=\"http:\/\/www.openembedded.org\/wiki\/Documentation\">OpenEmbedded documentation<\/a> and related links.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In order to package your application and include it in the root filesystem image, you must write a BitBake recipe for it. When starting from scratch, it is easiest to learn by example from existing recipes. Example HelloWorld recipe using autotools For software that uses autotools (.\/configure; make; make install), writing recipes can be very [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"parent":314,"menu_order":2,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"class_list":["post-688","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/pages\/688","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/comments?post=688"}],"version-history":[{"count":15,"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/pages\/688\/revisions"}],"predecessor-version":[{"id":22905,"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/pages\/688\/revisions\/22905"}],"up":[{"embeddable":true,"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/pages\/314"}],"wp:attachment":[{"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/media?parent=688"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}