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