diff options
author | elliott_c <ocielliottc@users.noreply.github.com> | 2003-09-25 14:26:04 +0000 |
---|---|---|
committer | elliott_c <ocielliottc@users.noreply.github.com> | 2003-09-25 14:26:04 +0000 |
commit | 0e3f99af4b89a49c15a569a848e20e59ea883079 (patch) | |
tree | a83342a9dfbeed271d07b6d1f694cdc774a84c2d | |
parent | b9e23492e7a425a574de718702910cc8b7575729 (diff) | |
download | ATCD-0e3f99af4b89a49c15a569a848e20e59ea883079.tar.gz |
ChangeLogTag: Thu Sep 25 09:24:23 2003 Chad Elliott <elliott_c@ociweb.com>
-rw-r--r-- | ChangeLog | 15 | ||||
-rw-r--r-- | bin/DependencyGenerator/DependencyEditor.pm | 25 | ||||
-rw-r--r-- | bin/DependencyGenerator/DependencyGenerator.pm | 70 | ||||
-rw-r--r-- | bin/DependencyGenerator/Preprocessor.pm | 103 | ||||
-rwxr-xr-x | bin/depgen.pl | 36 | ||||
-rw-r--r-- | include/makeinclude/rules.local.GNU | 6 |
6 files changed, 133 insertions, 122 deletions
diff --git a/ChangeLog b/ChangeLog index e395827cae6..10badb9f414 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +Thu Sep 25 09:24:23 2003 Chad Elliott <elliott_c@ociweb.com> + + * bin/DependencyGenerator/DependencyEditor.pm: + * bin/DependencyGenerator/DependencyGenerator.pm: + * bin/DependencyGenerator/Preprocessor.pm: + * bin/depgen.pl: + + Modified the dependency generator to be smarter about processing + include files. + + * include/makeinclude/rules.local.GNU: + + By default use g++dep for dependency generation, but allow an + alternate by setting the DEPGEN make macro. + Wed Sep 24 12:36:21 2003 Chad Elliott <elliott_c@ociweb.com> * bin/MakeProjectCreator/modules/WorkspaceCreator.pm: diff --git a/bin/DependencyGenerator/DependencyEditor.pm b/bin/DependencyGenerator/DependencyEditor.pm index 72f1c693e7b..2859e29155e 100644 --- a/bin/DependencyGenerator/DependencyEditor.pm +++ b/bin/DependencyGenerator/DependencyEditor.pm @@ -33,29 +33,13 @@ sub process { my($self) = shift; my($output) = shift; my($type) = shift; - my($cpp) = shift; my($macros) = shift; my($ipaths) = shift; my($replace) = shift; my($files) = shift; my($status) = 0; - my(@exclude) = (); my(@options) = (); - ## Determine which include files to exclude based on the directory - if (lc(basename($cpp)) eq 'cl' || lc(basename($cpp)) eq 'cl.exe') { - push(@options, '/MD'); - if (defined $ENV{INCLUDE}) { - foreach my $exc (split(';', $ENV{INCLUDE})) { - $exc =~ s/\\/\\\\\\\\/g; - push(@exclude, $exc); - } - } - } - else { - @exclude = ('/usr/','/opt/', '/var/'); - } - ## Back up the original file and receive the contents my(@contents) = (); if (-r $output) { @@ -69,7 +53,7 @@ sub process { my($fh) = new FileHandle(); if (open($fh, ">$output")) { foreach my $line (@contents) { - if ($line =~ /DO NOT DELETE THIS LINE/) { + if ($line =~ /DO NOT DELETE/) { last; } print $fh $line; @@ -78,12 +62,13 @@ sub process { print $fh "# DO NOT DELETE THIS LINE -- " . basename($0) . " uses it.\n" . "# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.\n\n"; - my($dep) = new DependencyGenerator($cpp, $macros, \@options, $ipaths); + my($dep) = new DependencyGenerator($macros, \@options, + $ipaths, $replace, $type); my($objgen) = ObjectGeneratorFactory::create($type); + ## Sort the files so the dependencies are reproducible foreach my $file (sort @$files) { my(@objects) = $objgen->process($file); - print $fh $dep->process($file, \@objects, - \@exclude, $replace, $type) . "\n"; + print $fh $dep->process($file, \@objects) . "\n"; } print $fh "# IF YOU PUT ANYTHING HERE IT WILL GO AWAY\n"; diff --git a/bin/DependencyGenerator/DependencyGenerator.pm b/bin/DependencyGenerator/DependencyGenerator.pm index 5105d3a00f3..f84b31ca40e 100644 --- a/bin/DependencyGenerator/DependencyGenerator.pm +++ b/bin/DependencyGenerator/DependencyGenerator.pm @@ -22,67 +22,53 @@ use DependencyWriterFactory; sub new { my($class) = shift; - my($pre) = shift; my($macros) = shift; my($options) = shift; my($ipaths) = shift; - my($self) = bless {'pre' => new Preprocessor($pre, $macros, - $options, $ipaths), + my($replace) = shift; + my($type) = shift; + my($self) = bless {'pre' => new Preprocessor($macros, + $options, $ipaths), + 'replace' => $replace, + 'dwrite' => DependencyWriterFactory::create($type), + 'cwd' => Cwd::getcwd() . '/', }, $class; return $self; } sub process { - my($self) = shift; - my($file) = shift; - my($objects) = shift; - my($exclude) = shift; - my($replace) = shift; - my($type) = shift; - my(%split) = (); - my(@files) = (); + my($self) = shift; + my($file) = shift; + my($objects) = shift; + my($replace) = $self->{'replace'}; + my(@repkeys) = keys %$replace; + my($cwd) = $self->{'cwd'}; + my(@files) = @{$self->{'pre'}->process($file)}; - ## Preprocess the file - foreach my $line (@{$self->{'pre'}->process($file)}) { - if ($line =~ /^#\s*(line\s+)?\d+\s+\"([\w\\\/:\s\.\-\+\~]+)/) { - $split{$2} = 1; - } - } + ## Go through each file + foreach my $finc (@files) { + ## Remove the current working directory from the front of the + ## file. This will help reduce the size of the dependency file. + $finc =~ s/^$cwd//; - ## Go through each file and exclude those that need exclusion - ## and modify those that have elements for replacement - my($skip) = 0; - foreach my $file (keys %split) { - foreach my $exc (@$exclude) { - if ($file =~ /^$exc/i) { - $skip = 1; + ## Modify those that have elements for replacement + foreach my $rep (@repkeys) { + if ($finc =~ /^$rep/) { + $finc =~ s/^$rep/$$replace{$rep}/; last; } } - if ($skip) { - $skip = 0; - } - else { - foreach my $rep (keys %$replace) { - if ($file =~ /^$rep/) { - $file =~ s/^$rep/$$replace{$rep}/; - last; - } - } - $file =~ s/\\\\/\\/g; - $file =~ s/\/\//\\/g; - push(@files, $file); - } + + ## Remove extra slashes + $finc =~ s/\/\//\\/g; } ## Sort the dependencies to make them reproducible @files = sort @files; - ## Allocate the correct type of dependency writer - ## and generate the dependency string - my($dwrite) = DependencyWriterFactory::create($type); - return $dwrite->process($objects, \@files); + ## Generate the dependency string + return $self->{'dwrite'}->process($objects, \@files); } diff --git a/bin/DependencyGenerator/Preprocessor.pm b/bin/DependencyGenerator/Preprocessor.pm index f7f95bfdd63..f28ab6f2397 100644 --- a/bin/DependencyGenerator/Preprocessor.pm +++ b/bin/DependencyGenerator/Preprocessor.pm @@ -1,7 +1,7 @@ package Preprocessor; # ************************************************************ -# Description : Invokes the preprocessor on the supplied file. +# Description : Preprocesses the supplied file. # Author : Chad Elliott # Create Date : 2/10/2002 # ************************************************************ @@ -12,7 +12,6 @@ package Preprocessor; use strict; use FileHandle; -use File::Spec; # ************************************************************ # Subroutine Section @@ -20,54 +19,96 @@ use File::Spec; sub new { my($class) = shift; - my($cxx) = shift; my($macros) = shift; my($options) = shift; my($ipaths) = shift; - my($self) = bless {'cxx' => $cxx, - 'macros' => $macros, + my($self) = bless {'macros' => $macros, 'options' => $options, 'ipaths' => $ipaths, - 'fh' => new FileHandle(), - 'nul' => File::Spec->devnull(), + 'files' => {}, }, $class; return $self; } -sub process { - my($self) = shift; - my($file) = shift; - my(@lines) = (); - - if (defined $file && -r $file) { - my($cmd) = "$self->{'cxx'} -E"; +sub locateFile { + my($self) = shift; + my($file) = shift; - foreach my $macro (keys %{$self->{'macros'}}) { - $cmd .= " -D$macro" . (defined $self->{'macros'}->{$macro} ? - "=$self->{'macros'}->{$macro}" : ''); - } - foreach my $option (@{$self->{'options'}}) { - $cmd .= " $option"; + foreach my $dir ('.', @{$self->{'ipaths'}}) { + if (-r "$dir/$file") { + return "$dir/$file"; } - foreach my $ipath (@{$self->{'ipaths'}}) { - $cmd .= " -I$ipath"; + } + + return undef; +} + + +sub getFiles { + my($self) = shift; + my($file) = shift; + + foreach my $inc (@{$self->{'files'}->{$file}}) { + if (!defined $self->{'ifiles'}->{$inc}) { + $self->{'ifiles'}->{$inc} = 1; + $self->getFiles($inc); } - $cmd .= " $file"; + } +} + + +sub process { + my($self) = shift; + my($file) = shift; + my($noincs) = shift; + my($fh) = new FileHandle(); + my(@incs) = (); + + if (open($fh, $file)) { + my($ifcount) = 0; + my(@zero) = (); - my($fh) = $self->{'fh'}; - if (open($fh, "$cmd 2> $self->{'nul'} |")) { - while(<$fh>) { - push(@lines, $_); + $self->{'files'}->{$file} = []; + while(<$fh>) { + $_ =~ s/\/\/.*//; + + if (/#\s*if\s+0/) { + push(@zero, $ifcount); + ++$ifcount; + } + elsif (/#\s*if/) { + ++$ifcount; + } + elsif (/#\s*endif/) { + --$ifcount; + if (defined $zero[0] && $ifcount == $zero[$#zero]) { + pop(@zero); + } + } + elsif (!defined $zero[0] && + /#\s*include\s+(\/\*\*\/\s*)?[<"]([^">]+)[">]/) { + my($inc) = $self->locateFile($2); + if (defined $inc) { + $inc =~ s/\\/\//g; + push(@{$self->{'files'}->{$file}}, $inc); + if (!defined $self->{'files'}->{$inc}) { + ## Process this file, but do not return the include files + $self->process($inc, 1); + } + } } - close($fh); } - else { - print STDERR "ERROR: Unable to run: $cmd\n"; + close($fh); + + if (!$noincs) { + $self->{'ifiles'} = {}; + $self->getFiles($file); + @incs = keys %{$self->{'ifiles'}}; } } - return \@lines; + return \@incs; } diff --git a/bin/depgen.pl b/bin/depgen.pl index d4b35b5543d..d6e8436f57a 100755 --- a/bin/depgen.pl +++ b/bin/depgen.pl @@ -27,13 +27,13 @@ require DependencyEditor; # Data Section # ************************************************************ -my($version) = '0.3'; +my($version) = '0.4'; my($os) = ($^O eq 'MSWin32' || $^O eq 'cygwin' ? 'Windows' : 'UNIX'); my(%types) = ('gnu' => 1, 'nmake' => 1, ); -my(%defaults) = ('UNIX' => ['/lib/cpp', 'gnu'], - 'Windows' => ['CL', 'nmake'], +my(%defaults) = ('UNIX' => ['gnu'], + 'Windows' => ['nmake'], ); # ************************************************************ @@ -101,26 +101,17 @@ sub usageAndExit { "Usage: $base [-D<MACRO>[=VALUE]] [-I<include dir>] [-A] " . "[-R <VARNAME>]\n" . " " . (" " x length($base)) . - " [-P <preprocessor>] [-f <output file>] [-t <type>] <files...>\n" . + " [-f <output file>] [-t <type>] <files...>\n" . "\n" . "-D This option sets a macro to an optional value.\n" . "-I The -I option adds an include directory.\n" . "-A Replace \$ACE_ROOT and \$TAO_ROOT paths with \$(ACE_ROOT) " . "and \$(TAO_ROOT)\n respectively.\n" . "-R Replace \$VARNAME paths with \$(VARNAME).\n" . - "-P Specifies which preprocessor to use.\n" . - " The default is "; - my(@keys) = sort keys %defaults; - for(my $i = 0; $i <= $#keys; ++$i) { - my($def) = $keys[$i]; - print $defaults{$def}->[0] . " on $def" . - ($i != $#keys ? $i == $#keys - 1 ? ' and ' : ', ' : ''); - } - print ".\n" . "-f Specifies the output file. This file will be edited if it " . "already\n exists.\n" . "-t Use specified type ("; - @keys = sort keys %types; + my(@keys) = sort keys %types; for(my $i = 0; $i <= $#keys; ++$i) { print "$keys[$i]" . ($i != $#keys ? $i == $#keys - 1 ? ' or ' : ', ' : '');; @@ -130,7 +121,7 @@ sub usageAndExit { @keys = sort keys %defaults; for(my $i = 0; $i <= $#keys; ++$i) { my($def) = $keys[$i]; - print $defaults{$def}->[1] . " on $def" . + print $defaults{$def}->[0] . " on $def" . ($i != $#keys ? $i == $#keys - 1 ? ' and ' : ', ' : ''); } print ".\n"; @@ -143,8 +134,7 @@ sub usageAndExit { # ************************************************************ my($base) = basename($0); -my($cpp) = $defaults{$os}->[0]; -my($type) = $defaults{$os}->[1]; +my($type) = $defaults{$os}->[0]; my(@files) = (); my(%macros) = (); my(@ipaths) = (); @@ -194,16 +184,6 @@ for(my $i = 0; $i <= $#ARGV; ++$i) { elsif ($arg eq '-h') { usageAndExit($base); } - elsif ($arg eq '-P') { - ++$i; - $arg = $ARGV[$i]; - if (defined $arg) { - $cpp = $arg; - } - else { - usageAndExit($base, 'Invalid use of -P'); - } - } elsif ($arg eq '-t') { ++$i; $arg = $ARGV[$i]; @@ -227,6 +207,6 @@ if (!defined $files[0]) { } my($editor) = new DependencyEditor(); -my($status) = $editor->process($output, $type, $cpp, +my($status) = $editor->process($output, $type, \%macros, \@ipaths, \%replace, \@files); exit($status); diff --git a/include/makeinclude/rules.local.GNU b/include/makeinclude/rules.local.GNU index 5de018643f1..8df678f94b0 100644 --- a/include/makeinclude/rules.local.GNU +++ b/include/makeinclude/rules.local.GNU @@ -277,10 +277,14 @@ depend.local: $(DEPENDENCY_FILE) -include $(DEPENDENCY_FILE) endif +ifeq ($(DEPGEN),) + DEPGEN = $(ACE_ROOT)/bin/g++dep +endif + depend.local: $(MAKEFILE) @$(RM) $(DEPENDENCY_FILE).old @cp $(DEPENDENCY_FILE) $(DEPENDENCY_FILE).old - SOEXT=$(SOEXT) VSHDIR=$(VSHDIR) ACE_DEPEND_SED_CMD="$(ACE_DEPEND_SED_CMD)" $(ACE_ROOT)/bin/g++dep -A $(DEPEND_CMD_ARGS) -f $(DEPENDENCY_FILE) $(CPPFLAGS) -DMAKEDEPEND $(LSRC) $(SRC) $(PSRC) + SOEXT=$(SOEXT) VDIR=.obj/ VSHDIR=$(VSHDIR) ACE_DEPEND_SED_CMD="$(ACE_DEPEND_SED_CMD)" $(DEPGEN) -A $(DEPEND_CMD_ARGS) -f $(DEPENDENCY_FILE) $(CPPFLAGS) -DMAKEDEPEND $(LSRC) $(SRC) $(PSRC) @if cmp -s $(DEPENDENCY_FILE) $(DEPENDENCY_FILE).old ;\ then echo "Makefile dependencies unchanged." ;\ else \ |