52d876d82b3c0d35acbcd72e72588dcff5fbc615
[novacoin.git] / doc / build-osx.txt
1 Copyright (c) 2010 Laszlo Hanyecz
2 Portions Copyright (c) 2011 Douglas Huff
3 Distributed under the MIT/X11 software license, see the accompanying file
4 license.txt or http://www.opensource.org/licenses/mit-license.php.  This
5 product includes software developed by the OpenSSL Project for use in the
6 OpenSSL Toolkit (http://www.openssl.org/).  This product includes cryptographic
7 software written by Eric Young (eay@cryptsoft.com) and UPnP software written by
8 Thomas Bernard.
9
10
11 Mac OS X build instructions
12 Laszlo Hanyecz <solar@heliacal.net>
13 Douglas Huff <dhuff@jrbobdobbs.org>
14
15
16 Tested on 10.5 and 10.6 intel.  PPC is not supported because it's big-endian.
17
18 All of the commands should be executed in Terminal.app.. it's in
19 /Applications/Utilities
20
21 You need to install XCode with all the options checked so that the compiler and
22 everything is available in /usr not just /Developer I think it comes on the DVD
23 but you can get the current version from http://developer.apple.com
24
25
26 1.  Pick a directory to work inside.. something like ~/bitcoin works.  The
27 structure I use looks like this:
28
29 (~ is your home directory)
30
31 ~/bitcoin
32 ~/bitcoin/bitcoin       # Upstream source tree
33 ~/bitcoin/src           # source code (symlink to ~/bitcoin/bitcoin/src)
34 ~/bitcoin/deps          # dependencies.. like libraries and headers needed to compile
35 ~/bitcoin/Bitcoin.app   # the application bundle where you can run the app
36
37 Just execute: mkdir ~/bitcoin
38 This will create the top dir for you..
39
40 WARNING: do not use the ~ notation with the configure scripts.. use the full
41 name of the directory, for example /Users/james/bitcoin/deps for a user named
42 'james'.  In my examples I am using 'macosuser' so make sure you change that.
43
44 2.  Check out the bitcoin code from github:
45
46 cd ~/bitcoin
47 git clone https://github.com/bitcoin/bitcoin.git
48 ln -s bitcoin/src src
49
50 This will make ~/bitcoin/bitcoin for you with all the files from git. This puts
51 the actual sources in ~/bitcoin/bitcoin/src and create a symlink src in
52 ~/bitcoin to this location.
53
54 3.  Get and build the dependencies
55
56
57 Boost
58 -----
59
60 Download from http://www.boost.org/users/download/
61 I'm assuming it ended up in ~/Downloads..
62
63 mkdir ~/bitcoin/deps
64 cd ~/bitcoin/deps
65 tar xvjf ~/Downloads/boost_1_42_0.tar.bz2
66 cd boost_1_42_0
67 ./bootstrap.sh
68 ./bjam architecture=combined address-model=32_64 macosx-version=10.5 macosx-version-min=10.5 link=static runtime-link=static --toolset=darwin --prefix=/Users/macosuser/bitcoin/deps install
69
70 If you're using Snow Leopard, you will need to specify 10.6 as your Mac OS X
71 version instead of 10.5.
72
73 This part takes a while.. use your judgement and fix it if something doesn't
74 build for some reason.
75
76 Change the prefix to whatever your directory is (my username in this example
77 is macosuser).  I'm also running on 10.6 so i have macosx-version=10.6  change
78 to 10.5 if you're using leopard.
79
80 This is what my output looked like at the end:
81 ...failed updating 2 targets...
82 ...skipped 144 targets...
83 ...updated 8074 targets...
84
85
86 OpenSSL
87 -------
88
89 (System or MacPorts openssl will work fine. Optional.)
90
91 Download from http://www.openssl.org/source/
92
93 We would like to build this as a 32 bit/64 bit library so we actually build it
94 2 times and join it together here..  If you downloaded with safari it already
95 uncompressed it so it will just be a tar not a tar.gz
96
97 cd ~/bitcoin/deps
98 tar xvf ~/Downloads/openssl-1.0.0.tar
99 mv openssl-1.0.0 openssl-1.0.0-i386
100 tar xvf ~/Downloads/openssl-1.0.0.tar
101 mv openssl-1.0.0 openssl-1.0.0-x86_64
102 # build i386 (32 bit intel) binary
103 cd openssl-1.0.0-i386
104 ./Configure --prefix=/Users/macosuser/bitcoin/deps --openssldir=/Users/macosuser/bitcoin/deps/openssl darwin-i386-cc && make
105 make install # only do this on one of the architectures, to install the headers
106 cd ..
107 # build x86_64 (64 bit intel) binary
108 cd openssl-1.0.0-x86_64
109 ./Configure --prefix=/Users/macosuser/bitcoin/deps --openssldir=/Users/macosuser/bitcoin/deps/openssl darwin64-x86_64-cc && make
110 cd ..
111
112 # combine the libs
113 cd ~/bitcoin/deps
114 lipo -arch i386 openssl-1.0.0-i386/libcrypto.a -arch x86_64 openssl-1.0.0-x86_64/libcrypto.a -o lib/libcrypto.a -create
115 lipo -arch i386 openssl-1.0.0-i386/libssl.a -arch x86_64 openssl-1.0.0-x86_64/libssl.a -o lib/libssl.a -create
116
117 Verify your binaries
118
119 file lib/libcrypto.a
120
121 output should look like this:
122
123 lib/libcrypto.a: Mach-O universal binary with 2 architectures
124 lib/libcrypto.a (for architecture i386):  current ar archive random library
125 lib/libcrypto.a (for architecture x86_64):  current ar archive random library
126
127
128 miniupnpc
129 ---------
130
131 (MacPorts miniupnpc package works fine. You will need to modify makefile.)
132
133 The process for miniupnpc (optional) is similar to that of OpenSSL.
134
135 Download from http://miniupnp.tuxfamily.org/files/.
136
137 cd ~/bitcoin/deps
138 tar xvf ~/Downloads/miniupnpc-1.6.tar
139 mv miniupnpc-1.6 miniupnpc-1.6-x86_64
140 tar xvf ~/Downloads/miniupnpc-1.6.tar
141 mv miniupnpc-1.6 miniupnpc-1.6-i386
142 # build x86_64 (64 bit intel) binary
143 cd miniupnpc-1.6-x86_64
144 export CFLAGS="-arch x86_64"
145 export LDFLAGS="-arch x86_64"
146 export PREFIX="/Users/macuser/bitcoin/deps"
147 make && make install
148 # build i386 (32 bit intel) binary
149 cd miniupnpc-1.6-i386
150 export CFLAGS="-arch i386"
151 export LDFLAGS="-arch i386"
152 export PREFIX="/Users/macuser/bitcoin/deps"
153 make
154
155 # combine the libs
156 cd ~/bitcoin/deps
157 lipo -arch i386 miniupnpc-1.6-i386/libminiupnpc.a -arch x86_64 miniupnpc-1.6-x86_64/libminiupnpc.a -o lib/libminiupnpc.a -create
158
159 Verify your binaries
160
161 file lib/libminiupnpc.a
162
163 output should look like this:
164
165 lib/libminiupnpc.a: Mach-O universal binary with 2 architectures
166 lib/libminiupnpc.a (for architecture i386): current ar archive random library
167 lib/libminiupnpc.a (for architecture x86_64): current ar archive random library
168
169
170 Berkeley DB
171 -----------
172
173 (System or MacPorts version work fine.)
174
175 Download from http://freshmeat.net/projects/berkeleydb/
176
177 cd ~/bitcoin/deps
178 tar xvf ~/Downloads/db-4.8.30.tar
179 cd db-4.8.30/build_unix
180 ../dist/configure --prefix=/Users/macosuser/bitcoin/deps --enable-cxx && make && make install
181
182
183 wxWidgets
184 ---------
185
186 (The wxWidgets-devel MacPorts package will work but will throw annoying assertion dialogs.)
187
188 This is the big one..
189
190 Check it out from svn
191
192 cd ~/bitcoin/deps
193 svn checkout http://svn.wxwidgets.org/svn/wx/wxWidgets/trunk wxWidgets-trunk
194
195 This will make a wxWidgets-trunk directory in deps.
196
197 Use this script snippet, change your prefix to whatever your dir is:
198
199 PREFIX=~/bitcoin/deps
200 SRCDIR="$PREFIX/wxWidgets-trunk"
201 BUILDDIR="$SRCDIR/macbuild"
202
203 cd "$PREFIX" &&
204 #svn checkout http://svn.wxwidgets.org/svn/wx/wxWidgets/trunk wxWidgets-trunk &&
205 cd "$SRCDIR" &&
206
207 [ -f include/wx/hashmap.h.orig ] || cp include/wx/hashmap.h include/wx/hashmap.h.orig &&
208 sed 's/if wxUSE_STL/if 0 \&\& wxUSE_STL/g' < include/wx/hashmap.h.orig > include/wx/hashmap.h &&
209
210 [ -f include/wx/hashset.h.orig ] || cp include/wx/hashset.h include/wx/hashset.h.orig &&
211 sed 's/if wxUSE_STL/if 0 \&\& wxUSE_STL/g' < include/wx/hashset.h.orig > include/wx/hashset.h &&
212
213
214
215 rm -vrf "$BUILDDIR" &&
216 mkdir "$BUILDDIR" &&
217 cd "$BUILDDIR" &&
218
219 ../configure --prefix="$PREFIX" \
220 --with-osx_cocoa \
221 --disable-shared \
222 --disable-debug_flag \
223 --with-macosx-version-min=10.5 \
224 --enable-stl \
225 --enable-utf8 \
226 --enable-universal_binary \
227 --with-libjpeg=builtin \
228 --with-libpng=builtin \
229 --with-regex=builtin \
230 --with-libtiff=builtin \
231 --with-zlib=builtin \
232 --with-expat=builtin \
233 --with-macosx-sdk=/Developer/SDKs/MacOSX10.5.sdk &&
234
235
236 find . -name Makefile | 
237 while read i; do 
238   echo $i; 
239   sed 's/-arch i386/-arch i386 -arch x86_64/g' < "$i" > "$i".new && 
240   mv "$i" "$i".old && 
241   mv "$i".new "$i"; 
242 done
243
244
245
246 make && 
247 make install
248
249
250
251 Now you should be able to build bitcoin
252
253 cd ~/bitcoin/src
254 make -f makefile.osx bitcoin
255
256 Before you can run it, you need to create an application bundle for Mac OS.
257
258 A bundle is provided in contrib/Bitcoin.app.
259
260 Copy the bitcoin binary in to it like this:
261   cp -pR ~/bitcoin/bitcoin/contrib/Bitcoin.app ~/bitcoin/
262   cp ~/bitcoin/src/bitcoin ~/bitcoin/Bitcoin.app/Contents/MacOS/
263
264 To run it you can just click the Bitcoin.app in Finder, or just do:
265 open ~/bitcoin/Bitcoin.app
266
267 If you want to run it with arguments you can just run it without backgrounding
268 by specifying the full name in terminal:
269
270 ~/bitcoin/Bitcoin.app/Contents/MacOS/bitcoin -addnode=192.75.207.66
271
272 You can also run it with arguments in the background with output going to the
273 normal places for apps (Console) like this:
274
275 open ~/bitcoin/Bitcoin.app --args -connect=192.75.207.66
276
277 It is advisable to relocate Bitcoin.app to /Applications or $HOME/Applications.
278