]> wimlib.net Git - wimlib/blob - tools/make-windows-release
SHA-1 rework
[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         # Note: putting -static-libgcc in CC is a workaround for libtool
51         # stripping it:
52         # http://www.gnu.org/software/libtool/manual/libtool.html#Stripped-link-flags
53         #
54         # We also need to override the MinGW pkg-config with the "native" one in
55         # order for it to correctly restrict the include path to our $SYSROOT.
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=pkg-config                                   \
61                 PKG_CONFIG_LIBDIR="$SYSROOT/lib/pkgconfig"              \
62                 "$@"
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 sed -n '/^#/q; s/^[\/\* ]*//; p' src/divsufsort.c > $DESTDIR/COPYING.libdivsufsort-lite
83 if ! grep -q 'Copyright' $DESTDIR/COPYING.libdivsufsort-lite; then
84         echo "ERROR: failed to extract libdivsufsort-lite license text" 1>&2
85         exit 1
86 fi
87 (
88         cd $DESTDIR
89         for fil in NEWS README* COPYING*; do
90                 sed < $fil > ${fil}.txt -e 's/$/\r/g'
91                 rm $fil
92         done
93 )
94
95
96 # Install man pages
97
98 mkdir $DESTDIR/doc
99
100 function gen_pdf_from_man_page() {
101         local manbase=$1
102         local pdf=${DESTDIR}/doc/${manbase}.pdf
103
104         echo "Generating $pdf"
105
106         MANPATH="./doc" man -t $manbase | ps2pdf - $pdf
107 }
108
109 for fil in ./doc/man1/wim*.1; do
110         manbase=`basename $fil`
111         cmd=${manbase%.1}
112         case $cmd in
113         wimlib-imagex|wimmount|wimmountrw|wimunmount)
114                 continue
115                 ;;
116         esac
117
118         gen_pdf_from_man_page $cmd
119
120         sed 's/$/\r/g' > ${DESTDIR}/${cmd}.cmd <<- EOF
121                 @echo off
122                 "%~dp0\\wimlib-imagex" ${cmd#wim} %*
123         EOF
124         chmod +x ${DESTDIR}/${cmd}.cmd
125 done
126
127 gen_pdf_from_man_page wimlib-imagex
128
129 # Install development files
130
131 mkdir $DESTDIR/devel
132 cp .libs/libwim.dll.a $DESTDIR/devel/libwim.lib
133 cp include/wimlib.h $DESTDIR/devel/
134
135 # Generate ZIP file
136
137 rm -f $ZIPFILE
138 (
139         dir=$PWD
140         cd $DESTDIR
141         7z -mx9 a "$dir/$ZIPFILE" .
142 )