aboutsummaryrefslogtreecommitdiffstats
path: root/meta/classes/toolchain-scripts-base.bbclass
blob: 2489b9dbeb81f48dd6167028a360619238196c2b (plain)
1
2
3
4
5
6
7
8
9
10
11
#This function create a version information file
toolchain_create_sdk_version () {
	local versionfile=$1
	rm -f $versionfile
	touch $versionfile
	echo 'Distro: ${DISTRO}' >> $versionfile
	echo 'Distro Version: ${DISTRO_VERSION}' >> $versionfile
	echo 'Metadata Revision: ${METADATA_REVISION}' >> $versionfile
	echo 'Timestamp: ${DATETIME}' >> $versionfile
}
toolchain_create_sdk_version[vardepsexclude] = "DATETIME"
ar */ .highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */ .highlight .sd { color: #e6db74 } /* Literal.String.Doc */ .highlight .s2 { color: #e6db74 } /* Literal.String.Double */ .highlight .se { color: #ae81ff } /* Literal.String.Escape */ .highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */ .highlight .si { color: #e6db74 } /* Literal.String.Interpol */ .highlight .sx { color: #e6db74 } /* Literal.String.Other */ .highlight .sr { color: #e6db74 } /* Literal.String.Regex */ .highlight .s1 { color: #e6db74 } /* Literal.String.Single */ .highlight .ss { color: #e6db74 } /* Literal.String.Symbol */ .highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #a6e22e } /* Name.Function.Magic */ .highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */ .highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */ .highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */ .highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */ .highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */ } @media (prefers-color-scheme: light) { .highlight .hll { background-color: #ffffcc } .highlight .c { color: #888888 } /* Comment */ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ .highlight .k { color: #008800; font-weight: bold } /* Keyword */ .highlight .ch { color: #888888 } /* Comment.Hashbang */ .highlight .cm { color: #888888 } /* Comment.Multiline */ .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"
[<!ENTITY % poky SYSTEM "../poky.ent"> %poky; ] >

<chapter id='using-the-command-line'>
<title>Using the Command Line</title>

    <para>
        Recall that earlier the manual discussed how to use an existing toolchain
        tarball that had been installed into the default installation
        directory, <filename>/opt/poky/&DISTRO;</filename>, which is outside of the
        <ulink url='&YOCTO_DOCS_DEV_URL;#build-directory'>Build Directory</ulink>
        (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.
    </para>

    <para>
        During this setup, locations for the compiler, QEMU scripts, QEMU binary,
        a special version of <filename>pkgconfig</filename> and other useful
        utilities are added to the <filename>PATH</filename> variable.
        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.
    </para>

    <para>
        Collectively, these conditions allow you to easily use the toolchain
        outside of the OpenEmbedded build environment on both Autotools-based
        projects and Makefile-based projects.
        This chapter provides information for both these types of projects.
    </para>


<section id='autotools-based-projects'>
<title>Autotools-Based Projects</title>

    <para>
        Once you have a suitable cross-toolchain installed, it is very easy to
        develop a project outside of the OpenEmbedded build system.
        This section presents a simple "Helloworld" example that shows how
        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>
            Follow these steps to create a simple Autotools-based project:
            <orderedlist>
                <listitem><para><emphasis>Create your directory:</emphasis>
                    Create a clean directory for your project and then make
                    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 &lt;stdio.h&gt;

     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>
                <listitem><para><emphasis>Source the cross-toolchain
                    environment setup file:</emphasis>
                    Installation of the cross-toolchain creates a cross-toolchain
                    environment setup script in the directory that the ADT
                    was installed.
                    Before you can use the tools to develop your project, you must
                    source this setup script.
                    The script begins with the string "environment-setup" and contains
                    the machine architecture, which is followed by the string
                    "poky-linux".
                    Here is an example that sources a script from the
                    default ADT installation directory that uses the
                    32-bit Intel x86 Architecture and using the
                    &DISTRO_NAME; Yocto Project release:
                    <literallayout class='monospaced'>
     $ source /opt/poky/&DISTRO;/environment-setup-i586-poky-linux
                    </literallayout></para></listitem>
                <listitem><para><emphasis>Generate the local aclocal.m4
                    files and create the configure script:</emphasis>
                    The following GNU Autotools generate the local
                    <filename>aclocal.m4</filename> files and create the
                    configure script:
                    <literallayout class='monospaced'>
     $ aclocal
     $ autoconf
                    </literallayout></para></listitem>
                <listitem><para><emphasis>Generate files needed by GNU
                    coding standards:</emphasis>
                    GNU coding standards require certain files in order for the
                    project to be compliant.
                    This command creates those files:
                    <literallayout class='monospaced'>
     $ touch NEWS README AUTHORS ChangeLog
                    </literallayout></para></listitem>
                <listitem><para><emphasis>Generate the configure
                    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>
                    These two commands generate and install the project into the
                    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
                    of your project.
                    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:
            <literallayout class='monospaced'>
     $ ./configure --host=armv5te-poky-linux-gnueabi \
        --with-libtool-sysroot=&lt;sysroot-dir&gt;
            </literallayout>
        </para>

        <para>
            This single command updates your project and rebuilds it using the appropriate
            cross-toolchain tools.
            <note>
                If the <filename>configure</filename> script results in problems recognizing the
                <filename>--with-libtool-sysroot=&lt;sysroot-dir&gt;</filename> option,
                regenerate the script to enable the support by doing the following and then
                run the script again:
                <literallayout class='monospaced'>
     $ libtoolize --automake
     $ aclocal -I ${OECORE_NATIVE_SYSROOT}/usr/share/aclocal \
        [-I &lt;dir_containing_your_project-specific_m4_macros&gt;]
     $ autoconf
     $ autoheader
     $ automake -a
                </literallayout>
            </note>
        </para>
    </section>
</section>

<section id='makefile-based-projects'>
<title>Makefile-Based Projects</title>

    <para>
        For a Makefile-based project, you use the cross-toolchain by making sure
        the tools are used.
        You can do this as follows:
        <literallayout class='monospaced'>
     CC=arm-poky-linux-gnueabi-gcc
     LD=arm-poky-linux-gnueabi-ld
     CFLAGS=”${CFLAGS} --sysroot=&lt;sysroot-dir&gt;”
     CXXFLAGS=”${CXXFLAGS} --sysroot=&lt;sysroot-dir&gt;</literallayout>
    </para>
</section>

</chapter>
<!--
vim: expandtab tw=80 ts=4
-->