martedì 3 febbraio 2009

Gdal e Grass from source in Ubuntu Intrepid Ibex - 2

Faccio un seguito a questo precedente blog: installare GDAL  e GRASS  da sorgente è un tormentone, almeno per me.

Ecco gli appunti che uso, sotto forma di script; spero possano essere utili a qualcuno.

Non lanciare alla cieca lo script: quasi sicuramente non funzionarà; leggerlo per capire le diverse operazioni ed eventualmente modificarlo. Gran parte del contenuto è tratto dai link riportati.

#! /usr/bin/env bash
# # # january 2009
# # # this isn't a script! It's a reminder only
# # # SO THINK TWICE BEFORE RUNNING (AT YOUR OWN RISK)

# # # you should read these links before try:
# # # http://grass.osgeo.org/wiki/Compile_and_Install
# # # http://grass.osgeo.org/grass64/source/REQUIREMENTS.html
# # # http://casoilresource.lawr.ucdavis.edu/drupal/node/123
# # # http://mpa.itc.it/markus/useful/conf_install_gdal_ogr_grass_plugin.sh
# # # http://trac.osgeo.org/gdal/wiki/GRASS
# # # http://trac.osgeo.org/gdal/wiki/BuildingOnUnix

PROGRAM=`basename $0`
CURRENTDIR="`pwd`"

# # # change

# # # gdal source directory
DIR_SRC_GDAL="/usr/local/src/gdal"
# # # gdal install directory
DIR_INST_GDAL="/usr/local"
# # # grass source directory
DIR_SRC_GRASS="/usr/local/src/grass6_devel"
# # # grass install directory
DIR_INST_GRASS="/usr/local/grass-6.5.svn"
# # # plugin grass-gdal source directory
DIR_SRC_PLUGIN="/usr/local/src/gdal-grass-1.4.3"
# # # plugin grass-gdal install directory
DIR_INST_PLUGIN="/usr/local/lib/gdalplugins"


# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
ask_yes_no()
{
local yn=
while [ "$yn" = "" ]; do
echo "$1"
read yn
case $yn in
y|Y) yn=0 ;;
n|N) yn=1 ;;
e|E)
# cd ${CURRENTDIR}
exit 1 ;;
*) yn=
echo "Invalid response - please answer y or n"
;;
esac
done
return $yn
}

if ask_yes_no "Update/upgrade system [Y/N/(E)xit] ?"; then
sudo apt-get update
sudo apt-get upgrade
fi

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # #
# # # GDAL - Geospatial Data Abstraction Library
# # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

# # # cleaning
if ask_yes_no "Clean GDAL source [Y/N/(E)xit] ?"; then
cd ${DIR_SRC_GDAL}
make distclean
fi

# # # upgrade from svn
if ask_yes_no "Upgrade GDAL source from svn [Y/N/(E)xit] ?"; then
# # #
# # # FIRST INSTALL:
# # # sudo mkdir /usr/local/src
# # # sudo chown my_user_name:my_user_group /usr/local/src/
# # # cd /usr/local/src
# # # current development version:
# # # svn checkout https://svn.osgeo.org/gdal/trunk/gdal gdal
# # # current stable version:
# # # svn checkout https://svn.osgeo.org/gdal/branches/1.5/gdal gdal
# # #
# # # AFTER FIRST INSTALL:
cd ${DIR_SRC_GDAL}
svn up
cd ${CURRENTDIR}
fi

# # # configure ***WITHOUT GRASS***
if ask_yes_no "Configure GDAL [Y/N/(E)xit] ?"; then
cd ${DIR_SRC_GDAL}
./configure \
--with-pg=/usr/bin/pg_config \
--prefix=${DIR_INST_GDAL} \
--with-python \
--with-ogdi \
--with-sqlite \
--with-mysql=/usr/bin/mysql_config \
--with-libtiff=internal \
--without-grass \
-with-hide-internal-symbols
cd ${CURRENTDIR}
fi

# # # make
if ask_yes_no "Make GDAL [Y/N/(E)xit] ?"; then
cd ${DIR_SRC_GDAL}
make
cd ${CURRENTDIR}
fi

# # # make install
if ask_yes_no "Install GDAL [Y/N/(E)xit] ?"; then
cd ${DIR_SRC_GDAL}
sudo make install
cd ${CURRENTDIR}
fi

# # # Is directory, where binary have been installed, in PATH variable?
if ask_yes_no "Check if PATH variable contains path to GDAL binaries [Y/N/(E)xit] ?"; then
echo "GDAL binary are here ...${DIR_INST_GDAL}/bin"
echo ""
cd "${DIR_INST_GDAL}/bin"
ls -l
echo "PATH variable:"
echo "$PATH"
fi

if ask_yes_no "You can change PATH variable now...[Y/N/(E)xit] ?"; then
echo "There many ways to do this; perhaps you can modify .bashrc..."
gedit $HOME/.bashrc
fi

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # #
# # # GRASS GIS (Geographic Resources Analysis Support System)
# # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

# # # cleaning
if ask_yes_no "Clean GRASS source[Y/N/(E)xit] ?"; then
cd ${DIR_SRC_GRASS}
make distclean
cd ${CURRENTDIR}
fi

# # # upgrade from svn
if ask_yes_no "Upgrade GRASS from svn [Y/N/(E)xit] ?"; then
# # #
# # # FIRST INSTALL: (6.5.0 development branch)
# # # Note: development here is discouraged and
# # # should take place in GRASS 7.
# # #
# # # svn checkout https://svn.osgeo.org/grass/grass/branches/develbranch_6 grass6_devel
# # # To switch from SVN 'trunk' (now GRASS 7 development)
# # # to 'develbranch_6' (now GRASS 6.4 development) use
# # # cd /path/to/your/local/copy/trunk
# # # svn switch https://svn.osgeo.org/grass/grass/branches/develbranch_6 .
# # #
# # # AFTER FIRST INSTALL:
cd ${DIR_SRC_GRASS}
svn up
cd ${CURRENTDIR}
fi

# # # configure GRASS
if ask_yes_no "Configure GRASS [Y/N/(E)xit] ?"; then
cd ${DIR_SRC_GRASS}
# # # --with-gdal="${DIR_INST_GDAL}/bin/gdal-config" \
# # # CFLAGS="-O2 -march=pentium-m -Wall" LDFLAGS="-s"
# # # CFLAGS="-ggdb -Wall -Werror-implicit-function-declaration"
CFLAGS="-g -Wall" LDFLAGS="-s" ./configure \
--with-gdal="${DIR_INST_GDAL}/bin/gdal-config" \
--with-tcltk-includes=/usr/include/tcl8.5 \
--with-postgres=yes \
--with-postgres-includes=/usr/include/postgresql \
--with-sqlite \
--with-cxx \
--with-blas \
--with-lapack \
--with-cairo \
--with-fftw \
--with-freetype=yes \
--with-freetype-includes=/usr/include/freetype2 \
--with-readline \
--with-opengl-includes=/usr/include/GL \
--with-mysql \
--with-mysql-includes=/usr/include/mysql \
--with-python=/usr/bin/python2.5-config \
--with-wxwidgets=/usr/bin/wx-config \
--enable-largefile=yes \
--with-proj-includes=/usr/include \
--with-proj-share=/usr/share/proj \
--with-proj-libs=/usr/lib
cd ${CURRENTDIR}
fi

# # # make
if ask_yes_no "Make GRASS [Y/N/(E)xit] ?"; then
cd ${DIR_SRC_GRASS}
make
cd ${CURRENTDIR}
fi

# # # make vdigit nviz
if ask_yes_no "Make vdigit and nviz [Y/N/(E)xit] ?"; then
# # # symbolic link (overwrite if exists)
sudo ln -s -f /usr/lib/python2.5/site-packages/wx-2.8-gtk2-unicode/wx/_gdi_.so \
/usr/local/lib/libgdi.so
cd "${DIR_SRC_GRASS}/gui/wxpython/vdigit"
make
cd "${DIR_SRC_GRASS}/gui/wxpython/nviz"
make
cd ${CURRENTDIR}
fi

# # # make install
if ask_yes_no "Install GRASS [Y/N/(E)xit] ?"; then
cd ${DIR_SRC_GRASS}
sudo make install
cd ${CURRENTDIR}
fi

# # # check/set/modify shared library
if ask_yes_no "Check ld.so.conf [Y/N/(E)xit] ?"; then
echo ""
echo "REMEMBER: ${DIR_INST_GRASS}/lib must be shared!"
echo ""
cat /etc/ld.so.conf
fi
# # # /etc/ld.so.conf
if ask_yes_no "Modify ld.so.conf [Y/N/(E)xit] ?"; then
sudo gedit /etc/ld.so.conf
sudo ldconfig
fi

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # #
# # # PLUGIN GDAL - GRASS
# # # http://download.osgeo.org/gdal/gdal-grass-1.4.3.tar.gz
# # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

if ask_yes_no "Compile gdal-grass plugin [Y/N/(E)xit] ?"; then
# # # FIRST INSTALL
# # # cd /usr/local/src
# # # tar xfvz gdal-grass-1.4.3.tar.gz
# # # AFTER FIRST INSTALL:
cd ${DIR_INST_GDAL}/lib
# # # link GRASS libs to the lib/ folder
sudo ln -sf ${DIR_INST_GRASS}/lib/*.so .
cd ${DIR_SRC_PLUGIN}
make distclean

./configure --with-grass=${DIR_INST_GRASS} \
--with-gdal=${DIR_INST_GDAL}/bin/gdal-config \
--with-autoload=${DIR_INST_PLUGIN} \
--with-ld-shared="g++ -shared"

make
# # # sudo mkdir /usr/local/lib/gdalplugins # # # first install
sudo cp *.so ${DIR_INST_PLUGIN}
fi


Nessun commento:

Posta un commento