]> wimlib.net Git - wimlib/blob - tools/make-windows-release
configure.ac: generate version number from git commit and tags
[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=$(tools/get-version-number)
31 DESTDIR=wimlib-${VERSION}-windows-${ARCH}-bin
32 ZIPFILE=wimlib-${VERSION}-windows-${ARCH}-bin.zip
33 MAKE="make -j $(grep -c processor /proc/cpuinfo)"
34 WINDEPDIR=./tools/windeps
35 SYSROOT=$WINDEPDIR/sysroot_${ARCH}
36
37 # Prepare third party libraries
38
39 if [ ! -e $SYSROOT ]; then
40         $MAKE -C $WINDEPDIR sysroot_${ARCH}
41 fi
42
43 # Compile wimlib
44
45 if ! [ -e config.log ] ||
46         ! 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         #
58         # We also need to override the MinGW pkg-config with the "native" one in
59         # order for it to correctly restrict the include path to our $SYSROOT.
60         ./configure --host=${ARCH}-w64-mingw32 --disable-static         \
61                 CC="${ARCH}-w64-mingw32-gcc -static-libgcc"             \
62                 CPPFLAGS="-I$SYSROOT/include"                           \
63                 LDFLAGS="-L$SYSROOT/lib"                                \
64                 PKG_CONFIG=pkg-config                                   \
65                 PKG_CONFIG_LIBDIR="$SYSROOT/lib/pkgconfig"              \
66                 --without-libcrypto                                     \
67                 $extra_args "$@"
68         $MAKE clean
69 fi
70 $MAKE
71
72 # Create empty destination directory
73
74 rm -rf $DESTDIR
75 mkdir $DESTDIR
76
77 # Install binaries
78
79 cp .libs/*.{dll,exe} $DESTDIR
80 ${ARCH}-w64-mingw32-strip $DESTDIR/*.{dll,exe}
81
82 # Install text files
83
84 cp NEWS README* COPYING* $DESTDIR
85 cp $WINDEPDIR/COPYING* $DESTDIR
86
87 sed -n '/^#/q; s/^[\/\* ]*//; p' src/divsufsort.c > $DESTDIR/COPYING.libdivsufsort-lite
88 if ! grep -q 'Copyright' $DESTDIR/COPYING.libdivsufsort-lite; then
89         echo "ERROR: failed to extract libdivsufsort-lite license text" 1>&2
90         exit 1
91 fi
92 (
93         cd $DESTDIR
94         for fil in NEWS README* COPYING*; do
95                 sed < $fil > ${fil}.txt -e 's/$/\r/g'
96                 rm $fil
97         done
98 )
99
100
101 # Install man pages
102
103 mkdir $DESTDIR/doc
104
105 function gen_pdf_from_man_page() {
106         local manbase=$1
107         local pdf=${DESTDIR}/doc/${manbase}.pdf
108
109         echo "Generating $pdf"
110
111         MANPATH="./doc" man -t $manbase | ps2pdf - $pdf
112 }
113
114 for fil in ./doc/man1/wim*.1; do
115         manbase=`basename $fil`
116         cmd=${manbase%.1}
117         case $cmd in
118         wimlib-imagex|wimmount|wimmountrw|wimunmount)
119                 continue
120                 ;;
121         esac
122
123         gen_pdf_from_man_page $cmd
124
125         sed 's/$/\r/g' > ${DESTDIR}/${cmd}.cmd <<- EOF
126                 @echo off
127                 "%~dp0\\wimlib-imagex" ${cmd#wim} %*
128         EOF
129         chmod +x ${DESTDIR}/${cmd}.cmd
130 done
131
132 gen_pdf_from_man_page wimlib-imagex
133
134 # Install development files
135
136 mkdir $DESTDIR/devel
137 cp .libs/libwim.dll.a $DESTDIR/devel/libwim.lib
138 cp include/wimlib.h $DESTDIR/devel/
139
140 # Generate ZIP file
141
142 rm -f $ZIPFILE
143 (
144         dir=$PWD
145         cd $DESTDIR
146         7z -mx9 a "$dir/$ZIPFILE" .
147 )