#! 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 = $ENV{GLOBUS_LOCATION}; } 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= -version= [-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 # \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 # \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 (