File: gpt-setup

package info (click to toggle)
grid-packaging-tools 3.2globus2-5
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 4,816 kB
  • ctags: 1,621
  • sloc: perl: 19,536; sh: 3,047; makefile: 320; exp: 89
file content (738 lines) | stat: -rwxr-xr-x 23,623 bytes parent folder | download
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
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
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
#! perl

#
# Do a perl check for version >= 5.005.  See 'gpt-translate-interpreter' should you
# need to alter the invocation path to a valid perl interpreter in the GPT front-end
# programs.
#

if ( ! ( defined eval "require 5.005" ) )
{
    die "GPT requires at least Perl version 5.005";
}

my $gpath = $ENV{GPT_LOCATION};
if (!defined($gpath))
{
  $gpath = "/usr";
}
if (!defined($gpath))
{
   die "GPT_LOCATION or GLOBUS_LOCATION needs to be set before running this script"
}

@INC = ("$gpath/lib/perl", "$gpath/lib/perl/$Config{'archname'}", @INC);

if ( ! ( defined eval "require Grid::GPT::GPTObject" ) )
{
    die("$gpath does not appear to hold a valid GPT installation\n");
}

use strict;
use Getopt::Long;

use vars qw($VERSION %ignored_dirs %ignored_scripts);


$VERSION = '0.01';

require Pod::Usage;

my ($name, $version, $gptversion,$verbose, $make_test, $help, $nocomments);

# sub pod2usage {
#   my $ex = shift;
#   print "gpt-setup -name=<Package Name> -version=<Major.Minor.Age> [-nocomments -verbose -help -v ] source_dir build_dir\n";
#   exit $ex;
# }

GetOptions( 'name=s' => \$name, 'version=s' => \$version, 
	    'tstdir' => $make_test, 'verbose=i' => \$verbose, 
            'nocomments' => \$nocomments,
	    'help' => \$help, 'v' => \$gptversion)
  or Pod::Usage::pod2usage(1);

Pod::Usage::pod2usage(0) if $help;
require Grid::GPT::GPTIdentity;
Grid::GPT::GPTIdentity::print_gpt_version() if defined $gptversion;

if (!defined($version) or !defined($name)) {
  print "ERROR: You must specify name and version\n"; 
  Pod::Usage::pod2usage(1); 
}

$version =~ /(\d+)\.(\d+)\.(\d+)/;
my ($major, $minor, $age) = ($1, $2, $3);

if (!defined ($major)) {
  print "ERROR: Version needs to be in d.d.d format\n";
  Pod::Usage::pod2usage(1);
}

my $packagedizedir = $gpath;

$packagedizedir .= '/share/globus/aclocal';

# establish stuff to be ignored by packagedize
for (@{ ['CVS', 'RCS', 'pkgdata', 'doxygen'] }) {
  $ignored_dirs{$_}++;
}

for (@{ ['config.status', 'bootstrap', 'libtool', 'configure', 'install-sh'] }) {
  $ignored_scripts{$_}++;
}


my $source_prefix = ".";
$source_prefix = $ARGV[0] if(defined($ARGV[0]));
my $build_prefix = $source_prefix;
$build_prefix = $ARGV[1] if(defined($ARGV[1]));
$source_prefix =~ s/\/+$//g;
$build_prefix =~ s/\/+$//g;

my @ac_outputs;
my $ac_headers = "";
my $pkglibs = "";
my @doxygen_src_dirs;


# generating Makefile.am's. 
my @subdirs = ("pkgdata", "doxygen");
process_dir(suffix => "", 
            subdirs => \@subdirs, 
            frg => "$packagedizedir/top_Makefile_am.frg");

my %targets;

# do the right thing for doxygen

if (! -d "$source_prefix/doxygen") {
   mkdir("$source_prefix/doxygen", 0755) || 
      die "Unable to create doxygen directory\n";
}

push @ac_outputs, "doxygen/Makefile";
push @ac_outputs, "doxygen/Doxyfile";
push @ac_outputs, "doxygen/Doxyfile-internal";

for(0..$#doxygen_src_dirs) 
{
   $doxygen_src_dirs[$_] = " ../$doxygen_src_dirs[$_] "
}

# generate doxygen specific configure.in substitutions

$targets{'PACKAGE_NAME'} = "\"$name\"";

$targets{'DOXYGEN_SRC_DIRS'} = "\"@doxygen_src_dirs\"";

# generate configure.in

my $am_config_header = "";
if ($ac_headers ne "") {
  $am_config_header = "AM_CONFIG_HEADER($ac_headers)";
}

my $ac_outputs_line = join("\n\t",@ac_outputs);

($targets{'AM_CONFIG_HEADER'}, $targets{'AC_OUTPUT'})= 
  ($am_config_header, $ac_outputs_line);

transform_file("$packagedizedir/configure_in.frg", "$source_prefix/configure.in", 
               \%targets);
($targets{'AM_CONFIG_HEADER'},$targets{'AC_OUTPUT'} )= (undef, undef);

# Create bootstrap script.
install("$packagedizedir/bootstrap.frg",  "$source_prefix/bootstrap", 755);

# generate pkgdata directory
if (! -d "$source_prefix/pkgdata") {
my $result =`mkdir $source_prefix/pkgdata`;
}

($targets{'PACKAGE'}, $targets{'MAJOR'}, $targets{'MINOR'}, $targets{'AGE'}, 
 $targets{'PKGLIBS'}) = ($name, $major, $minor, $age, $pkglibs);

transform_file("$packagedizedir/pkg_data_src_gpt_in.frg", 
               "$source_prefix/pkgdata/pkg_data_src.gpt.in", 
               \%targets);

($targets{'PACKAGE'}, $targets{'MAJOR'}, $targets{'MINOR'}, $targets{'AGE'}) = 
  (undef, undef, undef, undef);



sub process_dir {
  my (%args) = @_;
  my $suffix = $args{'suffix'};
  my $prog_target = 'bin_';

  # determine if $suffix is a test directory
  
  if ($suffix =~ /tests?$/ and $make_test) {
    $prog_target = 'test_';
  }
  my $srcdir = qq($source_prefix/$suffix);  
  my $builddir = qq($build_prefix/$suffix);

  # strip trailing slashes

  $srcdir =~ s/\/+$//;
  $builddir =~ s/\/+$//;
  
#  print "process_dir extracting from $srcdir and $builddir\n";
  my $subdirs_r = extract_files($srcdir, 'subdirs');
  my $sources_r = extract_files($srcdir, 'expression',qr/\.[cChH]$/);
  my $libraries_r = extract_files($builddir, 'expression',qr/\.(so|a|la)$/);
  my $initialized_r = extract_files($srcdir, 'expression',qr/\.in$/);
  my $programs_r =  extract_files($builddir, 'executables');
  my $man_r = extract_files($srcdir, 'expression',qr/\.\d$/);
  my $headers_r = extract_files($srcdir, 'expression',qr/\.h(?:\.in)?$/);

  my $valid = 0;
  my @subdirs;
  my @sources = (@$sources_r);
  my @libraries = (@$libraries_r);
  my @programs;
  my @scripts;
  my @man = (@$man_r);
  my @headers;

# This section filters out some files 

  if (@$subdirs_r > 0) {
    for (@$subdirs_r) {
      if (!defined($ignored_dirs{$_})) {
	push @subdirs, $_;
      }
    }
  }
  my $slashed_suffix = $suffix;
  if ($slashed_suffix ne "") {
    $slashed_suffix .= '/';
  }
  if (@$initialized_r > 0) {
    for (@$initialized_r) {
      if (!/Makefile.in/ && !/configure.in/) {
	s/\.in//;
	my $rootname = $_;
        if ( /\.h$/) {
          print "Found autoconf'ed header $_\n";
          $ac_headers .=" $_:${slashed_suffix}$rootname";
          push @headers, $rootname;
        } else {
          print "Found autoconf'ed file $_\n";
          push @ac_outputs, "${slashed_suffix}$rootname";
        }
      }
    }
  }
  
  if (@$programs_r > 0) {
    for (@$programs_r) {
#      print "Examining $_\n";
      if (-T "$builddir/$_") {
	if (!defined($ignored_scripts{$_})) {
#	  print "FOUND A SCRIPT $_\n";
	  push @scripts, $_;
	}
      }
      elsif (-f "$builddir/$_"){
#	print "FOUND A PROGRAM $_\n";
	push @programs, $_;
      }
    }
  }

  if (@$headers_r > 0) {
    for (@$headers_r) {
      if (! /(?:ac)?config\.h/) {
	push @headers, $_;
      }
    }
  }

  my %targets;
  $targets{'TARGETS'} = "";

# Put together a Makefile.am
  my @mysubdirs = @subdirs;
  if(defined($args{'subdirs'}))
  {
     @mysubdirs = (@mysubdirs, @{$args{'subdirs'}});
  }

  my %comments = (
                  "SUBDIRS", 
                  "# SUBDIRS is an automake macro which contains 
# the list of subdirectories that have Makefile.am's\n",
                  "Sources",
                  "# Sources contains all of the source files in the directory.
# Header files are included because automake will generate dependency targets 
# for them and include them in a source distribution.
#
# If this directory builds multiple programs or libraries than these sources
# will need to be seperated into seperate macros.\n",
                 "INCLUDES",
                  "# INCLUDES is an automake macro which contains 
# the include directives (-I..) for the compiler.
#
# GPT_INCLUDES contains the include directives generated by GPT 
# from the dependent packages.\n",
                  "Scripts",
                  "# Scripts contains all of the scripts in this directory\n",
                  "TESTS",
                  "# TESTS is an automake that contains a list 
# of tests to run during a \"make check\"
# These test can be either be programs or scripts.
# All of the test are expected to return 0 for pass and non-zero for a fail\n",
                  "SCRIPTS",
                  "# $ {prog_target}SCRIPTS is an autmake macro that contains 
# a list of scripts to be installed in a certain directory.
# bin is \$prefix/bin
# noinst means that the scripts are not installed in any directory.
# You can also use the following:
# sbin is \$prefix/sbin
# libexec is \$prefix/libexec
# You can also use any directory defined by a macro of the form
# \<directory_name\>dir\n",
                  "EXTRA_DIST",
                  "# EXTRA_DIST is used to include files in 
# a source distribution that automake fails to detect.\n",
                  "MANS",
                  "# man_MANS is an automake macro which contains a list of man files to install.
# automake will install the files into the man directory indicated by the file's extension.
# For example, file foo.3 will be installed \$prefix/man/man3",
                  "HEADERS",
                  "# include_HEADERS is an automake macro which contains 
# a list of header files that are to be installed in \$prefix/include\n",
                  "LTLIBRARIES",
                  "# lib_LTLIBRARIES is an automake macro which contains
# a list of libtool libraries that are to be installed in \$prefix/lib\n",
                  "SOURCES",
                  "# _SOURCES is an automake macro which contains
# a list of sources needed to compile the library.\n",
                  "LDFLAGS",
                  "# _LDFLAGS is an automake macro which contains
# directives to the linker add before the list of objects and libraries.
# 
# GPT_LDFLAGS is a macro that contains the linker directives GPT generated 
# from the dependent packages\n",
                  "LIBADD",
"# _LIBADD is an automake macro which contains
# directives to the linker added after the list of objects.  
# LIBADD is specific for linking libraries
# 
# GPT_LIB_LINKS is a macro that contains the linker directives GPT generated 
# from the dependent packages\n",
                  "LDADD",
"# _LDADD is an automake macro which contains
# directives to the linker added after the list of objects.  
# LDADD is specific for linking programs
# 
# GPT_PGM_LINKS is a macro that contains the linker directives GPT generated 
# from the dependent packages\n",
                  "PROGRAMS",
                  "# bin_PROGRAMS is an automake macro which contains
# a list of programs that are to be installed in a certain directory.
# bin is \$prefix/bin
# noinst means that the programs are not installed in any directory.
# You can also use the following:
# sbin is \$prefix/sbin
# libexec is \$prefix/libexec
# You can also use any directory defined by a macro of the form 
# \<directory_name\>dir\n",
                 );
  
  if (@mysubdirs > 0) {
    $targets{'TARGETS'} .=  $comments{'SUBDIRS'} if ! defined $nocomments;
    $targets{'TARGETS'} .=  "SUBDIRS=";
    for (@mysubdirs) {
      if ($_ ne 'CVS') {
      $targets{'TARGETS'} .=  " \\\n\t$_";
      }
    }
    $targets{'TARGETS'} .=  "\n\n";
    $valid = 1;
  }
  
  if (@sources  > 0) {
    my $relsrcdir = $srcdir;
    $relsrcdir =~ s!^$source_prefix/*!!;
    push @doxygen_src_dirs, $relsrcdir;
    $targets{'TARGETS'} .=  $comments{'Sources'} if ! defined $nocomments;
    $targets{'TARGETS'} .=  "Sources=";
    for (@sources) {
      $targets{'TARGETS'} .=  " \\\n\t$_";
    }
    $targets{'TARGETS'} .=  "\n\n";
    $targets{'TARGETS'} .=  $comments{'INCLUDES'} if ! defined $nocomments;
    $targets{'TARGETS'} .=  "INCLUDES += \$\(GPT_INCLUDES\)\n\n";

    $valid = 1;
  }
  if (@scripts > 0) {
    $targets{'TARGETS'} .=  $comments{'Scripts'} if ! defined $nocomments;
    $targets{'TARGETS'} .=  "Scripts=";
    for (@scripts) {
      $targets{'TARGETS'} .=  " \\\n\t$_";
    }
    $targets{'TARGETS'} .=  "\n\n";

    $targets{'TARGETS'} .=  $comments{'SCRIPTS'} if ! defined $nocomments;
    $targets{'TARGETS'} .=  "$ {prog_target}SCRIPTS = \$\(Scripts\)\n";
    $targets{'TARGETS'} .=  $comments{'EXTRA_DIST'} if ! defined $nocomments;
    $targets{'TARGETS'} .=  "EXTRA_DIST = \$\(Scripts\)\n";
    $valid = 1;

  }

  if (@man > 0) {
    $targets{'TARGETS'} .=  $comments{'MANS'} if ! defined $nocomments;
    $targets{'TARGETS'} .=  "man_MANS=";
    for (@man) {
      $targets{'TARGETS'} .=  " \\\n\t$_";
    }
    $targets{'TARGETS'} .=  "\n\n";
    $targets{'TARGETS'} .=  $comments{'EXTRA_DIST'} if ! defined $nocomments;
    $targets{'TARGETS'} .=  "EXTRA_DIST = \$\(man_MANS\)\n";
    $valid = 1;

  }

  if (@headers > 0) {
    $targets{'TARGETS'} .=  $comments{'HEADERS'} if ! defined $nocomments;
    $targets{'TARGETS'} .=  "include_HEADERS=";
    for (@headers) {
      if ($_ ne 'CVS') {
      $targets{'TARGETS'} .=  " \\\n\t$_";
      }
    }
    $targets{'TARGETS'} .=  "\n\n";
    $valid = 1;
  }

  if (!$valid) {
    print "WARNING: Makefile.am not created for $srcdir\n" if defined $verbose;
    return;
  }
  
  if (@libraries > 0) {
    my $made_comment;  
    for (@libraries) {
      my $ltl = $_;
      my $rootname = $_;
      $ltl =~ s/\.(so|a)$/_\$(GLOBUS_FLAVOR_NAME)\.la/g;
      my $target = $ltl;
      $target =~ s/\W/_/g;
      $rootname =~ s/\.(so|a)$//g;
      $rootname =~ s/^\s*lib//g;
      $pkglibs .= " -l$ {rootname}";
      $targets{'TARGETS'} .=  $comments{'LTLIBRARIES'} if ! defined $nocomments;
      $targets{'TARGETS'} .=  "lib_LTLIBRARIES = $ltl\n\n";
      $targets{'TARGETS'} .=  $comments{'SOURCES'} if ! defined $nocomments;
      $targets{'TARGETS'} .=  "$ {target}_SOURCES = \$\(Sources\)\n\n";
      $targets{'TARGETS'} .=  $comments{'LDFLAGS'} if ! defined $nocomments;
      $targets{'TARGETS'} .=  "$ {target}_LDFLAGS = \$\(GPT_LDFLAGS\)\n\n";
      $targets{'TARGETS'} .=  $comments{'LIBADD'} if ! defined $nocomments;
      $targets{'TARGETS'} .=  "$ {target}_LIBADD = \$\(GPT_LIB_LINKS\)\n\n";
    }
  }
  
  if (@programs > 0) {
    my ($programline, $compilelines, $testline) = 
      ("$ {prog_target}PROGRAMS= ",'','TESTS = ');
    $programline = $comments{'PROGRAMS'} . $programline if ! defined $nocomments;
    $testline = $comments{'TESTS'} . $testline if ! defined $nocomments;
    my $made_comment;  
    for (@programs) {
      my $target = $_;
      $target =~ s/\W/_/g;
      $programline .= "\\\n\t$_ ";
      $testline .= "\\\n\t$_ ";
      $compilelines .=  $comments{'SOURCES'} if ! defined $nocomments;
      $compilelines .= "$ {target}_SOURCES = \$\(Sources\)\n";
      $compilelines .=  $comments{'LDFLAGS'} if ! defined $nocomments;
      $compilelines .=  "$ {target}_LDFLAGS = \$\(GPT_LDFLAGS\)\n\n";
      $compilelines .=  $comments{'LDADD'} if ! defined $nocomments;
      $compilelines .=  "$ {target}_LDADD = \$\(GPT_PGM_LINKS\)\n\n";
    }
    $programline .= "\n\n";
    $testline .= "\n\n";
    $targets{'TARGETS'} .=  $programline;
    $targets{'TARGETS'} .=  $compilelines;
  }

  my $makefile_frg = "$packagedizedir/Makefile_am.frg";
  $makefile_frg = $args{'frg'} if defined $args{'frg'};

  transform_file($makefile_frg, 
                 "$srcdir/Makefile.am", 
                 \%targets);

  push @ac_outputs, "$ {slashed_suffix}Makefile";

  if (@subdirs > 0) {
    for (@subdirs) {
      if ($_ ne 'CVS') {
	process_dir(suffix => "$ {slashed_suffix}$_");
      }
    }
  }
    
}

sub transform_file {
  my ($template, $outname, $substitutions) = @_;

  if ( -f "$outname") {
    if (! -f "$outname.orig") {
      print "WARNING: $outname already exists. Moved to $outname.orig\n" if defined $verbose;
      my $result =`mv $outname $outname.orig`;
    }
  }
  open (TEMPLATE, "$template");
  open (OUT, ">$outname");
  
  while (<TEMPLATE>) {
    for my $t (sort keys %$substitutions) {
      my $expr = "XXX_$ {t}_XXX";
      s/$expr/$substitutions->{$t}/g;
    }
    print OUT $_;
  }

  close TEMPLATE;
  close OUT;
  
}

sub extract_files {
  my ($directory, $type, $expression) = (shift, shift, shift);
#  print "extracting from $directory\n";
  opendir(DIR, $directory) or do { 
    print "WARNING: directory \"$directory\" could not be opened!\n" if defined $verbose;
    return [];
  };
  my @file_list;
  {
    $type eq 'subdirs' and do { 
      # HINT the following is executed backwards.  IOW readdir is executed first.
      # HINT The statements process a list similar to bash's pipe symble.
      # HINT $_ contains the result of the previous statement
      @file_list =
	map { $_->[0] } # Form a list of names without paths.
      grep { -d $_->[1] } # extract the directories using the second array element.
      map { [ $_, "$directory/$_" ] } # form anonymous array [ name, pathname ] because 
      # readdir strips the path from the bname
      grep { ! /^\.\.?$/ } # remove the current directory and its parent 
      readdir(DIR); #read all of the filenames in the directory
    };

    $type eq 'executables' and do { 
      # HINT the following is executed backwards.  IOW readdir is executed first.
      # HINT The statements process a list similar to bash's pipe symble.
      # HINT $_ contains the result of the previous statement
      @file_list =
	map { $_->[0] } # Form a list of names without paths.
      grep { -x $_->[1] } # extract the directories using the second array element.
      map { [ $_, "$directory/$_" ] } # form anonymous array [ name, pathname ] because 
      # readdir strips the path from the bname
      grep { ! /^\.\.?$/ } # remove the current directory and its parent 
      readdir(DIR); #read all of the filenames in the directory
    };

    $type eq 'expression' and do {
      defined($expression) or die "CODING: regular expression not defined\n";
      # HINT the following is executed backwards.  IOW readdir is executed first.
      # HINT The statements process a list similar to bash's pipe symble.
      # HINT $_ contains the result of the previous statement
      @file_list =
	map { $_->[0] } # Form a list of names without paths.
      grep { $_->[0] =~ /$expression/ } # extract the directories using the second array element.
      map { [ $_, "$directory/$_" ] } # form anonymous array [ name, pathname ] because 
      # readdir strips the path from the bname
      grep { ! /^\.\.?$/ } # remove the current directory and its parent 
      readdir(DIR); #read all of the filenames in the directory
    };


}
#  print "$expression, @file_list\n";
  closedir(DIR);
  return \@file_list;
}

sub usage {
  my $msg = shift;
  print "ERROR: $msg\n";
  die "USAGE: packagedize [-t] name version [directory_containing_source_code] \
[build_directory]
       -t  create make test target\n";
}

sub my_prefix {
  use Env;
  my $name = shift;

  if ($0 =~ /(.+)\/bin\/$name/) {
    my $result = $1;
    return $result;
  }
  
  my @path_list = split(/:/, $PATH);
  
  for my $path(@path_list) {
    if (-x "$path/$name") {
      $path =~ s/\/bin//;
      return $path;
    }
  }

}

sub install 
{
   use File::Copy;
   my $src = shift;
   my $dest = shift;
   my $mode = shift;

   copy($src, $dest) || die "Failed to copy $src to $dest\n";
   chmod($mode, $dest) || die "Failed to change $dest to mode $mode\n";
}


=head1 NAME

B<gpt-setup> - Create automake and autoconf files to convert
software into a package

=head1 SYNOPSIS

gpt-setup name version [directory_containing_source_code] [build_directory]

=head1 DESCRIPTION

B<gpt-setup> creates Makefile.am files and a configure.in file as well
as other stuff that is used to convert a software distribution into a
globus package.  I<name> is the name of the package. I<version> is the
version of the package.  I<directory_containing_source_code> is the
top source directory for the distribution (the default is the current
directory).  I<build_directory> is the top level directory containing
the resulting binaries (default is the source directory).  The
resulting build depends on other files from the globus packaging tools
(GPT) as well as the globus_core package.  B<NOTE> that the files that
gpt-setup creates need to be edited by hand in order for the packaging
to be complete. The idea behind gpt-setup is simple; "It is easier to
edit than to create.".

=head1 Description of the Files that B<gpt-setup> Creates

=over 4

=item B<Makefile.am>.  B<gpt-setup> creates a Makefile.am in the top
level directory and every subdirectory except for those called CVS or
RCS.  The Makefile.am files contain a list of sources, subdirectories,
libraries, programs, and scripts.  All libraries will be built as
libtool libraries.  B<NOTE> that all of the sources found will be
included in all of the targets found.  All libraries and executables
have flags from the autoconf variables GPT_INCLUDES, GPT_CFLAGS,
GPT_LDFLAGS, and GPT_LIBS added to them.  All of the Makefiles contain
directives to include files from globus_core that contain standard
make targets and rules.

=item B<configure.in> B<gpt-setup> creates a top level configure.in
containing the standard GLOBUS_* macros from globus_core. The script
detects the occurance of *.in files and headers and adds them to
AM_CONFIG_HEADER and AC_OUTPUT.

=item B<bootstrap> B<gpt-setup> creates a top level bootstrap script
which is used to invoke aclocal, automake, autoheader, and autoconf in
the correct order.

=item B<pkgdata> B<gpt-setup> creates a pkgdata directory that contains the following:

=over 4

=item B<pkg_data_src.gpt.in> is a file that contains the packaging
metadata for the newly created package.  B<gpt-setup> inserts the name
and version of the package as well as a list of all of the libraries
that the package provides.

=item B<MyFilelists.pm> is a perl module that is used by
B<gpt_sort_file_list> to sort the installed files from the source
package into binary packages.  The module can be modified to take care
of special files.

=item B<Makefile.am> is a makefile that assembles the filelists and
packaging data into the various files.

=back

=back

=head1 Post gpt-setup Tasks (What is Left to the Developer)


B<gpt-setup> does not do everything that is needed to compile a
package.  Some tasks need a developer's touch.  Here is a checklist of
tasks that may need to be done by hand:

=over 4

=item  Dependencies need to be added to pkgdata/pkg_data_src.gpt.in

You can use the GUI tool B<gpt-edit> or edit the file by hand.  The
format is explained in B<Package>, B<SourceDependency>, and
B<Version>.

=item  Build Environment flags need to be added to configure.in

Use the autoconf macros GPT_SET_CFLAGS, GPT_SET_INCLUDES, GPT_SET_LIBS
pass build environment flags to both the Makefiles and the packaging
metadata. With the exception of GPT_SET_CFLAGS, these flags will be
included in the packaging metadata and used when packages using this
package are built.  See B<Package> for details on the build
environment metadata.

=item Source needs to be assigned to programs and libraries in the Makefile.am's.

B<gpt-edit> automatically assigns all source found in a directory to
all of the targets found in a directory.  For example:

  Sources = \
         foo.c \
         foo.h \
         fee.c \
         fee.h

  bin_programs = foo fee

  foo_SOURCES = $(Sources)
  fee_SOURCES = $(Sources)

As you can see both programs fee and foo wind up being built with the
same set of sources.  This is of course wrong and needs to be
corrected for every directory where more than one program or
library is built.

=item Autoconf defines need to be tested for

Use B<gpt-undefines> to identify all of the preprocesser macros that
are used in the source code which are not defined internally.  This
list will highlight the autoconf tests that need to be added to the
configure.in script. 

=back

=head1 SEE ALSO

gpt-edit(8) gpt-undefines(8) automake(1) autoconf(1) Package(3) Version(3) SourceDependency(3)

=head1 AUTHOR

Michael Bletzinger E<lt>mbletzin.ncsa.uiuc.eduE<gt> and Eric Blau
E<lt>eblau.ncsa.uiuc.eduE<gt>

=cut