2 # SPDX-License-Identifier: 0BSD
4 ###############################################################################
6 # This build a XZ Utils binary package using the GNU Autotools build system
8 # NOTE: This requires files that are generated as part of "make mydist".
9 # So if building from xz.git, create a distribution tarball first,
10 # extract it, and run this script from there.
12 # These were tested and known to work:
13 # - Cross-compilation with MinGW-w64 v10.0.0 and GCC 12.2.0 from
14 # GNU/Linux ("make check" will be skipped)
15 # - MSYS2 with MinGW-w64 and GCC
16 # - MSYS 1.0.11 (from 2009) with MinGW-w64 v11.0.0 and GCC 13.1.0
18 # Optionally, 7-Zip is used to create the final .zip and .7z packages.
19 # If the 7z tool is in PATH or if you have installed it in the default
20 # directory on Windows, this script should find it automatically.
22 # Before running this script, copy COPYING.MinGW-w64-runtime.txt to
23 # the 'windows' directory.
25 # NOTE: MinGW-w64 includes getopt_long(). The GNU getopt_long() (LGPLv2.1)
26 # included in XZ Utils isn't used when building with MinGW-w64.
28 ###############################################################################
30 # Author: Lasse Collin
32 ###############################################################################
34 # Abort immediately if something goes wrong.
37 # White spaces in directory names may break things so catch them immediately.
40 ') echo "Error: White space in the directory name" >&2; exit 1 ;;
43 # This script can be run either at the top-level directory of the package
44 # or in the same directory containing this script.
45 if [ ! -f windows
/build.bash
]; then
47 if [ ! -f windows
/build.bash
]; then
48 echo "ERROR: You are in a wrong directory. This script" >&2
49 echo "can be run either at the top-level directory of" >&2
50 echo "the package or in the same directory containing" >&2
51 echo "this script." >&2
56 # COPYING.MinGW-w64-runtime.txt needs to be manually copied from MinGW-w64.
57 if [ ! -f windows
/COPYING.MinGW-w64-runtime.txt
]; then
58 echo "ERROR: The file 'windows/COPYING.MinGW-w64-runtime.txt'" >&2
59 echo "doesn't exists. Copy it from MinGW-w64 so that the" >&2
60 echo "copyright and license notices of the MinGW-w64 runtime" >&2
61 echo "can be included in the package." >&2
62 echo "(Or create an empty file if only doing a test build.)" >&2
66 # Number of jobs for "make":
67 MAKE_JOBS
=$
(nproc
2> /dev
/null ||
echo 1)
69 # "make check" has to be skipped when cross-compiling.
70 if [ "x$(uname -o)" = xMsys
]; then
76 # Run configure and copy the binaries to the given directory.
78 # The first argument is the directory where to copy the binaries.
79 # The rest of the arguments are passed to configure.
86 # In the MinGW-w64 + GCC toolchains running natively on Windows,
87 # $TRIPLET-windres and $TRIPLET-strip commands might not exist.
88 # Only the short names "windres" and "strip" might be available.
89 # If both i686 and x86_64 toolchains are in PATH, wrong windres.exe
90 # will be used for one of the builds, making the build fail. The
91 # workaround is to put the directory of $TRIPLET-gcc to the front
92 # of PATH if $TRIPLET-windres or $TRIPLET-strip is missing.
94 if type -P "$TRIPLET-windres" > /dev
/null \
95 && type -P "$TRIPLET-strip" > /dev
/null
; then
99 GCC_DIR
=$
(type -P "$TRIPLET-gcc")
100 PATH
=${GCC_DIR%/*}:$PATH
103 # Clean up if it was already configured.
104 [ -f Makefile
] && make distclean
106 # Build the size-optimized binaries. Providing size-optimized liblzma
107 # could be considered but I don't know if it should only use -Os or
108 # should it also use --enable-small and if it should support
109 # threading. So I don't include a size-optimized liblzma for now.
112 --enable-silent-rules \
113 --disable-dependency-tracking \
123 if "$IS_NATIVE_BUILD"; then
124 make -j"$MAKE_JOBS" check
128 cp -v src
/xzdec
/{xz
,lzma
}dec.exe src
/lzmainfo
/lzmainfo.exe
"$DESTDIR"
132 # Build the normal speed-optimized binaries. The type of threading
133 # (win95 vs. vista) will be autodetect from the target architecture.
136 --enable-silent-rules \
137 --disable-dependency-tracking \
142 make -j"$MAKE_JOBS" -C src
/liblzma
143 make -j"$MAKE_JOBS" -C src
/xz LDFLAGS
=-static
145 if "$IS_NATIVE_BUILD"; then
146 make -j"$MAKE_JOBS" -C tests check
149 cp -v src
/xz
/xz.exe
"$DESTDIR"
150 cp -v src
/liblzma
/.libs
/liblzma-5.dll
"$DESTDIR/liblzma.dll"
151 "$STRIP" -v "$DESTDIR/"*.
{exe
,dll
}
156 # Copy files and convert newlines from LF to CR+LF. Optionally add a suffix
157 # to the destination filename.
159 # The first argument is the destination directory. The second argument is
160 # the suffix to append to the filenames; use empty string if no extra suffix
161 # is wanted. The rest of the arguments are the actual filenames.
168 DESTFILE
="$DESTDIR/${SRCFILE##*/}$SUFFIX"
169 echo "Converting '$SRCFILE' -> '$DESTFILE'"
170 sed s
/\$
/$
'\r'/ < "$SRCFILE" > "$DESTFILE"
174 if type -P i686-w64-mingw32-gcc
> /dev
/null
; then
175 # 32-bit x86, Win2k or later
176 buildit pkg
/bin_i686 i686-w64-mingw32 \
177 '-march=i686 -mtune=generic'
179 # 32-bit x86 with SSE2, Win2k or later
180 buildit pkg
/bin_i686-sse2 i686-w64-mingw32 \
181 '-march=i686 -msse2 -mtune=generic'
184 echo "i686-w64-mingw32-gcc is not in PATH, skipping 32-bit x86 builds"
188 if type -P x86_64-w64-mingw32-gcc
> /dev
/null
; then
189 # x86-64, Windows Vista or later
190 buildit pkg
/bin_x86-64 x86_64-w64-mingw32 \
191 '-march=x86-64 -mtune=generic'
194 echo "x86_64-w64-mingw32-gcc is not in PATH, skipping x86-64 build"
198 # Copy the headers, the .def file, and the docs.
199 # They are the same for all architectures and builds.
200 mkdir
-pv pkg
/{include
/lzma
,doc
/{manuals
,examples
}}
201 txtcp pkg
/include
"" src
/liblzma
/api
/lzma.h
202 txtcp pkg
/include
/lzma
"" src
/liblzma
/api
/lzma
/*.h
203 txtcp pkg
/doc
"" src
/liblzma
/liblzma.def
204 txtcp pkg
/doc .txt AUTHORS COPYING COPYING
.0BSD NEWS README THANKS
205 txtcp pkg
/doc
"" doc
/*.txt \
206 windows
/README-Windows.txt \
207 windows
/liblzma-crt-mixing.txt \
208 windows
/COPYING.MinGW-w64-runtime.txt
209 txtcp pkg
/doc
/manuals
"" doc
/man
/txt
/{xz
,xzdec
,lzmainfo
}.txt
210 # cp -v doc/man/pdf-*/{xz,xzdec,lzmainfo}-*.pdf pkg/doc/manuals
211 # cp -rv doc/api pkg/doc/api
212 txtcp pkg
/doc
/examples
"" doc
/examples
/*
214 # Create the package. This requires 7z from 7-Zip.
215 # If it isn't found, this step is skipped.
216 for SEVENZ
in "$(type -P 7z || true)" \
217 "$PROGRAMW6432/7-Zip/7z.exe" "$PROGRAMFILES/7-Zip/7z.exe" \
218 "/c/Program Files/7-Zip/7z.exe"
220 [ -x "$SEVENZ" ] && break
223 if [ -x "$SEVENZ" ]; then
224 VER
=$
(sh build-aux
/version.sh
)
226 "$SEVENZ" a
-tzip ..
/xz-
$VER-windows.
zip *
227 "$SEVENZ" a ..
/xz-
$VER-windows.7z
*
230 echo "NOTE: 7z was not found. xz-$VER-windows.zip"
231 echo " and xz-$VER-windows.7z were not created."
232 echo " You can create them yourself from the pkg directory."
236 echo "Build completed successfully."