./configure --prefix=/usr/local/qgis \
--with-gdal=/usr/local/gdal/bin/gdal-config \
--with-pg=/usr/local/psql/bin/pg_config \
--with-grass=/usr/local/grass-5.7.0
This will configure QGIS to use GDAL, GRASS, and PostgreSQL. QGIS will be
installed in /usr/local/qgis.
If QTDIR is set and gdal-config and pg_config are both
in the PATH, there is no need to use the -with-gdal and -with-pg
options. The configure script will properly detect and configure
GDAL and PostgreSQL. You must still use the -with-grass option if building with GRASS support.