3 # This script prepares a Windows binary distribution of wimlib.
8 TOPDIR=$(dirname "$(dirname "$(realpath "$0")")")
9 cd "$TOPDIR" # Top-level directory of the git repo
11 # Global variables, read-only after parse_options has run
16 INSTALL_MSYS2_PACKAGES=false
17 MAKE="make -j$(getconf _NPROCESSORS_ONLN)"
20 VERSION=$(tools/get-version-number)
27 Usage: $SCRIPTNAME [OPTION]... [EXTRA_CONFIGURE_ARG]...
29 --arch=ARCH Specify the CPU architecture. This is unnecessary
32 --include-docs Build and install the PDF manual pages.
34 --install-msys2-packages Install the MSYS2 packages needed to build wimlib.
35 You can omit this if you have already done this for
36 the same MSYS2 environment.
38 --skip-configure Skip running the configure script again. You can
39 use this to save time in incremental builds if you
40 are sure you didn't change any options.
42 --zip Zip the output files up into a zip file.
48 if [ -z "$MSYSTEM" ]; then
54 CC_PKG=mingw-w64-i686-gcc
58 CC_PKG=mingw-w64-x86_64-gcc
62 CC_PKG=mingw-w64-clang-i686-clang
66 CC_PKG=mingw-w64-clang-x86_64-clang
70 CC_PKG=mingw-w64-clang-aarch64-clang
73 echo 1>&2 "Unsupported MSYS2 environment: $MSYSTEM. This script supports"
74 echo 1>&2 "MINGW32, MINGW64, CLANG32, CLANG64, and CLANGARM64."
75 echo 1>&2 "See https://www.msys2.org/docs/environments/"
82 longopts+=",include-docs"
83 longopts+=",install-msys2-packages"
84 longopts+=",skip-configure"
88 if ! options=$(getopt -o "" -l "$longopts" -- "$@"); then
92 eval set -- "$options"
106 --install-msys2-packages)
107 if [ -z "$MSYSTEM" ]; then
108 echo 1>&2 "--install-msys2-packages is not allowed outside MSYS2."
111 INSTALL_MSYS2_PACKAGES=true
124 echo 1>&2 "Invalid option '$1'"
135 echo 1>&2 "Unknown ARCH: $ARCH. Please specify a supported architecture with --arch"
139 DESTDIR=wimlib-${VERSION}-windows-${ARCH}-bin
141 EXTRA_CONFIGURE_ARGS=("$@")
144 install_msys2_packages()
146 echo "Installing the MSYS2 $MSYSTEM packages needed to build wimlib..."
147 pacman -Syu --noconfirm --needed \
155 echo "Done installing the MSYS2 $MSYSTEM packages needed to build wimlib."
158 bootstrap_repository()
160 echo "Bootstrapping the wimlib repository..."
166 echo "Configuring wimlib..."
167 local configure_args=("--host=${ARCH}-w64-mingw32")
168 configure_args+=("--disable-static")
169 # -static-libgcc is needed with gcc. It should go in the CFLAGS, but
170 # libtool strips it, so it must go directly in CC instead. See
171 # http://www.gnu.org/software/libtool/manual/libtool.html#Stripped-link-flags
172 if "${ARCH}-w64-mingw32-cc" --version | grep -q '(GCC)'; then
173 configure_args+=("CC=${ARCH}-w64-mingw32-cc -static-libgcc")
175 configure_args+=("${EXTRA_CONFIGURE_ARGS[@]}")
176 ./configure "${configure_args[@]}"
182 echo "Building wimlib..."
186 list_imagex_commands()
188 for cmd in ./doc/man1/wim*.1; do
192 wimlib-imagex|wimmount|wimmountrw|wimunmount)
203 echo "Installing binaries..."
204 cp .libs/*.{dll,exe} "$DESTDIR"
205 strip "$DESTDIR"/*.{dll,exe}
210 echo "Installing NEWS, README, and licenses..."
211 cp NEWS README* COPYING* "$DESTDIR"
212 sed -n '/^#/q; s/^[\/\* ]*//; p' src/divsufsort.c > "$DESTDIR"/COPYING.libdivsufsort-lite
213 if ! grep -q 'Copyright' "$DESTDIR"/COPYING.libdivsufsort-lite; then
214 echo 1>&2 "ERROR: failed to extract libdivsufsort-lite license text"
218 for fil in NEWS README* COPYING*; do
219 sed < "$fil" > "${fil}".txt -e 's/$/\r/g'
225 gen_pdf_from_man_page()
228 local pdf=${DESTDIR}/doc/${cmd}.pdf
230 echo "Generating $pdf"
231 MANPATH="./doc" man -t "$cmd" | ps2pdf - "$pdf"
236 echo "Installing PDF manual pages..."
238 for cmd in $(list_imagex_commands); do
239 gen_pdf_from_man_page "$cmd"
241 gen_pdf_from_man_page wimlib-imagex
244 install_cmd_aliases()
246 echo "Installing wim*.cmd files..."
247 for cmd in $(list_imagex_commands); do
248 sed 's/$/\r/g' > "${DESTDIR}/${cmd}.cmd" <<- EOF
250 "%~dp0\\wimlib-imagex" ${cmd#wim} %*
252 chmod +x "${DESTDIR}/${cmd}.cmd"
256 install_development_files()
258 echo "Installing development files..."
259 mkdir "$DESTDIR"/devel
260 cp .libs/libwim.dll.a "$DESTDIR"/devel/libwim.lib
261 cp include/wimlib.h "$DESTDIR"/devel/
266 echo "Creating zip file..."
268 7z -mx9 a ../"$ZIPFILE" . > /dev/null
273 rm -rf -- "$DESTDIR" "$ZIPFILE"
275 if $INSTALL_MSYS2_PACKAGES; then
276 install_msys2_packages
278 if [ ! -e configure ]; then
281 if [ ! -e config.log ] || ! $SKIP_CONFIGURE; then
287 if $INCLUDE_DOCS; then
291 install_development_files
294 echo "Success! Output is in $ZIPFILE"
296 echo "Success! Output is in $DESTDIR"