glib.h New functions for conversion between UTF-8 and the encoding
[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 binary packages, see
6 http://www.iki.fi/tml/gimp/win32/ . "Native" means that we use the
7 Win32 API only, and not any POSIX emulation layer except that provided
8 by the Microsoft runtime C library. Additionally, a pthreads emulation
9 library is used.
10
11 To build GLib on Win32, you can use either the Microsoft compiler and
12 tools, or gcc. Both the compiler from MSVC 5.0 and from MSVC 6.0 have
13 been used successfully. With gcc I mean gcc-2.95 or gcc-2.95.2 as
14 distributed by Mumit Khan, running under cygwin-b20.1. To successfully
15 use gcc, follow the instructions below. We want to use gcc
16 -mno-cygwin, i.e. produce executables (.exe and .dll files) that do
17 *not* require the cygwin runtime library. This is sometimes called
18 "mingw32".
19
20 To test the GLib functions, go to the tests subdirectory and enter
21 `nmake -f makefile.msc check` or `make -f makefile.cygwin check`.
22
23 If you would want to use the cygwin tools to generate executables that
24 *do* use the cygwin runtime, the normal Unix configuration method
25 should work as if on Unix. But it won't produce DLLs. At least I
26 haven't succeeded in that.
27
28 With a little work, it might be possible to use the ./configure
29 mechanism also with a "mingw32" configuration.
30
31 The following preprocessor macro are used for conditional compilation
32 related to Win32:
33
34 - G_OS_WIN32 is defined when compiling for Win32, *and* without
35   any POSIX emulation, other that to the extent provided by the
36   bundled Microsoft C library (msvcrt.dll) and the pthreads-win32
37   library. For instance, pathnames are in the native Windows syntax.
38
39 - _WIN32 is defined by the compiler
40
41 The Win32 port uses the combination with both of those on. As
42 G_OS_WIN32 is defined in glibconfig.h, it is available to all source
43 files that use GLib (or GTk+, which uses GLib).
44
45 Additionally, there are the compiler-specific macros:
46 - _MSC_VER is defined when using the Microsoft compiler
47 - __GNUC__ is defined when using GCC
48
49 Some of the usage of these macros used to be a bit mixed up, and had
50 to be straightened out when adding the gcc support. In particular, I
51 used to check for _MSC_VER in some places where I really wanted to
52 check for the Microsoft C library, and those checks has now been
53 changed to G_OS_WIN32.
54
55 G_OS_WIN32 implies using the Microsoft C runtime MSVCRT.DLL.
56
57 Building software that use GLib or GTk+
58 =======================================
59
60 Unfortunately, even building software that just *use* GLib or GTk+
61 also require to have the right compiler set up the right way, so if
62 you intend to use gcc, follow the relevant instructions below in that
63 case, too.
64
65 Pthreads library
66 ================
67
68 Before building you must get the pthreads library for Win32 from
69 http://sourceware.cygnus.com/pthreads-win32/. The pthreads-win32
70 snapshot from 1999-05-30 is the one that should be used. Edit the
71 location of the pthreads library and include files in makefile.msc or
72 makefile.cygwin. The pthreads distribution includes the precompiled dll
73 and import libraries both for MSVC and gcc.
74
75 The pthreads for Win32 package that the thread support uses supposedly
76 isn't quite ready yet, and thus threads stuff should not be relied
77 upon for anything serious.
78
79 Where are the makefiles?
80 ========================
81
82 If you are building from a CVS snapshot, you will not have any
83 makefile.msc or makefile.cygwin file. You should copy the
84 corresponding makefile.msc.in or makefile.cygwin.in file to that name,
85 and edit the line that sets GLIB_VER to the correct version number.
86
87 This is done automatically when an official distribution package is
88 built.
89
90 Building with MSVC
91 ==================
92
93 If using the Microsoft toolchain, build with `nmake -f
94 makefile.msc`. Install with `nmake -f makefile.msc install`. 
95
96 Building with gcc
97 =================
98
99 I use the latest and greatest gcc, gcc-2.95.2. 2.95 will also work.
100 Earlier version might, but you are on your own.
101
102 Read these instruction carefully and understand them. If you don't
103 understand or can't follow the instructions, you probably shouldn't
104 want to build GLib (or GTk+ or GIMP) yourself anyway. 
105
106 0) Get and install Cygwin B20.1.
107
108    Move the include files and libraries included in Cygwin out of the
109    way not to mix things up... (For example, rename
110    /cygnus/cygwin-b20/H-i586-cygwin32/i586-cygwin32/lib to
111    lib-no-thanks and rename
112    /cygnus/cygwin-b20/H-i586-cygwin32/i586-cygwin32/include to
113    include-no-thanks.
114
115 1) Get gcc 2.95.2 built for Cygwin B20.1 from 
116    ftp://ftp.xraylith.wisc.edu/pub/khan/gnu-win32/cygwin/gcc-2.95.2/gcc-2.95.2-cygb20.tar.gz
117
118    Install it somewhere, let's say G:\gcc-2.95.2 (//g/gcc-2.95.2 when
119    in Cygwin). Add //g/gcc-2.95.2/H-i586-cygwin32/bin to your
120    PATH. I assume you use bash below.
121
122    Replace the specs file in
123    //g/gcc-2.95.2/H-i586-cygwin32/lib/gcc-lib/i586-cygwin32/2.95.2/specs
124    with the following. (The changes are: Define __MSVCRT__, replace
125    the "1" versions of the crt files with the "2" ones, replace crtdll
126    with msvcrt. Also, extra whitespace squished. )
127
128 ================ cut here ================
129 *asm:
130
131
132 *asm_final:
133
134
135 *cpp:
136 -remap %(cpp_cpu) %{posix:-D_POSIX_SOURCE} %{!mno-cygwin:-D__CYGWIN32__ -D__CYGWIN__} %{mno-cygwin:-iwithprefixbefore ../../../../%(mingw_include_path)/include/mingw32 -D__MSVCRT__ -D__MINGW32__=0.2}
137
138 *cc1:
139 %(cc1_spec) 
140
141 *cc1plus:
142
143
144 *endfile:
145
146
147 *link:
148 %{mwindows:--subsystem windows} %{mconsole:--subsystem console} %{mdll:--dll -e _DllMainCRTStartup@12}
149
150 *lib:
151 %{pg:-lgmon} %{!mno-cygwin:-lcygwin} %{mno-cygwin:-lmingw32 -lmoldname -lmsvcrt} %{mwindows:-lgdi32 -lcomdlg32} -luser32 -lkernel32 -ladvapi32 -lshell32
152
153 *libgcc:
154 -lgcc
155
156 *startfile:
157 %{mdll: %{mno-cygwin:dllcrt2%O%s}} %{!mdll: %{!mno-cygwin:crt0%O%s} %{mno-cygwin:crt2%O%s} %{pg: %{!mno-cygwin:gcrt0%O%s} %{mno-cygwin:gcrt2%O%s}}}
158
159 *switches_need_spaces:
160
161
162 *signed_char:
163 %{funsigned-char:-D__CHAR_UNSIGNED__}
164
165 *predefines:
166 -Di386 -D_WIN32 -DWINNT -D_X86_=1 -D__STDC__=1 -D__stdcall=__attribute__((__stdcall__)) -D__cdecl=__attribute__((__cdecl__)) -D__declspec(x)=__attribute__((x)) -Asystem(winnt) -Acpu(i386) -Amachine(i386)
167
168 *cross_compile:
169 0
170
171 *version:
172 2.95.2
173
174 *multilib:
175 . !mno-cygwin;mingw32 mno-cygwin;;
176
177 *multilib_defaults:
178
179
180 *multilib_extra:
181
182
183 *multilib_matches:
184 mno-cygwin mno-cygwin;
185
186 *linker:
187 collect2
188
189 *cpp_486:
190 %{!ansi:-Di486} -D__i486 -D__i486__
191
192 *cpp_586:
193 %{!ansi:-Di586 -Dpentium} -D__i586 -D__i586__ -D__pentium -D__pentium__
194
195 *cpp_k6:
196 %{!ansi:-Di586 -Dk6} -D__i586 -D__i586__ -D__k6 -D__k6__
197
198 *cpp_686:
199 %{!ansi:-Di686 -Dpentiumpro} -D__i686 -D__i686__ -D__pentiumpro -D__pentiumpro__
200
201 *cpp_cpu_default:
202 %(cpp_586)
203
204 *cpp_cpu:
205 -Acpu(i386) -Amachine(i386) %{!ansi:-Di386} -D__i386 -D__i386__ %{mcpu=i486:%(cpp_486)} %{m486:%(cpp_486)} %{mpentium:%(cpp_586)} %{mcpu=pentium:%(cpp_586)} %{mpentiumpro:%(cpp_686)} %{mcpu=pentiumpro:%(cpp_686)} %{mcpu=k6:%(cpp_k6)} %{!mcpu*:%{!m486:%{!mpentium*:%(cpp_cpu_default)}}}
206
207 *cc1_cpu:
208 %{!mcpu*: %{m386:-mcpu=i386 -march=i386} %{m486:-mcpu=i486 -march=i486} %{mpentium:-mcpu=pentium} %{mpentiumpro:-mcpu=pentiumpro}}
209
210 *mingw_include_path:
211 i586-cygwin32
212
213 *link_command:
214 %{!fsyntax-only: %{!c:%{!M:%{!MM:%{!E:%{!S:%(linker) %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} %{r} %{s} %{t} %{u*} %{x} %{z} %{Z} %{!A:%{!nostdlib:%{!nostartfiles:%S}}} %{static:} %{L*} %D %o %{!nostdlib:%{!nodefaultlibs:%G %L %G}} %{!A:%{!nostdlib:%{!nostartfiles:%E}}} %{T*} 
215  }}}}}}
216
217 ================ cut here ================
218
219 2) Get the Mingw32 runtime sources from 
220    ftp://ftp.xraylith.wisc.edu/pub/khan/gnu-win32/mingw32/gcc-2.95.2/runtime-source-19991107.zip
221
222    Unpack it somewhere, say //g/src/mingw-runtime-19991107 .
223
224    Apply the following patches:
225
226    This makes the mingwm10.dll depend on the stuff that is needed
227    to build it.:
228
229 ================ cut here ================
230 diff -ru2 ./mingw/Makefile.in ../../src/mingw-runtime-19991107/mingw/Makefile.in
231 --- ./mingw/Makefile.in Sun Nov 07 12:19:22 1999
232 +++ ../../src/mingw-runtime-19991107/mingw/Makefile.in  Mon Nov 08 14:55:38 1999
233 @@ -138,5 +138,5 @@
234                      --base-file mingwthrd.base --output-exp mingwthrd.exp
235  
236 -$(THREAD_DLL_NAME) mingwthrd.def: $(DLL_OFILES) Makefile
237 +$(THREAD_DLL_NAME) mingwthrd.def: $(DLL_OFILES) Makefile libmingw32.a libmoldname.a lib$(RUNTIME).a dllcrt$(CRT_ID).o
238         $(DLLTOOL) --as $(AS) --output-def mingwthrd.def $(DLL_OFILES)
239         $(CC) -Wl,--base-file=mingwthrd.base $(DLL_CC_STUFF)
240 ================ cut here ================
241
242    This enables building the profiling gcrt2.o. I don't know how useful
243    it is, though, there doesn't seem to be any gprof command in cygwin.
244
245 ================ cut here ================
246 diff -ru2 ./mingw/profile/Makefile.in ../../src/mingw-runtime-19991107/mingw/profile/Makefile.in
247 --- ./mingw/profile/Makefile.in Sun Nov 07 12:18:56 1999
248 +++ ../../src/mingw-runtime-19991107/mingw/profile/Makefile.in  Mon Nov 08 12:12:12 1999
249 @@ -76,8 +76,8 @@
250  
251  gcrt1.o: gcrt0.c
252 -       $(CC) -U__MSVCRT__ -c -o $@ $(CPPFLAGS) $(CFLAGS) $?
253 +       $(CC) -U__MSVCRT__ -c -o $@ $(CPPFLAGS) $(ALL_CFLAGS) $?
254  
255  gcrt2.o: gcrt0.c
256 -       $(CC) -D__MSVCRT__ -c -o $@ $(CPPFLAGS) $(CFLAGS) $?
257 +       $(CC) -D__MSVCRT__ -c -o $@ $(CPPFLAGS) $(ALL_CFLAGS) $?
258  
259  Makefile: Makefile.in config.status configure
260 ================ cut here ================
261
262    This fixes a typo in wingdi.h:
263
264 ================ cut here ================
265 diff -ru2 ./w32api/include/wingdi.h ../../src/mingw-runtime-19991107/w32api/include/wingdi.h
266 --- ./w32api/include/wingdi.h   Thu Nov 04 03:42:40 1999
267 +++ ../../src/mingw-runtime-19991107/w32api/include/wingdi.h    Mon Nov 08 12:48:02 1999
268 @@ -304,5 +304,5 @@
269  #define FW_BOLD        700
270  #define FW_EXTRABOLD   800
271 -#define FW_ULTRABOLD   FW_EXTRABOOLD
272 +#define FW_ULTRABOLD   FW_EXTRABOLD
273  #define FW_HEAVY       900
274  #define FW_BLACK       FW_HEAVY
275
276 ================ cut here ================
277
278    fpos_t should be long long with MSVCRT.DLL:
279
280 ================ cut here ================
281 --- stdio.h~    Thu Aug 19 02:47:42 1999
282 +++ stdio.h     Mon Jan 17 21:58:20 2000
283 @@ -296,6 +296,11 @@
284   * it is fairly evident that the fpos_t type is a long (in CRTDLL.DLL).
285   * Perhaps an unsigned long? TODO?
286 + * In MSVCRT.DLL it's a long long, however.
287   */
288 +#ifdef __MSVCRT__
289 +typedef long long fpos_t;
290 +#else
291  typedef long   fpos_t;
292 +#endif
293  
294  int    fgetpos (FILE* fileGetPosition, fpos_t* pfpos);
295 ================ cut here ================
296
297
298    (I haven't checked yet if other small errors I have noticed in
299    previous w32api header versions have been corrected.)
300
301 3) Now you should build the mingw32 and w32api runtime and import libraries.
302
303    Go to //g/src/mingw-runtime-19991107/w32api. Enter:
304
305    CC='gcc -mno-cygwin' ./configure i586-pc-mingw32msvc
306    make
307
308    That should complete in a while. It should produce a lot of .a
309    libraries (both import libraries, and a couple of archive
310    libraries), and some .o files. I don't trust make install to do
311    what I want (especially as I didn't give any --prefix argument to
312    the configure...), so I install the stuff manually:
313
314    cd lib
315    mkdir //g/gcc-2.95.2/H-i586-cygwin32/lib/mingw32
316    cp *.a //g/gcc-2.95.2/H-i586-cygwin32/lib/mingw32
317    cd ../include
318    mkdir //g/gcc-2.95.2/H-i586-cygwin32/i586-cygwin32/include/mingw32
319    cp *.h //g/gcc-2.95.2/H-i586-cygwin32/i586-cygwin32/include/mingw32
320
321    Now go to ../../mingw, and run the same configure command, and do a
322    make:
323
324    CC='gcc -mno-cygwin' ./configure i586-pc-mingw32msvc
325    make
326
327    Then install the mingw32 libraries and headers:
328    cp *.a //g/gcc-2.95.2/H-i586-cygwin32/lib/mingw32
329    mkdir //g/gcc-2.95.2/H-i586-cygwin32/i586-cygwin32/include/mingw32/sys
330    cp include/sys/*.h //g/gcc-2.95.2/H-i586-cygwin32/i586-cygwin32/include/mingw32/sys
331    cp include/*.h //g/gcc-2.95.2/H-i586-cygwin32/i586-cygwin32/include/mingw32
332
333
334 4) Get an updated set of binutils for cygwin B20.1 from
335    ftp://ftp.xraylith.wisc.edu/pub/khan/gnu-win32/cygwin/gcc-2.95.2/binutils-2.9.4-cygb20.tar.gz
336    Unpack that in your /cygnus/cygwin-b20 directory.  The relevant
337    difference is: dlltool now parses GCC generated export directives
338    correctly for DATA items.
339    
340 5) Whew. That hopefully should be it.
341
342 Next, go back to the GLib directory and build using `make -f
343 makefile.cygwin`.  Building the dlls uses the script build-dll which
344 is somewhat of a hack. But I couldn't get things working in a cleaner
345 way.
346
347 --Tor Lillqvist <tml@iki.fi>