Browse Source

Fix build on windows and mac

Replaced all occurrences of #if* __WXMSW__ with WIN32,
and all occurrences of __WXMAC_OSX__ with MAC_OSX, and made
sure those are defined appropriately in the makefile and bitcoin-qt.pro.
miguelfreitas
Gavin Andresen 13 years ago
parent
commit
6853e627f1
  1. 4
      bitcoin-qt.pro
  2. 2
      src/crypter.cpp
  3. 2
      src/db.cpp
  4. 4
      src/headers.h
  5. 12
      src/init.cpp
  6. 2
      src/main.h
  7. 4
      src/makefile.osx
  8. 22
      src/net.cpp
  9. 2
      src/net.h
  10. 2
      src/protocol.cpp
  11. 2
      src/serialize.h
  12. 16
      src/util.cpp
  13. 18
      src/util.h

4
bitcoin-qt.pro

@ -211,10 +211,10 @@ isEmpty(BOOST_INCLUDE_PATH) {
} }
windows:LIBS += -lws2_32 -lgdi32 windows:LIBS += -lws2_32 -lgdi32
windows:DEFINES += __WXMSW__ windows:DEFINES += WIN32
windows:RC_FILE = src/qt/res/bitcoin-qt.rc windows:RC_FILE = src/qt/res/bitcoin-qt.rc
macx:DEFINES += __WXMAC_OSX__ MSG_NOSIGNAL=0 BOOST_FILESYSTEM_VERSION=3 macx:DEFINES += MAC_OSX MSG_NOSIGNAL=0 BOOST_FILESYSTEM_VERSION=3
macx:ICON = src/qt/res/icons/bitcoin.icns macx:ICON = src/qt/res/icons/bitcoin.icns
macx:TARGET = "Bitcoin Qt" macx:TARGET = "Bitcoin Qt"

2
src/crypter.cpp

@ -7,7 +7,7 @@
#include <vector> #include <vector>
#include <string> #include <string>
#include "headers.h" #include "headers.h"
#ifdef __WXMSW__ #ifdef WIN32
#include <windows.h> #include <windows.h>
#endif #endif

2
src/db.cpp

@ -658,7 +658,7 @@ int CWalletDB::LoadWallet(CWallet* pwallet)
vector<uint256> vWalletUpgrade; vector<uint256> vWalletUpgrade;
// Modify defaults // Modify defaults
#ifndef __WXMSW__ #ifndef WIN32
// Tray icon sometimes disappears on 9.10 karmic koala 64-bit, leaving no way to access the program // Tray icon sometimes disappears on 9.10 karmic koala 64-bit, leaving no way to access the program
fMinimizeToTray = false; fMinimizeToTray = false;
fMinimizeOnClose = false; fMinimizeOnClose = false;

4
src/headers.h

@ -22,7 +22,7 @@
#if (defined(__unix__) || defined(unix)) && !defined(USG) #if (defined(__unix__) || defined(unix)) && !defined(USG)
#include <sys/param.h> // to get BSD define #include <sys/param.h> // to get BSD define
#endif #endif
#ifdef __WXMAC_OSX__ #ifdef MAC_OSX
#ifndef BSD #ifndef BSD
#define BSD 1 #define BSD 1
#endif #endif
@ -51,7 +51,7 @@
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
#ifdef __WXMSW__ #ifdef WIN32
#include <windows.h> #include <windows.h>
#include <winsock2.h> #include <winsock2.h>
#include <mswsock.h> #include <mswsock.h>

12
src/init.cpp

@ -24,7 +24,7 @@ CWallet* pwalletMain;
void ExitTimeout(void* parg) void ExitTimeout(void* parg)
{ {
#ifdef __WXMSW__ #ifdef WIN32
Sleep(5000); Sleep(5000);
ExitProcess(0); ExitProcess(0);
#endif #endif
@ -121,10 +121,10 @@ bool AppInit2(int argc, char* argv[])
// Disable confusing "helpful" text message on abort, ctrl-c // Disable confusing "helpful" text message on abort, ctrl-c
_set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT); _set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
#endif #endif
#ifndef __WXMSW__ #ifndef WIN32
umask(077); umask(077);
#endif #endif
#ifndef __WXMSW__ #ifndef WIN32
// Clean shutdown on SIGTERM // Clean shutdown on SIGTERM
struct sigaction sa; struct sigaction sa;
sa.sa_handler = HandleSIGTERM; sa.sa_handler = HandleSIGTERM;
@ -192,7 +192,7 @@ bool AppInit2(int argc, char* argv[])
#ifdef GUI #ifdef GUI
" -server \t\t " + _("Accept command line and JSON-RPC commands\n") + " -server \t\t " + _("Accept command line and JSON-RPC commands\n") +
#endif #endif
#ifndef __WXMSW__ #ifndef WIN32
" -daemon \t\t " + _("Run in the background as a daemon and accept commands\n") + " -daemon \t\t " + _("Run in the background as a daemon and accept commands\n") +
#endif #endif
" -testnet \t\t " + _("Use the test network\n") + " -testnet \t\t " + _("Use the test network\n") +
@ -225,7 +225,7 @@ bool AppInit2(int argc, char* argv[])
fDebug = GetBoolArg("-debug"); fDebug = GetBoolArg("-debug");
fAllowDNS = GetBoolArg("-dns"); fAllowDNS = GetBoolArg("-dns");
#ifndef __WXMSW__ #ifndef WIN32
fDaemon = GetBoolArg("-daemon"); fDaemon = GetBoolArg("-daemon");
#else #else
fDaemon = false; fDaemon = false;
@ -260,7 +260,7 @@ bool AppInit2(int argc, char* argv[])
} }
#endif #endif
#ifndef __WXMSW__ #ifndef WIN32
if (fDaemon) if (fDaemon)
{ {
// Daemonize // Daemonize

2
src/main.h

@ -927,7 +927,7 @@ public:
fflush(fileout); fflush(fileout);
if (!IsInitialBlockDownload() || (nBestHeight+1) % 500 == 0) if (!IsInitialBlockDownload() || (nBestHeight+1) % 500 == 0)
{ {
#ifdef __WXMSW__ #ifdef WIN32
_commit(_fileno(fileout)); _commit(_fileno(fileout));
#else #else
fsync(fileno(fileout)); fsync(fileno(fileout));

4
src/makefile.osx vendored

@ -28,7 +28,7 @@ LIBS= -dead_strip \
-lssl \ -lssl \
-lcrypto -lcrypto
DEFS=-DMSG_NOSIGNAL=0 -DUSE_SSL DEFS=-DMAC_OSX -DMSG_NOSIGNAL=0 -DUSE_SSL
DEBUGFLAGS=-g DEBUGFLAGS=-g
# ppc doesn't work because we don't support big-endian # ppc doesn't work because we don't support big-endian
@ -73,7 +73,7 @@ ifdef USE_UPNP
LIBS += -lminiupnpc LIBS += -lminiupnpc
DEFS += -DUSE_UPNP=$(USE_UPNP) DEFS += -DUSE_UPNP=$(USE_UPNP)
endif endif
all: bitcoind all: bitcoind

22
src/net.cpp

@ -10,7 +10,7 @@
#include "init.h" #include "init.h"
#include "strlcpy.h" #include "strlcpy.h"
#ifdef __WXMSW__ #ifdef WIN32
#include <string.h> #include <string.h>
#endif #endif
@ -102,7 +102,7 @@ bool ConnectSocket(const CAddress& addrConnect, SOCKET& hSocketRet, int nTimeout
bool fProxy = (fUseProxy && addrConnect.IsRoutable()); bool fProxy = (fUseProxy && addrConnect.IsRoutable());
struct sockaddr_in sockaddr = (fProxy ? addrProxy.GetSockAddr() : addrConnect.GetSockAddr()); struct sockaddr_in sockaddr = (fProxy ? addrProxy.GetSockAddr() : addrConnect.GetSockAddr());
#ifdef __WXMSW__ #ifdef WIN32
u_long fNonblock = 1; u_long fNonblock = 1;
if (ioctlsocket(hSocket, FIONBIO, &fNonblock) == SOCKET_ERROR) if (ioctlsocket(hSocket, FIONBIO, &fNonblock) == SOCKET_ERROR)
#else #else
@ -141,7 +141,7 @@ bool ConnectSocket(const CAddress& addrConnect, SOCKET& hSocketRet, int nTimeout
return false; return false;
} }
socklen_t nRetSize = sizeof(nRet); socklen_t nRetSize = sizeof(nRet);
#ifdef __WXMSW__ #ifdef WIN32
if (getsockopt(hSocket, SOL_SOCKET, SO_ERROR, (char*)(&nRet), &nRetSize) == SOCKET_ERROR) if (getsockopt(hSocket, SOL_SOCKET, SO_ERROR, (char*)(&nRet), &nRetSize) == SOCKET_ERROR)
#else #else
if (getsockopt(hSocket, SOL_SOCKET, SO_ERROR, &nRet, &nRetSize) == SOCKET_ERROR) if (getsockopt(hSocket, SOL_SOCKET, SO_ERROR, &nRet, &nRetSize) == SOCKET_ERROR)
@ -158,7 +158,7 @@ bool ConnectSocket(const CAddress& addrConnect, SOCKET& hSocketRet, int nTimeout
return false; return false;
} }
} }
#ifdef __WXMSW__ #ifdef WIN32
else if (WSAGetLastError() != WSAEISCONN) else if (WSAGetLastError() != WSAEISCONN)
#else #else
else else
@ -175,7 +175,7 @@ bool ConnectSocket(const CAddress& addrConnect, SOCKET& hSocketRet, int nTimeout
CNode::ConnectNode immediately turns the socket back to non-blocking CNode::ConnectNode immediately turns the socket back to non-blocking
but we'll turn it back to blocking just in case but we'll turn it back to blocking just in case
*/ */
#ifdef __WXMSW__ #ifdef WIN32
fNonblock = 0; fNonblock = 0;
if (ioctlsocket(hSocket, FIONBIO, &fNonblock) == SOCKET_ERROR) if (ioctlsocket(hSocket, FIONBIO, &fNonblock) == SOCKET_ERROR)
#else #else
@ -674,7 +674,7 @@ CNode* ConnectNode(CAddress addrConnect, int64 nTimeout)
printf("connected %s\n", addrConnect.ToString().c_str()); printf("connected %s\n", addrConnect.ToString().c_str());
// Set to nonblocking // Set to nonblocking
#ifdef __WXMSW__ #ifdef WIN32
u_long nOne = 1; u_long nOne = 1;
if (ioctlsocket(hSocket, FIONBIO, &nOne) == SOCKET_ERROR) if (ioctlsocket(hSocket, FIONBIO, &nOne) == SOCKET_ERROR)
printf("ConnectSocket() : ioctlsocket nonblocking setting failed, error %d\n", WSAGetLastError()); printf("ConnectSocket() : ioctlsocket nonblocking setting failed, error %d\n", WSAGetLastError());
@ -1612,7 +1612,7 @@ bool BindListenPort(string& strError)
int nOne = 1; int nOne = 1;
addrLocalHost.port = htons(GetListenPort()); addrLocalHost.port = htons(GetListenPort());
#ifdef __WXMSW__ #ifdef WIN32
// Initialize Windows Sockets // Initialize Windows Sockets
WSADATA wsadata; WSADATA wsadata;
int ret = WSAStartup(MAKEWORD(2,2), &wsadata); int ret = WSAStartup(MAKEWORD(2,2), &wsadata);
@ -1638,13 +1638,13 @@ bool BindListenPort(string& strError)
setsockopt(hListenSocket, SOL_SOCKET, SO_NOSIGPIPE, (void*)&nOne, sizeof(int)); setsockopt(hListenSocket, SOL_SOCKET, SO_NOSIGPIPE, (void*)&nOne, sizeof(int));
#endif #endif
#ifndef __WXMSW__ #ifndef WIN32
// Allow binding if the port is still in TIME_WAIT state after // Allow binding if the port is still in TIME_WAIT state after
// the program was closed and restarted. Not an issue on windows. // the program was closed and restarted. Not an issue on windows.
setsockopt(hListenSocket, SOL_SOCKET, SO_REUSEADDR, (void*)&nOne, sizeof(int)); setsockopt(hListenSocket, SOL_SOCKET, SO_REUSEADDR, (void*)&nOne, sizeof(int));
#endif #endif
#ifdef __WXMSW__ #ifdef WIN32
// Set to nonblocking, incoming connections will also inherit this // Set to nonblocking, incoming connections will also inherit this
if (ioctlsocket(hListenSocket, FIONBIO, (u_long*)&nOne) == SOCKET_ERROR) if (ioctlsocket(hListenSocket, FIONBIO, (u_long*)&nOne) == SOCKET_ERROR)
#else #else
@ -1691,7 +1691,7 @@ void StartNode(void* parg)
if (pnodeLocalHost == NULL) if (pnodeLocalHost == NULL)
pnodeLocalHost = new CNode(INVALID_SOCKET, CAddress("127.0.0.1", 0, false, nLocalServices)); pnodeLocalHost = new CNode(INVALID_SOCKET, CAddress("127.0.0.1", 0, false, nLocalServices));
#ifdef __WXMSW__ #ifdef WIN32
// Get local host ip // Get local host ip
char pszHostName[1000] = ""; char pszHostName[1000] = "";
if (gethostname(pszHostName, sizeof(pszHostName)) != SOCKET_ERROR) if (gethostname(pszHostName, sizeof(pszHostName)) != SOCKET_ERROR)
@ -1827,7 +1827,7 @@ public:
if (closesocket(hListenSocket) == SOCKET_ERROR) if (closesocket(hListenSocket) == SOCKET_ERROR)
printf("closesocket(hListenSocket) failed with error %d\n", WSAGetLastError()); printf("closesocket(hListenSocket) failed with error %d\n", WSAGetLastError());
#ifdef __WXMSW__ #ifdef WIN32
// Shutdown Windows Sockets // Shutdown Windows Sockets
WSACleanup(); WSACleanup();
#endif #endif

2
src/net.h

@ -10,7 +10,7 @@
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
#include <openssl/rand.h> #include <openssl/rand.h>
#ifndef __WXMSW__ #ifndef WIN32
#include <arpa/inet.h> #include <arpa/inet.h>
#endif #endif

2
src/protocol.cpp

@ -6,7 +6,7 @@
#include "protocol.h" #include "protocol.h"
#include "util.h" #include "util.h"
#ifndef __WXMSW__ #ifndef WIN32
# include <arpa/inet.h> # include <arpa/inet.h>
#endif #endif

2
src/serialize.h

@ -30,7 +30,7 @@ typedef unsigned long long uint64;
#define for if (false) ; else for #define for if (false) ; else for
#endif #endif
#ifdef __WXMSW__ #ifdef WIN32
#include <windows.h> #include <windows.h>
// This is used to attempt to keep keying material out of swap // This is used to attempt to keep keying material out of swap
// Note that VirtualLock does not provide this as a guarantee on Windows, // Note that VirtualLock does not provide this as a guarantee on Windows,

16
src/util.cpp

@ -64,7 +64,7 @@ public:
ppmutexOpenSSL[i] = new boost::interprocess::interprocess_mutex(); ppmutexOpenSSL[i] = new boost::interprocess::interprocess_mutex();
CRYPTO_set_locking_callback(locking_callback); CRYPTO_set_locking_callback(locking_callback);
#ifdef __WXMSW__ #ifdef WIN32
// Seed random number generator with screen scrape and other hardware sources // Seed random number generator with screen scrape and other hardware sources
RAND_screen(); RAND_screen();
#endif #endif
@ -108,7 +108,7 @@ void RandAddSeedPerfmon()
return; return;
nLastPerfmon = GetTime(); nLastPerfmon = GetTime();
#ifdef __WXMSW__ #ifdef WIN32
// Don't need this on Linux, OpenSSL automatically uses /dev/urandom // Don't need this on Linux, OpenSSL automatically uses /dev/urandom
// Seed with the entire set of perfmon data // Seed with the entire set of perfmon data
unsigned char pdata[250000]; unsigned char pdata[250000];
@ -198,7 +198,7 @@ inline int OutputDebugStringF(const char* pszFormat, ...)
} }
} }
#ifdef __WXMSW__ #ifdef WIN32
if (fPrintToDebugger) if (fPrintToDebugger)
{ {
static CCriticalSection cs_OutputDebugStringF; static CCriticalSection cs_OutputDebugStringF;
@ -457,7 +457,7 @@ void ParseParameters(int argc, char* argv[])
pszValue = strchr(psz, '='); pszValue = strchr(psz, '=');
*pszValue++ = '\0'; *pszValue++ = '\0';
} }
#ifdef __WXMSW__ #ifdef WIN32
_strlwr(psz); _strlwr(psz);
if (psz[0] == '/') if (psz[0] == '/')
psz[0] = '-'; psz[0] = '-';
@ -648,7 +648,7 @@ bool WildcardMatch(const string& str, const string& mask)
void FormatException(char* pszMessage, std::exception* pex, const char* pszThread) void FormatException(char* pszMessage, std::exception* pex, const char* pszThread)
{ {
#ifdef __WXMSW__ #ifdef WIN32
char pszModule[MAX_PATH]; char pszModule[MAX_PATH];
pszModule[0] = '\0'; pszModule[0] = '\0';
GetModuleFileNameA(NULL, pszModule, sizeof(pszModule)); GetModuleFileNameA(NULL, pszModule, sizeof(pszModule));
@ -707,7 +707,7 @@ void PrintExceptionContinue(std::exception* pex, const char* pszThread)
#ifdef __WXMSW__ #ifdef WIN32
typedef WINSHELLAPI BOOL (WINAPI *PSHGETSPECIALFOLDERPATHA)(HWND hwndOwner, LPSTR lpszPath, int nFolder, BOOL fCreate); typedef WINSHELLAPI BOOL (WINAPI *PSHGETSPECIALFOLDERPATHA)(HWND hwndOwner, LPSTR lpszPath, int nFolder, BOOL fCreate);
string MyGetSpecialFolderPath(int nFolder, bool fCreate) string MyGetSpecialFolderPath(int nFolder, bool fCreate)
@ -748,7 +748,7 @@ string GetDefaultDataDir()
// Windows: C:\Documents and Settings\username\Application Data\Bitcoin // Windows: C:\Documents and Settings\username\Application Data\Bitcoin
// Mac: ~/Library/Application Support/Bitcoin // Mac: ~/Library/Application Support/Bitcoin
// Unix: ~/.bitcoin // Unix: ~/.bitcoin
#ifdef __WXMSW__ #ifdef WIN32
// Windows // Windows
return MyGetSpecialFolderPath(CSIDL_APPDATA, true) + "\\Bitcoin"; return MyGetSpecialFolderPath(CSIDL_APPDATA, true) + "\\Bitcoin";
#else #else
@ -758,7 +758,7 @@ string GetDefaultDataDir()
string strHome = pszHome; string strHome = pszHome;
if (strHome[strHome.size()-1] != '/') if (strHome[strHome.size()-1] != '/')
strHome += '/'; strHome += '/';
#ifdef __WXMAC_OSX__ #ifdef MAC_OSX
// Mac // Mac
strHome += "Library/Application Support/"; strHome += "Library/Application Support/";
filesystem::create_directory(strHome.c_str()); filesystem::create_directory(strHome.c_str());

18
src/util.h

@ -7,7 +7,7 @@
#include "uint256.h" #include "uint256.h"
#ifndef __WXMSW__ #ifndef WIN32
#include <sys/types.h> #include <sys/types.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/resource.h> #include <sys/resource.h>
@ -81,7 +81,7 @@ T* alignup(T* p)
return u.ptr; return u.ptr;
} }
#ifdef __WXMSW__ #ifdef WIN32
#define MSG_NOSIGNAL 0 #define MSG_NOSIGNAL 0
#define MSG_DONTWAIT 0 #define MSG_DONTWAIT 0
#ifndef UINT64_MAX #ifndef UINT64_MAX
@ -123,7 +123,7 @@ inline int myclosesocket(SOCKET& hSocket)
{ {
if (hSocket == INVALID_SOCKET) if (hSocket == INVALID_SOCKET)
return WSAENOTSOCK; return WSAENOTSOCK;
#ifdef __WXMSW__ #ifdef WIN32
int ret = closesocket(hSocket); int ret = closesocket(hSocket);
#else #else
int ret = close(hSocket); int ret = close(hSocket);
@ -192,7 +192,7 @@ std::string GetConfigFile();
std::string GetPidFile(); std::string GetPidFile();
void CreatePidFile(std::string pidFile, pid_t pid); void CreatePidFile(std::string pidFile, pid_t pid);
void ReadConfigFile(std::map<std::string, std::string>& mapSettingsRet, std::map<std::string, std::vector<std::string> >& mapMultiSettingsRet); void ReadConfigFile(std::map<std::string, std::string>& mapSettingsRet, std::map<std::string, std::vector<std::string> >& mapMultiSettingsRet);
#ifdef __WXMSW__ #ifdef WIN32
std::string MyGetSpecialFolderPath(int nFolder, bool fCreate); std::string MyGetSpecialFolderPath(int nFolder, bool fCreate);
#endif #endif
std::string GetDefaultDataDir(); std::string GetDefaultDataDir();
@ -390,7 +390,7 @@ inline void PrintHex(const std::vector<unsigned char>& vch, const char* pszForma
inline int64 GetPerformanceCounter() inline int64 GetPerformanceCounter()
{ {
int64 nCounter = 0; int64 nCounter = 0;
#ifdef __WXMSW__ #ifdef WIN32
QueryPerformanceCounter((LARGE_INTEGER*)&nCounter); QueryPerformanceCounter((LARGE_INTEGER*)&nCounter);
#else #else
timeval t; timeval t;
@ -424,7 +424,7 @@ void skipspaces(T& it)
inline bool IsSwitchChar(char c) inline bool IsSwitchChar(char c)
{ {
#ifdef __WXMSW__ #ifdef WIN32
return c == '-' || c == '/'; return c == '-' || c == '/';
#else #else
return c == '-'; return c == '-';
@ -467,7 +467,7 @@ inline bool GetBoolArg(const std::string& strArg)
inline void heapchk() inline void heapchk()
{ {
#ifdef __WXMSW__ #ifdef WIN32
/// for debugging /// for debugging
//if (_heapchk() != _HEAPOK) //if (_heapchk() != _HEAPOK)
// DebugBreak(); // DebugBreak();
@ -626,7 +626,7 @@ public:
// Note: It turns out we might have been able to use boost::thread // Note: It turns out we might have been able to use boost::thread
// by using TerminateThread(boost::thread.native_handle(), 0); // by using TerminateThread(boost::thread.native_handle(), 0);
#ifdef __WXMSW__ #ifdef WIN32
typedef HANDLE pthread_t; typedef HANDLE pthread_t;
inline pthread_t CreateThread(void(*pfn)(void*), void* parg, bool fWantHandle=false) inline pthread_t CreateThread(void(*pfn)(void*), void* parg, bool fWantHandle=false)
@ -708,7 +708,7 @@ inline void ExitThread(size_t nExitCode)
inline bool AffinityBugWorkaround(void(*pfn)(void*)) inline bool AffinityBugWorkaround(void(*pfn)(void*))
{ {
#ifdef __WXMSW__ #ifdef WIN32
// Sometimes after a few hours affinity gets stuck on one processor // Sometimes after a few hours affinity gets stuck on one processor
DWORD_PTR dwProcessAffinityMask = -1; DWORD_PTR dwProcessAffinityMask = -1;
DWORD_PTR dwSystemAffinityMask = -1; DWORD_PTR dwSystemAffinityMask = -1;

Loading…
Cancel
Save