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