adt-command.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
  2. "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"
  3. [<!ENTITY % poky SYSTEM "../poky.ent"> %poky; ] >
  4. <chapter id='using-the-command-line'>
  5. <title>Using the Command Line</title>
  6. <para>
  7. Recall that earlier the manual discussed how to use an existing toolchain
  8. tarball that had been installed into the default installation
  9. directory, <filename>/opt/poky/&DISTRO;</filename>, which is outside of the
  10. <ulink url='&YOCTO_DOCS_DEV_URL;#build-directory'>Build Directory</ulink>
  11. (see the section "<link linkend='using-an-existing-toolchain-tarball'>Using a Cross-Toolchain Tarball)</link>".
  12. And, that sourcing your architecture-specific environment setup script
  13. initializes a suitable cross-toolchain development environment.
  14. </para>
  15. <para>
  16. During this setup, locations for the compiler, QEMU scripts, QEMU binary,
  17. a special version of <filename>pkgconfig</filename> and other useful
  18. utilities are added to the <filename>PATH</filename> variable.
  19. Also, variables to assist
  20. <filename>pkgconfig</filename> and <filename>autotools</filename>
  21. are also defined so that, for example, <filename>configure.sh</filename>
  22. can find pre-generated test results for tests that need target hardware
  23. on which to run.
  24. You can see the
  25. "<link linkend='setting-up-the-cross-development-environment'>Setting Up the Cross-Development Environment</link>"
  26. section for the list of cross-toolchain environment variables
  27. established by the script.
  28. </para>
  29. <para>
  30. Collectively, these conditions allow you to easily use the toolchain
  31. outside of the OpenEmbedded build environment on both Autotools-based
  32. projects and Makefile-based projects.
  33. This chapter provides information for both these types of projects.
  34. </para>
  35. <section id='autotools-based-projects'>
  36. <title>Autotools-Based Projects</title>
  37. <para>
  38. Once you have a suitable cross-toolchain installed, it is very easy to
  39. develop a project outside of the OpenEmbedded build system.
  40. This section presents a simple "Helloworld" example that shows how
  41. to set up, compile, and run the project.
  42. </para>
  43. <section id='creating-and-running-a-project-based-on-gnu-autotools'>
  44. <title>Creating and Running a Project Based on GNU Autotools</title>
  45. <para>
  46. Follow these steps to create a simple Autotools-based project:
  47. <orderedlist>
  48. <listitem><para><emphasis>Create your directory:</emphasis>
  49. Create a clean directory for your project and then make
  50. that directory your working location:
  51. <literallayout class='monospaced'>
  52. $ mkdir $HOME/helloworld
  53. $ cd $HOME/helloworld
  54. </literallayout></para></listitem>
  55. <listitem><para><emphasis>Populate the directory:</emphasis>
  56. Create <filename>hello.c</filename>, <filename>Makefile.am</filename>,
  57. and <filename>configure.in</filename> files as follows:
  58. <itemizedlist>
  59. <listitem><para>For <filename>hello.c</filename>, include
  60. these lines:
  61. <literallayout class='monospaced'>
  62. #include &lt;stdio.h&gt;
  63. main()
  64. {
  65. printf("Hello World!\n");
  66. }
  67. </literallayout></para></listitem>
  68. <listitem><para>For <filename>Makefile.am</filename>,
  69. include these lines:
  70. <literallayout class='monospaced'>
  71. bin_PROGRAMS = hello
  72. hello_SOURCES = hello.c
  73. </literallayout></para></listitem>
  74. <listitem><para>For <filename>configure.in</filename>,
  75. include these lines:
  76. <literallayout class='monospaced'>
  77. AC_INIT(hello.c)
  78. AM_INIT_AUTOMAKE(hello,0.1)
  79. AC_PROG_CC
  80. AC_PROG_INSTALL
  81. AC_OUTPUT(Makefile)
  82. </literallayout></para></listitem>
  83. </itemizedlist></para></listitem>
  84. <listitem><para><emphasis>Source the cross-toolchain
  85. environment setup file:</emphasis>
  86. Installation of the cross-toolchain creates a cross-toolchain
  87. environment setup script in the directory that the ADT
  88. was installed.
  89. Before you can use the tools to develop your project, you must
  90. source this setup script.
  91. The script begins with the string "environment-setup" and contains
  92. the machine architecture, which is followed by the string
  93. "poky-linux".
  94. Here is an example that sources a script from the
  95. default ADT installation directory that uses the
  96. 32-bit Intel x86 Architecture and the
  97. &DISTRO_NAME; Yocto Project release:
  98. <literallayout class='monospaced'>
  99. $ source /opt/poky/&DISTRO;/environment-setup-i586-poky-linux
  100. </literallayout></para></listitem>
  101. <listitem><para><emphasis>Generate the local aclocal.m4
  102. files and create the configure script:</emphasis>
  103. The following GNU Autotools generate the local
  104. <filename>aclocal.m4</filename> files and create the
  105. configure script:
  106. <literallayout class='monospaced'>
  107. $ aclocal
  108. $ autoconf
  109. </literallayout></para></listitem>
  110. <listitem><para><emphasis>Generate files needed by GNU
  111. coding standards:</emphasis>
  112. GNU coding standards require certain files in order for the
  113. project to be compliant.
  114. This command creates those files:
  115. <literallayout class='monospaced'>
  116. $ touch NEWS README AUTHORS ChangeLog
  117. </literallayout></para></listitem>
  118. <listitem><para><emphasis>Generate the configure
  119. file:</emphasis>
  120. This command generates the <filename>configure</filename>:
  121. <literallayout class='monospaced'>
  122. $ automake -a
  123. </literallayout></para></listitem>
  124. <listitem><para><emphasis>Cross-compile the project:</emphasis>
  125. This command compiles the project using the cross-compiler.
  126. The
  127. <ulink url='&YOCTO_DOCS_REF_URL;#var-CONFIGURE_FLAGS'><filename>CONFIGURE_FLAGS</filename></ulink>
  128. environment variable provides the minimal arguments for
  129. GNU configure:
  130. <literallayout class='monospaced'>
  131. $ ./configure ${CONFIGURE_FLAGS}
  132. </literallayout></para></listitem>
  133. <listitem><para><emphasis>Make and install the project:</emphasis>
  134. These two commands generate and install the project into the
  135. destination directory:
  136. <literallayout class='monospaced'>
  137. $ make
  138. $ make install DESTDIR=./tmp
  139. </literallayout></para></listitem>
  140. <listitem><para><emphasis>Verify the installation:</emphasis>
  141. This command is a simple way to verify the installation
  142. of your project.
  143. Running the command prints the architecture on which
  144. the binary file can run.
  145. This architecture should be the same architecture that
  146. the installed cross-toolchain supports.
  147. <literallayout class='monospaced'>
  148. $ file ./tmp/usr/local/bin/hello
  149. </literallayout></para></listitem>
  150. <listitem><para><emphasis>Execute your project:</emphasis>
  151. To execute the project in the shell, simply enter the name.
  152. You could also copy the binary to the actual target hardware
  153. and run the project there as well:
  154. <literallayout class='monospaced'>
  155. $ ./hello
  156. </literallayout>
  157. As expected, the project displays the "Hello World!" message.
  158. </para></listitem>
  159. </orderedlist>
  160. </para>
  161. </section>
  162. <section id='passing-host-options'>
  163. <title>Passing Host Options</title>
  164. <para>
  165. For an Autotools-based project, you can use the cross-toolchain by just
  166. passing the appropriate host option to <filename>configure.sh</filename>.
  167. The host option you use is derived from the name of the environment setup
  168. script found in the directory in which you installed the cross-toolchain.
  169. For example, the host option for an ARM-based target that uses the GNU EABI
  170. is <filename>armv5te-poky-linux-gnueabi</filename>.
  171. You will notice that the name of the script is
  172. <filename>environment-setup-armv5te-poky-linux-gnueabi</filename>.
  173. Thus, the following command works to update your project and
  174. rebuild it using the appropriate cross-toolchain tools:
  175. <literallayout class='monospaced'>
  176. $ ./configure --host=armv5te-poky-linux-gnueabi \
  177. --with-libtool-sysroot=<replaceable>sysroot_dir</replaceable>
  178. </literallayout>
  179. <note>
  180. If the <filename>configure</filename> script results in problems recognizing the
  181. <filename>--with-libtool-sysroot=</filename><replaceable>sysroot-dir</replaceable> option,
  182. regenerate the script to enable the support by doing the following and then
  183. run the script again:
  184. <literallayout class='monospaced'>
  185. $ libtoolize --automake
  186. $ aclocal -I ${OECORE_NATIVE_SYSROOT}/usr/share/aclocal \
  187. [-I <replaceable>dir_containing_your_project-specific_m4_macros</replaceable>]
  188. $ autoconf
  189. $ autoheader
  190. $ automake -a
  191. </literallayout>
  192. </note>
  193. </para>
  194. </section>
  195. </section>
  196. <section id='makefile-based-projects'>
  197. <title>Makefile-Based Projects</title>
  198. <para>
  199. For Makefile-based projects, the cross-toolchain environment variables
  200. established by running the cross-toolchain environment setup script
  201. are subject to general <filename>make</filename> rules.
  202. </para>
  203. <para>
  204. To illustrate this, consider the following four cross-toolchain
  205. environment variables:
  206. <literallayout class='monospaced'>
  207. <ulink url='&YOCTO_DOCS_REF_URL;#var-CC'>CC</ulink>=i586-poky-linux-gcc -m32 -march=i586 --sysroot=/opt/poky/1.8/sysroots/i586-poky-linux
  208. <ulink url='&YOCTO_DOCS_REF_URL;#var-LD'>LD</ulink>=i586-poky-linux-ld --sysroot=/opt/poky/1.8/sysroots/i586-poky-linux
  209. <ulink url='&YOCTO_DOCS_REF_URL;#var-CFLAGS'>CFLAGS</ulink>=-O2 -pipe -g -feliminate-unused-debug-types
  210. <ulink url='&YOCTO_DOCS_REF_URL;#var-CXXFLAGS'>CXXFLAGS</ulink>=-O2 -pipe -g -feliminate-unused-debug-types
  211. </literallayout>
  212. Now, consider the following three cases:
  213. <itemizedlist>
  214. <listitem><para><emphasis>Case 1 - No Variables Set in the <filename>Makefile</filename>:</emphasis>
  215. Because these variables are not specifically set in the
  216. <filename>Makefile</filename>, the variables retain their
  217. values based on the environment.
  218. </para></listitem>
  219. <listitem><para><emphasis>Case 2 - Variables Set in the <filename>Makefile</filename>:</emphasis>
  220. Specifically setting variables in the
  221. <filename>Makefile</filename> during the build results in the
  222. environment settings of the variables being overwritten.
  223. </para></listitem>
  224. <listitem><para><emphasis>Case 3 - Variables Set when the <filename>Makefile</filename> is Executed from the Command Line:</emphasis>
  225. Executing the <filename>Makefile</filename> from the command
  226. line results in the variables being overwritten with
  227. command-line content regardless of what is being set in the
  228. <filename>Makefile</filename>.
  229. In this case, environment variables are not considered unless
  230. you use the "-e" flag during the build:
  231. <literallayout class='monospaced'>
  232. $ make -e <replaceable>file</replaceable>
  233. </literallayout>
  234. If you use this flag, then the environment values of the
  235. variables override any variables specifically set in the
  236. <filename>Makefile</filename>.
  237. </para></listitem>
  238. </itemizedlist>
  239. <note>
  240. For the list of variables set up by the cross-toolchain environment
  241. setup script, see the
  242. "<link linkend='setting-up-the-cross-development-environment'>Setting Up the Cross-Development Environment</link>"
  243. section.
  244. </note>
  245. </para>
  246. </section>
  247. </chapter>
  248. <!--
  249. vim: expandtab tw=80 ts=4
  250. -->