]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/win32/README.mingw
Tweak win32/64 build doc
[bacula/bacula] / bacula / src / win32 / README.mingw
1
2 Instructions for cross compiling the Win32/64 FD on Linux
3 =======================================================
4
5 This file documents the tools (scripts) we use for building Bacula for
6 Microsoft Windows using the cross-compiler tools on a Linux system.  We
7 use Ubuntu 8.04 so building on that system should definitely work.  But there
8 shouldn't be any issues on other Linux distributions.
9
10 We don't officially support this method, but it is what we use, and it should
11 build on any Linux machine if you carefully follow the instructions and have
12 all the prerequisite programs loaded on your machine.
13
14 We expect that there may be problems on systems other than Linux where you
15 are pretty much on your own.  However, we will try to provide responses to
16 your questions on the bacula-devel list, but we can't guarantee anything.
17
18 Directory Structure
19 =====================
20 The new directory structure is:
21
22   bacula-top                 Top level directory -- any name
23     bacula                   Top level Bacula source directory -- any name
24       src
25         win32                Main directory where Windows version is built.
26
27     docs                     Top level Bacula documentation directory
28
29     depkgs-mingw32 (MinGW32) 3rd Party Dependencies for MinGW32 build
30       bin              --    NOTE!  depkgs-msvc is no longer suppored
31       include            |
32       lib                |
33       man                |   Created by script
34       nsis               |-- .../bacula/src/win32/build-depkgs-mingw32
35       scons              |
36       share              |
37       src                |
38       ssl              --
39       vss
40         inc                  A copy of the Windows VSS/inc directory
41
42
43     depkgs-mingw-w64 (MinGW64) 3rd Party Dependencies for MinGW64 build
44       bin              --
45       include            |
46       lib                |
47       man                |
48       nsis               |
49       scons              |
50       share              |
51       src                |
52       ssl              --
53       vss
54         inc                  A copy of the Windows VSS/inc directory
55
56     cross-tools (MinGW64/32)  Cross compilation tools (gcc, g++, mingw32, ...)
57       binutils-mingw32 --
58       gcc-mingw32        |   Created by script
59       mingw32            |-- .../bacula/src/win32/build-win32-cross-tools
60       mingw-utils        |
61       source           --
62       mingw-w64/x86_64-pc-mingw32  \ Taken from http://sf.net/projects/mingw-w64
63       mingw-w64/bin/               / 
64
65
66
67 One-time Setup
68 ==============
69
70 If you're reading this file you've probably already enlisted in the SVN tree or
71 extracted the contents of the source tar.  If not you need to do that first.
72
73 You also need to download one of the doc tar balls and extract to your
74 top level Bacula directory. 
75
76 The extracted doc directory name will be bacula-docs-version where version
77 is the version number.  The directory must be renamed to docs (ie remove
78 the leading bacula- and the -version portion of the name).
79
80 Note, a number of packages must be installed to build the cross-tools
81 and the depkgs files.  Most are rather standard such as gcc, g++,
82 make, ...  However a few that you may not have are:
83
84   texinfo
85   flex
86   bison
87   patch (Debian)
88   m4
89   postgresql (at least client)
90   mysql (at least client)
91   SQLite3 (from depkgs or as package)
92   readline (readlineN-dev on Debian)
93   ...
94
95 NB: On Debian, I had to remove /usr/bin/lorder for
96 postresql to build correctly.
97
98 Build the 32 bit cross-tools and mingw32:
99
100 Once the source is on your system, change to the win32 directory
101         cd .../bacula/src/win32
102
103 Download and build the cross compiler tools
104         ./build-win32-cross-tools
105
106 Download and build the 3rd party dependencies
107         ./build-depkgs-mingw32
108
109 Note, that during the build process you will see a moderate amount of
110 output. If something fails, it is probably because you don't have one
111 of the build dependencies (hopefully all mentioned above) loaded on your  
112 system. To find out what is going wrong, do the following:
113
114   cd .../depkgs-mingw32/src/<package-name>
115    
116 where <package-name> is where the package is unpacked and built. Normally
117 it is relatively obvious when looking at the src directory.             
118
119 In that directory, you should find a make.log, which has the full details
120 of the compiles, links, and installs done for that package.
121
122 ===
123 Building the 64 bit cross-tools and mingw64:
124
125 When building the mingw64 environment and all dependencies
126 (cross-tools, and depkgs-mingw64) should be compiled by hand with
127 host=x86_64-pc-linux and target=x86_64-pc-mingw32.  
128
129 For that, use this configure line :
130 ./configure --host=x86_64-pc-linux --target=x86_64-pc-mingw32 --prefix=$ROOT/cross-tools
131 or
132 ./configure --host=x86_64-pc-linux --target=x86_64-pc-mingw32 --prefix=$ROOT/depkgs-mingw64
133
134 (It can work with other setup). We are using binutils-2.19, gcc-4.3.2,
135 gmp-4.2.4, mpfr-2.3.2. The mingw64 project delivers binaries that should do the
136 work.
137
138 Internal scripts and patches are using mingw32-xxx binaries, so you need to
139 make links in the gcc bin ($ROOT/cross-tools/mingw-w64/bin) directory.
140
141 ---8<------8<-------8<--------
142
143 for i in x86_64-pc-mingw32-*
144 do
145     ln -s $i ${i##x86_64-pc-}
146 done
147
148 ---8<------8<-------8<--------
149
150 They provide also a pthread lib but we aren't sure that they will work, you
151 can compile it yourself using the pthreads-snap-2004-06-22.tar.gz (same as
152 mingw32) + pthread-win64.patch.
153
154 The openssl lib version is openssl-0.9.8j.tar.gz + openssl-win64.patch
155
156 See External-mingw-w64 for download location (available on www.bacula.org).
157
158 You need the header files from the Microsoft VSS SDK.  Unfortunately the SDK
159 can only be downloaded and installed on a Windows system.  We do not have
160 the right to distribute it, so you must download it yourself.
161 You can find it on Microsoft's web-site at:
162
163 http://www.microsoft.com/downloads/details.aspx?FamilyID=0b4f56e4-0ccc-4626-826a-ed2c4c95c871&DisplayLang=en
164
165 If that link doesn't work then go to http://www.microsoft.com and search for
166
167         "download volume shadow copy service sdk"
168
169 we are currently using version 7.2 released 8/3/2005.
170
171 Normally the files will be installed in:
172
173         c:\Program Files\Microsoft\VSSSDK72
174
175 You only need to copy everything under the c:\Program Files\Microsoft\VSSSDK72\inc
176 directory into .../depkgs-mingw32/vss/inc. and .../depkgs-mingw-w64/vss/inc 
177 In doing so, please ensure that
178 the case in maintained on the directory and filenames -- some contain uppercase 
179 characters !!!
180
181 The above only needs to be done once unless we change the cross-tools
182 or the dependencies versions.  In general, you can run the script multiple
183 times with no problem.  For it to work, you must have at a minimum the
184 following:
185
186         gcc
187         g++
188         wget
189         texinfo
190         bison
191         flex
192         python
193         unzip
194         tar
195
196 and possibly other packages.
197
198
199 Building
200 ========
201
202 Finally, to build the Microsoft Windows version of Bacula, do the following:
203
204    cd .../bacula/src/win32
205    make clean
206    ./makeall
207
208 or
209   cd .../bacula/src/win32
210   make clean
211   make
212   make WIN64=yes
213
214 This builds both the 32 bit version and the 64 bit version.
215 The binaries are in the release32 and release64 directories.
216
217
218
219 Updating the 3rd party package patches
220 ======================================
221
222 If one of the patches changes in .../bacula/src/win32/patches, you will
223 need to update the corresponding dependency.
224
225 Adding a new global function or global data
226 ===========================================
227
228 bacula.dll
229 ----------
230
231 The code from the following directories is built into bacula.dll:
232
233    .../bacula/src/lib
234    .../bacula/src/libfind
235    .../bacula/src/win32/compat
236
237 A new function or data variable which must be accessed from outside
238 of bacula.dll requires special treatment.  It must be specifically
239 exported.
240
241 New data variables are exported by adding the macro DLL_IMP_EXP to
242 the variable declaration in the header file.  All exported variables
243 must be declared in a header file and MUST NOT be declared in a
244 source file referencing the variable. Example, src/lib/runscript.h:
245
246 extern DLL_IMP_EXP bool (*console_command)(JCR *jcr, const char *cmd);
247
248 or src/jcr.h
249
250 extern int DLL_IMP_EXP num_jobs_run;
251 extern DLL_IMP_EXP dlist * last_jobs;
252 ...
253
254
255 Exporting functions is now more or less automated.  If you find that
256 a function name has been added, changed, or an argument modified,    
257 simply do the following:
258
259    cd .../bacula/src/win32/lib
260    make                  (to build the .o files, note the link will fail)
261    ./make_def >bacula64.def   or >bacula64.def
262
263 This should rebuild the bacula.def file, but it uses relative paths
264 and assumes you have the directory structure noted above. If you 
265 are using something different, you can set the NM variable at the
266 top of the make_def file to use an absolute path to the correct
267 directory.
268
269 ===== manual changing of bacula32.def or bacula64.def no longer necessary =====
270 If you want to do it manually, please see below:
271 Exporting a function requires a bit more work.  You must determine the
272 C++ mangled name of the new function.
273
274    strings .../bacula/src/win32/lib/<file>.o | grep <symbol>
275
276 Note, strings often will not show the desired symbol. In that case,
277 use:
278    
279    nm .../bacula/src/win32/lib/<file>.o
280
281 Replace <file> with the base part of the name of the source code file
282 which contains the new function.  Replace <symbol> with the name of
283 the new function.  Remove the leading underscore and place the result
284 in the file
285
286    .../bacula/src/win32/lib/bacula64.def
287 === end manual changing of bacula64.def ==========
288
289 If you add a new file, you will need to specify its name in
290
291    .../bacula/src/win32/lib/Makefile
292 and
293    .../bacula/src/win32/libbac/Makefile
294
295
296 Running gdb on the Win32 files
297 ==================================================
298 You can use the mingw64 gdb to debug Bacula on Win64 by downloading
299 it from Source Forge:
300
301 http://sourceforge.net/project/showfiles.php?group_id=202880&package_id=311650
302
303
304 Download one of their .exe versions, which is an installer that you
305 can run on Win32 to install gdb.  This gdb is built with mingw64 so will
306 run independently of any cygwin installation.  Note, not all the releases
307 come with an installer. I had to go back 3 or 4 versions to find it.  Otherwise
308 you can download the source and build it.  Thanks to Eric Bollengier for
309 this tip.
310
311
312 Structure of the MinGW64/32 build environment
313 ==========================================
314
315 The basic strategy is each Makefile in the various subdirectories includes
316 Makefile.inc, defines variables and rules specific to what is being built,
317 then includes Makefile.rules which defines all the rules.
318
319 Makefile.inc defines the locations of all the dependencies and the compiler
320 and linker flags.  It is automatically created from Makefile.inc.in.  Any
321 changes must be made to Makefile.inc.in not Makefile.inc or they will be
322 overwritten the next time Makefile.inc.in is updated.
323
324 Makefile.rules defines a bunch of macros to simplify building.  It also
325 includes all the basic rules for building objects, GUI and console
326 executables, etc.
327
328 Makefile.template is a template for creating new Makefiles, if you are
329 creating a new directory, copy Makefile.template to Makefile in that
330 directory and edit to suit.