# $OpenBSD$

COMMENT = Geographic Resources Analysis Support System (GIS)
GRASS_V =	7.4.3
DISTNAME = grass-${GRASS_V}
CATEGORIES = geo

HOMEPAGE =	https://grass.osgeo.org
MASTER_SITES =	https://grass.osgeo.org/grass74/source/

# GPLv2+
PERMIT_PACKAGE_CDROM =	Yes

MAINTAINER =	Landry Breuil <landry@openbsd.org>

GRASS_LIBS =	arraystats bitmap btree btree2 cairodriver calc ccmath \
	cdhc cluster datetime dbmibase dbmiclient dbmidriver \
	dbstubs dgl dig2 display driver dspf g3d gis gmath gpde \
	gproj htmldriver imagery interpdata interpfl iortho lidar \
	linkm lrs manage neta nviz ogsf pngdriver psdriver qtree \
	raster rli rowio rtree segment shape sim sqlp stats symb \
	temporal vector vedit

SO_VERSION =	0.0
.for _lib in ${GRASS_LIBS}
SHARED_LIBS +=	grass_${_lib}.${GRASS_V}	${SO_VERSION}
.endfor

MODULES=	lang/python
USE_GMAKE =	Yes
ALL_TARGET =
CONFIGURE_STYLE =	gnu
CONFIGURE_ARGS =	--with-gdal=${LOCALBASE}/bin/gdal-config \
			--with-wxwidgets=${LOCALBASE}/bin/wx-config \
			--with-geos=${LOCALBASE}/bin/geos-config \
			--with-pthread \
			--with-freetype-includes=${X11BASE}/include/freetype2/ \
			--with-freetype-libs=${X11BASE}/lib \
			--with-proj-includes=${LOCALBASE}/include \
			--with-proj-share=${LOCALBASE}/share/proj \
			--with-proj-libs=${LOCALBASE}/lib \
			--with-postgres \
			--with-postgres-includes=${LOCALBASE}/include/postgresql/ \
			--with-postgres-libs=${LOCALBASE}/lib \
			--with-x-includes=${X11BASE}/include \
			--with-x-libs=${X11BASE}/libs

#			--with-readline \
#			--with-readline-includes=${LOCALBASE}/include/ \
#			--with-readline-libs=${LOCALBASE}/lib \
#

LIB_DEPENDS =	geo/gdal \
		math/fftw3 \
		graphics/cairo \
		databases/postgresql

WANTLIB += ${COMPILER_LIBCXX} GL GLU ICE SM X11 Xext Xrender c
WANTLIB += cairo fftw3 fontconfig freetype gdal geos_c iconv m
WANTLIB += png pq proj sqlite3 tiff z

RUN_DEPENDS =	devel/desktop-file-utils \
		math/gnuplot \
		math/py-numpy \
		x11/py-wxPython \
		x11/gtk+3,-guic

CONFIGURE_ENV +=	CPPFLAGS="-I${LOCALBASE}/include -I${X11BASE}/include"
CONFIGURE_ENV +=	LDFLAGS="-L${LOCALBASE}/lib -liconv -L${X11BASE}/lib"
MAKE_ENV +=	SO_VERSION=${SO_VERSION}
CONFIGURE_ENV +=	SO_VERSION=${SO_VERSION}
COMPILER = base-clang ports-gcc
FAKE_FLAGS =	WRKINST=${WRKINST}
SUBST_VARS +=	GRASS_V

post-patch:
	# fixup bazillions shebangs
	find ${WRKSRC} -type f | xargs sed -i -e 's,#!/usr/bin/env python,#!/usr/bin/env python2,'
	# set PYTHON
	ln -sf ${MODPY_BIN} ${WRKDIR}/bin/python

post-install:
	# move docs to $PREFIX/share/docs/grass
	#mv ${PREFIX}/grass/docs ${PREFIX}/share/doc/grass
	# move python stuff to where it belongs ?
	# move includes to $PREFIX/include
	mv ${PREFIX}/grass-${GRASS_V}/include/grass ${PREFIX}/include/grass-${GRASS_V}
	# rm include/Make & config.status & toplevel stuff ?
	# move share/{metainfo,applications,icons} to PREFIX
	mv ${PREFIX}/grass-${GRASS_V}/share/{metainfo,applications,icons} ${PREFIX}/share
	rmdir ${PREFIX}/grass-${GRASS_V}/share
	# check tools and scripts

.include <bsd.port.mk>
