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