general: Changed macros and definitions for the engine to compile with MinGW (#793)

This commit is contained in:
Leandro Benedet Garcia 2019-12-02 13:21:01 -03:00 committed by Sam Edwards
parent 77eeed6a82
commit 71dfc51f8a
10 changed files with 50 additions and 23 deletions

View File

@ -25,7 +25,7 @@ using std::string;
#include <sys/param.h> // for realpath #include <sys/param.h> // for realpath
#endif // __APPLE__ #endif // __APPLE__
#ifdef WIN32_VC #ifdef _WIN32
// Windows requires this for getcwd(). // Windows requires this for getcwd().
#include <direct.h> #include <direct.h>
#define getcwd _getcwd #define getcwd _getcwd
@ -80,7 +80,7 @@ extern char **environ;
// GLOBAL_ARGCGLOBAL_ARGV that we can read at static init time to determine // GLOBAL_ARGCGLOBAL_ARGV that we can read at static init time to determine
// our command-line arguments. // our command-line arguments.
#if !defined(WIN32_VC) && defined(HAVE_GLOBAL_ARGV) && defined(PROTOTYPE_GLOBAL_ARGV) #if !defined(_WIN32) && defined(HAVE_GLOBAL_ARGV) && defined(PROTOTYPE_GLOBAL_ARGV)
extern char **GLOBAL_ARGV; extern char **GLOBAL_ARGV;
extern int GLOBAL_ARGC; extern int GLOBAL_ARGC;
#endif #endif
@ -200,7 +200,7 @@ expand_string(const string &str) {
*/ */
Filename ExecutionEnvironment:: Filename ExecutionEnvironment::
get_cwd() { get_cwd() {
#ifdef WIN32_VC #ifdef _WIN32
// getcwd() requires us to allocate a dynamic buffer and grow it on demand. // getcwd() requires us to allocate a dynamic buffer and grow it on demand.
static size_t bufsize = 1024; static size_t bufsize = 1024;
static wchar_t *buffer = nullptr; static wchar_t *buffer = nullptr;

View File

@ -2507,25 +2507,25 @@ make_dir() const {
size_t slash = dirname.find('/'); size_t slash = dirname.find('/');
while (slash != string::npos) { while (slash != string::npos) {
Filename component(dirname.substr(0, slash)); Filename component(dirname.substr(0, slash));
#ifdef WIN32_VC #ifdef _WIN32
wstring os_specific = component.to_os_specific_w(); wstring os_specific = component.to_os_specific_w();
_wmkdir(os_specific.c_str()); _wmkdir(os_specific.c_str());
#else #else
string os_specific = component.to_os_specific(); string os_specific = component.to_os_specific();
::mkdir(os_specific.c_str(), 0777); ::mkdir(os_specific.c_str(), 0777);
#endif // WIN32_VC #endif // _WIN32
slash = dirname.find('/', slash + 1); slash = dirname.find('/', slash + 1);
} }
// Now make the last one, and check the return value. // Now make the last one, and check the return value.
Filename component(dirname); Filename component(dirname);
#ifdef WIN32_VC #ifdef _WIN32
wstring os_specific = component.to_os_specific_w(); wstring os_specific = component.to_os_specific_w();
int result = _wmkdir(os_specific.c_str()); int result = _wmkdir(os_specific.c_str());
#else #else
string os_specific = component.to_os_specific(); string os_specific = component.to_os_specific();
int result = ::mkdir(os_specific.c_str(), 0777); int result = ::mkdir(os_specific.c_str(), 0777);
#endif // WIN32_VC #endif // _WIN32
return (result == 0); return (result == 0);
} }
@ -2538,13 +2538,13 @@ make_dir() const {
*/ */
bool Filename:: bool Filename::
mkdir() const { mkdir() const {
#ifdef WIN32_VC #ifdef _WIN32
wstring os_specific = to_os_specific_w(); wstring os_specific = to_os_specific_w();
int result = _wmkdir(os_specific.c_str()); int result = _wmkdir(os_specific.c_str());
#else #else
string os_specific = to_os_specific(); string os_specific = to_os_specific();
int result = ::mkdir(os_specific.c_str(), 0777); int result = ::mkdir(os_specific.c_str(), 0777);
#endif // WIN32_VC #endif // _WIN32
return (result == 0); return (result == 0);
} }
@ -2642,7 +2642,7 @@ bool Filename::
atomic_compare_and_exchange_contents(string &orig_contents, atomic_compare_and_exchange_contents(string &orig_contents,
const string &old_contents, const string &old_contents,
const string &new_contents) const { const string &new_contents) const {
#ifdef WIN32_VC #ifdef _WIN32
wstring os_specific = to_os_specific_w(); wstring os_specific = to_os_specific_w();
HANDLE hfile = CreateFileW(os_specific.c_str(), GENERIC_READ | GENERIC_WRITE, HANDLE hfile = CreateFileW(os_specific.c_str(), GENERIC_READ | GENERIC_WRITE,
0, nullptr, OPEN_ALWAYS, 0, nullptr, OPEN_ALWAYS,
@ -2708,7 +2708,7 @@ atomic_compare_and_exchange_contents(string &orig_contents,
CloseHandle(hfile); CloseHandle(hfile);
return match; return match;
#else // WIN32_VC #else // _WIN32
string os_specific = to_os_specific(); string os_specific = to_os_specific();
int fd = open(os_specific.c_str(), O_RDWR | O_CREAT, 0666); int fd = open(os_specific.c_str(), O_RDWR | O_CREAT, 0666);
if (fd < 0) { if (fd < 0) {
@ -2761,7 +2761,7 @@ atomic_compare_and_exchange_contents(string &orig_contents,
} }
return match; return match;
#endif // WIN32_VC #endif // _WIN32
} }
/** /**
@ -2778,7 +2778,7 @@ atomic_compare_and_exchange_contents(string &orig_contents,
*/ */
bool Filename:: bool Filename::
atomic_read_contents(string &contents) const { atomic_read_contents(string &contents) const {
#ifdef WIN32_VC #ifdef _WIN32
wstring os_specific = to_os_specific_w(); wstring os_specific = to_os_specific_w();
HANDLE hfile = CreateFileW(os_specific.c_str(), GENERIC_READ, HANDLE hfile = CreateFileW(os_specific.c_str(), GENERIC_READ,
FILE_SHARE_READ, nullptr, OPEN_ALWAYS, FILE_SHARE_READ, nullptr, OPEN_ALWAYS,
@ -2824,7 +2824,7 @@ atomic_read_contents(string &contents) const {
CloseHandle(hfile); CloseHandle(hfile);
return true; return true;
#else // WIN32_VC #else // _WIN32
string os_specific = to_os_specific(); string os_specific = to_os_specific();
int fd = open(os_specific.c_str(), O_RDWR | O_CREAT, 0666); int fd = open(os_specific.c_str(), O_RDWR | O_CREAT, 0666);
if (fd < 0) { if (fd < 0) {
@ -2861,7 +2861,7 @@ atomic_read_contents(string &contents) const {
close(fd); close(fd);
return true; return true;
#endif // WIN32_VC #endif // _WIN32
} }
/** /**

View File

@ -38,7 +38,7 @@
#include <algorithm> #include <algorithm>
#include <ctype.h> #include <ctype.h>
#ifndef _MSC_VER #ifndef _WIN32
#include <dlfcn.h> #include <dlfcn.h>
#endif #endif
@ -120,7 +120,7 @@ reload_implicit_pages() {
const char *main_dir; const char *main_dir;
const char *log_filename; const char *log_filename;
}; };
#ifdef _MSC_VER #ifdef _WIN32
const BlobInfo *blobinfo = (const BlobInfo *)GetProcAddress(GetModuleHandle(NULL), "blobinfo"); const BlobInfo *blobinfo = (const BlobInfo *)GetProcAddress(GetModuleHandle(NULL), "blobinfo");
#elif defined(RTLD_MAIN_ONLY) #elif defined(RTLD_MAIN_ONLY)
const BlobInfo *blobinfo = (const BlobInfo *)dlsym(RTLD_MAIN_ONLY, "blobinfo"); const BlobInfo *blobinfo = (const BlobInfo *)dlsym(RTLD_MAIN_ONLY, "blobinfo");
@ -130,7 +130,7 @@ reload_implicit_pages() {
const BlobInfo *blobinfo = (const BlobInfo *)dlsym(dlopen(NULL, RTLD_NOW), "blobinfo"); const BlobInfo *blobinfo = (const BlobInfo *)dlsym(dlopen(NULL, RTLD_NOW), "blobinfo");
#endif #endif
if (blobinfo == nullptr) { if (blobinfo == nullptr) {
#ifndef _MSC_VER #ifndef _WIN32
// Clear the error flag. // Clear the error flag.
dlerror(); dlerror();
#endif #endif

View File

@ -68,10 +68,14 @@
#define BATTERY_LEVEL_FULL 0x03 #define BATTERY_LEVEL_FULL 0x03
#endif #endif
// With MingW32 this raises the error:
// Redefinition of '_XINPUT_BATTERY_INFORMATION'
#ifdef _MSC_VER
typedef struct _XINPUT_BATTERY_INFORMATION { typedef struct _XINPUT_BATTERY_INFORMATION {
BYTE BatteryType; BYTE BatteryType;
BYTE BatteryLevel; BYTE BatteryLevel;
} XINPUT_BATTERY_INFORMATION; } XINPUT_BATTERY_INFORMATION;
#endif
// Undocumented, I figured out how this looks by trial and error. // Undocumented, I figured out how this looks by trial and error.
typedef struct _XINPUT_BUSINFO { typedef struct _XINPUT_BUSINFO {

View File

@ -31,6 +31,18 @@
#include <fcntl.h> #include <fcntl.h>
#endif #endif
// For some reason in msys those two macros are not defined correctly in the
// header file ws2tcpip.h
// Also, those lines will be removed when the engine change
// _WIN32_WINNT to 0x0600
#ifndef AI_ADDRCONFIG
#define AI_ADDRCONFIG 0x00000400
#endif
#ifndef AI_V4MAPPED
#define AI_V4MAPPED 0x00000800
#endif
using std::string; using std::string;
#ifdef _WIN32 #ifdef _WIN32
@ -95,6 +107,7 @@ BioPtr(const URLSpec &url) : _connecting(false) {
// These hints tell getaddrinfo what kind of address to return. // These hints tell getaddrinfo what kind of address to return.
struct addrinfo hints, *res = nullptr; struct addrinfo hints, *res = nullptr;
memset(&hints, 0, sizeof(hints)); memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_V4MAPPED | AI_ADDRCONFIG; hints.ai_flags = AI_V4MAPPED | AI_ADDRCONFIG;
hints.ai_family = support_ipv6 ? AF_UNSPEC : AF_INET; hints.ai_family = support_ipv6 ? AF_UNSPEC : AF_INET;
hints.ai_socktype = SOCK_STREAM; hints.ai_socktype = SOCK_STREAM;

View File

@ -17,7 +17,7 @@
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#if defined(WIN32_VC) || defined(WIN64_VC) #ifdef _WIN32
#include <winsock2.h> #include <winsock2.h>
#endif #endif

View File

@ -15,7 +15,7 @@
#include "config_express.h" #include "config_express.h"
#include "textEncoder.h" #include "textEncoder.h"
#if defined(WIN32_VC) #if defined(_WIN32)
#ifndef WIN32_LEAN_AND_MEAN #ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1 #define WIN32_LEAN_AND_MEAN 1
#endif #endif

View File

@ -17,7 +17,7 @@
#include "pandabase.h" #include "pandabase.h"
// This class is only defined on Windows builds. // This class is only defined on Windows builds.
#ifdef WIN32_VC #ifdef _WIN32
/** /**
* This class provides a hook to Python to read and write strings and integers * This class provides a hook to Python to read and write strings and integers
@ -56,6 +56,6 @@ private:
static std::string format_message(int error_code); static std::string format_message(int error_code);
}; };
#endif // WIN32_VC #endif // _WIN32
#endif #endif

View File

@ -14,6 +14,14 @@
#include "socket_address.h" #include "socket_address.h"
#include "config_downloader.h" #include "config_downloader.h"
// For some reason in msys those two macros are not defined correctly in the
// header file ws2tcpip.h
// Also, those lines will be removed when the engine change
// _WIN32_WINNT to 0x0600
#ifndef AI_ADDRCONFIG
#define AI_ADDRCONFIG 0x00000400
#endif
/** /**
* This function will take a port and string-based TCP address and initialize * This function will take a port and string-based TCP address and initialize
* the address with this information. Returns true on success; on failure, it * the address with this information. Returns true on success; on failure, it
@ -28,6 +36,8 @@ set_host(const std::string &hostname, unsigned short port) {
struct addrinfo hints, *res = nullptr; struct addrinfo hints, *res = nullptr;
memset(&hints, 0, sizeof(hints)); memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_ADDRCONFIG; hints.ai_flags = AI_ADDRCONFIG;
hints.ai_family = support_ipv6 ? AF_UNSPEC : AF_INET; hints.ai_family = support_ipv6 ? AF_UNSPEC : AF_INET;

View File

@ -23,7 +23,7 @@
#include "trueClock.h" #include "trueClock.h"
#if defined(CPPPARSER) #if defined(CPPPARSER)
#elif defined(WIN32_VC) || defined(WIN64_VC) #elif defined(_WIN32)
#include <winsock2.h> // For gethostname() #include <winsock2.h> // For gethostname()
#include <Iphlpapi.h> // For GetAdaptersAddresses() #include <Iphlpapi.h> // For GetAdaptersAddresses()
#elif defined(__ANDROID__) #elif defined(__ANDROID__)