#!/bin/sh

# MN 2005
#    3, 2006
#

# HOWTO compile GDAL-OGR/GRASS-plugin:
#  1. compile GDAL without GRASS support (see ./conf_gdal.sh )
#  2. compile GRASS itself (see ./conf_grass61_linux.sh )
#  3. run this script to configure/compile/install GDAL/GRASS plugin
#  4. link GRASS libs:
#      add a file 'grass6.conf' into the directory /etc/ld.so.conf.d
#      (edit as root) which contains the path to the GRASS libraries 
#  5. run 'ldconfig' (as root)

# See also: http://grass.gdf-hannover.de/wiki/Compile_and_install_GRASS_and_QGIS_with_GDAL/OGR_Plugin

# check/update paths:
AUTOLOAD=/usr/local/lib/gdalplugins
GRASSBINARIES=$HOME/grass63/dist.$HOSTTYPE-unknown-linux-gnu

#### nothing to change below ######################################

#for the first time, paranoia:
test -d $AUTOLOAD || mkdir $AUTOLOAD

#cleanup:
rm -f $AUTOLOAD/gdal_GRASS.so

#building GRASS 6 plugin support
(
 cd frmts/grass/pkg/ 
 ./configure --with-grass=${GRASSBINARIES} \
   --with-autoload=${AUTOLOAD}  --with-ld-shared="g++ -shared"

 if [ $? -eq 1 ] ; then
         echo "an error occured"
         exit
 fi
 
 ln -sf ../*.cpp .
 ln -sf ../../../ogr/ogrsf_frmts/grass/*.cpp .
 ln -sf ../../../ogr/ogrsf_frmts/grass/*.h .
 make

 #this may need 'su' to become root user:
 make install
 make clean
)


