(Cross-)compiling TeX with MinGW

Open source tex versions

If you came to this page, then you probably know TeX as either the teTeX packages of your Linux distribution or as the multiplatform TeX Live CD.

TeTeX and TeX Live are developed in tandem, and have Web2c at their core. TeX Live also includes fpTeX for the Windows platform, which is built with Microsoft tools.

However, TeX developers working under Unix may appreciate the option to use the same GNU tools both for Windows and for Unix. Not necessarily to build a complete TeX environment; it may be enough to build specific programs which are to be used in an existing TeX setup.

MinGW

The MinGW compiler is a version of gcc which, other than CygWin, generates normal Windows executables, which use the Win32 dlls and don't require a Unix emulation layer. This makes porting to MinGW non-trivial.

However, for console programs the difficulties aren't that enormous, and much of the work was already been done by others: at one time, Han The Than, the author of pdf[e]tex, created Windows executables by cross-compiling with the MinGW compiler, and much of Fabrice Popineau's code for Win32/MSVC port can be adapted to the MinGW compiler.

MinGW can be built as a cross-compiler; see the MinGW FAQ. An alternative is to run a native version of MinGW under Windows. To this end, you need to either run MinGW from a CygWin environment or from MSYS (Minimal SYStem), which is a companion project to MinGW. MSYS provides enough of a Unix emulation layer and utilities for running Unix-style configure and make scripts. MSYS is not required for running MinGW-generated executables.

The patches

I based my patches on teTeX version 2.0.2 rather than TeX Live simply because that worked best for me. The Windows C sources though are taken from TeX Live 7, with very few changes. The Windows header files have been written from scratch. The Windows make files haven't been used at all. I offer my patches here for download as long as they have not been integrated into the official sources.

At patch time, Windows-specific sources are placed in a subdirectory of their own, where they can't interfere with a Unix build. The assumption is that compilation takes place in separate trees. For a MinGW compile, the Windows sources are added to the build tree at configure time.

Note that there is a slight twist to cross-compiling teTeX because the compilation process needs tools which it generated earlier. Naturally, this will fail when build platform and target platform differ. One solution is to create a native build first, and use the tools generated during the native build instead.

Successful builds

These include TeX, eTeX, pdf[e]TeX, MetaFont and MetaPost. Also utilities such as pltotf, kpsewhich, dvips and afm2tfm.

I did not try to build Omega and related programs, or the mktex... programs, or any kind of previewer. Additional patches to support some of these are welcome.

How to use the patches

  1. Unpack the teTeX sources and the patches in directories SOURCE and PATCHDIR of your choice.
  2. Edit PATCHDIR/bin/tetprep.mingw to reflect these choices.
  3. Run tetprep.mingw to patch the source tree.
  4. Unix:

    1. Install the MinGW cross-compiler if you have not already done so. See the MinGW site for some HOWTO's.
    2. Decide on build directories NATIVE and CROSS for a native build and a mingw build and create them.
    3. Edit PATCHDIR/tetexcfg.cross to reflect your choice of directories. Don't count on getting meaningful builtin TeX search paths, though.
    4. Go to NATIVE and run configure and make from there. It is better not to have any TeX-related environment variables during the configure step.
    5. Run tetexcfg.cross. You may get a warning that the main texmf tree wasn't found. Go to CROSS and run make. You should have i386-mingw-gcc etc. on your path. Make will fail eventually, but not before it has compiled [pdf][e]tex, MetaFont and MetaPost.
    6. Optional: try to compile additional components. You should be able to compile dvips by running make in texcross/texk/dvipsk.
    7. Installation has to be done manually: optionally run strip on the generated executables; give the generated executables a .exe extension and copy them to where you need them. Don't forget to copy the pool files to the texmf/web2c directory.

    Windows:

    1. Install the MinGW compiler, MSYS and mingwDTK (MinGW Developer ToolKit) if you have not already done so. In msys\1.0\msys.bat, you probably need to add lines such as
      set BISON_HAIRY=/d/MinGW/share/bison/bison.hairy
      set BISON_SIMPLE=/d/MinGW/share/bison/bison.simple
      
    2. Copy the patched source tree and the tetexcfg.win32 script to your Windows machine.
    3. Decide on a build tree BUILD and edit tetexcfg.win32. I tested with a file with DOS-style line endings.
    4. Start up MSYS and run tetexcfg.win32.
    5. Run make from the BUILD directory. Make will fail eventually, but not before it has compiled [pdf][e]tex, MetaFont and MetaPost.
    6. Optional: try to compile additional components.
    7. Installation has to be done manually: optionally run strip on the generated executables and copy them to where you need them. Don't forget to copy the pool files to the texmf/web2c directory.
  5. For file searching to work, you probably have to set the TEXMFCNF environment variable and possibly TEXMFMAIN. Also, check the contents of texmf\web2c\texmf.cnf.

Note. I am no expert in any of this. I just describe how I got things to work. There may be better ways.

Platform details

I originally used Debian Woody, which contains the gcc 2.95 toolchain. On the MinGW website, I picked gcc sources matching my system's gcc, and tried to match the other components date-wise as far as possible. This resulted in the following set:

At the moment, I run Debian Sarge/Unstable with gcc 3.2.3 and simply use current versions of everything:

Moving from gcc 2.95 to gcc 3.2 required no changes in the patches themselves, but did require one change in the configure script tetexcfg.cross, which is indicated in a comment.

On the Windows side, I run Windows NT4 under VMware. Versions:

An aside: although running inside a virtual machine means a performance hit, this is outweighed by the convenience of easy creation of a fresh machine simply by copying a directory. Theoretically, it would have been even more convenient to keep all files in Linux directories, making them available to the virtual machine via Samba. However, this had a very bad impact on performance. So for compilation I copy things back and forth, although I do test via (virtual) Samba shares; see below.

Testing

For testing the mingw executables I added a directory teTeX/bin/win32 to my regular teTeX installation and I put the generated executables in there. I made the entire teTeX tree available to Windows via a Samba share. In a Windows console window, I added this directory to the searchpath and defined an environment variable TEXMFCNF for the texmf/web2c directory of the teTeX tree (<drive letter>\...\web2c). This isn't exactly a fully functional TeX installation, but I was able to run the following tests:

Testing file searching:

kpsewhich cmr10.tfm

Creating a format file (somehow, the Linux format files don't work, which I find surprising and somewhat worrying):

pdfetex -ini latex.ltx

Using this format file:

pdfetex ^&latex test

If your testfile tries to use T1 encoding, you may have to do something first about ec fonts:

Generating a MetaFont format file:

mf --jobname=mf --ini "\input plain input modes dump"

Generating ecrm1000.mf:
Borrow mktexmf.exe, geturl.dll, kpathsea.dll, libmktex.dll and regex.dll from the TeX Live 7 cd and type

mktexmf ecrm1000

Generating ecrm1000.tfm:
Borrow mktextfm.exe from TeX Live 7 and type:

mktextfm ecrm1000

Last updated: May 5 2003
email