liblzma: Silence warnings in --enable-small build.
[xz.git] / windows / build.bash
blob5ae93a2eaa44481bc675f11b5c2b85e01329a670
1 #!/bin/bash
2 # SPDX-License-Identifier: 0BSD
4 ###############################################################################
6 # Build a binary package on Windows with MinGW and MSYS
8 # Set the paths where MinGW, Mingw-w32, or MinGW-w64 are installed. If both
9 # MinGW and MinGW-w32 are specified, MinGW-w32 will be used. If there is no
10 # 32-bit or 64-bit compiler at all, it is simply skipped.
12 # Optionally, 7-Zip is used to create the final .zip and .7z packages.
13 # If you have installed it in the default directory, this script should
14 # find it automatically. Otherwise adjust the path manually.
16 # If you want to use a cross-compiler e.g. on GNU/Linux, this script won't
17 # work out of the box. You need to omit "make check" commands and replace
18 # u2d with some other tool to convert newlines from LF to CR+LF. You will
19 # also need to pass the --host option to configure.
21 ###############################################################################
23 # Author: Lasse Collin
25 ###############################################################################
27 MINGW_DIR=/c/devel/tools/mingw
28 MINGW_W32_DIR=/c/devel/tools/mingw-w32
29 MINGW_W64_DIR=/c/devel/tools/mingw-w64
31 for SEVENZ_EXE in "$PROGRAMW6432/7-Zip/7z.exe" "$PROGRAMFILES/7-Zip/7z.exe" \
32 "/c/Program Files/7-Zip/7z.exe"
34 [ -x "$SEVENZ_EXE" ] && break
35 done
38 # Abort immediately if something goes wrong.
39 set -e
41 # White spaces in directory names may break things so catch them immediately.
42 case $(pwd) in
43 ' ' | ' ' | '
44 ') echo "Error: White space in the directory name" >&2; exit 1 ;;
45 esac
47 # This script can be run either at the top-level directory of the package
48 # or in the same directory containing this script.
49 if [ ! -f windows/build.bash ]; then
50 cd ..
51 if [ ! -f windows/build.bash ]; then
52 echo "You are in a wrong directory." >&2
53 exit 1
57 # Run configure and copy the binaries to the given directory.
59 # The first argument is the directory where to copy the binaries.
60 # The rest of the arguments are passed to configure.
61 buildit()
63 DESTDIR=$1
64 BUILD=$2
65 CFLAGS=$3
67 # Clean up if it was already configured.
68 [ -f Makefile ] && make distclean
70 # Build the size-optimized binaries. Providing size-optimized liblzma
71 # could be considered but I don't know if it should only use -Os or
72 # should it also use --enable-small and if it should support
73 # threading. So I don't include a size-optimized liblzma for now.
74 ./configure \
75 --prefix= \
76 --enable-silent-rules \
77 --disable-dependency-tracking \
78 --disable-nls \
79 --disable-scripts \
80 --disable-threads \
81 --disable-shared \
82 --enable-small \
83 --build="$BUILD" \
84 CFLAGS="$CFLAGS -Os"
85 make check
87 mkdir -pv "$DESTDIR"
88 cp -v src/xzdec/{xz,lzma}dec.exe src/lzmainfo/lzmainfo.exe "$DESTDIR"
90 make distclean
92 # Build the normal speed-optimized binaries. The type of threading
93 # (win95 vs. vista) will be autodetect from the target architecture.
94 ./configure \
95 --prefix= \
96 --enable-silent-rules \
97 --disable-dependency-tracking \
98 --disable-nls \
99 --disable-scripts \
100 --build="$BUILD" \
101 CFLAGS="$CFLAGS -O2"
102 make -C src/liblzma
103 make -C src/xz LDFLAGS=-static
104 make -C tests check
106 cp -v src/xz/xz.exe src/liblzma/.libs/liblzma.a "$DESTDIR"
107 cp -v src/liblzma/.libs/liblzma-*.dll "$DESTDIR/liblzma.dll"
109 strip -v "$DESTDIR/"*.{exe,dll}
110 strip -vg "$DESTDIR/"*.a
113 # Copy files and convert newlines from LF to CR+LF. Optionally add a suffix
114 # to the destination filename.
116 # The first argument is the destination directory. The second argument is
117 # the suffix to append to the filenames; use empty string if no extra suffix
118 # is wanted. The rest of the arguments are actual the filenames.
119 txtcp()
121 DESTDIR=$1
122 SUFFIX=$2
123 shift 2
124 for SRCFILE; do
125 DESTFILE="$DESTDIR/${SRCFILE##*/}$SUFFIX"
126 echo "Converting '$SRCFILE' -> '$DESTFILE'"
127 u2d < "$SRCFILE" > "$DESTFILE"
128 done
131 if [ -d "$MINGW_W32_DIR" ]; then
132 # 32-bit x86, Win2k or later, using MinGW-w32
133 PATH=$MINGW_W32_DIR/bin:$MINGW_W32_DIR/i686-w64-mingw32/bin:$PATH \
134 buildit \
135 pkg/bin_i686 \
136 i686-w64-mingw32 \
137 '-march=i686 -mtune=generic'
138 # 32-bit x86 with SSE2, Win2k or later, using MinGW-w32
139 PATH=$MINGW_W32_DIR/bin:$MINGW_W32_DIR/i686-w64-mingw32/bin:$PATH \
140 buildit \
141 pkg/bin_i686-sse2 \
142 i686-w64-mingw32 \
143 '-march=i686 -msse2 -mfpmath=sse -mtune=generic'
144 elif [ -d "$MINGW_DIR" ]; then
145 # 32-bit x86, Win2k or later, using MinGW
146 PATH=$MINGW_DIR/bin:$PATH \
147 buildit \
148 pkg/bin_i486 \
149 i486-pc-mingw32 \
150 '-march=i486 -mtune=generic'
153 if [ -d "$MINGW_W64_DIR" ]; then
154 # x86-64, Windows Vista or later, using MinGW-w64
155 PATH=$MINGW_W64_DIR/bin:$MINGW_W64_DIR/x86_64-w64-mingw32/bin:$PATH \
156 buildit \
157 pkg/bin_x86-64 \
158 x86_64-w64-mingw32 \
159 '-march=x86-64 -mtune=generic'
162 # Copy the headers, the .def file, and the docs.
163 # They are the same for all architectures and builds.
164 mkdir -pv pkg/{include/lzma,doc/{api,manuals,examples}}
165 txtcp pkg/include "" src/liblzma/api/lzma.h
166 txtcp pkg/include/lzma "" src/liblzma/api/lzma/*.h
167 txtcp pkg/doc "" src/liblzma/liblzma.def
168 txtcp pkg/doc .txt AUTHORS COPYING NEWS README THANKS TODO
169 txtcp pkg/doc "" doc/*.txt windows/README-Windows.txt
170 txtcp pkg/doc/manuals "" doc/man/txt/{xz,xzdec,lzmainfo}.txt
171 cp -v doc/man/pdf-*/{xz,xzdec,lzmainfo}-*.pdf pkg/doc/manuals
172 cp -v doc/api/* pkg/doc/api
173 txtcp pkg/doc/examples "" doc/examples/*
175 if [ -f windows/COPYING-Windows.txt ]; then
176 txtcp pkg/doc "" windows/COPYING-Windows.txt
179 # Create the package. This requires 7z.exe from 7-Zip. If it wasn't found,
180 # this step is skipped and you have to zip it yourself.
181 VER=$(sh build-aux/version.sh)
182 cd pkg
183 if [ -x "$SEVENZ_EXE" ]; then
184 "$SEVENZ_EXE" a -tzip ../xz-$VER-windows.zip *
185 "$SEVENZ_EXE" a ../xz-$VER-windows.7z *
186 else
187 echo
188 echo "NOTE: 7z.exe was not found. xz-$VER-windows.zip"
189 echo " and xz-$VER-windows.7z were not created."
190 echo " You can create them yourself from the pkg directory."
193 if [ ! -f ../windows/COPYING-Windows.txt ]; then
194 echo
195 echo "NOTE: windows/COPYING-Windows.txt doesn't exists."
196 echo " MinGW(-w64) runtime copyright information"
197 echo " is not included in the package."
200 echo
201 echo "Build completed successfully."
202 echo