]> icculus.org git repositories - icculus/xz.git/blob - windows/README
Some MSYS installations (e.g. MsysGit) don't include
[icculus/xz.git] / windows / README
1
2 XZ Utils on Windows
3 ===================
4
5 Introduction
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
14 Why 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
35 Getting 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
63 Building 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
76 Building 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
88 Additional 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     By default, liblzma is built as a DLL and the command line tools
103     linked dynamically against that liblzma.dll. To build static
104     versions instead, use STATIC=1:
105
106         mingw32-make STATIC=1
107
108     TODO: Static build is not implemented yet.
109
110     To copy the built binaries and required headers into a clean
111     directory, use the pkg target:
112
113         mingw32-make pkg
114
115     It first removes a possibly existing pkg directory, and then
116     recreates it with the required files.
117
118     TODO: The pkg target doesn't copy any license or other copyright
119     related information into the pkg directory.
120
121
122 Creating an Import Library for MSVC
123
124     The included Makefile creates import library liblzma.a which works
125     only(?) with MinGW. To use liblzma.dll for MSVC, you need to create
126     liblzma.lib using the lib command from MSVC:
127
128         lib /def:liblzma.def /out:liblzma.lib /machine:ix86
129
130     On x86-64, the /machine argument has to naturally be changed:
131
132         lib /def:liblzma.def /out:liblzma.lib /machine:x64
133
134
135 To Do
136
137     - Test Win64 support and add instructions about getting x86-64
138       version of MinGW.
139
140     - Static liblzma and statically linked command line tools
141
142     - Creating the import library for other compilers/linkers
143
144     - Building with other compilers for Windows
145
146     - liblzma currently uses cdecl. Would stdcall be more compatible?
147
148     - Support building more size-optimized liblzma (the HAVE_SMALL
149       define and other things that are needed)
150
151     - Support selecting which parts of liblzma to build to make the
152       library even smaller.
153
154     - Use the configure script on Windows just like it is used on all
155       the other systems?
156
157
158 Bugs
159
160     Report bugs to <lasse.collin@tukaani.org> (in English or Finnish).
161
162     Take into account that I don't have MSVC and I cannot very easily
163     test anything on Windows. As of writing, I have tried MinGW and the
164     resulting binaries only under 32-bit Wine.
165