# $Id: Portfile 106731 2013-06-06 21:05:42Z g5pw@macports.org $

PortSystem 1.0

name              grass
epoch             1
version           6.4.2
revision          3
maintainers       nomaintainer
categories        gis
license           GPL-2+
platforms         darwin

description       GRASS
long_description  GRASS is a Geographic Information System (GIS) used for \
                  geospatial data management and analysis.

homepage          http://grass.osgeo.org/
master_sites      ${homepage}grass[join [lrange [split ${version} .] 0 1] {}]/source/

checksums         rmd160  2a8a2a63edf8e1cc53b7b26975087eef59c9a397 \
                  sha256  670bb74d3000ea0932b7e988d3080d0c629f9eb22a8479bb2987ded473f7b4ca

depends_build     port:pkgconfig
depends_lib       port:fftw-3 \
                  port:freetype \
                  port:gdal \
                  port:geos \
                  port:jpeg \
                  port:libpng \
                  port:mesa \
                  lib:libXm:openmotif \
                  port:proj47 \
                  port:tk \
                  path:lib/pkgconfig/cairo.pc:cairo \
                  port:readline

use_parallel_build yes

# https://trac.macports.org/ticket/32790
# this should probably only apply to some Xcode versions
compiler.blacklist  clang

patchfiles \
    patch-Makefile.diff \
    patch-configure.diff \
    patch-macosx_Makefile.diff \
    patch-visualization_nviz_src-draw_c.diff

# List of all python scripts. Used later to ensure usage of python27 (and not
# the currently active python)
# Work around bug http://trac.osgeo.org/grass/ticket/1758
depends_build-append    port:python27
set python_scripts [ list \
    doc/python/example_ctypes.py \
    general/g.parser/test.py \
    gui/scripts/g.change.gui.py \
    gui/scripts/g.extension.py \
    gui/scripts/g.extension.rebuild.all.py \
    gui/scripts/v.type_wrapper.py \
    gui/wxpython/gui_modules/gmodeler.py \
    gui/wxpython/gui_modules/menuform.py \
    gui/wxpython/scripts/d.rast3d.py \
    gui/wxpython/scripts/p.cmd.py \
    gui/wxpython/scripts/p.db.py \
    gui/wxpython/scripts/p.mon.py \
    gui/wxpython/scripts/p.rast.py \
    gui/wxpython/scripts/p.vect.py \
    imagery/i.atcorr/create_iwave.py \
    lib/python/ctypes/ctypesgen.py \
    lib/python/ctypes/ctypesgencore/__init__.py \
    lib/python/ctypes/ctypesgencore/ctypedescs.py \
    lib/python/ctypes/ctypesgencore/descriptions.py \
    lib/python/ctypes/ctypesgencore/expressions.py \
    lib/python/ctypes/ctypesgencore/messages.py \
    lib/python/ctypes/ctypesgencore/options.py \
    lib/python/ctypes/ctypesgencore/parser/__init__.py \
    lib/python/ctypes/ctypesgencore/parser/cdeclarations.py \
    lib/python/ctypes/ctypesgencore/parser/cgrammar.py \
    lib/python/ctypes/ctypesgencore/parser/cparser.py \
    lib/python/ctypes/ctypesgencore/parser/ctypesparser.py \
    lib/python/ctypes/ctypesgencore/parser/datacollectingparser.py \
    lib/python/ctypes/ctypesgencore/parser/pplexer.py \
    lib/python/ctypes/ctypesgencore/parser/preprocessor.py \
    lib/python/ctypes/ctypesgencore/printer/__init__.py \
    lib/python/ctypes/ctypesgencore/printer/printer.py \
    lib/python/ctypes/ctypesgencore/processor/__init__.py \
    lib/python/ctypes/ctypesgencore/processor/dependencies.py \
    lib/python/ctypes/ctypesgencore/processor/operations.py \
    lib/python/ctypes/ctypesgencore/processor/pipeline.py ]

post-patch {
   reinplace "s|@@APPLICATIONS_DIR@@|${applications_dir}|" \
      ${worksrcpath}/configure
   foreach f $python_scripts {
       reinplace "s|/usr/bin/env python|${prefix}/bin/python2.7|" $f
   }
}

configure.ldflags-append -framework OpenGL -framework Accelerate
configure.args \
    --with-fftw-includes=${prefix}/include \
    --with-fftw-libs=${prefix}/lib \
    --with-freetype \
    --with-freetype-includes=${prefix}/include/freetype2 \
    --with-freetype-libs=${prefix}/lib \
    --with-gdal=${prefix}/bin/gdal-config \
    --with-jpeg-includes=${prefix}/include \
    --with-jpeg-libs=${prefix}/lib \
    --with-motif \
    --with-motif-includes=${prefix}/include \
    --with-motif-libs=${prefix}/lib \
    --with-png-includes=${prefix}/include \
    --with-png-libs=${prefix}/lib \
    --with-proj-includes=${prefix}/lib/proj47/include \
    --with-proj-libs=${prefix}/lib/proj47/lib \
    --with-proj-share=${prefix}/lib/proj47/share/proj \
    --with-tcltk-includes=${prefix}/include \
    --with-tcltk-libs=${prefix}/lib \
    --with-cxx \
    --with-x \
    --without-postgres \
    --disable-python \
    --disable-wxwidgets \
    --enable-largefile \
    --with-cairo \
    --with-cairo-includes=${prefix}/include/cairo \
    --with-cairo-libs=${prefix}/lib \
    --with-blas \
    --with-lapack \
    --with-readline \
    --with-readline-includes=${prefix}/include/readline \
    --with-readline-libs=${prefix}/lib \
    --with-regex-includes=/usr/include \
    --with-regex-lib=/usr/lib

build.target    default

build.args-append PYTHON=${frameworks_dir}/Python.framework/Versions/2.7/bin/python2.7

variant mysql5 description {Add MySQL 5 support} {
    depends_lib-append    path:bin/mysql_config5:mysql5
    configure.args-append --with-mysql
    configure.args-append --with-mysql-includes=${prefix}/include/mysql5/mysql
    configure.args-append --with-mysql-libs=${prefix}/lib/mysql5/mysql
    configure.env-append MYSQLD_CONFIG=${prefix}/lib/mysql5/bin/mysql_config
}

variant postgresql83 conflicts postgresql84 postgresql90 postgresql91 description {Add PostgreSQL 8.3 support} {
    depends_lib-append    port:postgresql83
    configure.args-delete --without-postgres
    configure.args-append --with-postgres
    configure.args-append --with-postgres-includes=${prefix}/include/postgresql83
    configure.args-append --with-postgres-libs=${prefix}/lib/postgresql83
}

variant postgresql84 conflicts postgresql83 postgresql90 postgresql91 description {Add PostgreSQL 8.4 support} {
    depends_lib-append    port:postgresql84
    configure.args-delete --without-postgres
    configure.args-append --with-postgres
    configure.args-append --with-postgres-includes=${prefix}/include/postgresql84
    configure.args-append --with-postgres-libs=${prefix}/lib/postgresql84
}

variant postgresql90 conflicts postgresql83 postgresql84 postgresql91 description {Add PostgreSQL 9.0 support} {
    depends_lib-append    port:postgresql90
    configure.args-delete --without-postgres
    configure.args-append --with-postgres
    configure.args-append --with-postgres-includes=${prefix}/include/postgresql90
    configure.args-append --with-postgres-libs=${prefix}/lib/postgresql90
}

variant postgresql91 conflicts postgresql83 postgresql84 postgresql90 description {Add PostgreSQL 9.1 support} {
    depends_lib-append    port:postgresql91
    configure.args-delete --without-postgres
    configure.args-append --with-postgres
    configure.args-append --with-postgres-includes=${prefix}/include/postgresql91
    configure.args-append --with-postgres-libs=${prefix}/lib/postgresql91
}

variant sqlite3 description {Add SQLite 3 support} {
    depends_lib-append    port:sqlite3
    configure.args-append --with-sqlite
    configure.args-append --with-sqlite-includes=${prefix}/include
    configure.args-append --with-sqlite-libs=${prefix}/lib
}

variant ffmpeg description {Add ffmpeg support} {
    depends_lib-append    path:lib/libavcodec.dylib:ffmpeg
    configure.args-append --with-ffmpeg \
                          --with-ffmpeg-includes=\"${prefix}/include/libavcodec  \
                                                   ${prefix}/include/libavformat \
                                                   ${prefix}/include/libswscale\" \
                          --with-ffmpeglibs=${prefix}/lib
}

variant wxwidgets description {Add WXWidgets support} {
    depends_lib-append	  port:wxwidgets30
    configure.args-delete --disable-wxwidgets
    configure.args-append --with-wxwidgets=${prefix}/bin/wx-config
}

variant wxPython requires wxwidgets description {Enable support for wxGUI Python extensions} {
    depends_lib			  port:py27-wxpython30
    configure.args-delete --disable-python
    configure.args-append --with-python=${frameworks_dir}/Python.framework/Versions/2.7/bin/python2.7-config
}

livecheck.type      regex
livecheck.url       http://grass.osgeo.org/devel/svntags.php
livecheck.regex     {GRASS ([0-9.]+):}
