778562d4fb124855098b93b07faa136b7775fe5c
[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 operating system emulation layer
8 except that provided by the Microsoft runtime C library. Additionally,
9 a pthreads emulation 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, either as a mingw version (preferred), or
15 running under cygwin. To successfully use gcc, follow the instructions
16 below. We want to use gcc -mno-cygwin, i.e. produce executables (.exe
17 and .dll files) that do *not* require the cygwin runtime library. This
18 is called "mingw".
19
20 To test the GLib functions, go to the tests subdirectory and enter
21 `nmake -f makefile.msc check` or `make -f makefile.mingw 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.mingw. 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.mingw file. You should copy the
84 corresponding makefile.msc.in or makefile.mingw.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 You can either use gcc running on cygwin, or the "pure" mingw
103 gcc. Using the latter is much easier. Just fetch the latest version of
104 gcc for mingw and the msvcrt runtime, currently from
105 ftp://ftp.nanotech.wisc.edu/pub/khan/gnu-win32/mingw32/snapshots/gcc-2.95.2-1/
106 . Download the three zip archives: the gcc-<version>-msvcrt,
107 mingw-msvcrt-<timestamp> and binutils-<timestamp>-msvcrt, and unpack
108 them in a suitable directory. Set up your PATH so that the gcc from
109 the bin directory that got created above is the one that gets
110 used. You can skip steps 1--5 below. Even if you run the mingw gcc,
111 you still want to have cygwin to run make in.
112
113 If you want to run a cygwin-based gcc, it gets much more
114 complicated. We still want gcc to produce code that does not use
115 cygwin, but the msvcrt runtime. Read the below instruction carefully
116 and understand them. If you don't understand or can't follow the
117 instructions, you probably shouldn't want to build GLib (or GTk+ or
118 GIMP) yourself anyway.
119
120 0) Get and install Cygwin B20.1.
121
122    Move the include files and libraries included in Cygwin out of the
123    way not to mix things up... (For example, rename
124    /cygnus/cygwin-b20/H-i586-cygwin32/i586-cygwin32/lib to
125    lib-no-thanks and rename
126    /cygnus/cygwin-b20/H-i586-cygwin32/i586-cygwin32/include to
127    include-no-thanks.
128
129 1) Get gcc 2.95.2 built for Cygwin B20.1 from 
130    ftp://ftp.xraylith.wisc.edu/pub/khan/gnu-win32/cygwin/gcc-2.95.2/gcc-2.95.2-cygb20.tar.gz
131
132    Install it somewhere, let's say G:\gcc-2.95.2 (//g/gcc-2.95.2 when
133    in Cygwin). Add //g/gcc-2.95.2/H-i586-cygwin32/bin to your
134    PATH. I assume you use bash below.
135
136    Replace the specs file in
137    //g/gcc-2.95.2/H-i586-cygwin32/lib/gcc-lib/i586-cygwin32/2.95.2/specs
138    with the following. (The changes are: Define __MSVCRT__, replace
139    the "1" versions of the crt files with the "2" ones, replace crtdll
140    with msvcrt. Also, extra whitespace squished. )
141
142 ================ cut here ================
143 *asm:
144
145
146 *asm_final:
147
148
149 *cpp:
150 -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}
151
152 *cc1:
153 %(cc1_spec) 
154
155 *cc1plus:
156
157
158 *endfile:
159
160
161 *link:
162 %{mwindows:--subsystem windows} %{mconsole:--subsystem console} %{mdll:--dll -e _DllMainCRTStartup@12}
163
164 *lib:
165 %{pg:-lgmon} %{!mno-cygwin:-lcygwin} %{mno-cygwin:-lmingw32 -lmoldname -lmsvcrt} %{mwindows:-lgdi32 -lcomdlg32} -luser32 -lkernel32 -ladvapi32 -lshell32
166
167 *libgcc:
168 -lgcc
169
170 *startfile:
171 %{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}}}
172
173 *switches_need_spaces:
174
175
176 *signed_char:
177 %{funsigned-char:-D__CHAR_UNSIGNED__}
178
179 *predefines:
180 -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)
181
182 *cross_compile:
183 0
184
185 *version:
186 2.95.2
187
188 *multilib:
189 . !mno-cygwin;mingw32 mno-cygwin;;
190
191 *multilib_defaults:
192
193
194 *multilib_extra:
195
196
197 *multilib_matches:
198 mno-cygwin mno-cygwin;
199
200 *linker:
201 collect2
202
203 *cpp_486:
204 %{!ansi:-Di486} -D__i486 -D__i486__
205
206 *cpp_586:
207 %{!ansi:-Di586 -Dpentium} -D__i586 -D__i586__ -D__pentium -D__pentium__
208
209 *cpp_k6:
210 %{!ansi:-Di586 -Dk6} -D__i586 -D__i586__ -D__k6 -D__k6__
211
212 *cpp_686:
213 %{!ansi:-Di686 -Dpentiumpro} -D__i686 -D__i686__ -D__pentiumpro -D__pentiumpro__
214
215 *cpp_cpu_default:
216 %(cpp_586)
217
218 *cpp_cpu:
219 -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)}}}
220
221 *cc1_cpu:
222 %{!mcpu*: %{m386:-mcpu=i386 -march=i386} %{m486:-mcpu=i486 -march=i486} %{mpentium:-mcpu=pentium} %{mpentiumpro:-mcpu=pentiumpro}}
223
224 *mingw_include_path:
225 i586-cygwin32
226
227 *link_command:
228 %{!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*} 
229  }}}}}}
230
231 ================ cut here ================
232
233 2) Get the Mingw32 runtime sources from 
234    ftp://ftp.xraylith.wisc.edu/pub/khan/gnu-win32/mingw32/gcc-2.95.2/runtime-source-19991107.zip
235
236    Unpack it somewhere, say //g/src/mingw-runtime-19991107 .
237
238    Apply the following patches:
239
240    This makes the mingwm10.dll depend on the stuff that is needed
241    to build it.:
242
243 ================ cut here ================
244 diff -ru2 ./mingw/Makefile.in ../../src/mingw-runtime-19991107/mingw/Makefile.in
245 --- ./mingw/Makefile.in Sun Nov 07 12:19:22 1999
246 +++ ../../src/mingw-runtime-19991107/mingw/Makefile.in  Mon Nov 08 14:55:38 1999
247 @@ -138,5 +138,5 @@
248                      --base-file mingwthrd.base --output-exp mingwthrd.exp
249  
250 -$(THREAD_DLL_NAME) mingwthrd.def: $(DLL_OFILES) Makefile
251 +$(THREAD_DLL_NAME) mingwthrd.def: $(DLL_OFILES) Makefile libmingw32.a libmoldname.a lib$(RUNTIME).a dllcrt$(CRT_ID).o
252         $(DLLTOOL) --as $(AS) --output-def mingwthrd.def $(DLL_OFILES)
253         $(CC) -Wl,--base-file=mingwthrd.base $(DLL_CC_STUFF)
254 ================ cut here ================
255
256    This enables building the profiling gcrt2.o. I don't know how useful
257    it is, though, there doesn't seem to be any gprof command in cygwin.
258
259 ================ cut here ================
260 diff -ru2 ./mingw/profile/Makefile.in ../../src/mingw-runtime-19991107/mingw/profile/Makefile.in
261 --- ./mingw/profile/Makefile.in Sun Nov 07 12:18:56 1999
262 +++ ../../src/mingw-runtime-19991107/mingw/profile/Makefile.in  Mon Nov 08 12:12:12 1999
263 @@ -76,8 +76,8 @@
264  
265  gcrt1.o: gcrt0.c
266 -       $(CC) -U__MSVCRT__ -c -o $@ $(CPPFLAGS) $(CFLAGS) $?
267 +       $(CC) -U__MSVCRT__ -c -o $@ $(CPPFLAGS) $(ALL_CFLAGS) $?
268  
269  gcrt2.o: gcrt0.c
270 -       $(CC) -D__MSVCRT__ -c -o $@ $(CPPFLAGS) $(CFLAGS) $?
271 +       $(CC) -D__MSVCRT__ -c -o $@ $(CPPFLAGS) $(ALL_CFLAGS) $?
272  
273  Makefile: Makefile.in config.status configure
274 ================ cut here ================
275
276    This fixes a typo in wingdi.h:
277
278 ================ cut here ================
279 diff -ru2 ./w32api/include/wingdi.h ../../src/mingw-runtime-19991107/w32api/include/wingdi.h
280 --- ./w32api/include/wingdi.h   Thu Nov 04 03:42:40 1999
281 +++ ../../src/mingw-runtime-19991107/w32api/include/wingdi.h    Mon Nov 08 12:48:02 1999
282 @@ -304,5 +304,5 @@
283  #define FW_BOLD        700
284  #define FW_EXTRABOLD   800
285 -#define FW_ULTRABOLD   FW_EXTRABOOLD
286 +#define FW_ULTRABOLD   FW_EXTRABOLD
287  #define FW_HEAVY       900
288  #define FW_BLACK       FW_HEAVY
289
290 ================ cut here ================
291
292    fpos_t should be long long with MSVCRT.DLL:
293
294 ================ cut here ================
295 --- stdio.h~    Thu Aug 19 02:47:42 1999
296 +++ stdio.h     Mon Jan 17 21:58:20 2000
297 @@ -296,6 +296,11 @@
298   * it is fairly evident that the fpos_t type is a long (in CRTDLL.DLL).
299   * Perhaps an unsigned long? TODO?
300 + * In MSVCRT.DLL it's a long long, however.
301   */
302 +#ifdef __MSVCRT__
303 +typedef long long fpos_t;
304 +#else
305  typedef long   fpos_t;
306 +#endif
307  
308  int    fgetpos (FILE* fileGetPosition, fpos_t* pfpos);
309 ================ cut here ================
310
311
312    (I haven't checked yet if other small errors I have noticed in
313    previous w32api header versions have been corrected.)
314
315 3) Now you should build the mingw32 and w32api runtime and import libraries.
316
317    Go to //g/src/mingw-runtime-19991107/w32api. Enter:
318
319    CC='gcc -mno-cygwin' ./configure i586-pc-mingw32msvc
320    make
321
322    That should complete in a while. It should produce a lot of .a
323    libraries (both import libraries, and a couple of archive
324    libraries), and some .o files. I don't trust make install to do
325    what I want (especially as I didn't give any --prefix argument to
326    the configure...), so I install the stuff manually:
327
328    cd lib
329    mkdir //g/gcc-2.95.2/H-i586-cygwin32/lib/mingw32
330    cp *.a //g/gcc-2.95.2/H-i586-cygwin32/lib/mingw32
331    cp crt2.o crtdll2.o //g/gcc-2.95.2/H-i586-cygwin32/lib/mingw32
332    cd ../include
333    mkdir //g/gcc-2.95.2/H-i586-cygwin32/i586-cygwin32/include/mingw32
334    cp *.h //g/gcc-2.95.2/H-i586-cygwin32/i586-cygwin32/include/mingw32
335
336    Now go to ../../mingw, and run the same configure command, and do a
337    make:
338
339    CC='gcc -mno-cygwin' ./configure i586-pc-mingw32msvc
340    make
341
342    Then install the mingw32 libraries and headers:
343    cp *.a //g/gcc-2.95.2/H-i586-cygwin32/lib/mingw32
344    mkdir //g/gcc-2.95.2/H-i586-cygwin32/i586-cygwin32/include/mingw32/sys
345    cp include/sys/*.h //g/gcc-2.95.2/H-i586-cygwin32/i586-cygwin32/include/mingw32/sys
346    cp include/*.h //g/gcc-2.95.2/H-i586-cygwin32/i586-cygwin32/include/mingw32
347
348
349 4) Get an updated set of binutils for cygwin B20.1 from
350    ftp://ftp.xraylith.wisc.edu/pub/khan/gnu-win32/cygwin/gcc-2.95.2/binutils-2.9.4-cygb20.tar.gz
351    Unpack that in your /cygnus/cygwin-b20 directory.  The relevant
352    difference is: dlltool now parses GCC generated export directives
353    correctly for DATA items.
354    
355 5) Whew. That hopefully should be it.
356
357 Next, go back to the GLib directory and build using `make -f
358 makefile.mingw`. Building the dlls uses the script build-dll which
359 is somewhat of a hack. But I couldn't get things working in a cleaner
360 way.
361
362 --Tor Lillqvist <tml@iki.fi>