Updates.
[platform/upstream/glib.git] / README.win32
1 Tor Lillqvist <tml@iki.fi>
2 Hans Breuer <hans@breuer.org>
3
4 The general parts, and the stuff about gcc and autoconfiscated build
5 are by Tor Lillqvist. The stuff about MSVC build is by Hans Breuer.
6
7 General
8 =======
9
10 For prebuilt binaries (DLLs and EXEs) and developer packages (headers,
11 import libraries) of GLib, GTK+, GIMP etc for Windows, surf to
12 http://www.gimp.org/win32/ . They are for "native" Windows meaning
13 they use the Win32 API and Microsoft C runtime library only, no POSIX
14 (Unix) emulation layer (like Cygwin). 
15
16 To build GLib on Win32, you can use either gcc or the Microsoft
17 compiler and tools. Both the compiler from MSVC 5.0 and from MSVC 6.0
18 have been used successfully.
19
20 But note that to just *use* GLib on Windows, there is no need to build
21 it yourself. Prepackaged runtime and developer packages are available
22 from the webiste above. On Unix, it is quite normal that system admins
23 build and install libraries like GLib themselves. But on Windows
24 setting up a correct build environment can be quite a task, especially
25 if you are used to on Unix just type ./configure; make, and expect
26 things to work as smoothly on Windows.
27
28 The following preprocessor macros can be used for conditional
29 compilation related to Win32 in GLib-using code:
30
31 - G_OS_WIN32 is defined when compiling for native Win32, without
32   any POSIX emulation, other than to the extent provided by the
33   bundled Microsoft C library (msvcrt.dll).
34
35 - G_WITH_CYGWIN is defined if compiling for the Cygwin
36   environment. Note that G_OS_WIN32 is *not* defined in that case, as
37   Cygwin is supposed to behave like Unix. G_OS_UNIX *is* defined when
38   compiling for Cygwin.
39
40 - G_PLATFORM_WIN32 is defined when either G_OS_WIN32 or G_WITH_CYGWIN
41   is defined.
42
43 These macros are defined in glibconfig.h, and are thus (indirectly)
44 available in all source files that include <glib.h> or GTK+ headers.
45
46 Additionally, there are the compiler-specific macros:
47 - __GNUC__ is defined when using gcc
48 - _MSC_VER is defined when using the Microsoft compiler
49
50 G_OS_WIN32 implies using the Microsoft C runtime MSVCRT.DLL. GLib is
51 not known to work with the older CRTDLL.DLL runtime, or the static
52 Microsoft C runtime libraries LIBC.LIB and LIBCMT.LIB. It apparently
53 does work with the debugging version of MSVCRT.DLL, MSVCRTD.DLL.
54
55 Building software that use GLib or GTK+
56 =======================================
57
58 Even building software that just *uses* GLib or GTK+ also require to
59 have the right compiler set up the right way, so if you intend to use
60 gcc, follow the relevant instructions below in that case, too.
61
62 Tor uses gcc with the -mms-bitfields flag (used to be called
63 -fnative-struct in gcc 2.x), which means that in order to use the
64 prebuilt DLLs (especially of GTK+), if you compile your code with gcc,
65 you *must* also use that flag. (This flag means that the struct layout
66 rules are identical to those used by MSVC. This is essential if the
67 same DLLs are to be usable both from gcc- and MSVC-compiled code. This
68 definitely is something one wants.)
69
70 Building GLib
71 =============
72
73 Again, first decide whether you really want to do this.
74
75 Before building GLib you must also have the libiconv library, either
76 from the same website mentioned above, or from it's homepage at
77 http://clisp.cons.org/~haible/packages-libiconv.html. Libiconv has
78 makefiles for building with MS Visual C only, but as it is one source
79 file only, building it "by hand" with gcc isn't hard.
80
81 You must also have the "intl" library from GNU tettext 0.10.40 (or
82 later). Get a prebuilt version from the website mentioned above.
83
84 Edit the correct paths to those libraries in build/win32/module.defs
85 as appropriate.
86
87 Where are the makefiles?
88 ========================
89
90 If you are building from a CVS snapshot, you will not have any
91 makefile.mingw or makefile.msc files. You should copy the
92 corresponding makefile.mingw.in or makefile.msc.in file to that name,
93 and replace any @...@ strings with the correct value.
94
95 This is done automatically when an official GLib source distribution
96 package is built, so if you get GLib from a source distribution
97 package, there should be makefile.mingw and makefile.msc files ready
98 to use (after some editing).
99
100 Building GLib with gcc
101 ======================
102
103 Tor uses gcc 3.2. Version 2.95.3 also works.
104
105 You can either use gcc running on Cygwin, or the "pure" mingw
106 gcc. Using the latter might work better, or at least did at some
107 point.
108
109 Fetch the latest version of gcc for mingw and the msvcrt runtime, from
110 www.mingw.org.
111
112 Set up your PATH so that the gcc from the bin directory that got
113 created above is the one that gets used. Even if you run the mingw
114 gcc, you still want to have Cygwin to run make in.
115
116 Then run make -f makefile.mingw. Install the resulting DLLs somewhere
117 in your PATH. You can either keep the headers and import libraries
118 where they are, or install them somewhere else. There are no rules in
119 the makefile.mingws for installing, it is up to you where to put them.
120
121 Autoconfiscated build
122 =====================
123
124 It is also possible to use the auto*, ./configure and libtool
125 mechanism when building with gcc. You should be running Cygwin, or
126 maybe cross-compiling from real Unix, for the configure script to
127 work, obviously. (It should also be possible to use MSYS.) Tor invokes
128 configure using:
129
130 CC='gcc -mcpu=pentium3' CPPFLAGS='-I/target/include' 
131   CFLAGS=-O3 LDFLAGS='-L/target/lib' ./configure --with-libiconv 
132   --disable-static --prefix=/target --host=i386-pc-mingw32 
133   --enable-maintainer-mode
134
135 (on a single line)
136
137 But please note that the ./configure mechanism should not blindly be
138 used to build a GLib to be distributed to other developers because it
139 produces a compiler-dependent glibconfig.h (and config.h, but that
140 shouldn't matter, as it isn't seen by GLib-using applications). For
141 instance, the typedef for gint64 is long long with gcc, but __int64
142 with MSVC.
143
144 Except for this and a few other minor issues, there really shouldn't
145 be any reason to distribute separate GLib headers and DLLs for gcc and
146 MSVC users, as both compilers generate code that uses the same C
147 runtime library. Thus one either has to manually edit glibconfig.h
148 afterwards, or use the supplied glibconfig.h.win32. This has been
149 produced by running configure twice, once using gcc and once using
150 MSVC, and merging the resulting files with diff -D.
151
152 There might be other hickups when using auto* and configure to build
153 with gcc. Lately Tor has used auto*/configure/libtool exclusively when
154 building GLib, GTK+, GIMP etc on Win32, and it seems to work well
155 (with some patches applied to the current CVS libtool...).
156
157 The hand-written makefile.{mingw,msc} files, and the stuff in the
158 "build" subdirectory, produce DLLs and import libraries that match
159 what Makefile.am and libtool produces. For GLib, the DLL is called
160 libglib-2.0-0.dll, and the import libraries libglib-2.0.dll.a and
161 glib-2.0.lib. Note that the "2.0" is part of the "basename" of the
162 library, it is not something that libtool has tucked on. The -0 suffix
163 is the value of "LT_CURRENT - LT_AGE". The 0 is *not* simply the micro
164 version number of GLib, although, for GLib 2.2.0, it happens to be the
165 same. The LT_CURRENT - LT_AGE value will on purpose be kept as zero as
166 long as binary compatibility is maintained. For the gory details, see
167 configure.in and libtool documentation.
168
169 If you want to run the Cygwin-hosted gcc, and still want to produce
170 code that does not use Cygwin, but the msvcrt runtime, in theory it
171 should work to use the -no-cygwin flag, but Tor hasn't tested that
172 lately.
173
174 If you would want to use the Cygwin tools to generate a GLib that
175 *does* use the Cygwin runtime, the normal Unix configuration method
176 should work as if on Unix. Note that successfully producing shared
177 libraries (DLLs) for Cygwin most probably requires you to have a very
178 new libtool. (And a new libtool probably requires rather new autoconf
179 and automake.) Tor hasn't tested this in a while, either.
180
181 Building with MSVC
182 ==================
183
184 All the MSVC makefiles are for the command line build with nmake.
185 If you want to use the VC-UI you can simply create wrapper .dsp
186 makefiles (read the VC docs how to do so).
187
188 Some modules may require Perl to auto-generate files. The goal (at
189 least Hans's) is to not require any more tools.
190
191 Build with:
192
193 nmake -f makefile.msc
194   or
195 nmake -f makefile.msc DEBUG=1
196
197 [
198  The former will create 'release' versions of the DLLs. If you
199  plan to distribute you DLLs please use this command. The latter 
200  will create DLLs with debug information _and_ link them with
201  msvcrtd.dll instead of msvcrt.dll. 
202  Beware: There are known problems with mixing DLLs in one 
203  application, which are build against different runtimes. 
204  Especially the index-to-file mapping used by 'unix-style' file
205  operation - _open() _pipe() etc. - breaks sometimes in strange 
206  ways (for example the Gimp plug-in communication).
207 ]
208
209 Required libraries (not build from cvs)
210 ==================
211   libintl (gnu-intl), libiconv
212   libtiff, libpng, zlib, libjpeg
213
214 are available pre-built from the website mentioned above.
215
216 Versioning
217 ==========
218 Instead of the Unix and auto* way of tracking versions and resolving
219 dependencies (configure; make; make install) involving autoconf,
220 automake, libtool and friends the MSVC build uses a different
221 approach.
222
223 The core of it's versioning is the file build/win32/module.defs.
224 It contains entries of the form MODULE_VER, e.g.:
225
226         GLIB_VER = 2.0
227         LIBICONV_VER = 1.3
228
229 and the placement of these modules defined as MODULE, e.g.:
230
231         GLIB = $(TOP)/glib
232         LIBICONV = $(TOP)/libiconv-$(LIBICONV_VER)
233
234 whereas TOP is defined as the relative path from the respective
235 module directory to your top build directory. Every makefile.msc
236 needs to define TOP before including the common make file part
237 make.msc, which than includes module.defs, like:
238
239 TOP = ../..
240 !INCLUDE $(TOP)/glib/build/win32/make.msc
241
242 (Taken from gtk+/gdk/makefile.msc)
243
244 With this provision it is possible to create almost placement
245 independent makefiles without requiring to 'install' the libraries and
246 headers into a common place (as it is done on Unix, and as Tor does
247 when producing his zipfiles with prebuilt GLib, GTK+ etc).
248
249 Special Files
250 =============
251         config.h.win32.in : @XXX_MAJOR_VERSION@ needs to be replaced by
252 the current version/build number. The resulting file is to be saved
253 as 'config.h.win32'. This should be automatically done if a package
254 gets build on the Unix platform.
255
256         makefile.msc.in : @XXX_MAJOR_VERSION@ to be replaced. Save as
257 makefile.msc.
258
259         <module>.def : every function which should be used from the outside of
260 a dll needs to be marked for 'export'. It is common that one needs to change 
261 these files after some api changes occured. If there are variables to be
262 exported another mechanism is needed, like :
263
264         #ifdef G_OS_WIN32
265         #  ifdef GDK_COMPILATION
266         #    define GDKVAR __declspec(dllexport)
267         #  else
268         #    define GDKVAR extern __declspec(dllimport)
269         #  endif
270         #else
271         #  define GDKVAR extern
272         #endif
273
274
275
276 Directory Structure
277 ===================
278 all modules should be build in a common directory tree otherwise you 
279 need to adapt the file 'module.defs'. They are listed here in increasing
280 dependencies order.
281
282 <common rootdir without spaces>
283   |
284   +- glib
285   |   |
286   |   +- build          : [this module lives in the cvs root dir]
287   |   |   +- win32
288   |   |       .\module.defs : defines (relative) locations of the headers
289   |   |                       and libs and version numbers to be include 
290   |   |                       in dll names
291   |   |       .\make.msc    : include by almost every 'makefile.msc'
292   |   |
293   |   | .\README.WIN32  : more information how to build
294   |   | .\glibconfig.h.win32.in : similar to config.h.win32.in
295   |   | .\makefile.msc  : master makefile, sub dir makefiles should work 
296   |   |
297   |   +- glib
298   |   +- gmodule
299   |   +- gthread        : does _not_ depend on pthread anymore
300   |   +- gobject
301   |
302   +- pango
303   |   +- pango          : 'native' build does not require extra libs and
304   |   |                 includes the minimal required text renderer
305   |   |                 (there is also a currently slightly broken FreeType2 
306   |   |                 based implementation for win32)
307   |   +- modules (not yet build)
308   |
309   +- atk
310   |   +- atk
311   |       .\makefile.msc : build here
312   |
313   +- gtk+
314   |   | .\config.h.win32 : for all the below
315   |   |
316   |   +- gdk-pixbuf
317   |   |   .\gdk_pixbuf.rc.in : version resource for the DLLs. Needs
318   |   |                 to be converted (filled with version info)
319   |   |                 as described above.
320   |   |
321   |   +- gdk
322   |   |   | .\makefile.msc : some auto-generation is needed to build in the
323   |   |   |             in the subdirectory 
324   |   |   +- win32
325   |   |
326   |   +- gtk
327
328   |
329   +- gimp
330   |   .\makefile.msc    : master makefile to build The Gimp. The makefiles
331   |                     from the sub dirs should work stand alone, but than
332   |                     the user needs to know the build order
333
334   |
335   +- dia                : additionally depends on libart_lgpl (in cvs)
336       |                 and libxml2 ( see http://www.xmlsoft.org/ )
337       +- lib
338       +- app
339       +- objects
340       +- plug-ins
341           +- python
342