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