mirror of
https://git.yoctoproject.org/poky
synced 2026-06-02 13:29:49 +00:00
sdk-manual: Updated the Autotools workflow example.
Did a re-write of this section with better explanations. I also pulled the bit about passing parameters to the configure script into the step that talks about that. (From yocto-docs rev: 778e566100450cce15808f80ace2b92f811001a7) Signed-off-by: Scott Rifenbark <srifenbark@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
committed by
Richard Purdie
parent
21a4304581
commit
98423875ef
@@ -21,202 +21,204 @@
|
|||||||
<para>
|
<para>
|
||||||
Once you have a suitable
|
Once you have a suitable
|
||||||
<ulink url='&YOCTO_DOCS_REF_URL;#cross-development-toolchain'>cross-development toolchain</ulink>
|
<ulink url='&YOCTO_DOCS_REF_URL;#cross-development-toolchain'>cross-development toolchain</ulink>
|
||||||
installed, it is very easy to develop a project outside of the
|
installed, it is very easy to develop a project using the
|
||||||
|
<ulink url='https://en.wikipedia.org/wiki/GNU_Build_System'>GNU Autotools-based</ulink>
|
||||||
|
workflow, which is outside of the
|
||||||
<ulink url='&YOCTO_DOCS_REF_URL;#build-system-term'>OpenEmbedded build system</ulink>.
|
<ulink url='&YOCTO_DOCS_REF_URL;#build-system-term'>OpenEmbedded build system</ulink>.
|
||||||
This section presents a simple "Helloworld" example that shows how
|
|
||||||
to set up, compile, and run the project.
|
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<section id='creating-and-running-a-project-based-on-gnu-autotools'>
|
<para>
|
||||||
<title>Creating and Running a Project Based on GNU Autotools</title>
|
The following figure presents a simple Autotools workflow.
|
||||||
|
<imagedata fileref="figures/sdk-autotools-flow.png" width="7in" height="8in" align="center" />
|
||||||
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
Follow these steps to create a simple
|
Follow these steps to create a simple Autotools-based
|
||||||
<ulink url='https://en.wikipedia.org/wiki/GNU_Build_System'>GNU Autotools-based</ulink>
|
"Hello World" project:
|
||||||
project:
|
<note>
|
||||||
<orderedlist>
|
For more information on the GNU Autotools workflow,
|
||||||
<listitem><para>
|
see the same example on the
|
||||||
<emphasis>Create Your Directory:</emphasis>
|
<ulink url='https://developer.gnome.org/anjuta-build-tutorial/stable/create-autotools.html.en'>GNOME Developer</ulink>
|
||||||
Create a clean directory for your project and then make
|
site.
|
||||||
that directory your working location:
|
</note>
|
||||||
<literallayout class='monospaced'>
|
<orderedlist>
|
||||||
|
<listitem><para>
|
||||||
|
<emphasis>Create a Working Directory and Populate It:</emphasis>
|
||||||
|
Create a clean directory for your project and then make
|
||||||
|
that directory your working location.
|
||||||
|
<literallayout class='monospaced'>
|
||||||
$ mkdir $HOME/helloworld
|
$ mkdir $HOME/helloworld
|
||||||
$ cd $HOME/helloworld
|
$ cd $HOME/helloworld
|
||||||
</literallayout>
|
</literallayout>
|
||||||
</para></listitem>
|
After setting up the directory, populate it with three
|
||||||
<listitem><para>
|
simple files needed for the flow.
|
||||||
<emphasis>Populate the Directory:</emphasis>
|
You need a project source file, a file to help with
|
||||||
Create <filename>hello.c</filename>,
|
configuration, and a file to help create the Makefile:
|
||||||
<filename>Makefile.am</filename>,
|
<filename>hello.c</filename>,
|
||||||
and <filename>configure.ac</filename> files as follows:
|
<filename>configure.ac</filename>, and
|
||||||
<itemizedlist>
|
<filename>Makefile.am</filename>, respectively:
|
||||||
<listitem><para>
|
<itemizedlist>
|
||||||
For <filename>hello.c</filename>, include
|
<listitem><para>
|
||||||
these lines:
|
<emphasis><filename>hello.c</filename>:</emphasis>
|
||||||
<literallayout class='monospaced'>
|
<literallayout class='monospaced'>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
printf("Hello World!\n");
|
printf("Hello World!\n");
|
||||||
}
|
}
|
||||||
</literallayout>
|
</literallayout>
|
||||||
</para></listitem>
|
</para></listitem>
|
||||||
<listitem><para>
|
<listitem><para>
|
||||||
For <filename>Makefile.am</filename>,
|
<emphasis><filename>configure.ac</filename>:</emphasis>
|
||||||
include these lines:
|
<literallayout class='monospaced'>
|
||||||
<literallayout class='monospaced'>
|
|
||||||
bin_PROGRAMS = hello
|
|
||||||
hello_SOURCES = hello.c
|
|
||||||
</literallayout>
|
|
||||||
</para></listitem>
|
|
||||||
<listitem><para>
|
|
||||||
For <filename>configure.ac</filename>,
|
|
||||||
include these lines:
|
|
||||||
<literallayout class='monospaced'>
|
|
||||||
AC_INIT(hello,0.1)
|
AC_INIT(hello,0.1)
|
||||||
AM_INIT_AUTOMAKE([foreign])
|
AM_INIT_AUTOMAKE([foreign])
|
||||||
AC_PROG_CC
|
AC_PROG_CC
|
||||||
AC_CONFIG_FILES(Makefile)
|
AC_CONFIG_FILES(Makefile)
|
||||||
AC_OUTPUT
|
AC_OUTPUT
|
||||||
</literallayout>
|
</literallayout>
|
||||||
</para></listitem>
|
</para></listitem>
|
||||||
</itemizedlist>
|
<listitem><para>
|
||||||
</para></listitem>
|
<emphasis><filename>Makefile.am</filename>:</emphasis>
|
||||||
<listitem><para>
|
<literallayout class='monospaced'>
|
||||||
<emphasis>Source the Cross-Toolchain
|
bin_PROGRAMS = hello
|
||||||
Environment Setup File:</emphasis>
|
hello_SOURCES = hello.c
|
||||||
As described earlier in the manual, installing the
|
</literallayout>
|
||||||
cross-toolchain creates a cross-toolchain
|
</para></listitem>
|
||||||
environment setup script in the directory that the SDK
|
</itemizedlist>
|
||||||
was installed.
|
</para></listitem>
|
||||||
Before you can use the tools to develop your project,
|
<listitem><para>
|
||||||
you must source this setup script.
|
<emphasis>Source the Cross-Toolchain
|
||||||
The script begins with the string "environment-setup"
|
Environment Setup File:</emphasis>
|
||||||
and contains the machine architecture, which is
|
As described earlier in the manual, installing the
|
||||||
followed by the string "poky-linux".
|
cross-toolchain creates a cross-toolchain
|
||||||
Here is an example that sources a script from the
|
environment setup script in the directory that the SDK
|
||||||
default SDK installation directory that uses the
|
was installed.
|
||||||
32-bit Intel x86 Architecture and the
|
Before you can use the tools to develop your project,
|
||||||
&DISTRO_NAME; Yocto Project release:
|
you must source this setup script.
|
||||||
<literallayout class='monospaced'>
|
The script begins with the string "environment-setup"
|
||||||
|
and contains the machine architecture, which is
|
||||||
|
followed by the string "poky-linux".
|
||||||
|
For this example, the command sources a script from the
|
||||||
|
default SDK installation directory that uses the
|
||||||
|
32-bit Intel x86 Architecture and the
|
||||||
|
&DISTRO_NAME; Yocto Project release:
|
||||||
|
<literallayout class='monospaced'>
|
||||||
$ source /opt/poky/&DISTRO;/environment-setup-i586-poky-linux
|
$ source /opt/poky/&DISTRO;/environment-setup-i586-poky-linux
|
||||||
</literallayout>
|
</literallayout>
|
||||||
</para></listitem>
|
</para></listitem>
|
||||||
<listitem><para>
|
<listitem><para>
|
||||||
<emphasis>Generate the Local <filename>aclocal.m4</filename>
|
<emphasis>Generate the Local <filename>aclocal.m4</filename> Files:</emphasis>
|
||||||
Files and Create the <filename>configure</filename> Script:</emphasis>
|
The following command generates the local
|
||||||
The following GNU Autotools generate the local
|
<filename>aclocal.m4</filename> files, which are used
|
||||||
<filename>aclocal.m4</filename> files and create the
|
later with the <filename>autoconf</filename> command:
|
||||||
<filename>configure</filename> script:
|
<literallayout class='monospaced'>
|
||||||
<literallayout class='monospaced'>
|
|
||||||
$ aclocal
|
$ aclocal
|
||||||
|
</literallayout>
|
||||||
|
</para></listitem>
|
||||||
|
<listitem><para>
|
||||||
|
<emphasis>Create the <filename>configure</filename> Script:</emphasis>
|
||||||
|
The following command creates the
|
||||||
|
<filename>configure</filename> script:
|
||||||
|
<literallayout class='monospaced'>
|
||||||
$ autoconf
|
$ autoconf
|
||||||
</literallayout>
|
</literallayout>
|
||||||
</para></listitem>
|
</para></listitem>
|
||||||
<listitem><para>
|
<listitem><para>
|
||||||
<emphasis>Generate Files Needed by GNU Coding
|
<emphasis>Generate Files Needed by GNU Coding
|
||||||
Standards:</emphasis>
|
Standards:</emphasis>
|
||||||
GNU coding standards require certain files in order
|
GNU coding standards require certain files in order
|
||||||
for the project to be compliant.
|
for the project to be compliant.
|
||||||
This command creates those files:
|
This command creates those files:
|
||||||
<literallayout class='monospaced'>
|
<literallayout class='monospaced'>
|
||||||
$ touch NEWS README AUTHORS ChangeLog
|
$ touch NEWS README AUTHORS ChangeLog
|
||||||
</literallayout>
|
</literallayout>
|
||||||
</para></listitem>
|
</para></listitem>
|
||||||
<listitem><para>
|
<listitem><para>
|
||||||
<emphasis>Generate the Configure File:</emphasis>
|
<emphasis>Generate the <filename>Makefile.in</filename> File:</emphasis>
|
||||||
This command generates the
|
This command generates the
|
||||||
<filename>configure</filename>:
|
<filename>Makefile.in</filename>, which is used later
|
||||||
<literallayout class='monospaced'>
|
during cross-compilation:
|
||||||
|
<literallayout class='monospaced'>
|
||||||
$ automake -a
|
$ automake -a
|
||||||
</literallayout>
|
</literallayout>
|
||||||
</para></listitem>
|
</para></listitem>
|
||||||
<listitem><para>
|
<listitem><para>
|
||||||
<emphasis>Cross-Compile the Project:</emphasis>
|
<emphasis>Cross-Compile the Project:</emphasis>
|
||||||
This command compiles the project using the
|
This command compiles the project using the
|
||||||
cross-compiler.
|
cross-compiler.
|
||||||
The
|
The
|
||||||
<ulink url='&YOCTO_DOCS_REF_URL;#var-CONFIGURE_FLAGS'><filename>CONFIGURE_FLAGS</filename></ulink>
|
<ulink url='&YOCTO_DOCS_REF_URL;#var-CONFIGURE_FLAGS'><filename>CONFIGURE_FLAGS</filename></ulink>
|
||||||
environment variable provides the minimal arguments for
|
environment variable provides the minimal arguments for
|
||||||
GNU configure:
|
GNU configure:
|
||||||
<literallayout class='monospaced'>
|
<literallayout class='monospaced'>
|
||||||
$ ./configure ${CONFIGURE_FLAGS}
|
$ ./configure ${CONFIGURE_FLAGS}
|
||||||
</literallayout>
|
</literallayout>
|
||||||
</para></listitem>
|
For an Autotools-based project, you can use the
|
||||||
<listitem><para>
|
cross-toolchain by just passing the appropriate host
|
||||||
<emphasis>Make and Install the Project:</emphasis>
|
option to <filename>configure.sh</filename>.
|
||||||
These two commands generate and install the project
|
The host option you use is derived from the name of the
|
||||||
into the destination directory:
|
environment setup script found in the directory in which you
|
||||||
<literallayout class='monospaced'>
|
installed the cross-toolchain.
|
||||||
$ make
|
For example, the host option for an ARM-based target that uses
|
||||||
$ make install DESTDIR=./tmp
|
the GNU EABI is
|
||||||
</literallayout>
|
<filename>armv5te-poky-linux-gnueabi</filename>.
|
||||||
</para></listitem>
|
You will notice that the name of the script is
|
||||||
<listitem><para>
|
<filename>environment-setup-armv5te-poky-linux-gnueabi</filename>.
|
||||||
<emphasis>Verify the Installation:</emphasis>
|
Thus, the following command works to update your project
|
||||||
This command is a simple way to verify the installation
|
and rebuild it using the appropriate cross-toolchain tools:
|
||||||
of your project.
|
<literallayout class='monospaced'>
|
||||||
Running the command prints the architecture on which
|
|
||||||
the binary file can run.
|
|
||||||
This architecture should be the same architecture that
|
|
||||||
the installed cross-toolchain supports.
|
|
||||||
<literallayout class='monospaced'>
|
|
||||||
$ file ./tmp/usr/local/bin/hello
|
|
||||||
</literallayout>
|
|
||||||
</para></listitem>
|
|
||||||
<listitem><para>
|
|
||||||
<emphasis>Execute Your Project:</emphasis>
|
|
||||||
To execute the project in the shell, simply enter
|
|
||||||
the name.
|
|
||||||
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>
|
|
||||||
For an Autotools-based project, you can use the cross-toolchain
|
|
||||||
by just passing the appropriate host option to
|
|
||||||
<filename>configure.sh</filename>.
|
|
||||||
The host option you use is derived from the name of the
|
|
||||||
environment setup script found in the directory in which you
|
|
||||||
installed the cross-toolchain.
|
|
||||||
For example, the host option for an ARM-based target that uses
|
|
||||||
the GNU EABI is <filename>armv5te-poky-linux-gnueabi</filename>.
|
|
||||||
You will notice that the name of the script is
|
|
||||||
<filename>environment-setup-armv5te-poky-linux-gnueabi</filename>.
|
|
||||||
Thus, the following command works to update your project and
|
|
||||||
rebuild it using the appropriate cross-toolchain tools:
|
|
||||||
<literallayout class='monospaced'>
|
|
||||||
$ ./configure --host=armv5te-poky-linux-gnueabi \
|
$ ./configure --host=armv5te-poky-linux-gnueabi \
|
||||||
--with-libtool-sysroot=<replaceable>sysroot_dir</replaceable>
|
--with-libtool-sysroot=<replaceable>sysroot_dir</replaceable>
|
||||||
</literallayout>
|
</literallayout>
|
||||||
<note>
|
<note>
|
||||||
If the <filename>configure</filename> script results in
|
If the <filename>configure</filename> script results in
|
||||||
problems recognizing the
|
problems recognizing the
|
||||||
<filename>--with-libtool-sysroot=</filename><replaceable>sysroot-dir</replaceable>
|
<filename>--with-libtool-sysroot=</filename><replaceable>sysroot-dir</replaceable>
|
||||||
option, regenerate the script to enable the support by
|
option, regenerate the script to enable the support by
|
||||||
doing the following and then run the script again:
|
doing the following and then run the script again:
|
||||||
<literallayout class='monospaced'>
|
<literallayout class='monospaced'>
|
||||||
$ libtoolize --automake
|
$ libtoolize --automake
|
||||||
$ aclocal -I ${OECORE_TARGET_SYSROOT}/usr/share/aclocal [-I <replaceable>dir_containing_your_project-specific_m4_macros</replaceable>]
|
$ aclocal -I ${OECORE_TARGET_SYSROOT}/usr/share/aclocal [-I <replaceable>dir_containing_your_project-specific_m4_macros</replaceable>]
|
||||||
$ autoconf
|
$ autoconf
|
||||||
$ autoheader
|
$ autoheader
|
||||||
$ automake -a
|
$ automake -a
|
||||||
|
</literallayout>
|
||||||
|
</note>
|
||||||
|
</para></listitem>
|
||||||
|
<listitem><para>
|
||||||
|
<emphasis>Make and Install the Project:</emphasis>
|
||||||
|
These two commands generate and install the project
|
||||||
|
into the destination directory:
|
||||||
|
<literallayout class='monospaced'>
|
||||||
|
$ make
|
||||||
|
$ make install DESTDIR=./tmp
|
||||||
</literallayout>
|
</literallayout>
|
||||||
</note>
|
This next command is a simple way to verify the
|
||||||
</para>
|
installation of your project.
|
||||||
</section>
|
Running the command prints the architecture on which
|
||||||
|
the binary file can run.
|
||||||
|
This architecture should be the same architecture that
|
||||||
|
the installed cross-toolchain supports.
|
||||||
|
<literallayout class='monospaced'>
|
||||||
|
$ file ./tmp/usr/local/bin/hello
|
||||||
|
</literallayout>
|
||||||
|
</para></listitem>
|
||||||
|
<listitem><para>
|
||||||
|
<emphasis>Execute Your Project:</emphasis>
|
||||||
|
To execute the project in the shell, simply enter
|
||||||
|
the name.
|
||||||
|
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>
|
||||||
|
|
||||||
<section id='makefile-based-projects'>
|
<section id='makefile-based-projects'>
|
||||||
|
|||||||
Reference in New Issue
Block a user