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
12 if [ -z "$MSYSTEM" ]; then
18 CC_PKG=mingw-w64-i686-gcc
22 CC_PKG=mingw-w64-x86_64-gcc
26 CC_PKG=mingw-w64-clang-i686-clang
30 CC_PKG=mingw-w64-clang-x86_64-clang
34 CC_PKG=mingw-w64-clang-aarch64-clang
37 echo 1>&2 "Unsupported MSYS2 environment: $MSYSTEM. This script supports"
38 echo 1>&2 "MINGW32, MINGW64, CLANG32, CLANG64, and CLANGARM64."
39 echo 1>&2 "See https://www.msys2.org/docs/environments/"
44 INSTALL_MSYS2_PACKAGES=false
50 longopts+=",include-docs"
51 longopts+=",install-msys2-packages"
52 longopts+=",skip-configure"
58 Usage: $SCRIPTNAME [OPTION]... [EXTRA_CONFIGURE_ARG]...
60 --arch=ARCH Specify the CPU architecture. This is unnecessary
63 --include-docs Build and install the PDF manual pages.
65 --install-msys2-packages Install the MSYS2 packages needed to build wimlib.
66 You can omit this if you have already done this for
67 the same MSYS2 environment.
69 --skip-configure Skip running the configure script again. You can
70 use this to save time in incremental builds if you
71 are sure you didn't change any options.
73 --zip Zip the output files up into a zip file.
77 if ! options=$(getopt -o "" -l "$longopts" -- "$@"); then
81 eval set -- "$options"
95 --install-msys2-packages)
96 if [ -z "$MSYSTEM" ]; then
97 echo 1>&2 "--install-msys2-packages is not allowed outside MSYS2."
100 INSTALL_MSYS2_PACKAGES=true
113 echo 1>&2 "Invalid option '$1'"
121 EXTRA_CONFIGURE_ARGS=("$@")
127 echo 1>&2 "Unknown ARCH: $ARCH. Please specify a supported architecture with --arch"
132 VERSION=$(tools/get-version-number)
133 DESTDIR=wimlib-${VERSION}-windows-${ARCH}-bin
135 MAKE="make -j$(getconf _NPROCESSORS_ONLN)"
137 rm -rf "$DESTDIR" "$ZIPFILE"
140 # Install the required MSYS2 packages if requested.
141 if $INSTALL_MSYS2_PACKAGES; then
142 echo "Installing the MSYS2 $MSYSTEM packages needed to build wimlib..."
143 pacman -Syu --noconfirm --needed \
151 echo "Done installing the MSYS2 $MSYSTEM packages needed to build wimlib."
154 # Bootstrap the repository if not already done.
155 if [ ! -e configure ]; then
156 echo "Bootstrapping the wimlib repository..."
161 if ! [ -e config.log ] || ! $SKIP_CONFIGURE; then
162 echo "Configuring wimlib..."
163 configure_args=("--host=${ARCH}-w64-mingw32")
164 configure_args+=("--disable-static")
165 # -static-libgcc is needed with gcc. It should go in the CFLAGS, but
166 # libtool strips it, so it must go directly in CC instead. See
167 # http://www.gnu.org/software/libtool/manual/libtool.html#Stripped-link-flags
168 if "${ARCH}-w64-mingw32-cc" --version | grep -q '(GCC)'; then
169 configure_args+=("CC=${ARCH}-w64-mingw32-cc -static-libgcc")
171 configure_args+=("${EXTRA_CONFIGURE_ARGS[@]}")
172 ./configure "${configure_args[@]}"
176 echo "Building wimlib..."
179 echo "Installing binaries..."
180 cp .libs/*.{dll,exe} "$DESTDIR"
181 strip "$DESTDIR"/*.{dll,exe}
183 echo "Installing NEWS, README, and licenses..."
184 cp NEWS README* COPYING* "$DESTDIR"
185 sed -n '/^#/q; s/^[\/\* ]*//; p' src/divsufsort.c > "$DESTDIR"/COPYING.libdivsufsort-lite
186 if ! grep -q 'Copyright' "$DESTDIR"/COPYING.libdivsufsort-lite; then
187 echo 1>&2 "ERROR: failed to extract libdivsufsort-lite license text"
191 for fil in NEWS README* COPYING*; do
192 sed < "$fil" > "${fil}".txt -e 's/$/\r/g'
198 for cmd in ./doc/man1/wim*.1; do
202 wimlib-imagex|wimmount|wimmountrw|wimunmount)
205 IMAGEX_CMDS+=("$cmd")
210 function gen_pdf_from_man_page()
213 local pdf=${DESTDIR}/doc/${cmd}.pdf
215 echo "Generating $pdf"
216 MANPATH="./doc" man -t "$cmd" | ps2pdf - "$pdf"
219 if $INCLUDE_DOCS; then
220 echo "Installing manual pages..."
222 for cmd in "${IMAGEX_CMDS[@]}"; do
223 gen_pdf_from_man_page "$cmd"
225 gen_pdf_from_man_page wimlib-imagex
228 echo "Installing wim*.cmd files..."
229 for cmd in "${IMAGEX_CMDS[@]}"; do
230 sed 's/$/\r/g' > "${DESTDIR}/${cmd}.cmd" <<- EOF
232 "%~dp0\\wimlib-imagex" ${cmd#wim} %*
234 chmod +x "${DESTDIR}/${cmd}.cmd"
237 echo "Installing development files..."
238 mkdir "$DESTDIR"/devel
239 cp .libs/libwim.dll.a "$DESTDIR"/devel/libwim.lib
240 cp include/wimlib.h "$DESTDIR"/devel/
243 echo "Creating zip file..."
245 7z -mx9 a ../"$ZIPFILE" . > /dev/null
247 echo "Success! Output is in $ZIPFILE"
249 echo "Success! Output is in $DESTDIR"