Created
January 21, 2018 23:23
-
-
Save palmerj/6035fa41b3c30ab573c12741012ab011 to your computer and use it in GitHub Desktop.
Patch to support building the libecwj2 library on MacOSX based on https://trac.osgeo.org/gdal/attachment/wiki/ECW/libecwj2-3.3.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/Source/C/NCSEcw/NCSJP2/NCSJPCResolution.cpp b/Source/C/NCSEcw/NCSJP2/NCSJPCResolution.cpp | |
index 12a0cce..8747b24 100644 | |
--- a/Source/C/NCSEcw/NCSJP2/NCSJPCResolution.cpp | |
+++ b/Source/C/NCSEcw/NCSJP2/NCSJPCResolution.cpp | |
@@ -1773,10 +1773,10 @@ bool CNCSJPCResolution::SD_2D_OUTPUT4(ContextID nCtx, | |
//Step0-1 == 2State. | |
// | |
- UINT32 n = 0; | |
+ INT32 n = 0; | |
nWidth = NCSCeilDiv(nWidth, 2); | |
- UINT32 n2n = n * 2 - 2; | |
+ INT32 n2n = n * 2 - 2; | |
INT32 nPrevVert01 = pSrc1Down[n2n] - NCSFloorDiv(pSrc0[n2n] + pSrc2Down[n2n], 2); | |
INT32 nPrevVert11 = pSrc1Down[n2n+1] - NCSFloorDiv(pSrc0[n2n+1] + pSrc2Down[n2n+1], 2); | |
diff --git a/Source/C/NCSEcw/lcms/include/lcms.h b/Source/C/NCSEcw/lcms/include/lcms.h | |
index fa08c9a..6ef0648 100644 | |
--- a/Source/C/NCSEcw/lcms/include/lcms.h | |
+++ b/Source/C/NCSEcw/lcms/include/lcms.h | |
@@ -133,20 +133,12 @@ struct tm { | |
# define USE_C 1 | |
#endif | |
-#if defined(__sgi__) || defined(__sgi) || defined(__powerpc__) || defined(sparc) || defined(__ppc__) | |
-# define USE_BIG_ENDIAN 1 | |
-#endif | |
- | |
-#if TARGET_CPU_PPC | |
-# define USE_BIG_ENDIAN 1 | |
-#endif | |
- | |
-#ifdef macintosh | |
-# define USE_BIG_ENDIAN 1 | |
-#endif | |
- | |
-#ifdef WORDS_BIGENDIAN | |
-# define USE_BIG_ENDIAN 1 | |
+#ifdef __BIG_ENDIAN__ | |
+ #define WORDS_BIGENDIAN 1 | |
+ #define USE_BIG_ENDIAN 1 | |
+#else | |
+ #undef WORDS_BIGENDIAN | |
+ #undef USE_BIG_ENDIAN | |
#endif | |
#if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__) | |
diff --git a/Source/C/NCSUtil/NCSPrefsXML.cpp b/Source/C/NCSUtil/NCSPrefsXML.cpp | |
index b512f79..bc496d2 100644 | |
--- a/Source/C/NCSUtil/NCSPrefsXML.cpp | |
+++ b/Source/C/NCSUtil/NCSPrefsXML.cpp | |
@@ -32,7 +32,11 @@ void CNCSPrefsXML::Init() | |
} else { | |
char *pHomeDir = getenv("HOME"); | |
if( pHomeDir ) { | |
+#ifdef NCS_BUILD_UNICODE | |
+ sUserPrefsFile.Format( NCS_T("%s%ls"), pHomeDir, NCS_T("/.erm/ncsuserprefs.xml") ); | |
+#else | |
sUserPrefsFile.Format( NCS_T("%s%s"), pHomeDir, NCS_T("/.erm/ncsuserprefs.xml") ); | |
+#endif | |
} else { | |
sUserPrefsFile = NCS_T("/etc/erm/ncsuserprefs.xml"); | |
} | |
diff --git a/Source/C/NCSUtil/NCSThread.cpp b/Source/C/NCSUtil/NCSThread.cpp | |
index c16ce4f..04fa71e 100644 | |
--- a/Source/C/NCSUtil/NCSThread.cpp | |
+++ b/Source/C/NCSUtil/NCSThread.cpp | |
@@ -47,6 +47,12 @@ bool CNCSThread::Spawn(void *pData, bool bCreateSuspended) { | |
//void **pStartData = (void **)NCSMalloc(2 * sizeof(void*), TRUE); | |
//pStartData[0] = (void*)this; | |
//pStartData[1] = pData; | |
+ if( m_Thread != NCS_NULL_THREAD_ID ) | |
+ { | |
+ //fprintf( stderr, "Cleanup old threadinfo in spawn()\n" ); | |
+ FreeInfo(); | |
+ m_Thread = NCS_NULL_THREAD_ID; | |
+ } | |
m_pData = pData; | |
m_bRun = true; | |
return(NCSThreadSpawn(&m_Thread, CNCSThread::ThreadFunc, (void*)this, bCreateSuspended)==TRUE); | |
diff --git a/Source/C/NCSUtil/file.c b/Source/C/NCSUtil/file.c | |
index 46267bd..60b0db6 100644 | |
--- a/Source/C/NCSUtil/file.c | |
+++ b/Source/C/NCSUtil/file.c | |
@@ -41,6 +41,7 @@ | |
#ifdef MACOSX | |
# include "CoreServices/CoreServices.h" | |
+# include <unistd.h> | |
#endif | |
#ifndef _WIN32_WCE | |
@@ -1084,6 +1085,10 @@ char *NCSGetTempDirectory(void) | |
return(NCSStrDup("")); | |
+#elif defined POSIX | |
+ | |
+ return(NCSStrDup("/tmp")); | |
+ | |
#elif defined MACOSX | |
FSRef tempRef; | |
@@ -1098,10 +1103,6 @@ char *NCSGetTempDirectory(void) | |
return( NCSStrDup(szPath) ); | |
-#elif defined POSIX | |
- | |
- return(NCSStrDup("/tmp")); | |
- | |
#else /* PALM */ | |
char *szTmpDir = getenv("TMP"); | |
if (szTmpDir != NULL) | |
diff --git a/Source/C/NCSUtil/malloc.c b/Source/C/NCSUtil/malloc.c | |
index 6db5a84..8adc49a 100644 | |
--- a/Source/C/NCSUtil/malloc.c | |
+++ b/Source/C/NCSUtil/malloc.c | |
@@ -390,7 +390,12 @@ INT32 NCSPhysicalMemorySize(void) | |
#else /* SOLARIS */ | |
#ifdef LINUX | |
- return(sysconf(_SC_PHYS_PAGES) * sysconf(_SC_PAGESIZE)); | |
+ long nPages = sysconf(_SC_PHYS_PAGES); | |
+ long nPageSize = sysconf(_SC_PAGESIZE); | |
+ if (nPages > INT_MAX / nPageSize) | |
+ return INT_MAX; | |
+ else | |
+ return (INT32)(nPages * nPageSize); | |
#elif defined MACOSX | |
return(128*1024*1024); | |
diff --git a/Source/C/NCSUtil/thread.c b/Source/C/NCSUtil/thread.c | |
index 46dedc8..67133b8 100644 | |
--- a/Source/C/NCSUtil/thread.c | |
+++ b/Source/C/NCSUtil/thread.c | |
@@ -46,6 +46,11 @@ | |
pthread_attr_t sAttributes; | |
#endif | |
+#ifdef MACOSX | |
+// Native thread calls needed to work around pthread issues | |
+#include <mach/thread_act.h> | |
+#endif | |
+ | |
/* | |
** Internal thread info. | |
*/ | |
@@ -426,8 +431,14 @@ void NCSThreadFreeInfo(NCSThread *pThread) | |
#elif defined(PALM) | |
#elif defined(MACINTOSH) | |
#elif defined(POSIX) | |
+#ifndef MACOSX | |
void *value_pair = (void*)NULL; | |
pthread_join(ppThreadInfos[i]->thread, &value_pair); | |
+#else | |
+ // Work around non-POSIX pthreads implementation | |
+ mach_port_t machThread = pthread_mach_thread_np(ppThreadInfos[i]->thread); | |
+ thread_terminate (machThread); | |
+#endif // MACOSX | |
NCSMutexFini(&ppThreadInfos[i]->mSuspendMutex); | |
#else | |
#error NCSThreadFreeInfo() | |
diff --git a/Source/C/NCSnet/NCScnet3/NCSGetPasswordDlg.cpp b/Source/C/NCSnet/NCScnet3/NCSGetPasswordDlg.cpp | |
index 7171ee2..4eb0622 100644 | |
--- a/Source/C/NCSnet/NCScnet3/NCSGetPasswordDlg.cpp | |
+++ b/Source/C/NCSnet/NCScnet3/NCSGetPasswordDlg.cpp | |
@@ -31,7 +31,7 @@ | |
#endif // WIN32 | |
#if defined(MACOSX) | |
-#include "Carbon/Carbon.h" | |
+//#include "Carbon/Carbon.h" | |
#include "NCSThread.h" | |
#endif | |
@@ -86,7 +86,7 @@ BOOL CALLBACK PasswordDlgProc(HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam | |
#define DLLNAME "NCScnet.dll" | |
#endif | |
-#elif defined(MACOSX) | |
+#elif defined(BOGUS) | |
typedef struct { | |
WindowRef theWindow; | |
@@ -219,7 +219,7 @@ bool NCSGetPasswordDlg( const char *pszSite, const char *pszRealm, string &sUser | |
sPassword = ""; | |
return false; | |
} | |
-#elif defined(MACOSX) | |
+#elif defined(BOGUS) | |
OSStatus err; | |
IBNibRef theNib; | |
WindowRef theWindow; | |
diff --git a/Source/C/NCSnet/NCScnet3/NCSProxy.cpp b/Source/C/NCSnet/NCScnet3/NCSProxy.cpp | |
index 90adc4e..57f2b41 100644 | |
--- a/Source/C/NCSnet/NCScnet3/NCSProxy.cpp | |
+++ b/Source/C/NCSnet/NCScnet3/NCSProxy.cpp | |
@@ -31,6 +31,7 @@ | |
#elif defined(POSIX) | |
# ifdef MACOSX | |
# include <ctype.h> | |
+# include <unistd.h> | |
# else | |
# include <wctype.h> | |
# endif | |
diff --git a/Source/C/NCSnet/NCScnet3/NCSSocket.cpp b/Source/C/NCSnet/NCScnet3/NCSSocket.cpp | |
index 18ea477..70ba6bf 100644 | |
--- a/Source/C/NCSnet/NCScnet3/NCSSocket.cpp | |
+++ b/Source/C/NCSnet/NCScnet3/NCSSocket.cpp | |
@@ -187,11 +187,7 @@ CNCSSocket::CNCSSocket(const int handle) | |
//init(); | |
struct sockaddr_in info; | |
#if defined(POSIX) && !defined(HPUX) | |
-# ifdef MACOSX | |
- int tempSize = sizeof(struct sockaddr); | |
-# else | |
socklen_t tempSize = sizeof(struct sockaddr); | |
-# endif | |
#else | |
int tempSize = sizeof(struct sockaddr); | |
#endif | |
diff --git a/Source/C/tinyxml/tinyxml.cpp b/Source/C/tinyxml/tinyxml.cpp | |
index 8706683..136e0b8 100644 | |
--- a/Source/C/tinyxml/tinyxml.cpp | |
+++ b/Source/C/tinyxml/tinyxml.cpp | |
@@ -30,6 +30,9 @@ distribution. | |
#endif | |
+namespace NCSTiXML { | |
+ | |
+ | |
bool TiXmlBase::condenseWhiteSpace = true; | |
void TiXmlBase::PutString( const TIXML_STRING& str, TIXML_OSTREAM* stream ) | |
@@ -983,7 +986,7 @@ bool TiXmlDocument::LoadFile( const char* filename, TiXmlEncoding encoding ) | |
fseek( file, 0, SEEK_SET ); | |
// Strange case, but good to handle up front. | |
- if ( length == 0 ) | |
+ if ( length <= 0 || length > INT_MAX ) | |
{ | |
fclose( file ); | |
return false; | |
@@ -1020,6 +1023,8 @@ bool TiXmlDocument::LoadFile( const char* filename, TiXmlEncoding encoding ) | |
if ( fread( buf, length, 1, file ) != 1 ) { | |
//if ( fread( buf, 1, length, file ) != (size_t)length ) { | |
+ delete[] buf; | |
+ buf = NULL; | |
SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN ); | |
fclose( file ); | |
return false; | |
@@ -1730,3 +1735,5 @@ TiXmlHandle TiXmlHandle::ChildElement( const char* value, int count ) const | |
} | |
return TiXmlHandle( 0 ); | |
} | |
+ | |
+}; // namespace NCSTiXML | |
diff --git a/Source/C/tinyxml/tinyxml.h b/Source/C/tinyxml/tinyxml.h | |
index 8c384d7..acde948 100644 | |
--- a/Source/C/tinyxml/tinyxml.h | |
+++ b/Source/C/tinyxml/tinyxml.h | |
@@ -92,6 +92,8 @@ distribution. | |
#endif | |
#endif | |
+namespace NCSTiXML { | |
+ | |
class TiXmlDocument; | |
class TiXmlElement; | |
class TiXmlComment; | |
@@ -1513,6 +1515,20 @@ private: | |
TiXmlNode* node; | |
}; | |
+}; // namespace NCSTiXML | |
+ | |
+using NCSTiXML::TiXmlBase; | |
+using NCSTiXML::TiXmlDocument; | |
+using NCSTiXML::TiXmlElement; | |
+using NCSTiXML::TiXmlComment; | |
+using NCSTiXML::TiXmlUnknown; | |
+using NCSTiXML::TiXmlAttribute; | |
+using NCSTiXML::TiXmlText; | |
+using NCSTiXML::TiXmlDeclaration; | |
+using NCSTiXML::TiXmlParsingData; | |
+using NCSTiXML::TiXmlHandle; | |
+using NCSTiXML::TiXmlNode; | |
+ | |
#ifdef _MSC_VER | |
#pragma warning( pop ) | |
#endif | |
diff --git a/Source/C/tinyxml/tinyxmlparser.cpp b/Source/C/tinyxml/tinyxmlparser.cpp | |
index 67d0a9e..880187f 100644 | |
--- a/Source/C/tinyxml/tinyxmlparser.cpp | |
+++ b/Source/C/tinyxml/tinyxmlparser.cpp | |
@@ -28,6 +28,9 @@ distribution. | |
//#define DEBUG_PARSER | |
+ | |
+namespace NCSTiXML { | |
+ | |
// Note tha "PutString" hardcodes the same list. This | |
// is less flexible than it appears. Changing the entries | |
// or order will break putstring. | |
@@ -1570,3 +1573,4 @@ bool TiXmlText::Blank() const | |
return true; | |
} | |
+}; // namespace NCSTiXML | |
diff --git a/Source/NCSBuildGnu/Makefile.am b/Source/NCSBuildGnu/Makefile.am | |
index f0a2ba8..eb7f1d6 100644 | |
--- a/Source/NCSBuildGnu/Makefile.am | |
+++ b/Source/NCSBuildGnu/Makefile.am | |
@@ -7,9 +7,13 @@ NCSTypesWithGnuDefs.h: NCSGnuSystemDefs.h ../include/NCSTypes.h | |
cat ../include/NCSTypes.h >> NCSTypesWithGnuDefs.h | |
install-data-local: NCSTypesWithGnuDefs.h | |
+ mkdir -p $(DESTDIR)$(includedir); \ | |
$(includeHEADERS_INSTALL) NCSTypesWithGnuDefs.h \ | |
$(DESTDIR)$(includedir)/NCSTypes.h | |
+uninstall-data-local: | |
+ rm -f $(DESTDIR)$(includedir)/NCSTypes.h | |
+ | |
NCSECWSRC = \ | |
../C/NCSEcw/NCSJP2/NCSJP2.cpp \ | |
../C/NCSEcw/NCSJP2/NCSJP2BitsPerComponentBox.cpp \ | |
diff --git a/Source/NCSBuildGnu/Makefile.in b/Source/NCSBuildGnu/Makefile.in | |
index 504f824..5771f85 100644 | |
--- a/Source/NCSBuildGnu/Makefile.in | |
+++ b/Source/NCSBuildGnu/Makefile.in | |
@@ -1041,6 +1041,9 @@ install-libLIBRARIES: $(lib_LIBRARIES) | |
else :; fi; \ | |
done | |
+uninstall-data-local: | |
+ rm -f $(DESTDIR)$(includedir)/NCSTypes.h | |
+ | |
uninstall-libLIBRARIES: | |
@$(NORMAL_UNINSTALL) | |
@list='$(lib_LIBRARIES)'; for p in $$list; do \ | |
@@ -11633,7 +11636,7 @@ ps: ps-am | |
ps-am: | |
-uninstall-am: uninstall-includeHEADERS uninstall-info-am \ | |
+uninstall-am: uninstall-includeHEADERS uninstall-info-am uninstall-data-local \ | |
uninstall-libLIBRARIES uninstall-libLTLIBRARIES | |
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ | |
@@ -11658,6 +11661,7 @@ NCSTypesWithGnuDefs.h: NCSGnuSystemDefs.h ../include/NCSTypes.h | |
cat ../include/NCSTypes.h >> NCSTypesWithGnuDefs.h | |
install-data-local: NCSTypesWithGnuDefs.h | |
+ mkdir -p $(DESTDIR)$(includedir); \ | |
$(includeHEADERS_INSTALL) NCSTypesWithGnuDefs.h \ | |
$(DESTDIR)$(includedir)/NCSTypes.h | |
# Tell versions [3.59,3.63) of GNU make to not export all variables. | |
diff --git a/Source/include/NCSDefs.h b/Source/include/NCSDefs.h | |
index a6fda24..b8a763f 100644 | |
--- a/Source/include/NCSDefs.h | |
+++ b/Source/include/NCSDefs.h | |
@@ -58,7 +58,11 @@ extern "C" { | |
#endif | |
#if (defined(MACINTOSH)||defined(SOLARIS)||defined(IRIX)||defined(PALM)||defined(HPUX)||defined(MACOSX))&&(!defined(X86)) | |
+#ifdef __LITTLE_ENDIAN__ | |
+#define NCSBO_LSBFIRST | |
+#else | |
#define NCSBO_MSBFIRST | |
+#endif | |
#else // WIN32, LINUX (i386) | |
#define NCSBO_LSBFIRST | |
#endif | |
@@ -126,6 +130,10 @@ extern "C" { | |
#include <limits.h> | |
#include <ctype.h> | |
+#ifdef __LP64__ | |
+#define NCS_64BIT | |
+#endif | |
+ | |
#define NCS_FQNAN 0x0002 | |
#define NCS_NAN NAN | |
#ifndef MAXDOUBLE | |
@@ -427,14 +435,6 @@ static NCS_INLINE int wcsicmp(const wchar_t *s1, const wchar_t *s2) | |
return(towlower(*s1) - towlower(*s2)); | |
} | |
-static NCS_INLINE wchar_t *wcsdup(const wchar_t *s1) | |
-{ | |
- size_t len = (wcslen(s1) + 1) * sizeof(wchar_t); | |
- wchar_t *s2 = (wchar_t*)malloc(len); | |
- memcpy(s2, s1, len); | |
- return(s2); | |
-} | |
- | |
#endif /* SOLARIS || MACOSX */ | |
#else /* NCS_BUILD_UNICODE */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment