| 1 |
#!/bin/perl |
| 2 |
|
| 3 |
# steps: |
| 4 |
# 1) run configure |
| 5 |
# 2) perl local/minimalist/remove-unneeded-modules |
| 6 |
# 3) make depend |
| 7 |
# 4) make |
| 8 |
|
| 9 |
use File::Find; |
| 10 |
use Data::Dumper; |
| 11 |
use strict; |
| 12 |
|
| 13 |
my %exceptions = qw( |
| 14 |
agent/mibgroup/mibdefs.h 1 |
| 15 |
agent/mibgroup/struct.h 1 |
| 16 |
agent/mibgroup/agentx/protocol.h 1 |
| 17 |
agent/mibgroup/agentx/agentx_config.h 1 |
| 18 |
agent/mibgroup/agentx/subagent.h 1 |
| 19 |
agent/mibgroup/mib_module_includes.h 1 |
| 20 |
agent/mibgroup/mib_module_inits.h 1 |
| 21 |
agent/mibgroup/mib_module_dot_conf.h 1 |
| 22 |
agent/mibgroup/mib_module_shutdown.h 1 |
| 23 |
agent/mibgroup/agent_module_includes.h 1 |
| 24 |
agent/mibgroup/agent_module_inits.h 1 |
| 25 |
agent/mibgroup/agent_module_dot_conf.h 1 |
| 26 |
agent/mibgroup/agent_module_shutdown.h 1 |
| 27 |
agent/mibgroup/mibII/vacm_conf.c 1 |
| 28 |
agent/mibgroup/snmpv3/usmConf.c 1 |
| 29 |
agent/mibgroup/utilities/iquery.c 1 |
| 30 |
agent/mibgroup/mibII/vacm_conf.h 1 |
| 31 |
agent/mibgroup/snmpv3/usmConf.h 1 |
| 32 |
agent/mibgroup/utilities/iquery.h 1 |
| 33 |
agent/mibgroup/util_funcs/MIB_STATS_CACHE_TIMEOUT.h 1 |
| 34 |
agent/mibgroup/host_res.h 1 |
| 35 |
agent/mibgroup/hr_filesys.h 1 |
| 36 |
agent/mibgroup/if-mib/ifTable/ifTable_defs.h 1 |
| 37 |
agent/mibgroup/ifTable_defs.h 1 |
| 38 |
agent/mibgroup/mibII/mibII_common.h 1 |
| 39 |
agent/mibgroup/mnttypes.h 1 |
| 40 |
agent/mibgroup/utilities/execute.h 1 |
| 41 |
); |
| 42 |
|
| 43 |
my %opts; |
| 44 |
|
| 45 |
LocalGetOptions(\%opts, |
| 46 |
['n|dry-run', "Dry-run, just say what you would do"], |
| 47 |
['v|verbose', "Show what files are being left too"], |
| 48 |
); |
| 49 |
|
| 50 |
my $inputMakefile = $ARGV[0] || "agent/mibgroup/Makefile"; |
| 51 |
my $inputDir = $ARGV[1] || "agent/mibgroup"; |
| 52 |
|
| 53 |
my $collecting = 0; |
| 54 |
my (%files, @files); |
| 55 |
|
| 56 |
open(I, $inputMakefile); |
| 57 |
while(<I>) { |
| 58 |
if (/mib_module_list_c=/) { |
| 59 |
$collecting = 1; |
| 60 |
} elsif ($collecting) { |
| 61 |
if (! /\\\s*$/) { |
| 62 |
$collecting = 0; |
| 63 |
} |
| 64 |
chomp(); |
| 65 |
s/\\//; |
| 66 |
s/\s*//g; |
| 67 |
s/\.c//; |
| 68 |
push @files, "agent/mibgroup/$_"; |
| 69 |
$files{"agent/mibgroup/$_.c"} = 1; |
| 70 |
$files{"agent/mibgroup/$_.h"} = 1; |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
find(\&remove_files, $inputDir); |
| 75 |
|
| 76 |
sub remove_files { |
| 77 |
return if (!/\.[ch]$/); |
| 78 |
return if (/\.h$/); # XXX: we need to delete headers eventually too |
| 79 |
return if (/_constants.h/); |
| 80 |
return if (exists($exceptions{$File::Find::name})); |
| 81 |
|
| 82 |
if (!exists($files{$File::Find::name})) { |
| 83 |
Unlink($_, $File::Find::name); |
| 84 |
} elsif ($opts{'v'}) { |
| 85 |
print "Leaving $File::Find::name\n"; |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
sub Unlink { |
| 90 |
my ($file, $fullfile) = @_; |
| 91 |
print "Removing $fullfile\n"; |
| 92 |
if (!$opts{'n'}) { |
| 93 |
unlink($file); |
| 94 |
if (-f "$file") { |
| 95 |
print "*** FAILED to remove $file\n"; |
| 96 |
} |
| 97 |
} |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
sub LocalGetOptions { |
| 102 |
if (eval {require Getopt::GUI::Long;}) { |
| 103 |
import Getopt::GUI::Long; |
| 104 |
# optional configure call |
| 105 |
my @gopts = qw(no_ignore_case no_gui allow_zero); |
| 106 |
if ($Getopt::GUI::Long::VERSION > 0.2) { |
| 107 |
push @gopts, qw(display_help capture_output); |
| 108 |
} |
| 109 |
Getopt::GUI::Long::Configure(@gopts); |
| 110 |
return GetOptions(@_); |
| 111 |
} |
| 112 |
require Getopt::Long; |
| 113 |
import Getopt::Long; |
| 114 |
# optional configure call |
| 115 |
Getopt::Long::Configure(qw(display_help no_ignore_case capture_output)); |
| 116 |
GetOptions(LocalOptionsMap(@_)); |
| 117 |
} |
| 118 |
|
| 119 |
sub LocalOptionsMap { |
| 120 |
my ($st, $cb, @opts) = ((ref($_[0]) eq 'HASH') |
| 121 |
? (1, 1, $_[0]) : (0, 2)); |
| 122 |
for (my $i = $st; $i <= $#_; $i += $cb) { |
| 123 |
if ($_[$i]) { |
| 124 |
next if (ref($_[$i]) eq 'ARRAY' && $_[$i][0] =~ /^GUI:/); |
| 125 |
push @opts, ((ref($_[$i]) eq 'ARRAY') ? $_[$i][0] : $_[$i]); |
| 126 |
push @opts, $_[$i+1] if ($cb == 2); |
| 127 |
} |
| 128 |
} |
| 129 |
return @opts; |
| 130 |
} |