Ticket filed upstream at: https://www.gaia-gis.it/fossil/librasterlite2/tktview?name=86df0dd5a0

--- src/rl2gif.c.orig	2020-08-24 17:20:40.000000000 +0200
+++ src/rl2gif.c	2023-08-08 11:47:12.000000000 +0200
@@ -104,7 +104,7 @@
 print_gif_error (int ErrorCode)
 {
     const char *Err = NULL;
-#ifdef GIFLIB_MAJOR
+#if GIFLIB_MAJOR >= 5
     Err = GifErrorString (ErrorCode);
 #endif
     if (Err != NULL)
@@ -216,7 +216,7 @@
     struct gif_memory_buffer membuf;
     GifPixelType *ScanLine = NULL;
     GifFileType *GifFile = NULL;
-#ifdef GIFLIB_MAJOR
+#if GIFLIB_MAJOR >= 5
     int ErrorCode;
 #endif
     ColorMapObject *ColorMap = NULL;
@@ -242,14 +242,14 @@
       }
 
 /* opening the GIF */
-#ifdef GIFLIB_MAJOR
+#if GIFLIB_MAJOR >= 5
     GifFile = EGifOpen (&membuf, writeGif, &ErrorCode);
 #else
     GifFile = EGifOpen (&membuf, writeGif);
 #endif
     if (GifFile == NULL)
       {
-#ifdef GIFLIB_MAJOR
+#if GIFLIB_MAJOR >= 5
 	  print_gif_error (ErrorCode);
 #else
 	  print_gif_error (GifLastError ());
@@ -261,7 +261,7 @@
     switch (pixel_type)
       {
       case RL2_PIXEL_MONOCHROME:
-#ifdef GIFLIB_MAJOR
+#if GIFLIB_MAJOR >= 5
 	  ColorMap = GifMakeMapObject (2, NULL);
 #else
 	  ColorMap = MakeMapObject (2, NULL);
@@ -280,7 +280,7 @@
 	  switch (sample_type)
 	    {
 	    case RL2_SAMPLE_2_BIT:
-#ifdef GIFLIB_MAJOR
+#if GIFLIB_MAJOR >= 5
 		ColorMap = GifMakeMapObject (4, NULL);
 #else
 		ColorMap = MakeMapObject (4, NULL);
@@ -301,7 +301,7 @@
 		ColorMap->Colors[3].Blue = 255;
 		break;
 	    case RL2_SAMPLE_4_BIT:
-#ifdef GIFLIB_MAJOR
+#if GIFLIB_MAJOR >= 5
 		ColorMap = GifMakeMapObject (16, NULL);
 #else
 		ColorMap = MakeMapObject (16, NULL);
@@ -358,7 +358,7 @@
 		ColorMap->Colors[15].Blue = 255;
 		break;
 	    case RL2_SAMPLE_UINT8:
-#ifdef GIFLIB_MAJOR
+#if GIFLIB_MAJOR >= 5
 		ColorMap = GifMakeMapObject (256, NULL);
 #else
 		ColorMap = MakeMapObject (256, NULL);
@@ -394,7 +394,7 @@
 	      max_palette = 128;
 	  else
 	      max_palette = 256;
-#ifdef GIFLIB_MAJOR
+#if GIFLIB_MAJOR >= 5
 	  ColorMap = GifMakeMapObject (max_palette, NULL);
 #else
 	  ColorMap = MakeMapObject (max_palette, NULL);
@@ -426,7 +426,7 @@
 	(GifFile, width, height, ColorMap->BitsPerPixel, 0,
 	 ColorMap) == GIF_ERROR)
       {
-#ifdef GIFLIB_MAJOR
+#if GIFLIB_MAJOR >= 5
 	  print_gif_error (ErrorCode);
 #else
 	  print_gif_error (GifLastError ());
@@ -435,7 +435,7 @@
       }
     if (EGifPutImageDesc (GifFile, 0, 0, width, height, 0, NULL) == GIF_ERROR)
       {
-#ifdef GIFLIB_MAJOR
+#if GIFLIB_MAJOR >= 5
 	  print_gif_error (ErrorCode);
 #else
 	  print_gif_error (GifLastError ());
@@ -451,7 +451,7 @@
 	      ScanLine[col] = *p_data++;
 	  if (EGifPutLine (GifFile, ScanLine, width) == GIF_ERROR)
 	    {
-#ifdef GIFLIB_MAJOR
+#if GIFLIB_MAJOR >= 5
 		print_gif_error (ErrorCode);
 #else
 		print_gif_error (GifLastError ());
@@ -467,7 +467,7 @@
     if (EGifCloseFile (GifFile) == GIF_ERROR)
 #endif
       {
-#ifdef GIFLIB_MAJOR
+#if GIFLIB_MAJOR >= 5
 	  print_gif_error (ErrorCode);
 #else
 	  print_gif_error (GifLastError ());
@@ -476,7 +476,7 @@
       }
 
     free (ScanLine);
-#ifdef GIFLIB_MAJOR
+#if GIFLIB_MAJOR >= 5
     GifFreeMapObject (ColorMap);
 #else
     FreeMapObject (ColorMap);
@@ -495,7 +495,7 @@
 	free (ScanLine);
     if (ColorMap != NULL)
       {
-#ifdef GIFLIB_MAJOR
+#if GIFLIB_MAJOR >= 5
 	  GifFreeMapObject (ColorMap);
 #else
 	  FreeMapObject (ColorMap);
@@ -611,7 +611,7 @@
 {
 /* attempting to create a raster from a GIF image - raw block */
     struct gif_memory_buffer membuf;
-#ifdef GIFLIB_MAJOR
+#if GIFLIB_MAJOR >= 5
     int ErrorCode;
 #endif
     GifFileType *GifFile = NULL;
@@ -644,14 +644,14 @@
     membuf.off = 0;
 
 /* opening the GIF */
-#ifdef GIFLIB_MAJOR
+#if GIFLIB_MAJOR >= 5
     GifFile = DGifOpen (&membuf, readGif, &ErrorCode);
 #else
     GifFile = DGifOpen (&membuf, readGif);
 #endif
     if (GifFile == NULL)
       {
-#ifdef GIFLIB_MAJOR
+#if GIFLIB_MAJOR >= 5
 	  print_gif_error (ErrorCode);
 #else
 	  print_gif_error (GifLastError ());
@@ -664,7 +664,7 @@
 	  /* looping on GIF chunks */
 	  if (DGifGetRecordType (GifFile, &RecordType) == GIF_ERROR)
 	    {
-#ifdef GIFLIB_MAJOR
+#if GIFLIB_MAJOR >= 5
 		print_gif_error (GifFile->Error);
 #else
 		print_gif_error (GifLastError ());
@@ -677,7 +677,7 @@
 		/* we have a valid image */
 		if (DGifGetImageDesc (GifFile) == GIF_ERROR)
 		  {
-#ifdef GIFLIB_MAJOR
+#if GIFLIB_MAJOR >= 5
 		      print_gif_error (GifFile->Error);
 #else
 		      print_gif_error (GifLastError ());
@@ -728,7 +728,7 @@
 		      if (DGifGetLine (GifFile, Line, GifFile->Image.Width)
 			  == GIF_ERROR)
 			{
-#ifdef GIFLIB_MAJOR
+#if GIFLIB_MAJOR >= 5
 			    print_gif_error (GifFile->Error);
 #else
 			    print_gif_error (GifLastError ());
@@ -749,7 +749,7 @@
 		if (DGifGetExtension (GifFile, &ExtCode, &Extension) ==
 		    GIF_ERROR)
 		  {
-#ifdef GIFLIB_MAJOR
+#if GIFLIB_MAJOR >= 5
 		      print_gif_error (GifFile->Error);
 #else
 		      print_gif_error (GifLastError ());
@@ -761,7 +761,7 @@
 		      if (DGifGetExtensionNext (GifFile, &Extension) ==
 			  GIF_ERROR)
 			{
-#ifdef GIFLIB_MAJOR
+#if GIFLIB_MAJOR >= 5
 			    print_gif_error (GifFile->Error);
 #else
 			    print_gif_error (GifLastError ());
@@ -787,7 +787,7 @@
     if (DGifCloseFile (GifFile) == GIF_ERROR)
 #endif
       {
-#ifdef GIFLIB_MAJOR
+#if GIFLIB_MAJOR >= 5
 	  print_gif_error (GifFile->Error);
 #else
 	  print_gif_error (GifLastError ());
