| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
$| = 1; |
|---|
| 95 |
|
|---|
| 96 |
use strict; |
|---|
| 97 |
require 5.006; |
|---|
| 98 |
use sigtrap qw(die normal-signals error-signals); |
|---|
| 99 |
use Getopt::Long; |
|---|
| 100 |
use Config qw( %Config ); |
|---|
| 101 |
use Cwd; |
|---|
| 102 |
use File::Basename; |
|---|
| 103 |
use File::Path qw( mkpath ); |
|---|
| 104 |
use File::Spec; |
|---|
| 105 |
use FindBin qw( $Bin ); |
|---|
| 106 |
|
|---|
| 107 |
my $Version = '0.13'; |
|---|
| 108 |
|
|---|
| 109 |
my %URLs = ( |
|---|
| 110 |
|
|---|
| 111 |
'swish-e' => 'http://swish-e.org/distribution/latest.tar.gz', |
|---|
| 112 |
'zlib' => 'http://www.zlib.net/zlib-1.2.3.tar.gz', |
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 |
'libxml2' => 'ftp://xmlsoft.org/libxml2/LATEST_LIBXML2', |
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 |
'xpdf' => 'http://peknet.com/src/xpdf-3.01pl2.tar.gz', |
|---|
| 122 |
|
|---|
| 123 |
); |
|---|
| 124 |
|
|---|
| 125 |
my $swish_svn = 'http://svn.swish-e.org/swish-e/trunk'; |
|---|
| 126 |
my $svn_cmd = "svn -q co "; |
|---|
| 127 |
|
|---|
| 128 |
my $defdir = '/usr/local/swish-e/latest'; |
|---|
| 129 |
my $deftmp = $ENV{TMPDIR} || $ENV{TMP} || $ENV{CRAYDOC_TMP} || '/tmp'; |
|---|
| 130 |
|
|---|
| 131 |
my $opts = {}; |
|---|
| 132 |
|
|---|
| 133 |
my $usage_gutter = 25; |
|---|
| 134 |
|
|---|
| 135 |
my $allopts = { |
|---|
| 136 |
|
|---|
| 137 |
'quiet' => "run non-interactively", |
|---|
| 138 |
'svn' => "use latest Subversion trunk version of Swish-e", |
|---|
| 139 |
'swish-e=s' => |
|---|
| 140 |
"use <X> as Swish-e source -- either URL, tar.gz or directory", |
|---|
| 141 |
'libxml2=s' => |
|---|
| 142 |
"use <X> as libxml2 source -- either URL, tar.gz or directory", |
|---|
| 143 |
'zlib=s' => "use <X> as zlib source -- either URL, tar.gz or directory", |
|---|
| 144 |
'prevzlib=s' => "use already-installed zlib in directory <X>", |
|---|
| 145 |
'prevxml2=s' => "use already-installed libxml2 in directory <X>", |
|---|
| 146 |
'installdir=s' => "install in <X> [$defdir]", |
|---|
| 147 |
'verbose' => "don't send compiler output to log, send it to stdout", |
|---|
| 148 |
'srcdir=s' => "look in <X> for all src tar.gz files [./]", |
|---|
| 149 |
'tmpdir=s' => "use <X> to unpack tar files, compile and test [$deftmp]", |
|---|
| 150 |
'help' => "print usage statement", |
|---|
| 151 |
'opts' => "print options and description", |
|---|
| 152 |
'force' => "install zlib and libxml2 no matter what", |
|---|
| 153 |
'debug' => "lots of on-screen verbage", |
|---|
| 154 |
'sudo' => "run 'make' commands with sudo\n" |
|---|
| 155 |
. ' ' x $usage_gutter |
|---|
| 156 |
. "!! must be interactive if sudo expects a password !!", |
|---|
| 157 |
'static' => "build with --disable-shared flag", |
|---|
| 158 |
'progress' => |
|---|
| 159 |
"with --quiet, will print a few important progress messages to stdout", |
|---|
| 160 |
'make=s' => |
|---|
| 161 |
"use <X> as make command (useful if your GNU make is named gmake)", |
|---|
| 162 |
'errlog=s' => 'write build errors to <X> file instead of stderr', |
|---|
| 163 |
'perllib=s' => "install SWISH::API in <X>\n" |
|---|
| 164 |
. ' ' x $usage_gutter |
|---|
| 165 |
. "[ $Config{sitearch} ]", |
|---|
| 166 |
'xpdf=s' => 'use <X> as xpdf source -- either URL, tar.gz or directory', |
|---|
| 167 |
'noxpdf' => "don't install xpdf", |
|---|
| 168 |
'increm' => "build swish-e with experimental incremental feature", |
|---|
| 169 |
|
|---|
| 170 |
}; |
|---|
| 171 |
|
|---|
| 172 |
my $helpful = <<EOF; |
|---|
| 173 |
Please send email to the author with this message. |
|---|
| 174 |
Include all screen output and a description of your problem. |
|---|
| 175 |
Thanks. |
|---|
| 176 |
|
|---|
| 177 |
EOF |
|---|
| 178 |
|
|---|
| 179 |
usage() unless GetOptions($opts, keys %$allopts); |
|---|
| 180 |
usage() if $opts->{help}; |
|---|
| 181 |
|
|---|
| 182 |
if ($opts->{opts}) |
|---|
| 183 |
{ |
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 |
printopts(); |
|---|
| 187 |
exit; |
|---|
| 188 |
} |
|---|
| 189 |
|
|---|
| 190 |
|
|---|
| 191 |
|
|---|
| 192 |
use vars qw( |
|---|
| 193 |
$os $arch $cc $installdir $nogcc $min_gcc $tmpdir |
|---|
| 194 |
$outlog $errlog $output $ld_opts $Cout $Cin |
|---|
| 195 |
$zlib_test $libxml2_test $ld_test $gcc_test |
|---|
| 196 |
$swishdir $fetcher $libxml2dir $zlibdir $MinLibxml2 $cmdout |
|---|
| 197 |
$Make $startdir $swish_api_dir $perllib |
|---|
| 198 |
|
|---|
| 199 |
); |
|---|
| 200 |
|
|---|
| 201 |
$zlibdir = $opts->{prevzlib} || ''; |
|---|
| 202 |
$libxml2dir = $opts->{prevxml2} || ''; |
|---|
| 203 |
|
|---|
| 204 |
|
|---|
| 205 |
$installdir = $opts->{installdir} || $defdir; |
|---|
| 206 |
$installdir =~ s,/+$,,; |
|---|
| 207 |
$perllib = $opts->{perllib} || "$Config{sitearch}/../"; |
|---|
| 208 |
$startdir = Cwd::cwd(); |
|---|
| 209 |
$MinLibxml2 = '2.4.3'; |
|---|
| 210 |
|
|---|
| 211 |
|
|---|
| 212 |
|
|---|
| 213 |
|
|---|
| 214 |
$nogcc = "I refuse to compile without gcc\nCheck out http://gcc.gnu.org\n"; |
|---|
| 215 |
$min_gcc = '2.95'; |
|---|
| 216 |
$tmpdir = $opts->{tmpdir} || $deftmp; |
|---|
| 217 |
$outlog = $tmpdir . '/buildswishe.log'; |
|---|
| 218 |
$errlog = $opts->{errlog} || ''; |
|---|
| 219 |
$output = $opts->{verbose} ? '' : " 1>>$outlog"; |
|---|
| 220 |
$output .= " 2>>$errlog " if $errlog; |
|---|
| 221 |
|
|---|
| 222 |
$cmdout = $opts->{quiet} ? ' 1>/dev/null 2>/dev/null ' : ''; |
|---|
| 223 |
|
|---|
| 224 |
$ld_opts = ''; |
|---|
| 225 |
|
|---|
| 226 |
$Make = $opts->{make} || 'make'; |
|---|
| 227 |
|
|---|
| 228 |
|
|---|
| 229 |
$Cout = "$tmpdir/test"; |
|---|
| 230 |
$Cin = "$tmpdir/$$.c"; |
|---|
| 231 |
|
|---|
| 232 |
$zlib_test = <<EOF; |
|---|
| 233 |
|
|---|
| 234 |
|
|---|
| 235 |
|
|---|
| 236 |
int main ( void ) |
|---|
| 237 |
{ |
|---|
| 238 |
printf("%s\\n", ZLIB_VERSION); |
|---|
| 239 |
return 0; |
|---|
| 240 |
|
|---|
| 241 |
} |
|---|
| 242 |
|
|---|
| 243 |
EOF |
|---|
| 244 |
|
|---|
| 245 |
$ld_test = <<EOF; |
|---|
| 246 |
|
|---|
| 247 |
int main( void ) |
|---|
| 248 |
{ |
|---|
| 249 |
printf("success!\\n"); |
|---|
| 250 |
return 0; |
|---|
| 251 |
} |
|---|
| 252 |
|
|---|
| 253 |
|
|---|
| 254 |
EOF |
|---|
| 255 |
|
|---|
| 256 |
|
|---|
| 257 |
$libxml2_test = <<EOF; |
|---|
| 258 |
|
|---|
| 259 |
|
|---|
| 260 |
|
|---|
| 261 |
int main ( void ) |
|---|
| 262 |
{ |
|---|
| 263 |
printf("%s\\n", LIBXML_DOTTED_VERSION); |
|---|
| 264 |
return 0; |
|---|
| 265 |
|
|---|
| 266 |
} |
|---|
| 267 |
|
|---|
| 268 |
EOF |
|---|
| 269 |
|
|---|
| 270 |
|
|---|
| 271 |
|
|---|
| 272 |
$gcc_test = <<EOF; |
|---|
| 273 |
|
|---|
| 274 |
int main ( void ) |
|---|
| 275 |
{ |
|---|
| 276 |
|
|---|
| 277 |
printf("not gcc!\\n"); |
|---|
| 278 |
return 1; |
|---|
| 279 |
|
|---|
| 280 |
|
|---|
| 281 |
printf("yep, gcc\\n"); |
|---|
| 282 |
return 0; |
|---|
| 283 |
|
|---|
| 284 |
|
|---|
| 285 |
} |
|---|
| 286 |
|
|---|
| 287 |
EOF |
|---|
| 288 |
|
|---|
| 289 |
|
|---|
| 290 |
|
|---|
| 291 |
checkenv(); |
|---|
| 292 |
makedirs(); |
|---|
| 293 |
sanity(); |
|---|
| 294 |
|
|---|
| 295 |
my %routines = ( |
|---|
| 296 |
|
|---|
| 297 |
libxml2 => \&libxml2, |
|---|
| 298 |
zlib => \&zlib, |
|---|
| 299 |
'swish-e' => \&swishe, |
|---|
| 300 |
'swish::api' => \&swish_api, |
|---|
| 301 |
xpdf => \&xpdf, |
|---|
| 302 |
|
|---|
| 303 |
); |
|---|
| 304 |
|
|---|
| 305 |
my @toinstall = qw( zlib libxml2 swish-e swish::api ); |
|---|
| 306 |
|
|---|
| 307 |
push(@toinstall, 'xpdf') unless $opts->{noxpdf}; |
|---|
| 308 |
|
|---|
| 309 |
for (@toinstall) |
|---|
| 310 |
{ |
|---|
| 311 |
|
|---|
| 312 |
my $prevout; |
|---|
| 313 |
if ($opts->{progress}) |
|---|
| 314 |
{ |
|---|
| 315 |
|
|---|
| 316 |
$prevout = select STDOUT; |
|---|
| 317 |
|
|---|
| 318 |
} |
|---|
| 319 |
print '=' x 60 . "\n"; |
|---|
| 320 |
print "building $_ ...\n"; |
|---|
| 321 |
print '~' x 60 . "\n"; |
|---|
| 322 |
|
|---|
| 323 |
if ($opts->{progress}) |
|---|
| 324 |
{ |
|---|
| 325 |
|
|---|
| 326 |
select $prevout; |
|---|
| 327 |
|
|---|
| 328 |
} |
|---|
| 329 |
|
|---|
| 330 |
my $f = $routines{$_}; |
|---|
| 331 |
&$f; |
|---|
| 332 |
|
|---|
| 333 |
} |
|---|
| 334 |
|
|---|
| 335 |
test(); |
|---|
| 336 |
cleanup(); |
|---|
| 337 |
exit; |
|---|
| 338 |
|
|---|
| 339 |
END |
|---|
| 340 |
{ |
|---|
| 341 |
unless ($opts->{debug}) |
|---|
| 342 |
{ |
|---|
| 343 |
unlink("$tmpdir/$$.c", "$tmpdir/test") if $tmpdir; |
|---|
| 344 |
} |
|---|
| 345 |
} |
|---|
| 346 |
|
|---|
| 347 |
|
|---|
| 348 |
|
|---|
| 349 |
sub printopts |
|---|
| 350 |
{ |
|---|
| 351 |
print "\n$0 options\n", '-' x 30, "\n"; |
|---|
| 352 |
print "defaults print in [ ] \n"; |
|---|
| 353 |
for (sort keys %$allopts) |
|---|
| 354 |
{ |
|---|
| 355 |
|
|---|
| 356 |
(my $o = $_) =~ s,[:=]s,=<X>,g; |
|---|
| 357 |
|
|---|
| 358 |
my $space = ' ' x ($usage_gutter - length($o)); |
|---|
| 359 |
|
|---|
| 360 |
print " --$o $space $allopts->{$_}\n"; |
|---|
| 361 |
} |
|---|
| 362 |
print "\n\n"; |
|---|
| 363 |
exit; |
|---|
| 364 |
} |
|---|
| 365 |
|
|---|
| 366 |
sub usage |
|---|
| 367 |
{ |
|---|
| 368 |
|
|---|
| 369 |
system("perldoc $0"); |
|---|
| 370 |
printopts(); |
|---|
| 371 |
exit; |
|---|
| 372 |
|
|---|
| 373 |
} |
|---|
| 374 |
|
|---|
| 375 |
sub checkenv |
|---|
| 376 |
{ |
|---|
| 377 |
|
|---|
| 378 |
if ($opts->{quiet}) |
|---|
| 379 |
{ |
|---|
| 380 |
|
|---|
| 381 |
open(QUIET, ">/dev/null") or die "can't write to /dev/null: $!\n"; |
|---|
| 382 |
select(QUIET); |
|---|
| 383 |
|
|---|
| 384 |
} |
|---|
| 385 |
|
|---|
| 386 |
$os = $Config{osname} || $ENV{OSTYPE} || `uname`; |
|---|
| 387 |
$arch = $Config{archname}; |
|---|
| 388 |
$cc = $Config{cc}; |
|---|
| 389 |
|
|---|
| 390 |
|
|---|
| 391 |
if ($opts->{progress}) |
|---|
| 392 |
{ |
|---|
| 393 |
print STDOUT "os... $os\n"; |
|---|
| 394 |
print STDOUT "arch... $arch\n"; |
|---|
| 395 |
print STDOUT "cc... $cc\n"; |
|---|
| 396 |
print STDOUT "opt: $_ -> $opts->{$_}\n" for sort keys %$opts; |
|---|
| 397 |
} |
|---|
| 398 |
|
|---|
| 399 |
unlink $outlog, $errlog; |
|---|
| 400 |
|
|---|
| 401 |
|
|---|
| 402 |
|
|---|
| 403 |
|
|---|
| 404 |
ld_opts(); |
|---|
| 405 |
set_fetcher(); |
|---|
| 406 |
} |
|---|
| 407 |
|
|---|
| 408 |
sub makedirs |
|---|
| 409 |
{ |
|---|
| 410 |
|
|---|
| 411 |
my @d = |
|---|
| 412 |
($installdir, $tmpdir, "$installdir/lib", "$installdir/include", |
|---|
| 413 |
$perllib); |
|---|
| 414 |
mkpath(\@d, 1, 0755); |
|---|
| 415 |
for (@d) |
|---|
| 416 |
{ |
|---|
| 417 |
|
|---|
| 418 |
if ($opts->{progress}) |
|---|
| 419 |
{ |
|---|
| 420 |
print STDOUT "checking dir $_ ... "; |
|---|
| 421 |
} |
|---|
| 422 |
unless (-W $_) |
|---|
| 423 |
{ |
|---|
| 424 |
warn "can't write to $_: $!\n"; |
|---|
| 425 |
nice_exit(); |
|---|
| 426 |
} |
|---|
| 427 |
if ($opts->{progress}) |
|---|
| 428 |
{ |
|---|
| 429 |
print STDOUT "\n"; |
|---|
| 430 |
} |
|---|
| 431 |
} |
|---|
| 432 |
|
|---|
| 433 |
} |
|---|
| 434 |
|
|---|
| 435 |
sub sanity |
|---|
| 436 |
{ |
|---|
| 437 |
|
|---|
| 438 |
test_make(); |
|---|
| 439 |
|
|---|
| 440 |
print "is $cc a GNU C compiler... "; |
|---|
| 441 |
test_compiler(); |
|---|
| 442 |
|
|---|
| 443 |
|
|---|
| 444 |
if (test_c_prog($ld_test, '-lc')) |
|---|
| 445 |
{ |
|---|
| 446 |
|
|---|
| 447 |
die "can't link against libc with $cc\n"; |
|---|
| 448 |
|
|---|
| 449 |
} |
|---|
| 450 |
|
|---|
| 451 |
unless ($opts->{quiet}) |
|---|
| 452 |
{ |
|---|
| 453 |
|
|---|
| 454 |
print "Continue on our merry way? [y] "; |
|---|
| 455 |
nice_exit() unless confirm(); |
|---|
| 456 |
|
|---|
| 457 |
} |
|---|
| 458 |
|
|---|
| 459 |
} |
|---|
| 460 |
|
|---|
| 461 |
sub test_c_prog |
|---|
| 462 |
{ |
|---|
| 463 |
my $prog = shift; |
|---|
| 464 |
|
|---|
| 465 |
|
|---|
| 466 |
|
|---|
| 467 |
my $test = pop @_ if ref $_[-1] eq 'SCALAR'; |
|---|
| 468 |
|
|---|
| 469 |
|
|---|
| 470 |
open(TMP, "> $tmpdir/$$.c") || die "can't write to $tmpdir\n"; |
|---|
| 471 |
print TMP $prog; |
|---|
| 472 |
close(TMP); |
|---|
| 473 |
|
|---|
| 474 |
|
|---|
| 475 |
my $extra = join ' ', @_; |
|---|
| 476 |
$extra .= ' -w' if $os =~ /irix/i; |
|---|
| 477 |
my $cmd = "$cc $extra -o $Cout $Cin"; |
|---|
| 478 |
|
|---|
| 479 |
print "\n\ncompile cmd: $cmd\n" if $opts->{debug}; |
|---|
| 480 |
|
|---|
| 481 |
return 1 if system("$cmd $cmdout"); |
|---|
| 482 |
|
|---|
| 483 |
if ($test) |
|---|
| 484 |
{ |
|---|
| 485 |
|
|---|
| 486 |
chomp(my $o = `$Cout`); |
|---|
| 487 |
|
|---|
| 488 |
if ($o lt $$test) |
|---|
| 489 |
{ |
|---|
| 490 |
|
|---|
| 491 |
print $o . " -- failed!\n"; |
|---|
| 492 |
|
|---|
| 493 |
return 1; |
|---|
| 494 |
|
|---|
| 495 |
} |
|---|
| 496 |
|
|---|
| 497 |
} |
|---|
| 498 |
|
|---|
| 499 |
|
|---|
| 500 |
|
|---|
| 501 |
warn "run: $Cout $cmdout\n" if $opts->{debug}; |
|---|
| 502 |
|
|---|
| 503 |
return system("$Cout $cmdout"); |
|---|
| 504 |
|
|---|
| 505 |
} |
|---|
| 506 |
|
|---|
| 507 |
|
|---|
| 508 |
|
|---|
| 509 |
sub test_for_prior_zlib |
|---|
| 510 |
{ |
|---|
| 511 |
return undef if $opts->{force}; |
|---|
| 512 |
|
|---|
| 513 |
print "testing for already-installed zlib... "; |
|---|
| 514 |
|
|---|
| 515 |
my $err = test_c_prog($zlib_test, '-lz', $ld_opts); |
|---|
| 516 |
|
|---|
| 517 |
return get_ld_path('libz', '', \$zlibdir) unless $err; |
|---|
| 518 |
|
|---|
| 519 |
return 0; |
|---|
| 520 |
} |
|---|
| 521 |
|
|---|
| 522 |
sub test_for_prior_libxml2 |
|---|
| 523 |
{ |
|---|
| 524 |
|
|---|
| 525 |
return undef if $opts->{force}; |
|---|
| 526 |
|
|---|
| 527 |
print "testing for already-installed libxml2... "; |
|---|
| 528 |
|
|---|
| 529 |
|
|---|
| 530 |
|
|---|
| 531 |
my $path = get_ld_path('libxml2', '', \$libxml2dir) |
|---|
| 532 |
unless test_c_prog($ld_test, $ld_opts, '-lxml2'); |
|---|
| 533 |
|
|---|
| 534 |
|
|---|
| 535 |
|
|---|
| 536 |
return 0 unless $path; |
|---|
| 537 |
|
|---|
| 538 |
print "minimum libxml2 version required is $MinLibxml2 and you have... "; |
|---|
| 539 |
|
|---|
| 540 |
|
|---|
| 541 |
my $err = |
|---|
| 542 |
test_c_prog( |
|---|
| 543 |
$libxml2_test, |
|---|
| 544 |
'-I' . File::Spec->catfile($installdir, 'include', 'libxml2'), |
|---|
| 545 |
'-I' . File::Spec->catfile($path, 'include', 'libxml2'), |
|---|
| 546 |
$ld_opts, |
|---|
| 547 |
'-lxml2', |
|---|
| 548 |
\$MinLibxml2 |
|---|
| 549 |
); |
|---|
| 550 |
|
|---|
| 551 |
return get_ld_path('libxml2', '', \$libxml2dir) unless $err; |
|---|
| 552 |
|
|---|
| 553 |
return 0; |
|---|
| 554 |
|
|---|
| 555 |
} |
|---|
| 556 |
|
|---|
| 557 |
sub cleanup |
|---|
| 558 |
{ |
|---|
| 559 |
|
|---|
| 560 |
print STDOUT "Swish-e was installed in $installdir\n"; |
|---|
| 561 |
print STDOUT "SWISH::API was installed in $swish_api_dir\n"; |
|---|
| 562 |
|
|---|
| 563 |
} |
|---|
| 564 |
|
|---|
| 565 |
sub test |
|---|
| 566 |
{ |
|---|
| 567 |
|
|---|
| 568 |
test_api(); |
|---|
| 569 |
|
|---|
| 570 |
} |
|---|
| 571 |
|
|---|
| 572 |
sub set_fetcher |
|---|
| 573 |
{ |
|---|
| 574 |
|
|---|
| 575 |
|
|---|
| 576 |
|
|---|
| 577 |
|
|---|
| 578 |
$fetcher = which('wget'); |
|---|
| 579 |
$fetcher ||= which('curl'); |
|---|
| 580 |
$fetcher ||= perl_fetcher(); |
|---|
| 581 |
print "no program available to fetch remote sw source\n" unless $fetcher; |
|---|
| 582 |
|
|---|
| 583 |
} |
|---|
| 584 |
|
|---|
| 585 |
sub perl_fetcher |
|---|
| 586 |
{ |
|---|
| 587 |
print "trying LWP::Simple\n"; |
|---|
| 588 |
eval { require LWP::Simple }; |
|---|
| 589 |
$@ ? return 0 : return \&LWP::Simple::getstore; |
|---|
| 590 |
|
|---|
| 591 |
} |
|---|
| 592 |
|
|---|
| 593 |
sub which |
|---|
| 594 |
{ |
|---|
| 595 |
|
|---|
| 596 |
chomp(my $w = `which $_[0] 2>&1`); |
|---|
| 597 |
$w =~ s,\n,,g; |
|---|
| 598 |
$w !~ m/not found|^[^\/]/i |
|---|
| 599 |
? $w |
|---|
| 600 |
: 0; |
|---|
| 601 |
|
|---|
| 602 |
} |
|---|
| 603 |
|
|---|
| 604 |
sub test_compiler |
|---|
| 605 |
{ |
|---|
| 606 |
|
|---|
| 607 |
|
|---|
| 608 |
|
|---|
| 609 |
if (test_c_prog($gcc_test)) |
|---|
| 610 |
{ |
|---|
| 611 |
warn "Warning: this perl was not compiled with gcc!\n" |
|---|
| 612 |
. "Instead: $cc\n" |
|---|
| 613 |
. "This may cause compile of SWISH::API to fail.\n" |
|---|
| 614 |
. "We'll try anyway, but be warned.\n"; |
|---|
| 615 |
|
|---|
| 616 |
|
|---|
| 617 |
my $gcc = which('gcc'); |
|---|
| 618 |
if ($gcc) |
|---|
| 619 |
{ |
|---|
| 620 |
print "Found a gcc at $gcc\n"; |
|---|
| 621 |
if ($opts->{interactive}) |
|---|
| 622 |
{ |
|---|
| 623 |
print "Should I use that? [yes] "; |
|---|
| 624 |
if (confirm()) |
|---|
| 625 |
{ |
|---|
| 626 |
$cc = $gcc; |
|---|
| 627 |
} |
|---|
| 628 |
else |
|---|
| 629 |
{ |
|---|
| 630 |
print $nogcc; |
|---|
| 631 |
nice_exit(); |
|---|
| 632 |
} |
|---|
| 633 |
} |
|---|
| 634 |
else |
|---|
| 635 |
{ |
|---|
| 636 |
$cc = $gcc; |
|---|
| 637 |
} |
|---|
| 638 |
|
|---|
| 639 |
} |
|---|
| 640 |
else |
|---|
| 641 |
{ |
|---|
| 642 |
|
|---|
| 643 |
|
|---|
| 644 |
return 0; |
|---|
| 645 |
} |
|---|
| 646 |
} |
|---|
| 647 |
|
|---|
| 648 |
|
|---|
| 649 |
|
|---|
| 650 |
print "testing gcc version... "; |
|---|
| 651 |
my @v = `$cc -v 2>&1`; |
|---|
| 652 |
my @vers = grep { /version \d/ } @v; |
|---|
| 653 |
if (!@vers) |
|---|
| 654 |
{ |
|---|
| 655 |
warn "Warning: trouble getting version from $cc\n" |
|---|
| 656 |
. "Minimum version required is $min_gcc\n" |
|---|
| 657 |
. "We'll try anyway.\n"; |
|---|
| 658 |
} |
|---|
| 659 |
else |
|---|
| 660 |
{ |
|---|
| 661 |
V: for (@vers) |
|---|
| 662 |
{ |
|---|
| 663 |
next if !m/version \d/; |
|---|
| 664 |
my ($v) = ($_ =~ m/version ([\d\.]+)/); |
|---|
| 665 |
$v =~ s,^(\d\.\d+)\.?(\d*?),$1$2,g; |
|---|
| 666 |
if ($v < $min_gcc) |
|---|
| 667 |
{ |
|---|
| 668 |
die "Minimum version of gcc is $min_gcc\n"; |
|---|
| 669 |
} |
|---|
| 670 |
else |
|---|
| 671 |
{ |
|---|
| 672 |
print "version $v\n"; |
|---|
| 673 |
} |
|---|
| 674 |
} |
|---|
| 675 |
} |
|---|
| 676 |
|
|---|
| 677 |
} |
|---|
| 678 |
|
|---|
| 679 |
sub ld_opts |
|---|
| 680 |
{ |
|---|
| 681 |
|
|---|
| 682 |
|
|---|
| 683 |
|
|---|
| 684 |
|
|---|
| 685 |
|
|---|
| 686 |
|
|---|
| 687 |
|
|---|
| 688 |
|
|---|
| 689 |
|
|---|
| 690 |
|
|---|
| 691 |
|
|---|
| 692 |
|
|---|
| 693 |
|
|---|
| 694 |
|
|---|
| 695 |
|
|---|
| 696 |
|
|---|
| 697 |
|
|---|
| 698 |
|
|---|
| 699 |
|
|---|
| 700 |
|
|---|
| 701 |
|
|---|
| 702 |
|
|---|
| 703 |
|
|---|
| 704 |
|
|---|
| 705 |
|
|---|
| 706 |
|
|---|
| 707 |
|
|---|
| 708 |
|
|---|
| 709 |
|
|---|
| 710 |
my @path = ( |
|---|
| 711 |
File::Spec->catfile($installdir, 'lib'), |
|---|
| 712 |
$installdir, $libxml2dir, $zlibdir, '/usr/local', |
|---|
| 713 |
'/usr/local/lib' |
|---|
| 714 |
); |
|---|
| 715 |
|
|---|
| 716 |
my %seen; |
|---|
| 717 |
|
|---|
| 718 |
$ENV{LD_RUN_PATH} ||= '.'; |
|---|
| 719 |
|
|---|
| 720 |
$ENV{LD_RUN_PATH} = join(':', |
|---|
| 721 |
grep { /./ } map { $seen{$_}++ ? '' : $_ } @path, |
|---|
| 722 |
$ENV{LD_RUN_PATH}); |
|---|
| 723 |
|
|---|
| 724 |
|
|---|
| 725 |
$ENV{LD_LIBRARY_PATH} = ''; |
|---|
| 726 |
|
|---|
| 727 |
|
|---|
| 728 |
|
|---|
| 729 |
if ($os =~ /darwin/i) |
|---|
| 730 |
{ |
|---|
| 731 |
|
|---|
| 732 |
$ENV{DYLD_LIBRARY_PATH} = "$installdir/lib"; |
|---|
| 733 |
$ld_opts = "-Wl,-L" . join(' -Wl,-L', split(/:/, $ENV{LD_RUN_PATH})); |
|---|
| 734 |
|
|---|
| 735 |
|
|---|
| 736 |
} |
|---|
| 737 |
elsif ($os =~ /irix/i) |
|---|
| 738 |
{ |
|---|
| 739 |
|
|---|
| 740 |
$ld_opts = "-Wl,-L" . join(' -Wl,-L', split(/:/, $ENV{LD_RUN_PATH})); |
|---|
| 741 |
|
|---|
| 742 |
|
|---|
| 743 |
|
|---|
| 744 |
$ENV{LD_LIBRARYN32_PATH} = $ENV{LD_RUN_PATH}; |
|---|
| 745 |
|
|---|
| 746 |
|
|---|
| 747 |
} |
|---|
| 748 |
elsif ($os =~ /sun|sol/i) |
|---|
| 749 |
{ |
|---|
| 750 |
$ld_opts = "-Wl,-rpath -Wl,$ENV{LD_RUN_PATH} -L$ENV{LD_RUN_PATH}"; |
|---|
| 751 |
|
|---|
| 752 |
|
|---|
| 753 |
|
|---|
| 754 |
|
|---|
| 755 |
|
|---|
| 756 |
} |
|---|
| 757 |
elsif ($os =~ /linux/i) |
|---|
| 758 |
{ |
|---|
| 759 |
|
|---|
| 760 |
$ld_opts = "-Wl,-L" . join(' -Wl,-L', split(/:/, $ENV{LD_RUN_PATH})); |
|---|
| 761 |
|
|---|
| 762 |
|
|---|
| 763 |
} |
|---|
| 764 |
else |
|---|
| 765 |
{ |
|---|
| 766 |
|
|---|
| 767 |
|
|---|
| 768 |
|
|---|
| 769 |
|
|---|
| 770 |
|
|---|
| 771 |
|
|---|
| 772 |
|
|---|
| 773 |
|
|---|
| 774 |
|
|---|
| 775 |
$ld_opts = "-Wl,-L" . join(' -Wl,-L', split(/:/, $ENV{LD_RUN_PATH})); |
|---|
| 776 |
|
|---|
| 777 |
} |
|---|
| 778 |
|
|---|
| 779 |
|
|---|
| 780 |
|
|---|
| 781 |
$ld_opts .= " -I$_/include" |
|---|
| 782 |
for (grep { s,/lib$,, } split(/:/, $ENV{LD_RUN_PATH})); |
|---|
| 783 |
|
|---|
| 784 |
if ($opts->{debug}) |
|---|
| 785 |
{ |
|---|
| 786 |
print "LD_RUN_PATH = $ENV{LD_RUN_PATH}\n"; |
|---|
| 787 |
print "ld opts = $ld_opts\n"; |
|---|
| 788 |
} |
|---|
| 789 |
} |
|---|
| 790 |
|
|---|
| 791 |
sub get_ld_path |
|---|
| 792 |
{ |
|---|
| 793 |
my $lib = shift || ''; |
|---|
| 794 |
my $file = shift || $Cout; |
|---|
| 795 |
my $dir = shift; |
|---|
| 796 |
|
|---|
| 797 |
my $cmd = 'ldd'; |
|---|
| 798 |
$cmd = 'otool -L' if $os =~ m/darwin/i; |
|---|
| 799 |
|
|---|
| 800 |
my @s = `$cmd $file`; |
|---|
| 801 |
|
|---|
| 802 |
if ($opts->{debug}) |
|---|
| 803 |
{ |
|---|
| 804 |
warn '-' x 40 . "\n"; |
|---|
| 805 |
warn "ld test for $lib\n"; |
|---|
| 806 |
|
|---|
| 807 |
warn "libraries that ld linked to in $file:\n"; |
|---|
| 808 |
warn "$_" for @s; |
|---|
| 809 |
|
|---|
| 810 |
warn "looking for '/lib/$lib' in array\n"; |
|---|
| 811 |
|
|---|
| 812 |
} |
|---|
| 813 |
|
|---|
| 814 |
|
|---|
| 815 |
|
|---|
| 816 |
my @where = grep { m!/lib[\d]*/$lib! } @s; |
|---|
| 817 |
my $path = shift @where; |
|---|
| 818 |
chomp($path); |
|---|
| 819 |
|
|---|
| 820 |
warn "found path: $path\n" if $opts->{debug}; |
|---|
| 821 |
|
|---|
| 822 |
$path =~ s,^[^/]*,,g; |
|---|
| 823 |
|
|---|
| 824 |
warn "no space: $path\n" if $opts->{debug}; |
|---|
| 825 |
|
|---|
| 826 |
my @c = split(m!/!, $path); |
|---|
| 827 |
|
|---|
| 828 |
my @g; |
|---|
| 829 |
for (@c) |
|---|
| 830 |
{ |
|---|
| 831 |
next if !$_; |
|---|
| 832 |
last if $_ =~ m/^lib\d*$/; |
|---|
| 833 |
warn "adding $_ to \@g\n" if $opts->{debug}; |
|---|
| 834 |
push @g, $_; |
|---|
| 835 |
|
|---|
| 836 |
} |
|---|
| 837 |
|
|---|
| 838 |
$path = '/' . join('/', @g); |
|---|
| 839 |
|
|---|
| 840 |
print "libpath is $path\n"; |
|---|
| 841 |
|
|---|
| 842 |
$$dir = $path; |
|---|
| 843 |
|
|---|
| 844 |
return $path; |
|---|
| 845 |
|
|---|
| 846 |
} |
|---|
| 847 |
|
|---|
| 848 |
sub confirm |
|---|
| 849 |
{ |
|---|
| 850 |
|
|---|
| 851 |
|
|---|
| 852 |
return 1 if $opts->{quiet}; |
|---|
| 853 |
|
|---|
| 854 |
my $i = <>; |
|---|
| 855 |
chomp($i); |
|---|
| 856 |
if (!$i or $i =~ m/^y/) |
|---|
| 857 |
{ |
|---|
| 858 |
return 1; |
|---|
| 859 |
} |
|---|
| 860 |
else |
|---|
| 861 |
{ |
|---|
| 862 |
return 0; |
|---|
| 863 |
} |
|---|
| 864 |
} |
|---|
| 865 |
|
|---|
| 866 |
sub get_src |
|---|
| 867 |
{ |
|---|
| 868 |
|
|---|
| 869 |
|
|---|
| 870 |
|
|---|
| 871 |
my $sw = shift; |
|---|
| 872 |
|
|---|
| 873 |
my $src; |
|---|
| 874 |
|
|---|
| 875 |
|
|---|
| 876 |
|
|---|
| 877 |
DIR: for my $Dir ($tmpdir, $startdir, $Bin) |
|---|
| 878 |
{ |
|---|
| 879 |
|
|---|
| 880 |
chdir($Dir); |
|---|
| 881 |
|
|---|
| 882 |
|
|---|
| 883 |
|
|---|
| 884 |
|
|---|
| 885 |
|
|---|
| 886 |
|
|---|
| 887 |
|
|---|
| 888 |
if ($opts->{srcdir} and !$opts->{$sw}) |
|---|
| 889 |
{ |
|---|
| 890 |
|
|---|
| 891 |
my $dir = $opts->{srcdir}; |
|---|
| 892 |
|
|---|
| 893 |
$dir = File::Spec->catfile($startdir, $dir) if $dir !~ m!^/!; |
|---|
| 894 |
|
|---|
| 895 |
print "looking in $dir for $sw|latest.*tar.gz\n"; |
|---|
| 896 |
|
|---|
| 897 |
my $found = 0; |
|---|
|
|---|