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
23 echo 1>&2 "Unsupported MSYS2 environment: $MSYSTEM"
24 echo 1>&2 "In MSYS2, you must use the MINGW32 or MINGW64 environment."
25 echo 1>&2 "See https://www.msys2.org/docs/environments/"
29 INSTALL_MSYS2_PACKAGES=false
35 longopts+=",install-msys2-packages"
42 Usage: $SCRIPTNAME [OPTION]... [EXTRA_CONFIGURE_ARG]...
44 --arch=ARCH Specify the architecture. The default is taken
45 from MSYSTEM if available, otherwise is x86_64.
46 --install-msys2-packages Install prerequisite MSYS2 packages
47 --no-docs Don't build and install PDF manual pages
48 --no-zip Don't create the final zip file
52 if ! options=$(getopt -o "" -l "$longopts" -- "$@"); then
56 eval set -- "$options"
67 --install-msys2-packages)
68 if [ -z "$MSYSTEM" ]; then
69 echo 1>&2 "--install-msys2-packages is not allowed outside MSYS2."
72 INSTALL_MSYS2_PACKAGES=true
85 echo 1>&2 "Invalid option '$1'"
93 EXTRA_CONFIGURE_ARGS=("$@")
99 echo 1>&2 "Unknown ARCH: $ARCH. Please specify a supported architecture with --arch"
104 VERSION=$(tools/get-version-number)
105 DESTDIR=wimlib-${VERSION}-windows-${ARCH}-bin
107 MAKE="make -j$(getconf _NPROCESSORS_ONLN)"
109 rm -rf "$DESTDIR" "$ZIPFILE"
112 # Install the required MSYS2 packages if requested.
113 if $INSTALL_MSYS2_PACKAGES; then
114 echo "Installing the MSYS2 packages required to build wimlib ($MSYSTEM)..."
115 pacman -Syu --noconfirm --needed \
121 "mingw-w64-${ARCH}-gcc" \
123 echo "Done installing the MSYS2 packages required to build wimlib ($MSYSTEM)."
126 # Bootstrap the repository if not already done.
127 if [ ! -e configure ]; then
128 echo "Bootstrapping the wimlib repository..."
132 # Configure wimlib for the given $ARCH if not already done.
133 if ! [ -e config.log ] ||
134 ! grep -q "./configure --host=${ARCH}-w64-mingw32" config.log || \
135 ! grep -q "configure: exit 0" config.log || \
136 [ ${#EXTRA_CONFIGURE_ARGS[@]} -gt 0 ]
138 # Note: putting -static-libgcc in CC is a workaround for libtool
140 # http://www.gnu.org/software/libtool/manual/libtool.html#Stripped-link-flags
141 echo "Configuring wimlib..."
142 ./configure --host="${ARCH}-w64-mingw32" --disable-static \
143 CC="${ARCH}-w64-mingw32-gcc -static-libgcc" \
144 "${EXTRA_CONFIGURE_ARGS[@]}"
148 echo "Building wimlib..."
151 echo "Installing binaries..."
152 cp .libs/*.{dll,exe} "$DESTDIR"
153 strip "$DESTDIR"/*.{dll,exe}
155 echo "Installing NEWS, README, and licenses..."
156 cp NEWS README* COPYING* "$DESTDIR"
157 sed -n '/^#/q; s/^[\/\* ]*//; p' src/divsufsort.c > "$DESTDIR"/COPYING.libdivsufsort-lite
158 if ! grep -q 'Copyright' "$DESTDIR"/COPYING.libdivsufsort-lite; then
159 echo 1>&2 "ERROR: failed to extract libdivsufsort-lite license text"
163 for fil in NEWS README* COPYING*; do
164 sed < "$fil" > "${fil}".txt -e 's/$/\r/g'
169 function gen_pdf_from_man_page()
172 local pdf=${DESTDIR}/doc/${manbase}.pdf
174 echo "Generating $pdf"
175 MANPATH="./doc" man -t "$manbase" | ps2pdf - "$pdf"
178 echo "Installing manual pages..."
180 for fil in ./doc/man1/wim*.1; do
181 manbase=$(basename "$fil")
184 wimlib-imagex|wimmount|wimmountrw|wimunmount)
189 gen_pdf_from_man_page "$cmd"
191 gen_pdf_from_man_page wimlib-imagex
194 echo "Installing wimlib-imagex command shortcut files..."
195 for fil in ./doc/man1/wim*.1; do
196 manbase=$(basename "$fil")
198 sed 's/$/\r/g' > "${DESTDIR}/${cmd}.cmd" <<- EOF
200 "%~dp0\\wimlib-imagex" ${cmd#wim} %*
203 chmod +x "${DESTDIR}/${cmd}.cmd"
205 echo "Installing development files..."
206 mkdir "$DESTDIR"/devel
207 cp .libs/libwim.dll.a "$DESTDIR"/devel/libwim.lib
208 cp include/wimlib.h "$DESTDIR"/devel/
211 echo "Creating zip file..."
213 7z -mx9 a ../"$ZIPFILE" . > /dev/null
215 echo "Success! Output is in $ZIPFILE"
217 echo "Success! Output is in $DESTDIR"