#!/bin/bash
# initialize target directory (plugin, internationalization, themes)
# User: klose at 16:54 09.01.2012

PROFILE=$(basename $PWD)
PROJECT_DIR="$(dirname $0)"

rm -rf Plugins
rm -rf Themes
mkdir -p Plugins


if [ -x $PROJECT_DIR/../Plugins/ApoIdent ]
then
  echo Found Plugin: ApoIdent
  ln -sf $PROJECT_DIR/../Plugins/ApoIdent/ApoIdent/bin/$PROFILE Plugins/ApoIdent
fi

if [ -x $PROJECT_DIR/../Plugins ]
then
  for PROJECT in `find $PROJECT_DIR/../Plugins/ -name '*.csproj'`
  do
    PLUGIN=`basename $PROJECT .csproj`
    if [ -d $PROJECT_DIR/../Plugins/$PLUGIN/bin/$PROFILE ]
    then
      echo Found Plugin: $PLUGIN
	  ln -sf $PROJECT_DIR/../Plugins/$PLUGIN/bin/$PROFILE Plugins/$PLUGIN
	fi
  done
fi

if [ -x $PROJECT_DIR/../Pluginscs ]
then
  for PROJECT in `find $PROJECT_DIR/../Pluginscs/ -name '*.csproj'`
  do
    PLUGIN=`basename $PROJECT .csproj`
    if [ -d $PROJECT_DIR/../Pluginscs/$PLUGIN/bin/$PROFILE ]
    then
      echo Found Plugin: $PLUGIN
	  ln -sf $PROJECT_DIR/../Pluginscs/$PLUGIN/bin/$PROFILE Plugins/$PLUGIN
	fi
  done
fi

# FIXME: Remove/update this, once I18n is split up over projects.
if [ -x $PROJECT_DIR/../../Internationalization/Internationalization ]
then
  for PO in `find $PROJECT_DIR/../../Internationalization/Internationalization -name '??.po'`
  do
    LOCALIZATION=`basename $PO .po`
    echo Found localization: $LOCALIZATION
    mkdir -p $LOCALIZATION/LC_MESSAGES
    msgfmt -o $LOCALIZATION/LC_MESSAGES/Hiperscan.mo $PO
  done
fi

if [ -x $PROJECT_DIR/../Installer/Themes ]
then
  ln -sf $PROJECT_DIR/../Installer/Themes
fi
