* gpg.c (reopen_std): New function to reopen fd 0, 1, or 2 if we are
[gnupg.git] / scripts / mk-w32-dist
blob3f687cafdacaaed7d6cf2b16c344bf32d5ceb013
1 #!/bin/sh
3 # Copyright (C) 2000, 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
5 # This file is free software; as a special exception the author gives
6 # unlimited permission to copy and/or distribute it, with or without
7 # modifications, as long as this notice is preserved.
9 # This program is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
11 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 set -e
14 cd dist-w32
16 tmp="`echo $0 | sed 's,.*gnupg-\([^/]*\)/.*,\1,'`"
18 topdir=
19 bindir=..
21 if [ -f "../gnupg-$tmp/README" ]; then
22 srcdir="../gnupg-$tmp"
23 bindir="../gnupg-$tmp"
24 topdir=".."
25 elif [ -f ../README ]; then
26 srcdir=..
27 elif [ -f ../../README ]; then
28 srcdir=../..
29 bindir=..
30 elif [ -f ../../gnupg-stable/README ]; then
31 srcdir=../../gnupg-stable
32 elif [ -f ../../../gnupg-stable/README ]; then
33 srcdir=../../../gnupg-stable
34 else
35 echo "cannot figure out the source dir" >&2
36 exit 1
39 # Windows uses an internal build number. We use the last day of the
40 # year concatenated with the hour. for it. If it happens that a new
41 # release of the same version is to be made in the next year, the
42 # build number must be given manually by adding the appropriate number
43 # of days.
44 if [ "$1" = "--build-number" -a -n "$2" ]; then
45 build_number="$2"
46 shift
47 shift
48 else
49 build_number=$(date -u '+%j%k' | sed 's/^0*\(.*\)/\1/')
53 if i586-mingw32msvc-strip --version >/dev/null 2>&1 ; then
54 STRIP=i586-mingw32msvc-strip
55 else
56 STRIP="mingw32 strip"
59 # If we don't have an installer we don't need to prepare for it.
60 if ! makensis -version >/dev/null 2>&1 ; then
61 topdir=
65 # A function to return a plain ASCII (or Latin-1) encoded description
66 # text for a language identifier. We need this to display the list of
67 # available languages in the installer. NSIS does not support utf-8
68 # so we need to standardize on one character set. Note that this
69 # script itself is written in utf-8 but the resulting file will get
70 # converted to Latin-1
71 get_langname () {
72 case "$1" in
73 be) r="Belarusian"; ;;
74 ca) r="Català"; ;;
75 cs) r="Cesky"; ;;
76 da) r="Danish"; ;;
77 de) r="Deutsch"; ;;
78 el) r="Greek"; ;;
79 en|en@*) r="English"; ;;
80 eo) r="Esperanto"; ;;
81 es) r="Español"; ;;
82 et) r="Eesti keel"; ;;
83 fi) r="Suomi"; ;;
84 fr) r="Français"; ;;
85 gl) r="Galician"; ;;
86 hu) r="Magyar"; ;;
87 id) r="Indonesian"; ;;
88 it) r="Italiano"; ;;
89 ja) r="Japanese"; ;;
90 pl) r="Polski"; ;;
91 pt) r="Português"; ;;
92 pt_BR) r="Português (do Brasil)"; ;;
93 ro) r="Romana"; ;;
94 ru) r="Russian"; ;;
95 sk) r="Slovensky"; ;;
96 sv) r="Svenska"; ;;
97 tr) r="Türkçe"; ;;
98 zh_CN) r="Chinese (simplified)"; ;;
99 zh_TW) r="Chinese (traditional)"; ;;
101 *) r="" ;;
102 esac
103 echo "$r"
107 # Figure out the version
108 version=$(sed -n 's/^#[ ]*define[ ][ ]*VERSION[ ][ ]*\"\([0-9.a-z-]*\)\"/\1/p' $bindir/config.h)
109 prod_version=$(echo "$version"|awk -F'[^0-9]' '{print $1 "." $2 "." $3 }')
110 prod_version="${prod_version}.${build_number}"
111 echo "building version $version ($prod_version)"
113 rm * >/dev/null 2>/dev/null || true
115 cp ${bindir}/g10/gpg.exe gpg.exe
116 $STRIP gpg.exe
117 cp ${bindir}/g10/gpgv.exe gpgv.exe
118 $STRIP gpgv.exe
119 for name in hkp curl ldap finger; do
120 cp ${bindir}/keyserver/gpgkeys_$name.exe gpgkeys_$name.exe
121 $STRIP gpgkeys_$name.exe
122 done
123 cp ${bindir}/tools/gpgsplit.exe gpgsplit.exe
124 $STRIP gpgsplit.exe
126 for i in FAQ; do
127 cp ${bindir}/doc/$i $i.txt
128 todos $i.txt
129 done
130 man -Tlatin1 -l ${srcdir}/doc/gpg.1 | sed `printf "s/\b.//g"` >gpg.man
131 todos gpg.man
132 man -Tlatin1 -l ${srcdir}/doc/gpgv.1 | sed `printf "s/\b.//g"` >gpgv.man
133 todos gpgv.man
134 man -Tlatin1 -l ${srcdir}/doc/gnupg.7 | sed `printf "s/\b.//g"` >gnupg.man
135 todos gnupg.man
136 for i in README COPYING NEWS; do
137 cp ${srcdir}/$i $i.txt
138 todos $i.txt
139 done
141 cp ${srcdir}/doc/README.W32 README-W32.txt
142 todos README-W32.txt
144 patches_defs=
145 for i in `find "$topdir/patches" -type f -name '*.diff'`; do
146 cp $i .
147 patches_defs="-DWITH_PATCHES"
148 done
151 # We must distribute the MO files in UTF-8, the conversion is done by
152 # gpg at runtime. To include English at the right position in the list we
153 # need a special case.
154 langlist=""
155 langdesclist=""
156 for i in `(ls ${srcdir}/po/*.po; echo ${srcdir}/po/en.po) | sort`; do
157 lang=$(basename $i .po)
158 if [ $lang != "en" ]; then
159 grep -s $lang ${srcdir}/po/LINGUAS >/dev/null || continue
160 [ -f$lang.mo -a $lang.mo -nt $i ] && continue
162 fromset=`sed -n '/^"Content-Type:/ s/.*charset=\([a-zA-Z0-9_-]*\).*/\1/p' $i`
163 case "$fromset" in
164 utf8|utf-8|UTF8|UTF-8)
165 echo "$lang: keeping $fromset" >&2
166 msgfmt --output-file=$lang.mo $i
169 echo "$lang: converting from $fromset to utf-8" >&2
170 iconv --silent --from-code=$fromset --to-code=utf-8 < $i | \
171 sed "/^\"Content-Type:/ s/charset=[a-zA-Z0-9_-]*/charset=utf-8/"|\
172 msgfmt --output-file=$lang.mo -
174 esac
176 langlist="$langlist $lang"
177 langname="`get_langname $lang`"
178 [ -n "$langdesclist" ] && langdesclist="${langdesclist}|"
179 langdesclist="${langdesclist}${lang} - ${langname}"
180 done
183 # Create the option file for use with the NSIS installer.
184 cat <<EOF | iconv --silent --from-code=utf-8 --to-code=latin1 >opt.ini
185 [Settings]
186 NumFields=1
188 [Field 1]
189 Type=DropList
190 Left=0
191 Right=130
192 Top=20
193 Bottom=100
194 ListItems="$langdesclist"
198 # If we have a topdir, assume the full build environment and
199 # prepare the installer
200 if [ -n "$topdir" ]; then
201 winpt_defs=
202 src_defs=
203 buildinfo="`date -u '+%Y-%m-%d %H:%M UTC'`"
205 # iconv.dll is a hard requirement
206 if [ ! -f "$topdir/iconv/iconv.dll" ]; then
207 echo "iconv.dll not available" >&2
208 exit 1
210 ln "$topdir/iconv/iconv.dll" iconv.dll
211 for i in COPYING.LIB README.iconv; do
212 cp ${topdir}/iconv/$i $i.txt
213 todos $i.txt
214 done
216 # WinPT is optional
217 if [ -f "$topdir/winpt/WinPT.exe" ]; then
218 ln "$topdir/winpt/WinPT.exe" WinPT.exe
219 ln "$topdir/winpt/PTD.dll" PTD.dll
220 cp "$topdir/winpt/README-0.9.txt" README.winpt.txt
221 cp "$topdir/winpt/NEWS-0.9.txt" NEWS.winpt.txt
222 cp "$topdir/winpt/keyserver.conf" keyserver.conf
223 winpt_defs="-DWITH_WINPT"
226 # See whether we should include the source and figure out the
227 # version numbers of the source files.
228 if [ -d "$topdir/tarballs" ]; then
229 have_gnupg_src=no
230 have_libiconv_src=no
231 have_winpt_src=no
232 for i in `find "$topdir/tarballs" -type f -name '*.tar.gz'`; do
233 fname=$(basename "$i" .gz)
234 zcat "$i" > "$fname"
235 case "$fname" in
236 gnupg-*)
237 tmp=$(echo "$fname" | \
238 sed -n 's/^[^-]*-\([0-9.a-z-]*\)\.tar$/\1/p')
239 echo "gnupg source version is $tmp" >&2
240 if [ "$version" != "$tmp" ]; then
241 echo "gnupg source version does not match" >&2
242 exit 1
244 have_gnupg_src=yes
246 libiconv-*)
247 tmp=$(echo "$fname" | \
248 sed -n 's/^[^-]*-\([0-9.a-z-]*\)\.tar$/\1/p')
249 echo "libiconv source version is $tmp" >&2
250 src_defs="$src_defs -DLIBICONV_VERSION=$tmp"
251 have_libiconv_src=yes
253 winpt-*)
254 tmp=$(echo "$fname" | \
255 sed -n 's/^[^-]*-\([0-9.a-z-]*\)\.tar$/\1/p')
256 echo "winpt source version is $tmp" >&2
257 src_defs="$src_defs -DWINPT_VERSION=$tmp"
258 have_winpt_src=yes
262 echo "WARNING: unknown source file $fname ignored" >&2
264 esac
265 done
266 if [ -n "$src_defs" ]; then
267 if [ $have_gnupg_src = "no" ]; then
268 echo "gnupg source missing" >&2
269 exit 1
271 if [ $have_libiconv_src = "no" ]; then
272 echo "libiconv source missing" >&2
273 exit 1
275 if [ -n "$winpt_defs" ]; then
276 if [ $have_winpt_src = "no" ]; then
277 echo "winpt source missing" >&2
278 exit 1
282 src_defs="$src_defs -DWITH_SOURCE"
287 # Now run the installer
288 echo "invoking installer as:"
289 echo makensis -v0 -nocd -DVERSION="${version}" \
290 -DPROD_VERSION="${prod_version}" \
291 -DGNUPG_SRCDIR="${srcdir}" ${winpt_defs} ${src_defs} \
292 ${patches_defs} ${srcdir}/scripts/w32installer.nsi
293 BUILDINFO=$buildinfo makensis -v0 -nocd -DVERSION="${version}" \
294 -DPROD_VERSION="${prod_version}" \
295 -DGNUPG_SRCDIR="${srcdir}" ${winpt_defs} ${src_defs} \
296 ${patches_defs} ${srcdir}/scripts/w32installer.nsi
297 echo "Installer created" >&2
298 else
299 zip -9 "gnupg-w32cli-${version}.zip" *
300 echo "ZIP archive created" >&2