|
@@ -0,0 +1,643 @@
|
|
|
+<!DOCTYPE html>
|
|
|
+<!-- saved from url=(0055)https://fulinux.blog.csdn.net/article/details/109129587 -->
|
|
|
+<html lang="zh-CN">
|
|
|
+ <body class="nodata " style=""><div id="MathJax_Message" style="display: none;"></div>
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+<div class="main_father clearfix d-flex justify-content-center" style="height:100%;">
|
|
|
+ <div class="container clearfix" id="mainBox">
|
|
|
+ <main>
|
|
|
+
|
|
|
+<div class="blog-content-box">
|
|
|
+ <div class="article-header-box">
|
|
|
+ <div class="article-header">
|
|
|
+ <div class="article-title-box">
|
|
|
+ <h1 class="title-article" id="articleContentId">yocto-第5篇-在meta-mylayer中添加helloworld recipe</h1>
|
|
|
+ </div>
|
|
|
+ <div class="article-info-box">
|
|
|
+ <div class="article-bar-top">
|
|
|
+ <img class="article-type-img" src="./109129587_files/original.png" alt="">
|
|
|
+ <div class="bar-content">
|
|
|
+ <img class="article-vip-img article-heard-img" src="./109129587_files/identityVip.png" alt="">
|
|
|
+ <span class="article-vip-text vip_article"> VIP文章</span>
|
|
|
+ <a class="follow-nickName " href="https://fulinux.blog.csdn.net/" target="_blank" rel="noopener">fulinux</a>
|
|
|
+ <span class="time">2020-10-17 13:34:48</span>
|
|
|
+ <img class="article-read-img article-heard-img" src="./109129587_files/articleReadEyes.png" alt="">
|
|
|
+ <span class="read-count">1751</span>
|
|
|
+ <a id="blog_detail_zk_collection" class="un-collection" data-report-click="{"mod":"popu_823","spm":"1001.2101.3001.4232","ab":"new"}">
|
|
|
+ <img class="article-collect-img article-heard-img un-collect-status isdefault" style="display:inline-block" src="./109129587_files/tobarCollect.png" alt="">
|
|
|
+ <img class="article-collect-img article-heard-img collect-status isactive" style="display:none" src="./109129587_files/tobarCollectionActive.png" alt="">
|
|
|
+ <span class="name">收藏</span>
|
|
|
+ <span class="get-collection">
|
|
|
+ 5
|
|
|
+ </span>
|
|
|
+ </a>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div class="blog-tags-box">
|
|
|
+ <div class="tags-box artic-tag-box">
|
|
|
+ <span class="label">分类专栏:</span>
|
|
|
+ <a class="tag-link" href="https://blog.csdn.net/sonbai/category_10445379.html" target="_blank" rel="noopener">Yocto开发篇</a>
|
|
|
+ <span class="label">文章标签:</span>
|
|
|
+ <a data-report-click="{"mod":"popu_626","spm":"1001.2101.3001.4223","strategy":"yocto","ab":"new"}" class="tag-link" href="https://so.csdn.net/so/search/s.do?q=yocto&t=blog&o=vip&s=&l=&f=&viparticle=" target="_blank" rel="noopener">yocto</a>
|
|
|
+ <a data-report-click="{"mod":"popu_626","spm":"1001.2101.3001.4223","strategy":"layer","ab":"new"}" class="tag-link" href="https://so.csdn.net/so/search/s.do?q=layer&t=blog&o=vip&s=&l=&f=&viparticle=" target="_blank" rel="noopener">layer</a>
|
|
|
+ <a data-report-click="{"mod":"popu_626","spm":"1001.2101.3001.4223","strategy":"makefile","ab":"new"}" class="tag-link" href="https://so.csdn.net/so/search/s.do?q=makefile&t=blog&o=vip&s=&l=&f=&viparticle=" target="_blank" rel="noopener">makefile</a>
|
|
|
+ <a data-report-click="{"mod":"popu_626","spm":"1001.2101.3001.4223","strategy":"cmake","ab":"new"}" class="tag-link" href="https://so.csdn.net/so/search/s.do?q=cmake&t=blog&o=vip&s=&l=&f=&viparticle=" target="_blank" rel="noopener">cmake</a>
|
|
|
+ <a data-report-click="{"mod":"popu_626","spm":"1001.2101.3001.4223","strategy":"hello","ab":"new"}" class="tag-link" href="https://so.csdn.net/so/search/s.do?q=hello&t=blog&o=vip&s=&l=&f=&viparticle=" target="_blank" rel="noopener">hello</a>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div class="slide-content-box">
|
|
|
+ <div class="article-copyright">
|
|
|
+ <div class="creativecommons">
|
|
|
+ 版权声明:本文为博主原创文章,遵循<a href="http://creativecommons.org/licenses/by-sa/4.0/" target="_blank" rel="noopener"> CC 4.0 BY-SA </a>版权协议,转载请附上原文出处链接和本声明。
|
|
|
+ </div>
|
|
|
+ <div class="article-source-link">
|
|
|
+ 本文链接:<a href="https://blog.csdn.net/fulinus/article/details/109129587" target="_blank">https://blog.csdn.net/fulinus/article/details/109129587</a>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div class="operating">
|
|
|
+ <a class="href-article-edit slide-toggle">版权</a>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <article class="baidu_pl">
|
|
|
+ <div id="article_content" class="article_content clearfix">
|
|
|
+ <link rel="stylesheet" href="./109129587_files/ck_htmledit_views-1a85854398.css">
|
|
|
+ <div id="content_views" class="markdown_views prism-atom-one-light">
|
|
|
+ <svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
|
|
|
+ <path stroke-linecap="round" d="M5,0 0,2.5 5,5z" id="raphael-marker-block" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></path>
|
|
|
+ </svg>
|
|
|
+ <blockquote>
|
|
|
+ <p>By: fu<a href="https://so.csdn.net/so/search?from=pc_blog_highlight&q=linux" target="_blank" class="hl hl-1">linux</a><br> E-mail: fulinux@sina.com<br> Blog: https://blog.csdn.net/fulinus<br> 喜欢的盆友欢迎点赞和订阅!<br> 你的喜欢就是我写作的动力!</p>
|
|
|
+</blockquote>
|
|
|
+<p></p>
|
|
|
+<div class="toc">
|
|
|
+ <h3><a name="t0"></a>目录</h3>
|
|
|
+ <ul><li><ul><li><a href="https://fulinux.blog.csdn.net/article/details/109129587#_10" target="_self">前言</a></li><li><a href="https://fulinux.blog.csdn.net/article/details/109129587#recipes_15" target="_self">创建项目的recipes</a></li><li><a href="https://fulinux.blog.csdn.net/article/details/109129587#Makefile_25" target="_self">由Makefile构建的项目</a></li><li><a href="https://fulinux.blog.csdn.net/article/details/109129587#AutotoolsMakefileam_164" target="_self">由Autotools(Makefile.am)构建的项目</a></li><li><a href="https://fulinux.blog.csdn.net/article/details/109129587#CmakeCMakeListstxt_371" target="_self">由Cmake(CMakeLists.txt)构建的项目</a></li><li><a href="https://fulinux.blog.csdn.net/article/details/109129587#bb_499" target="_self">关于bb文件所处的位置问题</a></li><li><a href="https://fulinux.blog.csdn.net/article/details/109129587#_520" target="_self">安装执行程序到文件系统中</a></li><li><ul><li><a href="https://fulinux.blog.csdn.net/article/details/109129587#1_537" target="_self">关联的方法1</a></li><li><a href="https://fulinux.blog.csdn.net/article/details/109129587#2_548" target="_self">关联的方法2</a></li></ul>
|
|
|
+ </li><li><a href="https://fulinux.blog.csdn.net/article/details/109129587#_593" target="_self">构建只有源码的项目</a></li></ul>
|
|
|
+ </li></ul>
|
|
|
+</div>
|
|
|
+<p></p>
|
|
|
+<p><strong>返回总目录</strong>:<a href="https://fulinux.blog.csdn.net/article/details/116208803">Yocto开发讲解系列 - 总目录</a></p>
|
|
|
+<h2><a name="t1"></a><a id="_10"></a>前言</h2>
|
|
|
+<p>在前面的一篇<a href="https://blog.csdn.net/fulinus/category_10445379.html">yocto-第4篇-创建自己的meta layer</a>中,我们已经在<code>poky</code>目录中添加了自己的一个<code>meta layer</code>,即<code>meta-mylayer</code>,而且在该<code>layer</code>中还有一个自动生成的<code>recipe</code>,即<code>example</code>,没有任何源码仅仅是有一个可以<code>bitbake</code>的<code>example.bb</code>文件,用于输出编译信息。</p>
|
|
|
+<p>对于绝大部分小白盆友而言,如何快速添加一个项目,哪怕是一个<code>helloworld</code>项目,也是对于自己初识<code>yocto</code>想快速上手的一个也非常有用的示例和帮助,因为一个好的例子胜过千言万语。诚然,关于<code>yocto</code>如何添加<code>helloworld</code>项目在其他博文中也可以看到,但是应该没有本篇全面和系统化,考虑到项目有多种构建系统,比如<code>Makefile</code>、<code>Autotools</code>和<code>Cmake</code>等构建的项目。我将在本篇中尽可能为大家展示出来。</p>
|
|
|
+<h2><a name="t2"></a><a id="recipes_15"></a>创建项目的recipes</h2>
|
|
|
+<p>首先我们考虑下这个<code>helloworld</code>项目源代码放在哪里?git服务器或者本地?当然都是可以的(本专利其他系列有讲到)。这里先考虑将源代码(毕竟源文件很少)放到<code>meta-mylayer</code>目录中。之前的文章中我们说了<code>recipes</code>是放在<code>meta layer</code>目录下的,因此,我们也在<code>meta-mylayer</code>目录中创建一个<code>recipe</code>, 参考下面:</p>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">poky<span class="token punctuation">]</span>$ <span class="token builtin class-name">cd</span> meta-mylayer/
|
|
|
+meta-mylayer<span class="token punctuation">]</span>$ <span class="token function">mkdir</span> recipes-helloworld
|
|
|
+meta-mylayer<span class="token punctuation">]</span>$ <span class="token builtin class-name">cd</span> recipes-helloworld/
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li></ul></pre>
|
|
|
+<p>见上面,我们将会在<code>recipes-helloworld</code>目录中放置若干种方式构建的<code>helloworld</code>项目。</p>
|
|
|
+<h2><a name="t3"></a><a id="Makefile_25"></a>由Makefile构建的项目</h2>
|
|
|
+<ol><li>创建一个<code>Makefile</code>方式构建的<code>helloworld</code>项目,为了区分后面的构建系统项目,这里我们将目录名定为<code>hellowolrd-m</code>,参考如下过程:</li></ol>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">recipes-helloworld<span class="token punctuation">]</span>$ <span class="token function">mkdir</span> helloworld-m/helloworld
|
|
|
+recipes-helloworld<span class="token punctuation">]</span>$ <span class="token builtin class-name">cd</span> hellowolrd-m/helloworld
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li></ul></pre>
|
|
|
+<ol start="2"><li>并新建一个<code>helloworld.c</code>文件:</li></ol>
|
|
|
+<pre class="prettyprint"><code class="prism language-c has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;"><span class="token comment">//helloworld.c</span>
|
|
|
+<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string"><stdio.h></span></span>
|
|
|
+
|
|
|
+<span class="token keyword">int</span> <span class="token function">main</span> <span class="token punctuation">(</span><span class="token keyword">int</span> argc<span class="token punctuation">,</span> <span class="token keyword">char</span> <span class="token operator">*</span><span class="token operator">*</span>argv<span class="token punctuation">)</span>
|
|
|
+<span class="token punctuation">{<!-- --></span>
|
|
|
+ <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"Hello World!\n"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
|
|
+ <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
|
|
|
+<span class="token punctuation">}</span> <span class="token comment">/* ----- End of main() ----- */</span>
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li></ul></pre>
|
|
|
+<p>这个程序很简单,C程序内容也不是本篇的关注点,尽量简单哈。如果大家遇到复杂的情况不清楚怎么弄可以在评论区里面留言。</p>
|
|
|
+<ol start="3"><li>新建一个<code>Makefile</code>文件:</li></ol>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">TARGET <span class="token operator">=</span> helloworld
|
|
|
+all :<span class="token operator">=</span> <span class="token variable"><span class="token variable">$(</span>TARGET<span class="token variable">)</span></span>
|
|
|
+CFLAGS ?<span class="token operator">=</span> -Wall -O
|
|
|
+bindir <span class="token operator">=</span> <span class="token variable"><span class="token variable">$(</span>DESTDIR<span class="token variable">)</span></span>/usr/bin/
|
|
|
+
|
|
|
+OBJS <span class="token operator">=</span> helloworld.o
|
|
|
+
|
|
|
+<span class="token variable"><span class="token variable">$(</span>TARGET<span class="token variable">)</span></span><span class="token builtin class-name">:</span> <span class="token variable"><span class="token variable">$(</span>OBJS<span class="token variable">)</span></span>
|
|
|
+ <span class="token variable"><span class="token variable">$(</span>CC<span class="token variable">)</span></span> <span class="token variable"><span class="token variable">$(</span>CFLAGS<span class="token variable">)</span></span> <span class="token variable"><span class="token variable">$(</span>LDFLAGS<span class="token variable">)</span></span> $^ -o <span class="token variable">$@</span>
|
|
|
+
|
|
|
+install:
|
|
|
+ <span class="token function">install</span> -d <span class="token variable"><span class="token variable">$(</span>bindir<span class="token variable">)</span></span>
|
|
|
+ <span class="token function">install</span> -m 0755 <span class="token variable"><span class="token variable">$(</span>TARGET<span class="token variable">)</span></span> <span class="token variable"><span class="token variable">$(</span>bindir<span class="token variable">)</span></span>
|
|
|
+
|
|
|
+uninstall:
|
|
|
+ <span class="token variable">${RM}</span> <span class="token variable"><span class="token variable">$(</span>bindir<span class="token variable">)</span></span>/<span class="token variable"><span class="token variable">$(</span>TARGET<span class="token variable">)</span></span>
|
|
|
+
|
|
|
+clean:
|
|
|
+ <span class="token variable"><span class="token variable">$(</span>RM<span class="token variable">)</span></span> <span class="token variable"><span class="token variable">$(</span>TARGET<span class="token variable">)</span></span> <span class="token variable"><span class="token variable">$(</span>OBJS<span class="token variable">)</span></span>
|
|
|
+
|
|
|
+.PHONY: all clean <span class="token function">install</span> uninstall
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li></ul></pre>
|
|
|
+<ol start="4"><li>在添加bb文件之前,可以先自己手动验证是否有问题,如果没有问题了,我们再继续下一步:</li></ol>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">helloworld<span class="token punctuation">]</span>$ <span class="token function">ls</span>
|
|
|
+helloworld.c Makefile
|
|
|
+helloworld<span class="token punctuation">]</span>$ <span class="token function">make</span>
|
|
|
+cc -Wall -O -c -o helloworld.o helloworld.c
|
|
|
+cc -Wall -O helloworld.o -o helloworld
|
|
|
+helloworld<span class="token punctuation">]</span>$ ./helloworld
|
|
|
+Hello World<span class="token operator">!</span>
|
|
|
+helloworld<span class="token punctuation">]</span>$ <span class="token function">make</span> clean
|
|
|
+<span class="token function">rm</span> -f helloworld helloworld.o
|
|
|
+helloworld<span class="token punctuation">]</span>$ <span class="token function">ls</span>
|
|
|
+helloworld.c Makefile
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li></ul></pre>
|
|
|
+<p>OK~ 上面验证的结果正常,下一步就是写一个<code>recipe</code>的bb文件了:</p>
|
|
|
+<ol start="5"><li>新建一个bb文件,文件名就叫<code>helloworld-m.bb</code>,注意文件名中下划线"_"是分隔<code>recipe</code>名和版本的,<code>不能</code>出现<code>helloworld_m.bb</code>的名字,这样一来m就成版本号了。</li></ol>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">helloworld<span class="token punctuation">]</span>$ <span class="token builtin class-name">cd</span> <span class="token punctuation">..</span>/
|
|
|
+helloworld-m<span class="token punctuation">]</span>$ <span class="token function">vim</span> helloworld-m.bb
|
|
|
+<span class="token comment"># helloworld application</span>
|
|
|
+SUMMARY <span class="token operator">=</span> <span class="token string">"helloworld of makefile recipe"</span> <span class="token comment">#概要</span>
|
|
|
+DESCRIPTION <span class="token operator">=</span> <span class="token string">"My hello world application"</span> <span class="token comment">#描述</span>
|
|
|
+LICENSE <span class="token operator">=</span> <span class="token string">"CLOSED"</span> <span class="token comment">#关闭license</span>
|
|
|
+
|
|
|
+FILESEXTRAPATHS_prepend :<span class="token operator">=</span> <span class="token string">"<span class="token variable">${THISDIR}</span>/:"</span> <span class="token comment">#文件额外的搜索路径</span>
|
|
|
+SRC_URI <span class="token operator">=</span> <span class="token string">"file://helloworld/"</span> <span class="token comment">#指定源码路径</span>
|
|
|
+
|
|
|
+S <span class="token operator">=</span> <span class="token string">"<span class="token variable">${WORKDIR}</span>/helloworld"</span>
|
|
|
+
|
|
|
+CFLAGS_append <span class="token operator">=</span> <span class="token string">"-Wall -O -g"</span>
|
|
|
+
|
|
|
+EXTRA_OEMAKE <span class="token operator">=</span> <span class="token string">"'CC=<span class="token variable">${CC}</span>' 'CFLAGS=<span class="token variable">${CFLAGS}</span>'"</span>
|
|
|
+EXTRA_OEMAKE_append <span class="token operator">=</span> <span class="token string">" 'LDFLAGS=<span class="token variable">${LDFLAGS}</span>'"</span>
|
|
|
+EXTRA_OEMAKE_append <span class="token operator">=</span> <span class="token string">" 'DESTDIR=<span class="token variable">${D}</span>'"</span>
|
|
|
+
|
|
|
+<span class="token function-name function">do_install</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>
|
|
|
+ oe_runmake <span class="token function">install</span>
|
|
|
+<span class="token punctuation">}</span>
|
|
|
+
|
|
|
+<span class="token comment"># if no install target in makefile, using this do_install</span>
|
|
|
+<span class="token comment">#do_install () {<!-- --></span>
|
|
|
+<span class="token comment">#install -d ${D}${bindir}/</span>
|
|
|
+<span class="token comment">#install -m 0755 ${S}/helloworld ${D}${bindir}/</span>
|
|
|
+<span class="token comment">#}</span>
|
|
|
+
|
|
|
+<span class="token comment"># if no LDFLAGS, using this</span>
|
|
|
+<span class="token comment">#INSANE_SKIP_${PN} += "ldflags"</span>
|
|
|
+
|
|
|
+FILES_<span class="token variable">${PN}</span> <span class="token operator">=</span> <span class="token string">"<span class="token variable">${bindir}</span>/"</span>
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li><li style="color: rgb(153, 153, 153);">26</li><li style="color: rgb(153, 153, 153);">27</li><li style="color: rgb(153, 153, 153);">28</li><li style="color: rgb(153, 153, 153);">29</li><li style="color: rgb(153, 153, 153);">30</li><li style="color: rgb(153, 153, 153);">31</li><li style="color: rgb(153, 153, 153);">32</li></ul></pre>
|
|
|
+<p>这里不细讲bb文件了,关于bb文件的内容和变量等知识,我都放在后面的文章中有讲解,大家这里先了解有个印象即可。</p>
|
|
|
+<ol start="6"><li>查看文件拓扑结构:</li></ol>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">meta-mylayer<span class="token punctuation">]</span>$ tree recipes-helloworld/
|
|
|
+recipes-helloworld/
|
|
|
+└── helloworld-m
|
|
|
+ ├── helloworld
|
|
|
+ │ ├── helloworld.c
|
|
|
+ │ └── Makefile
|
|
|
+ └── helloworld-m.bb
|
|
|
+
|
|
|
+<span class="token number">2</span> directories, <span class="token number">3</span> files
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li></ul></pre>
|
|
|
+<ol start="7"><li>开始编译</li></ol>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">poky<span class="token punctuation">]</span>$ <span class="token builtin class-name">source</span> oe-init-build-env
|
|
|
+build<span class="token punctuation">]</span>$ bitbake helloworld-m
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li></ul></pre>
|
|
|
+<ol start="8"><li>查看编译结果:</li></ol>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">build<span class="token punctuation">]</span>$ <span class="token function">ls</span> tmp/work/core2-64-poky-linux/helloworld-m/1.0-r0/
|
|
|
+configure.sstate helloworld packages-split pseudo sysroot-destdir
|
|
|
+debugsources.list image pkgdata recipe-sysroot temp
|
|
|
+deploy-ipks license-destdir pkgdata-pdata-input recipe-sysroot-native
|
|
|
+deploy-source-date-epoch package pkgdata-sysroot source-date-epoch
|
|
|
+build<span class="token punctuation">]</span>$ <span class="token function">file</span> tmp/work/core2-64-poky-linux/helloworld-m/1.0-r0/image/usr/bin/helloworld
|
|
|
+tmp/work/core2-64-poky-linux/helloworld-m/1.0-r0/image/usr/bin/helloworld: ELF <span class="token number">64</span>-bit LSB shared object, x86-64, version <span class="token number">1</span> <span class="token punctuation">(</span>SYSV<span class="token punctuation">)</span>, dynamically linked, interpreter /lib/ld-linux-x86-64.so.2, BuildID<span class="token punctuation">[</span>sha1<span class="token punctuation">]</span><span class="token operator">=</span>641c84dfe75480fef888339aa2c782566d48a106, <span class="token keyword">for</span> GNU/Linux <span class="token number">3.2</span>.0, not stripped
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li></ul></pre>
|
|
|
+<p>OK~ 上面讲解用<code>Makefile</code>文件构建的项目,并如何在<code>yocto</code>中添加<code>recipe</code>的工作到这里就告一段落!</p>
|
|
|
+<p><em>注意:我们的工作到这里并还没有真正完成,如果编译<code>target</code>(比如<code>bitbake core-image-sato</code>),在文件系统的/usr/bin/目录下没有相应的<code>helloworld</code>执行程序。后面再讲。文末再讲如何安装到文件系统中。</em></p>
|
|
|
+<h2><a name="t4"></a><a id="AutotoolsMakefileam_164"></a>由Autotools(Makefile.am)构建的项目</h2>
|
|
|
+<p>可能你并没有听说过<code>Autotools</code>,但是如果项目当中存在<code>configure.ac</code>、<code>Makefile.am</code>等文件的时候,你可能会有印象,不错<code>configure.ac</code>和<code>Makefile.am</code>就是<code>Autotools</code>构建项目的配置文件。</p>
|
|
|
+<ol><li>新建的<code>recipe</code>的子目录,新建对应的新目录名为<code>helloworld-a</code>,过程参考如下:</li></ol>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">recipes-helloworld<span class="token punctuation">]</span>$ <span class="token function">mkdir</span> helloworld-a
|
|
|
+recipes-helloworld<span class="token punctuation">]</span>$ <span class="token builtin class-name">cd</span> helloworld-a/
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li></ul></pre>
|
|
|
+<ol start="3"><li>将上一篇的<code>helloworld</code>项目复制到该目录,并做增删操作</li></ol>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">helloworld-a<span class="token punctuation">]</span>$ <span class="token function">cp</span> -rf <span class="token punctuation">..</span>/helloworld-m/helloworld <span class="token builtin class-name">.</span>
|
|
|
+helloworld-a<span class="token punctuation">]</span>$ <span class="token builtin class-name">cd</span> helloworld/
|
|
|
+helloworld<span class="token punctuation">]</span>$ <span class="token function">rm</span> Makefile
|
|
|
+helloworld<span class="token punctuation">]</span>$ <span class="token function">mkdir</span> src
|
|
|
+helloworld<span class="token punctuation">]</span>$ <span class="token function">mv</span> helloworld.c src/
|
|
|
+helloworld<span class="token punctuation">]</span>$ <span class="token function">vim</span> src/helloworld.c
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li></ul></pre>
|
|
|
+<blockquote>
|
|
|
+ <p>实际上我们也可以不用将源码文件放到<code>src</code>目录下,这里只是尽可能向正规的做法靠拢。</p>
|
|
|
+</blockquote>
|
|
|
+<ol start="3"><li>修改代码:</li></ol>
|
|
|
+<pre class="prettyprint"><code class="prism language-c has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string"><stdio.h></span></span>
|
|
|
+<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string"><config.h></span> <span class="token comment">//添加了这个</span></span>
|
|
|
+
|
|
|
+<span class="token keyword">int</span> <span class="token function">main</span> <span class="token punctuation">(</span><span class="token keyword">int</span> argc<span class="token punctuation">,</span> <span class="token keyword">char</span> <span class="token operator">*</span><span class="token operator">*</span>argv<span class="token punctuation">)</span>
|
|
|
+<span class="token punctuation">{<!-- --></span>
|
|
|
+ <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"Hello World and Autotools\n"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
|
|
+ <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
|
|
|
+<span class="token punctuation">}</span> <span class="token comment">/* ----- End of main() ----- */</span>
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li></ul></pre>
|
|
|
+<ol start="4"><li>在<code>helloworld</code>目录中新建一个<code>README</code>文件(当然有没有这个文件也没关系):</li></ol>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">helloworld<span class="token punctuation">]</span>$ <span class="token function">vim</span> README
|
|
|
+This is a demonstration package <span class="token keyword">for</span> GNU Automake.
|
|
|
+Type <span class="token string">'info Automake'</span> to <span class="token builtin class-name">read</span> the Automake manual.
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li></ul></pre>
|
|
|
+<ol start="5"><li>在项目根目录和<code>src</code>目录中新建两个<code>Makefile.am</code>和<code>src/Makefile.am</code>(包含<code>Automake</code>指令语句)<br> 新建<code>Makefile.am</code>文件</li></ol>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">helloworld<span class="token punctuation">]</span>$ <span class="token function">vim</span> Makefile.am
|
|
|
+SUBDIRS <span class="token operator">=</span> src
|
|
|
+dist_doc_DATA <span class="token operator">=</span> README
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li></ul></pre>
|
|
|
+<p>新建<code>src/Makefile.am</code>文件</p>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">helloworld<span class="token punctuation">]</span>$ <span class="token function">vim</span> src/Makefile.am
|
|
|
+bin_PROGRAMS <span class="token operator">=</span> helloworlda <span class="token comment">#命名为helloworlda是为了区别上面的/usr/bin/helloworld,以免冲突</span>
|
|
|
+helloworlda_SOURCES <span class="token operator">=</span> helloworld.c
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li></ul></pre>
|
|
|
+<ol start="6"><li>新建<code>configure.ac</code>文件(该文件内包含创建<code>configure</code>脚本的<code>Autoconf</code>指令)。</li></ol>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">helloworld<span class="token punctuation">]</span>$ <span class="token function">vim</span> configure.ac
|
|
|
+AC_INIT<span class="token punctuation">(</span><span class="token punctuation">[</span>helloworld<span class="token punctuation">]</span>, <span class="token punctuation">[</span><span class="token number">1.0</span><span class="token punctuation">]</span>, <span class="token punctuation">[</span>fulinux@sina.com<span class="token punctuation">]</span><span class="token punctuation">)</span>
|
|
|
+AM_INIT_AUTOMAKE<span class="token punctuation">(</span><span class="token punctuation">[</span>-Wall -Werror foreign<span class="token punctuation">]</span><span class="token punctuation">)</span>
|
|
|
+AC_PROG_CC
|
|
|
+AC_CONFIG_HEADERS<span class="token punctuation">(</span><span class="token punctuation">[</span>config.h<span class="token punctuation">]</span><span class="token punctuation">)</span>
|
|
|
+AC_CONFIG_FILES<span class="token punctuation">(</span><span class="token punctuation">[</span>
|
|
|
+ Makefile
|
|
|
+ src/Makefile
|
|
|
+<span class="token punctuation">]</span><span class="token punctuation">)</span>
|
|
|
+
|
|
|
+AC_OUTPUT
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li></ul></pre>
|
|
|
+<p>一旦有了这五个文件,就可以运行<code>Autotools</code>来实例化构建系统了。</p>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">recipes-helloworld<span class="token punctuation">]</span>$ tree helloworld-a/helloworld/
|
|
|
+helloworld-a/helloworld/
|
|
|
+├── configure.ac
|
|
|
+├── Makefile.am
|
|
|
+├── README
|
|
|
+└── src
|
|
|
+ ├── helloworld.c
|
|
|
+ └── Makefile.am
|
|
|
+
|
|
|
+<span class="token number">1</span> directory, <span class="token number">5</span> files
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li></ul></pre>
|
|
|
+<ol start="7"><li>本地构建系统实例化和编译演示<br> 使用<code>autoreconf</code>命令执行此操作来实例化构建系统,我们首先在本地中验证下。如下所示:</li></ol>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">helloworld<span class="token punctuation">]</span>$ autoreconf --install
|
|
|
+configure.ac:3: installing <span class="token string">'./compile'</span>
|
|
|
+configure.ac:2: installing <span class="token string">'./install-sh'</span>
|
|
|
+configure.ac:2: installing <span class="token string">'./missing'</span>
|
|
|
+src/Makefile.am: installing <span class="token string">'./depcomp'</span>
|
|
|
+helloworld<span class="token punctuation">]</span>$ <span class="token function">ls</span>
|
|
|
+aclocal.m4 compile configure depcomp Makefile.am missing
|
|
|
+autom4te.cache config.h.in configure.ac install-sh Makefile.in src
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li></ul></pre>
|
|
|
+<p>此时构建系统已完成。除了上面命令输出中提到的三个脚本之外,还可以看到<code>autoreconf</code>还创建了四个其他文件:<code>configure</code>、<code>config.h.In</code>、<code>Makefile.In</code>和<code>src/Makefile.In</code>。后三个文件是模板,它们将通过在<code>config.h</code>、<code>Makefile</code>和<code>src/Makefile</code>下进行配置来适应系统。运行如下命令:</p>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">helloworld<span class="token punctuation">]</span>$ ./configure
|
|
|
+checking <span class="token keyword">for</span> a BSD-compatible install<span class="token punctuation">..</span>. /usr/bin/install -c
|
|
|
+checking whether build environment is sane<span class="token punctuation">..</span>. <span class="token function">yes</span>
|
|
|
+checking <span class="token keyword">for</span> a thread-safe <span class="token function">mkdir</span> -p<span class="token punctuation">..</span>. /bin/mkdir -p
|
|
|
+checking <span class="token keyword">for</span> gawk<span class="token punctuation">..</span>. <span class="token function">gawk</span>
|
|
|
+checking whether <span class="token function">make</span> sets <span class="token variable"><span class="token variable">$(</span>MAKE<span class="token variable">)</span></span><span class="token punctuation">..</span>. <span class="token function">yes</span>
|
|
|
+checking whether <span class="token function">make</span> supports nested variables<span class="token punctuation">..</span>. <span class="token function">yes</span>
|
|
|
+checking <span class="token keyword">for</span> gcc<span class="token punctuation">..</span>. gcc
|
|
|
+checking whether the C compiler works<span class="token punctuation">..</span>. <span class="token function">yes</span>
|
|
|
+checking <span class="token keyword">for</span> C compiler default output <span class="token function">file</span> name<span class="token punctuation">..</span>. a.out
|
|
|
+checking <span class="token keyword">for</span> suffix of executables<span class="token punctuation">..</span>.
|
|
|
+checking whether we are cross compiling<span class="token punctuation">..</span>. no
|
|
|
+checking <span class="token keyword">for</span> suffix of object files<span class="token punctuation">..</span>. o
|
|
|
+checking whether we are using the GNU C compiler<span class="token punctuation">..</span>. <span class="token function">yes</span>
|
|
|
+checking whether gcc accepts -g<span class="token punctuation">..</span>. <span class="token function">yes</span>
|
|
|
+checking <span class="token keyword">for</span> gcc option to accept ISO C89<span class="token punctuation">..</span>. none needed
|
|
|
+checking whether gcc understands -c and -o together<span class="token punctuation">..</span>. <span class="token function">yes</span>
|
|
|
+checking <span class="token keyword">for</span> style of include used by make<span class="token punctuation">..</span>. GNU
|
|
|
+checking dependency style of gcc<span class="token punctuation">..</span>. gcc3
|
|
|
+checking that generated files are newer than configure<span class="token punctuation">..</span>. <span class="token keyword">done</span>
|
|
|
+configure: creating ./config.status
|
|
|
+config.status: creating Makefile
|
|
|
+config.status: creating src/Makefile
|
|
|
+config.status: creating config.h
|
|
|
+config.status: executing depfiles commands
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li></ul></pre>
|
|
|
+<p>在<code>configure</code>运行之后,可以看到生成了<code>Makefile</code>、<code>src/Makefile</code>和<code>config.h</code>。现在我们可以调用make命令编译了:</p>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">helloworld<span class="token punctuation">]</span>$ <span class="token function">make</span>
|
|
|
+<span class="token function">make</span> all-recursive
|
|
|
+make<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span>: Entering directory <span class="token string">'/home/peeta/poky/meta-mylayer/recipes-helloworld/helloworld-a/helloworld'</span>
|
|
|
+Making all <span class="token keyword">in</span> src
|
|
|
+make<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span>: Entering directory <span class="token string">'/home/peeta/poky/meta-mylayer/recipes-helloworld/helloworld-a/helloworld/src'</span>
|
|
|
+gcc -DHAVE_CONFIG_H -I. -I<span class="token punctuation">..</span> -g -O2 -MT helloworld.o -MD -MP -MF .deps/helloworld.Tpo -c -o helloworld.o helloworld.c
|
|
|
+<span class="token function">mv</span> -f .deps/helloworld.Tpo .deps/helloworld.Po
|
|
|
+gcc -g -O2 -o helloworld helloworld.o
|
|
|
+make<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span>: Leaving directory <span class="token string">'/home/peeta/poky/meta-mylayer/recipes-helloworld/helloworld-a/helloworld/src'</span>
|
|
|
+make<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span>: Entering directory <span class="token string">'/home/peeta/poky/meta-mylayer/recipes-helloworld/helloworld-a/helloworld'</span>
|
|
|
+make<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span>: Leaving directory <span class="token string">'/home/peeta/poky/meta-mylayer/recipes-helloworld/helloworld-a/helloworld'</span>
|
|
|
+make<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span>: Leaving directory <span class="token string">'/home/peeta/poky/meta-mylayer/recipes-helloworld/helloworld-a/helloworld'</span>
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li></ul></pre>
|
|
|
+<ol start="8"><li>运行演示:</li></ol>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">helloworld<span class="token punctuation">]</span>$ ./src/helloworld
|
|
|
+Hello World and Autotools
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li></ul></pre>
|
|
|
+<ol start="9"><li>清理编译生成的文件:<br> 可以编译和运行后,最后就是清理和删除一些编译生成的文件:</li></ol>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">helloworld<span class="token punctuation">]</span>$ <span class="token function">make</span> distclean
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li></ul></pre>
|
|
|
+<p>当然更绝做法的是:</p>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">helloworld<span class="token punctuation">]</span>$ <span class="token function">rm</span> aclocal.m4 compile configure depcomp missing autom4te.cache config.h.in install-sh Makefile.in -rf
|
|
|
+helloworld<span class="token punctuation">]</span>$ <span class="token function">rm</span> src/Makefile.in
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li></ul></pre>
|
|
|
+<p>最后只保留一开始的5个文件。</p>
|
|
|
+<ol start="10"><li>添加recipe的bb文件,如下:</li></ol>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">helloworld<span class="token punctuation">]</span>$ <span class="token builtin class-name">cd</span> <span class="token punctuation">..</span>/
|
|
|
+helloworld-a<span class="token punctuation">]</span>$ <span class="token function">cat</span> helloworld-a.bb
|
|
|
+<span class="token comment"># helloworld application</span>
|
|
|
+SUMMARY <span class="token operator">=</span> <span class="token string">"helloworld of Autotools recipe"</span>
|
|
|
+DESCRIPTION <span class="token operator">=</span> <span class="token string">"My hello world application"</span>
|
|
|
+LICENSE <span class="token operator">=</span> <span class="token string">"CLOSED"</span>
|
|
|
+
|
|
|
+inherit autotools <span class="token comment">#继承了autotools, 这个是重点</span>
|
|
|
+
|
|
|
+FILESEXTRAPATHS_prepend :<span class="token operator">=</span> <span class="token string">"<span class="token variable">${THISDIR}</span>/:"</span>
|
|
|
+SRC_URI <span class="token operator">=</span> <span class="token string">"file://helloworld/"</span>
|
|
|
+
|
|
|
+S <span class="token operator">=</span> <span class="token string">"<span class="token variable">${WORKDIR}</span>/helloworld"</span>
|
|
|
+
|
|
|
+<span class="token comment">#CFLAGS_append = "-Wall -O -g"</span>
|
|
|
+
|
|
|
+FILES_<span class="token variable">${PN}</span> <span class="token operator">=</span> <span class="token string">"<span class="token variable">${bindir}</span>/"</span>
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li></ul></pre>
|
|
|
+<p>上面是不是很简单,没有前面的bb文件中的一些变量和函数了,不用修改<code>do_make()</code>或<code>do_install()</code>等函数的原因都是因为继承了<code>autotools</code>,继承的这个<code>class</code>类做了<code>autotools</code>构建编译过程中的各项任务,0是不是很简单~</p>
|
|
|
+<ol start="11"><li><code>bitbake</code>编译演示:</li></ol>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">poky<span class="token punctuation">]</span>$ <span class="token builtin class-name">source</span> oe-init-build-env
|
|
|
+build<span class="token punctuation">]</span>$ bitbake helloworld-a
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li></ul></pre>
|
|
|
+<ol start="12"><li>结果浏览:</li></ol>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">build<span class="token punctuation">]</span>$ <span class="token function">ls</span> tmp/work/core2-64-poky-linux/helloworld-a/1.0-r0/helloworld/
|
|
|
+aclocal.m4 compile config.h.in configure depcomp m4 Makefile.in README
|
|
|
+autom4te.cache config.guess config.sub configure.ac install-sh Makefile.am missing src
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li></ul></pre>
|
|
|
+<p>上面可见bitbake的过程中已经自己执行了<code>autoreconf</code>命令,是不是很简单呢?</p>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">build<span class="token punctuation">]</span>$ <span class="token function">ls</span> tmp/work/core2-64-poky-linux/helloworld-a/1.0-r0/image/usr/bin/
|
|
|
+helloworlda
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li></ul></pre>
|
|
|
+<p>文末再讲如何安装到文件系统中。使用<code>Autotools</code>工具构建的项目就完成了~</p>
|
|
|
+<h2><a name="t5"></a><a id="CmakeCMakeListstxt_371"></a>由Cmake(CMakeLists.txt)构建的项目</h2>
|
|
|
+<p>现在讲<code>Cmake</code>工具构建的项目,这个也是本专栏推荐的方式,后续的很多示例项目都是用CMake构建的,这方面的教程网上也有,大家感兴趣的也可以了解下~</p>
|
|
|
+<ol><li>首先我们就是新建一个目录用来放这个<code>recipe</code>,目录名为<code>helloworld-c</code>:</li></ol>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">recipes-helloworld<span class="token punctuation">]</span>$ <span class="token function">mkdir</span> helloworld-c
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li></ul></pre>
|
|
|
+<ol start="2"><li>将初始的<code>helloworld</code>项目复制到<code>helloworld-c</code>目录中:</li></ol>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">recipes-helloworld<span class="token punctuation">]</span>$ <span class="token function">cp</span> helloworld-m/helloworld helloworld-c/ -rf
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li></ul></pre>
|
|
|
+<ol start="3"><li>增删<code>helloworld</code>项目目录结果:</li></ol>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">recipes-helloworld<span class="token punctuation">]</span>$ <span class="token builtin class-name">cd</span> helloworld-c/helloworld/
|
|
|
+helloworld<span class="token punctuation">]</span>$ <span class="token function">rm</span> Makefile
|
|
|
+helloworld<span class="token punctuation">]</span>$ <span class="token function">mkdir</span> src
|
|
|
+helloworld<span class="token punctuation">]</span>$ <span class="token function">mv</span> helloworld.c src/
|
|
|
+helloworld<span class="token punctuation">]</span>$ <span class="token function">vim</span> src/helloworld.c
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li></ul></pre>
|
|
|
+<pre class="prettyprint"><code class="prism language-c has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string"><stdio.h></span></span>
|
|
|
+
|
|
|
+<span class="token keyword">int</span> <span class="token function">main</span> <span class="token punctuation">(</span><span class="token keyword">int</span> argc<span class="token punctuation">,</span> <span class="token keyword">char</span> <span class="token operator">*</span><span class="token operator">*</span>argv<span class="token punctuation">)</span>
|
|
|
+<span class="token punctuation">{<!-- --></span>
|
|
|
+ <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"Hello World and Cmake\n"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
|
|
+ <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
|
|
|
+<span class="token punctuation">}</span> <span class="token comment">/* ----- End of main() ----- */</span>
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li></ul></pre>
|
|
|
+<ol start="4"><li>改造<code>helloworld</code>项目为由<code>Cmake</code>构建:</li></ol>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">helloworld<span class="token punctuation">]</span>$ <span class="token function">vim</span> CMakeLists.txt
|
|
|
+project<span class="token punctuation">(</span>helloworld C<span class="token punctuation">)</span>
|
|
|
+cmake_minimum_required<span class="token punctuation">(</span>VERSION <span class="token number">2.6</span>.3<span class="token punctuation">)</span>
|
|
|
+
|
|
|
+add_subdirectory<span class="token punctuation">(</span>src<span class="token punctuation">)</span>
|
|
|
+
|
|
|
+helloworld<span class="token punctuation">]</span>$ <span class="token function">cat</span> src/CMakeLists.txt
|
|
|
+add_executable <span class="token punctuation">(</span>helloworldc helloworld.c<span class="token punctuation">)</span>
|
|
|
+
|
|
|
+install<span class="token punctuation">(</span>TARGETS helloworldc DESTINATION <span class="token variable">${CMAKE_INSTALL_PREFIX}</span>/bin<span class="token punctuation">)</span>
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li></ul></pre>
|
|
|
+<ol start="5"><li>OK, 就添加了这两个文件,拓扑结构如下:</li></ol>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">helloworld<span class="token punctuation">]</span>$ tree <span class="token builtin class-name">.</span>
|
|
|
+<span class="token builtin class-name">.</span>
|
|
|
+├── CMakeLists.txt
|
|
|
+└── src
|
|
|
+ ├── CMakeLists.txt
|
|
|
+ └── helloworld.c
|
|
|
+
|
|
|
+<span class="token number">1</span> directory, <span class="token number">3</span> files
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li></ul></pre>
|
|
|
+<ol start="6"><li>本地编译演示,确保<code>Cmake</code>构建的项目没问题:</li></ol>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">helloworld<span class="token punctuation">]</span>$ <span class="token function">mkdir</span> build
|
|
|
+helloworld<span class="token punctuation">]</span>$ <span class="token builtin class-name">cd</span> build/
|
|
|
+build<span class="token punctuation">]</span>$ cmake <span class="token punctuation">..</span>
|
|
|
+-- The C compiler identification is GNU <span class="token number">5.4</span>.0
|
|
|
+-- Check <span class="token keyword">for</span> working C compiler: /usr/bin/cc
|
|
|
+-- Check <span class="token keyword">for</span> working C compiler: /usr/bin/cc -- works
|
|
|
+-- Detecting C compiler ABI info
|
|
|
+-- Detecting C compiler ABI info - <span class="token keyword">done</span>
|
|
|
+-- Detecting C compile features
|
|
|
+-- Detecting C compile features - <span class="token keyword">done</span>
|
|
|
+-- Configuring <span class="token keyword">done</span>
|
|
|
+-- Generating <span class="token keyword">done</span>
|
|
|
+-- Build files have been written to: /home/peeta/poky/meta-mylayer/recipes-helloworld/helloworld-c/helloworld/build
|
|
|
+build<span class="token punctuation">]</span>$ <span class="token function">make</span>
|
|
|
+Scanning dependencies of target helloworldc
|
|
|
+<span class="token punctuation">[</span> <span class="token number">50</span>%<span class="token punctuation">]</span> Building C object src/CMakeFiles/helloworldc.dir/helloworld.c.o
|
|
|
+<span class="token punctuation">[</span><span class="token number">100</span>%<span class="token punctuation">]</span> Linking C executable helloworldc
|
|
|
+<span class="token punctuation">[</span><span class="token number">100</span>%<span class="token punctuation">]</span> Built target helloworldc
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li></ul></pre>
|
|
|
+<ol start="7"><li>运行演示:</li></ol>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">build<span class="token punctuation">]</span>$ ./src/helloworldc
|
|
|
+Hello World and Cmake
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li></ul></pre>
|
|
|
+<ol start="8"><li>清理编译内容,删除<code>build</code>目录</li></ol>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">helloworld<span class="token punctuation">]</span>$ <span class="token function">rm</span> -rf build/
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li></ul></pre>
|
|
|
+<ol start="9"><li>添加<code>recipe</code>的bb文件,如下:</li></ol>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">helloworld<span class="token punctuation">]</span>$ <span class="token builtin class-name">cd</span> <span class="token punctuation">..</span>
|
|
|
+helloworld-c<span class="token punctuation">]</span>$ <span class="token function">cat</span> helloworld-c.bb
|
|
|
+<span class="token comment"># helloworld application</span>
|
|
|
+SUMMARY <span class="token operator">=</span> <span class="token string">"helloworld of Autotools recipe"</span>
|
|
|
+DESCRIPTION <span class="token operator">=</span> <span class="token string">"My hello world application"</span>
|
|
|
+LICENSE <span class="token operator">=</span> <span class="token string">"CLOSED"</span>
|
|
|
+
|
|
|
+inherit cmake <span class="token comment">#继承了这个</span>
|
|
|
+
|
|
|
+FILESEXTRAPATHS_prepend :<span class="token operator">=</span> <span class="token string">"<span class="token variable">${THISDIR}</span>/:"</span>
|
|
|
+SRC_URI <span class="token operator">=</span> <span class="token string">"file://helloworld/"</span>
|
|
|
+
|
|
|
+S <span class="token operator">=</span> <span class="token string">"<span class="token variable">${WORKDIR}</span>/helloworld"</span>
|
|
|
+
|
|
|
+<span class="token comment">#CFLAGS_append = "-Wall -O -g"</span>
|
|
|
+
|
|
|
+FILES_<span class="token variable">${PN}</span> <span class="token operator">=</span> <span class="token string">"<span class="token variable">${bindir}</span>/"</span>
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li></ul></pre>
|
|
|
+<p>这个bb文件基本上和<code>Autotools</code>使用的bb文件类似,只是继承的<code>autotools</code>改成了<code>cmake</code>。</p>
|
|
|
+<ol start="10"><li><code>bitbake</code>编译演示:</li></ol>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">build<span class="token punctuation">]</span>$ bitbake helloworld-c
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li></ul></pre>
|
|
|
+<ol start="11"><li>结果浏览:</li></ol>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">build<span class="token punctuation">]</span>$ <span class="token function">ls</span> tmp/work/core2-64-poky-linux/helloworld-c/1.0-r0/image/usr/bin/
|
|
|
+helloworldc
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li></ul></pre>
|
|
|
+<p>到这里,我们使用<code>Cmake</code>工具构建的项目就完成了~</p>
|
|
|
+<h2><a name="t6"></a><a id="bb_499"></a>关于bb文件所处的位置问题</h2>
|
|
|
+<p>从上面我们看到了三个bb文件的路径是这样的:</p>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">meta-mylayer/recipes-helloworld/helloworld-a/helloworld-a.bb
|
|
|
+meta-mylayer/recipes-helloworld/helloworld-m/helloworld-m.bb
|
|
|
+meta-mylayer/recipes-helloworld/helloworld-c/helloworld-c.bb
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li></ul></pre>
|
|
|
+<p>如果,自己做个测试将bb文件放在这个<code>meta-mylayer/recipes-helloworld/</code>目录下,再<code>bitbake</code>编译,会发现找不到对于的<code>recipe</code>。这是为啥呢?<br> 这个是由于<code>meta-mylayer/conf/layer.conf</code>配置文件中定义了bb文件搜索路径的结果,看下面:</p>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">poky<span class="token punctuation">]</span>$ <span class="token function">cat</span> meta-mylayer/conf/layer.conf
|
|
|
+<span class="token punctuation">..</span>.
|
|
|
+<span class="token comment"># We have recipes-* directories, add to BBFILES</span>
|
|
|
+BBFILES <span class="token operator">+=</span> <span class="token string">"<span class="token variable">${LAYERDIR}</span>/recipes-*/*/*.bb \
|
|
|
+ <span class="token variable">${LAYERDIR}</span>/recipes-*/*/*.bbappend"</span>
|
|
|
+<span class="token punctuation">..</span>.
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li></ul></pre>
|
|
|
+<p>即只在<code>meta-mylayer/recipes-helloworld/xxx/</code>目录下查找bb文件。</p>
|
|
|
+<h2><a name="t7"></a><a id="_520"></a>安装执行程序到文件系统中</h2>
|
|
|
+<p>我们看下这么个情况:</p>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">poky<span class="token punctuation">]</span>$ <span class="token builtin class-name">source</span> oe-init-build-env
|
|
|
+build<span class="token punctuation">]</span>$ bitbake core-image-sato -c cleansstate
|
|
|
+build<span class="token punctuation">]</span>$ bitbake core-image-sato
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li></ul></pre>
|
|
|
+<p>编译完成后,看下文件系统中是否有helloworld等程序:</p>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">build<span class="token punctuation">]</span>$ <span class="token function">ls</span> tmp-qemux86-64/work/qemux86_64-poky-linux/core-image-sato/1.0-r0/rootfs/usr/bin/helloworld*
|
|
|
+ls: cannot access <span class="token string">'tmp-qemux86-64/work/qemux86_64-poky-linux/core-image-sato/1.0-r0/rootfs/usr/bin/helloworld*'</span><span class="token builtin class-name">:</span> No such <span class="token function">file</span> or directory
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li></ul></pre>
|
|
|
+<p>没有helloworld等文件或者目录。</p>
|
|
|
+<p>这个是什么原因?poky目录下有很多的recipes,并不是所有的recipes都会编译和安装,需要将需要的recipes和我们的目标(当前是core-image-sato 或者 core-image-minimal)关联起来,怎么关联呢?</p>
|
|
|
+<h3><a name="t8"></a><a id="1_537"></a>关联的方法1</h3>
|
|
|
+<p>第一个方法就是在<code>conf/local.conf</code>文件中添加这个关联关系:</p>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">build<span class="token punctuation">]</span>$ <span class="token function">vim</span> conf/local.conf
|
|
|
+<span class="token punctuation">..</span>.
|
|
|
+IMAGE_INSTALL <span class="token operator">+=</span> <span class="token string">"helloworld-m"</span>
|
|
|
+IMAGE_INSTALL <span class="token operator">+=</span> <span class="token string">"helloworld-a"</span>
|
|
|
+IMAGE_INSTALL <span class="token operator">+=</span> <span class="token string">"helloworld-c"</span>
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li></ul></pre>
|
|
|
+<p>但是我们知道,build目录是临时的目录,这是一种临时的做法。</p>
|
|
|
+<h3><a name="t9"></a><a id="2_548"></a>关联的方法2</h3>
|
|
|
+<p>添加一个目标的<code>bbappend</code>文件,例如我们的这个目标<code>core-image-sato</code>的bb文件是:</p>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">meta/recipes-sato/images/core-image-sato.bb
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li></ul></pre>
|
|
|
+<p>我需要做的只是在自己的<code>meta-mylayer</code>中创建相应的<code>recipe</code> <code>bbappend</code>文件,如下所示:</p>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">meta-mylayer<span class="token punctuation">]</span>$ <span class="token function">mkdir</span> -p recipes-sato/images/
|
|
|
+meta-mylayer<span class="token punctuation">]</span>$ <span class="token function">vim</span> recipes-sato/images/core-image-sato.bbappend
|
|
|
+IMAGE_INSTALL <span class="token operator">+=</span> <span class="token string">"helloworld-m"</span>
|
|
|
+IMAGE_INSTALL <span class="token operator">+=</span> <span class="token string">"helloworld-a"</span>
|
|
|
+IMAGE_INSTALL <span class="token operator">+=</span> <span class="token string">"helloworld-c"</span>
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li></ul></pre>
|
|
|
+<p>同时,我们将前面<code>conf/local.conf</code>文件中添加的三个语句删除掉,然后编译演示:</p>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">poky<span class="token punctuation">]</span>$ <span class="token builtin class-name">source</span> oe-init-build-env
|
|
|
+build<span class="token punctuation">]</span>$ bitbake core-image-sato
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li></ul></pre>
|
|
|
+<p>看下编译后的文件系统中是否有这个<code>helloworld</code>等文件:</p>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">build<span class="token punctuation">]</span>$ <span class="token function">ls</span> tmp/work/qemux86_64-poky-linux/core-image-sato/1.0-r0/rootfs/usr/bin/helloworld*
|
|
|
+tmp/work/qemux86_64-poky-linux/core-image-sato/1.0-r0/rootfs/usr/bin/helloworld
|
|
|
+tmp/work/qemux86_64-poky-linux/core-image-sato/1.0-r0/rootfs/usr/bin/helloworlda
|
|
|
+tmp/work/qemux86_64-poky-linux/core-image-sato/1.0-r0/rootfs/usr/bin/helloworldc
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li></ul></pre>
|
|
|
+<p>可见是有点,下面我们运行看看效果(在<code>Ubuntu</code>桌面的终端中执行):<br> <img src="./109129587_files/20210529154705904.png" alt="在这里插入图片描述"><br> 或者这样:</p>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">build<span class="token punctuation">]</span>$ ssh-keygen -f <span class="token string">"/home/peeta/.ssh/known_hosts"</span> -R <span class="token number">192.168</span>.7.2
|
|
|
+build<span class="token punctuation">]</span>$ <span class="token function">ssh</span> root@192.168.7.2
|
|
|
+root@qemux86-64:~<span class="token comment"># helloworld</span>
|
|
|
+Hello World<span class="token operator">!</span>
|
|
|
+root@qemux86-64:~<span class="token comment"># helloworlda</span>
|
|
|
+Hello World and Autotools
|
|
|
+root@qemux86-64:~<span class="token comment"># helloworldc</span>
|
|
|
+Hello World and Cmake
|
|
|
+root@qemux86-64:~<span class="token comment"># </span>
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li></ul></pre>
|
|
|
+<p>结果展示都表明我们的<code>helloworld</code>程序都安装到文件系统中了。</p>
|
|
|
+<h2><a name="t10"></a><a id="_593"></a>构建只有源码的项目</h2>
|
|
|
+<p>这一节是后面加上的,有些项目特别特别简单,就行上面的例子一样就只单单只有一个源文件,然后还要费那么大的精力去写这些或者那些编译脚本,太麻烦了。这里将介绍如何在yocto中构建极少数源文件又不依赖编译脚本的项目来添加一个recipe。</p>
|
|
|
+<p>1.首先创建一个<code>recipe</code>目录,取名<code>helloworld-o</code>吧,这里的o表示only source file的意思哈</p>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">recipes-helloworld<span class="token punctuation">]</span>$ <span class="token function">mkdir</span> helloworld-o
|
|
|
+recipes-helloworld<span class="token punctuation">]</span>$ <span class="token builtin class-name">cd</span> helloworld-o/
|
|
|
+helloworld-o<span class="token punctuation">]</span>$ <span class="token function">mkdir</span> files
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li></ul></pre>
|
|
|
+<ol start="2"><li>复制一个源文件到该目录:</li></ol>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">helloworld-o<span class="token punctuation">]</span>$ <span class="token function">cp</span> <span class="token punctuation">..</span>/helloworld-m/helloworld/helloworld.c files/
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li></ul></pre>
|
|
|
+<ol start="3"><li>写一个bb文件:</li></ol>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">SUMMARY <span class="token operator">=</span> <span class="token string">"Simple helloworld application"</span>
|
|
|
+SECTION <span class="token operator">=</span> <span class="token string">"examples"</span>
|
|
|
+LICENSE <span class="token operator">=</span> <span class="token string">"MIT"</span>
|
|
|
+LIC_FILES_CHKSUM <span class="token operator">=</span> <span class="token string">"file://<span class="token variable">${COMMON_LICENSE_DIR}</span>/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"</span>
|
|
|
+
|
|
|
+SRC_URI <span class="token operator">=</span> <span class="token string">"file://helloworld.c"</span>
|
|
|
+
|
|
|
+S <span class="token operator">=</span> <span class="token string">"<span class="token variable">${WORKDIR}</span>"</span>
|
|
|
+
|
|
|
+B <span class="token operator">=</span> <span class="token string">"<span class="token variable">${S}</span>"</span>
|
|
|
+
|
|
|
+<span class="token function-name function">do_compile</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>
|
|
|
+ <span class="token variable">${CC}</span> <span class="token variable">${CFLAGS}</span> <span class="token variable">${LDFLAGS}</span> helloworld.c -o helloworld
|
|
|
+<span class="token punctuation">}</span>
|
|
|
+
|
|
|
+<span class="token function-name function">do_install</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>
|
|
|
+ <span class="token function">install</span> -d <span class="token variable">${D}</span><span class="token variable">${bindir}</span>
|
|
|
+ <span class="token function">install</span> -m 0755 helloworld <span class="token variable">${D}</span><span class="token variable">${bindir}</span>
|
|
|
+<span class="token punctuation">}</span>
|
|
|
+
|
|
|
+FILES_<span class="token variable">${PN}</span> <span class="token operator">=</span> <span class="token string">"<span class="token variable">${bindir}</span>"</span>
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li></ul></pre>
|
|
|
+<ol start="4"><li>bitbake编译演示,以及结果:</li></ol>
|
|
|
+<pre class="prettyprint"><code class="prism language-bash has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">build<span class="token punctuation">]</span>$ bitbake helloworld-o
|
|
|
+build<span class="token punctuation">]</span>$ <span class="token function">ls</span> tmp/work/core2-64-poky-linux/helloworld-o/1.0-r0/image/usr/bin/helloworld
|
|
|
+tmp-qemux86-64/work/core2-64-poky-linux/helloworld-o/1.0-r0/image/usr/bin/helloworld
|
|
|
+<div class="hljs-button {2}" data-title="复制(为作者贡献原力分)" data-report-click="{"spm":"1001.2101.3001.4259"}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li></ul></pre>
|
|
|
+<p>如果有任何问题,请在评论区留言。</p>
|
|
|
+<p>End ~</p>
|
|
|
+<p>更新时间2021052x</p>
|
|
|
+<p><strong><font color="red">希望帮我点个赞加关注,你的喜欢就是我持续更新的动力!</font></strong></p>
|
|
|
+ </div><div><div></div></div>
|
|
|
+ <link href="./109129587_files/markdown_views-d7a94ec6ab.css" rel="stylesheet">
|
|
|
+ <link href="./109129587_files/style-49037e4d27.css" rel="stylesheet">
|
|
|
+ </div>
|
|
|
+
|
|
|
+ </article>
|
|
|
+</div>
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ </main>
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ </div>
|
|
|
+
|
|
|
+
|
|
|
+</div>
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ </body></html>
|