Fix a task number in NEWS
[gpg4win.git] / m4 / gpg4win.m4
1 dnl gpg4win.m4 - macros to configure gpg4win.
2 dnl Copyright (C) 2005, 2009 g10 Code GmbH
3 dnl
4 dnl This file is part of GPG4Win.
5 dnl
6 dnl GPG4Win is free software; you can redistribute it and/or modify
7 dnl it under the terms of the GNU General Public License as published by
8 dnl the Free Software Foundation; either version 2 of the License, or
9 dnl (at your option) any later version.
10 dnl
11 dnl GPG4Win is distributed in the hope that it will be useful,
12 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
13 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 dnl GNU General Public License for more details.
15 dnl
16 dnl You should have received a copy of the GNU General Public License
17 dnl along with this program; if not, write to the Free Software
18 dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 dnl MA 02110-1301, USA
20
21
22 # GPG4WIN_DEFINE SYMBOL
23 # A poor man's version of AC_DEFINE_UNQUOTED for NSIS.
24 AC_DEFUN([GPG4WIN_DEFINE],
25 [
26   eval $1=\"\!define $1 1\"
27   AC_SUBST($1)
28 ])
29
30
31 # GPG4WIN_BASH
32 # Gpg4Win needs bash.  This macro checks for it.
33 AC_DEFUN([GPG4WIN_BASH],
34 [
35   AC_MSG_CHECKING([for Bash])
36   _bash=$BASH_VERSION
37   if test -z "$_bash"; then
38     _bash=no
39   fi
40   AC_MSG_RESULT($_bash)
41   if test $_bash = no; then
42     AC_MSG_ERROR("this configure script requires Bash")
43   fi
44 ])
45
46
47 # GPG4WIN_PACKAGES
48 # Determines the path to the source and binary packages.
49 # Default is the "packages" directory in the source directory.
50 # The path is stored in the shell variable gpg4win_packages.
51 AC_DEFUN([GPG4WIN_PACKAGES],
52 [
53   AC_MSG_CHECKING(for packages directory)
54   _gpg4win_packages_default=packages
55   AC_ARG_WITH([packages],
56     AS_HELP_STRING([--with-packages=DIR],
57                    [source and binary packages [[packages]]]),
58     gpg4win_packages=$withval)
59   AS_IF([test -z $gpg4win_packages],
60         [gpg4win_packages=$_gpg4win_packages_default])
61   AS_IF([test `echo $gpg4win_packages | head -c 1` != /],
62         [gpg4win_packages=`pwd`/$gpg4win_packages])
63   AC_SUBST(gpg4win_packages)
64   AC_MSG_RESULT($gpg4win_packages)
65
66   # Set auto-detection.  FIXME: This should accept a comma-separated
67   # list of packages that will be autodetected.
68   _gpg4win_auto_detection=yes
69   AC_ARG_ENABLE([packages],
70     AS_HELP_STRING([--enable-packages], [enable auto-detection [[yes]]]),
71     _gpg4win_auto_detection=$enableval)
72 ])
73
74
75 # Should be called early.
76 AC_DEFUN([GPG4WIN_INIT],
77 [
78   # We call this here so its options appear before the per-package options.
79   AC_REQUIRE([GPG4WIN_PACKAGES])
80 ])
81
82
83 # GPG4WIN_FIND([FILE],[PATTERN],[ZIP|TAR],[DIR],[IF-FOUND],[IF-NOT-FOUND])
84 # Search for package file FILE in DIR.  If DIR is empty, yes or maybe,
85 # look in default directory.  If DIR is not maybe, abort if not found.
86 # The package file name is provided in gpg4win_val and the version in
87 # gpg4win_version.
88 AC_DEFUN([GPG4WIN_FIND],
89 [
90   AC_REQUIRE([GPG4WIN_BASH])
91   AC_REQUIRE([GPG4WIN_PACKAGES])
92
93   gpg4win_val=
94   gpg4win_version=
95
96   AC_MSG_CHECKING(for package $1)
97   _gpg4win_critical=no
98   _gpg4win_file=
99   _gpg4win_dir=$4
100
101   # If --enable-pkg-foo was specified, make success critical.
102   AS_IF([test x$_gpg4win_dir != xmaybe], [_gpg4win_critical=yes])
103
104   # Only check if critical or auto detection is requested.
105   AS_IF([test $_gpg4win_auto_detection = yes -o $_gpg4win_critical = yes],
106     [AS_IF([test -z "$_gpg4win_dir" -o "$_gpg4win_dir" = yes -o "$_gpg4win_dir" = maybe],
107           [_gpg4win_dir=$gpg4win_packages])
108
109     # Install pattern.
110     AS_IF([test -z "$2"], [_gpg4win_pat='$1-\([[0-9]].*\)'],
111           [_gpg4win_pat="$2"])
112
113     # Frob pattern.  Regex party!
114     [_gpg4win_glob=`echo "$_gpg4win_pat" | sed -e 's/\\\\(\(.*\)\\\\)/\1/'`]
115     [_gpg4win_glob=`echo "$_gpg4win_glob" | sed -e 's/\\.\\*/*/'`]
116
117     # Make non-matching globs expand to nothing.
118     shopt -s nullglob
119
120     _gpg4win_format=both
121     AS_IF([test ! -z "$3"], _gpg4win_format="$3")
122
123     AS_IF([test -z "$_gpg4win_file" -a $_gpg4win_format != zip],
124           [_gpg4win_file=`echo ${_gpg4win_dir}/${_gpg4win_glob}.tar.xz`
125            _gpg4win_suffix=.tar.xz])
126     AS_IF([test -z "$_gpg4win_file" -a $_gpg4win_format != zip],
127           [_gpg4win_file=`echo ${_gpg4win_dir}/${_gpg4win_glob}.tar.bz2`
128            _gpg4win_suffix=.tar.bz2])
129     AS_IF([test -z "$_gpg4win_file" -a $_gpg4win_format != zip],
130           [_gpg4win_file=`echo ${_gpg4win_dir}/${_gpg4win_glob}.tbz2`
131            _gpg4win_suffix=.tbz2])
132     AS_IF([test -z "$_gpg4win_file" -a $_gpg4win_format != zip],
133           [_gpg4win_file=`echo ${_gpg4win_dir}/${_gpg4win_glob}.tbz`
134            _gpg4win_suffix=.tbz])
135     AS_IF([test -z "$_gpg4win_file" -a $_gpg4win_format != zip],
136           [_gpg4win_file=`echo ${_gpg4win_dir}/${_gpg4win_glob}.tar.gz`
137            _gpg4win_suffix=.tar.gz])
138     AS_IF([test -z "$_gpg4win_file" -a $_gpg4win_format != zip],
139           [_gpg4win_file=`echo ${_gpg4win_dir}/${_gpg4win_glob}.tgz`
140            _gpg4win_suffix=.tgz])
141     AS_IF([test -z "$_gpg4win_file" -a $_gpg4win_format != tar],
142           [_gpg4win_file=`echo ${_gpg4win_dir}/${_gpg4win_glob}.zip`
143            _gpg4win_suffix=.zip])
144     AS_IF([test -z "$_gpg4win_file" -a $_gpg4win_format != tar -a $_gpg4win_format != zip],
145           [_gpg4win_file=`echo ${_gpg4win_dir}/${_gpg4win_glob}.exe`
146            _gpg4win_suffix=.exe])
147     shopt -u nullglob])
148
149   AS_IF([test -z "$_gpg4win_file"],
150         AC_MSG_RESULT(no),
151         AS_IF([test `echo $_gpg4win_file | head -c 1` != /],
152               [_gpg4win_file=`pwd`/$_gpg4win_file])
153         AC_MSG_RESULT($_gpg4win_file))
154   AS_IF([test -z "$_gpg4win_file" -a $_gpg4win_critical = yes],
155         AC_MSG_ERROR(could not find sources for $1 in $_gpg4win_dir))
156
157   # Test for duplicate.
158   _gpg4win_found=
159   for _gpg4win_f in $_gpg4win_file; do
160       AS_IF([test "$_gpg4win_found" = yes],
161             [AC_MSG_WARN(found more than one sources for $1 in $_gpg4win_dir)
162              gpg4win_dup_sources="$gpg4win_dup_sources $1";
163              gpg4win_rm_candidates="$gpg4win_rm_candidates $_gpg4win_file"])
164       _gpg4win_found=yes
165   done
166
167   AS_IF([test ! -z "$_gpg4win_file"],
168         [gpg4win_val="$_gpg4win_file"
169         [gpg4win_version=`echo "$gpg4win_val" | sed -e "s,^.*/${_gpg4win_pat}${_gpg4win_suffix}$,\1,"`]
170          [$5]],
171         [$6])
172 ])
173
174 AC_DEFUN([GPG4WIN_CHECK_EXDEPS],
175 [
176   AC_REQUIRE([GPG4WIN_CHECK_DEPS])
177
178   AC_MSG_CHECKING([additional host build list])
179
180   gpg4win_build_ex_list=`echo $_gpg4win_ex_deps | tsort`
181   # Remove newlines.
182   gpg4win_build_ex_list=`echo $gpg4win_build_ex_list`
183   AC_MSG_RESULT($gpg4win_build_ex_list)
184   AC_SUBST(gpg4win_build_ex_list)
185
186   # Check each dependency.
187   _gpg4win_not_found=
188   _gpg4win_d=
189   _gpg4win_p=
190   for _gpg4win_p in $_gpg4win_ex_deps; do
191     AS_IF([test -z $_gpg4win_d], [_gpg4win_d=$_gpg4win_p],
192           [
193             _gpg4win_found=
194             for _gpg4win_i in $_gpg4win_pkgs; do
195               AS_IF([test $_gpg4win_d = $_gpg4win_i],
196                     _gpg4win_found=yes
197                     break)
198             done
199             AS_IF([test -z $_gpg4win_found],
200                   AC_MSG_WARN(could not find ex variant of package $_gpg4win_d required by package $_gpg4win_p)
201                   _gpg4win_not_found=yes)
202             _gpg4win_d=
203           ])
204   done
205   AS_IF([test ! -z "$_gpg4win_not_found"],
206         AC_MSG_ERROR([could not find some required packages]))
207 ])
208
209 AC_DEFUN([GPG4WIN_CHECK_DEPS],
210 [
211   AC_MSG_CHECKING(build list)
212   gpg4win_build_list=`echo $_gpg4win_deps | tsort`
213   # Remove newlines.
214   gpg4win_build_list=`echo $gpg4win_build_list`
215   AC_MSG_RESULT($gpg4win_build_list)
216   AC_SUBST(gpg4win_build_list)
217
218   # Check each dependency.
219   _gpg4win_not_found=
220   _gpg4win_d=
221   _gpg4win_p=
222   for _gpg4win_p in $_gpg4win_deps; do
223     AS_IF([test -z $_gpg4win_d], [_gpg4win_d=$_gpg4win_p],
224           [
225             _gpg4win_found=
226             for _gpg4win_i in $_gpg4win_pkgs; do
227               AS_IF([test $_gpg4win_d = $_gpg4win_i],
228                     _gpg4win_found=yes
229                     break)
230             done
231             AS_IF([test -z $_gpg4win_found],
232                   AC_MSG_WARN(could not find package $_gpg4win_d required by package $_gpg4win_p)
233                   _gpg4win_not_found=yes)
234             _gpg4win_d=
235           ])
236   done
237   AS_IF([test ! -z "$_gpg4win_not_found"],
238         AC_MSG_ERROR([could not find some required packages]))
239 ])
240
241
242 AC_DEFUN([GPG4WIN_FINALIZE],
243 [
244   AC_REQUIRE([GPG4WIN_CHECK_EXDEPS])
245
246   _gpg4win_debug=no
247   AC_ARG_ENABLE([debug],
248     AS_HELP_STRING([--enable-debug], [enable debugging [[no]]]),
249     _gpg4win_debug=$enableval)
250
251   AS_IF([test "${_gpg4win_debug}" != no],
252     GPG4WIN_DEFINE(GPG4WIN_DEBUG))
253 ])
254
255
256 # GPG4WIN_IPKG([PKG],[DEPENDS],[IF-FOUND],[IF-NOT-FOUND])
257 # Set up the internal package PKG.
258 # It is provided in gpg4win_val.
259 AC_DEFUN([GPG4WIN_IPKG],
260 [
261   AC_REQUIRE([GPG4WIN_INIT])
262   AC_MSG_CHECKING([for internal package $1])
263   _gpg4win_pkg=maybe
264   AC_ARG_ENABLE([pkg-$1],
265     AS_HELP_STRING([--enable-pkg-$1[=DIR]],
266                    [include internal package $1]),
267     _gpg4win_pkg=$enableval,
268     _gpg4win_pkg=yes)
269
270   # gpg4win_pkg_PKGNAME_deps=DEPS
271   gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]_deps="$2"
272   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]_deps)
273
274   AC_MSG_RESULT($_gpg4win_pkg)
275
276   AS_IF([test "$_gpg4win_pkg" != no],
277     _gpg4win_pkgs="$_gpg4win_pkgs $1"
278     GPG4WIN_DEFINE(HAVE_PKG_[]m4_translit([$1],[a-z+-],[A-Z__]))
279     # Record dependencies.  Also enter every package as node.
280     _gpg4win_deps="$_gpg4win_deps $1 $1"
281     AS_IF([test ! -z "$2"],
282           for _gpg4win_i in $2; do
283             _gpg4win_deps="$_gpg4win_deps $_gpg4win_i $1"
284           done)
285       [$3],
286       [$4])
287 ])
288
289
290
291 # GPG4WIN_SPKG([PKG],[DEPENDS],[IF-FOUND],[IF-NOT-FOUND])
292 # Set up the source package PKG.
293 # It is provided in gpg4win_val.
294 AC_DEFUN([GPG4WIN_SPKG],
295 [
296   AC_REQUIRE([GPG4WIN_INIT])
297   _gpg4win_pkg=maybe
298   AC_ARG_ENABLE([pkg-$1],
299     AS_HELP_STRING([--enable-pkg-$1[=DIR]],
300                    [include package $1]),
301     _gpg4win_pkg=$enableval)
302   _gpg4win_spkg=no
303   _gpg4win_version=
304   AS_IF([test "$_gpg4win_pkg" != no],
305         [GPG4WIN_FIND($1,,, $_gpg4win_pkg,
306          _gpg4win_spkg=$gpg4win_val
307          _gpg4win_version=$gpg4win_version)])
308
309   # At this point, _gpg4win_spkg is no, or the actual package source file.
310
311   # gpg4win_pkg_PKGNAME=FILENAME_OF_SOURCE
312   gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]=$_gpg4win_spkg
313   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__]))
314
315   # gpg4win_pkg_PKGNAME_version=VERSION
316   gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_version=$_gpg4win_version
317   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_version)
318
319   # gpg4win_pkg_PKGNAME_deps=DEPS
320   gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]_deps="$2"
321   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]_deps)
322
323   AS_IF([test "$_gpg4win_spkg" != no],
324     _gpg4win_pkgs="$_gpg4win_pkgs $1"
325     GPG4WIN_DEFINE(HAVE_PKG_[]m4_translit([$1],[a-z+-],[A-Z__]))
326     # Record dependencies.  Also enter every package as node.
327     _gpg4win_deps="$_gpg4win_deps $1 $1"
328     AS_IF([test ! -z "$2"],
329           for _gpg4win_i in $2; do
330             _gpg4win_deps="$_gpg4win_deps $_gpg4win_i $1"
331           done)
332       [$3],
333       [$4])
334 ])
335
336
337 # GPG4WIN_SPKGEX([PKG],[DEPENDS],[IF-FOUND],[IF-NOT-FOUND])
338 # Set up the source package PKG to be additionally built
339 # for the host provided as additional-gpgex-host
340 AC_DEFUN([GPG4WIN_SPKGEX],
341 [
342   AC_REQUIRE([GPG4WIN_INIT])
343   _gpg4win_pkg=maybe
344   AC_ARG_ENABLE([pkg-$1],
345     AS_HELP_STRING([--enable-pkg-$1[=DIR]],
346                    [include package $1]),
347     _gpg4win_pkg=$enableval)
348   _gpg4win_spkg=no
349   _gpg4win_version=
350   AS_IF([test "$_gpg4win_pkg" != no],
351         [GPG4WIN_FIND($1,,, $_gpg4win_pkg,
352          _gpg4win_spkg=$gpg4win_val
353          _gpg4win_version=$gpg4win_version)])
354   # At this point, _gpg4win_spkg is no, or the actual package source file.
355
356   # gpg4win_pkg_PKGNAME=FILENAME_OF_SOURCE
357   gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]=$_gpg4win_spkg
358   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__]))
359
360   # gpg4win_pkg_PKGNAME_version=VERSION
361   gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_version=$_gpg4win_version
362   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_version)
363
364   AS_IF([test ! -z "$GPGEX_ADD_HOST"],
365
366     # gpg4win_pkg_PKGNAME_deps=DEPS
367     gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]_ex_deps="$2"
368     AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]_ex_deps)
369
370     gpg4win_ex_pkgs="$gpg4win_ex_pkgs $1"
371
372     GPG4WIN_DEFINE(HAVE_PKG_[]m4_translit([$1],[a-z+-],[A-Z__])_EX)
373     # Record dependencies.  Also enter every package as node.
374     _gpg4win_ex_deps="$_gpg4win_ex_deps $1 $1"
375     AS_IF([test ! -z "$2"],
376           for _gpg4win_i in $2; do
377             _gpg4win_ex_deps="$_gpg4win_ex_deps $_gpg4win_i $1"
378           done)
379   )
380 ])
381
382 # GPG4WIN_KDEPKG([PKG],[DEPENDS],[IF-FOUND],[IF-NOT-FOUND])
383 # Set up the source package PKG to be additionally built
384 # for the host provided as additional-gpgex-host
385 AC_DEFUN([GPG4WIN_KDEPKG],
386 [
387   AC_REQUIRE([GPG4WIN_INIT])
388   _gpg4win_pkg=maybe
389   AC_ARG_ENABLE([pkg-$1],
390     AS_HELP_STRING([--enable-pkg-$1[=DIR]],
391                    [include package $1]),
392     _gpg4win_pkg=$enableval)
393   _gpg4win_kdepkg=no
394   _gpg4win_version=
395   AS_IF([test "$_gpg4win_pkg" != no],
396         [GPG4WIN_FIND($1,,, $_gpg4win_pkg,
397         _gpg4win_kdepkg=$gpg4win_val
398         _gpg4win_version=$gpg4win_version)])
399
400   # gpg4win_pkg_PKGNAME=FILENAME_OF_SOURCE
401   gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]=$_gpg4win_kdepkg
402   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__]))
403
404   # gpg4win_pkg_PKGNAME_version=VERSION
405   gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_version=$_gpg4win_version
406   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_version)
407
408   # gpg4win_pkg_PKGNAME_deps=DEPS
409   gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]_deps="$2"
410   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]_deps)
411
412   AS_IF([test "$_gpg4win_kdepkg" != no],
413     _gpg4win_pkgs="$_gpg4win_pkgs $1"
414     GPG4WIN_DEFINE(HAVE_PKG_[]m4_translit([$1],[a-z+-],[A-Z__]))
415     # Record dependencies.  Also enter every package as node.
416     _gpg4win_deps="$_gpg4win_deps $1 $1"
417     AS_IF([test ! -z "$2"],
418           for _gpg4win_i in $2; do
419             _gpg4win_deps="$_gpg4win_deps $_gpg4win_i $1"
420           done)
421       [$3],
422       [$4])
423 ])
424
425 # GPG4WIN_BPKG_GNUWIN32([PKG],[DEPENDS],[IF-FOUND],[IF-NOT-FOUND])
426 # Set up the gnuwin32 package PKG.
427 # It is provided in gpg4win_val.
428 AC_DEFUN([GPG4WIN_BPKG_GNUWIN32],
429 [
430   AC_REQUIRE([GPG4WIN_INIT])
431   _gpg4win_pkg=maybe
432   AC_ARG_ENABLE([pkg-$1],
433     AS_HELP_STRING([--enable-pkg-$1[=DIR]],
434                    [include package $1]),
435     _gpg4win_pkg=$enableval)
436   _gpg4win_bpkg=no
437   _gpg4win_version=
438   AS_IF([test "$_gpg4win_pkg" != no],
439         [GPG4WIN_FIND($1-bin, [$1-\(.*\)-bin],,
440          $_gpg4win_pkg,
441          _gpg4win_bpkg=$gpg4win_val
442          _gpg4win_version=$gpg4win_version)])
443
444   # At this point, _gpg4win_bpkg is no, or the actual package source file.
445
446   # gpg4win_pkg_PKGNAME=FILENAME_OF_BINARY
447   gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]=$_gpg4win_bpkg
448   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__]))
449
450   # gpg4win_pkg_PKGNAME_version=VERSION
451   gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_version=$_gpg4win_version
452   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_version)
453
454   # gpg4win_pkg_PKGNAME_deps=DEPS
455   gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]_deps="$2"
456   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]_deps)
457
458   AS_IF([test "$_gpg4win_bpkg" != "no" ],
459     GPG4WIN_FIND($1-lib, [$1-\(.*\)-lib],,
460                  $_gpg4win_pkg, _gpg4win_bpkg=$gpg4win_val,
461        AC_MSG_ERROR(can not find development package for package $1))
462     # gpg4win_pkg_PKGNAME_dev=FILENAME_OF_BINARY_DEVEL
463     gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_dev=$_gpg4win_bpkg
464     AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_dev)
465
466     GPG4WIN_FIND($1-src, [$1-\(.*\)-src],,
467                  $_gpg4win_pkg, _gpg4win_bpkg=$gpg4win_val,
468        AC_MSG_ERROR(can not find sources for package $1))
469     # gpg4win_pkg_PKGNAME_src=FILENAME_OF_SOURCE
470     gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_src=$_gpg4win_bpkg
471     AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_src)
472
473     # FIXME: Add a version consistency check here.  All three packages
474     # must match!
475
476     GPG4WIN_DEFINE(HAVE_PKG_[]m4_translit([$1],[a-z+-],[A-Z__]))
477
478     _gpg4win_pkgs="$_gpg4win_pkgs $1"
479     # Record dependencies.  Also enter every package as node.
480     _gpg4win_deps="$_gpg4win_deps $1 $1"
481     AS_IF([test ! -z "$2"],
482           for _gpg4win_i in $2; do
483             _gpg4win_deps="$_gpg4win_deps $_gpg4win_i $1"
484           done)
485           [$3],
486           [$4])
487 ])
488
489 # GPG4WIN_BPKG_GNUWIN32_LIB([PKG],[DEPENDS],[IF-FOUND],[IF-NOT-FOUND])
490 # Set up the gnuwin32 package PKG.  This is a static only library version.
491 # It is provided in gpg4win_val.
492 AC_DEFUN([GPG4WIN_BPKG_GNUWIN32_LIB],
493 [
494   AC_REQUIRE([GPG4WIN_INIT])
495   _gpg4win_pkg=maybe
496   AC_ARG_ENABLE([pkg-$1],
497     AS_HELP_STRING([--enable-pkg-$1[=DIR]],
498                    [include package $1]),
499     _gpg4win_pkg=$enableval)
500   _gpg4win_bpkg=no
501   _gpg4win_version=
502   AS_IF([test "$_gpg4win_pkg" != no],
503         [GPG4WIN_FIND($1-lib, [$1-\(.*\)-lib],,
504          $_gpg4win_pkg,
505          _gpg4win_bpkg=$gpg4win_val
506          _gpg4win_version=$gpg4win_version)])
507
508   # At this point, _gpg4win_bpkg is no, or the actual package source file.
509
510   # gpg4win_pkg_PKGNAME=FILENAME_OF_BINARY
511   gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]=$_gpg4win_bpkg
512   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__]))
513
514   # gpg4win_pkg_PKGNAME_version=VERSION
515   gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_version=$_gpg4win_version
516   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_version)
517
518   AS_IF([test "$_gpg4win_bpkg" != no],
519     GPG4WIN_FIND($1-src, [$1-\(.*\)-src],,
520                  $_gpg4win_pkg, _gpg4win_bpkg=$gpg4win_val,
521        AC_MSG_ERROR(can not find sources for package $1))
522     # gpg4win_pkg_PKGNAME_src=FILENAME_OF_SOURCE
523     gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_src=$_gpg4win_bpkg
524     AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_src)
525
526     # FIXME: Add a version consistency check here.  All two packages
527     # must match!
528
529     GPG4WIN_DEFINE(HAVE_PKG_[]m4_translit([$1],[a-z+-],[A-Z__]))
530
531     _gpg4win_pkgs="$_gpg4win_pkgs $1"
532     # Record dependencies.  Also enter every package as node.
533     _gpg4win_deps="$_gpg4win_deps $1 $1"
534     AS_IF([test ! -z "$2"],
535           for _gpg4win_i in $2; do
536             _gpg4win_deps="$_gpg4win_deps $_gpg4win_i $1"
537           done)
538           [$3],
539           [$4])
540 ])
541
542
543 # GPG4WIN_BPKG_GTK([PKG],[DEPENDS],[IF-FOUND],[IF-NOT-FOUND])
544 # Set up the Gtk binary package PKG.
545 # It is provided in gpg4win_val.
546 AC_DEFUN([GPG4WIN_BPKG_GTK],
547 [
548   AC_REQUIRE([GPG4WIN_INIT])
549   _gpg4win_pkg=maybe
550   AC_ARG_ENABLE([pkg-$1],
551     AS_HELP_STRING([--enable-pkg-$1[=DIR]],
552                    [include package $1]),
553     _gpg4win_pkg=$enableval)
554   _gpg4win_bpkg=no
555   _gpg4win_version=
556   AS_IF([test "$_gpg4win_pkg" != no],
557         [GPG4WIN_FIND($1,,zip, $_gpg4win_pkg,
558          _gpg4win_bpkg=$gpg4win_val
559          _gpg4win_version=$gpg4win_version)])
560
561   # At this point, _gpg4win_bpkg is no, or the actual package source file.
562
563   # gpg4win_pkg_PKGNAME=FILENAME_OF_BINARY
564   gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]=$_gpg4win_bpkg
565   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__]))
566
567   # gpg4win_pkg_PKGNAME_version=VERSION
568   gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_version=$_gpg4win_version
569   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_version)
570
571   # gpg4win_pkg_PKGNAME_deps=DEPS
572   gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]_deps="$2"
573   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]_deps)
574
575   AS_IF([test "$_gpg4win_bpkg" != no],
576     [GPG4WIN_FIND($1,,tar, $_gpg4win_pkg, _gpg4win_bpkg=$gpg4win_val,
577        AC_MSG_ERROR(can not find sources for package $1))]
578     # gpg4win_pkg_PKGNAME_src=FILENAME_OF_SOURCE
579     gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_src=$_gpg4win_bpkg
580     AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_src)
581
582     # FIXME: Add a version consistency check here.  All three packages
583     # must match!
584
585     GPG4WIN_DEFINE(HAVE_PKG_[]m4_translit([$1],[a-z+-],[A-Z__]))
586
587     _gpg4win_pkgs="$_gpg4win_pkgs $1"
588     # Record dependencies.  Also enter every package as node.
589     _gpg4win_deps="$_gpg4win_deps $1 $1"
590     AS_IF([test ! -z "$2"],
591           for _gpg4win_i in $2; do
592             _gpg4win_deps="$_gpg4win_deps $_gpg4win_i $1"
593           done)
594           [$3],
595           [$4])
596 ])
597
598
599 # GPG4WIN_BPKG_GTK_DEV([PKG],[DEPENDS],[IF-FOUND],[IF-NOT-FOUND])
600 # Set up the Gtk library package PKG.
601 # It is provided in gpg4win_val.
602 AC_DEFUN([GPG4WIN_BPKG_GTK_DEV],
603 [
604   AC_REQUIRE([GPG4WIN_INIT])
605   _gpg4win_pkg=maybe
606   AC_ARG_ENABLE([pkg-$1],
607     AS_HELP_STRING([--enable-pkg-$1[=DIR]],
608                    [include package $1]),
609     _gpg4win_pkg=$enableval)
610   _gpg4win_bpkg=no
611   _gpg4win_version=
612   AS_IF([test "$_gpg4win_pkg" != no],
613         [GPG4WIN_FIND($1,,zip, $_gpg4win_pkg,
614          _gpg4win_bpkg=$gpg4win_val
615          _gpg4win_version=$gpg4win_version)])
616
617   # At this point, _gpg4win_bpkg is no, or the actual package source file.
618
619   # gpg4win_pkg_PKGNAME=FILENAME_OF_BINARY
620   gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]=$_gpg4win_bpkg
621   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__]))
622
623   # gpg4win_pkg_PKGNAME_version=VERSION
624   gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_version=$_gpg4win_version
625   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_version)
626
627   # gpg4win_pkg_PKGNAME_deps=DEPS
628   gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]_deps="$2"
629   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]_deps)
630
631   AS_IF([test "$_gpg4win_bpkg" != no],
632     [GPG4WIN_FIND($1-dev,,, $_gpg4win_pkg, _gpg4win_bpkg=$gpg4win_val,
633        AC_MSG_ERROR(can not find development package for package $1))]
634     # gpg4win_pkg_PKGNAME_dev=FILENAME_OF_BINARY_DEVEL
635     gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_dev=$_gpg4win_bpkg
636     AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_dev)
637
638     [GPG4WIN_FIND($1,,tar, $_gpg4win_pkg, _gpg4win_bpkg=$gpg4win_val,
639        AC_MSG_ERROR(can not find sources for package $1))]
640     # gpg4win_pkg_PKGNAME_src=FILENAME_OF_SOURCE
641     gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_src=$_gpg4win_bpkg
642     AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_src)
643
644     # FIXME: Add a version consistency check here.  All three packages
645     # must match!
646
647     GPG4WIN_DEFINE(HAVE_PKG_[]m4_translit([$1],[a-z+-],[A-Z__]))
648
649     _gpg4win_pkgs="$_gpg4win_pkgs $1"
650     # Record dependencies.  Also enter every package as node.
651     _gpg4win_deps="$_gpg4win_deps $1 $1"
652     AS_IF([test ! -z "$2"],
653           for _gpg4win_i in $2; do
654             _gpg4win_deps="$_gpg4win_deps $_gpg4win_i $1"
655           done)
656           [$3],
657           [$4])
658 ])
659
660
661 # GPG4WIN_BPKG_GNU([PKG],[DEPENDS],[IF-FOUND],[IF-NOT-FOUND])
662 # Set up the source package PKG.
663 # It is provided in gpg4win_val.
664 AC_DEFUN([GPG4WIN_BPKG_GNU],
665 [
666   AC_REQUIRE([GPG4WIN_INIT])
667   _gpg4win_pkg=maybe
668   AC_ARG_ENABLE([pkg-$1],
669     AS_HELP_STRING([--enable-pkg-$1[=DIR]],
670                    [include package $1]),
671     _gpg4win_pkg=$enableval)
672   _gpg4win_bpkg=no
673   _gpg4win_version=
674
675   AS_IF([test "$_gpg4win_pkg" != no],
676         [
677           # For some shameful reason, the gettext package is actually called
678           # gettext-runtime!
679           AS_IF([test $1 = gettext],
680                 [GPG4WIN_FIND($1-runtime,,zip, $_gpg4win_pkg,
681                              _gpg4win_bpkg=$gpg4win_val
682                              _gpg4win_version=$gpg4win_version)],
683                 [GPG4WIN_FIND($1,,zip, $_gpg4win_pkg,
684                              _gpg4win_bpkg=$gpg4win_val
685                              _gpg4win_version=$gpg4win_version)])
686         ])
687
688   # At this point, _gpg4win_bpkg is no, or the actual package source file.
689
690   # gpg4win_pkg_PKGNAME=FILENAME_OF_BINARY
691   gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]=$_gpg4win_bpkg
692   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__]))
693
694   # gpg4win_pkg_PKGNAME_version=VERSION
695   gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_version=$_gpg4win_version
696   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_version)
697
698   # gpg4win_pkg_PKGNAME_deps=DEPS
699   gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]_deps="$2"
700   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]_deps)
701
702   AS_IF([test "$_gpg4win_bpkg" != no],
703     [GPG4WIN_FIND($1,,tar, $_gpg4win_pkg, _gpg4win_bpkg=$gpg4win_val,
704        AC_MSG_ERROR(can not find sources for package $1))]
705     # gpg4win_pkg_PKGNAME_src=FILENAME_OF_SOURCE
706     gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_src=$_gpg4win_bpkg
707     AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_src)
708
709     # FIXME: Add a version consistency check here.  All two packages
710     # must match!
711
712     GPG4WIN_DEFINE(HAVE_PKG_[]m4_translit([$1],[a-z+-],[A-Z__]))
713
714     _gpg4win_pkgs="$_gpg4win_pkgs $1"
715     # Record dependencies.  Also enter every package as node.
716     _gpg4win_deps="$_gpg4win_deps $1 $1"
717     AS_IF([test ! -z "$2"],
718           for _gpg4win_i in $2; do
719             _gpg4win_deps="$_gpg4win_deps $_gpg4win_i $1"
720           done)
721           [$3],
722           [$4])
723 ])
724
725
726 # GPG4WIN_BPKG_BINSRC([PKG],[DEPENDS],[IF-FOUND],[IF-NOT-FOUND])
727 # Set up package PKG which is expected to be delivered as two ZIP files
728 # with a "-(src|source)" and a "-(bin|noinstaller)" suffix.
729 AC_DEFUN([GPG4WIN_BPKG_BINSRC],
730 [
731   AC_REQUIRE([GPG4WIN_INIT])
732   _gpg4win_pkg=maybe
733   AC_ARG_ENABLE([pkg-$1],
734     AS_HELP_STRING([--enable-pkg-$1[=DIR]],
735                    [include package $1]),
736     _gpg4win_pkg=$enableval)
737   _gpg4win_bpkg=no
738   _gpg4win_version=
739   AS_IF([test "$_gpg4win_pkg" != no],
740         [GPG4WIN_FIND($1-bin, [$1-\(.*\)-bin],,
741          $_gpg4win_pkg,
742          _gpg4win_bpkg=$gpg4win_val
743          _gpg4win_version=$gpg4win_version)])
744   AS_IF([test "$_gpg4win_pkg" != no -a "$_gpg4win_bpkg" = no],
745         [GPG4WIN_FIND($1-noinstaller, [$1-\(.*\)-noinstaller],,
746          $_gpg4win_pkg,
747          _gpg4win_bpkg=$gpg4win_val
748          _gpg4win_version=$gpg4win_version)])
749
750   # At this point, _gpg4win_bpkg is no, or the actual package binary file.
751
752   # gpg4win_pkg_PKGNAME=FILENAME_OF_BINARY
753   gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]=$_gpg4win_bpkg
754   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__]))
755
756   # gpg4win_pkg_PKGNAME_version=VERSION
757   gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]_version=$_gpg4win_version
758   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]_version)
759
760   # gpg4win_pkg_PKGNAME_deps=DEPS
761   gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]_deps="$2"
762   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]_deps)
763
764   AS_IF([test "$_gpg4win_bpkg" != no],
765     tmp_binsrc=yes
766     GPG4WIN_FIND($1-src, [$1-\(.*\)-src],,
767                  $_gpg4win_pkg, _gpg4win_bpkg=$gpg4win_val, tmp_binsrc=no)
768     if test $tmp_binsrc = no ; then
769        GPG4WIN_FIND($1-source, [$1-\(.*\)-source],,
770                     $_gpg4win_pkg, _gpg4win_bpkg=$gpg4win_val,
771                     AC_MSG_ERROR(can not find sources for package $1))
772     fi
773     # gpg4win_pkg_PKGNAME_src=FILENAME_OF_SOURCE
774     gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]_src=$_gpg4win_bpkg
775     AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]_src)
776
777     # FIXME: Add a version consistency check here.  Both packages
778     # must match!
779
780     GPG4WIN_DEFINE(HAVE_PKG_[]m4_translit([$1],[a-z+-],[A-Z__]))
781
782     _gpg4win_pkgs="$_gpg4win_pkgs []m4_translit([$1],[A-Z],[a-z])"
783     # Record dependencies.  Also enter every package as node.
784     _gpg4win_deps="$_gpg4win_deps []m4_translit([$1],[A-Z],[a-z]) []m4_translit([$1],[A-Z],[a-z])"
785     AS_IF([test ! -z "$2"],
786           for _gpg4win_i in $2; do
787             _gpg4win_deps="$_gpg4win_deps $_gpg4win_i []m4_translit([$1],[A-Z],[a-z])"
788           done)
789           [$3],
790           [$4])
791 ])
792
793 # Add a runtime library argument 1 should be the dll
794 # name without the .dll suffix
795 AC_DEFUN([GPG4WIN_RUNTIME_LIBRARY],
796 [
797     dll_path="no"
798     AC_ARG_WITH([$1],
799     AS_HELP_STRING([--with-$1-dll[=FILE]],
800                    [include FILE as runtime dependency for the installer.]),
801                    [dll_path=$withval])
802
803     if test "$dll_path" = "no"; then
804         changequote(,)
805         gcc_major_minor=$($CC --version \
806                           | awk 'NR==1 {split($NF,a,"."); print a[1] "." a[2]}')
807         gcc_major_minor_alt=$($CC --version | cut -d " " -f 3 \
808                              | awk 'NR==1 {split($NF,a,"."); print a[1] "." a[2]}')
809         changequote([,])
810         guesses="/usr/lib/gcc/$host/$gcc_major_minor/$1.dll
811                  /usr/$host/lib/$1.dll
812                  /usr/lib/gcc/$host/${gcc_major_minor}-win32/$1.dll
813                  /usr/lib/gcc/$host/${gcc_major_minor_alt}-win32/$1.dll
814                  /usr/lib/gcc/$host/${gcc_major_minor_alt}/$1.dll"
815
816         for file in $guesses; do
817             if test -r "$file"; then
818                 dll_path="$file"
819                 break
820             fi
821         done
822     fi
823
824     if test "$dll_path" = "no"; then
825         AC_MSG_ERROR(can not find the runtime library $1.dll in the default locations.
826                      Use the --with-$1 option to set the path directly.
827         )
828     fi
829     AC_MSG_NOTICE(Using $dll_path to provide $1)
830     $CP "$dll_path" src/$1.dll-x
831     $STRIP src/$1.dll-x
832 ])