From eca2afb982a28e286c2f344c838efe152140a3be Mon Sep 17 00:00:00 2001 From: curt Date: Thu, 2 Aug 2001 22:56:33 +0000 Subject: [PATCH] Various changes for MingWin32 support. --- configure.in | 5 +++-- simgear/compiler.h | 5 +++++ simgear/io/sg_binobj.cxx | 4 ++-- simgear/io/sg_file.cxx | 4 ++-- simgear/io/sg_socket.cxx | 16 ++++++++-------- simgear/io/sg_socket.hxx | 10 +++++----- simgear/threads/SGThread.cxx | 2 +- simgear/timing/sg_time.cxx | 11 ++++++----- simgear/timing/sg_time.hxx | 4 ++-- 9 files changed, 34 insertions(+), 27 deletions(-) diff --git a/configure.in b/configure.in index 732c2458..045daf47 100644 --- a/configure.in +++ b/configure.in @@ -77,9 +77,10 @@ if test -d /opt/X11R6 ; then fi if test "x$ac_cv_header_windows_h" = "xyes" ; then + if test -d /usr/mingw/usr ; then + EXTRA_DIRS="$EXTRA_DIRS /usr/mingw/usr" + fi EXTRA_DIRS="${EXTRA_DIRS} `pwd`/Win32" -# elif test `uname -s` = "SunOS" ; then -# EXTRA_DIRS="${EXTRA_DIRS} `pwd`/SunOS" fi wi_EXTRA_DIRS(no, ${EXTRA_DIRS}) diff --git a/simgear/compiler.h b/simgear/compiler.h index b64e8386..bb7e8303 100644 --- a/simgear/compiler.h +++ b/simgear/compiler.h @@ -139,6 +139,11 @@ # endif #endif +#if defined( __MINGW32__ ) +# define bcopy(from, to, n) memcpy(to, from, n) +# define FG_MEM_COPY(to,from,n) memcpy(to, from, n) +#endif + /* KAI C++ */ #if defined(__KCC) diff --git a/simgear/io/sg_binobj.cxx b/simgear/io/sg_binobj.cxx index 474a2f21..ff72ea50 100644 --- a/simgear/io/sg_binobj.cxx +++ b/simgear/io/sg_binobj.cxx @@ -551,7 +551,7 @@ bool SGBinObject::write_bin( const string& base, const string& name, string dir = base + "/" + b.gen_base_path(); string command = "mkdir -p " + dir; -#ifdef _MSC_VER +#if defined(_MSC_VER) || defined(__MINGW32__) system( (string("mkdir ") + dir).c_str() ); #else system(command.c_str()); @@ -828,7 +828,7 @@ bool SGBinObject::write_ascii( const string& base, const string& name, string dir = base + "/" + b.gen_base_path(); string command = "mkdir -p " + dir; -#ifdef _MSC_VER +#if defined(_MSC_VER) || defined(__MINGW32__) system( (string("mkdir ") + dir).c_str() ); #else system(command.c_str()); diff --git a/simgear/io/sg_file.cxx b/simgear/io/sg_file.cxx index e8c7bb8e..79cec7b7 100644 --- a/simgear/io/sg_file.cxx +++ b/simgear/io/sg_file.cxx @@ -25,7 +25,7 @@ #include STL_STRING -#ifdef _MSC_VER +#if defined(_MSC_VER) || defined(__MINGW32__) # include #endif @@ -51,7 +51,7 @@ bool SGFile::open( const SGProtocolDir d ) { set_dir( d ); if ( get_dir() == SG_IO_OUT ) { -#ifdef _MSC_VER +#if defined(_MSC_VER) || defined(__MINGW32__) int mode = 00666; #else mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; diff --git a/simgear/io/sg_socket.cxx b/simgear/io/sg_socket.cxx index 905639b9..3fd12168 100644 --- a/simgear/io/sg_socket.cxx +++ b/simgear/io/sg_socket.cxx @@ -23,7 +23,7 @@ #include -#if !defined(_MSC_VER) +#if !defined(_MSC_VER) && !defined(__MINGW32__) # include // select() # include // socket(), bind(), select(), accept() # include // socket(), bind(), listen(), accept() @@ -48,7 +48,7 @@ SGSocket::SGSocket( const string& host, const string& port, port_str(port), save_len(0) { -#if defined(_MSC_VER) +#if defined(_MSC_VER) || defined(__MINGW32__) if (!wsock_init && !wsastartup()) { SG_LOG( SG_IO, SG_ALERT, "Winsock not available"); } @@ -75,7 +75,7 @@ SGSocket::~SGSocket() { SGSocket::SocketType SGSocket::make_server_socket () { struct sockaddr_in name; -#if defined( __CYGWIN__ ) || defined( __CYGWIN32__ ) || defined( sgi ) || defined( _MSC_VER ) +#if defined( __CYGWIN__ ) || defined( __CYGWIN32__ ) || defined( sgi ) || defined( _MSC_VER ) || defined(__MINGW32__) int length; #else socklen_t length; @@ -161,7 +161,7 @@ SGSocket::SocketType SGSocket::make_client_socket () { // Wrapper functions size_t SGSocket::readsocket( int fd, void *buf, size_t count ) { -#if defined(_MSC_VER) +#if defined(_MSC_VER) || defined(__MINGW32__) return ::recv( fd, (char *)buf, count, 0 ); #else return ::read( fd, buf, count ); @@ -169,14 +169,14 @@ size_t SGSocket::readsocket( int fd, void *buf, size_t count ) { } size_t SGSocket::writesocket( int fd, const void *buf, size_t count ) { -#if defined(_MSC_VER) +#if defined(_MSC_VER) || defined(__MINGW32__) return ::send( fd, (const char*)buf, count, 0 ); #else return ::write( fd, buf, count ); #endif } -#if !defined(_MSC_VER) +#if !defined(_MSC_VER) && !defined(__MINGW32__) int SGSocket::closesocket( int fd ) { return ::close( fd ); } @@ -504,7 +504,7 @@ bool SGSocket::nonblock() { return 0; } -#if defined(_MSC_VER) +#if defined(_MSC_VER) || defined(__MINGW32__) u_long arg = 1; if (ioctlsocket( sock, FIONBIO, &arg ) != 0) { int error_code = WSAGetLastError(); @@ -519,7 +519,7 @@ bool SGSocket::nonblock() { return true; } -#if defined(_MSC_VER) +#if defined(_MSC_VER) || defined(__MINGW32__) bool SGSocket::wsock_init = false; diff --git a/simgear/io/sg_socket.hxx b/simgear/io/sg_socket.hxx index 795972d8..ced2b205 100644 --- a/simgear/io/sg_socket.hxx +++ b/simgear/io/sg_socket.hxx @@ -41,8 +41,8 @@ SG_USING_STD(string); -#if defined(_MSC_VER) -# include +#if defined(_MSC_VER) || defined(__MINGW32__) +# include #endif #define SG_MAX_SOCKET_QUEUE 32 @@ -53,7 +53,7 @@ SG_USING_STD(string); */ class SGSocket : public SGIOChannel { public: -#if defined(_MSC_VER) +#if defined(_MSC_VER) || defined(__MINGW32__) typedef SOCKET SocketType; #else typedef int SocketType; @@ -83,11 +83,11 @@ private: // wrapper functions size_t readsocket( int fd, void *buf, size_t count ); size_t writesocket( int fd, const void *buf, size_t count ); -#if !defined(_MSC_VER) +#if !defined(_MSC_VER) && !defined(__MINGW32__) int closesocket(int fd); #endif -#if defined(_MSC_VER) +#if defined(_MSC_VER) || defined(__MINGW32__) // Ensure winsock has been initialised. static bool wsock_init; static bool wsastartup(); diff --git a/simgear/threads/SGThread.cxx b/simgear/threads/SGThread.cxx index f7de11f7..4119d7b4 100644 --- a/simgear/threads/SGThread.cxx +++ b/simgear/threads/SGThread.cxx @@ -1,6 +1,6 @@ #include -#ifdef _MSC_VER +#if defined(_MSC_VER) || defined(__MINGW32__) # include #else # include diff --git a/simgear/timing/sg_time.cxx b/simgear/timing/sg_time.cxx index 12980c0b..76fb6f40 100644 --- a/simgear/timing/sg_time.cxx +++ b/simgear/timing/sg_time.cxx @@ -193,7 +193,7 @@ static double sidereal_course( time_t cur_time, struct tm *gmt, double lng ) void SGTime::update( double lon, double lat, long int warp ) { double gst_precise, gst_course; -#ifdef _MSC_VER +#if defined(_MSC_VER) || defined(__MINGW32__) tm * gmt = &m_gmt; #endif @@ -207,7 +207,7 @@ void SGTime::update( double lon, double lat, long int warp ) { << " warp = " << warp ); // get GMT break down for current time -#ifdef _MSC_VER +#if defined(_MSC_VER) || defined(__MINGW32__) memcpy( gmt, gmtime(&cur_time), sizeof(tm) ); #else gmt = gmtime(&cur_time); @@ -333,13 +333,14 @@ double sgTimeCalcMJD(int mn, double dy, int yr) { // return the current modified Julian date (number of days elapsed // since 1900 jan 0.5), mjd. double sgTimeCurrentMJD( long int warp ) { -#ifdef _MSC_VER + +#if defined(_MSC_VER) || defined(__MINGW32__) struct tm m_gmt; // copy of system gmtime(&time_t) structure #else struct tm *gmt; #endif -#ifdef _MSC_VER +#if defined(_MSC_VER) || defined(__MINGW32__) tm * gmt = &m_gmt; #endif @@ -351,7 +352,7 @@ double sgTimeCurrentMJD( long int warp ) { << " warp = " << warp ); // get GMT break down for current time -#ifdef _MSC_VER +#if defined(_MSC_VER) || defined(__MINGW32__) memcpy( gmt, gmtime(&cur_time), sizeof(tm) ); #else gmt = gmtime(&cur_time); diff --git a/simgear/timing/sg_time.hxx b/simgear/timing/sg_time.hxx index e7e82302..e8155c1d 100644 --- a/simgear/timing/sg_time.hxx +++ b/simgear/timing/sg_time.hxx @@ -78,7 +78,7 @@ private: time_t cur_time; // Break down of equivalent GMT time -#ifdef _MSC_VER +#if defined(_MSC_VER) || defined(__MINGW32__) struct tm m_gmt; // copy of system gmtime(&time_t) structure #else struct tm *gmt; @@ -166,7 +166,7 @@ public: inline char* get_zonename() const { return zonename; } /** @return GMT in a "brokent down" tm structure */ -#ifdef _MSC_VER +#if defined(_MSC_VER) || defined(__MINGW32__) inline struct tm* getGmt()const { return (struct tm *)&m_gmt; }; #else inline struct tm* getGmt()const { return gmt; }; -- 2.39.5