Chinaunix首页 | 论坛 | 博客
  • 博客访问: 179582
  • 博文数量: 27
  • 博客积分: 2774
  • 博客等级: 少校
  • 技术积分: 250
  • 用 户 组: 普通用户
  • 注册时间: 2007-08-31 11:00
文章分类

全部博文(27)

文章存档

2011年(2)

2010年(5)

2009年(10)

2008年(3)

2007年(7)

分类:

2010-04-30 15:16:02

具体变量和src目录,请参照实际情况修改。

#!/bin/bash
export BUILD_HOST="x86_64-apple-darwin10.3.0"
export TARGET="i686-linux"
export PREFIX="/Volumes/Data/XTools"
export TARGET_PREFIX=$PREFIX/$TARGET
export PATH=$PATH:$PREFIX/bin
export SRC="/Volumes/Data/src"

mkdir build
cd build

#Build gmp
ABI=64 NM="/usr/bin/nm -p" $SRC/gmp-4.3.2/configure --prefix=$PREFIX --enable-cxx
make > /dev/null
make check > /dev/null
make install

#BUild mpfr
rm -rf *
$SRC/mpfr-2.4.1/configure --prefix=$PREFIX --with-gmp=$PREFIX
make > /dev/null
make check > /dev/null
make install

#Build kernel headers files
cd $KSRC
make ARCH=x86 CROSS_COMPILE=$TARGET menuconfig
make ARCH=x86 INSTALL_HDR_PATH=$TARGET_PREFIX headers_install
cd -

#Build binutils
rm -rf *
CC="cc -no-cpp-precomp -I$PREFIX/include" $SRC/binutils-2.18/configure --prefix=$PREFIX --target=$TARGET --disable-nls --with-gmp=$PREFIX --with-mpfr=$PREFIX --program-prefix="$TARGET"- --disable-multilib --build=$BUILD_HOST --host=$BUILD_HOST
make configure-host > /dev/null
make > /dev/null
make check > /dev/null
make install
cp -v $SRC/binutils-2.18/include/libiberty.h $TARGET_PREFIX/include/
cd $PREFIX/bin
ln -vs $TARGET-readelf readelf
cd -

#bulid gcc
rm -rf *

AR_FOR_TARGET="$TARGET-ar" AS_FOR_TARGET="$TARGET-as" LD_FOR_TARGET="$TARGET-ld" NM_FOR_TARGET="$TARGET-nm" OBJDUMP_FOR_TARGET="$TARGET-objdump" RANLIB_FOR_TARGET="$TARGET-ranlib" STRIP_FOR_TARGET="$TARGET-strip" LDFLAGS="-L$PREFIX/lib $LDFLAGS" CC="cc -no-cpp-precomp -I$PREFIX/include" $SRC/gcc-4.4.3/configure --target=$TARGET --prefix=$PREFIX --without-headers --enable-languages="c" --disable-threads --disable-shared --disable-decimal-float --disable-libmudflap --disable-libssp --disable-nls --program-prefix=$TARGET- --disable-libgfortran --disable-libgomp --disable-multilib --with-gmp=$PREFIX --with-mpfr=$PREFIX --build=$BUILD_HOST --host=$BUILD_HOST
make configure-host > /dev/null
AR_FOR_TARGET="$TARGET-ar" AS_FOR_TARGET="$TARGET-as" LD_FOR_TARGET="$TARGET-ld" NM_FOR_TARGET="$TARGET-nm" OBJDUMP_FOR_TARGET="$TARGET-objdump" RANLIB_FOR_TARGET="$TARGET-ranlib" STRIP_FOR_TARGET="$TARGET-strip" LDFLAGS="-L$PREFIX/lib $LDFLAGS" CC="cc -no-cpp-precomp -I$PREFIX/include" make >/dev/null
make check > /dev/null
make install

cd $PREFIX/lib/gcc/$TARGET/`$TARGET-gcc --version |head -n1 |awk '{ print $3 }'`/
ln -vs libgcc.a libgcc_eh.a
cd -

#Build Glibc
rm -rf *

echo "libc_cv_forced_unwind=yes" > config.cache
echo "libc_cv_c_cleanup=yes" >> config.cache
echo "libc_cv_gnu89_inline=yes" >> config.cache
echo "install_root=$TARGET_PREFIX" >> configparms

CFLAGS="-O2 -U_FORTIFY_SOURCE -march=i686 -Wall -pipe -mtune=native -fno-stack-protector" $SRC/glibc-2.10.1/configure --host=$TARGET --prefix=/ --with-headers="$TARGET_PREFIX/include" --enable-add-ons --disable-profile --enable-omitfp --with-binutils="$TARGET_PREFIX/bin" --without-selinux --disable-multilib --without-gd --without-cvs --with-elf --build=$BUILD_HOST -C
make > /dev/null
make check > /dev/null
make install_root=$TARGET_PREFIX install

######################################
#Rebuild binutils
rm -rf *

CC="cc -no-cpp-precomp -I$PREFIX/include" $SRC/binutils-2.18/configure --prefix=$PREFIX --target=$TARGET --with-gmp=$PREFIX --with-mpfr=$PREFIX --program-prefix="$TARGET"- --disable-multilib --build=$BUILD_HOST --host=$BUILD_HOST --with-sysroot=$TARGET_PREFIX --disable-werror --disable-nls
make configure-host > /dev/null
make > /dev/null
make check > /dev/null
make install

#Rebuild gcc
rm -rf *

AR_FOR_TARGET="$TARGET-ar" AS_FOR_TARGET="$TARGET-as" LD_FOR_TARGET="$TARGET-ld" NM_FOR_TARGET="$TARGET-nm" OBJDUMP_FOR_TARGET="$TARGET-objdump" RANLIB_FOR_TARGET="$TARGET-ranlib" STRIP_FOR_TARGET="$TARGET-strip" LDFLAGS="-L$PREFIX/lib $LDFLAGS" CC="cc -no-cpp-precomp -I$PREFIX/include" $SRC/gcc-4.4.3/configure --target=$TARGET --prefix=$PREFIX --enable-languages="c,c++" --enable-threads=posix --program-prefix=$TARGET- --disable-multilib --with-gmp=$PREFIX --with-mpfr=$PREFIX --enable-__cxa_atexit --enable-c99 --enable-long-long --with-headers=$TARGET_PREFIX/include --build=$BUILD_HOST --host=$BUILD_HOST --enable-openmp --with-system-zlib
make configure-host > /dev/null
make > /dev/null
make check > /dev/null
make install

cd $TARGET_PREFIX
rm -rf sys-include
ln -vs include sys-include

cd -

cd ..
rm -rf build
@echo "Build Complete!!!"


其他需要安装的软件:Xcode,MacPorts

Xcode需要安装UNIX development
MacPorts安装软件如下:

localhost ~ $ port installed
The following ports are currently installed:
  bash-completion @1.1_6 (active)
  cscope @15.7a_1 (active)
  ctags @5.8_0 (active)
  curl @7.20.0_0+ssl (active)
  curl-ca-bundle @7.20.0_3 (active)
  expat @2.0.1_0 (active)
  findutils @4.4.2_0+with_default_names (active)
  gawk @3.1.7_0 (active)
  gettext @0.17_4 (active)
  git-core @1.7.1_0 (active)
  gperf @3.0.4_0 (active)
  gsed @4.2.1_0+with_default_names (active)
  libiconv @1.13.1_0 (active)
  libidn @1.18_0 (active)
  ncurses @5.7_0+darwin_10 (active)
  ncursesw @5.7_0+darwin_10 (active)
  openssl @0.9.8n_0+darwin (active)
  p5-error @0.17016_0 (active)
  perl5 @5.8.9_0 (active)
  perl5.8 @5.8.9_3 (active)
  pkgconfig @0.23_1 (active)
  popt @1.15_0 (active)
  rsync @3.0.7_0 (active)
  zlib @1.2.5_0 (active)
localhost ~ $


MacPorts中的部分软件(如awk、find等)由于和系统自带的重名,但是由于MAC系统自带的非GNU版本,会不支持部分参数。所以需要把MacPorts安装的软件修改名称(例如gfind -> find),并设定PATH将MacPorts的路径放置在前面。

Glibc和binutils需要进行小小的patch,如下:

Glibc

diff -Nupr glibc-2.10.1.orig/glibc-compat/nss_dns/dns-host.c glibc-2.10.1.new/glibc-compat/nss_dns/dns-host.c
--- glibc-2.10.1.orig/glibc-compat/nss_dns/dns-host.c    2009-11-21 15:14:42.000000000 +0800
+++ glibc-2.10.1.new/glibc-compat/nss_dns/dns-host.c    2010-04-28 12:59:52.000000000 +0800
@@ -171,7 +171,7 @@ _nss_dns_gethostbyname2_r (const char *n
   host_buffer.buf = orig_host_buffer = (querybuf *) alloca (1024);
 
   n = __libc_res_nsearch (&_res, name, C_IN, type, host_buffer.buf->buf, 1024,
-             &host_buffer.ptr);
+             &host_buffer.ptr, NULL, NULL, NULL);
   if (n < 0)
     {
       *h_errnop = h_errno;
@@ -286,7 +286,7 @@ _nss_dns_gethostbyaddr_r (const char *ad
   host_buffer.buf = orig_host_buffer = (querybuf *) alloca (1024);
 
   n = __libc_res_nquery (&_res, qbuf, C_IN, T_PTR, host_buffer.buf->buf,
-             1024, &host_buffer.ptr);
+             1024, &host_buffer.ptr, NULL, NULL, NULL);
   if (n < 0)
     {
       *h_errnop = h_errno;
diff -Nupr glibc-2.10.1.orig/glibc-compat/nss_dns/dns-network.c glibc-2.10.1.new/glibc-compat/nss_dns/dns-network.c
--- glibc-2.10.1.orig/glibc-compat/nss_dns/dns-network.c    2009-11-21 15:14:42.000000000 +0800
+++ glibc-2.10.1.new/glibc-compat/nss_dns/dns-network.c    2010-04-28 13:00:03.000000000 +0800
@@ -125,7 +125,7 @@ _nss_dns_getnetbyname_r (const char *nam
   net_buffer.buf = orig_net_buffer = (querybuf *) alloca (1024);
 
   anslen = __libc_res_nsearch (&_res, qbuf, C_IN, T_PTR, net_buffer.buf->buf,
-             1024, &net_buffer.ptr);
+             1024, &net_buffer.ptr, NULL, NULL, NULL);
   if (anslen < 0)
     {
       if (net_buffer.buf != orig_net_buffer)
@@ -197,7 +197,7 @@ _nss_dns_getnetbyaddr_r (long net, int t
   net_buffer.buf = orig_net_buffer = (querybuf *) alloca (1024);
 
   anslen = __libc_res_nquery (&_res, qbuf, C_IN, T_PTR, net_buffer.buf->buf,
-             1024, &net_buffer.ptr);
+             1024, &net_buffer.ptr, NULL, NULL, NULL);
   if (anslen < 0)
     {
       if (net_buffer.buf != orig_net_buffer)


Binutils

diff -Npur binutils-2.18.orig/bfd/doc/chew.c binutils-2.18.new/bfd/doc/chew.c
--- binutils-2.18.orig/bfd/doc/chew.c    2007-08-07 03:59:44.000000000 +0800
+++ binutils-2.18.new/bfd/doc/chew.c    2010-04-28 20:27:54.000000000 +0800
@@ -473,8 +473,8 @@ remove_noncomments (src, dst)
 static void
 print_stack_level ()
 {
- fprintf (stderr, "current string stack depth = %d, ", tos - stack);
- fprintf (stderr, "current integer stack depth = %d\n", isp - istack);
+ fprintf (stderr, "current string stack depth = %ld, ", tos - stack);
+ fprintf (stderr, "current integer stack depth = %ld\n", isp - istack);
   pc++;
 }
 
@@ -1560,7 +1560,7 @@ main (ac, av)
   write_buffer (stack + 0, stdout);
   if (tos != stack)
     {
- fprintf (stderr, "finishing with current stack level %d\n",
+ fprintf (stderr, "finishing with current stack level %ld\n",
      tos - stack);
       return 1;
     }
diff -Npur binutils-2.18.orig/binutils/strings.c binutils-2.18.new/binutils/strings.c
--- binutils-2.18.orig/binutils/strings.c    2007-08-07 03:56:15.000000000 +0800
+++ binutils-2.18.new/binutils/strings.c    2010-04-27 15:29:07.000000000 +0800
@@ -102,7 +102,7 @@ typedef off64_t file_off;
 typedef off_t file_off;
 #define file_open(s,m) fopen(s, m)
 #endif
-#ifdef HAVE_STAT64
+#if 0
 typedef struct stat64 statbuf;
 #define file_stat(f,s) stat64(f, s)
 #else


阅读(2434) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

adonishong2010-09-30 04:09:29

楼主你好, 按照你的描述, 我在我的snow leopard上重做了一遍(所有源代码均保持相同的版本), 结果在glibc最后链接ld.so的时候产生了大量undefined reference错误 经查找, 所有这些符号都是在原文件中受到libc_hidden_def修饰的, 现在不知道怎么解决了... 按照我自己的猜测, 可能是binutils或者gcc在编译的时候没有打开某个flag, 所以不支持这个特性, 或者是glibc在configure的时候没有加入某个flag, 所以找不到hidden的符号. 希望楼主能帮忙一起解决, 谢谢