61078270de9064b301099e61610d37940907e7be
[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.bz2`
125            _gpg4win_suffix=.tar.bz2])
126     AS_IF([test -z "$_gpg4win_file" -a $_gpg4win_format != zip],
127           [_gpg4win_file=`echo ${_gpg4win_dir}/${_gpg4win_glob}.tbz2`
128            _gpg4win_suffix=.tbz2])
129     AS_IF([test -z "$_gpg4win_file" -a $_gpg4win_format != zip],
130           [_gpg4win_file=`echo ${_gpg4win_dir}/${_gpg4win_glob}.tbz`
131            _gpg4win_suffix=.tbz])
132     AS_IF([test -z "$_gpg4win_file" -a $_gpg4win_format != zip],
133           [_gpg4win_file=`echo ${_gpg4win_dir}/${_gpg4win_glob}.tar.gz`
134            _gpg4win_suffix=.tar.gz])
135     AS_IF([test -z "$_gpg4win_file" -a $_gpg4win_format != zip],
136           [_gpg4win_file=`echo ${_gpg4win_dir}/${_gpg4win_glob}.tgz`
137            _gpg4win_suffix=.tgz])
138     AS_IF([test -z "$_gpg4win_file" -a $_gpg4win_format != tar],
139           [_gpg4win_file=`echo ${_gpg4win_dir}/${_gpg4win_glob}.zip`
140            _gpg4win_suffix=.zip])
141     shopt -u nullglob])
142
143   AS_IF([test -z "$_gpg4win_file"],
144         AC_MSG_RESULT(no),
145         AS_IF([test `echo $_gpg4win_file | head -c 1` != /],
146               [_gpg4win_file=`pwd`/$_gpg4win_file])
147         AC_MSG_RESULT($_gpg4win_file))
148   AS_IF([test -z "$_gpg4win_file" -a $_gpg4win_critical = yes],
149         AC_MSG_ERROR(could not find sources for $1 in $_gpg4win_dir))
150
151   # Test for duplicate.
152   _gpg4win_found=
153   for _gpg4win_f in $_gpg4win_file; do
154       AS_IF([test "$_gpg4win_found" = yes],
155             [AC_MSG_WARN(found more than one sources for $1 in $_gpg4win_dir)
156              gpg4win_dup_sources="$gpg4win_dup_sources $1"])
157       _gpg4win_found=yes
158   done
159
160   AS_IF([test ! -z "$_gpg4win_file"],
161         [gpg4win_val="$_gpg4win_file"
162         [gpg4win_version=`echo "$gpg4win_val" | sed -e "s,^.*/${_gpg4win_pat}${_gpg4win_suffix}$,\1,"`]
163          [$5]],
164         [$6])
165 ])
166
167
168 AC_DEFUN([GPG4WIN_CHECK_DEPS],
169 [
170   AC_MSG_CHECKING(build list)
171   gpg4win_build_list=`echo $_gpg4win_deps | tsort`
172   # Remove newlines.
173   gpg4win_build_list=`echo $gpg4win_build_list`
174   AC_MSG_RESULT($gpg4win_build_list)
175   AC_SUBST(gpg4win_build_list)
176
177   # Check each dependency.
178   _gpg4win_not_found=
179   _gpg4win_d=
180   _gpg4win_p=
181   for _gpg4win_p in $_gpg4win_deps; do
182     AS_IF([test -z $_gpg4win_d], [_gpg4win_d=$_gpg4win_p],
183           [
184             _gpg4win_found=
185             for _gpg4win_i in $_gpg4win_pkgs; do
186               AS_IF([test $_gpg4win_d = $_gpg4win_i],
187                     _gpg4win_found=yes
188                     break)
189             done
190             AS_IF([test -z $_gpg4win_found],
191                   AC_MSG_WARN(could not find package $_gpg4win_d required by package $_gpg4win_p)
192                   _gpg4win_not_found=yes)
193             _gpg4win_d=
194           ])
195   done
196   AS_IF([test ! -z "$_gpg4win_not_found"],
197         AC_MSG_ERROR([could not find some required packages]))
198 ])
199
200
201 AC_DEFUN([GPG4WIN_FINALIZE],
202 [
203   AC_REQUIRE([GPG4WIN_CHECK_DEPS])
204
205   _gpg4win_debug=no
206   AC_ARG_ENABLE([debug],
207     AS_HELP_STRING([--enable-debug], [enable debugging [[no]]]),
208     _gpg4win_debug=$enableval)
209
210   AS_IF([test "${_gpg4win_debug}" != no],
211     GPG4WIN_DEFINE(GPG4WIN_DEBUG))
212 ])
213
214
215 # GPG4WIN_IPKG([PKG],[DEPENDS],[IF-FOUND],[IF-NOT-FOUND])
216 # Set up the internal package PKG.
217 # It is provided in gpg4win_val.
218 AC_DEFUN([GPG4WIN_IPKG],
219 [
220   AC_REQUIRE([GPG4WIN_INIT])
221   AC_MSG_CHECKING([for internal package $1])
222   _gpg4win_pkg=maybe
223   AC_ARG_ENABLE([pkg-$1],
224     AS_HELP_STRING([--enable-pkg-$1[=DIR]],
225                    [include internal package $1]),
226     _gpg4win_pkg=$enableval,
227     _gpg4win_pkg=yes)
228
229   # gpg4win_pkg_PKGNAME_deps=DEPS
230   gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]_deps="$2"
231   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]_deps)
232
233   AC_MSG_RESULT($_gpg4win_pkg)
234
235   AS_IF([test "$_gpg4win_pkg" != no],
236     _gpg4win_pkgs="$_gpg4win_pkgs $1"
237     GPG4WIN_DEFINE(HAVE_PKG_[]m4_translit([$1],[a-z+-],[A-Z__]))
238     # Record dependencies.  Also enter every package as node.
239     _gpg4win_deps="$_gpg4win_deps $1 $1"
240     AS_IF([test ! -z "$2"],
241           for _gpg4win_i in $2; do
242             _gpg4win_deps="$_gpg4win_deps $_gpg4win_i $1"
243           done)
244       [$3],
245       [$4])
246 ])
247
248
249
250 # GPG4WIN_SPKG([PKG],[DEPENDS],[IF-FOUND],[IF-NOT-FOUND])
251 # Set up the source package PKG.
252 # It is provided in gpg4win_val.
253 AC_DEFUN([GPG4WIN_SPKG],
254 [
255   AC_REQUIRE([GPG4WIN_INIT])
256   _gpg4win_pkg=maybe
257   AC_ARG_ENABLE([pkg-$1],
258     AS_HELP_STRING([--enable-pkg-$1[=DIR]],
259                    [include package $1]),
260     _gpg4win_pkg=$enableval)
261   _gpg4win_spkg=no
262   _gpg4win_version=
263   AS_IF([test "$_gpg4win_pkg" != no],
264         [GPG4WIN_FIND($1,,, $_gpg4win_pkg,
265          _gpg4win_spkg=$gpg4win_val
266          _gpg4win_version=$gpg4win_version)])
267
268   # At this point, _gpg4win_spkg is no, or the actual package source file.
269
270   # gpg4win_pkg_PKGNAME=FILENAME_OF_SOURCE
271   gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]=$_gpg4win_spkg
272   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__]))
273
274   # gpg4win_pkg_PKGNAME_version=VERSION
275   gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_version=$_gpg4win_version
276   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_version)
277
278   # gpg4win_pkg_PKGNAME_deps=DEPS
279   gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]_deps="$2"
280   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]_deps)
281
282   AS_IF([test "$_gpg4win_spkg" != no],
283     _gpg4win_pkgs="$_gpg4win_pkgs $1"
284     GPG4WIN_DEFINE(HAVE_PKG_[]m4_translit([$1],[a-z+-],[A-Z__]))
285     # Record dependencies.  Also enter every package as node.
286     _gpg4win_deps="$_gpg4win_deps $1 $1"
287     AS_IF([test ! -z "$2"],
288           for _gpg4win_i in $2; do
289             _gpg4win_deps="$_gpg4win_deps $_gpg4win_i $1"
290           done)
291       [$3],
292       [$4])
293 ])
294
295
296
297 # GPG4WIN_BPKG_GNUWIN32([PKG],[DEPENDS],[IF-FOUND],[IF-NOT-FOUND])
298 # Set up the gnuwin32 package PKG.
299 # It is provided in gpg4win_val.
300 AC_DEFUN([GPG4WIN_BPKG_GNUWIN32],
301 [
302   AC_REQUIRE([GPG4WIN_INIT])
303   _gpg4win_pkg=maybe
304   AC_ARG_ENABLE([pkg-$1],
305     AS_HELP_STRING([--enable-pkg-$1[=DIR]],
306                    [include package $1]),
307     _gpg4win_pkg=$enableval)
308   _gpg4win_bpkg=no
309   _gpg4win_version=
310   AS_IF([test "$_gpg4win_pkg" != no],
311         [GPG4WIN_FIND($1-bin, [$1-\(.*\)-bin],,
312          $_gpg4win_pkg,
313          _gpg4win_bpkg=$gpg4win_val
314          _gpg4win_version=$gpg4win_version)])
315
316   # At this point, _gpg4win_bpkg is no, or the actual package source file.
317
318   # gpg4win_pkg_PKGNAME=FILENAME_OF_BINARY
319   gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]=$_gpg4win_bpkg
320   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__]))
321
322   # gpg4win_pkg_PKGNAME_version=VERSION
323   gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_version=$_gpg4win_version
324   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_version)
325
326   # gpg4win_pkg_PKGNAME_deps=DEPS
327   gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]_deps="$2"
328   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]_deps)
329
330   AS_IF([test "$_gpg4win_bpkg" != "no" ],
331     GPG4WIN_FIND($1-lib, [$1-\(.*\)-lib],,
332                  $_gpg4win_pkg, _gpg4win_bpkg=$gpg4win_val,
333        AC_MSG_ERROR(can not find development package for package $1))
334     # gpg4win_pkg_PKGNAME_dev=FILENAME_OF_BINARY_DEVEL
335     gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_dev=$_gpg4win_bpkg
336     AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_dev)
337
338     GPG4WIN_FIND($1-src, [$1-\(.*\)-src],,
339                  $_gpg4win_pkg, _gpg4win_bpkg=$gpg4win_val,
340        AC_MSG_ERROR(can not find sources for package $1))
341     # gpg4win_pkg_PKGNAME_src=FILENAME_OF_SOURCE
342     gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_src=$_gpg4win_bpkg
343     AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_src)
344
345     # FIXME: Add a version consistency check here.  All three packages
346     # must match!
347
348     GPG4WIN_DEFINE(HAVE_PKG_[]m4_translit([$1],[a-z+-],[A-Z__]))
349
350     _gpg4win_pkgs="$_gpg4win_pkgs $1"
351     # Record dependencies.  Also enter every package as node.
352     _gpg4win_deps="$_gpg4win_deps $1 $1"
353     AS_IF([test ! -z "$2"],
354           for _gpg4win_i in $2; do
355             _gpg4win_deps="$_gpg4win_deps $_gpg4win_i $1"
356           done)
357           [$3],
358           [$4])
359 ])
360
361 # GPG4WIN_BPKG_GNUWIN32_LIB([PKG],[DEPENDS],[IF-FOUND],[IF-NOT-FOUND])
362 # Set up the gnuwin32 package PKG.  This is a static only library version.
363 # It is provided in gpg4win_val.
364 AC_DEFUN([GPG4WIN_BPKG_GNUWIN32_LIB],
365 [
366   AC_REQUIRE([GPG4WIN_INIT])
367   _gpg4win_pkg=maybe
368   AC_ARG_ENABLE([pkg-$1],
369     AS_HELP_STRING([--enable-pkg-$1[=DIR]],
370                    [include package $1]),
371     _gpg4win_pkg=$enableval)
372   _gpg4win_bpkg=no
373   _gpg4win_version=
374   AS_IF([test "$_gpg4win_pkg" != no],
375         [GPG4WIN_FIND($1-lib, [$1-\(.*\)-lib],,
376          $_gpg4win_pkg,
377          _gpg4win_bpkg=$gpg4win_val
378          _gpg4win_version=$gpg4win_version)])
379
380   # At this point, _gpg4win_bpkg is no, or the actual package source file.
381
382   # gpg4win_pkg_PKGNAME=FILENAME_OF_BINARY
383   gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]=$_gpg4win_bpkg
384   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__]))
385
386   # gpg4win_pkg_PKGNAME_version=VERSION
387   gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_version=$_gpg4win_version
388   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_version)
389
390   AS_IF([test "$_gpg4win_bpkg" != no],
391     GPG4WIN_FIND($1-src, [$1-\(.*\)-src],,
392                  $_gpg4win_pkg, _gpg4win_bpkg=$gpg4win_val,
393        AC_MSG_ERROR(can not find sources for package $1))
394     # gpg4win_pkg_PKGNAME_src=FILENAME_OF_SOURCE
395     gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_src=$_gpg4win_bpkg
396     AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_src)
397
398     # FIXME: Add a version consistency check here.  All two packages
399     # must match!
400
401     GPG4WIN_DEFINE(HAVE_PKG_[]m4_translit([$1],[a-z+-],[A-Z__]))
402
403     _gpg4win_pkgs="$_gpg4win_pkgs $1"
404     # Record dependencies.  Also enter every package as node.
405     _gpg4win_deps="$_gpg4win_deps $1 $1"
406     AS_IF([test ! -z "$2"],
407           for _gpg4win_i in $2; do
408             _gpg4win_deps="$_gpg4win_deps $_gpg4win_i $1"
409           done)
410           [$3],
411           [$4])
412 ])
413
414
415 # GPG4WIN_BPKG_GTK([PKG],[DEPENDS],[IF-FOUND],[IF-NOT-FOUND])
416 # Set up the Gtk binary package PKG.
417 # It is provided in gpg4win_val.
418 AC_DEFUN([GPG4WIN_BPKG_GTK],
419 [
420   AC_REQUIRE([GPG4WIN_INIT])
421   _gpg4win_pkg=maybe
422   AC_ARG_ENABLE([pkg-$1],
423     AS_HELP_STRING([--enable-pkg-$1[=DIR]],
424                    [include package $1]),
425     _gpg4win_pkg=$enableval)
426   _gpg4win_bpkg=no
427   _gpg4win_version=
428   AS_IF([test "$_gpg4win_pkg" != no],
429         [GPG4WIN_FIND($1,,zip, $_gpg4win_pkg,
430          _gpg4win_bpkg=$gpg4win_val
431          _gpg4win_version=$gpg4win_version)])
432
433   # At this point, _gpg4win_bpkg is no, or the actual package source file.
434
435   # gpg4win_pkg_PKGNAME=FILENAME_OF_BINARY
436   gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]=$_gpg4win_bpkg
437   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__]))
438
439   # gpg4win_pkg_PKGNAME_version=VERSION
440   gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_version=$_gpg4win_version
441   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_version)
442
443   # gpg4win_pkg_PKGNAME_deps=DEPS
444   gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]_deps="$2"
445   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]_deps)
446
447   AS_IF([test "$_gpg4win_bpkg" != no],
448     [GPG4WIN_FIND($1,,tar, $_gpg4win_pkg, _gpg4win_bpkg=$gpg4win_val,
449        AC_MSG_ERROR(can not find sources for package $1))]
450     # gpg4win_pkg_PKGNAME_src=FILENAME_OF_SOURCE
451     gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_src=$_gpg4win_bpkg
452     AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_src)
453
454     # FIXME: Add a version consistency check here.  All three packages
455     # must match!
456
457     GPG4WIN_DEFINE(HAVE_PKG_[]m4_translit([$1],[a-z+-],[A-Z__]))
458
459     _gpg4win_pkgs="$_gpg4win_pkgs $1"
460     # Record dependencies.  Also enter every package as node.
461     _gpg4win_deps="$_gpg4win_deps $1 $1"
462     AS_IF([test ! -z "$2"],
463           for _gpg4win_i in $2; do
464             _gpg4win_deps="$_gpg4win_deps $_gpg4win_i $1"
465           done)
466           [$3],
467           [$4])
468 ])
469
470
471 # GPG4WIN_BPKG_GTK_DEV([PKG],[DEPENDS],[IF-FOUND],[IF-NOT-FOUND])
472 # Set up the Gtk library package PKG.
473 # It is provided in gpg4win_val.
474 AC_DEFUN([GPG4WIN_BPKG_GTK_DEV],
475 [
476   AC_REQUIRE([GPG4WIN_INIT])
477   _gpg4win_pkg=maybe
478   AC_ARG_ENABLE([pkg-$1],
479     AS_HELP_STRING([--enable-pkg-$1[=DIR]],
480                    [include package $1]),
481     _gpg4win_pkg=$enableval)
482   _gpg4win_bpkg=no
483   _gpg4win_version=
484   AS_IF([test "$_gpg4win_pkg" != no],
485         [GPG4WIN_FIND($1,,zip, $_gpg4win_pkg,
486          _gpg4win_bpkg=$gpg4win_val
487          _gpg4win_version=$gpg4win_version)])
488
489   # At this point, _gpg4win_bpkg is no, or the actual package source file.
490
491   # gpg4win_pkg_PKGNAME=FILENAME_OF_BINARY
492   gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]=$_gpg4win_bpkg
493   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__]))
494
495   # gpg4win_pkg_PKGNAME_version=VERSION
496   gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_version=$_gpg4win_version
497   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_version)
498
499   # gpg4win_pkg_PKGNAME_deps=DEPS
500   gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]_deps="$2"
501   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]_deps)
502
503   AS_IF([test "$_gpg4win_bpkg" != no],
504     [GPG4WIN_FIND($1-dev,,, $_gpg4win_pkg, _gpg4win_bpkg=$gpg4win_val,
505        AC_MSG_ERROR(can not find development package for package $1))]
506     # gpg4win_pkg_PKGNAME_dev=FILENAME_OF_BINARY_DEVEL
507     gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_dev=$_gpg4win_bpkg
508     AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_dev)
509
510     [GPG4WIN_FIND($1,,tar, $_gpg4win_pkg, _gpg4win_bpkg=$gpg4win_val,
511        AC_MSG_ERROR(can not find sources for package $1))]
512     # gpg4win_pkg_PKGNAME_src=FILENAME_OF_SOURCE
513     gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_src=$_gpg4win_bpkg
514     AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_src)
515
516     # FIXME: Add a version consistency check here.  All three packages
517     # must match!
518
519     GPG4WIN_DEFINE(HAVE_PKG_[]m4_translit([$1],[a-z+-],[A-Z__]))
520
521     _gpg4win_pkgs="$_gpg4win_pkgs $1"
522     # Record dependencies.  Also enter every package as node.
523     _gpg4win_deps="$_gpg4win_deps $1 $1"
524     AS_IF([test ! -z "$2"],
525           for _gpg4win_i in $2; do
526             _gpg4win_deps="$_gpg4win_deps $_gpg4win_i $1"
527           done)
528           [$3],
529           [$4])
530 ])
531
532
533 # GPG4WIN_BPKG_GNU([PKG],[DEPENDS],[IF-FOUND],[IF-NOT-FOUND])
534 # Set up the source package PKG.
535 # It is provided in gpg4win_val.
536 AC_DEFUN([GPG4WIN_BPKG_GNU],
537 [
538   AC_REQUIRE([GPG4WIN_INIT])
539   _gpg4win_pkg=maybe
540   AC_ARG_ENABLE([pkg-$1],
541     AS_HELP_STRING([--enable-pkg-$1[=DIR]],
542                    [include package $1]),
543     _gpg4win_pkg=$enableval)
544   _gpg4win_bpkg=no
545   _gpg4win_version=
546
547   AS_IF([test "$_gpg4win_pkg" != no],
548         [
549           # For some shameful reason, the gettext package is actually called
550           # gettext-runtime!
551           AS_IF([test $1 = gettext],
552                 [GPG4WIN_FIND($1-runtime,,zip, $_gpg4win_pkg,
553                              _gpg4win_bpkg=$gpg4win_val
554                              _gpg4win_version=$gpg4win_version)],
555                 [GPG4WIN_FIND($1,,zip, $_gpg4win_pkg,
556                              _gpg4win_bpkg=$gpg4win_val
557                              _gpg4win_version=$gpg4win_version)])
558         ])
559
560   # At this point, _gpg4win_bpkg is no, or the actual package source file.
561
562   # gpg4win_pkg_PKGNAME=FILENAME_OF_BINARY
563   gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]=$_gpg4win_bpkg
564   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__]))
565
566   # gpg4win_pkg_PKGNAME_version=VERSION
567   gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_version=$_gpg4win_version
568   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_version)
569
570   # gpg4win_pkg_PKGNAME_deps=DEPS
571   gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]_deps="$2"
572   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]_deps)
573
574   AS_IF([test "$_gpg4win_bpkg" != no],
575     [GPG4WIN_FIND($1,,tar, $_gpg4win_pkg, _gpg4win_bpkg=$gpg4win_val,
576        AC_MSG_ERROR(can not find sources for package $1))]
577     # gpg4win_pkg_PKGNAME_src=FILENAME_OF_SOURCE
578     gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_src=$_gpg4win_bpkg
579     AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[-+],[__])[]_src)
580
581     # FIXME: Add a version consistency check here.  All two packages
582     # must match!
583
584     GPG4WIN_DEFINE(HAVE_PKG_[]m4_translit([$1],[a-z+-],[A-Z__]))
585
586     _gpg4win_pkgs="$_gpg4win_pkgs $1"
587     # Record dependencies.  Also enter every package as node.
588     _gpg4win_deps="$_gpg4win_deps $1 $1"
589     AS_IF([test ! -z "$2"],
590           for _gpg4win_i in $2; do
591             _gpg4win_deps="$_gpg4win_deps $_gpg4win_i $1"
592           done)
593           [$3],
594           [$4])
595 ])
596
597
598 # GPG4WIN_BPKG_BINSRC([PKG],[DEPENDS],[IF-FOUND],[IF-NOT-FOUND])
599 # Set up package PKG which is expected to be delivered as two ZIP files
600 # with a "-(src|source)" and a "-(bin|noinstaller)" suffix.
601 AC_DEFUN([GPG4WIN_BPKG_BINSRC],
602 [
603   AC_REQUIRE([GPG4WIN_INIT])
604   _gpg4win_pkg=maybe
605   AC_ARG_ENABLE([pkg-$1],
606     AS_HELP_STRING([--enable-pkg-$1[=DIR]],
607                    [include package $1]),
608     _gpg4win_pkg=$enableval)
609   _gpg4win_bpkg=no
610   _gpg4win_version=
611   AS_IF([test "$_gpg4win_pkg" != no],
612         [GPG4WIN_FIND($1-bin, [$1-\(.*\)-bin],,
613          $_gpg4win_pkg,
614          _gpg4win_bpkg=$gpg4win_val
615          _gpg4win_version=$gpg4win_version)])
616   AS_IF([test "$_gpg4win_pkg" != no -a "$_gpg4win_bpkg" = no],
617         [GPG4WIN_FIND($1-noinstaller, [$1-\(.*\)-noinstaller],,
618          $_gpg4win_pkg,
619          _gpg4win_bpkg=$gpg4win_val
620          _gpg4win_version=$gpg4win_version)])
621
622   # At this point, _gpg4win_bpkg is no, or the actual package binary file.
623
624   # gpg4win_pkg_PKGNAME=FILENAME_OF_BINARY
625   gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]=$_gpg4win_bpkg
626   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__]))
627
628   # gpg4win_pkg_PKGNAME_version=VERSION
629   gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]_version=$_gpg4win_version
630   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]_version)
631
632   # gpg4win_pkg_PKGNAME_deps=DEPS
633   gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]_deps="$2"
634   AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]_deps)
635
636   AS_IF([test "$_gpg4win_bpkg" != no],
637     tmp_binsrc=yes
638     GPG4WIN_FIND($1-src, [$1-\(.*\)-src],,
639                  $_gpg4win_pkg, _gpg4win_bpkg=$gpg4win_val, tmp_binsrc=no)
640     if test $tmp_binsrc = no ; then
641        GPG4WIN_FIND($1-source, [$1-\(.*\)-source],,
642                     $_gpg4win_pkg, _gpg4win_bpkg=$gpg4win_val, 
643                     AC_MSG_ERROR(can not find sources for package $1))
644     fi
645     # gpg4win_pkg_PKGNAME_src=FILENAME_OF_SOURCE
646     gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]_src=$_gpg4win_bpkg
647     AC_SUBST(gpg4win_pkg_[]m4_translit([$1],[A-Z+-],[a-z__])[]_src)
648
649     # FIXME: Add a version consistency check here.  Both packages
650     # must match!
651
652     GPG4WIN_DEFINE(HAVE_PKG_[]m4_translit([$1],[a-z+-],[A-Z__]))
653
654     _gpg4win_pkgs="$_gpg4win_pkgs []m4_translit([$1],[A-Z],[a-z])"
655     # Record dependencies.  Also enter every package as node.
656     _gpg4win_deps="$_gpg4win_deps []m4_translit([$1],[A-Z],[a-z]) []m4_translit([$1],[A-Z],[a-z])"
657     AS_IF([test ! -z "$2"],
658           for _gpg4win_i in $2; do
659             _gpg4win_deps="$_gpg4win_deps $_gpg4win_i []m4_translit([$1],[A-Z],[a-z])"
660           done)
661           [$3],
662           [$4])
663 ])
664