1b80d31529eb72fda5ea713025ff17f2747b7fa4
[wimlib] / tools / make-windows-release
1 #!/bin/bash
2 #
3 # This script prepares a Windows binary distribution of wimlib on Linux using
4 # MinGW-w64.  The desired architecture must be passed as the first argument.
5
6 set -e
7
8 if [ ! -e src/wim.c ]; then
9         echo "This script must be run from the toplevel directory" 1>&2
10         exit 1
11 fi
12
13 if [ $# -ne 1 ]; then
14         echo "Usage: $0 i686|x86_64" 1>&2
15         exit 1
16 fi
17
18 ARCH="$1"
19 shift
20
21 case "$ARCH" in
22 i686|x86_64)
23         ;;
24 *)
25         echo "ERROR: ARCH must be i686 or x86_64" 1>&2
26         exit 1
27         ;;
28 esac
29
30 VERSION=$(grep 'AC_INIT' configure.ac | \
31           grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+[^]]*')
32 DESTDIR=wimlib-${VERSION}-windows-${ARCH}-bin
33 ZIPFILE=wimlib-${VERSION}-windows-${ARCH}-bin.zip
34 MAKE="make -j $(grep -c processor /proc/cpuinfo)"
35 WINDEPDIR=./tools/windeps
36 SYSROOT=$WINDEPDIR/sysroot_${ARCH}
37
38 # Prepare third party libraries
39
40 if [ ! -e $SYSROOT ]; then
41         $MAKE -C $WINDEPDIR sysroot_${ARCH}
42 fi
43
44 # Compile wimlib
45
46 if ! grep -q "./configure --host=${ARCH}-w64-mingw32" config.log || \
47         ! grep -q "configure: exit 0" config.log
48 then
49         extra_args=
50         if [ $ARCH = x86_64 ]; then
51                 extra_args="--enable-ssse3-sha1"
52         fi
53         # Note: putting -static-libgcc in CC is a workaround for libtool
54         # stripping it:
55         # http://www.gnu.org/software/libtool/manual/libtool.html#Stripped-link-flags
56         ./configure --host=${ARCH}-w64-mingw32 --disable-static         \
57                 CC="${ARCH}-w64-mingw32-gcc -static-libgcc"             \
58                 CPPFLAGS="-I$SYSROOT/include"                           \
59                 LDFLAGS="-L$SYSROOT/lib"                                \
60                 PKG_CONFIG_PATH="$SYSROOT/lib/pkgconfig"                \
61                 --without-libcrypto                                     \
62                 $extra_args
63         $MAKE clean
64 fi
65 $MAKE
66
67 # Create empty destination directory
68
69 rm -rf $DESTDIR
70 mkdir $DESTDIR
71
72 # Install binaries
73
74 cp .libs/*.{dll,exe} $DESTDIR
75 ${ARCH}-w64-mingw32-strip $DESTDIR/*.{dll,exe}
76
77 # Install text files
78
79 cp NEWS README* COPYING* $DESTDIR
80 cp $WINDEPDIR/COPYING* $DESTDIR
81 (
82         cd $DESTDIR
83         for fil in NEWS README* COPYING*; do
84                 sed < $fil > ${fil}.txt -e 's/$/\r/g'
85                 rm $fil
86         done
87 )
88
89
90 # Install man pages
91
92 mkdir $DESTDIR/doc
93
94 function gen_pdf_from_man_page() {
95         local manbase=$1
96         local pdf=${DESTDIR}/doc/${manbase}.pdf
97
98         echo "Generating $pdf"
99
100         MANPATH="./doc" man -t $manbase | ps2pdf - $pdf
101 }
102
103 for fil in ./doc/man1/wimlib-imagex-*.1; do
104         manbase=`basename $fil`
105         manbase=${manbase%%.1}
106         cmd=$(echo $manbase | sed s/wimlib-imagex-//)
107         if [ $cmd == mount -o $cmd == mountrw -o $cmd == unmount ]; then
108                 continue
109         fi
110
111         gen_pdf_from_man_page $manbase
112
113         sed 's/$/\r/g' > ${DESTDIR}/wim${cmd}.cmd <<- EOF
114                 @echo off
115                 "%~dp0\\wimlib-imagex" $cmd %*
116         EOF
117         chmod +x ${DESTDIR}/wim${cmd}.cmd
118 done
119
120 gen_pdf_from_man_page wimlib-imagex
121
122 # Generate ZIP file
123
124 rm -f $ZIPFILE
125 (
126         dir=$PWD
127         cd $DESTDIR
128         7z -mx9 a "$dir/$ZIPFILE" .
129 )