#! /bin/bash
#-------------------------------------------------------------------------------

## project tree definitions.
OSM_DIR=${HOME}/osm-build


## bail immediately if error exists.
set -e


## check for limoi-core
if [ ! -d ${OSM_DIR} ]; then
    if [ ! -d ../limoi-base* ]; then
	echo "limoi-base not found, unknown source tree layout!" ;
	exit -1 ;
    else
	pushd .
	cd ../limoi-base* ;
	./osm ;
	popd
    fi
fi


## so that we can find the limoi-core package.
export PKG_CONFIG_PATH=${OSM_DIR}/lib/pkgconfig


## config and build components from sub-directories
COMPONENT_SUBDIRS=(\
    "ffmpeg" \
    "sdl" \
)
for sd in "${COMPONENT_SUBDIRS[@]}" ; do
    if [ -d ${sd} ]; then
	cd ${sd} ;
	./osm
	cd ..
    fi
done


## config and build all other components
COMPONENTS=(\
    "alsa_sink" \
    "ogg_dec" \
    "mad_dec" \
    "clock" \
    "video_scheduler" \
)

for comp in "${COMPONENTS[@]}" ; do
    if [ -d ${comp}* ]; then
	echo
	echo "config and build OpenMAX IL limoi component: $comp"
	echo
	cd ${comp}*
	autoreconf -i
	./configure --prefix=${OSM_DIR}
	make all install
	make check
	cd ..
    fi
done

echo
echo "CONGRATULATIONS, you've successfully made all limoi components."
echo "components have been installed to ${OSM_DIR}/lib/limoi."
echo
