Map fileno to _fileno for mingw32. Map fstat to _fstat.
[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 patch replaces -lcrtdll with -lmsvcrt, replaces crt1 with
88 crt2, removes -lmoldname (because that might pull in crtdll.dll), and
89 defines __MSVCRT__.
90
91 --- specs.ORIG  Sun Apr 25 00:40:40 1999
92 +++ specs       Sun Apr 25 00:48:04 1999
93 @@ -23 +23 @@
94 -%{pg:-lgmon}                   %{!mno-cygwin:-lcygwin}                   %{mno-cygwin:-lmingw32 -lmoldname -lcrtdll}                   %{mwindows:-luser32 -lgdi32 -lcomdlg32}                   -lkernel32 -ladvapi32 -lshell32
95 +%{pg:-lgmon}                   %{!mno-cygwin:-lcygwin}                   %{mno-cygwin:-lmingw32 -lmsvcrt}                   %{mwindows:-luser32 -lgdi32 -lcomdlg32}              -lkernel32 -ladvapi32 -lshell32
96 @@ -29 +29 @@
97 -%{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}}
98 +%{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}}
99 @@ -38 +38 @@
100 --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)
101 +-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) 
102
103 You should also fix the definition of _dev_t in the header
104 mingw32/sys/types.h to correspond to what it actually is used by
105 msvcrt.dll. It should be unsigned int, not short. Otherwise stat()
106 calls will fail.
107
108 You also will have to get the mingw32 source snapshot from
109 http://www.geocities.com/Tokyo/Towers/6162/mingw32_980701_tar.gz (this
110 is the source to the "mingw32" part of what's included with Mumit
111 Khan's egcs-1.1.2. Unpack it and fix the prototype and call to
112 __getmainargs() in init.c to include one more parameter, an int *,
113 which should be passed the address of a zero int. Remake dllcrt2.o
114 (which is the file which gets linked into dlls when using msvcrt, as
115 per the specs file above). Code snippets below:
116
117 ...
118 #ifdef __MSVCRT__
119 extern void __getmainargs(int *, char***, char***, int, int *);
120 #else
121 ...
122 #ifdef __MSVCRT__
123         int newmode = 0;
124         (void) __getmainargs(&_argc, &_argv, &dummy_environ, _CRT_glob, &newmode);
125 #else
126 ...
127
128 Next, build using `make -f makefile.cygwin`.