Bio-Genex

 view release on metacpan or  search on metacpan

scripts/configure.pl.in  view on Meta::CPAN


#
# Find all .in files and do  variable substitution
#
sub wanted {
  if (-d $_) {
    foreach my $dir_re(@ignore_dirs) {
      if ($_ =~ $dir_re) {
	# if we are to ignore this directory set $File::Find::prune
	$File::Find::prune = 1;
	return;
      }
    }
    # we don't substitue directories, so return
    return;
  }

  # only substitute '.in' files
  return unless /\.in$/;

  # we don't want to substitute the configure.pl.in 
  return if /^configure\.pl\.in$/;

  my ($outfile) = $File::Find::name =~ m/^(.*)\.in$/;
  
  # we only want to substitute if the infile has been modified 
  # since we last ran the substitution, or if the config file
  # has been modified
  if (-f $outfile) {
    my $st_out = stat($outfile);
    my $st_in = stat($File::Find::name);

    # First, if the config file is local, check if the config more
    # recent, otherwise check if infile is more recent
    if (!defined $st_config || $st_config->mtime < $st_out->mtime) {
      # has the infile been modified?
      return unless $st_in->mtime > $st_out->mtime;
    }
  }

  open(IN,$File::Find::name) or die "Couldn't open $File::Find::name for reading";
  open(OUT,">$outfile") or die "Couldn't open $outfile for writing";
  print STDERR "  Creating ", basename($outfile), " from $_ ";
  while (<IN>) {
    next unless /\%\%[^\%]+\%\%/;
    foreach my $pattern (keys %SUBST) {
      if ($_ =~ /\%\%$pattern\%\%/) { 
	print STDERR "."; 
	$_ =~  s/\%\%$pattern\%\%/$SUBST{$pattern}/g;
      }
    }
  } continue {
    print OUT;
  }
  print STDERR "\n";
  close(OUT);
  close(IN);

  # make the perl scripts executable, or any already executable file
  if ($outfile =~ m/\.pl$/ || -x $File::Find::name) {
    chmod(0775,$outfile);
  } else {
    chmod(0664,$outfile);
  }
}

print STDERR "Substituting parameters in perl scripts and modules\n";
find(\&wanted, cwd());

\%SUBST;



( run in 0.902 second using v1.01-cache-2.11-cpan-39bf76dae61 )