Imported Upstream version 2.6.1
[debian/amanda] / config / macro-archive / ac_perl_module_version.m4
1 # ===========================================================================
2 #         http://autoconf-archive.cryp.to/ac_perl_module_version.html
3 # ===========================================================================
4 #
5 # SYNOPSIS
6 #
7 #   AC_PERL_MODULE_VERSION([MODULE VERSION], [ACTION-IF-TRUE], [ACTION-IF-FALSE])
8 #
9 # DESCRIPTION
10 #
11 #   Checks to see if the list of 'Module Version' are avaiable in the
12 #   system. If all the modules in the list are avaiable ACTION-IF-TRUE is
13 #   executed. Case one module is not avaiable ACTION-IF-FALSE is executed
14 #   and the macro execution is aborted. NOTE: Perl is needed.
15 #
16 #   Example:
17 #
18 #     AC_PERL_MODULE_VERSION(CGI::Test 0.104 CGI::Ajax 0.694, ,
19 #        AC_MSG_ERROR(Need some Perl modules))
20 #
21 # LAST MODIFICATION
22 #
23 #   2008-04-12
24 #
25 # COPYLEFT
26 #
27 #   Copyright (c) 2008 Marco Gomes <mpglesi@gmail.com>
28 #   Copyright (c) 2008 Ruben Fonseca <fonseka@gmail.com>
29 #
30 #   Copying and distribution of this file, with or without modification, are
31 #   permitted in any medium without royalty provided the copyright notice
32 #   and this notice are preserved.
33
34 AC_DEFUN([AC_PERL_MODULE_VERSION],[dnl
35 ac_perl_list_modules="$1"
36 # Make sure we have perl
37 if test -z "$PERL"; then
38 AC_CHECK_PROG(PERL,perl,perl)
39 fi
40
41 # Check the number of arguments
42 args_num=`echo $ac_perl_list_modules | wc -w`
43 let "ckeck_args = $args_num % 2"
44 if test "$check_args" = "1" ; then
45   AC_MSG_ERROR(syntax error)
46 else
47   eval
48 fi
49
50 if test "x$PERL" != x; then
51   ac_failed=0
52   while test ${#ac_perl_list_modules} -gt 2 ; do
53         module_name=`echo $ac_perl_list_modules | cut -d " " -f 1`
54         module_version=`echo $ac_perl_list_modules | cut -d " " -f 2`
55         ac_perl_list_modules=`echo $ac_perl_list_modules | cut -d " " -f 3-`
56         AC_MSG_CHECKING(for perl module $module_name version $module_version)
57
58         $PERL "-M$module_name" -e exit > /dev/null 2>&1
59         if test $? -ne 0; then
60           AC_MSG_RESULT(no);
61           ac_failed=1
62           ac_perl_list_modules=""
63         else
64           version=`$PERL "-M$module_name" -e 'print $'"$module_name::VERSION" 2>&1`
65           $PERL -e 'exit(shift cmp shift)' "$version" "$module_version"
66           if test $? -eq 0 -o $? -eq 1 ; then
67             AC_MSG_RESULT(ok);
68           else
69             AC_MSG_RESULT(no)
70             ac_failed=1
71             ac_perl_list_modules=""
72           fi
73         fi;
74   done
75
76   if test "$ac_failed" = 0; then
77     :
78     $2
79   else
80     :
81     $3
82   fi
83 else
84   AC_MSG_ERROR(could not find perl)
85 fi])dnl