#!/bin/bash

if [ ! -d output ]; then
	mkdir output
fi

PROJECTS="net.alcetech.Mocha.Core net.alcetech.Mocha.System"
PROJECTS_WITH_SYSTEM_REFS="net.alcetech.Mocha.Web"

if [ "$1" != "" ]; then
	PROJECT_SELECTED="$1"
fi

for p in $PROJECTS; do

	if [ "$PROJECT_SELECTED" != "" ]; then
		if [ "$p" != "$PROJECT_SELECTED" ]; then
			continue
		fi
	fi

	./yaml2mcl --export-entities=output/$p.cs -o output/$p.mcl data/libraries/yaml/$p
	Q=$?
	if [ $Q -ne 0 ]; then
		echo "error MCX9911 : build failed"
		exit $Q
	fi

done

for p in $PROJECTS_WITH_SYSTEM_REFS; do

	if [ "$PROJECT_SELECTED" != "" ]; then
                if [ "$p" != "$PROJECT_SELECTED" ]; then
                        continue
                fi
        fi

	./yaml2mcl --reference output/net.alcetech.Mocha.System.mcl --export-entities=output/$p.cs -o output/$p.mcl data/libraries/yaml/$p

done
