Minor edits.
[platform/upstream/glib.git] / README.win32
1 General
2 =======
3
4 For more information about the port or GLib, GTK+ and the GIMP to
5 native Windows, and pre-built binaries (DLLs), surf to
6 http://www.gimp.org/win32/ . "Native" means that we use the Win32 API
7 only, and no POSIX (Unix) emulation layer except that provided by the
8 Microsoft runtime C library.
9
10 To build GLib on Win32, you can use either gcc or the Microsoft
11 compiler and tools. Both the compiler from MSVC 5.0 and from MSVC 6.0
12 have been used successfully.
13
14 But note that to just *use* GLib on Windows, there is no need to build
15 it, prebuilt DLLs are available from the webiste above.
16
17 The following preprocessor macros are used for conditional compilation
18 related to Win32:
19
20 - G_OS_WIN32 is defined when compiling for Win32, *and* without
21   any POSIX emulation, other that to the extent provided by the
22   bundled Microsoft C library (msvcrt.dll).
23
24 - G_WITH_CYGWIN is defined if compiling for the Cygwin
25   environment. Note that G_OS_WIN32 is *not* defined in that case, as
26   Cygwin is supposed to behave like Unix. G_OS_UNIX *is* defined when
27   compiling for Cygwin.
28
29 - G_PLATFORM_WIN32 is defined when either G_OS_WIN32 or G_WITH_CYGWIN
30   is defined.
31
32 The Win32 port of GLib and related software uses only G_OS_WIN32. As
33 G_OS_WIN32 is defined in glibconfig.h, it is available to all source
34 files that use GLib (or GTK+, which uses GLib).
35
36 Additionally, there are the compiler-specific macros:
37 - __GNUC__ is defined when using GCC
38 - _MSC_VER is defined when using the Microsoft compiler
39
40 G_OS_WIN32 implies using the Microsoft C runtime MSVCRT.DLL. GLib is
41 not known to work with the older CRTDLL.DLL runtime, or the static
42 Microsoft C runtime libraries LIBC.LIB and LIBCMT.LIB. 
43
44 Building software that use GLib or GTK+
45 =======================================
46
47 Even building software that just *use* GLib or GTK+ also require to
48 have the right compiler set up the right way, so if you intend to use
49 gcc, follow the relevant instructions below in that case, too.
50
51 Dependent libraries
52 ===================
53
54 Before building GLib you must also have the libiconv library, either
55 from the same website mentioned above, or from it's homepage at
56 http://clisp.cons.org/~haible/packages-libiconv.html. Libiconv has
57 makefiles for building with MS Visual C only, but as it is one source
58 file only, building it "by hand" with gcc isn't hard.
59
60 You must also have the "intl" library from GNU tettext 0.10.40 (or
61 later). Get a prebuilt version from the website mentioned above.
62
63 Edit the correct paths to those libraries in build/win32/module.defs
64 as appropriate.
65
66 Where are the makefiles?
67 ========================
68
69 If you are building from a CVS snapshot, you will not have any
70 makefile.mingw or makefile.msc file. You should copy the corresponding
71 makefile.mingw.in or makefile.msc.in file to that name, and replace
72 any @...@ strings with the correct value.
73
74 This is done automatically when an official GLib source distribution
75 package is built.
76
77 Building GLib with gcc
78 ======================
79
80 I use gcc-2.95.3. Version 2.95.2 will most probably also work.
81
82 You can either use gcc running on Cygwin, or the "pure" mingw
83 gcc. Using the latter might work better, or at least did at some
84 point.
85
86 Fetch the latest version of gcc for mingw and the msvcrt runtime, from
87 www.mingw.org.
88
89 Set up your PATH so that the gcc from the bin directory that got
90 created above is the one that gets used. Even if you run the mingw
91 gcc, you still want to have Cygwin to run make in.
92
93 Then run make -f makefile.mingw. Install the resulting DLLs somewhere
94 in your PATH. You can either keep the headers and import libraries
95 where they are, or install them somewhere else. There are no rules in
96 the makefile.mingws for installing, it is up to you where to put
97 stuff.
98
99 I use the -fnative-struct flag, which means that in order to use the
100 prebuilt DLLs (especially of GTK+), you *must* also use that flag.
101 (This flag means that the struct layout is identical to that used by
102 MSVC. This is essential if the same DLLs are to be usable both from
103 gcc- and MSVC-compiled code, which definitely is a good thing.)
104
105 It is also possible to use the auto*, ./configure and libtool
106 mechanism when building for mingw. You should be running Cygwin, or
107 maybe cross-compiling from real Unix, for the configure script to
108 work, obviously. You most probably should have very new auto* and
109 libtool. Personally, I invoke configure using:
110
111 CC='gcc -mpentium -fnative-struct'
112   CPPFLAGS='-I/src/libiconv-1.7/include -I/target/include'
113   LDFLAGS='-L/src/libiconv-1.7/lib -L/target/lib' ./configure
114   --with-libiconv --disable-static --prefix=/target
115   --host=i386-pc-mingw32 --enable-maintainer-mode
116
117 (on a single line)
118
119 But please note that the ./configure mechanism should not blindly be
120 used to build a GLib to be distributed to potential developers because
121 it produces a compiler-dependent glibconfig.h (and config.h, but that
122 shouldn't matter, as it isn't seen by GLib-using applications). For
123 instance, the typedef for gint64 is long long with gcc, but __int64
124 with MSVC.
125
126 Except for this and a few other minor issues, there really shouldn't
127 be any reason to distribute separate GLib DLLs for gcc and MSVC users,
128 as both compiler+tools generate code that uses the same C runtime
129 library. Thus one either has to manually edit glibconfig.h afterwards,
130 or use the supplied config.h.win32 and glibconfig.h.win32. These have
131 been produced by running configure twice, once using gcc and once
132 using MSVC, and merging the resulting files with diff -D.
133
134 There are probably also other hickups when using auto* and configure
135 to build for mingw, sigh. Every now and then I try to get rid of the
136 hand-written makefiles and configuration headers for Win32, and start
137 fooling around with auto* etc, but after a while give up and fall
138 back. At least, it used to be like that. Lately I have again been
139 working on using auto*/configure/libtool on Win32, and it now seems to
140 work well enough (with some patches applied to the current CVS
141 libtool...).
142
143 The hand-written makefile.{mingw,msc} files, and the stuff in the
144 "build" subdirectory, has been updated to produce DLLs and import
145 libraries that match what Makefile.am and libtool produces. For GLib,
146 the DLL is called libglib-1.3-10.dll (at GLib 1.3.10), and the import
147 libraries libglib-1.3.a and glib-1.3.lib. Note that the "1.3" is part
148 of the "basename" of the library, it is not something that libtool
149 would tuck on. The -10 suffix is the value of "LT_CURRENT -
150 LT_AGE". The 10 is *not* the micro version number of GLib, although,
151 for GLib 1.3.10, it happens to be the same. For the gory details, see
152 configure.in and libtool documentation.
153
154 If you want to run the Cygwin-hosted gcc, and still want to produce
155 code that does not use Cygwin, but the msvcrt runtime, in theory it
156 should work to use the -no-cygwin flag, but I haven't tested that
157 lately.
158
159 If you would want to use the Cygwin tools to generate a GLib that
160 *does* use the Cygwin runtime, the normal Unix configuration method
161 should work as if on Unix. Note that successfully producing shared
162 libraries (DLLs) for Cygwin most probably requires you to have a very
163 new libtool. (And a new libtool probably requires rather new autoconf
164 and automake.) I haven't personally tested this in a while.
165
166 Building with MSVC
167 ==================
168
169 If using the Microsoft toolchain, build with `nmake -f
170 makefile.msc`.
171
172 --Tor Lillqvist <tml@iki.fi>