SUMMARY="IDE for the Arduino embedded hardware family"
DESCRIPTION="The open-source Arduino Software (IDE) makes it easy to write code \
and upload it to the board. It runs on Windows, Mac OS X, and Linux. \
The environment is written in Java and based on Processing and other \
open-source software."
HOMEPAGE="http://arduino.cc"
LICENSE="GNU GPL v2"
COPYRIGHT="Arduino team"

SOURCE_URI="http://downloads.arduino.cc/arduino-1.0.6-linux32.tgz"
CHECKSUM_SHA256="f059a572231abafb92099a3a404c0a41502c3413668610676c40029384edc658"
REVISION="1"

ARCHITECTURES="x86 ?x86_64"
if [ $effectiveTargetArchitecture != x86_gcc2 ]; then
    ARCHITECTURES="$ARCHITECTURES x86_gcc2"
else
    ARCHITECTURES="$ARCHITECTURES !x86_gcc2"
fi
SECONDARY_ARCHITECTURES="x86"

PATCHES="arduino_x86-1.0.6.patchset"

PROVIDES="
	arduino$secondaryArchSuffix = $portVersion
	app:Arduino$secondaryArchSuffix = $portVersion
	"

REQUIRES="
	haiku$secondaryArchSuffix
	openjdk$secondaryArchSuffix
	rxtx$secondaryArchSuffix
	cmd:avrdude$secondaryArchSuffix
	avr_libc$secondaryArchSuffix
	avr_gcc$secondaryArchSuffix
	avr_binutils$secondaryArchSuffix
	"
BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	"
BUILD_PREREQUIRES="
	cmd:gcc
	cmd:make	
	"

SOURCE_DIR="arduino-1.0.6"

BUILD()
{
	cd haiku
	make
}

INSTALL()
{
	arduinoDir=$appsDir/Arduino
	mkdir -p $arduinoDir
	
	cp -r examples $arduinoDir
	cp -r libraries $arduinoDir
	cp -r reference $arduinoDir
	cp -r lib $arduinoDir
	cp -r tools $arduinoDir
	rm $arduinoDir/lib/RXTXcomm.jar
	rm $arduinoDir/lib/librxtxSerial.so
	rm $arduinoDir/lib/librxtxSerial64.so
	
	mkdir -p $arduinoDir/hardware
	cp -r hardware/arduino $arduinoDir/hardware
	
	mkdir -p $arduinoDir/hardware/tools
	cp hardware/tools/avrdude.conf $arduinoDir/hardware/tools
	ln -s /bin/x86/avrdude $arduinoDir/hardware/tools/avrdude
	
	mkdir -p $arduinoDir/hardware/tools/avr
	ln -s /bin/x86 $arduinoDir/hardware/tools/avr/bin
	mkdir -p $arduinoDir/hardware/tools/avr/bin.gcc
	ln -s /bin/x86/avr-cpp $arduinoDir/hardware/tools/avr/bin.gcc/avr-cpp
	ln -s /bin/x86/avr-g++ $arduinoDir/hardware/tools/avr/bin.gcc/avr-g++
	ln -s /bin/x86/avr-gcc $arduinoDir/hardware/tools/avr/bin.gcc/avr-gcc
	mkdir -p $arduinoDir/hardware/tools/avr/etc
	ln -s /system/settings/avrdude.conf $arduinoDir/hardware/tools/avr/etc/avrdude.conf
	
	echo '#!/bin/sh
APPDIR="$(dirname -- "$(readlink -f -- "${0}")" )"
cd "$APPDIR"
for LIB in \
    java/lib/rt.jar \
    java/lib/tools.jar \
    lib/*.jar \
    ;
do
    CLASSPATH="${CLASSPATH}:${LIB}"
done
export CLASSPATH
LD_LIBRARY_PATH=`pwd`/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
export LD_LIBRARY_PATH
export PATH="${APPDIR}/java/bin:${PATH}"
java processing.app.Base "$@"
' > $arduinoDir/arduino.sh
	
	chmod +x $arduinoDir/arduino.sh
		
	cp "haiku/Arduino IDE" $arduinoDir	
	cp revisions.txt $arduinoDir
	
	addAppDeskbarSymlink "$arduinoDir/Arduino IDE"
}
