Browse Source

Add HAVE_GDAL
Enable GDAL-link/r.external functionality
Improve failure mode if GDAL links are used in a version built without GDAL


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@33141 15284696-431f-4ddb-bdfa-cd5b030d7da7

Glynn Clements 16 năm trước cách đây
mục cha
commit
66e9f4366a

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 440 - 435
configure


+ 11 - 9
configure.in

@@ -636,6 +636,11 @@ AC_SUBST(JPEGLIB)
 
 
 AC_MSG_CHECKING(whether to use GDAL)
 AC_MSG_CHECKING(whether to use GDAL)
 
 
+GDAL_LIBS=
+GDAL_CFLAGS=
+USE_GDAL=
+USE_OGR=
+
 if test "`basename xx/$with_gdal`" = "gdal-config" ; then
 if test "`basename xx/$with_gdal`" = "gdal-config" ; then
   GDAL_CONFIG="$with_gdal"
   GDAL_CONFIG="$with_gdal"
 fi
 fi
@@ -650,11 +655,6 @@ else
     AC_MSG_ERROR([*** couldn't find gdal-config])
     AC_MSG_ERROR([*** couldn't find gdal-config])
   fi
   fi
 
 
-  GDAL_LIBS=
-  GDAL_CFLAGS=
-  USE_GDAL=
-  USE_OGR=
-
   if test "$GDAL_CONFIG" != "" ; then
   if test "$GDAL_CONFIG" != "" ; then
     GDAL_LIBS=`"$GDAL_CONFIG" --libs`
     GDAL_LIBS=`"$GDAL_CONFIG" --libs`
     GDAL_DEP_LIBS=`"$GDAL_CONFIG" --dep-libs`
     GDAL_DEP_LIBS=`"$GDAL_CONFIG" --dep-libs`
@@ -680,12 +680,14 @@ else
   LIBS=${ac_save_libs}
   LIBS=${ac_save_libs}
   CFLAGS=${ac_save_cflags}
   CFLAGS=${ac_save_cflags}
 
 
-  AC_SUBST(GDAL_LIBS)
-  AC_SUBST(GDAL_CFLAGS)
-  AC_SUBST(USE_GDAL)
-  AC_SUBST(USE_OGR)
+  AC_DEFINE(HAVE_GDAL)
 fi
 fi
 
 
+AC_SUBST(GDAL_LIBS)
+AC_SUBST(GDAL_CFLAGS)
+AC_SUBST(USE_GDAL)
+AC_SUBST(USE_OGR)
+
 # Enable TIFF option
 # Enable TIFF option
 
 
 LOC_CHECK_USE(tiff,TIFF,USE_TIFF)
 LOC_CHECK_USE(tiff,TIFF,USE_TIFF)

+ 3 - 0
include/config.h.in

@@ -137,6 +137,9 @@
 /* define if SQLite is to be used */
 /* define if SQLite is to be used */
 #undef HAVE_SQLITE
 #undef HAVE_SQLITE
 
 
+/* define if GDAL is to be used */
+#undef HAVE_GDAL
+
 /* define if OGR is to be used */
 /* define if OGR is to be used */
 #undef HAVE_OGR
 #undef HAVE_OGR
 
 

+ 1 - 15
include/gis.h

@@ -28,10 +28,6 @@
 #include <grass/config.h>
 #include <grass/config.h>
 #include <grass/datetime.h>
 #include <grass/datetime.h>
 
 
-#ifdef GDAL_LINK
-#include <gdal.h>
-#endif
-
 /*=========================== Constants/Defines ============================*/
 /*=========================== Constants/Defines ============================*/
 
 
 #if !defined __GNUC__ || __GNUC__ < 2
 #if !defined __GNUC__ || __GNUC__ < 2
@@ -627,17 +623,7 @@ struct TimeStamp
     int count;
     int count;
 };
 };
 
 
-#ifdef GDAL_LINK
-struct GDAL_link
-{
-    char *filename;
-    int band_num;
-    DCELL null_val;
-    GDALDatasetH data;
-    GDALRasterBandH band;
-    GDALDataType type;
-};
-#endif
+struct GDAL_link;
 
 
 /*============================== Prototypes ================================*/
 /*============================== Prototypes ================================*/
 
 

+ 0 - 2
include/gisdefs.h

@@ -513,10 +513,8 @@ void G_fpreclass_perform_if(const struct FPReclass *, const CELL *, FCELL *,
 void G_fpreclass_perform_id(const struct FPReclass *, const CELL *, DCELL *,
 void G_fpreclass_perform_id(const struct FPReclass *, const CELL *, DCELL *,
 			    int);
 			    int);
 /* gdal.c */
 /* gdal.c */
-#ifdef GDAL_LINK
 struct GDAL_link *G_get_gdal_link(const char *, const char *);
 struct GDAL_link *G_get_gdal_link(const char *, const char *);
 void G_close_gdal_link(struct GDAL_link *);
 void G_close_gdal_link(struct GDAL_link *);
-#endif
 
 
 /* geodesic.c */
 /* geodesic.c */
 int G_begin_geodesic_equation(double, double, double, double);
 int G_begin_geodesic_equation(double, double, double, double);

+ 16 - 2
lib/gis/G.h

@@ -1,6 +1,10 @@
+#include <grass/config.h>
 #include <grass/gis.h>
 #include <grass/gis.h>
 #include <rpc/types.h>
 #include <rpc/types.h>
 #include <rpc/xdr.h>
 #include <rpc/xdr.h>
+#ifdef HAVE_GDAL
+#include <gdal.h>
+#endif
 
 
 #define XDR_FLOAT_NBYTES 4
 #define XDR_FLOAT_NBYTES 4
 #define XDR_DOUBLE_NBYTES 8
 #define XDR_DOUBLE_NBYTES 8
@@ -14,6 +18,18 @@
  */
  */
 typedef int COLUMN_MAPPING;
 typedef int COLUMN_MAPPING;
 
 
+struct GDAL_link
+{
+    char *filename;
+    int band_num;
+    DCELL null_val;
+#ifdef HAVE_GDAL
+    GDALDatasetH data;
+    GDALRasterBandH band;
+    GDALDataType type;
+#endif
+};
+
 struct fileinfo			/* Information for opened cell files */
 struct fileinfo			/* Information for opened cell files */
 {
 {
     int open_mode;		/* see defines below            */
     int open_mode;		/* see defines below            */
@@ -44,9 +60,7 @@ struct fileinfo			/* Information for opened cell files */
     unsigned char *null_work_buf;	/* data buffer for reading null rows    */
     unsigned char *null_work_buf;	/* data buffer for reading null rows    */
     int min_null_row;		/* Minimum row null row number in memory */
     int min_null_row;		/* Minimum row null row number in memory */
     struct Quant quant;
     struct Quant quant;
-#ifdef GDAL_LINK
     struct GDAL_link *gdal;
     struct GDAL_link *gdal;
-#endif
 };
 };
 
 
 struct G__			/*  Structure of library globals */
 struct G__			/*  Structure of library globals */

+ 1 - 1
lib/gis/Makefile

@@ -17,7 +17,7 @@ ifneq ($(USE_LARGEFILES),)
 	EXTRA_CFLAGS = -D_FILE_OFFSET_BITS=64
 	EXTRA_CFLAGS = -D_FILE_OFFSET_BITS=64
 endif
 endif
 
 
-ifneq ($(GDAL_LINK),)
+ifneq ($(USE_GDAL),)
 EXTRA_CFLAGS += -DGDAL_LINK
 EXTRA_CFLAGS += -DGDAL_LINK
 EXTRA_INC += $(PROJINC) $(GDALCFLAGS)
 EXTRA_INC += $(PROJINC) $(GDALCFLAGS)
 EXTRA_LIBS += $(GDALLIBS)
 EXTRA_LIBS += $(GDALLIBS)

+ 0 - 2
lib/gis/closecell.c

@@ -134,10 +134,8 @@ static int close_old(int fd)
        This is obsolete since now the mask_bus is always allocated
        This is obsolete since now the mask_bus is always allocated
      */
      */
 
 
-#ifdef GDAL_LINK
     if (fcb->gdal)
     if (fcb->gdal)
 	G_close_gdal_link(fcb->gdal);
 	G_close_gdal_link(fcb->gdal);
-#endif
 
 
     for (i = 0; i < NULL_ROWS_INMEM; i++)
     for (i = 0; i < NULL_ROWS_INMEM; i++)
 	G_free(fcb->NULL_ROWS[i]);
 	G_free(fcb->NULL_ROWS[i]);

+ 16 - 10
lib/gis/gdal.c

@@ -1,20 +1,23 @@
+
+#include <stdlib.h>
+#include <string.h>
 #include <grass/config.h>
 #include <grass/config.h>
 #include <grass/gis.h>
 #include <grass/gis.h>
-
-#ifdef GDAL_LINK
-
-#include <gdal.h>
+#include "G.h"
 
 
 struct GDAL_link *G_get_gdal_link(const char *name, const char *mapset)
 struct GDAL_link *G_get_gdal_link(const char *name, const char *mapset)
 {
 {
+#ifdef HAVE_GDAL
     static int initialized;
     static int initialized;
-    const char *filename;
-    int band_num;
     GDALDatasetH data;
     GDALDatasetH data;
     GDALRasterBandH band;
     GDALRasterBandH band;
     GDALDataType type;
     GDALDataType type;
+    RASTER_MAP_TYPE req_type;
+#endif
+    const char *filename;
+    int band_num;
     struct GDAL_link *gdal;
     struct GDAL_link *gdal;
-    RASTER_MAP_TYPE map_type, req_type;
+    RASTER_MAP_TYPE map_type;
     FILE *fp;
     FILE *fp;
     struct Key_Value *key_val;
     struct Key_Value *key_val;
     const char *p;
     const char *p;
@@ -55,12 +58,12 @@ struct GDAL_link *G_get_gdal_link(const char *name, const char *mapset)
     else
     else
 	null_val = atof(p);
 	null_val = atof(p);
 
 
+#ifdef HAVE_GDAL
     p = G_find_key_value("type", key_val);
     p = G_find_key_value("type", key_val);
     if (!p)
     if (!p)
 	return NULL;
 	return NULL;
     type = atoi(p);
     type = atoi(p);
 
 
-
     switch (type) {
     switch (type) {
     case GDT_Byte:
     case GDT_Byte:
     case GDT_Int16:
     case GDT_Int16:
@@ -96,24 +99,27 @@ struct GDAL_link *G_get_gdal_link(const char *name, const char *mapset)
 	GDALClose(data);
 	GDALClose(data);
 	return NULL;
 	return NULL;
     }
     }
+#endif
 
 
     gdal = G_calloc(1, sizeof(struct GDAL_link));
     gdal = G_calloc(1, sizeof(struct GDAL_link));
 
 
     gdal->filename = G_store(filename);
     gdal->filename = G_store(filename);
     gdal->band_num = band_num;
     gdal->band_num = band_num;
     gdal->null_val = null_val;
     gdal->null_val = null_val;
+#ifdef HAVE_GDAL
     gdal->data = data;
     gdal->data = data;
     gdal->band = band;
     gdal->band = band;
     gdal->type = type;
     gdal->type = type;
+#endif
 
 
     return gdal;
     return gdal;
 }
 }
 
 
 void G_close_gdal_link(struct GDAL_link *gdal)
 void G_close_gdal_link(struct GDAL_link *gdal)
 {
 {
+#ifdef HAVE_GDAL
     GDALClose(gdal->data);
     GDALClose(gdal->data);
+#endif
     G_free(gdal->filename);
     G_free(gdal->filename);
     G_free(gdal);
     G_free(gdal);
 }
 }
-
-#endif

+ 7 - 7
lib/gis/get_row.c

@@ -198,7 +198,7 @@ static int read_data_uncompressed(int fd, int row, unsigned char *data_buf,
 
 
 /*--------------------------------------------------------------------------*/
 /*--------------------------------------------------------------------------*/
 
 
-#ifdef GDAL_LINK
+#ifdef HAVE_GDAL
 static int read_data_gdal(int fd, int row, unsigned char *data_buf, int *nbytes)
 static int read_data_gdal(int fd, int row, unsigned char *data_buf, int *nbytes)
 {
 {
     struct fileinfo *fcb = &G__.fileinfo[fd];
     struct fileinfo *fcb = &G__.fileinfo[fd];
@@ -222,7 +222,7 @@ static int read_data(int fd, int row, unsigned char *data_buf, int *nbytes)
 {
 {
     struct fileinfo *fcb = &G__.fileinfo[fd];
     struct fileinfo *fcb = &G__.fileinfo[fd];
 
 
-#ifdef GDAL_LINK
+#ifdef HAVE_GDAL
     if (fcb->gdal)
     if (fcb->gdal)
 	return read_data_gdal(fd, row, data_buf, nbytes);
 	return read_data_gdal(fd, row, data_buf, nbytes);
 #endif
 #endif
@@ -373,7 +373,7 @@ static void cell_values_double(int fd, const unsigned char *data,
 
 
 /*--------------------------------------------------------------------------*/
 /*--------------------------------------------------------------------------*/
 
 
-#ifdef GDAL_LINK
+#ifdef HAVE_GDAL
 
 
 /*--------------------------------------------------------------------------*/
 /*--------------------------------------------------------------------------*/
 
 
@@ -489,13 +489,13 @@ static void transfer_to_cell_XX(int fd, void *cell)
 {
 {
     static void (*cell_values_type[3]) () = {
     static void (*cell_values_type[3]) () = {
     cell_values_int, cell_values_float, cell_values_double};
     cell_values_int, cell_values_float, cell_values_double};
-#ifdef GDAL_LINK
+#ifdef HAVE_GDAL
     static void (*gdal_values_type[3]) () = {
     static void (*gdal_values_type[3]) () = {
     gdal_values_int, gdal_values_float, gdal_values_double};
     gdal_values_int, gdal_values_float, gdal_values_double};
 #endif
 #endif
     struct fileinfo *fcb = &G__.fileinfo[fd];
     struct fileinfo *fcb = &G__.fileinfo[fd];
 
 
-#ifdef GDAL_LINK
+#ifdef HAVE_GDAL
     if (fcb->gdal)
     if (fcb->gdal)
     (gdal_values_type[fcb->map_type]) (fd, fcb->data, fcb->col_map,
     (gdal_values_type[fcb->map_type]) (fd, fcb->data, fcb->col_map,
 				       fcb->cur_nbytes, cell,
 				       fcb->cur_nbytes, cell,
@@ -1130,7 +1130,7 @@ static void get_null_value_row_nomask(int fd, char *flags, int row)
 
 
 /*--------------------------------------------------------------------------*/
 /*--------------------------------------------------------------------------*/
 
 
-#ifdef GDAL_LINK
+#ifdef HAVE_GDAL
 
 
 static void get_null_value_row_gdal(int fd, char *flags, int row)
 static void get_null_value_row_gdal(int fd, char *flags, int row)
 {
 {
@@ -1177,7 +1177,7 @@ static void embed_mask(char *flags, int row)
 
 
 static void get_null_value_row(int fd, char *flags, int row, int with_mask)
 static void get_null_value_row(int fd, char *flags, int row, int with_mask)
 {
 {
-#ifdef GDAL_LINK
+#ifdef HAVE_GDAL
     struct fileinfo *fcb = &G__.fileinfo[fd];
     struct fileinfo *fcb = &G__.fileinfo[fd];
     if (fcb->gdal)
     if (fcb->gdal)
 	get_null_value_row_gdal(fd, flags, row);
 	get_null_value_row_gdal(fd, flags, row);

+ 17 - 15
lib/gis/opencell.c

@@ -159,9 +159,7 @@ int G__open_cell_old(const char *name, const char *mapset)
     RASTER_MAP_TYPE MAP_TYPE;
     RASTER_MAP_TYPE MAP_TYPE;
     struct Reclass reclass;
     struct Reclass reclass;
     char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
     char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
-#ifdef GDAL_LINK
     struct GDAL_link *gdal;
     struct GDAL_link *gdal;
-#endif
 
 
     /* make sure window is set    */
     /* make sure window is set    */
     G__init_window();
     G__init_window();
@@ -255,15 +253,21 @@ int G__open_cell_old(const char *name, const char *mapset)
 	MAP_NBYTES = CELL_nbytes;
 	MAP_NBYTES = CELL_nbytes;
     }
     }
 
 
-#ifdef GDAL_LINK
-    gdal = G_get_gdal_link(name, mapset);
-    if (gdal)
+    gdal = G_get_gdal_link(r_name, r_mapset);
+    if (gdal) {
+#ifdef HAVE_GDAL
 	/* dummy descriptor to reserve the fileinfo slot */
 	/* dummy descriptor to reserve the fileinfo slot */
 	fd = open("/dev/null", O_RDONLY);
 	fd = open("/dev/null", O_RDONLY);
-    else
+#else
+	G_warning(_("map <%s@%s> is a GDAL link but GRASS is compiled without GDAL support"),
+		  r_name, r_mapset);
+	return -1;
 #endif
 #endif
-    /* now actually open file for reading */
-    fd = G_open_old(cell_dir, r_name, r_mapset);
+    }
+    else
+	/* now actually open file for reading */
+	fd = G_open_old(cell_dir, r_name, r_mapset);
+
     if (fd < 0)
     if (fd < 0)
 	return -1;
 	return -1;
 
 
@@ -297,16 +301,14 @@ int G__open_cell_old(const char *name, const char *mapset)
     if ((fcb->reclass_flag = reclass_flag))
     if ((fcb->reclass_flag = reclass_flag))
 	G_copy(&fcb->reclass, &reclass, sizeof(reclass));
 	G_copy(&fcb->reclass, &reclass, sizeof(reclass));
 
 
-#ifdef GDAL_LINK
     if (gdal)
     if (gdal)
 	fcb->gdal = gdal;
 	fcb->gdal = gdal;
     else
     else
-#endif
-    /* check for compressed data format, making initial reads if necessary */
-    if (G__check_format(fd) < 0) {
-	close(fd);		/* warning issued by check_format() */
-	return -1;
-    }
+	/* check for compressed data format, making initial reads if necessary */
+	if (G__check_format(fd) < 0) {
+	    close(fd);		/* warning issued by check_format() */
+	    return -1;
+	}
 
 
     /* create the mapping from cell file to window */
     /* create the mapping from cell file to window */
     G__create_window_mapping(fd);
     G__create_window_mapping(fd);

+ 4 - 0
raster/r.external/Makefile

@@ -8,4 +8,8 @@ EXTRA_INC = $(PROJINC) $(GDALCFLAGS)
 
 
 include $(MODULE_TOPDIR)/include/Make/Module.make
 include $(MODULE_TOPDIR)/include/Make/Module.make
 
 
+ifneq ($(USE_GDAL),)
 default: cmd
 default: cmd
+else
+default:
+endif