From: Oliver Schmidt
Date: Mon, 3 Mar 2014 21:12:14 +0000 (+0100)
Subject: Improve MinGW support.
X-Git-Tag: V2.15~138
X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=50c4fd1c4ce740c8e9ae1e416dc7daa3dbdb5e82;p=cc65
Improve MinGW support.
- Code specific to Windows was #ifdef'ed with _MSC_VER so it wasn't included with MinGW. So _MSC_VER is replaced with _WIN32.
- MinGW doesn't support _get_pgmptr() so it is necessary to directly call the Win32 function GetModuleFileName(). This implies including windows.h which in turn causes a name clash with the Win32 function SearchPath(). So the cc65 type SearchPath is renamed to SearchPaths.
---
diff --git a/src/ca65/incpath.c b/src/ca65/incpath.c
index 76ad3111a..81422b059 100644
--- a/src/ca65/incpath.c
+++ b/src/ca65/incpath.c
@@ -44,8 +44,8 @@
-SearchPath* IncSearchPath; /* Standard include path */
-SearchPath* BinSearchPath; /* Binary include path */
+SearchPaths* IncSearchPath; /* Standard include path */
+SearchPaths* BinSearchPath; /* Binary include path */
@@ -75,7 +75,7 @@ void FinishIncludePaths (void)
AddSubSearchPathFromEnv (IncSearchPath, "CC65_HOME", "asminc");
/* Add some compiled-in search paths if defined at compile time. */
-#ifdef CA65_INC
+#if defined(CA65_INC) && !defined(_WIN32)
AddSearchPath (IncSearchPath, STRINGIZE (CA65_INC));
#endif
diff --git a/src/ca65/incpath.h b/src/ca65/incpath.h
index 841767e4b..5e23ebc72 100644
--- a/src/ca65/incpath.h
+++ b/src/ca65/incpath.h
@@ -49,8 +49,8 @@
-extern SearchPath* IncSearchPath; /* Standard include path */
-extern SearchPath* BinSearchPath; /* Binary include path */
+extern SearchPaths* IncSearchPath; /* Standard include path */
+extern SearchPaths* BinSearchPath; /* Binary include path */
diff --git a/src/cc65/incpath.c b/src/cc65/incpath.c
index 7a4b31e94..c74e167de 100644
--- a/src/cc65/incpath.c
+++ b/src/cc65/incpath.c
@@ -44,8 +44,8 @@
-SearchPath* SysIncSearchPath; /* System include path */
-SearchPath* UsrIncSearchPath; /* User include path */
+SearchPaths* SysIncSearchPath; /* System include path */
+SearchPaths* UsrIncSearchPath; /* User include path */
@@ -76,7 +76,7 @@ void FinishIncludePaths (void)
AddSubSearchPathFromEnv (SysIncSearchPath, "CC65_HOME", "include");
/* Add some compiled-in search paths if defined at compile time. */
-#ifdef CC65_INC
+#if defined(CC65_INC) && !defined(_WIN32)
AddSearchPath (SysIncSearchPath, STRINGIZE (CC65_INC));
#endif
diff --git a/src/cc65/incpath.h b/src/cc65/incpath.h
index ed8ba50cc..4df8fca44 100644
--- a/src/cc65/incpath.h
+++ b/src/cc65/incpath.h
@@ -49,8 +49,8 @@
-extern SearchPath* SysIncSearchPath; /* System include path */
-extern SearchPath* UsrIncSearchPath; /* User include path */
+extern SearchPaths* SysIncSearchPath; /* System include path */
+extern SearchPaths* UsrIncSearchPath; /* User include path */
diff --git a/src/cl65/main.c b/src/cl65/main.c
index e704d985c..d81a1bcc9 100644
--- a/src/cl65/main.c
+++ b/src/cl65/main.c
@@ -36,10 +36,10 @@
/* Check out if we have a spawn() function on the system, or if we must use
* our own.
*/
-#if defined(__WATCOMC__) || defined(_MSC_VER) || defined(__MINGW32__) || defined(__DJGPP__)
-# define HAVE_SPAWN 1
+#if defined(_WIN32)
+# define HAVE_SPAWN 1
#else
-# define NEED_SPAWN 1
+# define NEED_SPAWN 1
#endif
#if defined(_MSC_VER)
# pragma warning(disable : 4996)
@@ -375,7 +375,7 @@ static void ExecProgram (CmdDesc* Cmd)
}
/* Call the program */
- Status = spawnvp (P_WAIT, Cmd->Name, Cmd->Args);
+ Status = spawnvp (P_WAIT, Cmd->Name, (const char* const *) Cmd->Args);
/* Check the result code */
if (Status < 0) {
diff --git a/src/common/filestat.c b/src/common/filestat.c
index 0f5f5cd11..fd42c5ec0 100644
--- a/src/common/filestat.c
+++ b/src/common/filestat.c
@@ -2,7 +2,7 @@
/* */
/* filestat.c */
/* */
-/* Replacement for buggy Microsoft code */
+/* Replacement for Windows code */
/* */
/* */
/* */
@@ -46,8 +46,7 @@
#include
#include
-#if defined(__WATCOMC__) && defined(__NT__)
-#define BUGGY_OS 1
+#if defined(_WIN32)
#include
#include
#endif
@@ -63,7 +62,7 @@
-#if defined(BUGGY_OS)
+#if defined(_WIN32)
@@ -77,7 +76,7 @@ static time_t FileTimeToUnixTime (const FILETIME* T)
* way to express a number > 32 bit (known to me) but is able to do
* calculations with 64 bit integers, so we need to do it this way.
*/
- static const ULARGE_INTEGER Offs = { 0xB6109100UL, 0x00000020UL };
+ static const ULARGE_INTEGER Offs = { { 0xB6109100UL, 0x00000020UL } };
ULARGE_INTEGER V;
V.LowPart = T->dwLowDateTime;
V.HighPart = T->dwHighDateTime;
diff --git a/src/common/filestat.h b/src/common/filestat.h
index 50b7685ef..56ce2e9e0 100644
--- a/src/common/filestat.h
+++ b/src/common/filestat.h
@@ -2,7 +2,7 @@
/* */
/* filestat.h */
/* */
-/* Replacement for buggy Microsoft code */
+/* Replacement for Windows code */
/* */
/* */
/* */
diff --git a/src/common/filetime.c b/src/common/filetime.c
index 025380759..88a79bf97 100644
--- a/src/common/filetime.c
+++ b/src/common/filetime.c
@@ -2,7 +2,7 @@
/* */
/* filetime.c */
/* */
-/* Replacement for buggy Microsoft code */
+/* Replacement for Windows code */
/* */
/* */
/* */
@@ -42,18 +42,12 @@
-#if defined(__WATCOMC__) && defined(__NT__)
-#define BUGGY_OS 1
+#if defined(_WIN32)
#include
#include
#else
-#if defined(__WATCOMC__) || defined(_MSC_VER) || defined(__MINGW32__)
-/* The Windows compilers have the file in the wrong directory */
-# include
-#else
-# include /* FreeBSD needs this */
-# include
-#endif
+#include /* FreeBSD needs this */
+#include
#endif
@@ -68,7 +62,7 @@
-#if defined(BUGGY_OS)
+#if defined(_WIN32)
@@ -82,7 +76,7 @@ static FILETIME* UnixTimeToFileTime (time_t T, FILETIME* FT)
* way to express a number > 32 bit (known to me) but is able to do
* calculations with 64 bit integers, so we need to do it this way.
*/
- static const ULARGE_INTEGER Offs = { 0xB6109100UL, 0x00000020UL };
+ static const ULARGE_INTEGER Offs = { { 0xB6109100UL, 0x00000020UL } };
ULARGE_INTEGER V;
V.QuadPart = ((unsigned __int64) T + Offs.QuadPart) * 10000000U;
FT->dwLowDateTime = V.LowPart;
@@ -150,6 +144,3 @@ int SetFileTimes (const char* Path, time_t T)
#endif
-
-
-
diff --git a/src/common/filetime.h b/src/common/filetime.h
index 8a27712d9..4d20c7d63 100644
--- a/src/common/filetime.h
+++ b/src/common/filetime.h
@@ -2,7 +2,7 @@
/* */
/* filetime.h */
/* */
-/* Replacement for buggy Microsoft code */
+/* Replacement for Windows code */
/* */
/* */
/* */
diff --git a/src/common/searchpath.c b/src/common/searchpath.c
index 16945f36d..009deaded 100644
--- a/src/common/searchpath.c
+++ b/src/common/searchpath.c
@@ -35,6 +35,9 @@
#include
#include
+#if defined(_WIN32)
+# include
+#endif
#if defined(_MSC_VER)
/* Microsoft compiler */
# include
@@ -83,7 +86,7 @@ static char* CleanupPath (const char* Path)
-static void Add (SearchPath* P, const char* New)
+static void Add (SearchPaths* P, const char* New)
/* Cleanup a new search path and add it to the list */
{
/* Add a clean copy of the path to the collection */
@@ -92,7 +95,7 @@ static void Add (SearchPath* P, const char* New)
-SearchPath* NewSearchPath (void)
+SearchPaths* NewSearchPath (void)
/* Create a new, empty search path list */
{
return NewCollection ();
@@ -100,7 +103,7 @@ SearchPath* NewSearchPath (void)
-void AddSearchPath (SearchPath* P, const char* NewPath)
+void AddSearchPath (SearchPaths* P, const char* NewPath)
/* Add a new search path to the end of an existing list */
{
/* Allow a NULL path */
@@ -111,7 +114,7 @@ void AddSearchPath (SearchPath* P, const char* NewPath)
-void AddSearchPathFromEnv (SearchPath* P, const char* EnvVar)
+void AddSearchPathFromEnv (SearchPaths* P, const char* EnvVar)
/* Add a search path from an environment variable to the end of an existing
* list.
*/
@@ -121,7 +124,7 @@ void AddSearchPathFromEnv (SearchPath* P, const char* EnvVar)
-void AddSubSearchPathFromEnv (SearchPath* P, const char* EnvVar, const char* SubDir)
+void AddSubSearchPathFromEnv (SearchPaths* P, const char* EnvVar, const char* SubDir)
/* Add a search path from an environment variable, adding a subdirectory to
* the environment variable value.
*/
@@ -157,21 +160,20 @@ void AddSubSearchPathFromEnv (SearchPath* P, const char* EnvVar, const char* Sub
-void AddSubSearchPathFromWinBin (SearchPath* P, const char* SubDir)
+void AddSubSearchPathFromWinBin (SearchPaths* P, const char* SubDir)
{
/* Windows only:
* Add a search path from the running binary, adding a subdirectory to
* the parent directory of the directory containing the binary.
*/
-#if defined(_MSC_VER)
+#if defined(_WIN32)
char Dir[_MAX_PATH];
char* Ptr;
- if (_get_pgmptr (&Ptr) != 0) {
+ if (GetModuleFileName (NULL, Dir, _MAX_PATH) == 0) {
return;
}
- strcpy (Dir, Ptr);
/* Remove binary name */
Ptr = strrchr (Dir, '\\');
@@ -204,7 +206,7 @@ void AddSubSearchPathFromWinBin (SearchPath* P, const char* SubDir)
}
-int PushSearchPath (SearchPath* P, const char* NewPath)
+int PushSearchPath (SearchPaths* P, const char* NewPath)
/* Add a new search path to the head of an existing search path list, provided
* that it's not already there. If the path is already at the first position,
* return zero, otherwise return a non zero value.
@@ -227,7 +229,7 @@ int PushSearchPath (SearchPath* P, const char* NewPath)
-void PopSearchPath (SearchPath* P)
+void PopSearchPath (SearchPaths* P)
/* Remove a search path from the head of an existing search path list */
{
/* Remove the path at position 0 */
@@ -237,7 +239,7 @@ void PopSearchPath (SearchPath* P)
-char* SearchFile (const SearchPath* P, const char* File)
+char* SearchFile (const SearchPaths* P, const char* File)
/* Search for a file in a list of directories. Return a pointer to a malloced
* area that contains the complete path, if found, return 0 otherwise.
*/
@@ -271,6 +273,3 @@ char* SearchFile (const SearchPath* P, const char* File)
SB_Done (&PathName);
return Name;
}
-
-
-
diff --git a/src/common/searchpath.h b/src/common/searchpath.h
index 555a0e18e..33db0c779 100644
--- a/src/common/searchpath.h
+++ b/src/common/searchpath.h
@@ -53,7 +53,7 @@
#define STRINGIZE(arg) _STRINGIZE(arg)
/* A search path is a pointer to the list */
-typedef struct Collection SearchPath;
+typedef struct Collection SearchPaths;
@@ -63,38 +63,38 @@ typedef struct Collection SearchPath;
-SearchPath* NewSearchPath (void);
+SearchPaths* NewSearchPath (void);
/* Create a new, empty search path list */
-void AddSearchPath (SearchPath* P, const char* NewPath);
+void AddSearchPath (SearchPaths* P, const char* NewPath);
/* Add a new search path to the end of an existing list */
-void AddSearchPathFromEnv (SearchPath* P, const char* EnvVar);
+void AddSearchPathFromEnv (SearchPaths* P, const char* EnvVar);
/* Add a search path from an environment variable to the end of an existing
* list.
*/
-void AddSubSearchPathFromEnv (SearchPath* P, const char* EnvVar, const char* SubDir);
+void AddSubSearchPathFromEnv (SearchPaths* P, const char* EnvVar, const char* SubDir);
/* Add a search path from an environment variable, adding a subdirectory to
* the environment variable value.
*/
-void AddSubSearchPathFromWinBin (SearchPath* P, const char* SubDir);
+void AddSubSearchPathFromWinBin (SearchPaths* P, const char* SubDir);
/* Windows only:
* Add a search path from the running binary, adding a subdirectory to
* the parent directory of the directory containing the binary.
*/
-int PushSearchPath (SearchPath* P, const char* NewPath);
+int PushSearchPath (SearchPaths* P, const char* NewPath);
/* Add a new search path to the head of an existing search path list, provided
* that it's not already there. If the path is already at the first position,
* return zero, otherwise return a non zero value.
*/
-void PopSearchPath (SearchPath* P);
+void PopSearchPath (SearchPaths* P);
/* Remove a search path from the head of an existing search path list */
-char* SearchFile (const SearchPath* P, const char* File);
+char* SearchFile (const SearchPaths* P, const char* File);
/* Search for a file in a list of directories. Return a pointer to a malloced
* area that contains the complete path, if found, return 0 otherwise.
*/
diff --git a/src/common/xsprintf.h b/src/common/xsprintf.h
index 07672c5c4..2758e5bc2 100644
--- a/src/common/xsprintf.h
+++ b/src/common/xsprintf.h
@@ -41,7 +41,11 @@
* and precision to such a StrBuf, but *not* using %p would bring up a warning
* about a wrong argument type each time. Maybe gcc will one day allow custom
* format specifiers and we can change this ...
+ * However this cheat doesn't work with MinGW as there's no support for %m :-(
*/
+#if defined( __MINGW32__)
+# pragma GCC diagnostic ignored "-Wformat"
+#endif
diff --git a/src/ld65/filepath.c b/src/ld65/filepath.c
index 42357bb47..1010023f2 100644
--- a/src/ld65/filepath.c
+++ b/src/ld65/filepath.c
@@ -44,13 +44,13 @@
-SearchPath* LibSearchPath; /* Library path */
-SearchPath* ObjSearchPath; /* Object file path */
-SearchPath* CfgSearchPath; /* Config file path */
+SearchPaths* LibSearchPath; /* Library path */
+SearchPaths* ObjSearchPath; /* Object file path */
+SearchPaths* CfgSearchPath; /* Config file path */
-SearchPath* LibDefaultPath; /* Default Library path */
-SearchPath* ObjDefaultPath; /* Default Object file path */
-SearchPath* CfgDefaultPath; /* Default Config file path */
+SearchPaths* LibDefaultPath; /* Default Library path */
+SearchPaths* ObjDefaultPath; /* Default Object file path */
+SearchPaths* CfgDefaultPath; /* Default Config file path */
@@ -88,13 +88,13 @@ void InitSearchPaths (void)
AddSubSearchPathFromEnv (CfgDefaultPath, "CC65_HOME", "cfg");
/* Add some compiled-in search paths if defined at compile time. */
-#if defined(LD65_LIB)
+#if defined(LD65_LIB) && !defined(_WIN32)
AddSearchPath (LibDefaultPath, STRINGIZE (LD65_LIB));
#endif
-#if defined(LD65_OBJ)
+#if defined(LD65_OBJ) && !defined(_WIN32)
AddSearchPath (ObjDefaultPath, STRINGIZE (LD65_OBJ));
#endif
-#if defined(LD65_CFG)
+#if defined(LD65_CFG) && !defined(_WIN32)
AddSearchPath (CfgDefaultPath, STRINGIZE (LD65_CFG));
#endif
diff --git a/src/ld65/filepath.h b/src/ld65/filepath.h
index 97e77068b..12032b165 100644
--- a/src/ld65/filepath.h
+++ b/src/ld65/filepath.h
@@ -49,13 +49,13 @@
-extern SearchPath* LibSearchPath; /* Library path */
-extern SearchPath* ObjSearchPath; /* Object file path */
-extern SearchPath* CfgSearchPath; /* Config file path */
+extern SearchPaths* LibSearchPath; /* Library path */
+extern SearchPaths* ObjSearchPath; /* Object file path */
+extern SearchPaths* CfgSearchPath; /* Config file path */
-extern SearchPath* LibDefaultPath; /* Default Library path */
-extern SearchPath* ObjDefaultPath; /* Default Object file path */
-extern SearchPath* CfgDefaultPath; /* Default Config file path */
+extern SearchPaths* LibDefaultPath; /* Default Library path */
+extern SearchPaths* ObjDefaultPath; /* Default Object file path */
+extern SearchPaths* CfgDefaultPath; /* Default Config file path */
diff --git a/src/sim65/paravirt.c b/src/sim65/paravirt.c
index 29b8ea930..035bb1d87 100644
--- a/src/sim65/paravirt.c
+++ b/src/sim65/paravirt.c
@@ -36,15 +36,18 @@
#include
#include
#include
+#if defined(_WIN32)
+# define O_INITIAL O_BINARY
+#else
+# define O_INITIAL 0
+#endif
#if defined(_MSC_VER)
/* Microsoft compiler */
# include
# pragma warning(disable : 4996)
-# define O_INITIAL O_BINARY
#else
/* Anyone else */
# include
-# define O_INITIAL 0
#endif
/* common */