《NetBSD指南-30.1.构建交叉编译器》

NetBSD用户指南中文版、NetBSD pkgsrc指南中文版...

版主: lionux

主题已锁定
头像
leo
帖子: 2465
注册时间: 2010-01-21 3:27

《NetBSD指南-30.1.构建交叉编译器》

帖子 leo » 2010-03-08 3:12

交叉开发的第一步是使所有所需工具可用。 在NetBSD的术语里被称为 "工具链", 并且包含 兼容BSD的make(1), C/C++编译器, linker, assembler, config(8),同时好包含了相当多的工具,这些工具仅在交叉编译一个完整的发行版时才用的到, 这不在我们讨论的范围内。

创建交叉编译器的命令非常简单, 使用NetBSD新的src/build.sh 脚本. 请注意,普通用户(非root)可以运行这里的所有命令:

代码: 全选

$ cd /usr/src
$ ./build.sh -m sparc64 tools
请确保目录 /usr/obj 存在, 否则在调用build.sh时添加一个"-O"选项, 将目标目录重定向到其它目录。

如果以前已经编译过这些工具,并且它们仅需进行更新, 那么可以使用更新选项"-u",这样仅重新编译需更新的工具:

代码: 全选

$ ./build.sh -u -m sparc64 tools
当工具编译完成后, 它们的相关信息以及几个环境变量会输出在屏幕上:

代码: 全选

...
===> build.sh started: Thu Dec  2 22:18:11 CET 2007
===> build.sh ended:   Thu Dec  2 22:28:22 CET 2007
===> Summary of results:
         build.sh command: ./build.sh -m sparc64 tools
         build.sh started: Thu Dec  2 22:18:11 CET 2007
         No nonexistent/bin/nbmake, needs building.
         Bootstrapping nbmake
         MACHINE:          sparc64
         MACHINE_ARCH:     sparc64
         TOOLDIR path:     /usr/src/tooldir.NetBSD-4.0-i386
         DESTDIR path:     /usr/src/destdir.sparc64
         RELEASEDIR path:  /usr/src/releasedir
         Created /usr/src/tooldir.NetBSD-4.0-i386/bin/nbmake
         makewrapper:      /usr/src/tooldir.NetBSD-4.0-i386/bin/nbmake-sparc64
         Updated /usr/src/tooldir.NetBSD-4.0-i386/bin/nbmake-sparc64
         Tools built to /usr/src/tooldir.NetBSD-4.0-i386
         build.sh started: Thu Dec  2 22:18:11 CET 2007
         build.sh ended:   Thu Dec  2 22:28:22 CET 2007
===> . 
在构建过程中, 使用的object目录是固定的, 即每个特定目录保存着特定平台的目标文件和编译结果。本例中, 目标文件和编译结果保存在名为 "obj.sparc64" 的目录内,因为我们将 UltraSPARC作为目标平台。

工具链本身也是其中的一部分, 但是因为它在i386系统上并且是在i386上编译的, 它将被放置于自己的目录内,标志着在哪里进行的交叉编译。 这是交叉编译工具所在位置:

代码: 全选

$ pwd
/usr/src
$ ls -d tooldir.*
tooldir.NetBSD-4.0-i386
所以,一般对于给定的 "主" 和 "目标" 系统的结合来讲, 交叉编译器默认位于 "src/tooldir.host" 目录。整个NetBSD操作系统的交叉编译工具清单包括:

代码: 全选

$ ls tooldir.NetBSD-4.0-i386/bin/
nbasn1_compile          nbmakefs                nbzic
nbcap_mkdb              nbmakeinfo              sparc64--netbsd-addr2li
nbcat                   nbmakewhatis            sparc64--netbsd-ar
nbcksum                 nbmenuc                 sparc64--netbsd-as
nbcompile_et            nbmkcsmapper            sparc64--netbsd-c++
nbconfig                nbmkdep                 sparc64--netbsd-c++filt
nbcrunchgen             nbmkesdb                sparc64--netbsd-cpp
nbctags                 nbmklocale              sparc64--netbsd-dbsym
nbdb                    nbmknod                 sparc64--netbsd-g++
nbeqn                   nbmktemp                sparc64--netbsd-g77
nbfgen                  nbmsgc                  sparc64--netbsd-gcc
nbfile                  nbmtree                 sparc64--netbsd-gcc-3.3
nbgencat                nbnroff                 sparc64--netbsd-gccbug
nbgroff                 nbpax                   sparc64--netbsd-gcov
nbhexdump               nbpic                   sparc64--netbsd-ld
nbhost-mkdep            nbpwd_mkdb              sparc64--netbsd-lint
nbindxbib               nbrefer                 sparc64--netbsd-mdsetim
nbinfo                  nbrpcgen                sparc64--netbsd-nm
nbinfokey               nbsoelim                sparc64--netbsd-objcopy
nbinstall               nbstat                  sparc64--netbsd-objdump
nbinstall-info          nbsunlabel              sparc64--netbsd-ranlib
nbinstallboot           nbtbl                   sparc64--netbsd-readelf
nblex                   nbtexi2dvi              sparc64--netbsd-size
nblorder                nbtexindex              sparc64--netbsd-strings
nbm4                    nbtsort                 sparc64--netbsd-strip
nbmake                  nbuudecode
nbmake-sparc64          nbyacc 
如你所见, NetBSD上多数可用的本地工具具有某些程序前缀以区分哪些目标平台上的工具。

One important tool that should be pointed out here is "nbmake-sparc64". This is a shell wrapper for a BSD compatible make(1) command that's setup to use all the right commands from the crosscompiler toolchain. Using this wrapper instead of /usr/bin/make allows crosscompiling programs that were written using the NetBSD Makefile infrastructure (see src/share/mk). We will use this make(1) wrapper in a second to cross compile the kernel!

主题已锁定

在线用户

正浏览此版面之用户: 没有注册用户 和 11 访客