#!/bin/bash
# usage : ninjen LIBRARY_NAME
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

LIB=$1
WORKDIR=$SCRIPT_DIR
SRCPATH=$WORKDIR/mocha-common/data/libraries/yaml/$LIB
PREFIX=$2

if [ "$LIB" == "" ]; then

	echo "usage: ninjen LIBRARY_NAME [PREFIX]"
	exit 2
fi

YAMLFILES=$(find $SRCPATH -name '*.yaml' -type f | sed 's/ /\$ /g' | sort | tr '\n' ' ')

if [ "$PREFIX" != "" ]; then
	YAMLFILESSPACE="${YAMLFILES//"$WORKDIR"/"\$root/$PREFIX"}"
	echo "build \$root/$PREFIX/mocha-common/output/$LIB.mcl: yaml2mcl $YAMLFILESSPACE"
else
	YAMLFILESSPACE="${YAMLFILES//"$WORKDIR"/"\$root"}"
	echo "build \$root/mocha-common/output/$LIB.mcl: yaml2mcl $YAMLFILESSPACE"
fi