Build: Fix the detection of missing CRC32.
[xz/debian.git] / windows / build.bash
blobc5cf2b3124293d8b8f9e188916c0d02596d9baf5
1 #!/bin/bash
3 ###############################################################################
5 # Build a binary package on Windows with MinGW and MSYS
7 # Set the paths where MinGW, Mingw-w32, or MinGW-w64 are installed. If both
8 # MinGW and MinGW-w32 are specified, MinGW-w32 will be used. If there is no
9 # 32-bit or 64-bit compiler at all, it is simply skipped.
11 # Optionally, 7-Zip is used to create the final .zip and .7z packages.
12 # If you have installed it in the default directory, this script should
13 # find it automatically. Otherwise adjust the path manually.
15 # If you want to use a cross-compiler e.g. on GNU/Linux, this script won't
16 # work out of the box. You need to omit "make check" commands and replace
17 # u2d with some other tool to convert newlines from LF to CR+LF. You will
18 # also need to pass the --host option to configure.
20 ###############################################################################
22 # Author: Lasse Collin
24 # This file has been put into the public domain.
25 # You can do whatever you want with this file.
27 ###############################################################################
29 MINGW_DIR=/c/devel/tools/mingw
30 MINGW_W32_DIR=/c/devel/tools/mingw-w32
31 MINGW_W64_DIR=/c/devel/tools/mingw-w64
33 for SEVENZ_EXE in "$PROGRAMW6432/7-Zip/7z.exe" "$PROGRAMFILES/7-Zip/7z.exe" \
34 "/c/Program Files/7-Zip/7z.exe"
36 [ -x "$SEVENZ_EXE" ] && break
37 done
40 # Abort immediately if something goes wrong.
41 set -e
43 # White spaces in directory names may break things so catch them immediately.
44 case $(pwd) in
45 ' ' | ' ' | '
46 ') echo "Error: White space in the directory name" >&2; exit 1 ;;
47 esac
49 # This script can be run either at the top-level directory of the package
50 # or in the same directory containing this script.
51 if [ ! -f windows/build.bash ]; then
52 cd ..
53 if [ ! -f windows/build.bash ]; then
54 echo "You are in a wrong directory." >&2
55 exit 1
59 # Run configure and copy the binaries to the given directory.
61 # The first argument is the directory where to copy the binaries.
62 # The rest of the arguments are passed to configure.
63 buildit()
65 DESTDIR=$1
66 BUILD=$2
67 CFLAGS=$3
69 # Clean up if it was already configured.
70 [ -f Makefile ] && make distclean
72 # Build the size-optimized binaries. Note that I don't want to
73 # provide size-optimized liblzma (shared nor static), because
74 # that isn't thread-safe now, and depending on bunch of things,
75 # maybe it will never be on Windows (pthreads-win32 helps but
76 # static liblzma might bit a bit tricky with it).
77 ./configure \
78 --prefix= \
79 --disable-nls \
80 --disable-scripts \
81 --disable-threads \
82 --disable-shared \
83 --enable-small \
84 --build="$BUILD" \
85 CFLAGS="$CFLAGS -Os"
86 make check
88 mkdir -pv "$DESTDIR"
89 cp -v src/xzdec/{xz,lzma}dec.exe src/lzmainfo/lzmainfo.exe "$DESTDIR"
91 make distclean
93 # Build the normal speed-optimized binaries. Note that while
94 # --disable-threads has been documented to make some things
95 # thread-unsafe, it's not actually true with this combination
96 # of configure flags in XZ Utils 5.0.x. Things can (and probably
97 # will) change after 5.0.x, and this script will be updated too.
98 ./configure \
99 --prefix= \
100 --disable-nls \
101 --disable-scripts \
102 --disable-threads \
103 --build="$BUILD" \
104 CFLAGS="$CFLAGS -O2"
105 make -C src/liblzma
106 make -C src/xz LDFLAGS=-static
107 make -C tests check
109 cp -v src/xz/xz.exe src/liblzma/.libs/liblzma.a "$DESTDIR"
110 cp -v src/liblzma/.libs/liblzma-*.dll "$DESTDIR/liblzma.dll"
112 strip -v "$DESTDIR/"*.{exe,dll}
113 strip -vg "$DESTDIR/"*.a
116 # Copy files and convert newlines from LF to CR+LF. Optinally add a suffix
117 # to the destination filename.
119 # The first argument is the destination directory. The second argument is
120 # the suffix to append to the filenames; use empty string if no extra suffix
121 # is wanted. The rest of the arguments are actual the filenames.
122 txtcp()
124 DESTDIR=$1
125 SUFFIX=$2
126 shift 2
127 for SRCFILE; do
128 DESTFILE="$DESTDIR/${SRCFILE##*/}$SUFFIX"
129 echo "Converting \`$SRCFILE' -> \`$DESTFILE'"
130 u2d < "$SRCFILE" > "$DESTFILE"
131 done
134 # FIXME: Make sure that we don't get i686 or i586 code from the runtime.
135 # Actually i586 would be fine, but i686 probably not if the idea is to
136 # support even Win95.
138 # FIXME: Using i486 in the configure triplet may be wrong.
139 if [ -d "$MINGW_W32_DIR" ]; then
140 # 32-bit x86, Win95 or later, using MinGW-w32
141 PATH=$MINGW_W32_DIR/bin:$MINGW_W32_DIR/i686-w64-mingw32/bin:$PATH \
142 buildit \
143 pkg/bin_i486 \
144 i486-w64-mingw32 \
145 '-march=i486 -mtune=generic'
146 elif [ -d "$MINGW_DIR" ]; then
147 # 32-bit x86, Win95 or later, using MinGW
148 PATH=$MINGW_DIR/bin:$PATH \
149 buildit \
150 pkg/bin_i486 \
151 i486-pc-mingw32 \
152 '-march=i486 -mtune=generic'
155 if [ -d "$MINGW_W64_DIR" ]; then
156 # 64-bit x86, WinXP or later, using MinGW-w64
157 PATH=$MINGW_W64_DIR/bin:$MINGW_W64_DIR/x86_64-w64-mingw32/bin:$PATH \
158 buildit \
159 pkg/bin_x86-64 \
160 x86_64-w64-mingw32 \
161 '-march=x86-64 -mtune=generic'
164 # Copy the headers, the .def file, and the docs.
165 # They are the same for all architectures and builds.
166 mkdir -pv pkg/{include/lzma,doc/{manuals,examples}}
167 txtcp pkg/include "" src/liblzma/api/lzma.h
168 txtcp pkg/include/lzma "" src/liblzma/api/lzma/*.h
169 txtcp pkg/doc "" src/liblzma/liblzma.def
170 txtcp pkg/doc .txt AUTHORS COPYING NEWS README THANKS TODO
171 txtcp pkg/doc "" doc/*.txt windows/README-Windows.txt
172 txtcp pkg/doc/manuals "" doc/man/txt/{xz,xzdec,lzmainfo}.txt
173 cp -v doc/man/pdf-*/{xz,xzdec,lzmainfo}-*.pdf pkg/doc/manuals
174 txtcp pkg/doc/examples "" doc/examples/*
176 if [ -f windows/COPYING-Windows.txt ]; then
177 txtcp pkg/doc "" windows/COPYING-Windows.txt
180 # Create the package. This requires 7z.exe from 7-Zip. If it wasn't found,
181 # this step is skipped and you have to zip it yourself.
182 VER=$(sh build-aux/version.sh)
183 cd pkg
184 if [ -x "$SEVENZ_EXE" ]; then
185 "$SEVENZ_EXE" a -tzip ../xz-$VER-windows.zip *
186 "$SEVENZ_EXE" a ../xz-$VER-windows.7z *
187 else
188 echo
189 echo "NOTE: 7z.exe was not found. xz-$VER-windows.zip"
190 echo " and xz-$VER-windows.7z were not created."
191 echo " You can create them yourself from the pkg directory."
194 if [ ! -f ../windows/COPYING-Windows.txt ]; then
195 echo
196 echo "NOTE: windows/COPYING-Windows.txt doesn't exists."
197 echo " MinGW(-w64) runtime copyright information"
198 echo " is not included in the package."
201 echo
202 echo "Build completed successfully."
203 echo