#!/bin/sh

################################################################################
#      This file is part of OpenELEC - http://www.openelec.tv
#      Copyright (C) 2009-2012 Stephan Raue (stephan@openelec.tv)
#
#  This Program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2, or (at your option)
#  any later version.
#
#  This Program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with OpenELEC.tv; see the file COPYING.  If not, write to
#  the Free Software Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110, USA.
#  http://www.gnu.org/copyleft/gpl.html
################################################################################

. config/options $1

mkdir -p $INSTALL/lib
  cp -P $PKG_BUILD/objdir-$1/elf/ld*.so* $INSTALL/lib
  cp $PKG_BUILD/objdir-$1/libc.so.6 $INSTALL/lib
  cp $PKG_BUILD/objdir-$1/math/libm.so.6 $INSTALL/lib

if [ "$TARGET_ARCH" = "arm" -a "$TARGET_FLOAT" = "hard" ]; then
  ln -sf ld.so $INSTALL/lib/ld-linux.so.3
fi

mkdir -p $INSTALL/usr/lib
  cp $PKG_BUILD/objdir-$1/crypt/libcrypt.so.1 $INSTALL/usr/lib
  cp $PKG_BUILD/objdir-$1/dlfcn/libdl.so.2 $INSTALL/usr/lib
  cp $PKG_BUILD/objdir-$1/nis/libnsl.so.1 $INSTALL/usr/lib
  cp $PKG_BUILD/objdir-$1/nis/libnss_compat.so.2 $INSTALL/usr/lib
  cp $PKG_BUILD/objdir-$1/nss/libnss_files.so.2 $INSTALL/usr/lib
  cp $PKG_BUILD/objdir-$1/resolv/libnss_dns.so.2 $INSTALL/usr/lib
  cp $PKG_BUILD/objdir-$1/resolv/libresolv.so.2 $INSTALL/usr/lib
  cp $PKG_BUILD/objdir-$1/rt/librt.so.1 $INSTALL/usr/lib
  cp $PKG_BUILD/objdir-$1/nptl/libpthread.so.0 $INSTALL/usr/lib
  cp $PKG_BUILD/objdir-$1/login/libutil.so.1 $INSTALL/usr/lib # e.g. for utmp support, needed by PAM_filter


  [ "$DEVTOOLS" = yes ] && cp $PKG_BUILD/objdir-$1/nptl_db/libthread_db.so.1 $INSTALL/usr/lib # for GDB

mkdir -p $INSTALL/usr/bin
  cp $PKG_BUILD/objdir-$1/elf/ldd $INSTALL/usr/bin
  sed -i 's%/usr/bin/bash%/bin/sh%g' $INSTALL/usr/bin/ldd

  cp $PKG_BUILD/objdir-$1/locale/locale $INSTALL/usr/bin

# libiconv replacement:
  mkdir -p $INSTALL/usr/lib/gconv
    cp $PKG_BUILD/iconvdata/gconv-modules $INSTALL/usr/lib/gconv
    cp $PKG_BUILD/objdir-$1/iconvdata/*.so $INSTALL/usr/lib/gconv

mkdir -p $INSTALL/etc
  cp $PKG_DIR/config/nsswitch.conf $INSTALL/etc
  cp $PKG_DIR/config/gai.conf $INSTALL/etc
  cp $PKG_BUILD/sunrpc/etc.rpc $INSTALL/etc/rpc
