<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package WorkspaceCreator;

# ************************************************************
# Description   : Base class for all workspace creators
# Author        : Chad Elliott
# Create Date   : 5/13/2002
# ************************************************************

# ************************************************************
# Pragmas
# ************************************************************

use strict;
use FileHandle;
use File::Path;
use File::Compare;
use File::Basename;

use Creator;
use Options;

use vars qw(@ISA);
@ISA = qw(Creator Options);

# ************************************************************
# Data Section
# ************************************************************

my($wsext)  = 'mwc';
my($wsbase) = 'mwb';

## Valid names for assignments within a workspace
my(%validNames) = ('cmdline'  =&gt; 1,
                   'implicit' =&gt; 1,
                  );

## Singleton hash maps of project information
my(%allprinfo)   = ();
my(%allprojects) = ();

## Global previous workspace names
my(%previous_workspace_name) = ();

## Constant aggregated workspace type name
my($aggregated) = 'aggregated_workspace';

# ************************************************************
# Subroutine Section
# ************************************************************

sub new {
  my($class)     = shift;
  my($global)    = shift;
  my($inc)       = shift;
  my($template)  = shift;
  my($ti)        = shift;
  my($dynamic)   = shift;
  my($static)    = shift;
  my($relative)  = shift;
  my($addtemp)   = shift;
  my($addproj)   = shift;
  my($progress)  = shift;
  my($toplevel)  = shift;
  my($baseprojs) = shift;
  my($gfeature)  = shift;
  my($feature)   = shift;
  my($hierarchy) = shift;
  my($exclude)   = shift;
  my($makeco)    = shift;
  my($nmod)      = shift;
  my($applypj)   = shift;
  my($genins)    = shift;
  my($into)      = shift;
  my($self)      = Creator::new($class, $global, $inc,
                                $template, $ti, $dynamic, $static,
                                $relative, $addtemp, $addproj,
                                $progress, $toplevel, $baseprojs,
                                $feature, $hierarchy, $nmod, $applypj,
                                $into,
                                'workspace');

  $self-&gt;{'workspace_name'}      = undef;
  $self-&gt;{$self-&gt;{'type_check'}} = 0;
  $self-&gt;{'projects'}            = [];
  $self-&gt;{'project_info'}        = {};
  $self-&gt;{'reading_parent'}      = [];
  $self-&gt;{'project_files'}       = [];
  $self-&gt;{'scoped_assign'}       = {};
  $self-&gt;{'cacheok'}             = 1;
  $self-&gt;{'exclude'}             = {};
  $self-&gt;{'wctype'}              = $self-&gt;extractType("$self");
  $self-&gt;{'modified_count'}      = 0;
  $self-&gt;{'global_feature_file'} = $gfeature;
  $self-&gt;{'coexistence'}         = $makeco;
  $self-&gt;{'project_file_list'}   = {};
  $self-&gt;{'ordering_cache'}      = {};
  $self-&gt;{'handled_scopes'}      = {};
  $self-&gt;{'generate_ins'}        = $genins;

  if (defined $$exclude[0]) {
    my($type) = $self-&gt;{'wctype'};
    if (!defined $self-&gt;{'exclude'}-&gt;{$type}) {
      $self-&gt;{'exclude'}-&gt;{$type} = [];
    }
    push(@{$self-&gt;{'exclude'}-&gt;{$type}}, @$exclude);
  }

  ## Add a hash reference for our workspace type
  if (!defined $previous_workspace_name{$self-&gt;{'wctype'}}) {
    $previous_workspace_name{$self-&gt;{'wctype'}} = {};
  }

  return $self;
}


sub modify_assignment_value {
  my($self)  = shift;
  my($value) = shift;

  ## Workspace assignments do not need modification.
  return $value;
}


sub parse_line {
  my($self)   = shift;
  my($ih)     = shift;
  my($line)   = shift;
  my($status, $error, @values) = $self-&gt;parse_known($line);

  ## Was the line recognized?
  if ($status &amp;&amp; defined $values[0]) {
    if ($values[0] eq $self-&gt;{'grammar_type'}) {
      my($name) = $values[1];
      if (defined $name &amp;&amp; $name eq '}') {
        if (!defined $self-&gt;{'reading_parent'}-&gt;[0]) {
          ## Fill in all the default values
          $self-&gt;generate_defaults();

          ## End of workspace; Have subclass write out the file
          ## Generate the project files
          my($gstat, $creator) = $self-&gt;generate_project_files();
          if ($gstat) {
            ($status, $error) = $self-&gt;write_workspace($creator, 1);
            $self-&gt;{'assign'} = {};
          }
          else {
            $error = 'Unable to generate all of the project files';
            $status = 0;
          }

          $self-&gt;{'modified_count'} = 0;
          $self-&gt;{'workspace_name'} = undef;
          $self-&gt;{'projects'}       = [];
          $self-&gt;{'project_info'}   = {};
          $self-&gt;{'project_files'}  = [];
        }
        $self-&gt;{$self-&gt;{'type_check'}} = 0;
      }
      else {
        ## Workspace Beginning
        ## Deal with the inheritance hiearchy first
        if (defined $values[2]) {
          foreach my $parent (@{$values[2]}) {
            ## Read in the parent onto ourself
            my($file) = $self-&gt;search_include_path("$parent.$wsbase");
            if (!defined $file) {
              $file = $self-&gt;search_include_path("$parent.$wsext");
            }

            if (defined $file) {
              push(@{$self-&gt;{'reading_parent'}}, 1);
              $status = $self-&gt;parse_file($file);
              pop(@{$self-&gt;{'reading_parent'}});

              if (!$status) {
                $error = "Invalid parent: $parent";
              }
            }
            else {
              $status = 0;
              $error = "Unable to locate parent: $parent";
            }
          }
        }

        ## Set up some initial values
        if (defined $name) {
          if ($name =~ /[\/\\]/) {
            $status = 0;
            $error = 'Workspaces can not have a slash ' .
                     'or a back slash in the name';
          }
          else {
            $name =~ s/^\(\s*//;
            $name =~ s/\s*\)$//;

            ## Replace any *'s with the default name
            my($def) = $self-&gt;get_default_workspace_name();
            $name = $self-&gt;fill_type_name($name, $def);

            $self-&gt;{'workspace_name'} = $name;
          }
        }
        $self-&gt;{$self-&gt;{'type_check'}} = 1;
      }
    }
    elsif ($values[0] eq 'assignment') {
      if (defined $validNames{$values[1]}) {
        $self-&gt;process_assignment($values[1], $values[2]);
      }
      else {
        $error = "Invalid assignment name: $values[1]";
        $status = 0;
      }
    }
    elsif ($values[0] eq 'assign_add') {
      if (defined $validNames{$values[1]}) {
        $self-&gt;process_assignment_add($values[1], $values[2]);
      }
      else {
        $error = "Invalid addition name: $values[1]";
        $status = 0;
      }
    }
    elsif ($values[0] eq 'assign_sub') {
      if (defined $validNames{$values[1]}) {
        $self-&gt;process_assignment_sub($values[1], $values[2]);
      }
      else {
        $error = "Invalid subtraction name: $values[1]";
        $status = 0;
      }
    }
    elsif ($values[0] eq 'component') {
      if ($values[1] eq 'exclude') {
        ($status, $error) = $self-&gt;parse_exclude($ih, $values[2]);
      }
      else {
        ($status, $error) = $self-&gt;parse_scope($ih,
                                               $values[1],
                                               $values[2],
                                               \%validNames);
      }
    }
    else {
      $error = "Unrecognized line: $line";
      $status = 0;
    }
  }
  elsif ($status == -1) {
    if ($line =~ /\.$wsext$/) {
      ($status, $error) = $self-&gt;aggregated_workspace($line);
    }
    else {
      push(@{$self-&gt;{'project_files'}}, $line);
      $status = 1;
    }
  }

  return $status, $error;
}


sub aggregated_workspace {
  my($self) = shift;
  my($file) = shift;
  my($fh)   = new FileHandle();

  if (open($fh, $file)) {
    my($oline) = $self-&gt;get_line_number();
    my($tc)    = $self-&gt;{$self-&gt;{'type_check'}};
    my($ag)    = $self-&gt;{'handled_scopes'}-&gt;{$aggregated};
    my($psbd)  = $self-&gt;{'scoped_basedir'};
    my($status, $error, @values) = (0, 'No recognizable lines');

    $self-&gt;{'handled_scopes'}-&gt;{$aggregated} = undef;
    $self-&gt;set_line_number(0);
    $self-&gt;{$self-&gt;{'type_check'}} = 0;
    $self-&gt;{'scoped_basedir'} = dirname($file);

    while(&lt;$fh&gt;) {
      my($line) = $self-&gt;preprocess_line($fh, $_);
      ($status, $error, @values) = $self-&gt;parse_known($line);

      ## Was the line recognized?
      if ($status) {
        if (defined $values[0]) {
          if ($values[0] eq $self-&gt;{'grammar_type'}) {
            if (defined $values[2]) {
              my($name) = basename($file);
              $name =~ s/\.[^\.]+$//;
              $status = 0;
              $error  = 'Aggregated workspace (' . $name .
                        ') can not inherit from another workspace';
            }
            else {
              ($status, $error) = $self-&gt;parse_scope($fh,
                                                     '',
                                                     $aggregated,
                                                     \%validNames);
            }
          }
          else {
            $status = 0;
            $error = 'Unable to aggregate ' . $file;
          }
          last;
        }
      }
      else {
        last;
      }
    }
    close($fh);

    $self-&gt;{'scoped_basedir'} = $psbd;
    $self-&gt;{'handled_scopes'}-&gt;{$aggregated} = $ag;
    $self-&gt;{$self-&gt;{'type_check'}} = $tc;
    $self-&gt;set_line_number($oline);

    return $status, $error;
  }

  return 0, 'Unable to open ' . $file;
}


sub parse_exclude {
  my($self)        = shift;
  my($fh)          = shift;
  my($typestr)     = shift;
  my($status)      = 0;
  my($errorString) = 'Unable to process exclude';

  if ($typestr eq $self-&gt;get_default_component_name()) {
    $typestr = $self-&gt;{'wctype'};
  }

  my(@types)   = split(/\s*,\s*/, $typestr);
  my(@exclude) = ();

  while(&lt;$fh&gt;) {
    my($line) = $self-&gt;preprocess_line($fh, $_);

    if ($line eq '') {
    }
    elsif ($line =~ /^}/) {
      $status = 1;
      $errorString = undef;
      last;
    }
    else {
      push(@exclude, $line);
    }
  }

  foreach my $type (@types) {
    if (!defined $self-&gt;{'exclude'}-&gt;{$type}) {
      $self-&gt;{'exclude'}-&gt;{$type} = [];
    }
    push(@{$self-&gt;{'exclude'}-&gt;{$type}}, @exclude);
  }

  return $status, $errorString;
}


sub excluded {
  my($self) = shift;
  my($file) = shift;

  foreach my $excluded (@{$self-&gt;{'exclude'}-&gt;{$self-&gt;{'wctype'}}}) {
    if ($excluded eq $file || $file =~ /^$excluded\//) {
      return 1;
    }
  }

  return 0;
}


sub handle_scoped_end {
  my($self)   = shift;
  my($type)   = shift;
  my($flags)  = shift;
  my($status) = 1;
  my($error)  = undef;

  if ($type eq $aggregated &amp;&amp;
      !defined $self-&gt;{'handled_scopes'}-&gt;{$type}) {
    ## Replace instances of $PWD with the current directory plus the
    ## scoped_basedir.  We have to do it now otherwise, $PWD will be the
    ## wrong directory if it's done later.
    if (defined $$flags{'cmdline'}) {
      my($dir) = $self-&gt;getcwd() . '/' . $self-&gt;{'scoped_basedir'};
      $$flags{'cmdline'} =~ s/\$PWD(\W)/$dir$1/g;
      $$flags{'cmdline'} =~ s/\$PWD$/$dir/;
    }

    ## Go back to the previous directory and add the directory contents
    ($status, $error) = $self-&gt;handle_scoped_unknown($type, $flags, '.');
  }

  $self-&gt;{'handled_scopes'}-&gt;{$type} = undef;
  return $status, $error;
}


sub handle_scoped_unknown {
  my($self)   = shift;
  my($type)   = shift;
  my($flags)  = shift;
  my($line)   = shift;
  my($status) = 1;
  my($error)  = undef;
  my($dupchk) = undef;

  if ($type eq $aggregated) {
    $line = $self-&gt;{'scoped_basedir'} . ($line ne '.' ? "/$line" : '');
    my(%dup) = ();
    @dup{@{$self-&gt;{'project_files'}}} = ();
    $dupchk = \%dup;
  }

  if (-d $line) {
    my(@files) = ();
    $self-&gt;search_for_files([ $line ], \@files, $$flags{'implicit'});

    ## If we are generating implicit projects within a scope, then
    ## we need to remove directories and the parent directories for which
    ## there is an mpc file.  Otherwise, the projects will be added
    ## twice.
    if ($$flags{'implicit'}) {
      my(%remove) = ();
      foreach my $file (@files) {
        if ($file =~ /\.mpc$/) {
          my($exc) = $file;
          do {
            $exc = dirname($exc);
            $remove{$exc} = 1;
          } while($exc ne '.' &amp;&amp; $exc !~ /[a-z]:[\/\\]/i);
        }
      }

      my(@acceptable) = ();
      foreach my $file (@files) {
        if (!defined $remove{$file}) {
          push(@acceptable, $file);
        }
      }
      @files = @acceptable;
    }

    if (defined $dupchk) {
      foreach my $file (@files) {
        if (exists $$dupchk{$file}) {
          $self-&gt;warning("Duplicate mpc file ($file) added by an " .
                         'aggregate workspace.  It will be ignored.');
        }
        else {
          $self-&gt;{'scoped_assign'}-&gt;{$file} = $flags;
          push(@{$self-&gt;{'project_files'}}, $file);
        }
      }
    }
    else {
      foreach my $file (@files) {
        $self-&gt;{'scoped_assign'}-&gt;{$file} = $flags;
        push(@{$self-&gt;{'project_files'}}, $file);
      }
    }
  }
  else {
    if ($line =~ /\.$wsext$/) {
      ## An aggregated workspace within an aggregated workspace.
      ($status, $error) = $self-&gt;aggregated_workspace($line);
    }
    else {
      if (defined $dupchk &amp;&amp; exists $$dupchk{$line}) {
        $self-&gt;warning("Duplicate mpc file ($line) added by an " .
                       'aggregate workspace.  It will be ignored.');
      }
      else {
        $self-&gt;{'scoped_assign'}-&gt;{$line} = $flags;
        push(@{$self-&gt;{'project_files'}}, $line);
      }
    }
  }
  $self-&gt;{'handled_scopes'}-&gt;{$type} = 1;

  return $status, $error;
}


sub search_for_files {
  my($self)  = shift;
  my($files) = shift;
  my($array) = shift;
  my($impl)  = shift;

  foreach my $file (@$files) {
    if (-d $file) {
      my(@f) = $self-&gt;generate_default_file_list(
                         $file,
                         $self-&gt;{'exclude'}-&gt;{$self-&gt;{'wctype'}});
      $self-&gt;search_for_files(\@f, $array, $impl);
      if ($impl) {
        unshift(@$array, $file);
      }
    }
    else {
      if ($file =~ /\.mpc$/) {
        unshift(@$array, $file);
      }
    }
  }
}


sub remove_duplicate_projects {
  my($self)  = shift;
  my($list)  = shift;
  my($count) = scalar(@$list);

  for(my $i = 0; $i &lt; $count; ++$i) {
    my($file) = $$list[$i];
    foreach my $inner (@$list) {
      if ($file ne $inner &amp;&amp; $file eq dirname($inner) &amp;&amp; ! -d $inner) {
        splice(@$list, $i, 1);
        --$count;
        --$i;
        last;
      }
    }
  }
}


sub generate_default_components {
  my($self)  = shift;
  my($files) = shift;
  my($impl)  = shift;
  my($pjf)   = $self-&gt;{'project_files'};

  if (defined $$pjf[0]) {
    ## If we have files, then process directories
    my(@built) = ();
    foreach my $file (@$pjf) {
      if (!$self-&gt;excluded($file)) {
        if (-d $file) {
          my(@found) = ();
          my(@gen)   = $self-&gt;generate_default_file_list(
                                $file,
                                $self-&gt;{'exclude'}-&gt;{$self-&gt;{'wctype'}});
          $self-&gt;search_for_files(\@gen, \@found, $impl);
          push(@built, @found);
          if ($impl || $self-&gt;{'scoped_assign'}-&gt;{$file}-&gt;{'implicit'}) {
            push(@built, $file);
          }
        }
        else {
          push(@built, $file);
        }
      }
    }

    ## If the workspace is set to implicit
    if ($impl) {
      ## Remove duplicates from this list
      $self-&gt;remove_duplicate_projects(\@built);
    }

    ## Set the project files
    $self-&gt;{'project_files'} = \@built;
  }
  else {
    ## Add all of the wanted files in this directory
    ## and in the subdirectories.
    $self-&gt;search_for_files($files, $pjf, $impl);

    ## If the workspace is set to implicit
    if ($impl) {
      ## Remove duplicates from this list
      $self-&gt;remove_duplicate_projects($pjf);
    }

    ## If no files were found, then we push the empty
    ## string, so the Project Creator will generate
    ## the default project file.
    if (!defined $$pjf[0]) {
      push(@$pjf, '');
    }
  }
}


sub get_default_workspace_name {
  my($self) = shift;
  my($name) = $self-&gt;{'current_input'};

  if ($name eq '') {
    $name = $self-&gt;base_directory();
  }
  else {
    ## Since files on UNIX can have back slashes, we transform them
    ## into underscores.
    $name =~ s/\\/_/g;

    ## Take off the extension
    $name =~ s/\.[^\.]+$//;
  }

  return $name;
}


sub generate_defaults {
  my($self) = shift;

  ## Generate default workspace name
  if (!defined $self-&gt;{'workspace_name'}) {
    $self-&gt;{'workspace_name'} = $self-&gt;get_default_workspace_name();
  }

  my(@files) = $self-&gt;generate_default_file_list(
                        '.',
                        $self-&gt;{'exclude'}-&gt;{$self-&gt;{'wctype'}});

  ## Generate default components
  $self-&gt;generate_default_components(\@files,
                                     $self-&gt;get_assignment('implicit'));
}


sub get_workspace_name {
  my($self) = shift;
  return $self-&gt;{'workspace_name'};
}


sub get_current_output_name {
  my($self) = shift;
  return $self-&gt;{'current_output'};
}


sub write_workspace {
  my($self)      = shift;
  my($creator)   = shift;
  my($addfile)   = shift;
  my($status)    = 1;
  my($error)     = undef;
  my($duplicates) = 0;

  if ($self-&gt;get_toplevel()) {
    my($progress) = $self-&gt;get_progress_callback();

    if (defined $progress) {
      &amp;$progress();
    }

    if ($addfile) {
      ## To be consistent across multiple project types, we disallow
      ## duplicate project names for all types, not just VC6.
      ## Note that these name are handled case-insensitive by VC6
      my(%names) = ();
      foreach my $project (@{$self-&gt;{'projects'}}) {
        my($name) = lc($self-&gt;{'project_info'}-&gt;{$project}-&gt;[0]);
        if (defined $names{$name}) {
          ++$duplicates;
          $self-&gt;error("Duplicate case-insensitive project '$name'. " .
                       "Look in " . dirname($project) . " and " .
                       dirname($names{$name}) .
                       " for project name conflicts.");
        }
        else {
          $names{$name} = $project;
        }
      }
    }
    else {
      $self-&gt;{'per_project_workspace_name'} = 1;
    }

    my($name)   = $self-&gt;transform_file_name($self-&gt;workspace_file_name());
    my($into)   = $self-&gt;get_into();
    my($outdir) = '.';
    my($oname)  = $name;

    if (defined $into) {
      $outdir = $self-&gt;getcwd();
      my($re) = $self-&gt;escape_regex_special($self-&gt;getstartdir());
      $outdir =~ s/^$re//;
      $outdir = $into . $outdir;
      $name = "$outdir/$name";
    }

    my($abort_creation) = 0;
    if ($duplicates &gt; 0) {
      $abort_creation = 1;
      $error = "Duplicate case-insensitive project names are " .
               "not allowed within a workspace.";
      $status = 0;
    }
    else {
      if (!defined $self-&gt;{'projects'}-&gt;[0]) {
        $self-&gt;information('No projects were created.');
        $abort_creation = 1;
      }
    }

    if (!$abort_creation) {
      my($fh)  = new FileHandle();
      my($dir) = dirname($name);

      ## Verify and possibly modify the dependencies
      if ($addfile) {
        $self-&gt;verify_build_ordering();
      }

      if ($dir ne '.') {
        mkpath($dir, 0, 0777);
      }

      if ($addfile || !$self-&gt;file_written($name)) {
        $self-&gt;{'current_output'} = $name;
        if ($self-&gt;compare_output()) {
          ## First write the output to a temporary file
          my($tmp) = "$outdir/MWC$&gt;.$$";
          my($different) = 1;
          if (open($fh, "&gt;$tmp")) {
            $self-&gt;pre_workspace($fh);
            $self-&gt;write_comps($fh, $creator, $addfile);
            $self-&gt;post_workspace($fh);
            close($fh);

            if (-r $name &amp;&amp;
                -s $tmp == -s $name &amp;&amp; compare($tmp, $name) == 0) {
              $different = 0;
            }
          }
          else {
            $error = "Unable to open $tmp for output.";
            $status = 0;
          }

          if ($status) {
            if ($different) {
              unlink($name);
              if (rename($tmp, $name)) {
                if ($addfile) {
                  $self-&gt;add_file_written($oname);
                }
              }
              else {
                $error = 'Unable to open ' . $self-&gt;getcwd() .
                         "/$name for output";
                $status = 0;
              }
            }
            else {
              ## We will pretend that we wrote the file
              unlink($tmp);
              if ($addfile) {
                $self-&gt;add_file_written($oname);
              }
            }
          }
        }
        else {
          if (open($fh, "&gt;$name")) {
            $self-&gt;pre_workspace($fh);
            $self-&gt;write_comps($fh, $creator, $addfile);
            $self-&gt;post_workspace($fh);
            close($fh);

            if ($addfile) {
              $self-&gt;add_file_written($oname);
            }
          }
          else {
            $error = "Unable to open $name for output.";
            $status = 0;
          }
        }
      }
    }

    if (!$addfile) {
      $self-&gt;{'per_project_workspace_name'} = undef;
    }
  }

  return $status, $error;
}


sub save_project_info {
  my($self)     = shift;
  my($gen)      = shift;
  my($gpi)      = shift;
  my($dir)      = shift;
  my($projects) = shift;
  my($pi)       = shift;
  my($c)        = 0;

  ## For each file written
  foreach my $pj (@$gen) {
    ## Save the full path to the project file in the array
    my($full) = ($dir ne '.' ? "$dir/" : '') . $pj;
    push(@$projects, $full);

    ## Get the corresponding generated project info and save it
    ## in the hash map keyed on the full project file name
    $$pi{$full} = $$gpi[$c];
    $c++;
  }
}


sub topname {
  my($self) = shift;
  my($file) = shift;
  my($dir)  = '.';
  my($rest) = $file;
  if ($file =~ /^([^\/\\]+)[\/\\](.*)/) {
    $dir  = $1;
    $rest = $2;
  }
  return $dir, $rest;
}


sub generate_hierarchy {
  my($self)      = shift;
  my($creator)   = shift;
  my($origproj)  = shift;
  my($originfo)  = shift;
  my($current)   = undef;
  my(@saved)     = ();
  my(%sinfo)     = ();
  my($cwd)       = $self-&gt;getcwd();

  ## Make a copy of these.  We will be modifying them.
  ## It is necessary to sort the projects to get the correct ordering.
  ## Projects in the current directory must come before projects in
  ## other directories.
  my(@projects)  = sort { my($sa) = ($a =~ /\//);
                          my($sb) = ($b =~ /\//);
                          if ($sa &amp;&amp; !$sb) {
                            return 1;
                          }
                          elsif ($sb &amp;&amp; !$sa) {
                            return -1;
                          }
                          return $a cmp $b;
                        } @{$origproj};
  my(%projinfo)  = %{$originfo};

  foreach my $prj (@projects) {
    my($top, $rest) = $self-&gt;topname($prj);

    if (!defined $current) {
      $current = $top;
      push(@saved, $rest);
      $sinfo{$rest} = $projinfo{$prj};
    }
    elsif ($top ne $current) {
      ## Write out the hierachical workspace
      $self-&gt;cd($current);
      $self-&gt;generate_hierarchy($creator, \@saved, \%sinfo);

      $self-&gt;{'projects'}       = \@saved;
      $self-&gt;{'project_info'}   = \%sinfo;
      $self-&gt;{'workspace_name'} = $self-&gt;base_directory();

      my($status, $error) = $self-&gt;write_workspace($creator);
      if (!$status) {
        $self-&gt;error($error);
      }
      $self-&gt;cd($cwd);

      ## Start the next one
      $current = $top;
      @saved = ($rest);
      %sinfo = ();
      $sinfo{$rest} = $projinfo{$prj};
    }
    else {
      push(@saved, $rest);
      $sinfo{$rest} = $projinfo{$prj};
    }
  }
  if (defined $current &amp;&amp; $current ne '.') {
    $self-&gt;cd($current);
    $self-&gt;generate_hierarchy($creator, \@saved, \%sinfo);

    $self-&gt;{'projects'}       = \@saved;
    $self-&gt;{'project_info'}   = \%sinfo;
    $self-&gt;{'workspace_name'} = $self-&gt;base_directory();

    my($status, $error) = $self-&gt;write_workspace($creator);
    if (!$status) {
      $self-&gt;error($error);
    }
    $self-&gt;cd($cwd);
  }
}


sub generate_project_files {
  my($self)      = shift;
  my($status)    = (scalar @{$self-&gt;{'project_files'}} == 0 ? 1 : 0);
  my(@projects)  = ();
  my(%pi)        = ();
  my($creator)   = $self-&gt;project_creator();
  my($cwd)       = $self-&gt;getcwd();
  my($impl)      = $self-&gt;get_assignment('implicit');
  my($postkey)   = $creator-&gt;get_dynamic() .
                   $creator-&gt;get_static() . "-$self";
  my($previmpl)  = $impl;
  my($prevcache) = $self-&gt;{'cacheok'};
  my(%gstate)    = $creator-&gt;save_state();
  my($genimpdep) = $self-&gt;generate_implicit_project_dependencies();

  ## Remove the address portion of the $self string
  $postkey =~ s/=.*//;

  ## Set the source file callback on our project creator
  $creator-&gt;set_source_listing_callback([\&amp;source_listing_callback, $self]);

  foreach my $ofile (@{$self-&gt;{'project_files'}}) {
    if (!$self-&gt;excluded($ofile)) {
      my($file)    = $ofile;
      my($dir)     = dirname($file);
      my($restore) = 0;

      if (defined $self-&gt;{'scoped_assign'}-&gt;{$ofile}) {
        ## Handle the implicit assignment
        my($oi) = $self-&gt;{'scoped_assign'}-&gt;{$ofile}-&gt;{'implicit'};
        if (defined $oi) {
          $previmpl = $impl;
          $impl     = $oi;
        }

        ## Handle the cmdline assignment
        my($cmdline) = $self-&gt;{'scoped_assign'}-&gt;{$ofile}-&gt;{'cmdline'};
        if (defined $cmdline &amp;&amp; $cmdline ne '') {
          ## Save the cacheok value
          $prevcache = $self-&gt;{'cacheok'};

          ## Get the current parameters and process the command line
          my(%parameters) = $self-&gt;current_parameters();
          $self-&gt;process_cmdline($cmdline, \%parameters);

          ## Set the parameters on the creator
          $creator-&gt;restore_state(\%parameters);
          $restore = 1;
        }
      }

      ## If we are generating implicit projects and the file is a
      ## directory, then we set the dir to the file and empty the file
      if ($impl &amp;&amp; -d $file) {
        $dir  = $file;
        $file = '';

        ## If the implicit assignment value was not a number, then
        ## we will add this value to our base projects.
        if ($impl !~ /^\d+$/) {
          my($bps) = $creator-&gt;get_baseprojs();
          push(@$bps, split(/\s+/, $impl));
          $restore = 1;
          $self-&gt;{'cacheok'} = 0;
        }
      }

      ## Generate the key for this project file
      my($prkey) = $self-&gt;getcwd() . '/' .
                   ($file eq '' ? $dir : $file) . "-$postkey";

      ## We must change to the subdirectory for
      ## which this project file is intended
      if ($self-&gt;cd($dir)) {
        my($gen) = [];
        my($gpi) = [];
        if ($self-&gt;{'cacheok'} &amp;&amp; defined $allprojects{$prkey}) {
          $gen = $allprojects{$prkey};
          $gpi = $allprinfo{$prkey};
          $status = 1;
        }
        else {
          $status = $creator-&gt;generate(basename($file));

          ## If any one project file fails, then stop
          ## processing altogether.
          if (!$status) {
            ## We don't restore the state before we leave,
            ## but that's ok since we will be exiting soon.
            return $status, $creator;
          }

          ## Get the individual project information and
          ## generated file name(s)
          $gen = $creator-&gt;get_files_written();
          $gpi = $creator-&gt;get_project_info();

          if ($self-&gt;{'cacheok'}) {
            $allprojects{$prkey} = $gen;
            $allprinfo{$prkey}   = $gpi;
          }
        }
        $self-&gt;cd($cwd);
        $self-&gt;save_project_info($gen, $gpi, $dir, \@projects, \%pi);
      }
      else {
        ## Unable to change to the directory.
        ## We don't restore the state before we leave,
        ## but that's ok since we will be exiting soon.
        return 0, $creator;
      }

      ## Return things to the way they were
      if (defined $self-&gt;{'scoped_assign'}-&gt;{$ofile}) {
        $impl = $previmpl;
      }
      if ($restore) {
        $self-&gt;{'cacheok'} = $prevcache;
        $creator-&gt;restore_state(\%gstate);
      }
    }
    else {
      ## This one was excluded, so status is ok
      $status = 1;
    }
  }

  ## Add implict project dependencies based on source files
  ## that have been used by multiple projects.  If we do it here
  ## before we call generate_hierarchy(), we don't have to call it
  ## in generate_hierarchy() for each workspace.
  $self-&gt;{'projects'}     = \@projects;
  $self-&gt;{'project_info'} = \%pi;
  if ($status &amp;&amp; $genimpdep) {
    $self-&gt;add_implicit_project_dependencies($creator, $cwd);
  }

  ## If we are generating the hierarchical workspaces, then do so
  if ($self-&gt;get_hierarchy() || $self-&gt;workspace_per_project()) {
    my($orig) = $self-&gt;{'workspace_name'};
    $self-&gt;generate_hierarchy($creator, \@projects, \%pi);
    $self-&gt;{'workspace_name'} = $orig;
  }

  ## Reset the projects and project_info
  $self-&gt;{'projects'}     = \@projects;
  $self-&gt;{'project_info'} = \%pi;

  return $status, $creator;
}


sub array_contains {
  my($self)   = shift;
  my($left)   = shift;
  my($right)  = shift;
  my(%check)  = ();

  ## Initialize the hash keys with the left side array
  @check{@$left} = ();

  ## Check each element on the right against the left.
  foreach my $r (@$right) {
    if (exists $check{$r}) {
      return 1;
    }
  }

  return 0;
}


sub non_intersection {
  my($self)   = shift;
  my($left)   = shift;
  my($right)  = shift;
  my($over)   = shift;
  my($status) = 0;
  my(%check)  = ();

  ## Initialize the hash keys with the left side array
  @check{@$left} = ();

  ## Check each element on the right against the left.
  ## Store anything that isn't in the left side in the over array.
  foreach my $r (@$right) {
    if (exists $check{$r}) {
      $status = 1;
    }
    else {
      push(@$over, $r);
    }
  }
  return $status;
}


sub indirect_depdency {
  my($self)   = shift;
  my($dir)    = shift;
  my($ccheck) = shift;
  my($cfile)  = shift;

  if ($self-&gt;{'project_info'}-&gt;{$ccheck}-&gt;[1] =~ /$cfile/) {
    return 1;
  }
  else {
    my($deps) = $self-&gt;create_array(
                         $self-&gt;{'project_info'}-&gt;{$ccheck}-&gt;[1]);
    foreach my $dep (@$deps) {
      if (defined $self-&gt;{'project_info'}-&gt;{"$dir$dep"} &amp;&amp;
          $self-&gt;indirect_depdency($dir, "$dir$dep", $cfile)) {
        return 1;
      }
    }
  }

  return 0;
}


sub add_implicit_project_dependencies {
  my($self)      = shift;
  my($creator)   = shift;
  my($cwd)       = shift;
  my(%bidir)     = ();
  my(%save)      = ();

  ## Take the current working directory and regular expression'ize it.
  $cwd = $self-&gt;escape_regex_special($cwd);

  ## Look at each projects file list and check it against all of the
  ## others.  If any of the other projects file lists contains anothers
  ## file, then they are dependent (due to build parallelism).  So, we
  ## append the dependency and remove the file in question from the
  ## project so that the next time around the foreach, we don't find it
  ## as a dependent on the one that we just modified.
  my(@pflkeys) = keys %{$self-&gt;{'project_file_list'}};
  foreach my $key (@pflkeys) {
    foreach my $ikey (@pflkeys) {
      ## Not the same project and
      ## The same directory and
      ## We've not already added a dependency to this project
      if ($key ne $ikey &amp;&amp;
          ($self-&gt;{'project_file_list'}-&gt;{$key}-&gt;[1] eq
           $self-&gt;{'project_file_list'}-&gt;{$ikey}-&gt;[1]) &amp;&amp;
          (!defined $bidir{$ikey} ||
           !$self-&gt;array_contains($bidir{$ikey}, [$key]))) {
        my(@over) = ();
        if ($self-&gt;non_intersection(
                      $self-&gt;{'project_file_list'}-&gt;{$key}-&gt;[2],
                      $self-&gt;{'project_file_list'}-&gt;{$ikey}-&gt;[2],
                      \@over)) {
          ## The project contains shared source files, so we need to
          ## look into adding an implicit inter-project dependency.
          $save{$ikey} = $self-&gt;{'project_file_list'}-&gt;{$ikey}-&gt;[2];
          $self-&gt;{'project_file_list'}-&gt;{$ikey}-&gt;[2] = \@over;
          if (defined $bidir{$key}) {
            push(@{$bidir{$key}}, $ikey);
          }
          else {
            $bidir{$key} = [$ikey];
          }
          my($append) = $creator-&gt;translate_value('after', $key);
          my($file)   = $self-&gt;{'project_file_list'}-&gt;{$ikey}-&gt;[0];
          my($dir)    = $self-&gt;{'project_file_list'}-&gt;{$ikey}-&gt;[1];
          my($cfile)  = $self-&gt;escape_regex_special(
                              $creator-&gt;translate_value('after', $ikey));
          ## Remove our starting directory from the projects directory
          ## to get the right part of the directory to prepend.
          $dir =~ s/^$cwd[\/\\]*//;

          ## Turn the append value into a key for 'project_info' and
          ## prepend the directory to the file.
          my($ccheck) = $append;
          $ccheck =~ s/"//g;
          if ($dir ne '') {
            $dir .= '/';
            $ccheck = "$dir$ccheck";
            $file = "$dir$file";
          }

          ## If the append value key contains a reference to the project
          ## that we were going to append the dependency value, then
          ## ignore the generated dependency.  It is redundant and
          ## quite possibly wrong.
          if (!defined $self-&gt;{'project_info'}-&gt;{$ccheck} ||
              !$self-&gt;indirect_depdency($dir, $ccheck, $cfile)) {
            ## Append the dependency
            $self-&gt;{'project_info'}-&gt;{$file}-&gt;[1] .= " $append";
          }
        }
      }
    }
  }

  ## Restore the modified values in case this method is called again
  ## which is the case when using the -hierarchy option.
  foreach my $skey (keys %save) {
    $self-&gt;{'project_file_list'}-&gt;{$skey}-&gt;[2] = $save{$skey};
  }
}


sub get_projects {
  my($self) = shift;
  return $self-&gt;{'projects'};
}


sub get_project_info {
  my($self) = shift;
  return $self-&gt;{'project_info'};
}


sub get_first_level_directory {
  my($self) = shift;
  my($file) = shift;
  my($dir)  = undef;
  if (($file =~ tr/\///) &gt; 0) {
    $dir = $file;
    $dir =~ s/^([^\/]+\/).*/$1/;
    $dir =~ s/\/+$//;
  }
  else {
    $dir = '.';
  }
  return $dir;
}


sub sort_within_group {
  my($self)    = shift;
  my($list)    = shift;
  my($start)   = shift;
  my($end)     = shift;
  my($deps)    = undef;
  my($ccount)  = 0;
  my($cmax)    = ($end - $start) + 1;

  ## If we go more than twice the number of elements in this group
  ## factorial, then there is a circular dependency.
  my($f) = $cmax - 1;
  while($f &gt; 1) {
    $cmax *= $f--;
  }
  $cmax = ($cmax * 2) + 1;

  ## Put the projects in the order specified
  ## by the project dpendencies.
  for(my $i = $start; $i &lt;= $end; ++$i) {
    ## Detect circular dependencies
    if ($ccount &gt; $cmax) {
      my($cprojs) = '';
      for(my $j = $i; $j &lt;= $end; ++$j) {
        $cprojs .= ($j != $i ? ', ' : '') . $$list[$j];
      }
      $self-&gt;warning('Circular dependency detected while processing the ' .
                     ($self-&gt;{'current_input'} eq '' ?
                       'default' : $self-&gt;{'current_input'}) .
                     ' workspace. ' .
                     "The following projects are involved: $cprojs");
      return;
    }

    $deps = $self-&gt;get_validated_ordering($$list[$i]);
    if ($deps ne '') {
      my($baseproj) = basename($$list[$i]);
      my($darr) = $self-&gt;create_array($deps);

      my($moved) = 0;
      foreach my $dep (@$darr) {
        if ($baseproj ne $dep) {
          ## See if the dependency is listed after this project
          for(my $j = $i + 1; $j &lt;= $end; ++$j) {
            if (basename($$list[$j]) eq $dep) {
              ## If so, move it in front of the current project.
              ## The original code, which had splices, didn't always
              ## work correctly (especially on AIX for some reason).
              my($save) = $$list[$j];
              for(my $k = $j; $k &gt; $i; --$k) {
                $$list[$k] = $$list[$k - 1];
              }
              $$list[$i] = $save;

              ## Mark that an entry has been moved
              $moved = 1;
              $j--;
            }
          }
        }
      }
      if ($moved) {
        $i--;
      }
    }
    ++$ccount;
  }
}


sub sort_by_groups {
  my($self)    = shift;
  my($list)    = shift;
  my($grindex) = shift;
  my(@groups)  = @$grindex;
  my($ccount)  = 0;
  my($cmax)    = $#groups;

  ## If we go more than twice $#groups factorial, then there is
  ## a circular dependency.
  my($f) = $cmax - 1;
  while($f &gt; 1) {
    $cmax *= $f--;
  }
  $cmax = ($cmax * 2) + 1;

  for(my $gi = 0; $gi &lt;= $#groups; ++$gi) {
    ## Detect circular dependencies
    if ($ccount &gt; $cmax) {
      my($cprojs) = '';
      for(my $j = $groups[$gi]-&gt;[0]; $j &lt;= $groups[$gi]-&gt;[1]; ++$j) {
        $cprojs .= ($j != $groups[$gi]-&gt;[0] ? ', ' : '') . $$list[$j];
      }
      $self-&gt;warning('Circular dependency detected while processing the ' .
                     ($self-&gt;{'current_input'} eq '' ?
                       'default' : $self-&gt;{'current_input'}) .
                     ' workspace. ' .
                     "The following projects are involved: $cprojs");
      return;
    }

    ## Build up the group dependencies
    my(%gdeps) = ();
    for(my $i = $groups[$gi]-&gt;[0]; $i &lt;= $groups[$gi]-&gt;[1]; ++$i) {
      my($deps) = $self-&gt;get_validated_ordering($$list[$i]);
      if ($deps ne '') {
        my($darr) = $self-&gt;create_array($deps);
        foreach my $dep (@$darr) {
          $gdeps{$dep} = 1;
        }
      }
    }

    ## Search the rest of the groups for any of the group dependencies
    my($moved) = 0;
    for(my $gj = $gi + 1; $gj &lt;= $#groups; ++$gj) {
      for(my $i = $groups[$gj]-&gt;[0]; $i &lt;= $groups[$gj]-&gt;[1]; ++$i) {
        if (defined $gdeps{basename($$list[$i])}) {
          ## Move this group ($gj) in front of the current group ($gi)
          my(@save) = ();
          for(my $j = $groups[$gi]-&gt;[1] + 1; $j &lt;= $groups[$gj]-&gt;[1]; ++$j) {
            push(@save, $$list[$j]);
          }
          my($offset) = $groups[$gj]-&gt;[1] - $groups[$gi]-&gt;[1];
          for(my $j = $groups[$gi]-&gt;[1]; $j &gt;= $groups[$gi]-&gt;[0]; --$j) {
            $$list[$j + $offset] = $$list[$j];
          }
          for(my $j = 0; $j &lt;= $#save; ++$j) {
            $$list[$groups[$gi]-&gt;[0] + $j] = $save[$j];
          }

          ## Update the group indices
          my($shiftamt) = ($groups[$gi]-&gt;[1] - $groups[$gi]-&gt;[0]) + 1;
          for(my $j = $gi + 1; $j &lt;= $gj; ++$j) {
            $groups[$j]-&gt;[0] -= $shiftamt;
            $groups[$j]-&gt;[1] -= $shiftamt;
          }
          my(@grsave) = @{$groups[$gi]};
          $grsave[0] += $offset;
          $grsave[1] += $offset;
          for(my $j = $gi; $j &lt; $gj; ++$j) {
            $groups[$j] = $groups[$j + 1];
          }
          $groups[$gj] = \@grsave;

          ## Signify that we have moved a group
          $moved = 1;
          last;
        }
      }
      if ($moved) {
        ## Start over from the first group
        $gi = -1;
        last;
      }
    }
    ++$ccount;
  }
}


sub sort_dependencies {
  my($self)     = shift;
  my($projects) = shift;
  my(@list)     = sort @$projects;

  ## Put the projects in the order specified
  ## by the project dpendencies.  We only need to do
  ## this if there is more than one element in the array.
  if ($#list &gt; 0) {
    ## First determine the individual groups
    my(@grindex)  = ();
    my($previous) = [0, undef];
    for(my $li = 0; $li &lt;= $#list; ++$li) {
      my($dir) = $self-&gt;get_first_level_directory($list[$li]);
      if (!defined $previous-&gt;[1]) {
        $previous = [$li, $dir];
      }
      elsif ($previous-&gt;[1] ne $dir) {
        push(@grindex, [$previous-&gt;[0], $li - 1]);
        $previous = [$li, $dir];
      }
    }
     push(@grindex, [$previous-&gt;[0], $#list]);

    ## Next, sort the individual groups
    foreach my $gr (@grindex) {
      if ($$gr[0] != $$gr[1]) {
        $self-&gt;sort_within_group(\@list, @$gr);
      }
    }

    ## Now sort the groups as single entities
    if ($#grindex &gt; 0) {
      $self-&gt;sort_by_groups(\@list, \@grindex);
    }
  }

  return @list;
}


sub number_target_deps {
  my($self)     = shift;
  my($projects) = shift;
  my($pjs)      = shift;
  my($targets)  = shift;
  my(@list)     = $self-&gt;sort_dependencies($projects);

  ## This block of code must be done after the list of dependencies
  ## has been sorted in order to get the correct project numbers.
  for(my $i = 0; $i &lt;= $#list; ++$i) {
    my($project) = $list[$i];
    if (defined $$pjs{$project}) {
      my($name, $deps) = @{$$pjs{$project}};
      if (defined $deps &amp;&amp; $deps ne '') {
        my(%targetnumbers) = ();
        my($darr) = $self-&gt;create_array($deps);

        ## For each dependency, search in the sorted list
        ## up to the point of this project for the projects
        ## that this one depends on.  When the project is
        ## found, we put the target number in a hash map (to avoid
        ## duplicates).
        foreach my $dep (@$darr) {
          for(my $j = 0; $j &lt; $i; ++$j) {
            if (basename($list[$j]) eq $dep) {
              $targetnumbers{$j} = 1;
            }
          }
        }

        ## Get the keys of the hash map and store the
        ## array in the hash keyed on the project file.
        my(@numbers) = sort { $a &lt;=&gt; $b } keys %targetnumbers;
        if (defined $numbers[0]) {
          $$targets{$project} = \@numbers;
        }
      }
    }
  }

  return @list;
}


sub optionError {
  my($self) = shift;
  my($str)  = shift;
  $self-&gt;warning("$self-&gt;{'current_input'}: $str.");
}


sub process_cmdline {
  my($self)       = shift;
  my($cmdline)    = shift;
  my($parameters) = shift;

  ## It's ok to use the cache
  $self-&gt;{'cacheok'} = 1;

  if (defined $cmdline &amp;&amp; $cmdline ne '') {
    my($args) = $self-&gt;create_array($cmdline);

    ## Look for environment variables
    foreach my $arg (@$args) {
      while($arg =~ /\$(\w+)/) {
        my($name) = $1;
        my($val)  = '';
        if ($name eq 'PWD') {
          $val = $self-&gt;getcwd();
        }
        elsif (defined $ENV{$name}) {
          $val = $ENV{$name};
        }
        $arg =~ s/\$\w+/$val/;
      }
    }

    my($options) = $self-&gt;options('MWC', {}, 0, @$args);
    if (defined $options) {
      foreach my $key (keys %$options) {
        my($type) = $self-&gt;is_set($key, $options);

        if (!defined $type) {
          ## This option was not used, so we ignore it
        }
        elsif ($type eq 'ARRAY') {
          push(@{$parameters-&gt;{$key}}, @{$options-&gt;{$key}});
        }
        elsif ($type eq 'HASH') {
          foreach my $hk (keys %{$options-&gt;{$key}}) {
            $parameters-&gt;{$key}-&gt;{$hk} = $options-&gt;{$key}-&gt;{$hk};
          }
        }
        elsif ($type eq 'SCALAR') {
          $parameters-&gt;{$key} = $options-&gt;{$key};
        }
      }

      ## Issue warnings for these options
      if (defined $options-&gt;{'recurse'}) {
        $self-&gt;optionError('-recurse is ignored');
      }
      if (defined $options-&gt;{'reldefs'}) {
        $self-&gt;optionError('-noreldefs is ignored');
      }
      if (defined $options-&gt;{'coexistence'}) {
        $self-&gt;optionError('-make_coexistence is ignored');
      }
      if (defined $options-&gt;{'genins'}) {
        $self-&gt;optionError('-genins is ignored');
      }
      if (defined $options-&gt;{'into'}) {
        $self-&gt;optionError('-into is ignored');
      }
      if (defined $options-&gt;{'input'}-&gt;[0]) {
        $self-&gt;optionError('Command line files ' .
                           'specified in a workspace are ignored');
      }

      ## Determine if it's ok to use the cache
      my(@cacheInvalidating) = ('global', 'include', 'baseprojs',
                                'template', 'ti', 'relative',
                                'addtemp', 'addproj', 'feature_file');
      foreach my $key (@cacheInvalidating) {
        if ($self-&gt;is_set($key, $options)) {
          $self-&gt;{'cacheok'} = 0;
          last;
        }
      }
    }
  }
}


sub current_parameters {
  my($self) = shift;
  my(%parameters) = $self-&gt;save_state();

  ## We always want the project creator to generate a toplevel
  $parameters{'toplevel'} = 1;
  return %parameters;
}


sub project_creator {
  my($self) = shift;
  my($str)  = "$self";

  ## NOTE: If the subclassed WorkspaceCreator name prefix does not
  ##       match the name prefix of the ProjectCreator, this code
  ##       will not work and the subclassed WorkspaceCreator will
  ##       need to override this method.

  $str =~ s/Workspace/Project/;
  $str =~ s/=HASH.*//;

  ## Set up values for each project creator
  ## If we have command line arguments in the workspace, then
  ## we process them before creating the project creator
  my($cmdline)    = $self-&gt;get_assignment('cmdline');
  my(%parameters) = $self-&gt;current_parameters();
  $self-&gt;process_cmdline($cmdline, \%parameters);

  ## Create the new project creator with the updated parameters
  return $str-&gt;new($parameters{'global'},
                   $parameters{'include'},
                   $parameters{'template'},
                   $parameters{'ti'},
                   $parameters{'dynamic'},
                   $parameters{'static'},
                   $parameters{'relative'},
                   $parameters{'addtemp'},
                   $parameters{'addproj'},
                   $parameters{'progress'},
                   $parameters{'toplevel'},
                   $parameters{'baseprojs'},
                   $self-&gt;{'global_feature_file'},
                   $parameters{'feature_file'},
                   $parameters{'hierarchy'},
                   $self-&gt;{'exclude'}-&gt;{$self-&gt;{'wctype'}},
                   $self-&gt;make_coexistence(),
                   $parameters{'name_modifier'},
                   $parameters{'apply_project'},
                   $self-&gt;{'generate_ins'},
                   $parameters{'into'});
}


sub sort_files {
  #my($self) = shift;
  return 0;
}


sub make_coexistence {
  my($self) = shift;
  return $self-&gt;{'coexistence'};
}


sub get_modified_workspace_name {
  my($self)   = shift;
  my($name)   = shift;
  my($ext)    = shift;
  my($nmod)   = $self-&gt;get_name_modifier();

  if (defined $nmod) {
    $nmod =~ s/\*/$name/g;
    $name = $nmod;
  }

  ## If this is a per project workspace, then we should not
  ## modify the workspace name.  It may overwrite another workspace
  ## but that's ok, it will also be a per project workspace.
  if ($self-&gt;{'per_project_workspace_name'}) {
    return "$name$ext";
  }

  my($pwd)    = $self-&gt;getcwd();
  my($type)   = $self-&gt;{'wctype'};
  my($wsname) = $self-&gt;get_workspace_name();

  if (!defined $previous_workspace_name{$type}-&gt;{$pwd}) {
    $previous_workspace_name{$type}-&gt;{$pwd} = $wsname;
    $self-&gt;{'current_workspace_name'} = undef;
  }
  else {
    my($prefix) = ($name eq $wsname ? $name : "$name.$wsname");
    $previous_workspace_name{$type}-&gt;{$pwd} = $wsname;
    while($self-&gt;file_written("$prefix" .
                              ($self-&gt;{'modified_count'} &gt; 0 ?
                                   ".$self-&gt;{'modified_count'}" : '') .
                              "$ext")) {
      ++$self-&gt;{'modified_count'};
    }
    $self-&gt;{'current_workspace_name'} =
               "$prefix" . ($self-&gt;{'modified_count'} &gt; 0 ?
                                ".$self-&gt;{'modified_count'}" : '') . "$ext";
  }

  return (defined $self-&gt;{'current_workspace_name'} ?
                  $self-&gt;{'current_workspace_name'} : "$name$ext");
}


sub generate_recursive_input_list {
  my($self)    = shift;
  my($dir)     = shift;
  my($exclude) = shift;
  return $self-&gt;extension_recursive_input_list($dir, $exclude, $wsext);
}


sub verify_build_ordering {
  my($self) = shift;
  foreach my $project (@{$self-&gt;{'projects'}}) {
    $self-&gt;get_validated_ordering($project);
  }
}


sub get_validated_ordering {
  my($self)    = shift;
  my($project) = shift;
  my($deps)    = undef;

  if (defined $self-&gt;{'ordering_cache'}-&gt;{$project}) {
    $deps = $self-&gt;{'ordering_cache'}-&gt;{$project};
  }
  else {
    $deps = '';
    if (defined $self-&gt;{'project_info'}-&gt;{$project}) {
      my($name) = undef;
      ($name, $deps) = @{$self-&gt;{'project_info'}-&gt;{$project}};
      if (defined $deps &amp;&amp; $deps ne '') {
        my($darr) = $self-&gt;create_array($deps);
        foreach my $dep (@$darr) {
          my($found) = 0;
          ## Avoid circular dependencies
          if ($dep ne $name &amp;&amp; $dep ne basename($project)) {
            foreach my $p (@{$self-&gt;{'projects'}}) {
              if ($dep eq $self-&gt;{'project_info'}-&gt;{$p}-&gt;[0] ||
                  $dep eq basename($p)) {
                $found = 1;
                last;
              }
            }
            if (!$found) {
              if (defined $ENV{MPC_VERBOSE_ORDERING}) {
                $self-&gt;warning("'$name' references '$dep' which has " .
                               "not been processed.");
              }
              my($reg) = $self-&gt;escape_regex_special($dep);
              $deps =~ s/\s*"$reg"\s*/ /g;
            }
          }
        }
      }

      $deps =~ s/^\s+//;
      $deps =~ s/\s+$//;
      $self-&gt;{'ordering_cache'}-&gt;{$project} = $deps;
    }
  }

  return $deps;
}


sub source_listing_callback {
  my($self)         = shift;
  my($project_file) = shift;
  my($project_name) = shift;
  my(@files)        = @_;
  my($cwd)          = $self-&gt;getcwd();
  $self-&gt;{'project_file_list'}-&gt;{$project_name} = [ $project_file,
                                                    $cwd, \@files ];
}

# ************************************************************
# Virtual Methods To Be Overridden
# ************************************************************

sub generate_implicit_project_dependencies {
  #my($self) = shift;
  return 0;
}


sub workspace_file_name {
  #my($self) = shift;
  return '';
}


sub workspace_per_project {
  #my($self) = shift;
  return 0;
}


sub pre_workspace {
  #my($self) = shift;
  #my($fh)   = shift;
}


sub write_comps {
  #my($self) = shift;
  #my($fh)   = shift;
  #my($gens) = shift;
  #my($top)  = shift;
}


sub post_workspace {
  #my($self) = shift;
  #my($fh)   = shift;
}


1;
</pre></body></html>