#!/bin/sh

################################################################################
#      This file is part of OpenELEC - http://www.openelec.tv
#      Copyright (C) 2009-2011 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, 675 Mass Ave, Cambridge, MA 02139, USA.
#  http://www.gnu.org/copyleft/gpl.html
################################################################################

. config/options

PKG_DIR=`find $PACKAGES -type d -name $1`

mkdir -p $INSTALL/etc/bluetooth
  cp $PKG_BUILD/src/main.conf $INSTALL/etc/bluetooth
  cp $PKG_BUILD/tools/rfcomm.conf $INSTALL/etc/bluetooth
  cp $PKG_BUILD/audio/audio.conf $INSTALL/etc/bluetooth
  cp $PKG_BUILD/input/input.conf $INSTALL/etc/bluetooth

mkdir -p $INSTALL/etc/dbus-1/system.d
  cp $PKG_BUILD/src/bluetooth.conf $INSTALL/etc/dbus-1/system.d

mkdir -p $INSTALL/lib/udev
# not needed:  cp $PKG_BUILD/scripts/bluetooth_serial $INSTALL/lib/udev
# not needed:  chmod +x $INSTALL/lib/udev/bluetooth_serial
  cp $PKG_BUILD/tools/hid2hci $INSTALL/lib/udev

mkdir -p $INSTALL/lib/udev/rules.d
  cp $PKG_BUILD/scripts/97-bluetooth.rules $INSTALL/lib/udev/rules.d
# todo:        cp $PKG_BUILD/scripts/97-bluetooth-hid2hci.rules $INSTALL/lib/udev/rules.d
# not needed:  cp $PKG_BUILD/scripts/97-bluetooth-serial.rules $INSTALL/lib/udev/rules.d

mkdir -p $INSTALL/usr/lib
  cp -P $PKG_BUILD/lib/.libs/libbluetooth.so* $INSTALL/usr/lib

mkdir -p $INSTALL/usr/lib/alsa
  cp $PKG_BUILD/audio/.libs/*.so $INSTALL/usr/lib/alsa

mkdir -p $INSTALL/usr/lib/bluetooth/plugins

mkdir -p $INSTALL/usr/sbin
  cp $PKG_BUILD/src/.libs/bluetoothd $INSTALL/usr/sbin

mkdir -p $INSTALL/usr/share/alsa
  cp $PKG_BUILD/audio/bluetooth.conf $INSTALL/usr/share/alsa

if [ "$DEVTOOLS" = "yes" ]; then
  mkdir -p $INSTALL/usr/bin
    cp $PKG_BUILD/tools/.libs/ciptool $INSTALL/usr/bin
    cp $PKG_BUILD/tools/dfutool $INSTALL/usr/bin
    cp $PKG_BUILD/tools/.libs/hcitool $INSTALL/usr/bin
    cp $PKG_BUILD/tools/.libs/l2ping $INSTALL/usr/bin
    cp $PKG_BUILD/test/.libs/l2test $INSTALL/usr/bin
    cp $PKG_BUILD/test/.libs/rctest $INSTALL/usr/bin
    cp $PKG_BUILD/tools/.libs/rfcomm $INSTALL/usr/bin
    cp $PKG_BUILD/tools/.libs/sdptool $INSTALL/usr/bin

mkdir -p $INSTALL/usr/sbin
  cp $PKG_BUILD/tools/.libs/bccmd $INSTALL/usr/sbin # TODO
  cp $PKG_BUILD/tools/.libs/hciattach $INSTALL/usr/sbin
  cp $PKG_BUILD/tools/.libs/hciconfig $INSTALL/usr/sbin
  cp $PKG_BUILD/test/.libs/hciemu $INSTALL/usr/sbin
fi

