Glib is upgraded(2.28.6->2.32.3), python-xml dependancy added
[external/glib2.0.git] / README.win32
1 Tor Lillqvist <tml@iki.fi>\r
2 Hans Breuer <hans@breuer.org>\r
3 \r
4 Note that this document is not really maintained in a serious\r
5 fashion. Lots of information here might be misleading or outdated. You\r
6 have been warned.\r
7 \r
8 The general parts, and the section about gcc and autoconfiscated\r
9 build, and about a Visual Studio build are by Tor Lillqvist. The\r
10 sections about MSVC build with NMAKE is by Hans Breuer. \r
11 \r
12 General\r
13 =======\r
14 \r
15 For prebuilt binaries (DLLs and EXEs) and developer packages (headers,\r
16 import libraries) of GLib, Pango, GTK+ etc for Windows, go to\r
17 http://www.gtk.org/download-windows.html . They are for "native"\r
18 Windows meaning they use the Win32 API and Microsoft C runtime library\r
19 only. No POSIX (Unix) emulation layer like Cygwin in involved.\r
20 \r
21 To build GLib on Win32, you can use either gcc ("mingw") or the\r
22 Microsoft compiler and tools. For the latter, MSVC6 and later have\r
23 been used successfully. Also the Digital Mars C/C++ compiler has\r
24 reportedly been used.\r
25 \r
26 You can also cross-compile GLib for Windows from Linux using the\r
27 cross-compiling mingw packages for your distro.\r
28 \r
29 Note that to just *use* GLib on Windows, there is no need to build it\r
30 yourself.\r
31 \r
32 On Windows setting up a correct build environment can be quite a task,\r
33 especially if you are used to just type "./configure; make" on Linux,\r
34 and expect things to work as smoothly on Windows.\r
35 \r
36 The following preprocessor macros are to be used for conditional\r
37 compilation related to Win32 in GLib-using code:\r
38 \r
39 - G_OS_WIN32 is defined when compiling for native Win32, without\r
40   any POSIX emulation, other than to the extent provided by the\r
41   bundled Microsoft C library (msvcr*.dll).\r
42 \r
43 - G_WITH_CYGWIN is defined if compiling for the Cygwin\r
44   environment. Note that G_OS_WIN32 is *not* defined in that case, as\r
45   Cygwin is supposed to behave like Unix. G_OS_UNIX *is* defined by a GLib\r
46   for Cygwin.\r
47 \r
48 - G_PLATFORM_WIN32 is defined when either G_OS_WIN32 or G_WITH_CYGWIN\r
49   is defined.\r
50 \r
51 These macros are defined in glibconfig.h, and are thus available in\r
52 all source files that include <glib.h>.\r
53 \r
54 Additionally, there are the compiler-specific macros:\r
55 - __GNUC__ is defined when using gcc\r
56 - _MSC_VER is defined when using the Microsoft compiler\r
57 - __DMC__ is defined when using the Digital Mars C/C++ compiler\r
58 \r
59 G_OS_WIN32 implies using the Microsoft C runtime, normally\r
60 msvcrt.dll. GLib is not known to work with the older crtdll.dll\r
61 runtime, or the static Microsoft C runtime libraries libc.lib and\r
62 libcmt.lib. It apparently does work with the debugging version of\r
63 msvcrt.dll, msvcrtd.dll. If compiled with Microsoft compilers newer\r
64 than MSVC6, it also works with their compiler-specific runtimes, like\r
65 msvcr70.dll or msvcr80.dll. Please note that it's non totally clear if\r
66 you would be allowed by the license to distrubute a GLib linked to\r
67 msvcr70.dll or msvcr80.dll, as those are not part of the operating\r
68 system, but of the MSVC product. msvcrt.dll is part of Windows.\r
69 \r
70 Building software that use GLib or GTK+\r
71 =======================================\r
72 \r
73 Building software that just *uses* GLib or GTK+ also require to have\r
74 the right compiler set up the right way. If you intend to use gcc,\r
75 follow the relevant instructions below in that case, too.\r
76 \r
77 Tor uses gcc with the -mms-bitfields flag which means that in order to\r
78 use the prebuilt DLLs (especially of GTK+), if you compile your code\r
79 with gcc, you *must* also use that flag. This flag means that the\r
80 struct layout rules are identical to those used by MSVC. This is\r
81 essential if the same DLLs are to be usable both from gcc- and\r
82 MSVC-compiled code. Such compatibility is desirable.\r
83 \r
84 When using the prebuilt GLib DLLs that use msvcrt.dll from code that\r
85 uses other C runtimes like for example msvcr70.dll, one should note\r
86 that one cannot use such GLib API that take or returns file\r
87 descriptors. On Windows, a file descriptor (the small integer as\r
88 returned by open() and handled by related functions, and included in\r
89 the FILE struct) is an index into a table local to the C runtime\r
90 DLL. A file descriptor in one C runtime DLL does not have the same\r
91 meaning in another C runtime DLL.\r
92 \r
93 Building GLib\r
94 =============\r
95 \r
96 Again, first decide whether you really want to do this.\r
97 \r
98 Before building GLib you must also have a GNU gettext-runtime\r
99 developer package. Get prebuilt binaries of gettext-runtime from\r
100 http://www.gtk.org/download-windows.html .\r
101 \r
102 Autoconfiscated build (with gcc)\r
103 ================================\r
104 \r
105 Tor uses gcc 3.4.5 and the rest of the mingw utilities, including MSYS\r
106 from www.mingw.org. Somewhat earlier or later versions of gcc\r
107 presumably also work fine.\r
108 \r
109 Using Cygwin's gcc with the -mno-cygwin switch is not recommended. In\r
110 theory it should work, but Tor hasn't tested that lately. It can\r
111 easily lead to confusing situations where one mixes headers for Cygwin\r
112 from /usr/include with the headers for native software one really\r
113 should use. Ditto for libraries.\r
114 \r
115 If you want to use mingw's gcc, install gcc, win32api, binutils and\r
116 MSYS from www.mingw.org.\r
117 \r
118 Tor invokes configure using:\r
119 \r
120 CC='gcc -mtune=pentium3 -mthreads' CPPFLAGS='-I/opt/gnu/include' \\r
121         LDFLAGS='-L/opt/gnu/lib -Wl,--enable-auto-image-base' CFLAGS=-O2 \\r
122         ./configure --disable-gtk-doc --prefix=$TARGET\r
123 \r
124 The /opt/gnu mentioned contains the header files for GNU and (import)\r
125 libraries for GNU libintl. The build scripts used to produce the\r
126 prebuilt binaries are included in the "dev" packages.\r
127 \r
128 Please note that the ./configure mechanism should not blindly be used\r
129 to build a GLib to be distributed to other developers because it\r
130 produces a compiler-dependent glibconfig.h. For instance, the typedef\r
131 for gint64 is long long with gcc, but __int64 with MSVC.\r
132 \r
133 Except for this and a few other minor issues, there shouldn't be any\r
134 reason to distribute separate GLib headers and DLLs for gcc and MSVC6\r
135 users, as the compilers generate code that uses the same C runtime\r
136 library.\r
137 \r
138 The DLL generated by either compiler is binary compatible with the\r
139 other one. Thus one either has to manually edit glibconfig.h\r
140 afterwards, or use the supplied glibconfig.h.win32 which has been\r
141 produced by running configure twice, once using gcc and once using\r
142 MSVC, and merging the resulting files with diff -D.\r
143 \r
144 For MSVC7 and later (Visual C++ .NET 2003, Visual C++ 2005, Visual C++\r
145 2008 etc) it is preferred to use specific builds of GLib DLLs that use\r
146 the same C runtime as the code that uses GLib. Such DLLs should be\r
147 named differently than the ones that use msvcrt.dll.\r
148 \r
149 For GLib, the DLL that uses msvcrt.dll is called libglib-2.0-0.dll,\r
150 and the import libraries libglib-2.0.dll.a and glib-2.0.lib. Note that\r
151 the "2.0" is part of the "basename" of the library, it is not\r
152 something that libtool has added. The -0 suffix is added by libtool\r
153 and is the value of "LT_CURRENT - LT_AGE". The 0 should *not* be\r
154 thought to be part of the version number of GLib. The LT_CURRENT -\r
155 LT_AGE value will on purpose be kept as zero as long as binary\r
156 compatibility is maintained. For the gory details, see configure.ac\r
157 and libtool documentation.\r
158 \r
159 Building with Visual Studio\r
160 ===========================\r
161 \r
162 A more detailed outline of building GLib with its dependencies can\r
163 now be found in GNOME Live!:\r
164 \r
165 https://live.gnome.org/GTK%2B/Win32/MSVCCompilationOfGTKStack\r
166 \r
167 Please do not build GLib in paths that contain spaces in them, as\r
168 this may cause problems during compilation and during usage of the\r
169 library.\r
170 \r
171 In an unpacked tarball, you will find in build\win32\vs9 (VS 2008) and\r
172 build\win32\vs10 (VS 2010) a solution file that can be used to build\r
173 the GLib DLLs and some auxiliary programs under VS 2008 and VS 2010\r
174 (Express Edition will suffice with the needed dependencies) respectively.\r
175 Read the README.txt file in those folders for more\r
176 information. Note that you will need a libintl implementation, zlib, and \r
177 libFFI.\r
178 \r
179 If you are building from a GIT checkout, you will first need to use some\r
180 Unix-like environment or run build/win32/setup.py, \r
181 which will expand the VS 2008/2010 project files, the DLL resouce files and\r
182 other miscellanious files required for the build.  Run build/win32/setup.py\r
183 as follows:\r
184 \r
185 $python build/win32/setup.py --perl path_to_your_perl.exe\r
186 \r
187 for more usage on this script, run\r
188 $python build/win32/setup.py -h/--help\r
189 \r
190 Building with MSVC and NMAKE\r
191 ============================\r
192 \r
193 If you are building from a GIT snapshot, you will not have all\r
194 makefile.msc files. You should copy the corresponding makefile.msc.in\r
195 file to that name, and replace any @...@ strings with the correct\r
196 value (or use the python script de-in.py from http://hans.breuer.org/gtk/de-in.py).\r
197 \r
198 This is done automatically when an official GLib source distribution\r
199 package is built, so if you get GLib from a source distribution\r
200 package, there should be makefile.msc files ready to use (possibly after some\r
201 editing).\r
202 \r
203 The hand-written makefile.msc files, and the stuff in the "build"\r
204 subdirectory, produce DLLs and import libraries that match what the\r
205 so-called autoconfiscated build produces.\r
206 \r
207 All the MSVC makefiles are for the command line build with nmake.  If\r
208 you want to use the VC-UI you can simply create wrapper .dsp makefiles\r
209 (read the VC docs how to do so).\r
210 \r
211 Some modules may require Perl to auto-generate files. The goal (at\r
212 least Hans's) is to not require any more tools. Of course you need\r
213 the Microsoft Platform SDK in a recent enough - but not too recent - version.\r
214 The last PSDK for Visual Studio 6 is:\r
215   http://www.microsoft.com/msdownload/platformsdk/sdkupdate/psdk-full.htm\r
216 At least install the Core SDK, maybe also the "Tablet PC SDK".\r
217 \r
218 \r
219 Build with:\r
220 \r
221 nmake -f makefile.msc\r
222   or\r
223 nmake -f makefile.msc DEBUG=1\r
224 \r
225 [\r
226  The former will create 'release' versions of the DLLs. If you\r
227  plan to distribute you DLLs please use this command. The latter \r
228  will create DLLs with debug information _and_ link them with\r
229  msvcrtd.dll instead of msvcrt.dll. \r
230  Beware: There are known problems with mixing DLLs in one \r
231  application, which are build against different runtimes. \r
232  Especially the index-to-file mapping used by 'unix-style' file\r
233  operation - _open() _pipe() etc. - breaks sometimes in strange \r
234  ways (for example the Gimp plug-in communication).\r
235 ]\r
236 \r
237 Required libraries (not build from svn)\r
238 ------------------\r
239   libintl (gnu-intl),\r
240 \r
241 are available pre-built from the website mentioned above.\r
242 \r
243 Versioning\r
244 ----------\r
245 Instead of the Unix and auto* way of tracking versions and resolving\r
246 dependencies (configure; make; make install) involving autoconf,\r
247 automake, libtool and friends the MSVC build uses a different\r
248 approach.\r
249 \r
250 The core of it's versioning is the file build/win32/module.defs.\r
251 It contains entries of the form MODULE_VER, e.g.:\r
252 \r
253         GLIB_VER = 2.0\r
254         LIBICONV_VER = 1.3\r
255 \r
256 and the placement of these modules defined as MODULE, e.g.:\r
257 \r
258         GLIB = $(TOP)/glib\r
259         LIBICONV = $(TOP)/libiconv-$(LIBICONV_VER)\r
260 \r
261 whereas TOP is defined as the relative path from the respective\r
262 module directory to your top build directory. Every makefile.msc\r
263 needs to define TOP before including the common make file part\r
264 make.msc, which than includes module.defs, like:\r
265 \r
266 TOP = ../..\r
267 !INCLUDE $(TOP)/glib/build/win32/make.msc\r
268 \r
269 (Taken from gtk+/gdk/makefile.msc)\r
270 \r
271 With this provision it is possible to create almost placement\r
272 independent makefiles without requiring to 'install' the libraries and\r
273 headers into a common place (as it is done on Unix, and as Tor does\r
274 when producing his zipfiles with prebuilt GLib, GTK+ etc).\r
275 \r
276 Special Files\r
277 -------------\r
278         config.h.win32.in : @XXX_MAJOR_VERSION@ needs to be replaced by\r
279 the current version/build number. The resulting file is to be saved\r
280 as 'config.h.win32'. This should be automatically done if a package\r
281 gets build on the Unix platform.\r
282 \r
283         makefile.msc.in : @XXX_MAJOR_VERSION@ to be replaced. Save as\r
284 makefile.msc.\r
285 \r
286         <module>.def : every function which should be used from the outside of\r
287 a dll needs to be marked for 'export'. It is common that one needs to change \r
288 these files after some api changes occured. If there are variables to be\r
289 exported another mechanism is needed, like :\r
290 \r
291         #ifdef G_OS_WIN32\r
292         #  ifdef GDK_COMPILATION\r
293         #    define GDKVAR __declspec(dllexport)\r
294         #  else\r
295         #    define GDKVAR extern __declspec(dllimport)\r
296         #  endif\r
297         #else\r
298         #  define GDKVAR extern\r
299         #endif\r
300 \r
301 \r
302 \r
303 Directory Structure\r
304 -------------------\r
305 all modules should be build in a common directory tree otherwise you \r
306 need to adapt the file 'module.defs'. They are listed here in increasing\r
307 dependencies order.\r
308 \r
309 <common rootdir without spaces>\r
310   |\r
311   +- glib\r
312   |   |\r
313   |   +- build          : [this module lives in the SVN root dir]\r
314   |   |   +- win32\r
315   |   |       .\module.defs : defines (relative) locations of the headers\r
316   |   |                       and libs and version numbers to be include \r
317   |   |                       in dll names\r
318   |   |       .\make.msc    : include by almost every 'makefile.msc'\r
319   |   |\r
320   |   | .\README.WIN32  : more information how to build\r
321   |   | .\glibconfig.h.win32.in : similar to config.h.win32.in\r
322   |   | .\makefile.msc  : master makefile, sub dir makefiles should work \r
323   |   |\r
324   |   +- glib\r
325   |   +- gmodule\r
326   |   +- gthread        : does _not_ depend on pthread anymore\r
327   |   +- gobject\r
328   |\r
329   +- pango\r
330   |   +- pango          : 'native' build does not require extra libs and\r
331   |   |                 includes the minimal required text renderer\r
332   |   |                 (there is also a currently slightly broken FreeType2 \r
333   |   |                 based implementation for win32)\r
334   |   +- modules (not yet build)\r
335   |\r
336   +- atk\r
337   |   +- atk\r
338   |       .\makefile.msc : build here\r
339   |\r
340   +- gtk+\r
341   |   | .\config.h.win32 : for all the below\r
342   |   |\r
343   |   +- gdk-pixbuf\r
344   |   |   .\gdk_pixbuf.rc.in : version resource for the DLLs. Needs\r
345   |   |                 to be converted (filled with version info)\r
346   |   |                 as described above.\r
347   |   |\r
348   |   +- gdk\r
349   |   |   | .\makefile.msc : some auto-generation is needed to build in the\r
350   |   |   |             in the subdirectory \r
351   |   |   +- win32\r
352   |   |\r
353   |   +- gtk\r
354 \r
355   |\r
356   +- gimp\r
357   |   .\makefile.msc    : master makefile to build The Gimp. The makefiles\r
358   |                     from the sub dirs should work stand alone, but than\r
359   |                     the user needs to know the build order\r
360 \r
361   |\r
362   +- dia                : additionally depends on libart_lgpl (in SVN)\r
363       |                 and libxml2 ( see http://www.xmlsoft.org/ )\r
364       +- lib\r
365       +- app\r
366       +- objects\r
367       +- plug-ins\r
368           +- python\r
369 \r