2011-03-14 20:19:44 +00:00
|
|
|
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
|
2012-03-06 23:06:44 +00:00
|
|
|
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"
|
|
|
|
[<!ENTITY % poky SYSTEM "../poky.ent"> %poky; ] >
|
2011-03-14 20:19:44 +00:00
|
|
|
|
2011-03-15 23:15:49 +00:00
|
|
|
<chapter id='using-the-command-line'>
|
|
|
|
<title>Using the Command Line</title>
|
2011-09-01 16:18:33 +00:00
|
|
|
|
2011-03-14 20:19:44 +00:00
|
|
|
<para>
|
2012-12-07 23:19:36 +00:00
|
|
|
Recall that earlier the manual discussed how to use an existing toolchain
|
2013-03-01 20:22:44 +00:00
|
|
|
tarball that had been installed into the default installation
|
2013-10-25 17:37:12 +00:00
|
|
|
directory, <filename>/opt/poky/&DISTRO;</filename>, which is outside of the
|
2012-10-22 17:28:05 +00:00
|
|
|
<ulink url='&YOCTO_DOCS_DEV_URL;#build-directory'>Build Directory</ulink>
|
2012-12-07 23:19:36 +00:00
|
|
|
(see the section "<link linkend='using-an-existing-toolchain-tarball'>Using a Cross-Toolchain Tarball)</link>".
|
|
|
|
And, that sourcing your architecture-specific environment setup script
|
|
|
|
initializes a suitable cross-toolchain development environment.
|
2013-10-25 17:37:12 +00:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
During this setup, locations for the compiler, QEMU scripts, QEMU binary,
|
2012-12-07 23:19:36 +00:00
|
|
|
a special version of <filename>pkgconfig</filename> and other useful
|
2012-01-20 16:00:47 +00:00
|
|
|
utilities are added to the <filename>PATH</filename> variable.
|
2013-10-25 17:37:12 +00:00
|
|
|
Also, variables to assist
|
|
|
|
<filename>pkgconfig</filename> and <filename>autotools</filename>
|
|
|
|
are also defined so that, for example, <filename>configure.sh</filename>
|
|
|
|
can find pre-generated test results for tests that need target hardware
|
|
|
|
on which to run.
|
2011-03-14 20:19:44 +00:00
|
|
|
</para>
|
2011-03-15 23:15:49 +00:00
|
|
|
|
2013-10-25 17:37:12 +00:00
|
|
|
<para>
|
|
|
|
Collectively, these conditions allow you to easily use the toolchain
|
2014-03-14 14:56:15 +00:00
|
|
|
outside of the OpenEmbedded build environment on both Autotools-based
|
2013-10-25 17:37:12 +00:00
|
|
|
projects and Makefile-based projects.
|
|
|
|
This chapter provides information for both these types of projects.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
|
2011-03-15 23:15:49 +00:00
|
|
|
<section id='autotools-based-projects'>
|
|
|
|
<title>Autotools-Based Projects</title>
|
2011-09-01 16:18:33 +00:00
|
|
|
|
2011-03-14 20:19:44 +00:00
|
|
|
<para>
|
2012-12-07 23:19:36 +00:00
|
|
|
Once you have a suitable cross-toolchain installed, it is very easy to
|
2012-11-14 19:36:19 +00:00
|
|
|
develop a project outside of the OpenEmbedded build system.
|
2012-12-07 23:19:36 +00:00
|
|
|
This section presents a simple "Helloworld" example that shows how
|
2012-11-14 19:36:19 +00:00
|
|
|
to set up, compile, and run the project.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<section id='creating-and-running-a-project-based-on-gnu-autotools'>
|
|
|
|
<title>Creating and Running a Project Based on GNU Autotools</title>
|
|
|
|
|
|
|
|
<para>
|
2014-03-14 14:56:15 +00:00
|
|
|
Follow these steps to create a simple Autotools-based project:
|
2012-11-14 19:36:19 +00:00
|
|
|
<orderedlist>
|
|
|
|
<listitem><para><emphasis>Create your directory:</emphasis>
|
2012-12-07 23:19:36 +00:00
|
|
|
Create a clean directory for your project and then make
|
2012-11-14 19:36:19 +00:00
|
|
|
that directory your working location:
|
|
|
|
<literallayout class='monospaced'>
|
|
|
|
$ mkdir $HOME/helloworld
|
|
|
|
$ cd $HOME/helloworld
|
|
|
|
</literallayout></para></listitem>
|
|
|
|
<listitem><para><emphasis>Populate the directory:</emphasis>
|
|
|
|
Create <filename>hello.c</filename>, <filename>Makefile.am</filename>,
|
|
|
|
and <filename>configure.in</filename> files as follows:
|
|
|
|
<itemizedlist>
|
|
|
|
<listitem><para>For <filename>hello.c</filename>, include
|
|
|
|
these lines:
|
|
|
|
<literallayout class='monospaced'>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
main()
|
|
|
|
{
|
|
|
|
printf("Hello World!\n");
|
|
|
|
}
|
|
|
|
</literallayout></para></listitem>
|
|
|
|
<listitem><para>For <filename>Makefile.am</filename>,
|
|
|
|
include these lines:
|
|
|
|
<literallayout class='monospaced'>
|
|
|
|
bin_PROGRAMS = hello
|
|
|
|
hello_SOURCES = hello.c
|
|
|
|
</literallayout></para></listitem>
|
|
|
|
<listitem><para>For <filename>configure.in</filename>,
|
|
|
|
include these lines:
|
|
|
|
<literallayout class='monospaced'>
|
|
|
|
AC_INIT(hello.c)
|
|
|
|
AM_INIT_AUTOMAKE(hello,0.1)
|
|
|
|
AC_PROG_CC
|
|
|
|
AC_PROG_INSTALL
|
|
|
|
AC_OUTPUT(Makefile)
|
|
|
|
</literallayout></para></listitem>
|
|
|
|
</itemizedlist></para></listitem>
|
2012-12-07 23:19:36 +00:00
|
|
|
<listitem><para><emphasis>Source the cross-toolchain
|
2012-11-14 19:36:19 +00:00
|
|
|
environment setup file:</emphasis>
|
|
|
|
Installation of the cross-toolchain creates a cross-toolchain
|
2013-03-01 20:22:44 +00:00
|
|
|
environment setup script in the directory that the ADT
|
|
|
|
was installed.
|
2012-12-07 23:19:36 +00:00
|
|
|
Before you can use the tools to develop your project, you must
|
2012-11-14 19:36:19 +00:00
|
|
|
source this setup script.
|
|
|
|
The script begins with the string "environment-setup" and contains
|
2012-12-07 23:19:36 +00:00
|
|
|
the machine architecture, which is followed by the string
|
2012-11-14 19:36:19 +00:00
|
|
|
"poky-linux".
|
2013-03-01 20:22:44 +00:00
|
|
|
Here is an example that sources a script from the
|
|
|
|
default ADT installation directory that uses the
|
2012-12-07 23:19:36 +00:00
|
|
|
32-bit Intel x86 Architecture and using the
|
2012-11-14 19:36:19 +00:00
|
|
|
&DISTRO_NAME; Yocto Project release:
|
|
|
|
<literallayout class='monospaced'>
|
|
|
|
$ source /opt/poky/&DISTRO;/environment-setup-i586-poky-linux
|
|
|
|
</literallayout></para></listitem>
|
2013-04-17 00:32:02 +00:00
|
|
|
<listitem><para><emphasis>Generate the local aclocal.m4
|
2012-11-14 19:36:19 +00:00
|
|
|
files and create the configure script:</emphasis>
|
2012-12-07 23:19:36 +00:00
|
|
|
The following GNU Autotools generate the local
|
|
|
|
<filename>aclocal.m4</filename> files and create the
|
2012-11-14 19:36:19 +00:00
|
|
|
configure script:
|
|
|
|
<literallayout class='monospaced'>
|
|
|
|
$ aclocal
|
|
|
|
$ autoconf
|
|
|
|
</literallayout></para></listitem>
|
|
|
|
<listitem><para><emphasis>Generate files needed by GNU
|
|
|
|
coding standards:</emphasis>
|
2012-12-07 23:19:36 +00:00
|
|
|
GNU coding standards require certain files in order for the
|
|
|
|
project to be compliant.
|
2012-11-14 19:36:19 +00:00
|
|
|
This command creates those files:
|
|
|
|
<literallayout class='monospaced'>
|
2012-11-15 17:45:18 +00:00
|
|
|
$ touch NEWS README AUTHORS ChangeLog
|
2012-11-14 19:36:19 +00:00
|
|
|
</literallayout></para></listitem>
|
2013-04-17 00:32:02 +00:00
|
|
|
<listitem><para><emphasis>Generate the configure
|
2012-11-14 19:36:19 +00:00
|
|
|
file:</emphasis>
|
|
|
|
This command generates the <filename>configure</filename>:
|
|
|
|
<literallayout class='monospaced'>
|
|
|
|
$ automake -a
|
|
|
|
</literallayout></para></listitem>
|
|
|
|
<listitem><para><emphasis>Cross-compile the project:</emphasis>
|
|
|
|
This command compiles the project using the cross-compiler:
|
|
|
|
<literallayout class='monospaced'>
|
|
|
|
$ ./configure ${CONFIGURE_FLAGS}
|
|
|
|
</literallayout></para></listitem>
|
|
|
|
<listitem><para><emphasis>Make and install the project:</emphasis>
|
2012-12-07 23:19:36 +00:00
|
|
|
These two commands generate and install the project into the
|
2012-11-14 19:36:19 +00:00
|
|
|
destination directory:
|
|
|
|
<literallayout class='monospaced'>
|
|
|
|
$ make
|
|
|
|
$ make install DESTDIR=./tmp
|
|
|
|
</literallayout></para></listitem>
|
|
|
|
<listitem><para><emphasis>Verify the installation:</emphasis>
|
|
|
|
This command is a simple way to verify the installation
|
2012-12-07 23:19:36 +00:00
|
|
|
of your project.
|
|
|
|
Running the command prints the architecture on which
|
2012-11-14 19:36:19 +00:00
|
|
|
the binary file can run.
|
2012-12-07 23:19:36 +00:00
|
|
|
This architecture should be the same architecture that
|
2012-11-14 19:36:19 +00:00
|
|
|
the installed cross-toolchain supports.
|
|
|
|
<literallayout class='monospaced'>
|
|
|
|
$ file ./tmp/usr/local/bin/hello
|
|
|
|
</literallayout></para></listitem>
|
|
|
|
<listitem><para><emphasis>Execute your project:</emphasis>
|
2012-12-07 23:19:36 +00:00
|
|
|
To execute the project in the shell, simply enter the name.
|
2012-11-14 19:36:19 +00:00
|
|
|
You could also copy the binary to the actual target hardware
|
|
|
|
and run the project there as well:
|
|
|
|
<literallayout class='monospaced'>
|
|
|
|
$ ./hello
|
|
|
|
</literallayout>
|
|
|
|
As expected, the project displays the "Hello World!" message.
|
|
|
|
</para></listitem>
|
|
|
|
</orderedlist>
|
|
|
|
</para>
|
|
|
|
</section>
|
|
|
|
|
|
|
|
<section id='passing-host-options'>
|
|
|
|
<title>Passing Host Options</title>
|
|
|
|
|
|
|
|
<para>
|
2012-12-07 23:19:36 +00:00
|
|
|
For an Autotools-based project, you can use the cross-toolchain by just
|
2012-11-14 19:36:19 +00:00
|
|
|
passing the appropriate host option to <filename>configure.sh</filename>.
|
2012-12-07 23:19:36 +00:00
|
|
|
The host option you use is derived from the name of the environment setup
|
2013-03-01 20:22:44 +00:00
|
|
|
script found in the directory in which you installed the cross-toolchain.
|
2012-12-07 23:19:36 +00:00
|
|
|
For example, the host option for an ARM-based target that uses the GNU EABI
|
2012-11-14 19:36:19 +00:00
|
|
|
is <filename>armv5te-poky-linux-gnueabi</filename>.
|
2012-12-07 23:19:36 +00:00
|
|
|
You will notice that the name of the script is
|
2012-11-14 19:36:19 +00:00
|
|
|
<filename>environment-setup-armv5te-poky-linux-gnueabi</filename>.
|
|
|
|
Thus, the following command works:
|
|
|
|
<literallayout class='monospaced'>
|
2012-11-14 19:48:42 +00:00
|
|
|
$ ./configure --host=armv5te-poky-linux-gnueabi \
|
2014-10-16 23:53:39 +00:00
|
|
|
--with-libtool-sysroot=<replaceable>sysroot-dir</replaceable>
|
2012-11-14 19:36:19 +00:00
|
|
|
</literallayout>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2012-12-07 23:19:36 +00:00
|
|
|
This single command updates your project and rebuilds it using the appropriate
|
2012-11-14 19:36:19 +00:00
|
|
|
cross-toolchain tools.
|
|
|
|
<note>
|
2014-03-14 15:02:43 +00:00
|
|
|
If the <filename>configure</filename> script results in problems recognizing the
|
2014-10-16 23:53:39 +00:00
|
|
|
<filename>--with-libtool-sysroot=</filename><replaceable>sysroot-dir</replaceable> option,
|
2012-12-07 23:19:36 +00:00
|
|
|
regenerate the script to enable the support by doing the following and then
|
2013-10-25 17:37:12 +00:00
|
|
|
run the script again:
|
2012-11-14 19:36:19 +00:00
|
|
|
<literallayout class='monospaced'>
|
2011-09-23 15:49:20 +00:00
|
|
|
$ libtoolize --automake
|
|
|
|
$ aclocal -I ${OECORE_NATIVE_SYSROOT}/usr/share/aclocal \
|
2014-10-16 23:53:39 +00:00
|
|
|
[-I <replaceable>dir_containing_your_project-specific_m4_macros</replaceable>]
|
2011-09-23 15:49:20 +00:00
|
|
|
$ autoconf
|
|
|
|
$ autoheader
|
|
|
|
$ automake -a
|
2012-11-14 19:36:19 +00:00
|
|
|
</literallayout>
|
2012-12-07 23:19:36 +00:00
|
|
|
</note>
|
2012-11-14 19:36:19 +00:00
|
|
|
</para>
|
2012-12-07 23:19:36 +00:00
|
|
|
</section>
|
2011-03-14 20:19:44 +00:00
|
|
|
</section>
|
|
|
|
|
2011-03-15 23:15:49 +00:00
|
|
|
<section id='makefile-based-projects'>
|
|
|
|
<title>Makefile-Based Projects</title>
|
2011-09-01 16:18:33 +00:00
|
|
|
|
2011-03-15 23:15:49 +00:00
|
|
|
<para>
|
2012-12-07 23:19:36 +00:00
|
|
|
For a Makefile-based project, you use the cross-toolchain by making sure
|
|
|
|
the tools are used.
|
2011-03-15 23:15:49 +00:00
|
|
|
You can do this as follows:
|
|
|
|
<literallayout class='monospaced'>
|
|
|
|
CC=arm-poky-linux-gnueabi-gcc
|
|
|
|
LD=arm-poky-linux-gnueabi-ld
|
2011-08-16 13:41:32 +00:00
|
|
|
CFLAGS=”${CFLAGS} --sysroot=<sysroot-dir>”
|
|
|
|
CXXFLAGS=”${CXXFLAGS} --sysroot=<sysroot-dir>”
|
2011-03-15 23:15:49 +00:00
|
|
|
</literallayout>
|
|
|
|
</para>
|
|
|
|
</section>
|
2011-03-14 20:19:44 +00:00
|
|
|
|
|
|
|
</chapter>
|
|
|
|
<!--
|
|
|
|
vim: expandtab tw=80 ts=4
|
|
|
|
-->
|