#!/usr/bin/bash

 DIR="$( cd "$( dirname "$0" )" && pwd )"

 BASE=$DIR
 FILE="layout"
 ADD=""
 if [[ "$XDG_SESSION_TYPE" == "wayland" ]]; then
   echo "Wayland is in use."
   ADD="-platform xcb"
 fi

 if [ -f "$DIR/bin/layout" ]; then
     BASE=$DIR
     FILE=$DIR"/bin/layout"
 else 
     if [ -f "/opt/layout/bin/layout" ]; then
          BASE="/opt/layout"
          FILE="/opt/layout/bin/layout"
     else
          echo "executable not found"
          exit 1
     fi
 fi
 
 echo "LayoutEditor installed at $BASE"
 
ordPath=$(which openroad)
if [ ! -f "$ordPath" ]; then
   echo "add shpped OpenROAD to PATH"
   export PATH=$PATH:$BASE/openroad/bin
   export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$BASE/openroad/lib
fi

 if [ -d $BASE"/lib" ]; then
   # extra libraries
   export LD_LIBRARY_PATH=$BASE/lib:$LD_LIBRARY_PATH
 fi
 # XFAB dir to default installation
 if [ -z "$FTK_KIT_DIR" ]; then
    export FTK_KIT_DIR=$HOME/LayoutEditor
 fi

     echo "OpenAccess disabled"
     # start LayoutEditor without OpenAccess
     $FILE --oano "$@" $ADD


 

