Using GNU Autotools with Cygnus Cygwin

It is possible to use the GNU Autotools to build software packages on Windows. Since the tools were developed on Unix, it is easier to get them to work using Cygnus Solutions' Cygwin distribution which provides a POSIX wrapper for the Win32 API, See the section called The Diversity of Unix Systems in the chapter called History, but it is certainly possible to run the tools within other Windows environments, notably Colin Peters' Mingw32 and D.J. Delorie's DJGPP. These development environments are freely available on the Internet [1] . Unlike Cygwin, these other environments are designed for developing with the Win32 API directly and consequently they are not as useful for porting Unix projects to Windows or writing code that works on both Windows and Unix, see the section called Unix/Windows Portability in the chapter called Writing Portable C with GNU Autotools for more details. This chapter describes the process of using GNU Autotools with Cygwin, although some of this advice also applies to employing some of the other GNU based Windows development environments.
 It is notable that the recent Cygwin ports of GCC and
binutils can produce binaries which will run
with the cygwin1.dll emulation layer, or linked
against CRTDLL.DLL, the Windows native
C
RunTime
Dynamic Link
Library depending on the needs of
particular source code.  Recent versions [2]  of the binutils implement
the PE-COFF binary format used by Windows, so by specifying the
-mno-cygwin compiler option to the Cygwin compiler
and using only the API from CRTDLL.DLL, you can
build binaries which are independent of the
cygwin1.dll DLL.  Such binaries will generally run
faster, since they bypass the POSIX emulation, and give easier access
to Windows specific things such as drive letters.  Source code designed
to be compiled this way will not compile on Unix however, since it will
be limited to the Win32 API provided by CRTDLL.DLL.

After reading this chapter, you will be able to install and use GNU Autotools natively under Windows using Cygnus Solutions' Cygwin environment, both to develop your own packages with the aid of Cygwin, and to compile, install, and to a certain degree port other peoples packages for use with Cygwin. As a Unix package developer, you will learn how to write your configury to be Windows friendly, and to be aware of certain quirks of Windows which can affect the portability of packages which need to work on Windows in addition to your Unix development machine.

Preliminaries

As explained in the section called Installing GNU Autotools on Cygwin, GNU Autotools requires several other tools to operate. Most Unices provide the majority, if not all, of these prerequisites by default. Windows, unfortunately, does not. Cygwin is better than most in this respect, and only a few extras are required. The latest net release of Cygwin [3] has a packaging mechanism which downloads and installs various Unix tools that have been precompiled for the Cygwin environment by the Cygnus folks. To develop with GNU Autotools and Cygwin, you need to install all of these packages to make sure you have all of the necessary header files and compiler tools.

Bourne shell

Cygwin provides a port of ash which is smaller and faster than bash, but sometimes rejects arcane Bourne shell scripts. If you can stand to sacrifice a little speed, it is worth copying the supplied bash.exe to /bin/sh.exe to forestall any such problems.

GNU M4

Cygwin provides a port of GNU M4.

GNU Make

At the time of writing, developers need GNU Make in order to do dependency tracking (see the chapter called Advanced GNU Automake Usage), though this is set to change in a future release of Automake. Cygwin version 1.1.1 comes with a port of GNU make-3.77, which I have personally never had any problems with. The received wisdom from users is to manually upgrade to the latest version, make-3.79 [4] , which compiles and installs from source without modification. Should you experience (or anticipate) any Make related problems, you might try upgrading to this version or later.

GNU GCC

At the time of writing, GNU GCC is also needed by Automake in order to do dependency tracking. Cygwin version 1.1.1 comes with a port of the latest GNU GCC compiler.

Perl

The current implementation of Automake (1.4) is written in perl4, though it is likely that perl5 will be needed for Automake 1.5. The very latest versions of Perl now compile out of the box on Cygwin [5] .

There are some other pitfalls to installing a fully working Cygwin environment on your Windows machine, but that is outside the scope of this chapter. Cygnus host a mailing list archive and an FAQ [6] to provide some level of support, and these should be your first port of call in case the installation does not go according to plan.

Notes

[1]

Mingw32 home page, @uref{http://www.geocities.com/Tokyo/Towers/6162/gcc.html}; and DJGPP home page, @uref{http://www.delorie.com/djgpp/}.

[2]

since Cygwin-b20.1, I believe.

[3]

1.1.1 at the time of writing.

[4]

@uref{ftp://ftp.gnu.org/gnu/make/make-3.79.tar.gz}

[5]

You can get a precompiled package from @uref{http://cygutils.netpedia.net/}, also an excellent resource for other packages ported to Cygwin.

[6]

@uref{http://sourceware.cygnus.com/cygwin/}