Skip to content

Commit

Permalink
Fix build on windows and mac
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gavinandresen committed Oct 7, 2011
1 parent e9b95e4 commit 6853e62
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 46 deletions.
4 changes: 2 additions & 2 deletions bitcoin-qt.pro
Expand Up @@ -211,10 +211,10 @@ isEmpty(BOOST_INCLUDE_PATH) {
}

windows:LIBS += -lws2_32 -lgdi32
windows:DEFINES += __WXMSW__
windows:DEFINES += WIN32
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:TARGET = "Bitcoin Qt"

Expand Down
2 changes: 1 addition & 1 deletion src/crypter.cpp
Expand Up @@ -7,7 +7,7 @@
#include <vector>
#include <string>
#include "headers.h"
#ifdef __WXMSW__
#ifdef WIN32
#include <windows.h>
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/db.cpp
Expand Up @@ -658,7 +658,7 @@ int CWalletDB::LoadWallet(CWallet* pwallet)
vector<uint256> vWalletUpgrade;

// Modify defaults
#ifndef __WXMSW__
#ifndef WIN32
// Tray icon sometimes disappears on 9.10 karmic koala 64-bit, leaving no way to access the program
fMinimizeToTray = false;
fMinimizeOnClose = false;
Expand Down
4 changes: 2 additions & 2 deletions src/headers.h
Expand Up @@ -22,7 +22,7 @@
#if (defined(__unix__) || defined(unix)) && !defined(USG)
#include <sys/param.h> // to get BSD define
#endif
#ifdef __WXMAC_OSX__
#ifdef MAC_OSX
#ifndef BSD
#define BSD 1
#endif
Expand Down Expand Up @@ -51,7 +51,7 @@

#include <boost/foreach.hpp>

#ifdef __WXMSW__
#ifdef WIN32
#include <windows.h>
#include <winsock2.h>
#include <mswsock.h>
Expand Down
12 changes: 6 additions & 6 deletions src/init.cpp
Expand Up @@ -24,7 +24,7 @@ CWallet* pwalletMain;

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

#ifndef __WXMSW__
#ifndef WIN32
fDaemon = GetBoolArg("-daemon");
#else
fDaemon = false;
Expand Down Expand Up @@ -260,7 +260,7 @@ bool AppInit2(int argc, char* argv[])
}
#endif

#ifndef __WXMSW__
#ifndef WIN32
if (fDaemon)
{
// Daemonize
Expand Down
2 changes: 1 addition & 1 deletion src/main.h
Expand Up @@ -927,7 +927,7 @@ class CBlock
fflush(fileout);
if (!IsInitialBlockDownload() || (nBestHeight+1) % 500 == 0)
{
#ifdef __WXMSW__
#ifdef WIN32
_commit(_fileno(fileout));
#else
fsync(fileno(fileout));
Expand Down
4 changes: 2 additions & 2 deletions src/makefile.osx
Expand Up @@ -28,7 +28,7 @@ LIBS= -dead_strip \
-lssl \
-lcrypto

DEFS=-DMSG_NOSIGNAL=0 -DUSE_SSL
DEFS=-DMAC_OSX -DMSG_NOSIGNAL=0 -DUSE_SSL

DEBUGFLAGS=-g
# ppc doesn't work because we don't support big-endian
Expand Down Expand Up @@ -73,7 +73,7 @@ ifdef USE_UPNP
LIBS += -lminiupnpc
DEFS += -DUSE_UPNP=$(USE_UPNP)
endif


all: bitcoind

Expand Down
22 changes: 11 additions & 11 deletions src/net.cpp
Expand Up @@ -10,7 +10,7 @@
#include "init.h"
#include "strlcpy.h"

#ifdef __WXMSW__
#ifdef WIN32
#include <string.h>
#endif

Expand Down Expand Up @@ -102,7 +102,7 @@ bool ConnectSocket(const CAddress& addrConnect, SOCKET& hSocketRet, int nTimeout
bool fProxy = (fUseProxy && addrConnect.IsRoutable());
struct sockaddr_in sockaddr = (fProxy ? addrProxy.GetSockAddr() : addrConnect.GetSockAddr());

#ifdef __WXMSW__
#ifdef WIN32
u_long fNonblock = 1;
if (ioctlsocket(hSocket, FIONBIO, &fNonblock) == SOCKET_ERROR)
#else
Expand Down Expand Up @@ -141,7 +141,7 @@ bool ConnectSocket(const CAddress& addrConnect, SOCKET& hSocketRet, int nTimeout
return false;
}
socklen_t nRetSize = sizeof(nRet);
#ifdef __WXMSW__
#ifdef WIN32
if (getsockopt(hSocket, SOL_SOCKET, SO_ERROR, (char*)(&nRet), &nRetSize) == SOCKET_ERROR)
#else
if (getsockopt(hSocket, SOL_SOCKET, SO_ERROR, &nRet, &nRetSize) == SOCKET_ERROR)
Expand All @@ -158,7 +158,7 @@ bool ConnectSocket(const CAddress& addrConnect, SOCKET& hSocketRet, int nTimeout
return false;
}
}
#ifdef __WXMSW__
#ifdef WIN32
else if (WSAGetLastError() != WSAEISCONN)
#else
else
Expand All @@ -175,7 +175,7 @@ bool ConnectSocket(const CAddress& addrConnect, SOCKET& hSocketRet, int nTimeout
CNode::ConnectNode immediately turns the socket back to non-blocking
but we'll turn it back to blocking just in case
*/
#ifdef __WXMSW__
#ifdef WIN32
fNonblock = 0;
if (ioctlsocket(hSocket, FIONBIO, &fNonblock) == SOCKET_ERROR)
#else
Expand Down Expand Up @@ -674,7 +674,7 @@ CNode* ConnectNode(CAddress addrConnect, int64 nTimeout)
printf("connected %s\n", addrConnect.ToString().c_str());

// Set to nonblocking
#ifdef __WXMSW__
#ifdef WIN32
u_long nOne = 1;
if (ioctlsocket(hSocket, FIONBIO, &nOne) == SOCKET_ERROR)
printf("ConnectSocket() : ioctlsocket nonblocking setting failed, error %d\n", WSAGetLastError());
Expand Down Expand Up @@ -1612,7 +1612,7 @@ bool BindListenPort(string& strError)
int nOne = 1;
addrLocalHost.port = htons(GetListenPort());

#ifdef __WXMSW__
#ifdef WIN32
// Initialize Windows Sockets
WSADATA wsadata;
int ret = WSAStartup(MAKEWORD(2,2), &wsadata);
Expand All @@ -1638,13 +1638,13 @@ bool BindListenPort(string& strError)
setsockopt(hListenSocket, SOL_SOCKET, SO_NOSIGPIPE, (void*)&nOne, sizeof(int));
#endif

#ifndef __WXMSW__
#ifndef WIN32
// Allow binding if the port is still in TIME_WAIT state after
// the program was closed and restarted. Not an issue on windows.
setsockopt(hListenSocket, SOL_SOCKET, SO_REUSEADDR, (void*)&nOne, sizeof(int));
#endif

#ifdef __WXMSW__
#ifdef WIN32
// Set to nonblocking, incoming connections will also inherit this
if (ioctlsocket(hListenSocket, FIONBIO, (u_long*)&nOne) == SOCKET_ERROR)
#else
Expand Down Expand Up @@ -1691,7 +1691,7 @@ void StartNode(void* parg)
if (pnodeLocalHost == NULL)
pnodeLocalHost = new CNode(INVALID_SOCKET, CAddress("127.0.0.1", 0, false, nLocalServices));

#ifdef __WXMSW__
#ifdef WIN32
// Get local host ip
char pszHostName[1000] = "";
if (gethostname(pszHostName, sizeof(pszHostName)) != SOCKET_ERROR)
Expand Down Expand Up @@ -1827,7 +1827,7 @@ class CNetCleanup
if (closesocket(hListenSocket) == SOCKET_ERROR)
printf("closesocket(hListenSocket) failed with error %d\n", WSAGetLastError());

#ifdef __WXMSW__
#ifdef WIN32
// Shutdown Windows Sockets
WSACleanup();
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/net.h
Expand Up @@ -10,7 +10,7 @@
#include <boost/foreach.hpp>
#include <openssl/rand.h>

#ifndef __WXMSW__
#ifndef WIN32
#include <arpa/inet.h>
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/protocol.cpp
Expand Up @@ -6,7 +6,7 @@
#include "protocol.h"
#include "util.h"

#ifndef __WXMSW__
#ifndef WIN32
# include <arpa/inet.h>
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/serialize.h
Expand Up @@ -30,7 +30,7 @@ typedef unsigned long long uint64;
#define for if (false) ; else for
#endif

#ifdef __WXMSW__
#ifdef WIN32
#include <windows.h>
// This is used to attempt to keep keying material out of swap
// Note that VirtualLock does not provide this as a guarantee on Windows,
Expand Down
16 changes: 8 additions & 8 deletions src/util.cpp
Expand Up @@ -64,7 +64,7 @@ class CInit
ppmutexOpenSSL[i] = new boost::interprocess::interprocess_mutex();
CRYPTO_set_locking_callback(locking_callback);

#ifdef __WXMSW__
#ifdef WIN32
// Seed random number generator with screen scrape and other hardware sources
RAND_screen();
#endif
Expand Down Expand Up @@ -108,7 +108,7 @@ void RandAddSeedPerfmon()
return;
nLastPerfmon = GetTime();

#ifdef __WXMSW__
#ifdef WIN32
// Don't need this on Linux, OpenSSL automatically uses /dev/urandom
// Seed with the entire set of perfmon data
unsigned char pdata[250000];
Expand Down Expand Up @@ -198,7 +198,7 @@ inline int OutputDebugStringF(const char* pszFormat, ...)
}
}

#ifdef __WXMSW__
#ifdef WIN32
if (fPrintToDebugger)
{
static CCriticalSection cs_OutputDebugStringF;
Expand Down Expand Up @@ -457,7 +457,7 @@ void ParseParameters(int argc, char* argv[])
pszValue = strchr(psz, '=');
*pszValue++ = '\0';
}
#ifdef __WXMSW__
#ifdef WIN32
_strlwr(psz);
if (psz[0] == '/')
psz[0] = '-';
Expand Down Expand Up @@ -648,7 +648,7 @@ bool WildcardMatch(const string& str, const string& mask)

void FormatException(char* pszMessage, std::exception* pex, const char* pszThread)
{
#ifdef __WXMSW__
#ifdef WIN32
char pszModule[MAX_PATH];
pszModule[0] = '\0';
GetModuleFileNameA(NULL, pszModule, sizeof(pszModule));
Expand Down Expand Up @@ -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);

string MyGetSpecialFolderPath(int nFolder, bool fCreate)
Expand Down Expand Up @@ -748,7 +748,7 @@ string GetDefaultDataDir()
// Windows: C:\Documents and Settings\username\Application Data\Bitcoin
// Mac: ~/Library/Application Support/Bitcoin
// Unix: ~/.bitcoin
#ifdef __WXMSW__
#ifdef WIN32
// Windows
return MyGetSpecialFolderPath(CSIDL_APPDATA, true) + "\\Bitcoin";
#else
Expand All @@ -758,7 +758,7 @@ string GetDefaultDataDir()
string strHome = pszHome;
if (strHome[strHome.size()-1] != '/')
strHome += '/';
#ifdef __WXMAC_OSX__
#ifdef MAC_OSX
// Mac
strHome += "Library/Application Support/";
filesystem::create_directory(strHome.c_str());
Expand Down

0 comments on commit 6853e62

Please sign in to comment.