eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
    & eval 'exec perl -S $0 $argv:q'
    if 0;

# make_release,v 4.61 2002/02/09 21:20:29 bala Exp
#
# Creates an ACE or TAO kit.  Intended to be called from the
# ACE or TAO top-level Makefiles.
#
# The first three lines above let this script run without specifying the
# full path to perl, as long as it is in the user's PATH.
# Taken from perlrun man page.

use strict;

my $usage="usage: $0 [-?] [-i] [-g] [-k <kit>] [-n] [-v <version>] " .
  "[-ta <ACE tag>] [-tt <TAO tag>] " .
  "[-c <controlled files>] [-r <release files>] [-l <release lib files] " .
  "[-u] [-z]\n";
my $long_usage="   -? option prints this message\n" .
  "   -i to install to public web server directory\n" .
  "   -g to generate the man pages\n" .
  "   -k <kit>, where <kit> is ace, tao, or ace+tao\n" .
  "   -n option prints what would be done, but doesn't do it\n" .
  "   -v <version>, where <version> is major, minor, or beta (default)\n" .
  "   -ta <ACE tag>, to specify ACE tag to be use for checkout (export)\n" .
  "   -tt <TAO tag>, to specify TAO tag to be use for checkout (export)\n" .
  "   -c <controlled files> lists the CVS-controlled files\n" .
  "   -r <release files> lists the files to be released\n" .
  "   -l <release lib files> list the files to put in the lib kit\n" .
  "   -u to update versions\n" .
  "   -z to suppress creation of .zip files\n";


########
######## Sanity checks.
########
$ENV{'SIGNATURE'} ||
  die "$0: must set your SIGNATURE environment variable\n";

my $which_host = $ENV{'OSTYPE'};

my $release_host = substr ($which_host, 0, 5);

## We are not going to use any Sun boxes for the release anymore.. 

if (! ($release_host eq 'linux')){
    die "$0: You are on the wrong OS, please move to linux box\n";
}

my  $perl_path = '/usr/bin/perl';

&can_run($perl_path.' -V') ||
  die "$0: perl path is incorrect, please fix the script\n";

my $dot_path = '/usr/bin';

&can_run($dot_path.'/dot -V') ||
  die "$0: dot path is incorrect, please fix the script\n";

my  $doxy_path = '/project/deuce/doxygen/bin';

my $doxy_version = '1.2.13.1';

&can_run($doxy_path.'/doxygen --version | grep '.$doxy_version.' >/dev/null') ||
  die "$0: doxygen path or version incorrect, please fix the script\n";

$ENV{'PATH'} = $ENV{'PATH'}.':'.$doxy_path;

my $hostname;
chomp ($hostname = $ENV{'HOSTNAME'}  ||  `uname -n`);
unless ("$hostname" eq 'deuce.doc.wustl.edu') {
  #### For efficiency sake . . .
  die "$0: must run on host deuce.doc.wustl.edu\n";
}


$ENV{'CVSROOT'} ||
  die "$0: must set your CVSROOT environment variable\n";

$ENV{'ACE_ROOT'} ||
  die "$0: must set your CVSROOT environment variable\n";

########
######## Configuration parameters.
########
my $gnu = '/bin';

####### Add the path to /bin unconditionally..

$ENV{'PATH'} = "$gnu" . ':' . $ENV{'PATH'};

### Any tools in /usr/local/bin can also be added. We dont need that
### for deuce.doc 
my $gnu2 = '/usr/bin';

####### Add the path to /usr/bin unconditionally..
$ENV{'PATH'} = "$gnu2" . ':' . $ENV{'PATH'};

my $export_dir = '/project/deuce/ftp/pub/ACE+TAO-distribution';
my $diffs_dir = "$export_dir/diffs";
my $exec_prefix = '';
my $generate_man_pages = 0;
my $install = 0;
my $kit = '';
my $release_type = 'beta';
my $ace_tag = my $tao_tag = '';
my $controlled_files = my $release_files = my $release_lib_files = '';
my $release_tag_files = '';
my $release_filter = '\\( -name CVS -o -name build \\) -prune -o ' .
                     '! -name \'.\#*\' ! -name \'\#*\' ! -name \'*~\' ' .
                     '! -name \'*.MAK\' -print';
my $update_versions = 0;
my $create_zips = 1;


########
######## Process command line args.
########
while ($#ARGV >= $[  &&  $ARGV[0] =~ /^-/) {
  if ($ARGV[0] eq '-i') {
    $install = 1;
  } elsif ($ARGV[0] eq '-g') {
    $generate_man_pages = 1;
  } elsif ($ARGV[0] eq '-k') {
    if ($ARGV[1] =~ /^[^-]+/  &&
        ($ARGV[1] eq 'ace' || $ARGV[1] eq 'tao' || $ARGV[1] eq 'ace+tao')) {
      $kit = $ARGV[1]; shift;
    } else {
      print STDERR "$0:  must provide argument for -k option\n";
      die "$usage$long_usage";
    }
  } elsif ($ARGV[0] eq '-n') {
    $exec_prefix = 'echo ';
  } elsif ($ARGV[0] eq '-v') {
    if ($ARGV[1] =~ /^[^-]+/  &&
        ($ARGV[1] eq 'major' || $ARGV[1] eq 'minor' ||
         $ARGV[1] eq 'beta')) {
      $release_type = $ARGV[1]; shift;
    } else {
      print STDERR "$0:  must provide argument for -v option\n";
      die "$usage$long_usage";
    }
  } elsif ($ARGV[0] eq '-ta') {
    if ($ARGV[1] =~ /^[^-]+/) {
      $ace_tag = $ARGV[1]; shift;
    } else {
      print STDERR "$0:  must provide argument for -ta option\n";
      die "$usage$long_usage";
    }
  } elsif ($ARGV[0] eq '-tt') {
    if ($ARGV[1] =~ /^[^-]+/) {
      $tao_tag = $ARGV[1]; shift;
    } else {
      print STDERR "$0:  must provide argument for -tt option\n";
      die "$usage$long_usage";
    }
  } elsif ($ARGV[0] eq '-c') {
    if ($ARGV[1] =~ /^[^-]+/) {
      $controlled_files = $ARGV[1]; shift;
    } else {
      print STDERR "$0:  must provide argument for -c option\n";
      die "$usage$long_usage";
    }
  } elsif ($ARGV[0] eq '-r') {
    if ($ARGV[1] =~ /^[^-]+/) {
      $release_files = $ARGV[1]; shift;
    } else {
      print STDERR "$0:  must provide argument for -r option\n";
      die "$usage$long_usage";
    }
  } elsif ($ARGV[0] eq '-l') {
    if ($ARGV[1] =~ /^[^-]+/) {
      $release_lib_files = $ARGV[1]; shift;
    } else {
      print STDERR "$0:  must provide argument for -l option\n";
      die "$usage$long_usage";
    }
  } elsif ($ARGV[0] eq '-u') {
    $update_versions = 1;
  } elsif ($ARGV[0] eq '-z') {
    $create_zips = 0;
  } elsif ($ARGV[0] eq '-?') {
    print "$usage$long_usage";
    exit;
  } else {
    print STDERR "$0:  unknown option $ARGV[0]\n";
    die "$usage$long_usage";
  }
  shift;

}

die "$0: must specify a -k option\n" unless "$kit";
my $KIT;
if ($kit eq 'ace') {
  $KIT = 'ACE';
} elsif ($kit eq 'tao') {
  $KIT = 'TAO';
} else {
  #### Creating combined ACE+TAO kit.  Don't use $KIT.
};

my $chmod = 'chmod';
# All of them had gnu suffixes. Removed them..
my $chgrp = 'chgrp';
my $cpio = 'cpio';
my $cvs = 'cvs';
my $date = 'date';
my $egrep = 'egrep';
my $find = 'find';
my $gzip = 'gzip';
my $bzip2 = 'bzip2';
my $make = 'make -s';
my $mv = 'mv -f';
my $rm = 'rm -f';
my $md5sum = 'md5sum';
chop (my $now = `$date +"%a %b %d %T %Y"`);

unless ("$controlled_files") {
  chomp ($controlled_files = `$make show_controlled_files`);
}

unless ("$release_files") {
  chomp ($release_files = `$make show_release_files`);
}

unless ("$release_lib_files") {
  chomp ($release_lib_files = `$make show_release_lib_files`);
}

unless ("$release_tag_files") {
  chomp ($release_tag_files = `$make show_release_tag_files`);
}

########
######## Setup signal handlers.
########
my $status = 1;  #### Must get set to 0 explicitly to indicate success.
$SIG{'HUP'} = $SIG{'INT'} = $SIG{'QUIT'} = $SIG{'TERM'} = 'cleanup';


########
######## Defend against fascist umasks.
########
umask 022;


my $major_version = my $minor_version = my $beta_version = 0;
my $previous_version = my $version = '';
my $ace_version = '';

########
######## Main execution thread.
########
if ($update_versions  &&  "$kit" ne 'ace+tao') {
  #### Update versions and tag, but don't create the kit.

  $status =
    &check_workspace ()  ||
    &get_versions ()  ||
    &update_version_files ()  ||
    &update_changelog ()  ||
    &tag ();
} else {
  #### Create the kit.

  #### If a tag was specified, export using the tag from a staging area.
  #### If not, create a kit from the current directory.
  my $stage_dir = '..';
  if ("$ace_tag"  ||  "$tao_tag") {
    $stage_dir = "/tmp/ACE_wrappers_stage-$$/";
    unless ("$exec_prefix") {
      mkdir "$stage_dir", 0755  ||
        die "$0: unable to mkdir $stage_dir\n";
    }
  }

  if ("$exec_prefix") {
    print "chdir $stage_dir\n";
  } else {
    chdir $stage_dir  ||  die "$0: unable to chdir $stage_dir\n";
  }

  if ("$ace_tag") {
    &ex ("$cvs -q export -r$ace_tag -kv ACE_wrappers > /dev/null")  &&
      die "$0: failed cvs export of $ace_tag in $stage_dir\n";
    unless ("$exec_prefix") {
      mkdir "ACE_wrappers/man", 0755  ||
        die "$0: unable to mkdir $stage_dir/ACE_wrappers/man\n";
      mkdir "ACE_wrappers/man/man3", 0755  ||
        die "$0: unable to mkdir $stage_dir/ACE_wrappers/man/man3\n";
    }
    if ($generate_man_pages) {
      &ex ("cd ACE_wrappers && bin/generate_doxygen.pl -is_release -exclude_tao -perl_path $perl_path -dot_path $dot_path")
	&& die "$0: failed to generate ACE man pages in $stage_dir\n";

##      DONT generate the windex database on Linux. Things get screwed. 
##      &ex ("cd ACE_wrappers/man && catman -w -M .")
##	&& die "$0: failed to generate man page index in $stage_dir\n";
    }
    &ex ("cd ACE_wrappers  &&  $make ACE-INSTALL")  &&
      die "$0: failed make ACE-INSTALL in $stage_dir/ACE_wrappers\n";
  }

  if ("$tao_tag") {
    &ex ("$cvs -q export -r$tao_tag -kv ACE_wrappers/TAO > /dev/null")  &&
      die "$0: failed cvs export of $tao_tag in $stage_dir\n";
    &ex ("cd ACE_wrappers/TAO  &&  $make INSTALL orbsvcs/README")  &&
      die "$0: failed make INSTALL TAO/orbsvcs/README in " .
          "$stage_dir/ACE_wrappers/TAO\n";

    if ($generate_man_pages) {
      &ex ("cd ACE_wrappers && bin/generate_doxygen.pl -is_release -exclude_ace -perl_path $perl_path -dot_path $dot_path")
	&& die "$0: failed to generate TAO man pages in $stage_dir\n";
    }
  }

  $status = &create_kit ();

  if (! $status  &&  $install) {
    if ("$ace_tag") {
      my $major_v = 0;
      my $minor_v = 0;
      my $beta_v = 0;
      if ($ace_tag =~ /(\d+)_(\d+)_(\d+)/o) {
        my $major_v = $1;
        my $minor_v = $2;
        my $beta_v = $3;

        ## There is a small problem here and was reported by Don
        ## Hinton<don@gmx.net> . The problem is that
        ## $previous_version = "$major_v.$minor_v.$previous_beta";
        ## // and hence if $previous_beta == 0 then the current beta
        ## == 1 and so $previous_version == "X.Y.0"
        ## &diff ('ACE_wrappers', "ACE-$previous_version", "$ace_tag");
        ## // so "ACE-$previous_version" == "ACE-X.Y.0"
        ## Which gets sent to cvs as "ACE-X_Y_0" but since the real
        ## tag is "ACE-X_Y", rdiff doesn't find anything. This problem
        ## needs fixing. Will fix this when we get time.

        #### $previous_version is used by diff ().
        if ($beta_v > 0) {
          my $previous_beta = $beta_v - 1;
          $previous_version = "$major_v.$minor_v.$previous_beta";

          &diff ('ACE_wrappers', "ACE-$previous_version", "$ace_tag");
        }
      }
    }

    if ("$tao_tag") {
      my $major_v = 0;
      my $minor_v = 0;
      my $beta_v = 0;
      if ($tao_tag =~ /(\d+)_(\d+)_(\d+)/o) {
        my $major_v = $1;
        my $minor_v = $2;
        my $beta_v = $3;

        #### $previous_version is used by diff ().
        if ($beta_v > 0) {
          my $previous_beta = $beta_v - 1;
          $previous_version = "$major_v.$minor_v.$previous_beta";

          &diff ('ACE_wrappers/TAO', "TAO-$previous_version", "$tao_tag");
        }
      }
    }
  }

  if ("$ace_tag"  ||  "$tao_tag") {
    if ($install) {
      chdir "..";
      &ex ("$rm -r $stage_dir")  &&
        warn "$0: failed to remove $stage_dir\n";
    } else {
      warn "$0: kits are in $stage_dir\n";
    }
  }
}
&cleanup;


########
######## Clean up when done or on signal.
########
sub cleanup {
  exit $status;
}


########
######## Check that the workspace is up-to-date, if releasing from
######## the official release directory.
########
sub check_workspace () {
  my $module;

  if ($kit =~ /^ace/) {
    chdir '..'  ||  die "$0: unable to chdir ..\n";
    $module = 'ACE_wrappers';
  } elsif ($kit =~ /tao/) {
    chdir '../..'  ||  die "$0: unable to chdir ../..\n";
    $module = 'ACE_wrappers/TAO';
  }

  my @out_of_date = ();
  open (CVS, "$cvs -nq checkout -P $module 2>&1 |")  ||
    die "$0: unable to open $cvs\n";
  while (<CVS>) {
    next if m%^U %;    #### Allow others to update the repository.
    next if m%^cvs checkout: New directory `.*' -- ignored$%;  #### empty dirs.

    push (@out_of_date, $_) if "$_";
  }
  close CVS;

  if ($kit =~ /^ace/) {
    chdir 'ACE_wrappers'  ||  die "$0: unable to chdir ACE_wrappers\n";
  } elsif ($kit =~ /tao/) {
    chdir 'ACE_wrappers/TAO'  ||  die "$0: unable to chdir ACE_wrappers/TAO\n";
  }

  if (@out_of_date) {
    warn "ERROR: workspace must be updated (with cvs -q up -d) or " .
         "cleaned:\n  " .
         join ("\n  ", @out_of_date) . "\n";
    return 1;
  }

  0;
}


########
######## Retrieve version information from VERSION file(s).
########
sub get_versions () {
  open (VERSION, '< VERSION')  ||
    die "$0: unable to open VERSION\n";
  while (<VERSION>) {
    if (/$KIT version (\d+)\.(\d+)\.(\d+)/o) {
      $major_version = $1;
      $minor_version = $2;
      $beta_version = $3;
      last;
    } elsif (/$KIT version (\d+)\.(\d+)[^\.]/o) {
      #### Previous release was a minor.
      $major_version = $1;
      $minor_version = $2;
      last;
    } elsif (/$KIT version (\d+)[^\.]/o) {
      #### Previous release was a major.
      $major_version = $1;
      last;
    }
  }
  close VERSION;

  if ($release_type eq 'beta') {
    ++$beta_version;
    $version = "$major_version.$minor_version.$beta_version";
  } elsif ($release_type eq 'minor' ) {
    $beta_version = 0;
    ++$minor_version;
    $version = "$major_version.$minor_version";
  } elsif ($release_type eq 'major' ) {
    $minor_version = $beta_version = 0;
    ++$major_version;
    $version = "$major_version.$minor_version";
  }

  print "new $KIT version: $version\n";

  if ($kit =~ /tao/) {
    my $ace_major_version = my $ace_minor_version = my $ace_beta_version = 0;
    open (ACE_VERSION, '< ../VERSION')  ||
      die "$0: unable to open ../VERSION\n";
    while (<ACE_VERSION>) {
      if (/ACE version (\d+)\.(\d+)\.(\d+)/o) {
        $ace_major_version = $1;
        $ace_minor_version = $2;
        $ace_beta_version = $3;
        last;
      } elsif (/ACE version (\d+)\.(\d+)[^\.]/o) {
        #### ACE release was a minor.
        $ace_major_version = $1;
        $ace_minor_version = $2;
        last;
      } elsif (/ACE version (\d+)[^\.]/o) {
        #### ACE release was a major.
        $ace_major_version = $1;
        last;
      }
    }
    close ACE_VERSION;

    if ($ace_beta_version == 0) {
      $ace_version = "$ace_major_version.$ace_minor_version";
    } else {
      $ace_version = "$ace_major_version.$ace_minor_version.$ace_beta_version";
    }
  }

  0;
}


########
######## Update VERSION file(s).
########
sub update_version_files () {
  &ex ("perl -pi -e " .
       "'s/$KIT version .*/$KIT version $version, released $now./' VERSION");
  return 1 if $? >> 8;

  &ex ("perl -pi -e 's/$KIT VERSION:.*/$KIT VERSION: $version/' " .
       "PROBLEM-REPORT-FORM");
  return 1 if $? >> 8;

  if ($kit =~ /^tao/) {
    &ex ("perl -pi -e 's/ACE VERSION:.*/ACE VERSION: $ace_version/' " .
         "PROBLEM-REPORT-FORM");
    return 1 if $? >> 8;

    if ("$exec_prefix") {
      print "TAO version ${major_version}.${minor_version}.${beta_version}\n";
    } else {
      open (TAO_VERSION_H, "> tao/Version.h")  ||
        die "$0: unable to open tao/Version.h\n";

      print TAO_VERSION_H
        "// \$Id\$\n" .
        "// This is an automatically generated file.\n\n" .
        "\#define TAO_MAJOR_VERSION ${major_version}\n" .
        "\#define TAO_MINOR_VERSION ${minor_version}\n" .
        "\#define TAO_BETA_VERSION ${beta_version}\n" .
        "\#define TAO_VERSION \"${version}\"\n";

      close TAO_VERSION_H;
    }
  }

  if ($kit =~ /^ace/) {
    if ("$exec_prefix") {
      print "ACE version ${major_version}.${minor_version}.${beta_version}\n";
    } else {

      open (ACE_VERSION_H, "> ace/Version.h")  ||
        die "$0: unable to open ace/Version.h\n";

      print ACE_VERSION_H
        "// \$Id\$\n" .
        "// This is an automatically generated file.\n\n" .
        "\#define ACE_MAJOR_VERSION ${major_version}\n" .
        "\#define ACE_MINOR_VERSION ${minor_version}\n" .
        "\#define ACE_BETA_VERSION ${beta_version}\n" .
        "\#define ACE_VERSION \"${version}\"\n";

      close ACE_VERSION_H;
    }
  }

  0;
}


########
######## Add ChangeLog entries, and make sure that they have proper
######## permissions.
########
sub update_changelog () {
  my $logname = $ENV{'LOGNAME'};
  if (! "$logname") {
    chop ($logname = `/usr/ucb/whoami`);
  }
  my $signature = $ENV{'SIGNATURE'} || $logname;
  my $message = "$now  $signature  <$logname\@cs.wustl.edu>\n\n" .
                "        * $KIT version $version released.\n\n";

  if ("$exec_prefix") {
    print "Adding to ChangeLog: \n", $message, "\n";
    return 0;
  }
  open (NEW_CHANGELOG, ">ChangeLog.bak")
    || return 1;
  open (CHANGELOG, "ChangeLog")
    || return 1;
  print NEW_CHANGELOG $message;
  while (<CHANGELOG>) {
    print NEW_CHANGELOG $_;
  }
  close (CHANGELOG)
    || return 1;
  close (NEW_CHANGELOG)
    || return 1;
  rename "ChangeLog.bak", "ChangeLog"
    || return 1;

  my $version_h = $kit =~ /^ace/  ?  'ace/Version.h'  :  'tao/Version.h';

  &ex ("$cvs commit -m'$version' " .
       "VERSION PROBLEM-REPORT-FORM ChangeLog $version_h  &&  " .
       "chmod 0644 VERSION PROBLEM-REPORT-FORM ChangeLog $version_h; " .
       "chgrp doc VERSION PROBLEM-REPORT-FORM ChangeLog $version_h");
  return 1 if $? >> 8;

  0;
}


########
######## Tag the release.
########
sub tag () {
  my $tag = "$KIT-$version";
  #### cvs tag does not allow dots.
  $tag =~ tr/./_/;

  print "start tagging $tag\n";
  if ($KIT eq "TAO") {
    chdir "..";
  }
  &ex ("$cvs -q tag $tag $controlled_files $release_tag_files > /dev/null");
  if ($KIT eq "TAO") {
    chdir "TAO";
  }
  return 1 if $? >> 8;
  print "finished tagging $tag\n";

  0;
}


########
######## If building a beta, create a diff from the previous version.
########
sub diff () {
  my ($module, $previous_tag, $tag) = @_;

  if ("$previous_version") {
    #### Only create a diff for a beta version.

    #### cvs tag does not allow dots.
    $previous_tag =~ tr/./_/;
    $tag =~ tr/./_/;

    &ex ("nice -15 $cvs -q rdiff -u -r $previous_tag -r $tag " .
           "$module 2>/dev/null | " .
         "nice -15 sed 's%ACE_wrappers-repository/%ACE_wrappers/%g' | " .
         "nice -15 $gzip -9 > $diffs_dir/$previous_tag-$tag.diff.gz")
     if -d "$diffs_dir";
  }

  #### Ignore return value.  No promises on diffs.
  0;
}


########
######## Create the tar file(s) and move to their proper location.
########
sub create_kit () {

  #### Create kits with group write permission.
  umask 002;

  my $dest = $install  ?  "$export_dir"  :  'created';
  my $dispose = $install  ?  "$mv"  :  'echo';
  my $checksum = $install  ?  "$md5sum"  :  'echo';
  my $cksum_ext = 'md5';
  my $redirect = $install  ?  '>'  :  '\>';
  my $shell_cd = $install  ?  'cd'  :  'echo cd';

  # These files don't get LF->CRLF conversions done when making the zip.
  my $bin_files =
    "\"\\.dsp|\\.dsw|\\.mak|\\.mdp|\\.ide|\\.exe\|\\.ico\|\\.gz\|\\.zip\|" .
    "\\.gif\"";

  my $build_command;
  my $archives;

  ##### @@ DISABLED UNTIL READY FOR GENERAL USE -- Ossama
  ## Temporary ACE+autoconf hack to bootstrap autoconf support into
  ## ACE distribution.
  #&ex("cd ACE_wrappers && bin/bootstrap");

  if ($kit eq 'ace'  ||  $kit eq 'ace+tao') {
    if ($create_zips) {
      $build_command =
        "$rm ACE.zip ACE-lib.zip; " .
        "$find $release_files $release_filter | $egrep $bin_files | " .
          "zip ACE.zip -q9@ &&" .
        "$find $release_files $release_filter | $egrep -v $bin_files | " .
          "zip ACE.zip -qlg9@ &&" .
        "$find $release_lib_files $release_filter | $egrep $bin_files | " .
          "zip ACE-lib.zip -q9@ &&" .
        "$find $release_lib_files $release_filter | $egrep -v $bin_files | " .
          "zip ACE-lib.zip -qlg9@ &&" .
        "$find $release_files $release_filter | $cpio -o -H tar | " .
          "$gzip -9 > ACE.tar.gz && " .
        "$find $release_files $release_filter | $cpio -o -H tar | " .
          "$bzip2 > ACE.tar.bz2 && " .
        "$find $release_lib_files $release_filter | $cpio -o -H tar | " .
          "$gzip -9 > ACE-lib.tar.gz && " .
        "$find $release_lib_files $release_filter | $cpio -o -H tar | " .
          "$bzip2 > ACE-lib.tar.bz2 && " .
	"$find ACE_wrappers/html $release_filter | $cpio -o -H tar | " .
	  "$gzip -9 > ACE-html.tar.gz && ".
	"$find ACE_wrappers/html $release_filter | $cpio -o -H tar | " .
	  "$bzip2 -9 > ACE-html.tar.bz2 && ".
	"$find ACE_wrappers/html $release_filter | $egrep $bin_files | " .
	  "zip ACE-html.zip -q9@ &&" .
	"$find ACE_wrappers/html $release_filter | $egrep -v $bin_files | " .
	  "zip ACE-html.zip -qlg9@ &&" .
        "$chmod 664 ACE.tar.gz ACE-lib.tar.gz ACE.tar.bz2 ACE-lib.tar.bz2 ".
	  "ACE.zip ACE-lib.zip ACE-html.zip && " .
        "$chgrp doc ACE.tar.gz ACE-lib.tar.gz ACE.tar.bz2 ACE-lib.tar.bz2 ".
	  "ACE.zip ACE-lib.zip ACE-html.zip && " .
        "$dispose ACE.zip ACE-lib.zip ACE-html.zip $dest && " .
        "$dispose ACE.tar.gz ACE-lib.tar.gz ACE-html.tar.gz ACE.tar.bz2 ACE-lib.tar.bz2 ACE-html.tar.bz2 $dest; ";
      $archives = " ACE.tar.gz ACE-lib.tar.gz ACE-html.tar.gz ".
	          "ACE.zip ACE-lib.zip ACE-html.zip ACE.tar.bz2 ACE-lib.tar.bz2 ACE-html.tar.bz2 ";
    } else {
      $build_command =
        "$find $release_files $release_filter | $cpio -o -H tar | " .
          "$gzip -9 > ACE.tar.gz && " .
        "$find $release_lib_files $release_filter | $cpio -o -H tar | " .
          "$gzip -9 > ACE-lib.tar.gz && " .
	"$find ACE_wrappers/html $release_filter | $cpio -o -H tar | " .
	  "$gzip -9 > ACE-html.tar.gz && ".
        "$chmod 664 ACE.tar.gz ACE-lib.tar.gz ACE-html.tar.gz && " .
        "$chgrp doc ACE.tar.gz ACE-lib.tar.gz ACE-html.tar.gz && " .
        "$dispose ACE.tar.gz ACE-lib.tar.gz ACE-html.tar.gz $dest; ";
      $archives = " ACE.tar.gz ACE-lib.tar.gz TAO-html.tar.gz ";
    }
  }

  if ($kit eq 'ace+tao') {
    $release_files .= ' ACE_wrappers/TAO';

    if ($create_zips) {
      $build_command .=
        "$rm ACE+TAO.zip; " .
        "$find $release_files $release_filter | $egrep $bin_files | " .
          "zip ACE+TAO.zip -q9@ &&" .
        "$find $release_files $release_filter | $egrep -v $bin_files | " .
          "zip ACE+TAO.zip -qlg9@ &&" .
        "$find $release_files $release_filter | $cpio -o -H tar | " .
          "$gzip -9 > ACE+TAO.tar.gz && " .
        "$find $release_files $release_filter | $cpio -o -H tar | " .
          "$bzip2 > ACE+TAO.tar.bz2 && " .
        "$chmod 664 ACE+TAO.tar.gz ACE+TAO.zip ACE+TAO.tar.bz2 && " .
        "$chgrp doc ACE+TAO.tar.gz ACE+TAO.zip ACE+TAO.tar.bz2 && " .
        "$dispose ACE+TAO.tar.gz ACE+TAO.zip ACE+TAO.tar.bz2 $dest";
      $archives .= " ACE+TAO.tar.gz ACE+TAO.zip ACE+TAO.tar.bz2 ";
    } else {
      $build_command .=
        "$find $release_files $release_filter | $cpio -o -H tar | " .
          "$gzip -9 > ACE+TAO.tar.gz && " .
        "$find $release_files $release_filter | $cpio -o -H tar | " .
          "$bzip2 > ACE+TAO.tar.bz2 && " .
        "$chmod 664 ACE+TAO.tar.gz && " .
        "$chmod 664 ACE+TAO.tar.bz2 && " .
        "$chgrp doc ACE+TAO.tar.gz && " .
        "$chgrp doc ACE+TAO.tar.bz2 && " .
        "$dispose ACE+TAO.tar.gz $dest";
        "$dispose ACE+TAO.tar.bz2 $dest";
      $archives .= " ACE+TAO.tar.gz ACE+TAO.tar.bz2 ";
    }
  }

  # The "$dest/\$p" is going to look a bit funny if the release isn't
  # being installed in the FTP directory since it will expand to
  # `created/ACE.tar.gz', for example.  No big deal, I guess.
  my $checksum_command =
    "$shell_cd $dest; " .
      "for p in $archives; do " .
      "$rm \${p}.${cksum_ext}; " .
      "$checksum \$p $redirect \${p}.${cksum_ext}; " .
      "done";

  &ex ($build_command);
  &ex ($checksum_command);
}


########
######## Execute a command, unless -n had been specified.  Return value
######## of 0 indicates success.
########
sub ex ()
{
  my ($command) = @_;

  if ("$exec_prefix") {
    print $command . "\n";
    0;
  } else {
    system ("$command");
  }
}

########
######## Verify that a command can be executed, return 1 on sucess
########
sub can_run {
  my $command = shift;

  open (RUN, "$command 2>&1 |")
    || return 0;
  while (<RUN>) {}
  close(RUN)
    || return 0;
  return 1;
}
