diff options
author | elliott_c <ocielliottc@users.noreply.github.com> | 2003-05-23 13:13:03 +0000 |
---|---|---|
committer | elliott_c <ocielliottc@users.noreply.github.com> | 2003-05-23 13:13:03 +0000 |
commit | 9da89b1b9171a4e33540e281c46214b713223fb6 (patch) | |
tree | b354e7cc3e146bdf136a19b5438ba28c9d07400c | |
parent | ff4d1de573148c8821e794c03b9de476fea9f5a0 (diff) | |
download | ATCD-9da89b1b9171a4e33540e281c46214b713223fb6.tar.gz |
ChangeLogTag: Fri May 23 08:10:23 2003 Chad Elliott <elliott_c@ociweb.com>
-rw-r--r-- | ChangeLog | 18 | ||||
-rw-r--r-- | bin/DependencyGenerator/DependencyEditor.pm | 131 | ||||
-rw-r--r-- | bin/DependencyGenerator/DependencyGenerator.pm | 87 | ||||
-rw-r--r-- | bin/DependencyGenerator/DependencyWriter.pm | 35 | ||||
-rw-r--r-- | bin/DependencyGenerator/DependencyWriterFactory.pm | 35 | ||||
-rw-r--r-- | bin/DependencyGenerator/GNUDependencyWriter.pm | 38 | ||||
-rw-r--r-- | bin/DependencyGenerator/GNUObjectGenerator.pm | 49 | ||||
-rw-r--r-- | bin/DependencyGenerator/NMakeDependencyWriter.pm | 54 | ||||
-rw-r--r-- | bin/DependencyGenerator/NMakeObjectGenerator.pm | 30 | ||||
-rw-r--r-- | bin/DependencyGenerator/ObjectGenerator.pm | 34 | ||||
-rw-r--r-- | bin/DependencyGenerator/ObjectGeneratorFactory.pm | 35 | ||||
-rw-r--r-- | bin/DependencyGenerator/Preprocessor.pm | 74 | ||||
-rwxr-xr-x | bin/depgen.pl | 229 |
13 files changed, 849 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog index 031cc67fad0..5f7dbfd6c92 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +Fri May 23 08:10:23 2003 Chad Elliott <elliott_c@ociweb.com> + + * bin/DependencyGenerator/DependencyEditor.pm: + * bin/DependencyGenerator/DependencyGenerator.pm: + * bin/DependencyGenerator/DependencyWriter.pm: + * bin/DependencyGenerator/DependencyWriterFactory.pm: + * bin/DependencyGenerator/GNUDependencyWriter.pm: + * bin/DependencyGenerator/GNUObjectGenerator.pm: + * bin/DependencyGenerator/NMakeDependencyWriter.pm: + * bin/DependencyGenerator/NMakeObjectGenerator.pm: + * bin/DependencyGenerator/ObjectGenerator.pm: + * bin/DependencyGenerator/ObjectGeneratorFactory.pm: + * bin/DependencyGenerator/Preprocessor.pm: + * bin/depgen.pl: + + Added my generic dependency generator that will work with both GNU + Makefiles and NMakefiles. + Fri May 23 11:41:01 UTC 2003 Johnny Willemsen <jwillemsen@remedy.nl> * ace/Sock_Connect.cpp: diff --git a/bin/DependencyGenerator/DependencyEditor.pm b/bin/DependencyGenerator/DependencyEditor.pm new file mode 100644 index 00000000000..72f1c693e7b --- /dev/null +++ b/bin/DependencyGenerator/DependencyEditor.pm @@ -0,0 +1,131 @@ +package DependencyEditor; + +# ************************************************************ +# Description : Edits existing dependencies. +# Author : Chad Elliott +# Create Date : 2/10/2002 +# ************************************************************ + +# ************************************************************ +# Pragmas +# ************************************************************ + +use strict; +use FileHandle; +use File::Basename; + +use DependencyGenerator; +use ObjectGeneratorFactory; + +# ************************************************************ +# Subroutine Section +# ************************************************************ + +sub new { + my($class) = shift; + my($self) = bless { + }, $class; + return $self; +} + + +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) { + if (!$self->backup($output, \@contents)) { + print STDERR "ERROR: Unable to backup $output\n"; + return 1; + } + } + + ## Write out the new file + my($fh) = new FileHandle(); + if (open($fh, ">$output")) { + foreach my $line (@contents) { + if ($line =~ /DO NOT DELETE THIS LINE/) { + last; + } + print $fh $line; + } + + 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($objgen) = ObjectGeneratorFactory::create($type); + foreach my $file (sort @$files) { + my(@objects) = $objgen->process($file); + print $fh $dep->process($file, \@objects, + \@exclude, $replace, $type) . "\n"; + } + + print $fh "# IF YOU PUT ANYTHING HERE IT WILL GO AWAY\n"; + close($fh); + } + else { + print STDERR "ERROR: Unable to open $output for output\n"; + $status++; + } + return $status; +} + + +sub backup { + my($self) = shift; + my($source) = shift; + my($contents) = shift; + my($status) = 0; + my($fh) = new FileHandle(); + my($backup) = "$source.bak"; + + unlink($backup); + if (open($fh, $source)) { + my($oh) = new FileHandle(); + if (open($oh, ">$backup")) { + $status = 1; + while(<$fh>) { + print $oh $_; + push(@$contents, $_); + } + close($oh); + + ## Set file permission + my(@buf) = stat($source); + if (defined $buf[8] && defined $buf[9]) { + utime($buf[8], $buf[9], $backup); + } + } + close($fh); + } + return $status; +} + + +1; diff --git a/bin/DependencyGenerator/DependencyGenerator.pm b/bin/DependencyGenerator/DependencyGenerator.pm new file mode 100644 index 00000000000..5624ee5f1e5 --- /dev/null +++ b/bin/DependencyGenerator/DependencyGenerator.pm @@ -0,0 +1,87 @@ +package DependencyGenerator; + +# ************************************************************ +# Description : Runs the correct dependency generator on the file. +# Author : Chad Elliott +# Create Date : 2/10/2002 +# ************************************************************ + +# ************************************************************ +# Pragmas +# ************************************************************ + +use strict; +use FileHandle; + +use Preprocessor; +use DependencyWriterFactory; + +# ************************************************************ +# Subroutine Section +# ************************************************************ + +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), + }, $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) = (); + + ## 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 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/) { + $skip = 1; + last; + } + } + if ($skip) { + $skip = 0; + } + else { + foreach my $rep (keys %$replace) { + if ($file =~ /^$rep/) { + $file =~ s/^$rep/$$replace{$rep}/; + last; + } + } + push(@files, $file); + } + } + + ## 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); +} + + +1; diff --git a/bin/DependencyGenerator/DependencyWriter.pm b/bin/DependencyGenerator/DependencyWriter.pm new file mode 100644 index 00000000000..df3dded0451 --- /dev/null +++ b/bin/DependencyGenerator/DependencyWriter.pm @@ -0,0 +1,35 @@ +package DependencyWriter; + +# ************************************************************ +# Description : Base class for all Dependency Writers. +# Author : Chad Elliott +# Create Date : 2/10/2002 +# ************************************************************ + +# ************************************************************ +# Pragmas +# ************************************************************ + +use strict; + +# ************************************************************ +# Subroutine Section +# ************************************************************ + +sub new { + my($class) = shift; + my($self) = bless { + }, $class; + return $self; +} + + +sub process { + my($self) = shift; + my($objects) = shift; + my($files) = shift; + return ''; +} + + +1; diff --git a/bin/DependencyGenerator/DependencyWriterFactory.pm b/bin/DependencyGenerator/DependencyWriterFactory.pm new file mode 100644 index 00000000000..b95d1a1d81a --- /dev/null +++ b/bin/DependencyGenerator/DependencyWriterFactory.pm @@ -0,0 +1,35 @@ +package DependencyWriterFactory; + +# ************************************************************ +# Description : Create DependencyWriter objects. +# Author : Chad Elliott +# Create Date : 5/23/2003 +# ************************************************************ + +# ************************************************************ +# Pragmas +# ************************************************************ + +use strict; + +use GNUDependencyWriter; +use NMakeDependencyWriter; + +# ************************************************************ +# Subroutine Section +# ************************************************************ + +sub create { + my($type) = shift; + + switch: { + $type eq 'gnu' && do { return new GNUDependencyWriter(); }; + $type eq 'nmake' && do { return new NMakeDependencyWriter(); }; + print STDERR "WARNING: Invalid dependency writer type: $type\n"; + } + + return new DependencyWriter(); +} + + +1; diff --git a/bin/DependencyGenerator/GNUDependencyWriter.pm b/bin/DependencyGenerator/GNUDependencyWriter.pm new file mode 100644 index 00000000000..2209d1eac8e --- /dev/null +++ b/bin/DependencyGenerator/GNUDependencyWriter.pm @@ -0,0 +1,38 @@ +package GNUDependencyWriter; + +# ************************************************************ +# Description : Generates GNU Makefile dependencies. +# Author : Chad Elliott +# Create Date : 2/10/2002 +# ************************************************************ + +# ************************************************************ +# Pragmas +# ************************************************************ + +use strict; +use DependencyWriter; + +use vars qw(@ISA); +@ISA = qw(DependencyWriter); + +# ************************************************************ +# Subroutine Section +# ************************************************************ + +sub process { + my($self) = shift; + my($objects) = shift; + my($files) = shift; + my($dep) = "@$objects: \\\n"; + my($count) = scalar(@$files) - 1; + + for(my $i = 0; $i <= $count; ++$i) { + $dep .= " $$files[$i]" . ($i != $count ? " \\\n" : "\n"); + } + + return $dep; +} + + +1; diff --git a/bin/DependencyGenerator/GNUObjectGenerator.pm b/bin/DependencyGenerator/GNUObjectGenerator.pm new file mode 100644 index 00000000000..8276c5a7098 --- /dev/null +++ b/bin/DependencyGenerator/GNUObjectGenerator.pm @@ -0,0 +1,49 @@ +package GNUObjectGenerator; + +# ************************************************************ +# Description : Generates object files for GNU Makefiles. +# Author : Chad Elliott +# Create Date : 5/23/2003 +# ************************************************************ + +# ************************************************************ +# Pragmas +# ************************************************************ + +use strict; +use ObjectGenerator; + +use vars qw(@ISA); +@ISA = qw(ObjectGenerator); + +# ************************************************************ +# Subroutine Section +# ************************************************************ + +sub process { + my($self) = shift; + my($file) = shift; + my(@objects) = (); + my(@exts) = ('o'); + my(@dirs) = (defined $ENV{VDIR} ? $ENV{VDIR} : ''); + my($noext) = $file; + $noext =~ s/\.[^\.]+$//; + + if (defined $ENV{SOEXT}) { + push(@exts, $ENV{SOEXT}); + } + if (defined $ENV{VSHDIR}) { + push(@dirs, $ENV{VSHDIR}); + } + + foreach my $dirs (@dirs) { + foreach my $ext (@exts) { + push(@objects, "$dirs$noext.$ext"); + } + } + + return @objects; +} + + +1; diff --git a/bin/DependencyGenerator/NMakeDependencyWriter.pm b/bin/DependencyGenerator/NMakeDependencyWriter.pm new file mode 100644 index 00000000000..9bdbbca6ca0 --- /dev/null +++ b/bin/DependencyGenerator/NMakeDependencyWriter.pm @@ -0,0 +1,54 @@ +package NMakeDependencyWriter; + +# ************************************************************ +# Description : Generates NMake dependencies. +# Author : Chad Elliott +# Create Date : 2/10/2002 +# ************************************************************ + +# ************************************************************ +# Pragmas +# ************************************************************ + +use strict; +use DependencyWriter; + +use vars qw(@ISA); +@ISA = qw(DependencyWriter); + +# ************************************************************ +# Subroutine Section +# ************************************************************ + +sub process { + my($self) = shift; + my($sources) = shift; + my($files) = shift; + my($count) = scalar(@$files); + my($total) = 0; + + $$sources[0] =~ s/\//\\/g; + $$sources[0] =~ s/\\\\/\\/g; + my($dep) = "$$sources[0] :\\\n"; + + for(my $i = 0; $i < $count; ++$i) { + $$files[$i] =~ s/\//\\/g; + $$files[$i] =~ s/\\\\/\\/g; + if ($$files[$i] ne $$sources[0]) { + $dep .= "\t\"$$files[$i]\"\\\n"; + ++$total; + } + } + + if ($total == 0) { + $dep = ''; + } + else { + $dep .= "\n\n"; + } + + return $dep; +} + + +1; diff --git a/bin/DependencyGenerator/NMakeObjectGenerator.pm b/bin/DependencyGenerator/NMakeObjectGenerator.pm new file mode 100644 index 00000000000..9a66f9a5f09 --- /dev/null +++ b/bin/DependencyGenerator/NMakeObjectGenerator.pm @@ -0,0 +1,30 @@ +package NMakeObjectGenerator; + +# ************************************************************ +# Description : Generates object files for NMake Makefiles. +# Author : Chad Elliott +# Create Date : 5/23/2003 +# ************************************************************ + +# ************************************************************ +# Pragmas +# ************************************************************ + +use strict; +use ObjectGenerator; + +use vars qw(@ISA); +@ISA = qw(ObjectGenerator); + +# ************************************************************ +# Subroutine Section +# ************************************************************ + +sub process { + my($self) = shift; + my($file) = shift; + return $file; +} + + +1; diff --git a/bin/DependencyGenerator/ObjectGenerator.pm b/bin/DependencyGenerator/ObjectGenerator.pm new file mode 100644 index 00000000000..a1b65f76ad7 --- /dev/null +++ b/bin/DependencyGenerator/ObjectGenerator.pm @@ -0,0 +1,34 @@ +package ObjectGenerator; + +# ************************************************************ +# Description : Base class for all Object Generators. +# Author : Chad Elliott +# Create Date : 5/23/2003 +# ************************************************************ + +# ************************************************************ +# Pragmas +# ************************************************************ + +use strict; + +# ************************************************************ +# Subroutine Section +# ************************************************************ + +sub new { + my($class) = shift; + my($self) = bless { + }, $class; + return $self; +} + + +sub process { + my($self) = shift; + my($file) = shift; + return (); +} + + +1; diff --git a/bin/DependencyGenerator/ObjectGeneratorFactory.pm b/bin/DependencyGenerator/ObjectGeneratorFactory.pm new file mode 100644 index 00000000000..2dd7d175130 --- /dev/null +++ b/bin/DependencyGenerator/ObjectGeneratorFactory.pm @@ -0,0 +1,35 @@ +package ObjectGeneratorFactory; + +# ************************************************************ +# Description : Create ObjectGenerator objects. +# Author : Chad Elliott +# Create Date : 5/23/2003 +# ************************************************************ + +# ************************************************************ +# Pragmas +# ************************************************************ + +use strict; + +use GNUObjectGenerator; +use NMakeObjectGenerator; + +# ************************************************************ +# Subroutine Section +# ************************************************************ + +sub create { + my($type) = shift; + + switch: { + $type eq 'gnu' && do { return new GNUObjectGenerator(); }; + $type eq 'nmake' && do { return new NMakeObjectGenerator(); }; + print STDERR "WARNING: Invalid object generator type: $type\n"; + } + + return new ObjectGenerator(); +} + + +1; diff --git a/bin/DependencyGenerator/Preprocessor.pm b/bin/DependencyGenerator/Preprocessor.pm new file mode 100644 index 00000000000..f7f95bfdd63 --- /dev/null +++ b/bin/DependencyGenerator/Preprocessor.pm @@ -0,0 +1,74 @@ +package Preprocessor; + +# ************************************************************ +# Description : Invokes the preprocessor on the supplied file. +# Author : Chad Elliott +# Create Date : 2/10/2002 +# ************************************************************ + +# ************************************************************ +# Pragmas +# ************************************************************ + +use strict; +use FileHandle; +use File::Spec; + +# ************************************************************ +# Subroutine Section +# ************************************************************ + +sub new { + my($class) = shift; + my($cxx) = shift; + my($macros) = shift; + my($options) = shift; + my($ipaths) = shift; + my($self) = bless {'cxx' => $cxx, + 'macros' => $macros, + 'options' => $options, + 'ipaths' => $ipaths, + 'fh' => new FileHandle(), + 'nul' => File::Spec->devnull(), + }, $class; + return $self; +} + + +sub process { + my($self) = shift; + my($file) = shift; + my(@lines) = (); + + if (defined $file && -r $file) { + my($cmd) = "$self->{'cxx'} -E"; + + 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 $ipath (@{$self->{'ipaths'}}) { + $cmd .= " -I$ipath"; + } + $cmd .= " $file"; + + my($fh) = $self->{'fh'}; + if (open($fh, "$cmd 2> $self->{'nul'} |")) { + while(<$fh>) { + push(@lines, $_); + } + close($fh); + } + else { + print STDERR "ERROR: Unable to run: $cmd\n"; + } + } + + return \@lines; +} + + +1; diff --git a/bin/depgen.pl b/bin/depgen.pl new file mode 100755 index 00000000000..01140c767e3 --- /dev/null +++ b/bin/depgen.pl @@ -0,0 +1,229 @@ +eval '(exit $?0)' && eval 'exec perl -w -S $0 ${1+"$@"}' + & eval 'exec perl -w -S $0 $argv:q' + if 0; + +# ************************************************************ +# Description : Generate dependencies for GNU Make and NMake. +# Author : Chad Elliott +# Create Date : 5/06/2002 +# $Id$ +# ************************************************************ + +# ************************************************************ +# Pragma Section +# ************************************************************ + +use strict; +use Cwd; +use FileHandle; +use File::Basename; + +my($execPath) = getExecutePath($0); +unshift(@INC, "$execPath/DependencyGenerator"); + +require DependencyEditor; + +# ************************************************************ +# Data Section +# ************************************************************ + +my($version) = '0.3'; +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'], + ); + +# ************************************************************ +# Subroutine Section +# ************************************************************ + +sub which { + my($prog) = shift; + my($exec) = $prog; + my($part) = ''; + my($envSep) = ($^O eq 'MSWin32' ? ';' : ':'); + + if (defined $ENV{'PATH'}) { + foreach $part (split(/$envSep/, $ENV{'PATH'})) { + $part .= "/$prog"; + if ( -x $part ) { + $exec = $part; + last; + } + } + } + + return $exec; +} + + +sub getExecutePath { + my($prog) = shift; + my($loc) = ''; + + if ($prog ne basename($prog)) { + if ($prog =~ /^[\/\\]/ || + $prog =~ /^[A-Za-z]:[\/\\]?/) { + $loc = dirname($prog); + } + else { + $loc = getcwd() . '/' . dirname($prog); + } + } + else { + $loc = dirname(which($prog)); + } + + if ($loc eq '.') { + $loc = getcwd(); + } + + if ($loc ne '') { + $loc .= '/'; + } + + return $loc; +} + + +sub usageAndExit { + my($base) = shift; + my($opt) = shift; + + if (defined $opt) { + print "$opt.\n"; + } + + print "$base v$version\n" . + "Usage: $base [-D<MACRO>[=VALUE]] [-I<include dir>] [-A] " . + "[-R <VARNAME>]\n" . + " " . (" " x length($base)) . + " [-P <preprocessor>] [-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; + for(my $i = 0; $i <= $#keys; ++$i) { + print "$keys[$i]" . + ($i != $#keys ? $i == $#keys - 1 ? ' or ' : ', ' : '');; + } + print ") instead of the default.\n" . + " The default is "; + @keys = sort keys %defaults; + for(my $i = 0; $i <= $#keys; ++$i) { + my($def) = $keys[$i]; + print $defaults{$def}->[1] . " on $def" . + ($i != $#keys ? $i == $#keys - 1 ? ' and ' : ', ' : ''); + } + print ".\n"; + exit(0); +} + + +# ************************************************************ +# Main Section +# ************************************************************ + +my($base) = basename($0); +my($cpp) = $defaults{$os}->[0]; +my($type) = $defaults{$os}->[1]; +my(@files) = (); +my(%macros) = (); +my(@ipaths) = (); +my(%replace) = (); +my($output) = '-'; + + +if (defined $ENV{ACE_ROOT} && !defined $ENV{TAO_ROOT}) { + $ENV{TAO_ROOT} = "$ENV{ACE_ROOT}/TAO"; +} + +for(my $i = 0; $i <= $#ARGV; ++$i) { + my($arg) = $ARGV[$i]; + if ($arg =~ /^\-D(\w+)(=(.*))?/) { + $macros{$1} = $3; + } + elsif ($arg =~ /^\-I(.*)/) { + push(@ipaths, $1); + } + elsif ($arg eq '-A') { + $replace{$ENV{ACE_ROOT}} = '$(ACE_ROOT)'; + $replace{$ENV{TAO_ROOT}} = '$(TAO_ROOT)'; + } + elsif ($arg eq '-R') { + ++$i; + $arg = $ARGV[$i]; + if (defined $arg) { + my($val) = $ENV{$arg}; + if (defined $val) { + $replace{$val} = "\$($arg)"; + } + } + else { + usageAndExit($base, 'Invalid use of -R'); + } + } + elsif ($arg eq '-f') { + ++$i; + $arg = $ARGV[$i]; + if (defined $arg) { + $output = $arg; + } + else { + usageAndExit($base, 'Invalid use of -f'); + } + } + 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]; + if (defined $arg && defined $types{$arg}) { + $type = $arg; + } + else { + usageAndExit($base, 'Invalid use of -t'); + } + } + elsif ($arg =~ /^\-/) { + usageAndExit($base, "Unknown option: $arg"); + } + else { + push(@files, $arg); + } +} + +if (!defined $files[0]) { + usageAndExit($base, 'No files specified'); +} + +my($editor) = new DependencyEditor(); +my($status) = $editor->process($output, $type, $cpp, + \%macros, \@ipaths, \%replace, \@files); +exit($status); |