--- /dev/null
+--- gdal-3.0.1/gcore/rasterio.cpp~ 2019-06-28 12:58:14.000000000 +0200
++++ gdal-3.0.1/gcore/rasterio.cpp 2019-10-30 10:08:18.083471282 +0100
+@@ -2872,15 +2872,15 @@
+
+ void GDALUnrolledCopy_GByte_2_1_SSSE3( GByte* CPL_RESTRICT pDest,
+ const GByte* CPL_RESTRICT pSrc,
+- GPtrDiff_t nIters );
++ GInt64 nIters );
+
+ void GDALUnrolledCopy_GByte_3_1_SSSE3( GByte* CPL_RESTRICT pDest,
+ const GByte* CPL_RESTRICT pSrc,
+- GPtrDiff_t nIters );
++ GInt64 nIters );
+
+ void GDALUnrolledCopy_GByte_4_1_SSSE3( GByte* CPL_RESTRICT pDest,
+ const GByte* CPL_RESTRICT pSrc,
+- GPtrDiff_t nIters );
++ GInt64 nIters );
+ #endif
+
+
--- /dev/null
+From 7a18e2669a733ebe3544e4f5c735fd4d2ded5fa3 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder@redhat.com>
+Date: Thu, 10 Dec 2020 14:02:44 +0100
+Subject: [PATCH] Add some missing <limits> includes
+
+Otherwise, the builds fails with either gcc11 or recent clang.
+---
+ gdal/ogr/ogrsf_frmts/cad/libopencad/cadobjects.cpp | 1 +
+ gdal/ogr/ogrsf_frmts/cad/libopencad/dwg/r2000.cpp | 1 +
+ gdal/third_party/LercLib/Lerc2.h | 1 +
+ 3 files changed, 3 insertions(+)
+
+diff --git a/gdal/ogr/ogrsf_frmts/cad/libopencad/cadobjects.cpp b/gdal/ogr/ogrsf_frmts/cad/libopencad/cadobjects.cpp
+index f59f7d50e2f5..edff5100e1f4 100644
+--- a/gdal/ogr/ogrsf_frmts/cad/libopencad/cadobjects.cpp
++++ b/gdal/ogr/ogrsf_frmts/cad/libopencad/cadobjects.cpp
+@@ -31,6 +31,7 @@
+
+ #include "cadobjects.h"
+
++#include <limits>
+ #include <math.h>
+ #include <algorithm>
+
+diff --git a/gdal/ogr/ogrsf_frmts/cad/libopencad/dwg/r2000.cpp b/gdal/ogr/ogrsf_frmts/cad/libopencad/dwg/r2000.cpp
+index 83951fd7e7fc..6ae837da6467 100644
+--- a/gdal/ogr/ogrsf_frmts/cad/libopencad/dwg/r2000.cpp
++++ b/gdal/ogr/ogrsf_frmts/cad/libopencad/dwg/r2000.cpp
+@@ -36,6 +36,7 @@
+ #include <cassert>
+ #include <cstring>
+ #include <iostream>
++#include <limits>
+ #include <memory>
+ #include <string>
+
+diff --git a/gdal/third_party/LercLib/Lerc2.h b/gdal/third_party/LercLib/Lerc2.h
+index feec95529c83..564f928ee672 100644
+--- a/gdal/third_party/LercLib/Lerc2.h
++++ b/gdal/third_party/LercLib/Lerc2.h
+@@ -27,6 +27,7 @@ Contributors: Thomas Maurer
+ #include <algorithm>
+ #include <cfloat>
+ #include <cmath>
++#include <limits>
+ #include <string>
+ #include <typeinfo>
+ #include "Defines.h"
---- gdal-1.11.2/gcore/gdaldrivermanager.cpp.orig 2015-02-10 13:12:08.000000000 +0100
-+++ gdal-1.11.2/gcore/gdaldrivermanager.cpp 2015-03-01 21:11:24.537623226 +0100
-@@ -686,12 +686,12 @@
- }
- else
- {
--#ifdef GDAL_PREFIX
-+#if 1
- papszSearchPath = CSLAddString( papszSearchPath,
- #ifdef MACOSX_FRAMEWORK
- GDAL_PREFIX "/PlugIns");
- #else
-- GDAL_PREFIX "/lib/gdalplugins" );
-+ GDAL_LIBDIR "/gdalplugins" );
- #endif
- #else
- char szExecPath[1024];
---- gdal-1.11.2/configure.ac.orig 2015-03-01 09:07:33.069445871 +0100
-+++ gdal-1.11.2/configure.ac 2015-03-01 21:13:55.727616880 +0100
-@@ -3812,12 +3812,16 @@
+diff -urNp -x '*.orig' gdal-3.0.4.org/configure.ac gdal-3.0.4/configure.ac
+--- gdal-3.0.4.org/configure.ac 2021-04-02 16:52:15.663388370 +0200
++++ gdal-3.0.4/configure.ac 2021-04-02 16:52:16.026721386 +0200
+@@ -5219,12 +5219,16 @@ dnl ------------------------------------
- if test "$prefix" = "NONE" ; then
+ if test "$prefix" = "NONE" ; then
GDAL_PREFIX=/usr/local
+ GDAL_LIBDIR=${GDAL_PREFIX}/lib
else
dnl ---------------------------------------------------------------------------
dnl Perl bindings.
+diff -urNp -x '*.orig' gdal-3.0.4.org/gcore/gdaldrivermanager.cpp gdal-3.0.4/gcore/gdaldrivermanager.cpp
+--- gdal-3.0.4.org/gcore/gdaldrivermanager.cpp 2020-01-28 11:18:44.000000000 +0100
++++ gdal-3.0.4/gcore/gdaldrivermanager.cpp 2021-04-02 16:52:16.026721386 +0200
+@@ -745,12 +745,12 @@ void GDALDriverManager::AutoLoadDrivers(
+ }
+ else
+ {
+-#ifdef GDAL_PREFIX
++#if 1
+ papszSearchPath = CSLAddString( papszSearchPath,
+ #ifdef MACOSX_FRAMEWORK
+ GDAL_PREFIX "/PlugIns");
+ #else
+- GDAL_PREFIX "/lib/gdalplugins" );
++ GDAL_LIBDIR "/gdalplugins" );
+ #endif
+ #else
+ char szExecPath[1024];
---- gdal-2.4.0/frmts/pdf/pdfdataset.cpp.orig 2018-12-14 22:37:15.000000000 +0100
-+++ gdal-2.4.0/frmts/pdf/pdfdataset.cpp 2018-12-27 05:35:39.755925135 +0100
-@@ -3459,7 +3459,7 @@
+From 17e98757e78969a199d1d6318f53d088da192191 Mon Sep 17 00:00:00 2001
+From: Even Rouault <even.rouault@spatialys.com>
+Date: Fri, 18 Feb 2022 22:47:01 +0100
+Subject: [PATCH] PDF: fix build against Poppler > 22.2
+
+---
+ frmts/pdf/pdfdataset.cpp | 17 +++++++++++------
+ 1 file changed, 11 insertions(+), 6 deletions(-)
+
+diff --git a/frmts/pdf/pdfdataset.cpp b/frmts/pdf/pdfdataset.cpp
+index 22238bd74822..08f8e31c86a7 100644
+--- a/frmts/pdf/pdfdataset.cpp
++++ b/frmts/pdf/pdfdataset.cpp
+@@ -4101,8 +4101,6 @@ PDFDataset *PDFDataset::Open( GDALOpenIn
+ #ifdef HAVE_POPPLER
+ if(bUseLib.test(PDFLIB_POPPLER))
+ {
+- GooString* poUserPwd = nullptr;
+-
+ /* Set custom error handler for poppler errors */
+ #if POPPLER_MAJOR_VERSION >= 1 || POPPLER_MINOR_VERSION >= 85
+ setErrorCallback(PDFDatasetErrorFunction);
+@@ -4136,8 +4134,6 @@ PDFDataset *PDFDataset::Open( GDALOpenIn
+ while( true )
+ {
+ VSIFSeekL(fp, 0, SEEK_SET);
+- if (pszUserPwd)
+- poUserPwd = new GooString(pszUserPwd);
+
+ #if POPPLER_MAJOR_VERSION >= 1 || POPPLER_MINOR_VERSION >= 58
+ auto poStream = new VSIPDFFileStream(fp, pszFilename, std::move(oObj));
+@@ -4145,8 +4141,18 @@ PDFDataset *PDFDataset::Open( GDALOpenIn
+ oObj.getObj()->initNull();
+ auto poStream = new VSIPDFFileStream(fp, pszFilename, oObj.getObj());
#endif
- if( ocg != nullptr && ocg->getName() != nullptr )
- {
-- const char* pszLayerName = (const char*)ocg->getName()->getCString();
-+ const char* pszLayerName = (const char*)ocg->getName()->c_str();
- AddLayer(pszLayerName);
- oLayerOCGMapPoppler[pszLayerName] = ocg;
- }
-@@ -4787,7 +4787,7 @@
++#if POPPLER_MAJOR_VERSION > 22 || (POPPLER_MAJOR_VERSION == 22 && POPPLER_MINOR_VERSION > 2)
++ std::optional<GooString> osUserPwd;
++ if (pszUserPwd)
++ osUserPwd = std::optional<GooString>(pszUserPwd);
++ poDocPoppler = new PDFDoc(poStream, std::optional<GooString>(), osUserPwd);
++#else
++ GooString* poUserPwd = nullptr;
++ if (pszUserPwd)
++ poUserPwd = new GooString(pszUserPwd);
+ poDocPoppler = new PDFDoc(poStream, nullptr, poUserPwd);
+ delete poUserPwd;
++#endif
+
+ if ( !poDocPoppler->isOk() || poDocPoppler->getNumPages() == 0 )
+ {
+--- gdal-3.0.4/frmts/pdf/pdfdataset.cpp.orig 2022-04-15 17:08:03.072819386 +0200
++++ gdal-3.0.4/frmts/pdf/pdfdataset.cpp 2022-04-15 17:43:26.613241927 +0200
+@@ -4837,7 +4837,11 @@ PDFDataset *PDFDataset::Open( GDALOpenIn
+ #ifdef HAVE_POPPLER
+ if (bUseLib.test(PDFLIB_POPPLER))
+ {
++#if POPPLER_MAJOR_VERSION > 22 || (POPPLER_MAJOR_VERSION == 22 && POPPLER_MINOR_VERSION > 3)
++ std::unique_ptr<GooString> poMetadata = poCatalogPoppler->readMetadata();
++#else
GooString* poMetadata = poCatalogPoppler->readMetadata();
++#endif
if (poMetadata)
{
-- const char* pszContent = poMetadata->getCString();
-+ const char* pszContent = poMetadata->c_str();
- if (pszContent != nullptr &&
- STARTS_WITH(pszContent, "<?xpacket begin="))
- {
---- gdal-2.4.0/frmts/pdf/pdfobject.cpp.orig 2018-12-14 22:37:15.000000000 +0100
-+++ gdal-2.4.0/frmts/pdf/pdfobject.cpp 2018-12-27 16:31:17.472142636 +0100
-@@ -1061,7 +1061,7 @@
- #else
- GooString* gooString = m_po->getString();
- #endif
-- return (osStr = GDALPDFGetUTF8StringFromBytes(reinterpret_cast<const GByte*>(gooString->getCString()),
-+ return (osStr = GDALPDFGetUTF8StringFromBytes(reinterpret_cast<const GByte*>(gooString->c_str()),
- static_cast<int>(gooString->getLength())));
- }
- else
-@@ -1422,7 +1422,7 @@
- char* pszContent = (char*) VSIMalloc(m_nLength + 1);
- if (pszContent)
- {
-- memcpy(pszContent, gstr->getCString(), m_nLength);
-+ memcpy(pszContent, gstr->c_str(), m_nLength);
- pszContent[m_nLength] = '\0';
+ #if (POPPLER_MAJOR_VERSION >= 1 || POPPLER_MINOR_VERSION >= 72)
+@@ -4851,7 +4855,9 @@ PDFDataset *PDFDataset::Open( GDALOpenIn
+ const char * const apszMDList[2] = { pszContent, nullptr };
+ poDS->SetMetadata(const_cast<char**>(apszMDList), "xml:XMP");
}
- delete gstr;
++#if POPPLER_MAJOR_VERSION < 22 || (POPPLER_MAJOR_VERSION == 22 && POPPLER_MINOR_VERSION < 4)
+ delete poMetadata;
++#endif
+ }
+
+ /* Read Info object */
+++ /dev/null
---- gdal-1.9.0/configure.ac.orig 2012-01-04 08:03:42.000000000 +0100
-+++ gdal-1.9.0/configure.ac 2012-01-19 20:50:08.902476176 +0100
-@@ -1493,7 +1493,7 @@
- AC_MSG_CHECKING([libnetcdf version with $ncdump])
- netcdf_version=`$ncdump 2>&1 | grep "netcdf library version" | awk '{gsub(/"/,"");print $4}'`
- AC_MSG_RESULT([got $netcdf_version])
-- if test "$netcdf_version" != "" -a "${netcdf_version:0:1}" == "4" ; then
-+ if test "$netcdf_version" != "" -a "$(echo ${netcdf_version} | sed 's/^\(.\).*/\1/')" == "4" ; then
- nc_config=$NETCDF_ROOT"/bin/nc-config"
- fi
- fi
%if %{with podofo}
%undefine with_poppler
%endif
+
+%{?use_default_jdk}
+
Summary: Geospatial Data Abstraction Library
Summary(pl.UTF-8): Biblioteka abstrakcji danych dotyczących powierzchni Ziemi
Name: gdal
-Version: 2.4.0
-Release: 10
+Version: 3.0.4
+Release: 21
License: BSD-like
Group: Libraries
-Source0: http://download.osgeo.org/gdal/%{version}/%{name}-%{version}.tar.xz
-# Source0-md5: 794096364a50df4bc7c5b710d997b6b4
+Source0: https://github.com/OSGeo/gdal/releases/download/v%{version}/%{name}-%{version}.tar.gz
+# Source0-md5: c6bbb5caca06e96bd97a32918e0aa9aa
Patch0: %{name}-perl.patch
-Patch1: %{name}-poppler.patch
-Patch2: %{name}-pc.patch
-Patch9: %{name}-dds.patch
-Patch12: %{name}-rasdaman.patch
-Patch13: %{name}-pluginsdir.patch
-Patch15: libx32.patch
+Patch1: %{name}-pc.patch
+Patch2: %{name}-dds.patch
+Patch3: %{name}-rasdaman.patch
+Patch4: %{name}-pluginsdir.patch
+Patch5: libx32.patch
+Patch6: %{name}-poppler.patch
+Patch7: decl.patch
+Patch8: %{name}_tirpcinc.patch
+Patch9: jasper.patch
+Patch10: gcc11.patch
URL: http://www.gdal.org/
# 1.x or 2.x supported
BuildRequires: CharLS-devel
BuildRequires: hdf-devel >= 4.2.5
BuildRequires: hdf5-devel
BuildRequires: jasper-devel
-%{?with_java:BuildRequires: jdk}
+%{?with_java:%buildrequires_jdk}
%{?with_java:BuildRequires: jpackage-utils}
BuildRequires: json-c-devel >= 0.11
%{?with_kea:BuildRequires: kealib-devel}
%{?with_spatialite:BuildRequires: libspatialite-devel}
BuildRequires: libstdc++-devel
BuildRequires: libtiff-devel >= 4.0
+BuildRequires: libtirpc-devel
BuildRequires: libtool
BuildRequires: libuuid-devel
BuildRequires: libwebp-devel
BuildRequires: qhull-devel >= 2012
%{?with_rasdaman:BuildRequires: rasdaman-devel}
BuildRequires: rpm-pythonprov
-BuildRequires: rpmbuild(macros) >= 1.344
+BuildRequires: rpmbuild(macros) >= 2.021
BuildRequires: sed >= 4.0
BuildRequires: sqlite3-devel >= 3.0.0
BuildRequires: swig-perl
BuildRequires: zlib-devel >= 1.1.4
# for ZSTD compression in TIFF
BuildRequires: zstd-devel
+%{?with_java:Requires: %{?use_jdk:%{use_jdk}-jre-base}%{!?use_jdk:jre}}
Requires: freexl >= 1.0
Requires: geos >= 3.1.0
Requires: hdf >= 4.2.5
%patch0 -p1
%patch1 -p1
%patch2 -p1
-%patch9 -p1
-%patch12 -p1
-%patch13 -p1
-%patch15 -p1
+%patch3 -p1
+%patch4 -p1
+%patch5 -p1
+%patch6 -p1
+%patch7 -p1
+%patch8 -p1
+%patch9 -p2
+%patch10 -p2
# need to regenerate (old ones don't support perl 5.10)
%{__rm} swig/perl/{gdal_wrap.cpp,gdalconst_wrap.c,ogr_wrap.cpp,osr_wrap.cpp}
%{__sed} -i -e 's,DODS_INC="-I.*,DODS_INC="$(pkg-config --cflags libdap)",' configure.ac
+sed -E -i -e '1s,#!\s*/usr/bin/env\s+python2(\s|$),#!%{__python}\1,' \
+ -e '1s,#!\s*/usr/bin/env\s+python(\s|$),#!%{__python}\1,' \
+ -e '1s,#!\s*/usr/bin/python(\s|$),#!%{__python}\1,' \
+ swig/python/scripts/epsg_tr.py \
+ swig/python/scripts/esri2wkt.py \
+ swig/python/scripts/gcps2vec.py \
+ swig/python/scripts/gcps2wld.py \
+ swig/python/scripts/gdal2tiles.py \
+ swig/python/scripts/gdal2xyz.py \
+ swig/python/scripts/gdal_auth.py \
+ swig/python/scripts/gdal_calc.py \
+ swig/python/scripts/gdal_edit.py \
+ swig/python/scripts/gdal_fillnodata.py \
+ swig/python/scripts/gdal_merge.py \
+ swig/python/scripts/gdal_pansharpen.py \
+ swig/python/scripts/gdal_polygonize.py \
+ swig/python/scripts/gdal_proximity.py \
+ swig/python/scripts/gdal_retile.py \
+ swig/python/scripts/gdal_sieve.py \
+ swig/python/scripts/gdalchksum.py \
+ swig/python/scripts/gdalcompare.py \
+ swig/python/scripts/gdalident.py \
+ swig/python/scripts/gdalimport.py \
+ swig/python/scripts/gdalmove.py \
+ swig/python/scripts/mkgraticule.py \
+ swig/python/scripts/ogrmerge.py \
+ swig/python/scripts/pct2rgb.py \
+ swig/python/scripts/rgb2pct.py
+
%build
+cp -f /usr/share/gettext/config.rpath .
+
+%if %{with java}
%ifarch %{x8664}
jvm_arch=amd64
%endif
%ifarch x32
jvm_arch=x32
%endif
+%ifarch aarch64
+jvm_arch=aarch64
+%endif
+%ifarch %{arm}
+jvm_arch=aarch32
+%endif
+for jvm_type in server client; do
+ for dir in lib jre/lib/$jvm_arch; do
+ if [ -f "%{java_home}/$dir/$jvm_type/libjvm.so" ]; then
+ jvm_lib="%{java_home}/$dir/$jvm_type"
+ break
+ fi
+ done
+done
+%endif
%{__libtoolize}
%{__aclocal} -I m4
%{?with_java:--with-java=%{java_home}} \
--with-liblzma \
%{!?with_kea:--without-kea} \
- %{?with_java:--with-mdb --with-jvm-lib-add-rpath --with-jvm-lib=%{java_home}/jre/lib/$jvm_arch/server} \
+ %{?with_java:--with-mdb --with-jvm-lib-add-rpath --with-jvm-lib="$jvm_lib"} \
%{?with_mysql:--with-mysql} \
%{?with_oci:--with-oci --with-oci-include=/usr/include/oracle/client --with-oci-lib=%{_libdir}} \
%{?with_opencl:--with-opencl} \
%attr(755,root,root) %{_bindir}/rgb2pct.py
%attr(755,root,root) %{_bindir}/testepsg
%attr(755,root,root) %{_libdir}/libgdal.so.*.*.*
-%attr(755,root,root) %ghost %{_libdir}/libgdal.so.20
+%attr(755,root,root) %ghost %{_libdir}/libgdal.so.26
%dir %{_libdir}/gdalplugins
%{_datadir}/gdal
%{_mandir}/man1/gdal2tiles.1*
--- /dev/null
+diff -rupN --no-dereference gdal-3.2.0-fedora/frmts/dods/GNUmakefile gdal-3.2.0-fedora-new/frmts/dods/GNUmakefile
+--- gdal-3.2.0-fedora/frmts/dods/GNUmakefile 2020-10-26 14:05:39.000000000 +0100
++++ gdal-3.2.0-fedora-new/frmts/dods/GNUmakefile 2020-11-12 00:13:52.314881073 +0100
+@@ -4,7 +4,7 @@ include ../../GDALmake.opt
+
+ OBJ = dodsdataset2.o
+
+-CPPFLAGS := $(CPPFLAGS) $(DODS_INC)
++CPPFLAGS := $(CPPFLAGS) $(DODS_INC) -I/usr/include/tirpc
+
+ default: $(OBJ:.o=.$(OBJ_EXT))
+
+diff -rupN --no-dereference gdal-3.2.0-fedora/ogr/ogrsf_frmts/dods/GNUmakefile gdal-3.2.0-fedora-new/ogr/ogrsf_frmts/dods/GNUmakefile
+--- gdal-3.2.0-fedora/ogr/ogrsf_frmts/dods/GNUmakefile 2020-10-26 14:05:39.000000000 +0100
++++ gdal-3.2.0-fedora-new/ogr/ogrsf_frmts/dods/GNUmakefile 2020-11-12 00:13:52.314881073 +0100
+@@ -5,7 +5,7 @@ include ../../../GDALmake.opt
+ OBJ = ogrdodsdriver.o ogrdodsdatasource.o ogrdodslayer.o \
+ ogrdodssequencelayer.o ogrdodsfielddefn.o ogrdodsgrid.o
+
+-CPPFLAGS := -I.. $(CPPFLAGS) $(DODS_INC) -DDO_NOT_USE_DEBUG_BOOL
++CPPFLAGS := -I.. $(CPPFLAGS) $(DODS_INC) -DDO_NOT_USE_DEBUG_BOOL -I/usr/include/tirpc
+
+ default: $(O_OBJ:.o=.$(OBJ_EXT))
+
--- /dev/null
+From 3c5cb6266a01a607ee7560807465bc833240d793 Mon Sep 17 00:00:00 2001
+From: Even Rouault <even.rouault@spatialys.com>
+Date: Mon, 10 Aug 2020 17:26:53 +0200
+Subject: [PATCH] JPEG2000: fix build with Jasper 2.0.17 (fixes #2844)
+
+---
+ gdal/frmts/jpeg2000/jpeg2000dataset.cpp | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/gdal/frmts/jpeg2000/jpeg2000dataset.cpp b/gdal/frmts/jpeg2000/jpeg2000dataset.cpp
+index 3e668ffe503..2d3f4e46876 100644
+--- a/gdal/frmts/jpeg2000/jpeg2000dataset.cpp
++++ b/gdal/frmts/jpeg2000/jpeg2000dataset.cpp
+@@ -484,7 +484,7 @@ int JPEG2000Dataset::DecodeImage()
+ /* the JP2 boxes match the ones of the code stream */
+ if (nBands != 0)
+ {
+- if (nBands != jas_image_numcmpts( psImage ))
++ if (nBands != static_cast<int>(jas_image_numcmpts( psImage )))
+ {
+ CPLError(CE_Failure, CPLE_AppDefined,
+ "The number of components indicated in the IHDR box (%d) mismatch "
+@@ -595,7 +595,7 @@ GDALDataset *JPEG2000Dataset::Open( GDALOpenInfo * poOpenInfo )
+
+ {
+ int iFormat;
+- char *pszFormatName = nullptr;
++ const char *pszFormatName = nullptr;
+
+ if (!Identify(poOpenInfo))
+ return nullptr;
+From e236eeaed1be45a4af457565085e3db1f2fc489f Mon Sep 17 00:00:00 2001
+From: Even Rouault <even.rouault@spatialys.com>
+Date: Tue, 11 Aug 2020 09:26:41 +0200
+Subject: [PATCH] JPEG2000: follow-up fix to build with Jasper 2.0.17 (fixes
+ #2844)
+
+---
+ gdal/frmts/jpeg2000/jpeg2000_vsil_io.cpp | 10 ++++++++++
+ 1 file changed, 10 insertions(+)
+
+diff --git a/gdal/frmts/jpeg2000/jpeg2000_vsil_io.cpp b/gdal/frmts/jpeg2000/jpeg2000_vsil_io.cpp
+index e780d2bcaed..10a4f96f0ee 100644
+--- a/gdal/frmts/jpeg2000/jpeg2000_vsil_io.cpp
++++ b/gdal/frmts/jpeg2000/jpeg2000_vsil_io.cpp
+@@ -94,13 +94,23 @@ typedef struct {
+ * File stream object.
+ \******************************************************************************/
+
++// PRIjas_seqent macro is defined since Jasper 2.0.17
++
++#ifndef PRIjas_seqent
+ static int JPEG2000_VSIL_read(jas_stream_obj_t *obj, char *buf, int cnt)
++#else
++static int JPEG2000_VSIL_read(jas_stream_obj_t *obj, char *buf, unsigned cnt)
++#endif
+ {
+ jas_stream_VSIFL_t *fileobj = JAS_CAST(jas_stream_VSIFL_t *, obj);
+ return static_cast<int>(VSIFReadL(buf, 1, cnt, fileobj->fp));
+ }
+
++#ifndef PRIjas_seqent
+ static int JPEG2000_VSIL_write(jas_stream_obj_t *obj, char *buf, int cnt)
++#else
++static int JPEG2000_VSIL_write(jas_stream_obj_t *obj, char *buf, unsigned int cnt)
++#endif
+ {
+ jas_stream_VSIFL_t *fileobj = JAS_CAST(jas_stream_VSIFL_t *, obj);
+ return static_cast<int>(VSIFWriteL(buf, 1, cnt, fileobj->fp));
+From 1562e215c6f53a53efa66263113ecc6e761818d2 Mon Sep 17 00:00:00 2001
+From: Even Rouault <even.rouault@spatialys.com>
+Date: Mon, 5 Oct 2020 12:11:52 +0200
+Subject: [PATCH] JPEG2000: make it build with Jasper 2.0.21 (fixes #3012)
+
+---
+ gdal/frmts/jpeg2000/jpeg2000_vsil_io.cpp | 16 +++++++++-------
+ gdal/frmts/jpeg2000/jpeg2000dataset.cpp | 2 +-
+ 2 files changed, 10 insertions(+), 8 deletions(-)
+
+diff --git a/gdal/frmts/jpeg2000/jpeg2000_vsil_io.cpp b/gdal/frmts/jpeg2000/jpeg2000_vsil_io.cpp
+index 10a4f96f0ee..ebcac4010ce 100644
+--- a/gdal/frmts/jpeg2000/jpeg2000_vsil_io.cpp
++++ b/gdal/frmts/jpeg2000/jpeg2000_vsil_io.cpp
+@@ -94,22 +94,24 @@ typedef struct {
+ * File stream object.
+ \******************************************************************************/
+
++#if defined(PRIjas_seqent)
+ // PRIjas_seqent macro is defined since Jasper 2.0.17
+-
+-#ifndef PRIjas_seqent
+-static int JPEG2000_VSIL_read(jas_stream_obj_t *obj, char *buf, int cnt)
+-#else
+ static int JPEG2000_VSIL_read(jas_stream_obj_t *obj, char *buf, unsigned cnt)
++#else
++static int JPEG2000_VSIL_read(jas_stream_obj_t *obj, char *buf, int cnt)
+ #endif
+ {
+ jas_stream_VSIFL_t *fileobj = JAS_CAST(jas_stream_VSIFL_t *, obj);
+ return static_cast<int>(VSIFReadL(buf, 1, cnt, fileobj->fp));
+ }
+
+-#ifndef PRIjas_seqent
+-static int JPEG2000_VSIL_write(jas_stream_obj_t *obj, char *buf, int cnt)
+-#else
++#if defined(JAS_INCLUDE_JP2_CODEC)
++// Jasper 2.0.21
++static int JPEG2000_VSIL_write(jas_stream_obj_t *obj, const char *buf, unsigned int cnt)
++#elif defined(PRIjas_seqent)
+ static int JPEG2000_VSIL_write(jas_stream_obj_t *obj, char *buf, unsigned int cnt)
++#else
++static int JPEG2000_VSIL_write(jas_stream_obj_t *obj, char *buf, int cnt)
+ #endif
+ {
+ jas_stream_VSIFL_t *fileobj = JAS_CAST(jas_stream_VSIFL_t *, obj);
+diff --git a/gdal/frmts/jpeg2000/jpeg2000dataset.cpp b/gdal/frmts/jpeg2000/jpeg2000dataset.cpp
+index a5a6b258ed9..bd1e7763186 100644
+--- a/gdal/frmts/jpeg2000/jpeg2000dataset.cpp
++++ b/gdal/frmts/jpeg2000/jpeg2000dataset.cpp
+@@ -513,7 +513,7 @@ int JPEG2000Dataset::DecodeImage()
+ for ( iBand = 0; iBand < nBands; iBand++ )
+ {
+ JPEG2000RasterBand* poBand = (JPEG2000RasterBand*) GetRasterBand(iBand+1);
+- if (poBand->iDepth != jas_image_cmptprec( psImage, iBand ) ||
++ if (poBand->iDepth != static_cast<int>(jas_image_cmptprec( psImage, iBand )) ||
+ poBand->bSignedness != jas_image_cmptsgnd( psImage, iBand ))
+ {
+ CPLError(CE_Failure, CPLE_AppDefined,