b21551192a16778ec4f44a8c85ad745d00b89510
[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 [ $# -lt 1 ]; then
14         echo "Usage: $0 i686|x86_64 [EXTRA_CONFIGURE_ARG]..." 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         [ $# -gt 0 ]
49 then
50         extra_args=
51         if [ $ARCH = x86_64 ]; then
52                 extra_args="--enable-ssse3-sha1"
53         fi
54         # Note: putting -static-libgcc in CC is a workaround for libtool
55         # stripping it:
56         # http://www.gnu.org/software/libtool/manual/libtool.html#Stripped-link-flags
57         ./configure --host=${ARCH}-w64-mingw32 --disable-static         \
58                 CC="${ARCH}-w64-mingw32-gcc -static-libgcc"             \
59                 CPPFLAGS="-I$SYSROOT/include"                           \
60                 LDFLAGS="-L$SYSROOT/lib"                                \
61                 PKG_CONFIG_PATH="$SYSROOT/lib/pkgconfig"                \
62                 --without-libcrypto                                     \
63                 $extra_args "$@"
64         $MAKE clean
65 fi
66 $MAKE
67
68 # Create empty destination directory
69
70 rm -rf $DESTDIR
71 mkdir $DESTDIR
72
73 # Install binaries
74
75 cp .libs/*.{dll,exe} $DESTDIR
76 ${ARCH}-w64-mingw32-strip $DESTDIR/*.{dll,exe}
77
78 # Install text files
79
80 cp NEWS README* COPYING* $DESTDIR
81 cp $WINDEPDIR/COPYING* $DESTDIR
82
83 sed -n '/^#/q; s/^[\/\* ]*//; p' src/divsufsort.c > $DESTDIR/COPYING.libdivsufsort-lite
84 if ! grep -q 'Copyright' $DESTDIR/COPYING.libdivsufsort-lite; then
85         echo "ERROR: failed to extract libdivsufsort-lite license text" 1>&2
86         exit 1
87 fi
88 (
89         cd $DESTDIR
90         for fil in NEWS README* COPYING*; do
91                 sed < $fil > ${fil}.txt -e 's/$/\r/g'
92                 rm $fil
93         done
94 )
95
96
97 # Install man pages
98
99 mkdir $DESTDIR/doc
100
101 function gen_pdf_from_man_page() {
102         local manbase=$1
103         local pdf=${DESTDIR}/doc/${manbase}.pdf
104
105         echo "Generating $pdf"
106
107         MANPATH="./doc" man -t $manbase | ps2pdf - $pdf
108 }
109
110 for fil in ./doc/man1/wim*.1; do
111         manbase=`basename $fil`
112         cmd=${manbase%.1}
113         case $cmd in
114         wimlib-imagex|wimmount|wimmountrw|wimunmount)
115                 continue
116                 ;;
117         esac
118
119         gen_pdf_from_man_page $cmd
120
121         sed 's/$/\r/g' > ${DESTDIR}/${cmd}.cmd <<- EOF
122                 @echo off
123                 "%~dp0\\wimlib-imagex" ${cmd#wim} %*
124         EOF
125         chmod +x ${DESTDIR}/${cmd}.cmd
126 done
127
128 gen_pdf_from_man_page wimlib-imagex
129
130 # Install development files
131
132 mkdir $DESTDIR/devel
133 cp .libs/libwim.dll.a $DESTDIR/devel/libwim.lib
134 cp include/wimlib.h $DESTDIR/devel/
135
136 # Generate ZIP file
137
138 rm -f $ZIPFILE
139 (
140         dir=$PWD
141         cd $DESTDIR
142         7z -mx9 a "$dir/$ZIPFILE" .
143 )