#!/bin/sh

. config/options

if [ "$2" = toolchain ]; then
  rm -rf "$SYSROOT_PREFIX/lib" "$SYSROOT_PREFIX/usr/lib" "$SYSROOT_PREFIX/usr/include"
  $SCRIPTS/install linux-headers
  make -C $PKG_BUILD PREFIX="$SYSROOT_PREFIX" install
  exit 0
fi

if [ "$2" = initramfs ]; then
  mkdir -p $INSTALL/$2/lib
  cp $PKG_BUILD/lib/ld-uClibc.so.0 $INSTALL/$2/lib
  cp $PKG_BUILD/lib/libc.so.0 $INSTALL/$2/lib
  exit 0
fi

    mkdir -p $INSTALL/lib
    cp $PKG_BUILD/lib/ld*-uClibc.so.0 $INSTALL/lib
    cp $PKG_BUILD/lib/libc.so.0 $INSTALL/lib
    cp $PKG_BUILD/lib/libdl.so.0 $INSTALL/lib
    cp $PKG_BUILD/lib/libpthread.so.0 $INSTALL/lib
    cp $PKG_BUILD/lib/libm.so.0 $INSTALL/lib
    cp $PKG_BUILD/lib/libutil.so.0 $INSTALL/lib
    cp $PKG_BUILD/lib/librt.so.0 $INSTALL/lib

# needed by dbus-glib
    cp $PKG_BUILD/lib/libnsl.so.0 $INSTALL/lib

    [ "$DEVTOOLS" = yes ] && cp $PKG_BUILD/lib/libthread_db.so.1 $INSTALL/lib
    [ "$NETWORK" = yes ] && cp $PKG_BUILD/lib/libcrypt.so.0 $INSTALL/lib
    [ "$NETWORK" = yes ] && cp $PKG_BUILD/lib/libresolv.so.0 $INSTALL/lib

    [ "$DEVTOOLS" = yes ] && \
      mkdir -p $INSTALL/bin && \
      cp $PKG_BUILD/utils/ldd $INSTALL/bin

    [ -n "$TIMEZONE" ] && mkdir -p $INSTALL/etc && echo -n "$TIMEZONE" > $INSTALL/etc/TZ

exit 0
