So what is needed to compile a Windows application with Winelib? Well, it really depends on the complexity of your application but here are some issues that are shared by all applications:
the case of your files may be bad. For example they could be in all caps: HELLO.C. It's not very nice to work with and probably not what you intended.
then the case of the filenames in your include statements may be wrong: maybe they include Windows.h instead of windows.h.
your include statements may use '\' instead of '/'. '\' is not recognized by Unix compilers while '/' is recognized in both environments.
you will need to perform the usual DOS to Unix text file conversion otherwise you'll get in trouble when the compiler considers that your '\' is not at the end of the line since it is followed by a pesky carriage return.
you will have to write new makefiles.
The best way to take care of all these issues is to use winemaker.
winemaker is a Perl script which is designed to help you bootstrap the conversion of your Windows projects to Winelib. In order to do this it will go analyze your code, fixing the issues listed above and generate straight Makefiles.
Let's suppose that you are already in the top directory of your sources. Then converting your project to Winelib may be as simple as just running the two commands below (note the dot indicating current directory at the end of the first command):
$ winemaker --lower-uppercase . $ make
But of course things are not always that simple which is why we have this guide at all.
Before starting to work on a big project you may want to try to port a small application. The notepad application from the Wine source tree suits well for testing purposes. It can be found in the programs subdirectory. notepad is a simple application, but has a few C, header and resource files.
Run make clean in the notepad source directory if it contains results of previous builds. Create a separate directory with name notepad2, so it won't conflict with the Wine copy of the application. Copy the sources of notepad (*.c, *.h, and *.rc files) to this directory. Now run the commands mentioned above from the notepad2 directory:
$ winemaker --lower-uppercase . $ make
Notice how it fails linking, because of undefined reference to
wnsprintfW. This is because we didn't specify the
libraries we need to link to. Normally you know which libraries you need
or you can find a list in your old Makefile or project file.
To fix that problem, open notepad2/Makefile.in
in a text editor and search for an assignment to a variable with
IMPORTS as part of its name. There will
be a list of import libraries. Now run winemaker again, but with
these libraries prefixed by
$ winemaker --lower-uppercase -icomdlg32 -ishell32 -ishlwapi -iuser32 -igdi32 -iadvapi32 . $ make
You are done! Now you can start the application as wine notepad2.exe.so or ./notepad2.exe.
If you come across problems preparing and building this application
this probably means that winemaker utility is broken by some changes
in Wine. Try asking for help on
Let's retrace the steps above in more details.
First you should try to get the sources together with the executables/libraries that they build. If you have no Visual C++ project files available winemaker having these around can help it guess what it is that your project is trying to build. Otherwise, it is able to understand Visual C++ projects. Usually the executables and libraries are in a Release or Debug subdirectory of the directory where the sources are. So it's best if you can transfer the source files and either of these directories to Linux. Note that you don't need to transfer the .obj, .pch, .sbr and other files that also reside in these directories; especially as they tend to be quite big.
Then go to the root directory where are your source files. winemaker can deal with a whole directory hierarchy at once so you don't need to go into a leaf directory, quite the contrary. winemaker will automatically generate makefiles in each directory where one is required, and will generate a global makefile so that you can rebuild all your executables and libraries with a single make command.
Then make sure you have write access to your sources. It may sound obvious, but if you copied your source files from a CD-ROM or if they are in Source Safe on Windows, chances are that they will be read-only. But winemaker needs write access so that it can fix them. You can arrange that by running "chmod -R u+w .". Also you will want to make sure that you have a backup copy of your sources in case something went horribly wrong, or more likely, just for reference at a later point. If you use a version control system you're already covered.
If you have already modified your source files and you want
to make sure that winemaker will not make further changes to
them then you can use the
--nosource-fix option to protect
Then you'll run winemaker.. Here are the options you will most likely want to use. For a complete list of options see the man page.
These options specify how to deal with files, and
directories, that have an 'incorrect' case.
--lower-uppercase specifies they should
only be renamed if their name is all uppercase. So files
that have a mixed case, like Hello.c would not be
--lower-all will rename any
file. If neither is specified then no file or directory
will be renamed, almost. As you will see
later winemaker may
still have to rename some files.
Winemaker normally makes a backup of all the files in which it does more than the standard DOS to Unix conversion. But if you already have (handy) copies of these files elsewhere you may not need these so you should use this option.
These options lets winemaker know what kind of target you are
building. If you have the windows library in your source
hierarchy then you should not need to specify
--dll. But if you have console executables
then you will need to use the corresponding option.
This option tells winemaker that you are building an MFC application/library.
-i specifies a Winelib library to
import via the spec file
mechanism. Contrast this with the
which specifies a Unix library to link with. The other
options work the same way they would with a C
compiler. All are applied to all the targets found.
When specifying a directory with either
will prefix a relative path with
$(TOPDIRECTORY)/ so that it is valid
from any of the source directories. You can also use a
variable in the path yourself if you wish (but don't
forget to escape the '$'). For instance you could specify
So your command may finally look like: winemaker --lower-uppercase -Imylib/include .
When you execute winemaker it will first rename files to bring their character case in line with your expectations and so that they can be processed by the makefiles. This later category implies that files with a non lowercase extension will be renamed so that the extension is in lowercase. So, for instance, HELLO.C will be renamed to HELLO.c. Also if a file or directory name contains a space or a dollar, then this character will be replaced with an underscore. This is because these characters cause problems with current versions of autoconf (2.13) and make (3.79).
winemaker will then proceed to modify the source files so that they will compile more readily with Winelib. As it does so it may print warnings when it has to make a guess or identifies a construct that it cannot correct. Finally it will generate the makefiles. Once all this is done you can review the changes that winemaker did to your files by using diff -uw. For instance: diff -uw hello.c.bak hello.c
This is a pretty simple step: just type make and voila, you should have all your executables and libraries. If this did not work out, then it means that you will have to read this guide further to: