make-windows-release: Set VERSION correctly for betas
[wimlib] / make-windows-release
1 #!/bin/bash
2
3 set -e -u
4
5 WIMLIB_ARCH=i686
6 if [ $# -ge 1 ]; then
7         WIMLIB_ARCH=$1
8 fi
9
10 if [ $# -ge 2 ]; then
11         CONF_EXTRA_ARGS="$2"
12 else
13         CONF_EXTRA_ARGS=
14 fi
15
16 if [[ $WIMLIB_ARCH = i686 ]] ; then
17         DESTDIR=/mnt/tmp/wimlib
18 elif [[ $WIMLIB_ARCH = x86_64 ]]; then
19         DESTDIR=/mnt/tmp/x64/wimlib
20 else
21         echo "Unknown architecture $1" 1>&2
22         exit 2
23 fi
24
25 VERSION=$(grep 'This is wimlib version' README | \
26           grep -o '\<[0-9]\+\.[0-9]\+\.[0-9]\+\(-BETA\)\?\>')
27 ZIPFILE=wimlib-${VERSION}-windows-${WIMLIB_ARCH}-bin.zip
28
29 if ! grep -q "./configure --host=${WIMLIB_ARCH}-w64-mingw32" config.log; then
30         ./configure --host=${WIMLIB_ARCH}-w64-mingw32 $CONF_EXTRA_ARGS
31         make clean
32 fi
33
34 make -j2
35
36 rm -f $DESTDIR/{libwim-*.dll,doc/*,wim*.bat,wim*.cmd}
37
38 TEXTFILES=(NEWS README* COPYING*)
39
40 cp .libs/imagex.exe $DESTDIR/wimlib-imagex.exe
41 cp .libs/libwim-*.dll $DESTDIR
42 cp "${TEXTFILES[@]}" $DESTDIR
43
44 function genman() {
45         local name=$1
46         local dest=$DESTDIR/doc/${name}.pdf
47
48         echo "Generating $dest"
49
50         MANPATH="./doc" man -t $name | ps2pdf - $dest
51 }
52
53 for fil in ./doc/man1/wimlib-imagex-*.1; do
54         base=`basename $fil`
55         base=${base%%.1}
56         cmd=$(echo $base | sed s/wimlib-imagex-//)
57         if [ $cmd == mount -o $cmd == mountrw -o $cmd == unmount ]; then
58                 continue
59         fi
60
61         genman $base
62
63         sed 's/$/\r/g' > $DESTDIR/wim${cmd}.cmd <<- EOF
64                 @echo off
65                 %~dp0\\wimlib-imagex $cmd %*
66         EOF
67 done
68
69 genman wimlib-imagex
70
71 for fil in "${TEXTFILES[@]/#/$DESTDIR/}"; do
72         sed < $fil > ${fil}.txt -e 's/$/\r/g'
73         rm $fil
74 done
75
76 ${WIMLIB_ARCH}-w64-mingw32-strip $DESTDIR/*.{dll,exe}
77
78 rm -f $ZIPFILE
79 (
80         dir=$PWD
81         cd $DESTDIR
82         zip -r $dir/$ZIPFILE .
83 )