Many Windows programs may still be useful in Linux and so we may want to have a package for them. The differences between the two operating systems make this task a little complex. In this guideline we'll talk about Win32 binaries, since projects where source is available usually are ported to Linux.

Many Windows programs may still be useful in Linux and so we may want to have a package for them. The differences between the two operating systems make this task a little complex. In this guideline we'll talk about Win32 binaries, since projects where source is available usually are ported to Linux.

Revision as of 11:05, 6 January 2011

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.

Many Windows programs may still be useful in Linux and so we may want to have a package for them. The differences between the two operating systems make this task a little complex. In this guideline we'll talk about Win32 binaries, since projects where source is available usually are ported to Linux.

Things to check outright

Installer, is it possible to install the program silently? Even better, does an installer-less version exist?

Portability and cleanness, is the program portable? It is clean?

Here we mean a program is portable if it never writes in the registry or outside its directory; we mean a program is clean if it never writes in its directory, but it may write its settings in the user folder. A program can be also both (e.g., it never writes settings) or neither (e.g., it writes in its directory, it writes around, it writes in the registry...)

License

Usually licenses are in a text file in the install directory. If you can't find it, try following the screens during installation. If nothing is said about repackaging, go on. The author does not care. Otherwise the license usually does not allow removing files or does not allow repackaging at all. In the former case just be careful that the makepkg process does not lose any file, you may delete unneeded files (e.g., uninstallers) in the post_install() phase; in the latter case all the installing process must be done in the post_install() phase. The build() phase will only be for copying the install files.

Installer

It is much easier to work with compressed files like .zip than with Windows installers. If you have no choice, since the author insists on distributing its program with an installer, search the Internet for if it is possible to silently install the software. MSFN is usually a good place to search. If you can't find a way, try to open the installer with cabextract, unrar or other unpacking utilities; it may work.

Portability and cleanness

A portable program does not need its own wine emulated filesystem, so check in Portable Freeware if the program you are packaging is portable.

The guideline in short

The idea behind packaging a Windows program is to use the program's files as mere data that wine will interpret, just like JVM and java bytecode.

So we will install the program in /usr/share/"$pkgname" and the program will write all what it needs in "$HOME"/."$pkgname". Everything will be prepared by a small script saved in /usr/bin/"$pkgname" that will create the folder, prepare it if needed, and finally start the program.

In the next sections we will talk about every step.

This way every user will have their own settings and their decisions won't bother other users.

Installing

If the program has no installer, the installation is a mere decompression of a file; unpack it to "$pkgdir"/usr/share/$pkgname, making sure that the permissions are correct. These commands will do:

We have not discussed portability yet, but if your program does not need the registry keys it modified, you can just copy the directory from the:

"$srcdir"/tmp/env/drive_c/Program\ Files/programname

Otherwise you need to copy all the registry files too and eventually the files the program installed around. The "$srcdir"/tmp/local will contains menu icons and desktop files, you may want to copy them in the package. If there does not exist a way to install the program silently... Maybe you can make a .tar.gz file and upload it somewhere? If nothing automated is possible, force the user to follow the installer and hope he does not mess up the installation, write some checks before blindly copying a folder that may not exist (e.g., the user pressed 'Cancel'.)

The /usr/bin script

This script prepares the settings folder and starts the program. If your program is portable, it will look like this:

As you can see, in the second case there is no environment preparation. In fact a clean application will be started directly from /usr/share since it won't need to write in its folder, so its settings will be wrote somewhere in the emulated filesystem.

If the application is neither clean neither portable the two ideas must be combined.

If the application does not write settings at all, skip the if and start it from /usr/share.

The task of preparing the environment may differ greatly between applications, but follow these rules of thumb:

if the program...

...just needs to read a file, symlink it.

...needs to write in a file, copy it.

...does not use a file, ignore it.

Of course the minimum is just starting WINEDEBUG=-all wine /usr/share/programname "$@".

Usually the environment will be made by symlinking between the "$HOME"/.programname directory and the /usr/share/programname files. But since some Windows programs are very fickle about their paths, you may need to symlink directly in the "$HOME"/.programname/wine/drive_c/Program\ Files/programname directory.

Of course those are just ideas to integrate Win32 applications in the Linux environment, do not forget your intelligence and gumption.

As example, utorrent is by default a clean application, but with a easy step can be used as a portable one. Since it is a single file and it is pretty small creating its wine environment (about 5MB) it is probably an overkill. It is better to symlink the executable, create the empty settings.dat in order to use it portable in the $HOME/.utorrent directory. With the added advantage that just visiting .utorrent folder an user can see a copy of the .torrent files she downloaded.

One example

We will make a package for eMule. According to Portable Freeware, eMule is not completely portable since it writes some (useless) keys in the registry.

On the other hand, it is not clean either since it writes its configuration files and puts its downloads in its installation folder.

If you want to be more precise, you may add a message in the .install file telling the user that they should disable search history since wine messes up that menu. You may even provide a default config file with the best settings. And that's it... makepkg, check the pkg folder to be sure, and install.

Gecko

Gecko is a html engine used by Wine to render html for programs which normally use Explorer. Only few programs actually need this feature, but Wine will always ask to install Gecko if you did not.
To disable the dialogue you can: install Gecko, use a dlloverride.

The easiest way to install Gecko is using winetricks (from the package of the same name):

$ wineboot -u #(Click cancel when asked)
$ winetricks -q gecko

To disable html rendering and the dialogue you need to use a dlloverride in your script.