root/swish-e/trunk/buildswishe.pl

Revision 2146, 35.6 kB (checked in by karpet, 5 months ago)

update build script to use svn

  • 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 #   0.13    Fri Jun 27 10:18:42 CDT 2008
90 #    change from CVS to SVN (only a year+ late...)
91 #
92 ################################################################################
93
94 $| = 1;
95
96 use strict;
97 require 5.006;    # might work with < perl 5.6.0 but untested
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     # madler@alumni.caltech.edu assures me that zlib will support a
115     # http://www.zlib.net/zlib-current.tar.gz link but no such link as of
116     # 7/12/2006
117
118     'libxml2' => 'ftp://xmlsoft.org/libxml2/LATEST_LIBXML2',
119
120     # peknet hosts a pre-patched version of XPDF
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     # print all options and descriptions
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 # some defaults
205 $installdir = $opts->{installdir} || $defdir;
206 $installdir =~ s,/+$,,;
207 $perllib = $opts->{perllib} || "$Config{sitearch}/../";   # must go up one level
208 $startdir = Cwd::cwd();
209 $MinLibxml2 = '2.4.3';
210
211 # we ought to be able to retrieve this from swish src somehow
212 # but we don't have source till after we've tested for this -- chick and egg
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 = '';    # define these based on OS platform
225
226 $Make = $opts->{make} || 'make';
227
228 # better C tests would be nice. these seem to work.
229 $Cout = "$tmpdir/test";
230 $Cin  = "$tmpdir/$$.c";
231
232 $zlib_test = <<EOF;
233 #include <stdio.h>
234 #include "zlib.h"
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 #include <stdio.h>
247 int main( void )
248 {
249    printf("success!\\n");
250    return 0;
251 }
252
253
254 EOF
255
256 # because xml-config doesn't always exist...
257 $libxml2_test = <<EOF;
258 #include <stdio.h>
259 #include "libxml/xmlversion.h"
260
261 int main ( void )
262 {
263     printf("%s\\n", LIBXML_DOTTED_VERSION);
264     return 0;
265
266 }
267
268 EOF
269
270 # gcc might be symlinked from something else, or named cc or some
271 # other weirdness, so test it to be sure
272 $gcc_test = <<EOF;
273 #include <stdio.h>
274 int main ( void )
275 {
276     #ifndef __GNUC__
277            printf("not gcc!\\n");
278            return 1;
279            
280     #else
281         printf("yep, gcc\\n");
282         return 0;
283     #endif
284  
285 }
286
287 EOF
288
289 ##########################################################
290 ## run
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 );    # order matters
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);    # should send all default print()s to oblivion
383
384     }
385
386     $os = $Config{osname} || $ENV{OSTYPE} || `uname`;
387     $arch = $Config{archname};
388     $cc = $Config{cc};    # for SWISH::API should use same compiler as perl
389                           # was compiled with, and that SHOULD be gcc.
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     # so we start afresh
402     # but don't warn if we fail to unlink (e.g., perms or something)
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     # basic ld test with libc
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     # if last value in @_ is a SCALAR ref, use it as a test against output of prog
466
467     my $test = pop @_ if ref $_[-1] eq 'SCALAR';
468
469     # write
470     open(TMP, "> $tmpdir/$$.c") || die "can't write to $tmpdir\n";
471     print TMP $prog;
472     close(TMP);
473
474     # compile
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");  # don't bother if we can't even compile
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;    # 1 indicated failure like system() does
494
495         }
496
497     }
498
499     # run it
500
501     warn "run: $Cout $cmdout\n" if $opts->{debug};
502
503     return system("$Cout $cmdout");
504
505 }
506
507 # fix from chyla@knihovnabbb.cz
508 # Tue Apr 26 09:15:16 CDT 2005
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;    # 0 indicates failure
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     # first include -lxml2 and see if it returns a path
530
531     my $path = get_ld_path('libxml2', '', \$libxml2dir)
532       unless test_c_prog($ld_test, $ld_opts, '-lxml2');
533
534     # then check version with xmlversion.h
535
536     return 0 unless $path;
537
538     print "minimum libxml2 version required is $MinLibxml2 and you have... ";
539
540     # include $installdir in -I path, since we may be a repeat user
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;    # 0 indicates failure
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     # we'd prefer to use some external command like wget
576     # but will resort to the LWP stuff if need be
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     # verify that we are using a current version of gcc
608     # other compilers MIGHT work, but we KNOW gcc does
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         # if $cc is not gcc, test for it in our path anyway.
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             #die $nogcc;
644             return 0;
645         }
646     }
647
648     # by now, we should be using gcc
649     # check version
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     # the libtool message, here for reference
683     #------------------------------------------
684     #If you ever happen to want to link against installed libraries
685     #in a given directory, LIBDIR, you must either use libtool, and
686     #specify the full pathname of the library, or use the `-LLIBDIR'
687     #flag during linking and do at least one of the following:
688     #   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
689     #     during execution
690     #   - add LIBDIR to the `LD_RUN_PATH' environment variable
691     #     during linking
692     #   - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
693     #
694     #See any operating system documentation about shared libraries for
695     #more information, such as the ld(1) and ld.so(8) manual pages.
696     #------------------------------------------
697
698     # we opt for the LD_RUN_PATH/-LLIBDIR combination because:
699     # 1. we can't rely on LD_LIBRARY_PATH for future execution
700     # 2. --rpath doesn't seem to work for all gcc's equally well
701
702     # set LD_RUN_PATH, etc to include our new lib/ path
703     # this whole library path deal is a nefarious and odious beast, largely
704     # because default libraries go in one path, while later-installed libraries
705     # might go anywhere at all. and while some OSes use LD_RUN_PATH, some do not.
706     # we try and cover all the bases here.
707
708     # both set env var LD_RUN_PATH and pass it at configure time
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     # unset LD_LIBRARY_PATH for this script, so that tests accurately reflect what we've linked
725     $ENV{LD_LIBRARY_PATH} = '';
726
727     # Darwin (Mac OS X) requirements
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         # irix
736     }
737     elsif ($os =~ /irix/i)
738     {
739
740         $ld_opts = "-Wl,-L" . join(' -Wl,-L', split(/:/, $ENV{LD_RUN_PATH}));
741
742         # special irix req
743
744         $ENV{LD_LIBRARYN32_PATH} = $ENV{LD_RUN_PATH};
745
746         # solaris
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         #$ld_opts =     "-Wl,-L" .
753         #        join(' -Wl,-L', split(/:/,$ENV{LD_RUN_PATH}) );
754
755         # linux
756     }
757     elsif ($os =~ /linux/i)
758     {
759
760         $ld_opts = "-Wl,-L" . join(' -Wl,-L', split(/:/, $ENV{LD_RUN_PATH}));
761
762         # default
763     }
764     else
765     {
766
767         #$ld_opts =     '-Wl,-rpath ' .
768         #        "-Wl,$ENV{LD_RUN_PATH} -L$ENV{LD_RUN_PATH}";
769
770         #        $ld_opts =     '-Wl,-rpath';
771         #        for ( split(/:/,$ENV{LD_RUN_PATH}) ) {
772         #            $ld_opts .= " -Wl,$_ -L$_ ";
773         #        }
774
775         $ld_opts = "-Wl,-L" . join(' -Wl,-L', split(/:/, $ENV{LD_RUN_PATH}));
776
777     }
778
779     # include the -I include paths too
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     # \d* is for irix which often uses lib32, etc.
815
816     my @where = grep { m!/lib[\d]*/$lib! } @s;
817     my $path = shift @where;    # should only be one path
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     # check STDIN for a 'yes' or ''
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     # returns dir of unpacked src
870
871     my $sw = shift;
872
873     my $src;    # will ultimately be a directory path to sw src
874
875     # check tmpdir first since that's where we download via http
876
877   DIR: for my $Dir ($tmpdir, $startdir, $Bin)
878     {
879
880         chdir($Dir);
881
882         # several scenarios
883         # 1. srcdir indicates dir to look in for tar.gz files
884         # 2. srcdir indicates base dir, plus --sw=file.tar.gz for specific file
885         # 3. --sw=file.tar.gz with no srcdir base
886         # 4. no --srcdir and no --sw [ this is default ]
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;