From da45f6f242ae683585a585c53dcb61564b1d53e5 Mon Sep 17 00:00:00 2001 From: Rashad Kanavath Date: Tue, 18 Feb 2020 01:11:26 +0100 Subject: [PATCH 1/8] define unistd only if unistd.h is not available MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Edouard Choinière <27212526+echoix@users.noreply.github.com> --- lib/db/dbmi_base/dirent.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/db/dbmi_base/dirent.c b/lib/db/dbmi_base/dirent.c index 708795bd4da..8f5ba5a06ea 100644 --- a/lib/db/dbmi_base/dirent.c +++ b/lib/db/dbmi_base/dirent.c @@ -21,8 +21,8 @@ #include /* NOTE: these should come from or from */ -#ifndef R_OK #if !defined(HAVE_UNISTD_H) +#ifndef R_OK #define R_OK 4 #endif #ifndef W_OK From 735c059893f65b5efa56cdc0ad94b26a16c2d659 Mon Sep 17 00:00:00 2001 From: Rashad Kanavath Date: Tue, 18 Feb 2020 01:11:44 +0100 Subject: [PATCH 2/8] fix msvc broken build (works on gcc) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Edouard Choinière <27212526+echoix@users.noreply.github.com> --- general/g.proj/main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/general/g.proj/main.c b/general/g.proj/main.c index 5ce72b95509..c5c4ce631b7 100644 --- a/general/g.proj/main.c +++ b/general/g.proj/main.c @@ -111,6 +111,7 @@ int main(int argc, char *argv[]) dontprettify = G_define_flag(); dontprettify->key = 'f'; dontprettify->guisection = _("Print"); + /* Does anyone build gdal without ogr these days ?. Anyway.. */ #ifdef HAVE_OGR dontprettify->description = _("Print 'flat' output with no linebreaks " "(applies to WKT and PROJ.4 output)"); @@ -369,6 +370,7 @@ int main(int argc, char *argv[]) #endif (create->answer ? 1 : 0)); if (formats > 1) { + /* Does anyone build gdal without ogr these days ?. Anyway.. */ #ifdef HAVE_OGR G_fatal_error(_("Only one of -%c, -%c, -%c, -%c, -%c" " or -%c flags may be specified"), From 14de097a8f2082ac1a751e1b3950ea145ecf76c5 Mon Sep 17 00:00:00 2001 From: Rashad Kanavath Date: Tue, 18 Feb 2020 01:12:32 +0100 Subject: [PATCH 3/8] msvc: __attribute__ is gcc only MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Edouard Choinière <27212526+echoix@users.noreply.github.com> --- include/grass/defs/glocale.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/grass/defs/glocale.h b/include/grass/defs/glocale.h index b153afe21d5..f216b2b213d 100644 --- a/include/grass/defs/glocale.h +++ b/include/grass/defs/glocale.h @@ -1,10 +1,11 @@ #ifndef GRASS_GLOCALEDEFS_H #define GRASS_GLOCALEDEFS_H -#if !defined __GNUC__ || __GNUC__ < 2 -#undef __attribute__ +#if defined(_MSC_VER) +#ifndef __attribute__ #define __attribute__(x) #endif +#endif extern void G_init_locale(void); extern char *G_gettext(const char *, const char *) From d7165331094dcb729c8dc93df440bdb1f4e06fc6 Mon Sep 17 00:00:00 2001 From: Rashad Kanavath Date: Tue, 18 Feb 2020 01:12:57 +0100 Subject: [PATCH 4/8] check for _WIN32 to support msvc and mingw --- lib/gis/parser_interface.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/gis/parser_interface.c b/lib/gis/parser_interface.c index fb091af9144..f3bab3d2aa9 100644 --- a/lib/gis/parser_interface.c +++ b/lib/gis/parser_interface.c @@ -107,7 +107,7 @@ void G__usage_xml(void) char *type; char *s, *top; int i; - const char *encoding = NULL; + const char *encoding = ""; int new_prompt = 0; new_prompt = G__uses_new_gisprompt(); From db58993ab14f9adcc7c3e30926828d864cb5e84f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edouard=20Choini=C3=A8re?= <27212526+echoix@users.noreply.github.com> Date: Sun, 6 Apr 2025 21:37:02 +0000 Subject: [PATCH 5/8] msvc: undef min max and use math.h for math constants Co-authored-by: Rashad Kanavath --- include/grass/gis.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/grass/gis.h b/include/grass/gis.h index ad0687ffa6a..73befb16381 100644 --- a/include/grass/gis.h +++ b/include/grass/gis.h @@ -137,7 +137,7 @@ static const char *GRASS_copyright UNUSED = "GRASS GNU GPL licensed Software"; #define WKT_FILE "PROJ_WKT" #define SRID_FILE "PROJ_SRID" -#ifdef __MINGW32__ +#ifdef _WIN32 #define CONFIG_DIR "GRASS8" #else #define CONFIG_DIR ".grass8" @@ -154,6 +154,12 @@ static const char *GRASS_copyright UNUSED = "GRASS GNU GPL licensed Software"; #define MIN(a, b) ((a) < (b) ? (a) : (b)) /* define PI and friends */ +#if defined(_MSC_VER) +#define _USE_MATH_DEFINES 1 +#include +#undef min +#undef max +#else #undef M_PI #define M_PI 3.14159265358979323846 /* pi */ @@ -162,6 +168,7 @@ static const char *GRASS_copyright UNUSED = "GRASS GNU GPL licensed Software"; #undef M_PI_4 #define M_PI_4 0.78539816339744830962 /* pi/4 */ +#endif #undef M_R2D #define M_R2D 57.295779513082320877 /* 180/pi */ From c212d0ead2881e670f60e0cced7d7e863f87f012 Mon Sep 17 00:00:00 2001 From: Rashad Kanavath Date: Tue, 18 Feb 2020 01:17:43 +0100 Subject: [PATCH 6/8] msvc: fix warning POINT2D_C already defined --- lib/rst/interp_float/point2d.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/rst/interp_float/point2d.c b/lib/rst/interp_float/point2d.c index 8a5a0aa8d42..c4996ffa81e 100644 --- a/lib/rst/interp_float/point2d.c +++ b/lib/rst/interp_float/point2d.c @@ -30,7 +30,9 @@ #include #include -#define POINT2D_C +#ifndef POINT2D_C +#define POINT2D_C 1 +#endif #include /* needed for AIX */ From d90aff12b73b457b67f9f849226ca6aa98d78d4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edouard=20Choini=C3=A8re?= <27212526+echoix@users.noreply.github.com> Date: Sun, 6 Apr 2025 22:06:18 +0000 Subject: [PATCH 7/8] Remove unneeded comment about GDAL without OGR --- general/g.proj/main.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/general/g.proj/main.c b/general/g.proj/main.c index c5c4ce631b7..5ce72b95509 100644 --- a/general/g.proj/main.c +++ b/general/g.proj/main.c @@ -111,7 +111,6 @@ int main(int argc, char *argv[]) dontprettify = G_define_flag(); dontprettify->key = 'f'; dontprettify->guisection = _("Print"); - /* Does anyone build gdal without ogr these days ?. Anyway.. */ #ifdef HAVE_OGR dontprettify->description = _("Print 'flat' output with no linebreaks " "(applies to WKT and PROJ.4 output)"); @@ -370,7 +369,6 @@ int main(int argc, char *argv[]) #endif (create->answer ? 1 : 0)); if (formats > 1) { - /* Does anyone build gdal without ogr these days ?. Anyway.. */ #ifdef HAVE_OGR G_fatal_error(_("Only one of -%c, -%c, -%c, -%c, -%c" " or -%c flags may be specified"), From 389fa34305995ee64232eae8219c349c2fa8190b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edouard=20Choini=C3=A8re?= <27212526+echoix@users.noreply.github.com> Date: Thu, 22 May 2025 18:51:43 -0400 Subject: [PATCH 8/8] Apply suggestions from code review --- include/grass/defs/glocale.h | 5 ++--- include/grass/gis.h | 6 ------ lib/gis/parser_interface.c | 2 +- lib/rst/interp_float/point2d.c | 4 +--- 4 files changed, 4 insertions(+), 13 deletions(-) diff --git a/include/grass/defs/glocale.h b/include/grass/defs/glocale.h index f216b2b213d..b153afe21d5 100644 --- a/include/grass/defs/glocale.h +++ b/include/grass/defs/glocale.h @@ -1,11 +1,10 @@ #ifndef GRASS_GLOCALEDEFS_H #define GRASS_GLOCALEDEFS_H -#if defined(_MSC_VER) -#ifndef __attribute__ +#if !defined __GNUC__ || __GNUC__ < 2 +#undef __attribute__ #define __attribute__(x) #endif -#endif extern void G_init_locale(void); extern char *G_gettext(const char *, const char *) diff --git a/include/grass/gis.h b/include/grass/gis.h index 73befb16381..853d40e8d80 100644 --- a/include/grass/gis.h +++ b/include/grass/gis.h @@ -154,12 +154,6 @@ static const char *GRASS_copyright UNUSED = "GRASS GNU GPL licensed Software"; #define MIN(a, b) ((a) < (b) ? (a) : (b)) /* define PI and friends */ -#if defined(_MSC_VER) -#define _USE_MATH_DEFINES 1 -#include -#undef min -#undef max -#else #undef M_PI #define M_PI 3.14159265358979323846 /* pi */ diff --git a/lib/gis/parser_interface.c b/lib/gis/parser_interface.c index f3bab3d2aa9..fb091af9144 100644 --- a/lib/gis/parser_interface.c +++ b/lib/gis/parser_interface.c @@ -107,7 +107,7 @@ void G__usage_xml(void) char *type; char *s, *top; int i; - const char *encoding = ""; + const char *encoding = NULL; int new_prompt = 0; new_prompt = G__uses_new_gisprompt(); diff --git a/lib/rst/interp_float/point2d.c b/lib/rst/interp_float/point2d.c index c4996ffa81e..8a5a0aa8d42 100644 --- a/lib/rst/interp_float/point2d.c +++ b/lib/rst/interp_float/point2d.c @@ -30,9 +30,7 @@ #include #include -#ifndef POINT2D_C -#define POINT2D_C 1 -#endif +#define POINT2D_C #include /* needed for AIX */