2 <title>Porting Wine to new Platforms
</title>
4 This document provides a few tips on porting Wine to your
5 favorite (UNIX-based) operating system.
8 <sect1 id=
"wine-porting">
9 <title>Porting Wine to new Platforms
</title>
11 <title>Why
<symbol>#ifdef MyOS
</symbol> is probably a mistake.
</title>
14 Operating systems change. Maybe yours doesn't have the
15 <filename>foo.h
</filename> header, but maybe a future
16 version will have it. If you want to
<symbol>#include
17 <foo.h
></symbol>, it doesn't matter what operating
18 system you are using; it only matters whether
19 <filename>foo.h
</filename> is there.
22 Furthermore, operating systems change names or
"fork" into
23 several ones. An
<symbol>#ifdef MyOs
</symbol> will break
27 If you use the feature of
<command>autoconf
</command> -- the
28 Gnu auto-configuration utility -- wisely, you will help
29 future porters automatically because your changes will test
30 for
<emphasis>features
</emphasis>, not names of operating
31 systems. A feature can be many things:
37 existence of a header file
42 existence of a library function
47 existence of libraries
52 bugs in header files, library functions, the compiler, ...
57 You will need Gnu Autoconf, which you can get from your
58 friendly Gnu mirror. This program takes Wine's
59 <filename>configure.ac
</filename> file and produces a
60 <filename>configure
</filename> shell script that users use
61 to configure Wine to their system.
64 There
<emphasis>are
</emphasis> exceptions to the
"avoid
65 <symbol>#ifdef MyOS</symbol>" rule. Wine, for example, needs
66 the internals of the signal stack -- that cannot easily be
67 described in terms of features. Moreover, you can not use
68 <filename>autoconf
</filename>'s
<symbol>HAVE_*
</symbol>
69 symbols in Wine's headers, as these may be used by Winelib
70 users who may not be using a
<filename>configure
</filename>
74 Let's now turn to specific porting problems and how to solve
80 <title>MyOS doesn't have the
<filename>foo.h
</filename> header!
</title>
83 This first step is to make
<command>autoconf
</command> check
84 for this header. In
<filename>configure.in
</filename> you
85 add a segment like this in the section that checks for
86 header files (search for
"header files"):
89 AC_CHECK_HEADER(foo.h, AC_DEFINE(HAVE_FOO_H))
92 If your operating system supports a header file with the
93 same contents but a different name, say
94 <filename>bar.h
</filename>, add a check for that also.
100 #include
<foo.h
>
107 #include
<foo.h
>
108 #elif defined (HAVE_BAR_H)
109 #include
<bar.h
>
113 If your system doesn't have a corresponding header file even
114 though it has the library functions being used, you might
115 have to add an
<symbol>#else
</symbol> section to the
116 conditional. Avoid this if you can.
119 You will also need to add
<symbol>#undef HAVE_FOO_H
</symbol>
120 (etc.) to
<filename>include/config.h.in
</filename>
123 Finish up with
<command>make configure
</command> and
124 <command>./configure
</command>.
129 <title>MyOS doesn't have the
<function>bar
</function> function!
</title>
132 A typical example of this is the
133 <function>memmove
</function> function. To solve this
134 problem you would add
<function>memmove
</function> to the
135 list of functions that
<command>autoconf
</command> checks
136 for. In
<filename>configure.in
</filename> you search for
137 <function>AC_CHECK_FUNCS
</function> and add
138 <function>memmove
</function>. (You will notice that someone
139 already did this for this particular function.)
142 Secondly, you will also need to add
<symbol>#undef
144 <filename>include/config.h.in
</filename>
147 The next step depends on the nature of the missing function.
155 It's easy to write a complete implementation of the
156 function. (
<function>memmove
</function> belongs to
160 You add your implementation in
161 <filename>misc/port.c
</filename> surrounded by
162 <symbol>#ifndef HAVE_MEMMOVE
</symbol> and
163 <symbol>#endif
</symbol>.
166 You might have to add a prototype for your function.
167 If so,
<filename>include/miscemu.h
</filename> might be the place. Don't
168 forget to protect that definition by
<symbol>#ifndef
169 HAVE_MEMMOVE
</symbol> and
<symbol>#endif
</symbol> also!
177 A general implementation is hard, but Wine is only
178 using a special case.
181 An example is the various
<function>wait
</function>
182 calls used in
<function>SIGNAL_child
</function> from
183 <filename>loader/signal.c
</filename>. Here we have a
184 multi-branch case on features:
189 #elif defined (HAVE_THAT)
191 #elif defined (HAVE_SOMETHING_ELSE)
196 Note that this is very different from testing on
197 operating systems. If a new version of your operating
198 systems comes out and adds a new function, this code
199 will magically start using it.
205 Finish up with
<command>make configure
</command> and
206 <command>./configure
</command>.
214 <!-- Keep this comment at the end of the file
217 sgml-parent-document:("wine-devel.sgml" "set" "book" "part" "chapter" "")