1#!/usr/local/bin/perl -w 2 3# $Id: 4 5#**************************************************************************** 6# 7# BLDLVLCK 8# 9# This perl script checks the user's system for the required levels of 10# software needed to properly build Hercules from the source repository. 11# 12#**************************************************************************** 13# 14# ---- CHANGE LOG ---- 15# 16# DD/MM/YY Description... 17# 26/02/03 Created by Jim Morrison. 18# 21/09/03 Removed libintl & libtool. Although "gettextize" is no longer 19# run, pkg "gettext" is still needed to run the msgfmt/msgmerge 20# utilities. libintl is now self-contained. libtool is now self- 21# contained. (ISW) 22# 24/10/05 Added history section in preparation for possible changes. (Fish) 23# 24/10/05 According to jj, automake 1.6 is insufficient. He says 1.9 works 24# though, but doesn't know about 1.7 or 1.8 yet. (Fish) 25# 30/11/07 Changed URL to point to hercules-390.org. (JRM) 26# 30/11/10 Remove obsolete CVS test, add special gsed test for Apple/Darwin 27# (Enrico Sorichetti by Fish) 28# 06/12/10 M4 fix (Enrico Sorichetti by Fish) 29#**************************************************************************** 30 31use strict; 32 33# Facility, required level, special flag, download URL 34 35my @req = qw( 36 autoconf 2.5 0 http://www.gnu.org/directory/autoconf.html 37 automake 1.9 0 http://www.gnu.org/directory/automake.html 38 gawk 3.0 0 http://www.gnu.org/directory/gawk.html 39 gcc 3 0 http://www.gnu.org/directory/gcc.html 40 grep 1 0 http://www.gnu.org/directory/grep.html 41 libiconv 1.8 1 http://www.gnu.org/directory/libiconv.html 42 m4 1.4.6 0 http://www.gnu.org/directory/GNU/gnum4.html 43 make 3.79 0 http://www.gnu.org/directory/make.html 44 perl 5.6 1 http://www.gnu.org/directory/perl/html 45 sed 3.02 0 http://www.gnu.org/directory/sed.html 46); 47 48my $msg; 49my $instversion; 50 51sayintro(); 52 53for (my $i = 0; $i < @req; $i += 4) { 54 my $facility = $req[$i]; 55 if ($facility eq 'sed') { 56 if ($^O eq 'darwin') { 57 print "Apple/Darwin ==> sed changed to gsed!\n" ; 58 $facility = 'gsed'; 59 } 60 } 61 62 my $level = $req[$i+1]; 63 my $special = $req[$i+2]; 64 if ($facility eq 'm4') { 65 if ($^O eq 'darwin') { 66 print "Apple/Darwin ==> custom version parsing!\n" ; 67 $special = 1; 68 } 69 } 70 71 my $url = $req[$i+3]; 72 if ($special) { 73 weird($facility, $level, $url); 74 } else { 75 if (present($facility, $url)) { 76 my @resp = `$facility --version`; 77 chomp $resp[0]; 78 $instversion = getvers($resp[0]); 79 $msg = ckvers($level, $instversion); 80 print "$msg\t$facility requires $level, found $instversion\n"; 81 print "\tURL: $url\n" if $msg eq 'UPGRADE'; 82 } 83 } 84 print "\n"; 85} 86 87exit 0; 88 89sub weird { 90 my ($facility, $level, $url) = @_; 91 92 if ($facility eq 'libiconv') { 93 if (present('iconv', $url)) { 94 my @resp = `iconv --version`; 95 chomp $resp[0]; 96 my $instversion = getvers($resp[0]); 97 my $msg = ckvers($level, $instversion); 98 print "$msg\t$facility requires $level, found $instversion\n"; 99 } 100 print "\tURL: $url\n" if $msg eq 'UPGRADE'; 101 return; 102 } 103 if ($facility eq 'perl') { 104 if (present($facility, $url)) { 105 my $instversion = getvers($^V); 106 my $msg = ckvers($level, $instversion); 107 print "$msg\t$facility requires $level, found $instversion\n"; 108 print "\tURL: $url\n" if $msg eq 'UPGRADE'; 109 } 110 return; 111 } 112 if ($facility eq 'libtool') { 113 if (present($facility, $url)) { 114 my @resp = `libtoolize --version`; 115 print "\t$resp[0]\n"; 116 chomp $resp[0]; 117 my $instversion = getvers($resp[0]); 118 my $msg = ckvers($level, $instversion); 119 print "$msg\t$facility requires $level, found $instversion\n"; 120 print "\tURL: $url\n" if $msg eq 'UPGRADE'; 121 } 122 return; 123 } 124 125 if ($facility eq 'm4') { # m4 --version: GNU m4 1.4o 126 if (present($facility, $url)) { 127 my $resp = `m4 --version`; 128 chomp $resp; 129 my $msg = 'HUH? '; 130 my $instversion = "DUNNO"; 131 if ($resp =~ /GNU [mM]4 (\d+.\d+.\d+)/) { 132 $instversion = ''; 133 $instversion = $1 if defined $1; 134 $instversion = "$1.$2" if defined $1 && defined $2; 135 $instversion = "$1.$2.$3" if defined $1 && defined $2 && defined $3; 136 $msg = ckvers($level, $instversion); 137 } 138 print "$msg\t$facility requires $level, found $instversion\n"; 139 print "\tURL: $url\n" if $msg eq 'UPGRADE'; 140 } 141 return; 142 } 143 print "ERROR $facility flagged as special, not found\n"; 144} 145 146sub getvers { 147 my $resp = $_[0]; 148 my $vers; 149 if ($resp =~ /(\d+).(\d+).(\d+)/) { 150 $vers = "$1.$2.$3"; 151 return $vers; 152 } 153 if ($resp =~ /(\d+).(\d+)/) { 154 $vers = "$1.$2"; 155 return $vers; 156 } 157 print "HUH?\n"; 158} 159 160sub ckvers { 161 my ($reqvers, $instvers) = @_; 162 my @rv = split /\./, $reqvers; 163 my @iv = split /\./, $instvers; 164 for (my $i = 0; $i < @rv; $i++) { 165 if ( (exists $rv[$i]) 166 && (exists $iv[$i]) 167 && ($iv[$i] > $rv[$i]) ) { 168 return 'OK'; 169 } 170 if ( (exists $rv[$i]) 171 && (exists $iv[$i]) 172 && ($iv[$i] < $rv[$i]) ) { 173 return 'UPGRADE'; 174 } 175 } 176 return 'OK'; 177} 178 179sub sayintro { 180 print "This utility will check the level of various utilities needed to build\n"; 181 print "hercules. Checking is done against versions that are KNOWN to work.\n"; 182 print "This doesn't mean a build will NOT succeed with older versions\n"; 183 print "of the utilities, but will give a hint as to what package may need\n"; 184 print "an upgrade if the build ever fails with some odd reason.\n\n\n"; 185} 186 187sub present { 188 my ($facility, $url) = @_; 189 my @present = `which $facility 2>/dev/null`; 190 if (! @present) { 191 print "INSTALL\t$facility not found\n"; 192 print "\tURL: $url\n"; 193 } 194 return scalar @present; 195} 196