#!/bin/sh

echo "Entering gstreamer.jni"
[ -d gstreamer.jni ] || exit 0
cd gstreamer.jni
echo "Done: $PWD"

# Compile java classes
mkdir -p target/classes
javac -d target/classes src/main/java/com/solaiemes/gstreamer/jni/*

# Generate C headers stubs
cd target/classes/
for i in com/solaiemes/gstreamer/jni/*
do
	name=`echo $i | cut -d'.' -f1 | sed -e "s/\//./g"`
	javah -jni $name
done

cd ../..

# Compile C sources
export PKG_CONFIG_PATH=/opt/gstreamer/lib/pkgconfig

sources=`ls src/main/native/*.c`

gcc -g -Wall -shared -fPIC -o libgstreamer-jni.so $sources -ldl `pkg-config --cflags --libs gstreamer-0.10` -I/usr/lib/jvm/java-6-sun/include -I/usr/lib/jvm/java-6-sun/include/linux -Itarget/classes

echo "Leaving gstreamer.jni"
cd ..
echo "Done: $PWD"
