Changeset 1974
- Timestamp:
- 12/04/07 21:25:54 (7 months ago)
- Files:
-
- swish-e/trunk/perl/Makefile.PL (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
swish-e/trunk/perl/Makefile.PL
r1743 r1974 3 3 use strict; 4 4 use ExtUtils::MakeMaker; 5 use Config; # for path separator 6 use File::Spec; # for catpath 7 use File::Basename; # for locating swish-e binary based on location of swish-config 5 use Config; # for path separator 6 use File::Spec; # for catpath 7 use File::Basename 8 ; # for locating swish-e binary based on location of swish-config 8 9 9 10 # $Id$ … … 13 14 14 15 my %make_maker_opts = ( 15 NAME => 'SWISH::API',16 VERSION_FROM => 'API.pm',17 AUTHOR => 'Bill Moseley',18 ABSTRACT => 'Perl interface to the swish-e search library',16 NAME => 'SWISH::API', 17 VERSION_FROM => 'API.pm', 18 AUTHOR => 'Bill Moseley', 19 ABSTRACT => 'Perl interface to the swish-e search library', 19 20 20 21 # Set LIBS and INC from swish-confg 21 22 22 NORECURS => 1, # keep it from recursing into subdirectories 23 DIR => [], 24 XSPROTOARG => '-noprototypes', 25 PREREQ_PM => { 26 'File::Spec' => '0.8', 27 }, 28 test => { 29 TESTS => 't/*.t', 30 }, 31 clean => { 32 FILES => join( ' ', qw( 33 t/index.swish-e 34 t/index.swish-e.prop 35 )), 23 NORECURS => 1, # keep it from recursing into subdirectories 24 DIR => [], 25 XSPROTOARG => '-noprototypes', 26 PREREQ_PM => { 'File::Spec' => '0.8', }, 27 test => { TESTS => 't/*.t', }, 28 clean => { 29 FILES => join( 30 ' ', qw( 31 t/index.swish-e 32 t/index.swish-e.prop 33 ) 34 ), 36 35 }, 37 36 ); 38 39 37 40 38 my $SWISH_BINARY = 'swish-e'; … … 42 40 my $MIN_VERSION = '2.4.3'; 43 41 44 45 my @valid_params = qw/ 42 my @valid_params = qw/ 46 43 SWISHBINDIR SWISHHELP SWISHIGNOREVER SWISHSKIPTEST 47 44 SWISHLIBS SWISHINC SWISHVERSION 48 /; 49 50 51 45 /; 52 46 53 47 my $help = <<EOF; … … 81 75 EOF 82 76 83 $SIG{__DIE__} = sub { 84 print STDERR "\n ** ERROR: ", @_; 85 print STDERR " Run perl Makefile.PL SWISHHELP for options\n\n"; 86 exit 1; 87 }; 77 END { 78 print STDERR "Run perl Makefile.PL SWISHHELP for options\n\n" if $?; 79 } 88 80 89 81 #---------------------------------------------------------------------------------- … … 92 84 # Swish variables get placed in $ENV. 93 85 94 my %config = load_command_line( @valid_params);86 my %config = load_command_line(@valid_params); 95 87 96 88 if ( exists $ENV{SWISHHELP} ) { … … 99 91 } 100 92 101 102 93 # Get LIBS INC and VERSION from either swish-config or command line/$ENV 103 94 … … 106 97 $config{$_} ||= $swish_config{$_} for qw/ LIBS INC /; 107 98 108 109 99 test_version( $swish_config{VERSION}, $MIN_VERSION ) 110 or die "Swish version $swish_config{VERSION} is older than required version $MIN_VERSION\n"; 111 112 100 or die 101 "Swish version $swish_config{VERSION} is older than required version $MIN_VERSION\n"; 113 102 114 103 # Create test index -- needed for make test 115 104 116 117 105 unless ( exists $ENV{SWISHSKIPTEST} ) { 118 106 119 my $swish_binary = File::Spec->catdir( $swish_config{BINDIR}, $SWISH_BINARY ); 120 create_index( $swish_binary ); 121 122 } else { 107 my $swish_binary 108 = File::Spec->catdir( $swish_config{BINDIR}, $SWISH_BINARY ); 109 create_index($swish_binary); 110 111 } 112 else { 123 113 $config{test}{TESTS} = 't/dummy.t'; 124 114 } 125 115 126 127 128 129 116 WriteMakefile( %make_maker_opts, %config ); 130 131 117 132 118 #---------------------------------------------------------------------------------- … … 139 125 return 1 if exists $ENV{SWISHIGNOREVER}; 140 126 141 my @tags = qw/ running_swish_version required_version /;127 my @tags = qw/ running_swish_version required_version /; 142 128 my @versions = qw/ major minor release /; 143 129 144 130 @versions{@tags} = @_; 145 131 146 147 for ( @tags ) { 132 for (@tags) { 148 133 die "Failed to find version for $_\n" unless $versions{$_}; 149 134 die "Failed to parse version ($versions{$_}) for $_\n" 150 135 unless $versions{$_} =~ /(\d+)\.(\d+)\.(\d+)/; 151 136 152 @{$split_vers{$_}}{@versions} = ( $1, $2, $3 ); 153 } 154 155 for ( @versions ) { 156 return 1 if $split_vers{running_swish_version}{$_} > $split_vers{required_version}{$_}; 157 return 0 if $split_vers{running_swish_version}{$_} < $split_vers{required_version}{$_}; 158 } 159 return 1; # same version. 137 @{ $split_vers{$_} }{@versions} = ( $1, $2, $3 ); 138 } 139 140 for (@versions) { 141 return 1 142 if $split_vers{running_swish_version}{$_} 143 > $split_vers{required_version}{$_}; 144 return 0 145 if $split_vers{running_swish_version}{$_} 146 < $split_vers{required_version}{$_}; 147 } 148 return 1; # same version. 160 149 } 161 150 … … 181 170 # Otherwise, read from swish-config 182 171 183 184 my $swish_config_path = find_swish_config( $SWISH_CONFIG ); 185 return read_swish_config( $swish_config_path ); 186 } 187 188 172 my $swish_config_path = find_swish_config($SWISH_CONFIG); 173 return read_swish_config($swish_config_path); 174 } 189 175 190 176 #---------------------------------------------------------------------------------- … … 194 180 my $prog = shift; 195 181 196 my $binary = find_program( $prog);182 my $binary = find_program($prog); 197 183 198 184 if ( $ENV{SWISHBINDIR} ) { … … 202 188 203 189 my $p = find_program( $prog, $ENV{SWISHBINDIR} ); 204 die "Failed to find [$prog] in directory $ENV{SWISHBINDIR}: $!" unless $p; 205 206 print "Using config program [$p], but also noticed you have $binary available in \$PATH\n" 190 die "Failed to find [$prog] in directory $ENV{SWISHBINDIR}: $!" 191 unless $p; 192 193 print 194 "Using config program [$p], but also noticed you have $binary available in \$PATH\n" 207 195 if $binary; 208 196 209 197 $binary = $p; 210 198 } 211 212 199 213 200 die "Failed to find [$prog] in PATH\n" unless $binary; … … 224 211 225 212 my %config; 226 $config{VERSION} = backtick( "$binary --version");227 $config{LIBS} = backtick( "$binary --libs");228 $config{INC} = backtick( "$binary --cflags");229 $config{BINDIR } = dirname( $binary);213 $config{VERSION} = backtick("$binary --version"); 214 $config{LIBS} = backtick("$binary --libs"); 215 $config{INC} = backtick("$binary --cflags"); 216 $config{BINDIR} = dirname($binary); 230 217 231 218 return %config; 232 219 } 233 234 220 235 221 #---------------------------------------------------------------------------------- … … 242 228 243 229 my %config; 244 while ( $_ = shift @ARGV ) {230 while ( $_ = shift @ARGV ) { 245 231 if ( $_ eq 'SWISHHELP' ) { 246 232 $ENV{SWISHHELP} = 'y'; … … 253 239 die "Invalid option '$param'\n" unless $valid{$param}; 254 240 $ENV{$param} = $value || ''; 255 } else { 241 } 242 else { 256 243 $config{$param} = $value || ''; 257 244 } … … 261 248 } 262 249 263 264 265 250 #---------------------------------------------------------------------------------- 266 251 # Find a program in either $PATH or path/directory passed in. … … 271 256 $search_path ||= $ENV{PATH} || ''; 272 257 273 for my $dir ( split /$Config{path_sep}/, $search_path ) {258 for my $dir ( split /$Config{path_sep}/, $search_path ) { 274 259 my $path = File::Spec->catfile( $dir, $name ); 275 260 276 261 for my $extension ( '', '.exe' ) { 277 262 my $file = $path . $extension; 278 return $file if -x $file && !-d _;263 return $file if -x $file && !-d _; 279 264 } 280 265 } … … 282 267 } 283 268 284 285 269 #---------------------------------------------------------------------------------- 286 270 # Run a program with backtics, checking for errors … … 288 272 289 273 sub backtick { 290 my ( $command) = @_;274 my ($command) = @_; 291 275 292 276 my $output = `$command`; 293 277 294 my $status = $? == 0 295 ? '' 296 : $? == -1 297 ? "Failed to execute: $!" 298 : $? & 127 299 ? sprintf("Child died with signal %d, %s corefile", ($? & 127), ($? & 128) ? 'with' : 'without' ) 300 : sprintf("chiled exited with value %d", $? >> 8); 278 my $status 279 = $? == 0 ? '' 280 : $? == -1 ? "Failed to execute: $!" 281 : $? & 127 ? sprintf( 282 "Child died with signal %d, %s corefile", 283 ( $? & 127 ), 284 ( $? & 128 ) ? 'with' : 'without' 285 ) 286 : sprintf( "chiled exited with value %d", $? >> 8 ); 301 287 302 288 die "Failed to run program [$command]: $status\n" if $status; … … 306 292 } 307 293 308 309 310 294 sub create_index { 311 295 my ($swish) = @_; … … 315 299 316 300 my $index = 't/index.swish-e'; 317 my $conf = 't/test.conf'; 318 301 my $conf = 't/test.conf'; 319 302 320 303 unlink $index if -e $index; 321 304 322 my @command = ( $swish, '-c', $conf, '-f', $index, '-v','0' ); 323 305 my @command = ( $swish, '-c', $conf, '-f', $index, '-v', '0' ); 324 306 325 307 print "Creating index...'@command'\n\n";
