1 2XZ Utils on Windows 3=================== 4 5Introduction 6 7 This document explains how to build XZ Utils for Microsoft Windows 8 using MinGW (Minimalist GNU for Windows). 9 10 This is currently experimental and has got very little testing. 11 No ABI stability is promised for liblzma.dll. 12 13 14Why MinGW 15 16 XZ Utils code is C99. It should be possible to compile at least 17 liblzma using any C99 compiler. Compiling the command line tools may 18 need a little extra work to get them built on new systems, because 19 they use some features that aren't standardized in POSIX. 20 21 MinGW is free software. MinGW runtime provides some functions that 22 made porting the command line tools easier. Most(?) of the MinGW 23 runtime, which gets linked into the resulting binaries, is in the 24 public domain. 25 26 While most C compilers nowadays support C99 well enough (including 27 most compilers for Windows), MSVC doesn't. It seems that Microsoft 28 has no plans to ever support C99. Thus, it is not possible to build 29 XZ Utils using MSVC without doing a lot of work to convert the code. 30 Using prebuilt liblzma from MSVC is possible though, since the 31 liblzma API headers are in C89 and contain some non-standard extra 32 hacks required by MSVC. 33 34 35Getting and Installing MinGW 36 37 You can download MinGW for 32-bit Windows from Sourceforge: 38 39 http://sourceforge.net/project/showfiles.php?group_id=2435 40 41 It is enough to pick Automated MinGW Installer and MSYS Base System. 42 Using the automated installer, select at least runtime, w32api, 43 core compiler, and MinGW make. From MSYS you actually need only 44 certain tools, but it is easiest to just install the whole MSYS. 45 46 To build for x86-64 version of Windows, you can download a snapshot 47 of MinGW targeting for 64-bit Windows: 48 49 http://sourceforge.net/project/showfiles.php?group_id=202880 50 51 You can use the 32-bit MSYS also for 64-bit build, since we don't 52 link against anything in MSYS, just use the tools from it. You may 53 use the make tool from 32-bit MinGW (mingw32-make.exe) although 54 probably the make.exe from MSYS works too. 55 56 Naturally you can pick the components manually, for example to try 57 the latest available GCC. It is also possible to use a cross-compiler 58 to build Windows binaries for example on GNU/Linux, or use Wine to 59 run the Windows binaries. However, these instructions focus on 60 building on Windows. 61 62 63Building for 32-bit Windows 64 65 Add MinGW and MSYS to PATH (adjust if you installed to non-default 66 location): 67 68 set PATH=C:\MinGW\bin;C:\MSYS\1.0\bin;%PATH% 69 70 Then it should be enough to just run mingw32-make in this directory 71 (the directory containing this README): 72 73 mingw32-make 74 75 76Building for 64-bit Windows 77 78 For 64-bit build the PATH has to point to 64-bit MinGW: 79 80 set PATH=C:\MinGW64\bin;C:\MSYS\1.0\bin;%PATH% 81 82 You need to pass W64=1 to mingw32-make (or make if you don't have 83 mingw32-make): 84 85 mingw32-make W64=1 86 87 88Additional Make Flags and Targets 89 90 You may want to try some additional optimizations, which may or 91 may not make the code faster (and may or may not hit possible 92 compiler bugs more easily): 93 94 mingw32-make CFLAGS="-O3 -fomit-frame-pointer -funroll-loops" 95 96 If you want to enable assertions (the assert() macro), use DEBUG=1. 97 You may want to disable optimizations too if you plan to actually 98 debug the code. Never use DEBUG=1 for production builds! 99 100 mingw32-make DEBUG=1 CFLAGS="-g -O0" 101 102 To copy the built binaries and required headers into a clean 103 directory, use the pkg target: 104 105 mingw32-make pkg 106 107 It first removes a possibly existing pkg directory, and then 108 recreates it with the required files. 109 110 TODO: The pkg target doesn't copy any license or other copyright 111 related information into the pkg directory. 112 113 114Creating an Import Library for MSVC 115 116 The included Makefile creates import library liblzma.a which works 117 only(?) with MinGW. To use liblzma.dll for MSVC, you need to create 118 liblzma.lib using the lib command from MSVC: 119 120 lib /def:liblzma.def /out:liblzma.lib /machine:ix86 121 122 On x86-64, the /machine argument has to naturally be changed: 123 124 lib /def:liblzma.def /out:liblzma.lib /machine:x64 125 126 127To Do 128 129 - Test Win64 support and add instructions about getting x86-64 130 version of MinGW. 131 132 - Creating the import library for other compilers/linkers 133 134 - Building with other compilers for Windows 135 136 - liblzma currently uses cdecl. Would stdcall be more compatible? 137 138 - Support building more size-optimized liblzma (the HAVE_SMALL 139 define and other things that are needed) 140 141 - Support selecting which parts of liblzma to build to make the 142 library even smaller. 143 144 - Use the configure script on Windows just like it is used on all 145 the other systems? 146 147 148Bugs 149 150 Report bugs to <lasse.collin@tukaani.org> (in English or Finnish). 151 152 Take into account that I don't have MSVC and I cannot very easily 153 test anything on Windows. As of writing, I have tried MinGW and the 154 resulting binaries only under 32-bit Wine. 155 156