2010-07-27 17:45:03 +00:00
|
|
|
#!/bin/bash
|
2024-02-12 15:09:10 +00:00
|
|
|
# SPDX-License-Identifier: 0BSD
|
|
|
|
|
2010-01-31 21:28:51 +00:00
|
|
|
###############################################################################
|
|
|
|
#
|
2024-02-18 13:15:04 +00:00
|
|
|
# This build a XZ Utils binary package using the GNU Autotools build system
|
2010-01-31 21:28:51 +00:00
|
|
|
#
|
2024-02-18 13:15:04 +00:00
|
|
|
# NOTE: This requires files that are generated as part of "make mydist".
|
|
|
|
# So if building from xz.git, create a distribution tarball first,
|
|
|
|
# extract it, and run this script from there.
|
|
|
|
#
|
|
|
|
# These were tested and known to work:
|
|
|
|
# - Cross-compilation with MinGW-w64 v10.0.0 and GCC 12.2.0 from
|
|
|
|
# GNU/Linux ("make check" will be skipped)
|
|
|
|
# - MSYS2 with MinGW-w64 and GCC
|
|
|
|
# - MSYS 1.0.11 (from 2009) with MinGW-w64 v11.0.0 and GCC 13.1.0
|
2010-01-31 21:28:51 +00:00
|
|
|
#
|
|
|
|
# Optionally, 7-Zip is used to create the final .zip and .7z packages.
|
2024-02-18 13:15:04 +00:00
|
|
|
# If the 7z tool is in PATH or if you have installed it in the default
|
|
|
|
# directory on Windows, this script should find it automatically.
|
|
|
|
#
|
|
|
|
# Before running this script, copy COPYING.MinGW-w64-runtime.txt to
|
|
|
|
# the 'windows' directory.
|
2010-01-31 21:28:51 +00:00
|
|
|
#
|
2024-02-18 13:15:04 +00:00
|
|
|
# NOTE: MinGW-w64 includes getopt_long(). The GNU getopt_long() (LGPLv2.1)
|
|
|
|
# included in XZ Utils isn't used when building with MinGW-w64.
|
2010-01-31 21:28:51 +00:00
|
|
|
#
|
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# Author: Lasse Collin
|
|
|
|
#
|
|
|
|
###############################################################################
|
|
|
|
|
2010-02-12 11:16:15 +00:00
|
|
|
# Abort immediately if something goes wrong.
|
2010-01-31 21:28:51 +00:00
|
|
|
set -e
|
|
|
|
|
2010-02-12 11:16:15 +00:00
|
|
|
# White spaces in directory names may break things so catch them immediately.
|
2010-01-31 21:28:51 +00:00
|
|
|
case $(pwd) in
|
|
|
|
' ' | ' ' | '
|
|
|
|
') echo "Error: White space in the directory name" >&2; exit 1 ;;
|
|
|
|
esac
|
|
|
|
|
2010-02-01 20:47:54 +00:00
|
|
|
# This script can be run either at the top-level directory of the package
|
2010-01-31 21:28:51 +00:00
|
|
|
# or in the same directory containing this script.
|
2010-07-27 17:45:03 +00:00
|
|
|
if [ ! -f windows/build.bash ]; then
|
2010-01-31 21:28:51 +00:00
|
|
|
cd ..
|
2010-07-27 17:45:03 +00:00
|
|
|
if [ ! -f windows/build.bash ]; then
|
2024-02-18 13:15:04 +00:00
|
|
|
echo "ERROR: You are in a wrong directory. This script" >&2
|
|
|
|
echo "can be run either at the top-level directory of" >&2
|
|
|
|
echo "the package or in the same directory containing" >&2
|
|
|
|
echo "this script." >&2
|
2010-01-31 21:28:51 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2024-02-18 13:15:04 +00:00
|
|
|
# COPYING.MinGW-w64-runtime.txt needs to be manually copied from MinGW-w64.
|
|
|
|
if [ ! -f windows/COPYING.MinGW-w64-runtime.txt ]; then
|
|
|
|
echo "ERROR: The file 'windows/COPYING.MinGW-w64-runtime.txt'" >&2
|
|
|
|
echo "doesn't exists. Copy it from MinGW-w64 so that the" >&2
|
|
|
|
echo "copyright and license notices of the MinGW-w64 runtime" >&2
|
|
|
|
echo "can be included in the package." >&2
|
|
|
|
echo "(Or create an empty file if only doing a test build.)" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Number of jobs for "make":
|
|
|
|
MAKE_JOBS=$(nproc 2> /dev/null || echo 1)
|
|
|
|
|
|
|
|
# "make check" has to be skipped when cross-compiling.
|
|
|
|
if [ "x$(uname -o)" = xMsys ]; then
|
|
|
|
IS_NATIVE_BUILD=true
|
|
|
|
else
|
|
|
|
IS_NATIVE_BUILD=false
|
|
|
|
fi
|
|
|
|
|
2010-01-31 21:28:51 +00:00
|
|
|
# Run configure and copy the binaries to the given directory.
|
|
|
|
#
|
|
|
|
# The first argument is the directory where to copy the binaries.
|
|
|
|
# The rest of the arguments are passed to configure.
|
|
|
|
buildit()
|
|
|
|
{
|
|
|
|
DESTDIR=$1
|
2024-02-18 13:15:04 +00:00
|
|
|
TRIPLET=$2
|
2010-01-31 21:28:51 +00:00
|
|
|
CFLAGS=$3
|
|
|
|
|
2024-02-18 13:15:04 +00:00
|
|
|
# In the MinGW-w64 + GCC toolchains running natively on Windows,
|
|
|
|
# $TRIPLET-windres and $TRIPLET-strip commands might not exist.
|
|
|
|
# Only the short names "windres" and "strip" might be available.
|
|
|
|
# If both i686 and x86_64 toolchains are in PATH, wrong windres.exe
|
|
|
|
# will be used for one of the builds, making the build fail. The
|
|
|
|
# workaround is to put the directory of $TRIPLET-gcc to the front
|
|
|
|
# of PATH if $TRIPLET-windres or $TRIPLET-strip is missing.
|
|
|
|
OLD_PATH=$PATH
|
|
|
|
if type -P "$TRIPLET-windres" > /dev/null \
|
|
|
|
&& type -P "$TRIPLET-strip" > /dev/null; then
|
|
|
|
STRIP=$TRIPLET-strip
|
|
|
|
else
|
|
|
|
STRIP=strip
|
|
|
|
GCC_DIR=$(type -P "$TRIPLET-gcc")
|
|
|
|
PATH=${GCC_DIR%/*}:$PATH
|
|
|
|
fi
|
|
|
|
|
2010-01-31 21:28:51 +00:00
|
|
|
# Clean up if it was already configured.
|
|
|
|
[ -f Makefile ] && make distclean
|
|
|
|
|
2013-09-17 08:52:28 +00:00
|
|
|
# Build the size-optimized binaries. Providing size-optimized liblzma
|
|
|
|
# could be considered but I don't know if it should only use -Os or
|
|
|
|
# should it also use --enable-small and if it should support
|
|
|
|
# threading. So I don't include a size-optimized liblzma for now.
|
2010-01-31 21:28:51 +00:00
|
|
|
./configure \
|
|
|
|
--prefix= \
|
2014-12-20 18:41:48 +00:00
|
|
|
--enable-silent-rules \
|
|
|
|
--disable-dependency-tracking \
|
2010-01-31 21:28:51 +00:00
|
|
|
--disable-nls \
|
2011-09-06 09:03:41 +00:00
|
|
|
--disable-scripts \
|
2010-01-31 21:28:51 +00:00
|
|
|
--disable-threads \
|
|
|
|
--disable-shared \
|
|
|
|
--enable-small \
|
2024-02-18 13:15:04 +00:00
|
|
|
--host="$TRIPLET" \
|
2010-01-31 21:28:51 +00:00
|
|
|
CFLAGS="$CFLAGS -Os"
|
2024-02-18 13:15:04 +00:00
|
|
|
make -j"$MAKE_JOBS"
|
|
|
|
|
|
|
|
if "$IS_NATIVE_BUILD"; then
|
|
|
|
make -j"$MAKE_JOBS" check
|
|
|
|
fi
|
2010-01-31 21:28:51 +00:00
|
|
|
|
|
|
|
mkdir -pv "$DESTDIR"
|
|
|
|
cp -v src/xzdec/{xz,lzma}dec.exe src/lzmainfo/lzmainfo.exe "$DESTDIR"
|
|
|
|
|
|
|
|
make distclean
|
|
|
|
|
2014-12-20 18:41:48 +00:00
|
|
|
# Build the normal speed-optimized binaries. The type of threading
|
|
|
|
# (win95 vs. vista) will be autodetect from the target architecture.
|
2010-01-31 21:28:51 +00:00
|
|
|
./configure \
|
|
|
|
--prefix= \
|
2014-12-20 18:41:48 +00:00
|
|
|
--enable-silent-rules \
|
|
|
|
--disable-dependency-tracking \
|
2010-01-31 21:28:51 +00:00
|
|
|
--disable-nls \
|
2011-09-06 09:03:41 +00:00
|
|
|
--disable-scripts \
|
2024-02-18 13:15:04 +00:00
|
|
|
--host="$TRIPLET" \
|
2010-10-08 18:42:37 +00:00
|
|
|
CFLAGS="$CFLAGS -O2"
|
2024-02-18 13:15:04 +00:00
|
|
|
make -j"$MAKE_JOBS" -C src/liblzma
|
|
|
|
make -j"$MAKE_JOBS" -C src/xz LDFLAGS=-static
|
|
|
|
|
|
|
|
if "$IS_NATIVE_BUILD"; then
|
|
|
|
make -j"$MAKE_JOBS" -C tests check
|
|
|
|
fi
|
2010-01-31 21:28:51 +00:00
|
|
|
|
2024-02-18 13:15:04 +00:00
|
|
|
cp -v src/xz/xz.exe "$DESTDIR"
|
|
|
|
cp -v src/liblzma/.libs/liblzma-5.dll "$DESTDIR/liblzma.dll"
|
|
|
|
"$STRIP" -v "$DESTDIR/"*.{exe,dll}
|
2010-01-31 21:28:51 +00:00
|
|
|
|
2024-02-18 13:15:04 +00:00
|
|
|
PATH=$OLD_PATH
|
2010-01-31 21:28:51 +00:00
|
|
|
}
|
|
|
|
|
2019-05-08 05:30:57 +00:00
|
|
|
# Copy files and convert newlines from LF to CR+LF. Optionally add a suffix
|
2010-01-31 21:28:51 +00:00
|
|
|
# to the destination filename.
|
|
|
|
#
|
|
|
|
# The first argument is the destination directory. The second argument is
|
|
|
|
# the suffix to append to the filenames; use empty string if no extra suffix
|
2024-02-18 13:15:04 +00:00
|
|
|
# is wanted. The rest of the arguments are the actual filenames.
|
2010-01-31 21:28:51 +00:00
|
|
|
txtcp()
|
|
|
|
{
|
|
|
|
DESTDIR=$1
|
|
|
|
SUFFIX=$2
|
|
|
|
shift 2
|
|
|
|
for SRCFILE; do
|
|
|
|
DESTFILE="$DESTDIR/${SRCFILE##*/}$SUFFIX"
|
2023-09-24 14:09:16 +00:00
|
|
|
echo "Converting '$SRCFILE' -> '$DESTFILE'"
|
2024-02-18 13:15:04 +00:00
|
|
|
sed s/\$/$'\r'/ < "$SRCFILE" > "$DESTFILE"
|
2010-01-31 21:28:51 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2024-02-18 13:15:04 +00:00
|
|
|
if type -P i686-w64-mingw32-gcc > /dev/null; then
|
|
|
|
# 32-bit x86, Win2k or later
|
|
|
|
buildit pkg/bin_i686 i686-w64-mingw32 \
|
2014-12-20 18:41:48 +00:00
|
|
|
'-march=i686 -mtune=generic'
|
2024-02-18 13:15:04 +00:00
|
|
|
|
|
|
|
# 32-bit x86 with SSE2, Win2k or later
|
|
|
|
buildit pkg/bin_i686-sse2 i686-w64-mingw32 \
|
|
|
|
'-march=i686 -msse2 -mtune=generic'
|
|
|
|
else
|
|
|
|
echo
|
|
|
|
echo "i686-w64-mingw32-gcc is not in PATH, skipping 32-bit x86 builds"
|
|
|
|
echo
|
2010-01-31 21:28:51 +00:00
|
|
|
fi
|
|
|
|
|
2024-02-18 13:15:04 +00:00
|
|
|
if type -P x86_64-w64-mingw32-gcc > /dev/null; then
|
|
|
|
# x86-64, Windows Vista or later
|
|
|
|
buildit pkg/bin_x86-64 x86_64-w64-mingw32 \
|
2010-01-31 21:28:51 +00:00
|
|
|
'-march=x86-64 -mtune=generic'
|
2024-02-18 13:15:04 +00:00
|
|
|
else
|
|
|
|
echo
|
|
|
|
echo "x86_64-w64-mingw32-gcc is not in PATH, skipping x86-64 build"
|
|
|
|
echo
|
2010-01-31 21:28:51 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Copy the headers, the .def file, and the docs.
|
|
|
|
# They are the same for all architectures and builds.
|
2023-03-17 16:36:22 +00:00
|
|
|
mkdir -pv pkg/{include/lzma,doc/{api,manuals,examples}}
|
2010-01-31 21:28:51 +00:00
|
|
|
txtcp pkg/include "" src/liblzma/api/lzma.h
|
|
|
|
txtcp pkg/include/lzma "" src/liblzma/api/lzma/*.h
|
|
|
|
txtcp pkg/doc "" src/liblzma/liblzma.def
|
2024-02-19 16:41:37 +00:00
|
|
|
txtcp pkg/doc .txt AUTHORS COPYING COPYING.0BSD NEWS README THANKS
|
2024-02-18 15:59:46 +00:00
|
|
|
txtcp pkg/doc "" doc/*.txt \
|
|
|
|
windows/README-Windows.txt \
|
|
|
|
windows/liblzma-crt-mixing.txt \
|
|
|
|
windows/COPYING.MinGW-w64-runtime.txt
|
2010-01-31 21:28:51 +00:00
|
|
|
txtcp pkg/doc/manuals "" doc/man/txt/{xz,xzdec,lzmainfo}.txt
|
2024-04-19 10:54:39 +00:00
|
|
|
# cp -v doc/man/pdf-*/{xz,xzdec,lzmainfo}-*.pdf pkg/doc/manuals
|
2023-03-17 16:36:22 +00:00
|
|
|
cp -v doc/api/* pkg/doc/api
|
2010-10-26 12:48:48 +00:00
|
|
|
txtcp pkg/doc/examples "" doc/examples/*
|
2010-10-09 08:33:21 +00:00
|
|
|
|
2024-02-18 13:15:04 +00:00
|
|
|
# Create the package. This requires 7z from 7-Zip.
|
|
|
|
# If it isn't found, this step is skipped.
|
|
|
|
for SEVENZ in "$(type -P 7z || true)" \
|
|
|
|
"$PROGRAMW6432/7-Zip/7z.exe" "$PROGRAMFILES/7-Zip/7z.exe" \
|
|
|
|
"/c/Program Files/7-Zip/7z.exe"
|
|
|
|
do
|
|
|
|
[ -x "$SEVENZ" ] && break
|
|
|
|
done
|
2010-01-31 21:28:51 +00:00
|
|
|
|
2024-02-18 13:15:04 +00:00
|
|
|
if [ -x "$SEVENZ" ]; then
|
|
|
|
VER=$(sh build-aux/version.sh)
|
|
|
|
cd pkg
|
|
|
|
"$SEVENZ" a -tzip ../xz-$VER-windows.zip *
|
|
|
|
"$SEVENZ" a ../xz-$VER-windows.7z *
|
2010-01-31 21:28:51 +00:00
|
|
|
else
|
|
|
|
echo
|
2024-02-18 13:15:04 +00:00
|
|
|
echo "NOTE: 7z was not found. xz-$VER-windows.zip"
|
2010-01-31 21:28:51 +00:00
|
|
|
echo " and xz-$VER-windows.7z were not created."
|
|
|
|
echo " You can create them yourself from the pkg directory."
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo "Build completed successfully."
|
|
|
|
echo
|