1
0
mirror of https://github.com/cc65/cc65.git synced 2025-08-09 13:25:06 +00:00

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.
This commit is contained in:
Oliver Schmidt
2014-03-03 22:12:14 +01:00
parent fcc95f4c1c
commit 50c4fd1c4c
15 changed files with 73 additions and 77 deletions

View File

@@ -44,8 +44,8 @@
SearchPath* IncSearchPath; /* Standard include path */ SearchPaths* IncSearchPath; /* Standard include path */
SearchPath* BinSearchPath; /* Binary include path */ SearchPaths* BinSearchPath; /* Binary include path */
@@ -75,7 +75,7 @@ void FinishIncludePaths (void)
AddSubSearchPathFromEnv (IncSearchPath, "CC65_HOME", "asminc"); AddSubSearchPathFromEnv (IncSearchPath, "CC65_HOME", "asminc");
/* Add some compiled-in search paths if defined at compile time. */ /* 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)); AddSearchPath (IncSearchPath, STRINGIZE (CA65_INC));
#endif #endif

View File

@@ -49,8 +49,8 @@
extern SearchPath* IncSearchPath; /* Standard include path */ extern SearchPaths* IncSearchPath; /* Standard include path */
extern SearchPath* BinSearchPath; /* Binary include path */ extern SearchPaths* BinSearchPath; /* Binary include path */

View File

@@ -44,8 +44,8 @@
SearchPath* SysIncSearchPath; /* System include path */ SearchPaths* SysIncSearchPath; /* System include path */
SearchPath* UsrIncSearchPath; /* User include path */ SearchPaths* UsrIncSearchPath; /* User include path */
@@ -76,7 +76,7 @@ void FinishIncludePaths (void)
AddSubSearchPathFromEnv (SysIncSearchPath, "CC65_HOME", "include"); AddSubSearchPathFromEnv (SysIncSearchPath, "CC65_HOME", "include");
/* Add some compiled-in search paths if defined at compile time. */ /* 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)); AddSearchPath (SysIncSearchPath, STRINGIZE (CC65_INC));
#endif #endif

View File

@@ -49,8 +49,8 @@
extern SearchPath* SysIncSearchPath; /* System include path */ extern SearchPaths* SysIncSearchPath; /* System include path */
extern SearchPath* UsrIncSearchPath; /* User include path */ extern SearchPaths* UsrIncSearchPath; /* User include path */

View File

@@ -36,10 +36,10 @@
/* Check out if we have a spawn() function on the system, or if we must use /* Check out if we have a spawn() function on the system, or if we must use
* our own. * our own.
*/ */
#if defined(__WATCOMC__) || defined(_MSC_VER) || defined(__MINGW32__) || defined(__DJGPP__) #if defined(_WIN32)
# define HAVE_SPAWN 1 # define HAVE_SPAWN 1
#else #else
# define NEED_SPAWN 1 # define NEED_SPAWN 1
#endif #endif
#if defined(_MSC_VER) #if defined(_MSC_VER)
# pragma warning(disable : 4996) # pragma warning(disable : 4996)
@@ -375,7 +375,7 @@ static void ExecProgram (CmdDesc* Cmd)
} }
/* Call the program */ /* 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 */ /* Check the result code */
if (Status < 0) { if (Status < 0) {

View File

@@ -2,7 +2,7 @@
/* */ /* */
/* filestat.c */ /* filestat.c */
/* */ /* */
/* Replacement for buggy Microsoft code */ /* Replacement for Windows code */
/* */ /* */
/* */ /* */
/* */ /* */
@@ -46,8 +46,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#if defined(__WATCOMC__) && defined(__NT__) #if defined(_WIN32)
#define BUGGY_OS 1
#include <errno.h> #include <errno.h>
#include <windows.h> #include <windows.h>
#endif #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 * 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. * 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; ULARGE_INTEGER V;
V.LowPart = T->dwLowDateTime; V.LowPart = T->dwLowDateTime;
V.HighPart = T->dwHighDateTime; V.HighPart = T->dwHighDateTime;

View File

@@ -2,7 +2,7 @@
/* */ /* */
/* filestat.h */ /* filestat.h */
/* */ /* */
/* Replacement for buggy Microsoft code */ /* Replacement for Windows code */
/* */ /* */
/* */ /* */
/* */ /* */

View File

@@ -2,7 +2,7 @@
/* */ /* */
/* filetime.c */ /* filetime.c */
/* */ /* */
/* Replacement for buggy Microsoft code */ /* Replacement for Windows code */
/* */ /* */
/* */ /* */
/* */ /* */
@@ -42,18 +42,12 @@
#if defined(__WATCOMC__) && defined(__NT__) #if defined(_WIN32)
#define BUGGY_OS 1
#include <errno.h> #include <errno.h>
#include <windows.h> #include <windows.h>
#else #else
#if defined(__WATCOMC__) || defined(_MSC_VER) || defined(__MINGW32__) #include <sys/types.h> /* FreeBSD needs this */
/* The Windows compilers have the file in the wrong directory */ #include <utime.h>
# include <sys/utime.h>
#else
# include <sys/types.h> /* FreeBSD needs this */
# include <utime.h>
#endif
#endif #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 * 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. * 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; ULARGE_INTEGER V;
V.QuadPart = ((unsigned __int64) T + Offs.QuadPart) * 10000000U; V.QuadPart = ((unsigned __int64) T + Offs.QuadPart) * 10000000U;
FT->dwLowDateTime = V.LowPart; FT->dwLowDateTime = V.LowPart;
@@ -150,6 +144,3 @@ int SetFileTimes (const char* Path, time_t T)
#endif #endif

View File

@@ -2,7 +2,7 @@
/* */ /* */
/* filetime.h */ /* filetime.h */
/* */ /* */
/* Replacement for buggy Microsoft code */ /* Replacement for Windows code */
/* */ /* */
/* */ /* */
/* */ /* */

View File

@@ -35,6 +35,9 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#if defined(_WIN32)
# include <windows.h>
#endif
#if defined(_MSC_VER) #if defined(_MSC_VER)
/* Microsoft compiler */ /* Microsoft compiler */
# include <io.h> # include <io.h>
@@ -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 */ /* Cleanup a new search path and add it to the list */
{ {
/* Add a clean copy of the path to the collection */ /* 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 */ /* Create a new, empty search path list */
{ {
return NewCollection (); 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 */ /* Add a new search path to the end of an existing list */
{ {
/* Allow a NULL path */ /* 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 /* Add a search path from an environment variable to the end of an existing
* list. * 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 /* Add a search path from an environment variable, adding a subdirectory to
* the environment variable value. * 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: /* Windows only:
* Add a search path from the running binary, adding a subdirectory to * Add a search path from the running binary, adding a subdirectory to
* the parent directory of the directory containing the binary. * the parent directory of the directory containing the binary.
*/ */
#if defined(_MSC_VER) #if defined(_WIN32)
char Dir[_MAX_PATH]; char Dir[_MAX_PATH];
char* Ptr; char* Ptr;
if (_get_pgmptr (&Ptr) != 0) { if (GetModuleFileName (NULL, Dir, _MAX_PATH) == 0) {
return; return;
} }
strcpy (Dir, Ptr);
/* Remove binary name */ /* Remove binary name */
Ptr = strrchr (Dir, '\\'); 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 /* 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, * that it's not already there. If the path is already at the first position,
* return zero, otherwise return a non zero value. * 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 a search path from the head of an existing search path list */
{ {
/* Remove the path at position 0 */ /* 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 /* 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. * 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); SB_Done (&PathName);
return Name; return Name;
} }

View File

@@ -53,7 +53,7 @@
#define STRINGIZE(arg) _STRINGIZE(arg) #define STRINGIZE(arg) _STRINGIZE(arg)
/* A search path is a pointer to the list */ /* 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 */ /* 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 */ /* 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 /* Add a search path from an environment variable to the end of an existing
* list. * 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 /* Add a search path from an environment variable, adding a subdirectory to
* the environment variable value. * the environment variable value.
*/ */
void AddSubSearchPathFromWinBin (SearchPath* P, const char* SubDir); void AddSubSearchPathFromWinBin (SearchPaths* P, const char* SubDir);
/* Windows only: /* Windows only:
* Add a search path from the running binary, adding a subdirectory to * Add a search path from the running binary, adding a subdirectory to
* the parent directory of the directory containing the binary. * 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 /* 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, * that it's not already there. If the path is already at the first position,
* return zero, otherwise return a non zero value. * 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 */ /* 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 /* 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. * area that contains the complete path, if found, return 0 otherwise.
*/ */

View File

@@ -41,7 +41,11 @@
* and precision to such a StrBuf, but *not* using %p would bring up a warning * 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 * about a wrong argument type each time. Maybe gcc will one day allow custom
* format specifiers and we can change this ... * 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

View File

@@ -44,13 +44,13 @@
SearchPath* LibSearchPath; /* Library path */ SearchPaths* LibSearchPath; /* Library path */
SearchPath* ObjSearchPath; /* Object file path */ SearchPaths* ObjSearchPath; /* Object file path */
SearchPath* CfgSearchPath; /* Config file path */ SearchPaths* CfgSearchPath; /* Config file path */
SearchPath* LibDefaultPath; /* Default Library path */ SearchPaths* LibDefaultPath; /* Default Library path */
SearchPath* ObjDefaultPath; /* Default Object file path */ SearchPaths* ObjDefaultPath; /* Default Object file path */
SearchPath* CfgDefaultPath; /* Default Config file path */ SearchPaths* CfgDefaultPath; /* Default Config file path */
@@ -88,13 +88,13 @@ void InitSearchPaths (void)
AddSubSearchPathFromEnv (CfgDefaultPath, "CC65_HOME", "cfg"); AddSubSearchPathFromEnv (CfgDefaultPath, "CC65_HOME", "cfg");
/* Add some compiled-in search paths if defined at compile time. */ /* 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)); AddSearchPath (LibDefaultPath, STRINGIZE (LD65_LIB));
#endif #endif
#if defined(LD65_OBJ) #if defined(LD65_OBJ) && !defined(_WIN32)
AddSearchPath (ObjDefaultPath, STRINGIZE (LD65_OBJ)); AddSearchPath (ObjDefaultPath, STRINGIZE (LD65_OBJ));
#endif #endif
#if defined(LD65_CFG) #if defined(LD65_CFG) && !defined(_WIN32)
AddSearchPath (CfgDefaultPath, STRINGIZE (LD65_CFG)); AddSearchPath (CfgDefaultPath, STRINGIZE (LD65_CFG));
#endif #endif

View File

@@ -49,13 +49,13 @@
extern SearchPath* LibSearchPath; /* Library path */ extern SearchPaths* LibSearchPath; /* Library path */
extern SearchPath* ObjSearchPath; /* Object file path */ extern SearchPaths* ObjSearchPath; /* Object file path */
extern SearchPath* CfgSearchPath; /* Config file path */ extern SearchPaths* CfgSearchPath; /* Config file path */
extern SearchPath* LibDefaultPath; /* Default Library path */ extern SearchPaths* LibDefaultPath; /* Default Library path */
extern SearchPath* ObjDefaultPath; /* Default Object file path */ extern SearchPaths* ObjDefaultPath; /* Default Object file path */
extern SearchPath* CfgDefaultPath; /* Default Config file path */ extern SearchPaths* CfgDefaultPath; /* Default Config file path */

View File

@@ -36,15 +36,18 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <fcntl.h> #include <fcntl.h>
#if defined(_WIN32)
# define O_INITIAL O_BINARY
#else
# define O_INITIAL 0
#endif
#if defined(_MSC_VER) #if defined(_MSC_VER)
/* Microsoft compiler */ /* Microsoft compiler */
# include <io.h> # include <io.h>
# pragma warning(disable : 4996) # pragma warning(disable : 4996)
# define O_INITIAL O_BINARY
#else #else
/* Anyone else */ /* Anyone else */
# include <unistd.h> # include <unistd.h>
# define O_INITIAL 0
#endif #endif
/* common */ /* common */