Debian Codegraph @

perl/SNMP/Makefile.PL

raw ◀ ▶
1 Debian patch touch this file
1 use strict;
2 use warnings;
3 use Carp;
4 use Config;
5 use Cwd 'abs_path';
6 use ExtUtils::MakeMaker;
7 use File::Spec;
8 use MakefileSubs;
9 require 5;
10
11 my $lib_version;
12 my $opts;
13 my $prefix;
14
15 # See lib/ExtUtils/MakeMaker.pm for details of how to influence
16 # the contents of the Makefile that is written.
17
18 WriteMakefile(SnmpInitMakeParams());
19
20 Check_Version($lib_version);
21
22 GetTestInfo();
23
24 sub SnmpInitMakeParams {
25 my %Params = (
26 NAME => 'SNMP',
27 dist => { SUFFIX => "gz", COMPRESS => "gzip -9f"},
•28 MAN3PODS => { 'SNMP.pm' => '$(INST_MAN3DIR)/SNMP.3pm' },
29 XSPROTOARG => '-noprototypes', # XXX remove later?
30 VERSION_FROM => 'SNMP.pm',
31 realclean => { FILES => 'host' },
32 );
33
34 AddCommonParams(\%Params);
35
36 my ($snmp_lib, $snmp_llib, $sep);
37
38 $opts = NetSNMPGetOpts();
39
40 if ($Config{'osname'} eq 'MSWin32' && !defined($ENV{'OSTYPE'})) {
41 $sep = '\\';
42 my $snmp_lib_file = 'netsnmp.lib';
43 my $snmp_link_lib = 'netsnmp';
44 my $lib_dir;
45
46 if (lc($opts->{'debug'}) eq "true") {
47 $lib_dir = 'lib\\debug';
48 }
49 else {
50 $lib_dir = 'lib\\release';
51 }
52
53 if (lc($opts->{'insource'}) eq "true") {
54 $Params{'LIBS'} = "-L" . $MakefileSubs::basedir . "\\win32\\$lib_dir\\ -l$snmp_link_lib";
55 }
56 else {
57 my @LibDirs = split($Config{path_sep}, $ENV{LIB});
58 my $LibDir;
59 if ($opts->{'prefix'}) {
60 push (@LibDirs,"$ENV{'NET-SNMP-PATH'}${sep}lib");
61 }
62 my $noLibDir = 1;
63 while ($noLibDir) {
64 $LibDir = find_files(["$snmp_lib_file"],\@LibDirs);
65 if ($LibDir ne '') {
66 $noLibDir = 0;
67 # Put quotes around LibDir to allow spaces in paths
68 $LibDir = '"' . $LibDir . '"';
69 }
70 else
71 {
72 @LibDirs = ();
73 $LibDirs[0] = prompt("The Net-SNMP library ($snmp_lib_file) could not be found.\nPlease enter the directory where it is located:");
74 $LibDirs[0] =~ s/\\$//;
75 }
76 }
77 $Params{LIBS} = "-L$LibDir -l$snmp_link_lib";
78 }
79 }
80 else {
81 if (!$ENV{'NETSNMP_LIBS'}) {
82 $Params{'LIBS'} = `$opts->{'nsconfig'} --libs` or
83 die "net-snmp-config failed\n";
84 chomp($Params{'LIBS'});
85 } else {
86 $Params{'LIBS'} = $ENV{'NETSNMP_LIBS'};
87 }
88 $lib_version = `$opts->{'nsconfig'} --version` or
89 die "net-snmp-config failed\n";
90 if (lc($opts->{'insource'}) eq "true") {
91 $Params{'LIBS'} =
92 "-L" . abs_path("../../snmplib/.libs") .
93 " -L" . abs_path("../../snmplib") .
94 " " . $Params{'LIBS'};
95 # } else {
96 # $Params{'PREREQ_PM'} = { 'NetSNMP::default_store' => 0.01 };
97 }
98 $prefix = ($opts->{'prefix'} or `$opts->{'nsconfig'} --prefix` or
99 die "net-snmp-config failed\n");
100 chomp($prefix);
101 $sep = '/';
102 }
103
104 return(%Params);
105
106 }
107
108 sub GetTestInfo {
109 my $info_file = File::Spec->catfile("t", "snmptest.cmd");
110
111 open(H, ">$info_file") || die "Error: could not open file '$info_file'($!)";
112
113 my ($mibdir, $snmpd, $snmptrapd);
114
115 # Windows
116 if ($Config{'osname'} eq 'MSWin32' && !defined($ENV{'OSTYPE'})) {
117 if (lc ($opts->{'insource'}) eq "true") {
118 $mibdir = abs_path("../../mibs");
119 my $cfg = lc($opts->{'debug'}) eq "true" ? "debug" : "release";
120 $snmpd = abs_path("../../win32/bin/$cfg/snmpd.exe");
121 $snmptrapd = abs_path("../../win32/bin/$cfg/snmptrapd.exe");
122 } else {
123 my $win32_snmpd_path = File::Spec->catdir($ENV{'NET-SNMP-PATH'},
124 "bin");
125 $mibdir = File::Spec->catdir($ENV{'NET-SNMP-PATH'}, "share",
126 "snmp", "mibs");
127 $snmpd = find_files(["snmpd.exe"], [$win32_snmpd_path]);
128 $snmptrapd = find_files(["snmptrapd.exe"], [$win32_snmpd_path]);
129 }
130 }
131 # Unix
132 else {
133 if (lc($opts->{'insource'}) eq "true") {
134 $mibdir = abs_path("../../mibs");
135 $snmpd = abs_path("../../agent/snmpd");
136 $snmptrapd = abs_path("../../apps/snmptrapd");
137 } else {
138 croak "\$prefix has not been set" if (!defined($prefix));
139 $mibdir = "${prefix}/share/snmp/mibs";
140 my $snmpd_path1 = abs_path("${prefix}/sbin");
141 my $snmpd_path2 = "/usr/sbin";
142 $snmpd = find_files(["snmpd"], [$snmpd_path1, $snmpd_path2]);
143 $snmptrapd = find_files(["snmptrapd"], [$snmpd_path1, $snmpd_path2]);
144 }
145 }
146
147 $mibdir = find_files(["NET-SNMP-MIB.txt"], [$mibdir]);
148
149 $mibdir ||= prompt("Unable to locate the MIBs, Please enter the path: ",
150 $mibdir);
151 $snmpd ||= prompt("Unable to locate \"snmpd\". Please enter the path: ");
152 $snmptrapd ||=
153 prompt("Unable to locate \"snmptrapd\". Please enter the path: ");
154
155 print H "SNMPD => $snmpd\n";
156 print H "SNMPTRAPD => $snmptrapd\n";
157 print H "MIBDIR => $mibdir\n";
158
159 if (!(lc($opts->{'insource'}) eq "true")) {
160 if (-e $snmpd and -r $snmpd) {
161 if (not -x $snmpd) {
162 warn("Error: $snmpd not executable. 'make test' will not work.\n");
163 }
164 } else {
165 warn("Error: $snmpd does not exist or is unreadable. 'make test' will not work.\n");
166 }
167
168 if (-e $snmptrapd and -r $snmptrapd) {
169 if (not -x $snmptrapd) {
170 warn("Error: $snmptrapd not executable. 'make test' will not work.\n");
171 }
172 } else {
173 warn("Error: $snmptrapd does not exist or is unreadable. 'make test' will not work.\n");
174 }
175 }
176 close H;
177 }
178
179 sub HasSSL {
180 my $config_header = shift;
181 my $has_ssl;
182 unless (open(C,"<$config_header")) {
183 warn("Unable to open $config_header, assuming no SSL\n");
184 return undef;
185 }
186 while (<C>) {
187 $has_ssl++, last if /^\s*#define\s+NETSNMP_USE_OPENSSL/;
188 }
189 close C;
190 return $has_ssl;
191 }