Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimal changes to get building on OS X with clang and Homebrew #136

Merged
merged 6 commits into from
Sep 21, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions src/Makefile.osx
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
CXX=g++
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just use autotools?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a PR that uses that I think: #135

The title of this PR explains why I stuck with Make.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any explanation in the title. Unless you mean "minimal".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I mean minimal. PR #135 is roughly 60x larger, and nobody seems inclined to audit it.


DEFS=-D_MT -DNOPCH -DFOURWAYSSE2 -DUSE_SSL -DMAC_OSX=1 -DCRYPTOPP_DISABLE_ASM=1 -DUSE_UPNP=1

# Detect MinGW
MINGW=$(shell uname -s|grep -i mingw32)

# Link boost statically
DEFS += -DBOOST_THREAD_USE_LIB

# TODO: add instructions on how to install specific versions of these via homebrew
INCLUDEPATHS= \
-I/usr/local/opt/openssl/include \
-I/usr/local/opt/boost/include \
-I/usr/local/opt/miniupnpc/include/miniupnpc \
-I/usr/local/opt/berkeley-db4/include

LIBPATHS= \
-L/usr/local/opt/openssl/lib \
-L/usr/local/opt/boost/lib \
-L/usr/local/opt/miniupnpc/lib \
-L/usr/local/opt/miniupnpc/lib \
-L/usr/local/opt/berkeley-db4/lib \
-L/usr/local/lib

LIBBOOST_SUFFIX=-mt

LIBS= \
-lboost_system$(LIBBOOST_SUFFIX) \
-lboost_filesystem$(LIBBOOST_SUFFIX) \
-lboost_program_options$(LIBBOOST_SUFFIX) \
-lboost_thread$(LIBBOOST_SUFFIX) \
-lboost_chrono$(LIBBOOST_SUFFIX) \
-ldb_cxx -lminiupnpc -lssl -lcrypto \
-Wl,-dynamic \
-lz \
-ldl \
-lpthread

# -lgthread-2.0 # doesn't seem necessary?

CXXFLAGS=-O2 -Wno-invalid-offsetof -Wformat $(DEFS) $(INCLUDEPATHS)

HEADERS=headers.h strlcpy.h serialize.h uint256.h util.h key.h bignum.h base58.h \
script.h allocators.h db.h walletdb.h crypter.h net.h irc.h keystore.h main.h wallet.h bitcoinrpc.h uibase.h ui.h noui.h init.h auxpow.h

OBJS= \
obj/auxpow.o \
obj/util.o \
obj/key.o \
obj/script.o \
obj/db.o \
obj/walletdb.o \
obj/crypter.o \
obj/net.o \
obj/irc.o \
obj/keystore.o \
obj/main.o \
obj/wallet.o \
obj/bitcoinrpc.o \
obj/init.o \
cryptopp/obj/sha.o \
cryptopp/obj/cpu.o

all: namecoind


obj/%.o: %.cpp $(HEADERS)
$(CXX) -c $(CXXFLAGS) -DGUI -o $@ $<

cryptopp/obj/%.o: cryptopp/%.cpp
$(CXX) -c $(CXXFLAGS) -O3 -o $@ $<

obj/nogui/%.o: %.cpp $(HEADERS)
$(CXX) -c $(CXXFLAGS) -o $@ $<

obj/test/%.o: test/%.cpp $(HEADERS)
$(CXX) -c $(CFLAGS) -o $@ $<

obj/nogui/namecoin.o: namecoin.h

namecoind: $(OBJS:obj/%=obj/nogui/%) obj/nogui/namecoin.o
$(CXX) $(CXXFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS)

clean:
-rm -f namecoin namecoind
-rm -f obj/*.o
-rm -f obj/nogui/*.o
-rm -f obj/test/*.o
-rm -f cryptopp/obj/*.o
-rm -f headers.h.gch
2 changes: 1 addition & 1 deletion src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ uint64 nLocalServices = (fClient ? 0 : NODE_NETWORK);
CAddress addrLocalHost("0.0.0.0", 0, false, nLocalServices);
CNode* pnodeLocalHost = NULL;
uint64 nLocalHostNonce = 0;
array<int, 10> vnThreadsRunning;
boost::array<int, 10> vnThreadsRunning;
SOCKET hListenSocket = INVALID_SOCKET;

CNodeList vNodes(true);
Expand Down
12 changes: 6 additions & 6 deletions src/serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -554,15 +554,15 @@ GetBitvectorWordCount (unsigned n)
template<typename A>
unsigned int
GetSerializeSize (const std::vector<bool, A>& v,
int nType, int nVersion = VERSION)
int nType, int nVersion)
{
return GetSizeOfCompactSize (v.size ()) + GetBitvectorWordCount (v.size ());
}

template<typename Stream, typename A>
void
Serialize (Stream& os, const std::vector<bool, A>& v,
int nType, int nVersion = VERSION)
int nType, int nVersion)
{
WriteCompactSize (os, v.size ());

Expand All @@ -582,7 +582,7 @@ template<typename Stream, typename A>
template<typename Stream, typename A>
void
Unserialize (Stream& is, std::vector<bool, A>& v,
int nType, int nVersion = VERSION)
int nType, int nVersion)
{
const unsigned size = ReadCompactSize (is);
std::vector<unsigned char> words(GetBitvectorWordCount (size));
Expand Down Expand Up @@ -926,7 +926,7 @@ class CDataStream
void clear() { vch.clear(); nReadPos = 0; }
iterator insert(iterator it, const char& x=char()) { return vch.insert(it, x); }
void insert(iterator it, size_type n, const char& x) { vch.insert(it, n, x); }

#ifdef __APPLE__
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change effectively removes the first insert method from the class on non-Apple platforms.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On OS X, the compiler errors because of multiple definitions. I can put the guard around the parameter definition if you'd prefer (as that's the only difference) and delete the duplicate body. Maybe there's a way to define the parameters correctly for all platforms, but again, I have no interest in figuring that out, I just made a few small changes to get it to compile on OS X.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need for a guard. Just remove the correct duplicate and it should work with any compiler on any OS.

Maybe there's a way to define the parameters correctly for all platforms, but again, I have no interest in figuring that out, I just made a few small changes to get it to compile on OS X.

Then why bother at all if you only want a quick and dirty hack?!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, it might also work to simply show the second definition on all platforms except __APPLE__, but so far this seems to work just fine (indicating only one definition is needed... per platform).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just remove the correct duplicate and it should work with any compiler on any OS.

Removing one will break compilation on one of the platforms (regardless of which you remove), if I remember correctly.

Feel free to send your own PR on top of this one if you'd like.

Then why bother at all if you only want a quick and dirty hack?!

...I wanted "minimal changes" to get it to work on OS X. I got them.

void insert(iterator it, const_iterator first, const_iterator last)
{
if (it == vch.begin() + nReadPos && last - first <= nReadPos)
Expand All @@ -938,7 +938,7 @@ class CDataStream
else
vch.insert(it, first, last);
}

#else
void insert(iterator it, std::vector<char>::const_iterator first, std::vector<char>::const_iterator last)
{
if (it == vch.begin() + nReadPos && last - first <= nReadPos)
Expand All @@ -950,7 +950,7 @@ class CDataStream
else
vch.insert(it, first, last);
}

#endif
#if !defined(_MSC_VER) || _MSC_VER >= 1300
void insert(iterator it, const char* first, const char* last)
{
Expand Down
12 changes: 10 additions & 2 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,12 @@ T* alignup(T* p)
return u.ptr;
}


#ifdef __WXMSW__
#include <windows.h>
#include <winsock2.h>
#include <mswsock.h>

#define MSG_NOSIGNAL 0
#define MSG_DONTWAIT 0
#ifndef UINT64_MAX
#define UINT64_MAX _UI64_MAX
#define INT64_MAX _I64_MAX
Expand Down Expand Up @@ -147,6 +146,15 @@ typedef u_int SOCKET;
#define Beep(n1,n2) (0)
#endif

#if defined(__WXMSW__) || defined(__APPLE__)
# ifndef MSG_NOSIGNAL
# define MSG_NOSIGNAL 0
# endif
# ifndef MSG_DONTWAIT
# define MSG_DONTWAIT 0
# endif
#endif

inline void MilliSleep(int64 n)
{
// Boost's sleep_for was uninterruptable when backed by nanosleep from 1.50
Expand Down