| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
use File::Basename; |
| 4 |
require 5; |
| 5 |
use Config; |
| 6 |
use MakefileSubs; |
| 7 |
|
| 8 |
my $lib_version; |
| 9 |
|
| 10 |
WriteMakefile(TrapReceiverInitMakeParams()); |
| 11 |
|
| 12 |
Check_Version($lib_version); |
| 13 |
|
| 14 |
if (eval {require ExtUtils::Constant; 1}) { |
| 15 |
# If you edit these definitions to change the constants used by this module, |
| 16 |
# you will need to use the generated const-c.inc and const-xs.inc |
| 17 |
# files to replace their "fallback" counterparts before distributing your |
| 18 |
# changes. |
| 19 |
my @names = (qw(NETSNMPTRAPD_AUTH_HANDLER NETSNMPTRAPD_HANDLER_BREAK |
| 20 |
NETSNMPTRAPD_HANDLER_FAIL NETSNMPTRAPD_HANDLER_FINISH |
| 21 |
NETSNMPTRAPD_HANDLER_OK NETSNMPTRAPD_POST_HANDLER |
| 22 |
NETSNMPTRAPD_PRE_HANDLER)); |
| 23 |
ExtUtils::Constant::WriteConstants( |
| 24 |
NAME => 'NetSNMP::TrapReceiver', |
| 25 |
NAMES => \@names, |
| 26 |
DEFAULT_TYPE => 'IV', |
| 27 |
C_FILE => 'const-c.inc', |
| 28 |
XS_FILE => 'const-xs.inc', |
| 29 |
); |
| 30 |
|
| 31 |
} else { |
| 32 |
use File::Copy; |
| 33 |
use File::Spec; |
| 34 |
foreach my $file ('const-c.inc', 'const-xs.inc') { |
| 35 |
my $fallback = File::Spec->catfile('fallback', $file); |
| 36 |
copy ($fallback, $file) or die "Can't copy $fallback to $file: $!"; |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
sub TrapReceiverInitMakeParams { |
| 41 |
my $opts; |
| 42 |
my %Params = ( |
| 43 |
'NAME' => 'NetSNMP::TrapReceiver', |
| 44 |
'VERSION_FROM' => 'TrapReceiver.pm', # finds $VERSION |
| 45 |
'XSPROTOARG' => '-prototypes', |
| 46 |
'PREREQ_PM' => { 'NetSNMP::OID' => 5.02 }, |
| 47 |
($] >= 5.005 ? ## Add these new keywords supported since 5.005 |
| 48 |
(ABSTRACT_FROM => 'TrapReceiver.pm', |
| 49 |
AUTHOR => |
| 50 |
'W. Hardaker <[email protected]>') : ()), |
| 51 |
'INC' => '-I.', # e.g., '-I. -I/usr/include/other' |
| 52 |
); |
| 53 |
|
| 54 |
|
| 55 |
AddCommonParams(\%Params); |
| 56 |
|
| 57 |
my ($snmp_lib, $snmp_llib, $sep); |
| 58 |
|
| 59 |
$opts = NetSNMPGetOpts(); |
| 60 |
|
| 61 |
if ($Config{'osname'} eq 'MSWin32' && !defined($ENV{'OSTYPE'})) { |
| 62 |
$sep = '\\'; |
| 63 |
my $snmp_lib_file = 'netsnmp.lib'; |
| 64 |
my $snmp_link_lib = 'netsnmp'; |
| 65 |
my $lib_dir; |
| 66 |
my $agent_link_lib = 'netsnmpagent'; |
| 67 |
my $mibs_link_lib = 'netsnmpmibs'; |
| 68 |
my $trapd_link_lib = 'netsnmptrapd'; |
| 69 |
|
| 70 |
if (lc($opts->{'debug'}) eq "true") { |
| 71 |
$lib_dir = 'lib\\debug'; |
| 72 |
} |
| 73 |
else { |
| 74 |
$lib_dir = 'lib\\release'; |
| 75 |
} |
| 76 |
|
| 77 |
if (lc($opts->{'insource'}) eq "true") { |
| 78 |
$Params{'LIBS'} = "-L" . $MakefileSubs::basedir . "\\win32\\$lib_dir\\ -l$snmp_link_lib -l$agent_link_lib " . |
| 79 |
"-l$mibs_link_lib -l$trapd_link_lib "; |
| 80 |
} |
| 81 |
else { |
| 82 |
my @LibDirs = split($Config{path_sep}, $ENV{LIB}); |
| 83 |
my $LibDir; |
| 84 |
if ($opts->{'prefix'}) { |
| 85 |
push (@LibDirs,"$ENV{'NET-SNMP-PATH'}${sep}lib"); |
| 86 |
} |
| 87 |
my $noLibDir = 1; |
| 88 |
while ($noLibDir) { |
| 89 |
$LibDir = find_files(["$snmp_lib_file"],\@LibDirs); |
| 90 |
if ($LibDir ne '') { |
| 91 |
$noLibDir = 0; |
| 92 |
# Put quotes around LibDir to allow spaces in paths |
| 93 |
$LibDir = '"' . $LibDir . '"'; |
| 94 |
} |
| 95 |
else |
| 96 |
{ |
| 97 |
@LibDirs = (); |
| 98 |
$LibDirs[0] = prompt("The Net-SNMP library ($snmp_lib_file) could not be found.\nPlease enter the directory where it is located:"); |
| 99 |
$LibDirs[0] =~ s/\\$//; |
| 100 |
} |
| 101 |
} |
| 102 |
$Params{LIBS} = "-L$LibDir -l$snmp_link_lib -l$agent_link_lib -l$mibs_link_lib -l$trapd_link_lib "; |
| 103 |
} |
| 104 |
} |
| 105 |
else { |
| 106 |
$Params{'LIBS'} = '-lnetsnmptrapd ' . `$opts->{'nsconfig'} --base-agent-libs` or |
| 107 |
die "net-snmp-config failed\n"; |
| 108 |
chomp($Params{'LIBS'}); |
| 109 |
|
| 110 |
if (lc($opts->{'insource'}) eq "true") { |
| 111 |
$Params{'LIBS'} = |
| 112 |
"-L" . abs_path("../../apps/.libs") . |
| 113 |
" -L" . abs_path("../../apps") . |
| 114 |
" -L" . abs_path("../../agent/.libs") . |
| 115 |
" -L" . abs_path("../../agent") . |
| 116 |
" -L" . abs_path("../../snmplib/.libs") . |
| 117 |
" -L" . abs_path("../../snmplib") . |
| 118 |
" " . $Params{'LIBS'}; |
| 119 |
} else { |
| 120 |
$Params{'LIBS'} = `$opts->{'nsconfig'} --libdir` . " $Params{'LIBS'}"; |
| 121 |
} |
| 122 |
|
| 123 |
$lib_version = `$opts->{'nsconfig'} --version` or |
| 124 |
die "net-snmp-config failed\n"; |
| 125 |
} |
| 126 |
|
| 127 |
return(%Params); |
| 128 |
} |