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