[tz] Building tzcode on Windows / MinGW

Ian Abbott abbotti at mev.co.uk
Mon Mar 14 17:50:48 UTC 2016


On 13/03/2016 07:27, Matt Johnson wrote:
> With the recent contributions to tzcode, I understand that building
> under MinGW should now be possible.  However, I've gone through all the
> docs I could find on various ways to set up an environment for this, and
> despite my best efforts and several hours of frustration, I could not
> get a successful build.
>
>
> It would be greatly appreciated if someone could either respond with a
> quick "how to", or post a blog or something explaining the minimal setup
> needed to make this work.  Which distribution do I download (MinGW,
> MinGW-w64), what environment do I need (cygwin, msys, bare windows),
> what minimal toolchain or cygwin packages, or msys packages, etc do I
> need?  Do I need "Win-builds"  (win-build.org)?

I can tell you what I used to build it.  I used the MSYS2 system as a 
base, as it seems to be in a better state of health than the older MSYS 
and MSYSGIT systems.  I'd never heard of "Win-builds" before you 
mentioned it.  There is another competing system called TDM-GCC that I 
haven't used, personally, but uses the same gcc executable to build both 
32-bit and 64-bit programs.

The package manager for MSYS2 includes a couple of toolchains from the 
MinGW-w64 project - one for i686, and one for x86_64. (I assume nobody 
cares about supporting i386, i486, and i586 any longer!).  Each of those 
toolchains includes a Windows shortcut to run bash in a terminal with 
slightly different PATH settings as compared to the standard MSYS2 
environment.

MSYS2 can be installed from <http://msys2.github.io/>.  There are 
versions for 32-bit and 64-bit systems.  Once installed, the pacman 
command can be used to install additional packages, such as "git", 
"man", "make", "mingw-w64-i686-toolchain", and 
"mingw-w64-x86_64-toolchain".  Some of those are "virtual" packages that 
just pull in a load of other packages via dependencies.

When the toolchains have been installed, then as well as the existing 
"MSYS2 Shell" shortcut in the start menu, there should be additional 
shortcuts "MinGW-w64 Win32 Shell" (for compiling native 32-bit stuff) 
and "MinGW-w64 Win64 Shell" (for compiling native 64-bit stuff).

I use the following command to compile tz under one of those MinGW-w64 
environments:

    make CFLAGS="-DHAVE_SYS_WAIT_H=0 -DHAVE_DIRECT_H=1 -DHAVE_SYMLINK=0 
-DHAVE_LINK=0 -DHAVE_DECL_ASCTIME_R=0 -DHAVE_LOCALTIME_R=0 
-DHAVE_DOS_FILE_NAMES"

In addition to setting CFLAGS on the make command line, you might want 
to set TZDIR to the place where the zoneinfo files will be read from by 
the zdump executable.  Using backslashes in the TZDIR pathname can be 
tricky due to the use of backslash as an escape character.  It's easier 
to stick with forward slashes, since the Windows API allows forward 
slash as a directory separator.

One thing I had a problem with was setting DESTDIR to an absolute path 
(or not setting it at all) during "make install", which caused zic to 
fail to create a directory.  I fixed that by adding 
"-DHAVE_DOS_FILE_NAMES" to CFLAGS above.

> Also, is compiling under Visual Studio possible?

Probably -- with a bit of hacking to the source code, especially to use 
its non-standard, 64-bit integer type names and corresponding 
printf/scanf format specifiers.

> At the end of the day, I want a zic.exe that I can run against a
> specific set of tzdata source files, and a zdump.exe I can run on the
> binary output of zic.  I'd like to be able to run both on
> Windows without having to have anything special on the machine at runtime.

-- 
-=( Ian Abbott @ MEV Ltd.    E-mail: <abbotti at mev.co.uk> )=-
-=(                          Web: http://www.mev.co.uk/  )=-



More information about the tz mailing list