Small typo...
[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 egcs-1.1.2 (as distributed by
14 Mumit Khan), running under cygwin-b20.1. To successfully use gcc,
15 follow the instructions below. I use gcc -mno-cygwin, i.e. the
16 produced executables (.exe and .dll files) do *not* require the cygwin
17 runtime library.
18
19 To test the GLib functions, go to the tests subdirectory and enter
20 `nmake -f makefile.msc check` or `make -f makefile.cygwin check`.
21
22 If you would want to use the cygwin tools to generate executables that
23 *do* use the cygwin runtime, the normal Unix configuration method
24 should work as if on Unix. But it won't produce DLLs. At least I
25 haven't succeeded in that.
26
27 With a little work, it might be possible to use the ./configure
28 mechanism also with a "mingw32" configuration.
29
30 The following preprocessor macros are used for conditional compilation 
31 related to Win32:
32
33 - WIN32 is defined when compiling for the Win32 platform, regardless
34   if using the X11 or Win32 windowing API (in the case of GLib, this
35   dimension isn't significant), regardless whether using a more or
36   less complete POSIX emulation runtime layer (like Cygwin) or not.
37
38 - NATIVE_WIN32 is defined when compiling for Win32, *and* without
39   any POSIX emulation, other that to the extent provided by the
40   bundled Microsoft C library (msvcrt.dll) and the pthreads-win32
41   library. For instance, pathnames are in the native Windows syntax.
42
43 The Win32 port uses the combination with both of those on.
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 (i.e. egcs)
48
49 Some of the usage of these macros was a bit mixed up, and had to be
50 straightened out when adding the gcc support. In particular, I used to
51 check for _MSC_VER in some places where I really wanted to check for
52 the Microsoft C library, and those checks has now been changed to
53 NATIVE_WIN32. NATIVE_WIN32 should maybe be renamed to USE_MSVCRT.
54
55 Pthreads library
56 ================
57
58 Before building you must get the pthreads library for Win32 from
59 http://sourceware.cygnus.com/pthreads-win32/. The pthreads-win32
60 snapshot from 1999-04-07 is the one that should be used. Edit the
61 location of the pthreads library and include files in makefile.msc or
62 makefile.cygwin. The ptreads distribution includes the precompiled dll
63 and import libraries both for MSVC and gcc.
64
65 The pthreads for Win32 package that the thread support uses supposedly
66 isn't quite ready yet, and thus threads stuff should not be relied
67 upon for anything serious.
68
69 Building with MSVC
70 ==================
71
72 If using the Microsoft toolchain, build with `nmake -f
73 makefile.msc`. Install with `nmake -f makefile.msc install`. 
74
75 Building with gcc
76 =================
77
78 The gcc support was added quite recently, but seems to work. Debugging
79 with gdb works. I prefer to use the msvcrt runtime and not the default
80 crtdll. Especially, as the pthread library also uses msvcrt, using
81 crtdll would probably not be a good idea at all. Using msvcrt can be
82 achieved by applying the following diff to the specs file, which
83 typically is installed as
84 C:/cygnus/cygwin-b20/H-i586-cygwin32/lib/gcc-lib/i586-cygwin32/egcs-2.91.66/specs.
85
86 Sorry for the illegibility of this diff, but the specs file is like
87 that... This diff replaces -lcrtdll with -lmsvcrt, replaces crt1 with
88 crt2, and defines __MSVCRT__.
89
90 --- specs.ORIG  Sun Apr 25 00:40:40 1999
91 +++ specs       Sun Apr 25 00:48:04 1999
92 @@ -23 +23 @@
93 -%{pg:-lgmon}                   %{!mno-cygwin:-lcygwin}                   %{mno-cygwin:-lmingw32 -lmoldname -lcrtdll}                   %{mwindows:-luser32 -lgdi32 -lcomdlg32}                   -lkernel32 -ladvapi32 -lshell32
94 +%{pg:-lgmon}                   %{!mno-cygwin:-lcygwin}                   %{mno-cygwin:-lmingw32 -lmoldname -lmsvcrt}                   %{mwindows:-luser32 -lgdi32 -lcomdlg32}                   -lkernel32 -ladvapi32 -lshell32
95 @@ -29 +29 @@
96 -%{mdll: %{!mno-cygwin:dllcrt0%O%s}                                 %{mno-cygwin:dllcrt1%O%s}}                         %{!mdll: %{!mno-cygwin:crt0%O%s}                                  %{mno-cygwin:crt1%O%s} %{pg:gcrt0%O%s}}
97 +%{mdll: %{!mno-cygwin:dllcrt0%O%s}                                 %{mno-cygwin:dllcrt2%O%s}}                         %{!mdll: %{!mno-cygwin:crt0%O%s}                                  %{mno-cygwin:crt2%O%s} %{pg:gcrt0%O%s}}
98 @@ -38 +38 @@
99 --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)
100 +-Di386 -D_WIN32 %{mno-cygwin:-D__MSVCRT__ } -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) 
101
102 You should also fix the definition of _dev_t in the header
103 mingw32/sys/types.h to correspond to what it actually is used by
104 msvcrt.dll. It should be unsigned int, not short. Otherwise stat()
105 calls will fail.
106
107 You also will have to get the mingw32 source snapshot from
108 http://www.geocities.com/Tokyo/Towers/6162/mingw32_980701_tar.gz (this
109 is the source to the "mingw32" part of what's included with Mumit
110 Khan's egcs-1.1.2. Unpack it and fix the prototype and call to
111 __getmainargs() in init.c to include one more parameter, an int *,
112 which should be passed the address of a zero int. Remake dllcrt2.o
113 (which is the file which gets linked into dlls when using msvcrt, as
114 per the specs file above). Code snippets below:
115
116 ...
117 #ifdef __MSVCRT__
118 extern void __getmainargs(int *, char***, char***, int, int *);
119 #else
120 ...
121 #ifdef __MSVCRT__
122         int newmode = 0;
123         (void) __getmainargs(&_argc, &_argv, &dummy_environ, _CRT_glob, &newmode);
124 #else
125 ...
126
127 Next, build using `make -f makefile.cygwin`.