# Description: The C library used in the GNU system
# URL: http://www.gnu.org/software/libc/
# Maintainer: CRUX System Team, core-ports at crux dot nu
# Arch Maintainer: CRUX-ARM System Team, devel at crux-arm dot nu
# Depends on:

name=glibc
version=2.10.1
release=1
source=(ftp://ftp.gnu.org/gnu/$name/$name-$version.tar.bz2 \
        ftp://ftp.gnu.org/gnu/$name/$name-ports-$version.tar.bz2 \
        ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.29.tar.bz2 \
        $name-$version-cross_hacks-2.patch \
        hosts resolv.conf nsswitch.conf host.conf ld.so.conf)

build() {
  # install build kernel headers
  cd linux-2.6.29
  make mrproper
  make ARCH=arm headers_check
  make ARCH=arm INSTALL_HDR_PATH=$PKG/usr headers_install

  cd $SRC
  mv $name-ports-$version $name-$version/ports

  pushd $name-$version
  patch -p1 -i $SRC/$name-$version-cross_hacks-2.patch
  popd

  mkdir build
  cd build

  cat > config.cache << EOF
libc_cv_gnu89_inline=yes
ac_cv_sizeof_long_double=0
EOF

  ../$name-$version/configure --build=$CHOST \
                              --host=$CTARGET \
                              --prefix=/usr \
                              --libexecdir=/usr/lib \
                              --with-headers=$PKG/usr/include \
                              --with-tls \
                              --enable-kernel=2.6.0 \
                              --enable-add-ons \
                              --disable-profile \
                              --without-gd \
                              --with-__thread 

  make CC="$CC" CFLAGS="$CFLAGS"
  make install_root=$PKG install

  cp $SRC/{hosts,resolv.conf,nsswitch.conf,host.conf,ld.so.conf} $PKG/etc
  ln -sf ../usr/share/zoneinfo/UTC $PKG/etc/localtime
  mkdir -p $PKG/etc/ld.so.conf.d $PKG/usr/lib/locale

  # conflicts with quota
  rm $PKG/usr/include/rpcsvc/{rquota.x,rquota.h}
  rm -rf $PKG/usr/share/{info,locale}
}