root/swish-e/branches/2.6/buildswishe.pl

Revision 1854, 35.5 kB (checked in by karman, 2 years ago)

perltidy

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 #!/usr/bin/perl -w
2 #
3 #    build swish-e with zlib and libxml2 support.
4 #    tries to be intelligent about OS and compiler
5 #    options.
6 #
7 ################################################################################
8 # History
9 #
10 #   0.01
11 #    initial public release . Wed Sep 15 12:07:55 CDT 2004 . karman@cray.com
12 #
13 #   0.02
14 #    --srcdir works; IRIX fixes; --quiet fixes
15 #
16 #   0.03
17 #    chdir to $Bin to check for cvs build
18 #    include $installdir in -I when checking for preinstalled libxml2
19 #    linux fixes
20 #    added --disable-shared to libxml2 build
21 #    --force actually works
22 #    added --static to make --disable-shared optional
23 #
24 #   0.04
25 #    fixed swishdir/installdir bug
26 #    thanks to chyla@knihovnabbb.cz
27 #
28 #   0.05     Tue Nov 16 07:08:56 CST 2004
29 #    rewrote get_src() with a little more reality in mind
30 #    fixed swish option to refer to swish-e, swish, or swishe
31 #        but look for file called 'swish-e' or 'latest'
32 #    added --progress option to print a few messages under --quiet
33 #    added --make option for when you can't symlink make -> gmake
34 #    libxml2-2.6.16  --- still need to get 'latest' support
35 #
36 #   0.06    Wed Nov 17 08:18:05 CST 2004
37 #    arrgg. need to read my email more thoroughly; libxml 2.6.16 fails
38 #        because of unannounced api change. reverting to .13
39 #    --errlog option; errors now print to stderr instead of to log by default
40 #    SWISHBIN replaced by SWISHBINDIR for making SWISH::API
41 #    --perllib to indicate specific install dir,
42 #        otherwise defaults to perl Config
43 #    usage fixes
44 #
45 #   0.07    Wed Dec  8 15:25:57 CST 2004
46 #    added xpdf to build (mostly for CrayDoc)
47 #    fixed get src logic (again)
48 #    standardized swish,swish-e,swishe debacle
49 #    remember CWD from where we start so relative paths are resolved from opts
50 #    zlib update
51 #    changed libxml2 back to .16 to support 2.4.3 fix
52 #    added swish_api_dir to determine where exactly the swish::api mod is installed
53 #    use File::Basename
54 #    assuming >=2.4.3 is now latest.
55 #    all 3rdparty stuff now has 'latest' URL (thanks to developers!)
56 #    changed default ld_opts to same as Linux, et al.
57 #    fixed SWISH::API LIBS and LDFLAGS opt to work on Solaris
58 #    unset LD_LIBRARY_PATH env var to accurately test linking
59 #
60 #   0.08    Tue Mar 29 14:18:56 CST 2005
61 #    perldoc fixes
62 #    -R optional in ::API build
63 #    xpdf build fixes -- only include pdftotext and pdfinfo
64 #    docs.cray.com URL fix for xpdf
65 #    -s option for zlib configure (default is dynamic/shared libs)
66 #    --disable-docs for new swish-e build
67 #    added --increm feature
68 #    URL fix for new swish-e.org site
69 #    added /usr/local to default LD_RUN_PATH and -I/path for all include paths
70 #
71 #   0.09    Tue Apr 26 09:09:10 CDT 2005
72 #    added libxml2 to swish-e -I path
73 #    fixed xpdf src url
74 #    rewrote perllib logic
75 #    -W test for all install dirs
76 #    thanks to chyla@knihovnabbb.cz for feedback on these fixes/features
77 #
78 #
79 #   0.10    Thu Feb 23 10:44:26 CST 2006
80 #    changed Xpdf URL to peknet patched copy of 3.01pl2
81 #
82 #   0.11    Fri Jul  7 11:15:41 CDT 2006
83 #    changed CVS url per sf.net updates
84 #    updated src URLs
85 #
86 #   0.12    Sat Nov 11 14:58:26 CST 2006
87 #    fixed swish-e get src to respect explicit opt path
88 #
89 ################################################################################
90
91 $| = 1;
92
93 use strict;
94 require 5.006;    # might work with < perl 5.6.0 but untested
95 use sigtrap qw(die normal-signals error-signals);
96 use Getopt::Long;
97 use Config qw( %Config );
98 use Cwd;
99 use File::Basename;
100 use File::Path qw( mkpath );
101 use File::Spec;
102 use FindBin qw( $Bin );
103
104 my $Version = '0.12';
105
106 my %URLs = (
107
108     'swish-e' => 'http://swish-e.org/distribution/latest.tar.gz',
109     'zlib'    => 'http://www.zlib.net/zlib-1.2.3.tar.gz',
110
111     # madler@alumni.caltech.edu assures me that zlib will support a
112     # http://www.zlib.net/zlib-current.tar.gz link but no such link as of
113     # 7/12/2006
114
115     'libxml2' => 'ftp://xmlsoft.org/libxml2/LATEST_LIBXML2',
116
117     # peknet hosts a pre-patched version of XPDF
118     'xpdf' => 'http://peknet.com/src/xpdf-3.01pl2.tar.gz',
119
120 );
121
122 my $swish_cvs = ':pserver:anonymous@swishe.cvs.sourceforge.net:/cvsroot/swishe';
123 my $cvs_cmd   = "cvs -q -d$swish_cvs co swish-e";
124
125 my $defdir = '/usr/local/swish-e/latest';
126 my $deftmp = $ENV{TMPDIR} || $ENV{TMP} || $ENV{CRAYDOC_TMP} || '/tmp';
127
128 my $opts = {};
129
130 my $usage_gutter = 25;
131
132 my $allopts = {
133
134     'quiet'     => "run non-interactively",
135     'cvs'       => "use latest CVS version of Swish-e",
136     'swish-e=s' =>
137       "use <X> as Swish-e source -- either URL, tar.gz or directory",
138     'libxml2=s' =>
139       "use <X> as libxml2 source -- either URL, tar.gz or directory",
140     'zlib=s'     => "use <X> as zlib source -- either URL, tar.gz or directory",
141     'prevzlib=s' => "use already-installed zlib in directory <X>",
142     'prevxml2=s' => "use already-installed libxml2 in directory <X>",
143     'installdir=s' => "install in <X> [$defdir]",
144     'verbose'      => "don't send compiler output to log, send it to stdout",
145     'srcdir=s'     => "look in <X> for all src tar.gz files [./]",
146     'tmpdir=s'     => "use <X> to unpack tar files, compile and test [$deftmp]",
147     'help'         => "print usage statement",
148     'opts'         => "print options and description",
149     'force'        => "install zlib and libxml2 no matter what",
150     'debug'        => "lots of on-screen verbage",
151     'sudo'         => "run 'make' commands with sudo\n"
152       . ' ' x $usage_gutter
153       . "!! must be interactive if sudo expects a password !!",
154     'static'   => "build with --disable-shared flag",
155     'progress' =>
156       "with --quiet, will print a few important progress messages to stdout",
157     'make=s' =>
158       "use <X> as make command (useful if your GNU make is named gmake)",
159     'errlog=s'  => 'write build errors to <X> file instead of stderr',
160     'perllib=s' => "install SWISH::API in <X>\n"
161       . ' ' x $usage_gutter
162       . "[ $Config{sitearch} ]",
163     'xpdf=s' => 'use <X> as xpdf source -- either URL, tar.gz or directory',
164     'noxpdf' => "don't install xpdf",
165     'increm' => "build swish-e with experimental incremental feature",
166
167 };
168
169 my $helpful = <<EOF;
170 Please send email to the author with this message.
171 Include all screen output and a description of your problem.
172 Thanks.
173
174 EOF
175
176 usage() unless GetOptions($opts, keys %$allopts);
177 usage() if $opts->{help};
178
179 if ($opts->{opts})
180 {
181
182     # print all options and descriptions
183     printopts();
184     exit;
185 }
186
187 ################################################################################
188
189 use vars qw(
190   $os $arch $cc $installdir $nogcc $min_gcc $tmpdir
191   $outlog $errlog $output $ld_opts $Cout $Cin
192   $zlib_test $libxml2_test $ld_test $gcc_test
193   $swishdir $fetcher $libxml2dir $zlibdir $MinLibxml2 $cmdout
194   $Make $startdir $swish_api_dir $perllib
195
196   );
197
198 $zlibdir    = $opts->{prevzlib} || '';
199 $libxml2dir = $opts->{prevxml2} || '';
200
201 # some defaults
202 $installdir = $opts->{installdir} || $defdir;
203 $installdir =~ s,/+$,,;
204 $perllib = $opts->{perllib} || "$Config{sitearch}/../";   # must go up one level
205 $startdir = Cwd::cwd();
206 $MinLibxml2 = '2.4.3';
207
208 # we ought to be able to retrieve this from swish src somehow
209 # but we don't have source till after we've tested for this -- chick and egg
210
211 $nogcc   = "I refuse to compile without gcc\nCheck out http://gcc.gnu.org\n";
212 $min_gcc = '2.95';
213 $tmpdir  = $opts->{tmpdir} || $deftmp;
214 $outlog  = $tmpdir . '/buildswishe.log';
215 $errlog  = $opts->{errlog} || '';
216 $output  = $opts->{verbose} ? '' : " 1>>$outlog";
217 $output .= " 2>>$errlog " if $errlog;
218
219 $cmdout = $opts->{quiet} ? ' 1>/dev/null 2>/dev/null ' : '';
220
221 $ld_opts = '';    # define these based on OS platform
222
223 $Make = $opts->{make} || 'make';
224
225 # better C tests would be nice. these seem to work.
226 $Cout = "$tmpdir/test";
227 $Cin  = "$tmpdir/$$.c";
228
229 $zlib_test = <<EOF;
230 #include <stdio.h>
231 #include "zlib.h"
232
233 int main ( void )
234 {
235     printf("%s\\n", ZLIB_VERSION);
236     return 0;
237
238 }
239
240 EOF
241
242 $ld_test = <<EOF;
243 #include <stdio.h>
244 int main( void )
245 {
246    printf("success!\\n");
247    return 0;
248 }
249
250
251 EOF
252
253 # because xml-config doesn't always exist...
254 $libxml2_test = <<EOF;
255 #include <stdio.h>
256 #include "libxml/xmlversion.h"
257
258 int main ( void )
259 {
260     printf("%s\\n", LIBXML_DOTTED_VERSION);
261     return 0;
262
263 }
264
265 EOF
266
267 # gcc might be symlinked from something else, or named cc or some
268 # other weirdness, so test it to be sure
269 $gcc_test = <<EOF;
270 #include <stdio.h>
271 int main ( void )
272 {
273     #ifndef __GNUC__
274            printf("not gcc!\\n");
275            return 1;
276            
277     #else
278         printf("yep, gcc\\n");
279         return 0;
280     #endif
281  
282 }
283
284 EOF
285
286 ##########################################################
287 ## run
288 checkenv();
289 makedirs();
290 sanity();
291
292 my %routines = (
293
294     libxml2      => \&libxml2,
295     zlib         => \&zlib,
296     'swish-e'    => \&swishe,
297     'swish::api' => \&swish_api,
298     xpdf         => \&xpdf,
299
300 );
301
302 my @toinstall = qw( zlib libxml2 swish-e swish::api );    # order matters
303
304 push(@toinstall, 'xpdf') unless $opts->{noxpdf};
305
306 for (@toinstall)
307 {
308
309     my $prevout;
310     if ($opts->{progress})
311     {
312
313         $prevout = select STDOUT;
314
315     }
316     print '=' x 60 . "\n";
317     print "building $_ ...\n";
318     print '~' x 60 . "\n";
319
320     if ($opts->{progress})
321     {
322
323         select $prevout;
324
325     }
326
327     my $f = $routines{$_};
328     &$f;
329
330 }
331
332 test();
333 cleanup();
334 exit;
335
336 END
337 {
338     unless ($opts->{debug})
339     {
340         unlink("$tmpdir/$$.c", "$tmpdir/test") if $tmpdir;
341     }
342 }
343
344 ##########################################################
345
346 sub printopts
347 {
348     print "\n$0 options\n", '-' x 30, "\n";
349     print "defaults print in [ ] \n";
350     for (sort keys %$allopts)
351     {
352
353         (my $o = $_) =~ s,[:=]s,=<X>,g;
354
355         my $space = ' ' x ($usage_gutter - length($o));
356
357         print "  --$o $space $allopts->{$_}\n";
358     }
359     print "\n\n";
360     exit;
361 }
362
363 sub usage
364 {
365
366     system("perldoc $0");
367     printopts();
368     exit;
369
370 }
371
372 sub checkenv
373 {
374
375     if ($opts->{quiet})
376     {
377
378         open(QUIET, ">/dev/null") or die "can't write to /dev/null: $!\n";
379         select(QUIET);    # should send all default print()s to oblivion
380
381     }
382
383     $os = $Config{osname} || $ENV{OSTYPE} || `uname`;
384     $arch = $Config{archname};
385     $cc = $Config{cc};    # for SWISH::API should use same compiler as perl
386                           # was compiled with, and that SHOULD be gcc.
387
388     if ($opts->{progress})
389     {
390         print STDOUT "os... $os\n";
391         print STDOUT "arch... $arch\n";
392         print STDOUT "cc... $cc\n";
393         print STDOUT "opt: $_ -> $opts->{$_}\n" for sort keys %$opts;
394     }
395
396     unlink $outlog, $errlog;
397
398     # so we start afresh
399     # but don't warn if we fail to unlink (e.g., perms or something)
400
401     ld_opts();
402     set_fetcher();
403 }
404
405 sub makedirs
406 {
407
408     my @d =
409       ($installdir, $tmpdir, "$installdir/lib", "$installdir/include",
410         $perllib);
411     mkpath(\@d, 1, 0755);
412     for (@d)
413     {
414
415         if ($opts->{progress})
416         {
417             print STDOUT "checking dir $_ ... ";
418         }
419         unless (-W $_)
420         {
421             warn "can't write to $_: $!\n";
422             nice_exit();
423         }
424         if ($opts->{progress})
425         {
426             print STDOUT "\n";
427         }
428     }
429
430 }
431
432 sub sanity
433 {
434
435     test_make();
436
437     print "is $cc a GNU C compiler... ";
438     test_compiler();
439
440     # basic ld test with libc
441     if (test_c_prog($ld_test, '-lc'))
442     {
443
444         die "can't link against libc with $cc\n";
445
446     }
447
448     unless ($opts->{quiet})
449     {
450
451         print "Continue on our merry way? [y] ";
452         nice_exit() unless confirm();
453
454     }
455
456 }
457
458 sub test_c_prog
459 {
460     my $prog = shift;
461
462     # if last value in @_ is a SCALAR ref, use it as a test against output of prog
463
464     my $test = pop @_ if ref $_[-1] eq 'SCALAR';
465
466     # write
467     open(TMP, "> $tmpdir/$$.c") || die "can't write to $tmpdir\n";
468     print TMP $prog;
469     close(TMP);
470
471     # compile
472     my $extra = join ' ', @_;
473     $extra .= ' -w' if $os =~ /irix/i;
474     my $cmd = "$cc $extra -o $Cout $Cin";
475
476     print "\n\ncompile cmd: $cmd\n" if $opts->{debug};
477
478     return 1 if system("$cmd $cmdout");  # don't bother if we can't even compile
479
480     if ($test)
481     {
482
483         chomp(my $o = `$Cout`);
484
485         if ($o lt $$test)
486         {
487
488             print $o . " -- failed!\n";
489
490             return 1;    # 1 indicated failure like system() does
491
492         }
493
494     }
495
496     # run it
497
498     warn "run: $Cout $cmdout\n" if $opts->{debug};
499
500     return system("$Cout $cmdout");
501
502 }
503
504 # fix from chyla@knihovnabbb.cz
505 # Tue Apr 26 09:15:16 CDT 2005
506 sub test_for_prior_zlib
507 {
508     return undef if $opts->{force};
509
510     print "testing for already-installed zlib... ";
511
512     my $err = test_c_prog($zlib_test, '-lz', $ld_opts);
513
514     return get_ld_path('libz', '', \$zlibdir) unless $err;
515
516     return 0;    # 0 indicates failure
517 }
518
519 sub test_for_prior_libxml2
520 {
521
522     return undef if $opts->{force};
523
524     print "testing for already-installed libxml2... ";
525
526     # first include -lxml2 and see if it returns a path
527
528     my $path = get_ld_path('libxml2', '', \$libxml2dir)
529       unless test_c_prog($ld_test, $ld_opts, '-lxml2');
530
531     # then check version with xmlversion.h
532
533     return 0 unless $path;
534
535     print "minimum libxml2 version required is $MinLibxml2 and you have... ";
536
537     # include $installdir in -I path, since we may be a repeat user
538     my $err =
539       test_c_prog(
540                   $libxml2_test,
541                   '-I' . File::Spec->catfile($installdir, 'include', 'libxml2'),
542                   '-I' . File::Spec->catfile($path,       'include', 'libxml2'),
543                   $ld_opts,
544                   '-lxml2',
545                   \$MinLibxml2
546                  );
547
548     return get_ld_path('libxml2', '', \$libxml2dir) unless $err;
549
550     return 0;    # 0 indicates failure
551
552 }
553
554 sub cleanup
555 {
556
557     print STDOUT "Swish-e was installed in $installdir\n";
558     print STDOUT "SWISH::API was installed in $swish_api_dir\n";
559
560 }
561
562 sub test
563 {
564
565     test_api();
566
567 }
568
569 sub set_fetcher
570 {
571
572     # we'd prefer to use some external command like wget
573     # but will resort to the LWP stuff if need be
574
575     $fetcher = which('wget');
576     $fetcher ||= which('curl');
577     $fetcher ||= perl_fetcher();
578     print "no program available to fetch remote sw source\n" unless $fetcher;
579
580 }
581
582 sub perl_fetcher
583 {
584     print "trying LWP::Simple\n";
585     eval { require LWP::Simple };
586     $@ ? return 0 : return \&LWP::Simple::getstore;
587
588 }
589
590 sub which
591 {
592
593     chomp(my $w = `which $_[0] 2>&1`);
594     $w =~ s,\n,,g;
595     $w !~ m/not found|^[^\/]/i
596       ? $w
597       : 0;
598
599 }
600
601 sub test_compiler
602 {
603
604     # verify that we are using a current version of gcc
605     # other compilers MIGHT work, but we KNOW gcc does
606     if (test_c_prog($gcc_test))
607     {
608         warn "Warning: this perl was not compiled with gcc!\n"
609           . "Instead: $cc\n"
610           . "This may cause compile of SWISH::API to fail.\n"
611           . "We'll try anyway, but be warned.\n";
612
613         # if $cc is not gcc, test for it in our path anyway.
614         my $gcc = which('gcc');
615         if ($gcc)
616         {
617             print "Found a gcc at $gcc\n";
618             if ($opts->{interactive})
619             {
620                 print "Should I use that? [yes] ";
621                 if (confirm())
622                 {
623                     $cc = $gcc;
624                 }
625                 else
626                 {
627                     print $nogcc;
628                     nice_exit();
629                 }
630             }
631             else
632             {
633                 $cc = $gcc;
634             }
635
636         }
637         else
638         {
639
640             #die $nogcc;
641             return 0;
642         }
643     }
644
645     # by now, we should be using gcc
646     # check version
647     print "testing gcc version... ";
648     my @v = `$cc -v 2>&1`;
649     my @vers = grep { /version \d/ } @v;
650     if (!@vers)
651     {
652         warn "Warning: trouble getting version from $cc\n"
653           . "Minimum version required is $min_gcc\n"
654           . "We'll try anyway.\n";
655     }
656     else
657     {
658       V: for (@vers)
659         {
660             next if !m/version \d/;
661             my ($v) = ($_ =~ m/version ([\d\.]+)/);
662             $v =~ s,^(\d\.\d+)\.?(\d*?),$1$2,g;
663             if ($v < $min_gcc)
664             {
665                 die "Minimum version of gcc is $min_gcc\n";
666             }
667             else
668             {
669                 print "version $v\n";
670             }
671         }
672     }
673
674 }
675
676 sub ld_opts
677 {
678
679     # the libtool message, here for reference
680     #------------------------------------------
681     #If you ever happen to want to link against installed libraries
682     #in a given directory, LIBDIR, you must either use libtool, and
683     #specify the full pathname of the library, or use the `-LLIBDIR'
684     #flag during linking and do at least one of the following:
685     #   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
686     #     during execution
687     #   - add LIBDIR to the `LD_RUN_PATH' environment variable
688     #     during linking
689     #   - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
690     #
691     #See any operating system documentation about shared libraries for
692     #more information, such as the ld(1) and ld.so(8) manual pages.
693     #------------------------------------------
694
695     # we opt for the LD_RUN_PATH/-LLIBDIR combination because:
696     # 1. we can't rely on LD_LIBRARY_PATH for future execution
697     # 2. --rpath doesn't seem to work for all gcc's equally well
698
699     # set LD_RUN_PATH, etc to include our new lib/ path
700     # this whole library path deal is a nefarious and odious beast, largely
701     # because default libraries go in one path, while later-installed libraries
702     # might go anywhere at all. and while some OSes use LD_RUN_PATH, some do not.
703     # we try and cover all the bases here.
704
705     # both set env var LD_RUN_PATH and pass it at configure time
706
707     my @path = (
708                 File::Spec->catfile($installdir, 'lib'),
709                 $installdir, $libxml2dir, $zlibdir, '/usr/local',
710                 '/usr/local/lib'
711                );
712
713     my %seen;
714
715     $ENV{LD_RUN_PATH} ||= '.';
716
717     $ENV{LD_RUN_PATH} = join(':',
718                              grep { /./ } map { $seen{$_}++ ? '' : $_ } @path,
719                              $ENV{LD_RUN_PATH});
720
721     # unset LD_LIBRARY_PATH for this script, so that tests accurately reflect what we've linked
722     $ENV{LD_LIBRARY_PATH} = '';
723
724     # Darwin (Mac OS X) requirements
725
726     if ($os =~ /darwin/i)
727     {
728
729         $ENV{DYLD_LIBRARY_PATH} = "$installdir/lib";
730         $ld_opts = "-Wl,-L" . join(' -Wl,-L', split(/:/, $ENV{LD_RUN_PATH}));
731
732         # irix
733     }
734     elsif ($os =~ /irix/i)
735     {
736
737         $ld_opts = "-Wl,-L" . join(' -Wl,-L', split(/:/, $ENV{LD_RUN_PATH}));
738
739         # special irix req
740
741         $ENV{LD_LIBRARYN32_PATH} = $ENV{LD_RUN_PATH};
742
743         # solaris
744     }
745     elsif ($os =~ /sun|sol/i)
746     {
747         $ld_opts = "-Wl,-rpath -Wl,$ENV{LD_RUN_PATH} -L$ENV{LD_RUN_PATH}";
748
749         #$ld_opts =     "-Wl,-L" .
750         #        join(' -Wl,-L', split(/:/,$ENV{LD_RUN_PATH}) );
751
752         # linux
753     }
754     elsif ($os =~ /linux/i)
755     {
756
757         $ld_opts = "-Wl,-L" . join(' -Wl,-L', split(/:/, $ENV{LD_RUN_PATH}));
758
759         # default
760     }
761     else
762     {
763
764         #$ld_opts =     '-Wl,-rpath ' .
765         #        "-Wl,$ENV{LD_RUN_PATH} -L$ENV{LD_RUN_PATH}";
766
767         #        $ld_opts =     '-Wl,-rpath';
768         #        for ( split(/:/,$ENV{LD_RUN_PATH}) ) {
769         #            $ld_opts .= " -Wl,$_ -L$_ ";
770         #        }
771
772         $ld_opts = "-Wl,-L" . join(' -Wl,-L', split(/:/, $ENV{LD_RUN_PATH}));
773
774     }
775
776     # include the -I include paths too
777
778     $ld_opts .= " -I$_/include"
779       for (grep { s,/lib$,, } split(/:/, $ENV{LD_RUN_PATH}));
780
781     if ($opts->{debug})
782     {
783         print "LD_RUN_PATH = $ENV{LD_RUN_PATH}\n";
784         print "ld opts = $ld_opts\n";
785     }
786 }
787
788 sub get_ld_path
789 {
790     my $lib  = shift || '';
791     my $file = shift || $Cout;
792     my $dir  = shift;
793
794     my $cmd = 'ldd';
795     $cmd = 'otool -L' if $os =~ m/darwin/i;
796
797     my @s = `$cmd $file`;
798
799     if ($opts->{debug})
800     {
801         warn '-' x 40 . "\n";
802         warn "ld test for $lib\n";
803
804         warn "libraries that ld linked to in $file:\n";
805         warn "$_" for @s;
806
807         warn "looking for '/lib/$lib' in array\n";
808
809     }
810
811     # \d* is for irix which often uses lib32, etc.
812
813     my @where = grep { m!/lib[\d]*/$lib! } @s;
814     my $path = shift @where;    # should only be one path
815     chomp($path);
816
817     warn "found path: $path\n" if $opts->{debug};
818
819     $path =~ s,^[^/]*,,g;
820
821     warn "no space: $path\n" if $opts->{debug};
822
823     my @c = split(m!/!, $path);
824
825     my @g;
826     for (@c)
827     {
828         next if !$_;
829         last if $_ =~ m/^lib\d*$/;
830         warn "adding $_ to \@g\n" if $opts->{debug};
831         push @g, $_;
832
833     }
834
835     $path = '/' . join('/', @g);
836
837     print "libpath is $path\n";
838
839     $$dir = $path;
840
841     return $path;
842
843 }
844
845 sub confirm
846 {
847
848     # check STDIN for a 'yes' or ''
849     return 1 if $opts->{quiet};
850
851     my $i = <>;
852     chomp($i);
853     if (!$i or $i =~ m/^y/)
854     {
855         return 1;
856     }
857     else
858     {
859         return 0;
860     }
861 }
862
863 sub get_src
864 {
865
866     # returns dir of unpacked src
867
868     my $sw = shift;
869
870     my $src;    # will ultimately be a directory path to sw src
871
872     # check tmpdir first since that's where we download via http
873
874   DIR: for my $Dir ($tmpdir, $startdir, $Bin)
875     {
876
877         chdir($Dir);
878
879         # several scenarios
880         # 1. srcdir indicates dir to look in for tar.gz files
881         # 2. srcdir indicates base dir, plus --sw=file.tar.gz for specific file
882         # 3. --sw=file.tar.gz with no srcdir base
883         # 4. no --srcdir and no --sw [ this is default ]
884
885         if ($opts->{srcdir} and !$opts->{$sw})
886         {
887
888             my $dir = $opts->{srcdir};
889
890             $dir = File::Spec->catfile($startdir, $dir) if $dir !~ m!^/!;
891
892             print "looking in $dir for $sw|latest.*tar.gz\n";
893
894             my $found = 0;
895             opendir(DIR, $dir) || die "can't open dir $dir: $!\n";
896             while (