Toolchain/zh cn

From Openmoko

(Difference between revisions)
Jump to: navigation, search
m (Replacing 'OpenMoko' with 'Openmoko')
 
(14 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 +
{{Languages|Toolchain}}
 
= 简介 =
 
= 简介 =
  
工具链是一组用来编译代码的工具集。OpenMoko有两类不同用途的工具链:
+
工具链是一组用来编译代码的工具集,Openmoko有两类不同用途的工具链。
  
* 开发简单的应用程序
+
== 基本工具链:用于开发简单的单一应用程序 ==
  
For this, you should use a prebuilt toolchain from the OpenMoko project. Here you can find a recipe to get started with this toolchain leading you through a series of steps to compile a project and run it on your target device. You might have heard about [[OpenEmbedded]], however as an application programmer, you should '''not''' be using [[OpenEmbedded]].
+
为了开发简单的单一应用程序,你可以使用针对Openmoko项目预先构建好的工具链。本文将说明这一工具链的使用方法,它将帮助你一步步的编译项目并最终运行在目标设备上。你应该听过[[OpenEmbedded]],但作为开发此类应用程序的开发人员,你’’’不’’’应该使用[[OpenEmbedded]]
  
* 系统集成和定制发行版
+
== [[OpenEmbedded]]:用于系统集成和定制发行版 ==
  
For this task, you should use [[OpenEmbedded]] which builds its own cross compiler during the bootstrapping/build process. System Integration and customizing a distribution is out of scope of this page.
+
针对系统集成和定制发行版的任务,你应该使用[[OpenEmbedded]],它能通过bootstrapping/build流程建立起自己的交叉编译工具链。系统集成和定制发行版未在本文加以讨论。
  
 
=基本工具链的用法=
 
=基本工具链的用法=
  
==先决条件==
+
==基本安装条件==
 
+
熟悉Linux及其命令行工具是最基本的,你必须有一台x86兼容的、最少有1G磁盘空间的电脑。你也必须要有使用本地编译器来编译程序源码的相关操作经验。同时,假设你有home目录(~)/usr/local/目录(有需要时,需使用root用户来操作)的写权限。如果你没有上述的权限,请与管理员联系。
You should be reasonably familiar with Linux and its command line tools, have an x86-compatible computer with at least 1G of free disk space. You should have experience with compiling programs from source using your local compiler. The remainder of this document will also assume you have write access in your home directory (~) and <tt>/usr/local/</tt> (becoming root if needed). If any of this is not the case, please call your local administrator for help.
+
 
+
Last but not least you should have a working setup that allows you to compile native software packages using the autotools build system (the triade of '''./configure, make, make install''').
+
  
A (partial) list of required packages -- please append as necessary:
+
你至少应该具有使用安装程序的权限,允许你使用自动工具构建软件包。(比如'''./configure, make, make install''')
  
* For most Linux version you might only need to install the packages
+
需要安装的部分软件如下:
 +
* 针对大多数Linux发行版,需要安装如下软件包:
 
** autoconf, automake
 
** autoconf, automake
 
** binutils, gcc, gcc-c++
 
** binutils, gcc, gcc-c++
Line 28: Line 27:
 
** intltool
 
** intltool
  
* For ubuntu (7.10) the following is required:
+
* 针对 ubuntu (7.10) ,需要安装以下软件包:
  sudo apt-get install gcc g++ autoconf automake binutils libtool libglib2.0-dev glib-gettextize ccache libxrender-dev
+
  sudo apt-get install gcc g++ autoconf automake binutils libtool libglib2.0-dev ccache libxrender-dev intltool
  
==下载和安装==
+
==下载及安装==
  
The prebuilt toolchain can be downloaded from [[http://downloads.openmoko.org/toolchains downloads.openmoko.org]]:
+
预构建的工具链可以从 [[http://downloads.openmoko.org/toolchains downloads.openmoko.org]]下载:
 
+
* Creating a destination directory can be anywhere, but for example:
+
  
 +
* 在计算机中的任一位置建立目标文件夹,但推荐建立下述文件夹:
 
   mkdir ~/sources
 
   mkdir ~/sources
 
   cd ~/sources
 
   cd ~/sources
  
* Depending on your CPU type (x86_64 or i686) download the proper package:
+
* 下载与计算机CPU类型(x86_64或i686)匹配的软件包:
  
 
   wget http://downloads.openmoko.org/toolchains/openmoko-x86_64-arm-linux-gnueabi-toolchain.tar.bz2
 
   wget http://downloads.openmoko.org/toolchains/openmoko-x86_64-arm-linux-gnueabi-toolchain.tar.bz2
Line 47: Line 45:
  
  
Next, you want to extract it on your filesystem. This toolchain is ''not'' relocatable, it needs to be installed into <tt>/usr/local/openmoko/</tt>.
+
接着,要将它解压缩到文件系统。注意:此软件包必须安装到且会自动安装到<tt>/usr/local/openmoko/</tt>目录。
Now you have the following options:
+
  
* Extract it directly as root, so use command "su" first (or prefix the tar command with "sudo" when you are using Debian/Ubuntu):
+
* 切换到超级用户,然后解压缩。(请使用"su",若您使用的是Debian/Ubuntu,请在tar指令前加入"sudo")
  
 
   cd /
 
   cd /
   tar xjvf ~/sources/openmoko-XYZ-arm-linux-gnueabi-toolchain.tar.bz2
+
   tar -xjvf ~/sources/openmoko-XYZ-arm-linux-gnueabi-toolchain.tar.bz2
 +
 
 +
* 在类Debian系统上,你可以使用alien(+fakeroot)来将.tar.bz2文件构建成一个易于卸载的软件包(使用dpkg -i <package.deb>):
  
* On Debian-based systems, you can use alien(+fakeroot) to create an easy-to-uninstall package from this .tar.bz2 (install with dpkg -i <package.deb>):
 
  
 
   bunzip2 openmoko-x86_64-arm-linux-gnueabi-toolchain.tar.bz2
 
   bunzip2 openmoko-x86_64-arm-linux-gnueabi-toolchain.tar.bz2
Line 61: Line 59:
 
   fakeroot alien -d openmoko-x86_64-arm-linux-gnueabi-toolchain.tar.gz
 
   fakeroot alien -d openmoko-x86_64-arm-linux-gnueabi-toolchain.tar.gz
  
* The prebuilt toolchain is for x86_64 or i686. If you wanted, you could build it on your own with OE:
+
* 预构建的工具链是针对x86_64或i686的。如果你希望的话,你可以使用OpenEmbedded来建立自己的工具链:
  
 
   bitbake meta-toolchain-openmoko
 
   bitbake meta-toolchain-openmoko
  
Finally, everytime you want to use this toolchain, you need to alter some environment variables, so that your tools will be found. The toolchain provides a script to do that, so the only thing you need to do is to source it.
+
最后,每次使用此工具链时,必须先改变环境变量,这样才会找到此工具链。此工具链提供了一个脚本来做这项工作。
Note that if you are not using a "sh" or "bash" shell (check with "echo $SHELL") that you need
+
 
to start "sh" or "bash" first.
+
请注意,如果你并没有使用"sh" "bash" shell ("echo $SHELL" 查看) ,那你必须先启动"sh" "bash"
  
 
  . /usr/local/openmoko/arm/setup-env
 
  . /usr/local/openmoko/arm/setup-env
  
==构建简单的项目==
+
==构建示例项目==
  
In a choosen destination directory (in this example ~/):
+
在目标文件夹中 (本文为~/):
  
* copy the downloaded sample application source:
+
* 复制已下载的示例应用程序源文件:
  
 
  cp -r /usr/local/openmoko/source/openmoko-sample2 ~/
 
  cp -r /usr/local/openmoko/source/openmoko-sample2 ~/
  
* Remember to set the proper environment variables (again with "sh" or "bash") for openmoko:
+
* 设定环境变量 (记得使用"sh" "bash")
  
 
  . /usr/local/openmoko/arm/setup-env
 
  . /usr/local/openmoko/arm/setup-env
  
* You need to create a build configuration for this application. This also checks if all needed libraries, tools, etc.. is available on your system. If this fails see the notes about the needed packages in the section "Prerequisites" mentioned earlier.
+
* 你需要为这个应用程序建立配置文件,这个过程也用来检查你的计算机上的函数库和工具等是否可用。如果这项工作无法完成时,请参考本文的"基本安装环境"一节。
  
 
  om-conf openmoko-sample2
 
  om-conf openmoko-sample2
  
* Optionally now you can modify the source code in openmoko-sample2/src
+
* 现在你可以选择性的修改openmoko-sample2/src 中的源码。
  
* To build the application from the source code you only need to use "make":
+
* 要从源代码中构建应用程序,你应该使用"make"
  
 
  cd openmoko-sample2
 
  cd openmoko-sample2
 
  make
 
  make
  
If you want to install this project on host for staging usage later, a shared library, for example, you can do the following to install it into a given configured prefix.
+
如果你希望在主机上安装这个程序,作为后续使用的共享库,那么你可以进行如下操作来将它安装到指定目录中:
 
+
 
  om-conf --prefix=/usr/local/openmoko openmoko-sample2
 
  om-conf --prefix=/usr/local/openmoko openmoko-sample2
 
  cd openmoko-sample2
 
  cd openmoko-sample2
 
  make install
 
  make install
  
==打包编译好的应用程序==
+
==如何修改示例项目==
 +
 
 +
为了要使用Openmoko-sample2 文件来制作你自己的项目,需要做适度修改:
 +
* 复制下载的示例应用程序:
 +
cp -r /usr/local/openmoko/source/openmoko-sample2 ~/
 +
 +
* 重命名文件夹 ( 在这个示例中为"your-project-name") ,并删除旧有的示例文件。
 +
 
 +
mv openmoko-sample2 your-project-name
 +
cd your-project-name
 +
cd src
 +
rm *.c
 +
 
 +
* 将你自己的源代码复制到src/目录(本示例中为"your-sources"):
 +
cp your-sources .
 +
cd ..
 +
 
 +
* 现在,在主目录下,修改autogen.sh:
 +
 
 +
PKG_NAME="your-project-name"
 +
 
 +
* 修改configure.ac文件("main.c"应该是项目中的主程序文件)
 +
AC_INIT(your-project-main, 0.0.1, [http://www.openmoko.org/ http://www.openmoko.org/])   
 +
AC_CONFIG_SRCDIR(src/main.c)
 +
 
 +
* 切换到data/目录,以你的项目名重命名几个文件:
 +
cd data
 +
mv openmoko-sample.png your-project-name.png
 +
mv openmoko-sample.desktop your-project-name.desktop
 +
 
 +
* 修改data/下的Makefile.am文件:
 +
 
 +
dist_desktop_DATA = your-project-name.desktop
 +
dist_appicon_DATA = your-project-name.png
 +
 
 +
* 修改data/下的 Makefile.in文件
 +
 +
dist_desktop_DATA = smart-search.desktop
 +
dist_appicon_DATA = smart-search.png
 +
 
 +
* 修改your-project-name.desktop文件:
 +
 
 +
Name=your-project-name
 +
Encoding=UTF-8
 +
Version=0.0.1
 +
Type=Application
 +
Exec=your-project-name
 +
 
 +
* 在your-project-name.desktop文件加入以下的内容,
 +
 
 +
Icon=your-project-name
 +
 
 +
* 切换到src/目录:
 +
 
 +
cd ..
 +
cd src
 +
 
 +
* 修改Makefile.am文件
 +
 
 +
bin_PROGRAMS = your-project-name
 +
your_project_name_SOURCES = \
 +
  main.c
 +
your_project_name_LDADD  = @DEPENDENCIES_LIBS@
 +
 
 +
* 请将main.c之外的所有.c和.h文件放入其中,并将变量名称中的 '-' 字符修改为 '_' 。
 +
 
 +
==将你的应用程序打包==
  
We have included a script to make an ipkg out of your application. Note that this is not needed to test your application on the Neo (for that you can just scp the resulting binary and data over), however it's very handy if you want to distribute your application to others.
+
工具链中有一个脚本用来将应用程序制作为ipkg包。请注意,你并不需要在Neo手机上测试此应用程序 ( 若要在Neo手机上测试此应用程序,只需要使用scp将生成的二进制代码和数据传送到手机上即可),打成ipkg包也是为了方便发布给他人。
  
 
  om-make-ipkg openmoko-sample2
 
  om-make-ipkg openmoko-sample2
  
Now you got openmoko-sample2_0.1_armv4t.ipk , you can `scp' it to your
+
现在你已经得到了openmoko-sample2_0.1_armv4t.ipk ,你可以使用"scp"将它传输到Neo手机并安装:
Neo and install it:
+
  
 
  scp openmoko-sample2_0.1_armv4t.ipk root@192.168.0.202:
 
  scp openmoko-sample2_0.1_armv4t.ipk root@192.168.0.202:
 
  ssh root@192.168.0.202 ipkg install openmoko-sample2_0.1_armv4t.ipk
 
  ssh root@192.168.0.202 ipkg install openmoko-sample2_0.1_armv4t.ipk
  
Note that while you can redistribute the generated ipkg, be aware that this is a bare-bones ipk that contains no further information, i.e. you will lack library dependencies. See below how to fix this.
+
请注意:这个ipkg包并未包含控制信息,例如函数库的依赖关系,所以,如果你想分发此ipkg包,应该加入控制信息文件。你可以在控制信息文件中提供版本号、软件包描述、作者和联系方式等:
 
+
You can also supply the version number, a description, and an author / contacts string in a control file:
+
  
 
  om-make-ipkg myapp myapp_control
 
  om-make-ipkg myapp myapp_control
  
A template of myapp_control:
+
myapp_control的模板如下:
  
 
  Package: $appname
 
  Package: $appname
Line 127: Line 187:
 
  Maintainer: $USER
 
  Maintainer: $USER
 
  Architecture: armv4t
 
  Architecture: armv4t
  Homepage: http://www.openmoko.org/
+
  Homepage: [http://www.openmoko.org/ http://www.openmoko.org/]
 
  Depends:  
 
  Depends:  
 
  Source: ${SRC}
 
  Source: ${SRC}
  
==Where to go from here==
+
==你下一步要参考的内容==
  
Using the external toolchain is an easy way to build applications for your Neo. If you are familiar with this procedure, you might also want to look into
+
使用外部工具链来为Neo构建应用程序比较简单。如果你熟悉这个流程的话,你也会想要参考:
* Using [[Qemu]] to test your applications in an emulated environment
+
* 使用[[Qemu]] 在仿真环境下测试你的应用程序
* Using [[Host-based_development_with_Xoo_and_Xephyr|host-based development]] to improve your efficiency
+
** Ubuntu使用者可能想要查看的[[Automatic_emulation_in_Ubuntu]]
* Using [[OpenEmbedded]] to customize your OpenMoko distribution image
+
* 使用[[Host-based_development_with_Xoo_and_Xephyr|host-based development]] 提高效率
 +
* 使用[[OpenEmbedded]] 定制你的Openmoko发行版映像文件
  
=Advanced topics=
+
=高级主题=
==Using toolchain provided libraries==
+
==使用工具链提供的链接库==
Add the necessary libraries to the _LDADD field in src/Makefile.am, for example:
+
向src/Makefile.am文件的 _LDADD 字段加入必要的链接库,示例如下:
 
  openmoko_sample2_LDADD  = @DEPENDENCIES_LIBS@ -lmokogsmd2
 
  openmoko_sample2_LDADD  = @DEPENDENCIES_LIBS@ -lmokogsmd2
  
make sure to run om-conf again after this.
+
之后,请再次运行
 +
om-conf  
  
==Installing additional libraries into the toolchain==
+
==向工具链中安装附加函数库==
 +
不久之后,你也许想要编译一个应用程序,这个应用程序依赖于生僻的函数库,而这些函数库并未由预编译的工具链提供。
  
Sooner or later you will want to compile an application that has dependencies which can't be fulfilled by the precompiled toolchain, e.g. some obscure libraries.
+
这种情况下,你可以请求将附加的函数库放入下一版本的Openmoko工具链,而在那之前,你可以通过如下方式增强现有的工具链。这里演示了如何向工具链中加入一个名为liburiparse的函数库:
 
+
In that case, feel free to request the inclusion of additional libraries into the next release of the OpenMoko toolchain. Until then, here is how you enhance your already installed toolchain. Say, we want to add the library called liburiparse:
+
  
 
  cd ~/source
 
  cd ~/source
Line 157: Line 218:
 
  make install
 
  make install
  
That's it.
+
==使用OE打包应用程序==
 +
当你编写了一个很酷的应用程序并想与他人分享,最佳方法是
 +
# 上传你的应用程序源代码到公共区域
 +
# 提交一个[[BitBake]]包到[[OpenEmbedded]],最好通过[http://bugs.openembedded.org OpenEmbedded bugtracker]
  
==Getting your application packaged by OE==
+
您也可以参考 [[Customizing your Openmoko distribution|定制化你的Openmoko发行版]].
  
If you have written a cool application which you want to share with others, the best way to do that is to
+
==问题排除==
  
# upload your application source code to a public location
+
* 请使用[http://lists.openmoko.org/mailman/listinfo/openmoko-devel Openmoko-Devel] 邮件列表来获得帮助。
# submit a [[BitBake]] recipe to [[OpenEmbedded]], preferably via the [http://bugs.openembedded.org OpenEmbedded bugtracker].
+
 
+
See also [[Customizing your OpenMoko distribution]].
+
 
+
==Troubleshooting==
+
 
+
* Please use the [http://lists.openmoko.org/mailman/listinfo/openmoko-devel OpenMoko-Devel] mailing list.
+
 
+
{{Languages|Toolchain}}
+
  
[[Category:OpenMoko]]
+
[[Category:Application Developer/zh cn]]

Latest revision as of 11:25, 23 August 2008

Contents

[edit] 简介

工具链是一组用来编译代码的工具集,Openmoko有两类不同用途的工具链。

[edit] 基本工具链:用于开发简单的单一应用程序

为了开发简单的单一应用程序,你可以使用针对Openmoko项目预先构建好的工具链。本文将说明这一工具链的使用方法,它将帮助你一步步的编译项目并最终运行在目标设备上。你应该听过OpenEmbedded,但作为开发此类应用程序的开发人员,你’’’不’’’应该使用OpenEmbedded

[edit] OpenEmbedded:用于系统集成和定制发行版

针对系统集成和定制发行版的任务,你应该使用OpenEmbedded,它能通过bootstrapping/build流程建立起自己的交叉编译工具链。系统集成和定制发行版未在本文加以讨论。

[edit] 基本工具链的用法

[edit] 基本安装条件

熟悉Linux及其命令行工具是最基本的,你必须有一台x86兼容的、最少有1G磁盘空间的电脑。你也必须要有使用本地编译器来编译程序源码的相关操作经验。同时,假设你有home目录(~)和/usr/local/目录(有需要时,需使用root用户来操作)的写权限。如果你没有上述的权限,请与管理员联系。

你至少应该具有使用安装程序的权限,允许你使用自动工具构建软件包。(比如./configure, make, make install)。

需要安装的部分软件如下:

  • 针对大多数Linux发行版,需要安装如下软件包:
    • autoconf, automake
    • binutils, gcc, gcc-c++
    • libtool
    • ccache
    • intltool
  • 针对 ubuntu (7.10) ,需要安装以下软件包:
sudo apt-get install gcc g++ autoconf automake binutils libtool libglib2.0-dev ccache libxrender-dev intltool

[edit] 下载及安装

预构建的工具链可以从 [downloads.openmoko.org]下载:

  • 在计算机中的任一位置建立目标文件夹,但推荐建立下述文件夹:
 mkdir ~/sources
 cd ~/sources
  • 下载与计算机CPU类型(x86_64或i686)匹配的软件包:
 wget http://downloads.openmoko.org/toolchains/openmoko-x86_64-arm-linux-gnueabi-toolchain.tar.bz2
or
 wget http://downloads.openmoko.org/toolchains/openmoko-i686-arm-linux-gnueabi-toolchain.tar.bz2


接着,要将它解压缩到文件系统。注意:此软件包必须安装到且会自动安装到/usr/local/openmoko/目录。

  • 切换到超级用户,然后解压缩。(请使用"su",若您使用的是Debian/Ubuntu,请在tar指令前加入"sudo"):
  cd /
  tar -xjvf ~/sources/openmoko-XYZ-arm-linux-gnueabi-toolchain.tar.bz2
  • 在类Debian系统上,你可以使用alien(+fakeroot)来将.tar.bz2文件构建成一个易于卸载的软件包(使用dpkg -i <package.deb>):


  bunzip2 openmoko-x86_64-arm-linux-gnueabi-toolchain.tar.bz2
  gzip openmoko-x86_64-arm-linux-gnueabi-toolchain.tar
  fakeroot alien -d openmoko-x86_64-arm-linux-gnueabi-toolchain.tar.gz
  • 预构建的工具链是针对x86_64或i686的。如果你希望的话,你可以使用OpenEmbedded来建立自己的工具链:
  bitbake meta-toolchain-openmoko

最后,每次使用此工具链时,必须先改变环境变量,这样才会找到此工具链。此工具链提供了一个脚本来做这项工作。

请注意,如果你并没有使用"sh" 或"bash" shell (用"echo $SHELL" 查看) ,那你必须先启动"sh" 或"bash"。

. /usr/local/openmoko/arm/setup-env

[edit] 构建示例项目

在目标文件夹中 (本文为~/):

  • 复制已下载的示例应用程序源文件:
cp -r /usr/local/openmoko/source/openmoko-sample2 ~/
  • 设定环境变量 (记得使用"sh" 或 "bash"):
. /usr/local/openmoko/arm/setup-env
  • 你需要为这个应用程序建立配置文件,这个过程也用来检查你的计算机上的函数库和工具等是否可用。如果这项工作无法完成时,请参考本文的"基本安装环境"一节。
om-conf openmoko-sample2
  • 现在你可以选择性的修改openmoko-sample2/src 中的源码。
  • 要从源代码中构建应用程序,你应该使用"make":
cd openmoko-sample2
make

如果你希望在主机上安装这个程序,作为后续使用的共享库,那么你可以进行如下操作来将它安装到指定目录中:

om-conf --prefix=/usr/local/openmoko openmoko-sample2
cd openmoko-sample2
make install

[edit] 如何修改示例项目

为了要使用Openmoko-sample2 文件来制作你自己的项目,需要做适度修改:

  • 复制下载的示例应用程序:
cp -r /usr/local/openmoko/source/openmoko-sample2 ~/

  • 重命名文件夹 ( 在这个示例中为"your-project-name") ,并删除旧有的示例文件。
mv openmoko-sample2 your-project-name
cd your-project-name
cd src
rm *.c
  • 将你自己的源代码复制到src/目录(本示例中为"your-sources"):
cp your-sources .
cd ..
  • 现在,在主目录下,修改autogen.sh:
PKG_NAME="your-project-name"
  • 修改configure.ac文件("main.c"应该是项目中的主程序文件)
AC_INIT(your-project-main, 0.0.1, http://www.openmoko.org/)    
AC_CONFIG_SRCDIR(src/main.c)
  • 切换到data/目录,以你的项目名重命名几个文件:
cd data
mv openmoko-sample.png your-project-name.png
mv openmoko-sample.desktop your-project-name.desktop
  • 修改data/下的Makefile.am文件:
dist_desktop_DATA = your-project-name.desktop
dist_appicon_DATA = your-project-name.png
  • 修改data/下的 Makefile.in文件
dist_desktop_DATA = smart-search.desktop
dist_appicon_DATA = smart-search.png
  • 修改your-project-name.desktop文件:
Name=your-project-name
Encoding=UTF-8
Version=0.0.1
Type=Application
Exec=your-project-name
  • 在your-project-name.desktop文件加入以下的内容,
Icon=your-project-name
  • 切换到src/目录:
cd ..
cd src
  • 修改Makefile.am文件
bin_PROGRAMS = your-project-name	
your_project_name_SOURCES = \				
 		main.c 
your_project_name_LDADD  = @DEPENDENCIES_LIBS@
  • 请将main.c之外的所有.c和.h文件放入其中,并将变量名称中的 '-' 字符修改为 '_' 。

[edit] 将你的应用程序打包

工具链中有一个脚本用来将应用程序制作为ipkg包。请注意,你并不需要在Neo手机上测试此应用程序 ( 若要在Neo手机上测试此应用程序,只需要使用scp将生成的二进制代码和数据传送到手机上即可),打成ipkg包也是为了方便发布给他人。

om-make-ipkg openmoko-sample2

现在你已经得到了openmoko-sample2_0.1_armv4t.ipk ,你可以使用"scp"将它传输到Neo手机并安装:

scp openmoko-sample2_0.1_armv4t.ipk root@192.168.0.202:
ssh root@192.168.0.202 ipkg install openmoko-sample2_0.1_armv4t.ipk

请注意:这个ipkg包并未包含控制信息,例如函数库的依赖关系,所以,如果你想分发此ipkg包,应该加入控制信息文件。你可以在控制信息文件中提供版本号、软件包描述、作者和联系方式等:

om-make-ipkg myapp myapp_control

myapp_control的模板如下:

Package: $appname
Version: 0.1
Description: package built by openmoko toolchain
Section: openmoko/applications
Priority: optional
Maintainer: $USER
Architecture: armv4t
Homepage: http://www.openmoko.org/
Depends: 
Source: ${SRC}

[edit] 你下一步要参考的内容

使用外部工具链来为Neo构建应用程序比较简单。如果你熟悉这个流程的话,你也会想要参考:

[edit] 高级主题

[edit] 使用工具链提供的链接库

向src/Makefile.am文件的 _LDADD 字段加入必要的链接库,示例如下:

openmoko_sample2_LDADD  = @DEPENDENCIES_LIBS@ -lmokogsmd2

之后,请再次运行

om-conf 

[edit] 向工具链中安装附加函数库

不久之后,你也许想要编译一个应用程序,这个应用程序依赖于生僻的函数库,而这些函数库并未由预编译的工具链提供。

这种情况下,你可以请求将附加的函数库放入下一版本的Openmoko工具链,而在那之前,你可以通过如下方式增强现有的工具链。这里演示了如何向工具链中加入一个名为liburiparse的函数库:

cd ~/source
wget http://downloads.sourceforge.net/uriparser/uriparser-0.6.0.tar.bz2
./configure --host=arm-angstrom-linux-gnueabi --prefix=/usr/local/openmoko/arm
make
make install

[edit] 使用OE打包应用程序

当你编写了一个很酷的应用程序并想与他人分享,最佳方法是

  1. 上传你的应用程序源代码到公共区域
  2. 提交一个BitBake包到OpenEmbedded,最好通过OpenEmbedded bugtracker

您也可以参考 定制化你的Openmoko发行版.

[edit] 问题排除

Personal tools

简介

工具链是一组用来编译代码的工具集。OpenMoko有两类不同用途的工具链:

  • 开发简单的应用程序

For this, you should use a prebuilt toolchain from the OpenMoko project. Here you can find a recipe to get started with this toolchain leading you through a series of steps to compile a project and run it on your target device. You might have heard about OpenEmbedded, however as an application programmer, you should not be using OpenEmbedded.

  • 系统集成和定制发行版

For this task, you should use OpenEmbedded which builds its own cross compiler during the bootstrapping/build process. System Integration and customizing a distribution is out of scope of this page.

基本工具链的用法

先决条件

You should be reasonably familiar with Linux and its command line tools, have an x86-compatible computer with at least 1G of free disk space. You should have experience with compiling programs from source using your local compiler. The remainder of this document will also assume you have write access in your home directory (~) and /usr/local/ (becoming root if needed). If any of this is not the case, please call your local administrator for help.

Last but not least you should have a working setup that allows you to compile native software packages using the autotools build system (the triade of ./configure, make, make install).

A (partial) list of required packages -- please append as necessary:

  • For most Linux version you might only need to install the packages
    • autoconf, automake
    • binutils, gcc, gcc-c++
    • libtool
    • ccache
    • intltool
  • For ubuntu (7.10) the following is required:
sudo apt-get install gcc g++ autoconf automake binutils libtool libglib2.0-dev glib-gettextize ccache libxrender-dev

下载和安装

The prebuilt toolchain can be downloaded from [downloads.openmoko.org]:

  • Creating a destination directory can be anywhere, but for example:
 mkdir ~/sources
 cd ~/sources
  • Depending on your CPU type (x86_64 or i686) download the proper package:
 wget http://downloads.openmoko.org/toolchains/openmoko-x86_64-arm-linux-gnueabi-toolchain.tar.bz2
or
 wget http://downloads.openmoko.org/toolchains/openmoko-i686-arm-linux-gnueabi-toolchain.tar.bz2


Next, you want to extract it on your filesystem. This toolchain is not relocatable, it needs to be installed into /usr/local/openmoko/. Now you have the following options:

  • Extract it directly as root, so use command "su" first (or prefix the tar command with "sudo" when you are using Debian/Ubuntu):
  cd /
  tar xjvf ~/sources/openmoko-XYZ-arm-linux-gnueabi-toolchain.tar.bz2
  • On Debian-based systems, you can use alien(+fakeroot) to create an easy-to-uninstall package from this .tar.bz2 (install with dpkg -i <package.deb>):
  bunzip2 openmoko-x86_64-arm-linux-gnueabi-toolchain.tar.bz2
  gzip openmoko-x86_64-arm-linux-gnueabi-toolchain.tar
  fakeroot alien -d openmoko-x86_64-arm-linux-gnueabi-toolchain.tar.gz
  • The prebuilt toolchain is for x86_64 or i686. If you wanted, you could build it on your own with OE:
  bitbake meta-toolchain-openmoko

Finally, everytime you want to use this toolchain, you need to alter some environment variables, so that your tools will be found. The toolchain provides a script to do that, so the only thing you need to do is to source it. Note that if you are not using a "sh" or "bash" shell (check with "echo $SHELL") that you need to start "sh" or "bash" first.

. /usr/local/openmoko/arm/setup-env

构建简单的项目

In a choosen destination directory (in this example ~/):

  • copy the downloaded sample application source:
cp -r /usr/local/openmoko/source/openmoko-sample2 ~/
  • Remember to set the proper environment variables (again with "sh" or "bash") for openmoko:
. /usr/local/openmoko/arm/setup-env
  • You need to create a build configuration for this application. This also checks if all needed libraries, tools, etc.. is available on your system. If this fails see the notes about the needed packages in the section "Prerequisites" mentioned earlier.
om-conf openmoko-sample2
  • Optionally now you can modify the source code in openmoko-sample2/src
  • To build the application from the source code you only need to use "make":
cd openmoko-sample2
make

If you want to install this project on host for staging usage later, a shared library, for example, you can do the following to install it into a given configured prefix.

om-conf --prefix=/usr/local/openmoko openmoko-sample2
cd openmoko-sample2
make install

打包编译好的应用程序

We have included a script to make an ipkg out of your application. Note that this is not needed to test your application on the Neo (for that you can just scp the resulting binary and data over), however it's very handy if you want to distribute your application to others.

om-make-ipkg openmoko-sample2

Now you got openmoko-sample2_0.1_armv4t.ipk , you can `scp' it to your Neo and install it:

scp openmoko-sample2_0.1_armv4t.ipk root@192.168.0.202:
ssh root@192.168.0.202 ipkg install openmoko-sample2_0.1_armv4t.ipk

Note that while you can redistribute the generated ipkg, be aware that this is a bare-bones ipk that contains no further information, i.e. you will lack library dependencies. See below how to fix this.

You can also supply the version number, a description, and an author / contacts string in a control file:

om-make-ipkg myapp myapp_control

A template of myapp_control:

Package: $appname
Version: 0.1
Description: package built by openmoko toolchain
Section: openmoko/applications
Priority: optional
Maintainer: $USER
Architecture: armv4t
Homepage: http://www.openmoko.org/
Depends: 
Source: ${SRC}

Where to go from here

Using the external toolchain is an easy way to build applications for your Neo. If you are familiar with this procedure, you might also want to look into

Advanced topics

Using toolchain provided libraries

Add the necessary libraries to the _LDADD field in src/Makefile.am, for example:

openmoko_sample2_LDADD  = @DEPENDENCIES_LIBS@ -lmokogsmd2

make sure to run om-conf again after this.

Installing additional libraries into the toolchain

Sooner or later you will want to compile an application that has dependencies which can't be fulfilled by the precompiled toolchain, e.g. some obscure libraries.

In that case, feel free to request the inclusion of additional libraries into the next release of the OpenMoko toolchain. Until then, here is how you enhance your already installed toolchain. Say, we want to add the library called liburiparse:

cd ~/source
wget http://downloads.sourceforge.net/uriparser/uriparser-0.6.0.tar.bz2
./configure --host=arm-angstrom-linux-gnueabi --prefix=/usr/local/openmoko/arm
make
make install

That's it.

Getting your application packaged by OE

If you have written a cool application which you want to share with others, the best way to do that is to

  1. upload your application source code to a public location
  2. submit a BitBake recipe to OpenEmbedded, preferably via the OpenEmbedded bugtracker.

See also Customizing your OpenMoko distribution.

Troubleshooting