+&checkcommandversion
[macros.git] / AutoGen.pm
index 796733e..cad8cbf 100644 (file)
@@ -63,6 +63,23 @@ Supported parameters:
 '.($Options{"help"} || "");
 }
 
+sub checkcommandversion
+{
+my($class,$command,$version)=@_;
+
+       local *F;
+       do { open F,$_ or confess "Open $_: $!"; } for ("$command --version|");
+       local $/;
+       undef $/;
+       my $command_out=<F>;
+       close F;
+       my $command_version=($command_out=~m#([\d.]+)#)[0];
+       confess "$command(1) version not found in its output" if !$command_version;
+       confess "'$command' version $version or higher required"
+                       # Do not take 3rd+ numbers as it would not be a number
+                       if ($command_version=~/^(\d+[.]\d+)/)[0]<$version;
+}
+
 sub _readfile
 {
 my($filename)=@_;