PageRenderTime 52ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/net-snmp-5.7.1/perl/SNMP/Makefile.PL

#
Perl | 363 lines | 337 code | 22 blank | 4 comment | 18 complexity | 1474c3939080a1c28334c95b6fcf69c8 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. use ExtUtils::MakeMaker;
  2. require 5;
  3. use Config;
  4. use Getopt::Long;
  5. my $lib_version;
  6. my %MakeParams = ();
  7. my $opts;
  8. # See lib/ExtUtils/MakeMaker.pm for details of how to influence
  9. # the contents of the Makefile that is written.
  10. %MakeParams = InitMakeParams();
  11. WriteMakefile(%MakeParams);
  12. Check_Version();
  13. GetTestInfo();
  14. sub InitMakeParams {
  15. my %Params = (
  16. NAME => 'SNMP',
  17. dist => { SUFFIX => "gz", COMPRESS => "gzip -9f"},
  18. MAN3PODS => { 'SNMP.pm' => '$(INST_MAN3DIR)/SNMP.3' },
  19. XSPROTOARG => '-noprototypes', # XXX remove later?
  20. VERSION_FROM => 'SNMP.pm',
  21. realclean => { FILES => 'host' },
  22. );
  23. if ($ENV{'OSTYPE'} eq 'msys') {
  24. $Params{'DEFINE'} = "-DMINGW_PERL";
  25. }
  26. my ($snmp_lib, $snmp_llib, $sep);
  27. if (($Config{'osname'} eq 'MSWin32' && $ENV{'OSTYPE'} eq '')) {
  28. $opts = NetSNMPGetOpts();
  29. $Params{'DEFINE'} = "-DMSVC_PERL -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS";
  30. $sep = '\\';
  31. $snmp_lib_file = 'netsnmp.lib';
  32. $snmp_link_lib = 'netsnmp';
  33. if (lc($opts->{'debug'}) eq "true") {
  34. $lib_dir = 'lib\\debug';
  35. }
  36. else {
  37. $lib_dir = 'lib\\release';
  38. }
  39. if (lc($opts->{'insource'}) eq "true") {
  40. $Params{'LIBS'} = "-L$basedir\\win32\\$lib_dir\\ -l$snmp_link_lib";
  41. }
  42. else {
  43. my @LibDirs = split (';',$ENV{LIB});
  44. my $LibDir;
  45. if ($opts->{'prefix'}) {
  46. push (@LibDirs,"$ENV{'NET-SNMP-PATH'}${sep}lib");
  47. }
  48. $noLibDir = 1;
  49. while ($noLibDir) {
  50. $LibDir = find_files(["$snmp_lib_file"],\@LibDirs);
  51. if ($LibDir ne '') {
  52. $noLibDir = 0;
  53. # Put quotes around LibDir to allow spaces in paths
  54. $LibDir = '"' . $LibDir . '"';
  55. }
  56. else
  57. {
  58. @LibDirs = ();
  59. $LibDirs[0] = prompt("The Net-SNMP library ($snmp_lib_file) could not be found.\nPlease enter the directory where it is located:");
  60. $LibDirs[0] =~ s/\\$//;
  61. }
  62. }
  63. $Params{LIBS} = "-L$LibDir -l$snmp_link_lib";
  64. }
  65. $Params{'INC'} = "-I$basedir\\include\\ -I$basedir\\include\\net-snmp\\ -I$basedir\\win32\\ ";
  66. }
  67. else {
  68. $opts = NetSNMPGetOpts();
  69. $Params{'LDDLFLAGS'} = "$Config{lddlflags} " . `$opts->{'nsconfig'} --ldflags`;
  70. if (!$ENV{'NETSNMP_LIBS'}) {
  71. $Params{'LIBS'} = `$opts->{'nsconfig'} --libs`;
  72. chomp($Params{'LIBS'});
  73. } else {
  74. $Params{'LIBS'} = $ENV{'NETSNMP_LIBS'};
  75. }
  76. if (!$ENV{'NETSNMP_CCFLAGS'}) {
  77. $Params{'CCFLAGS'} = `$opts->{'nsconfig'} --cflags`;
  78. chomp($Params{'CCFLAGS'});
  79. $Params{'CCFLAGS'} .= " " . $Config{'ccflags'};
  80. } else {
  81. $Params{'CCFLAGS'} = $ENV{'NETSNMP_CCFLAGS'};
  82. }
  83. $lib_version = `$opts->{'nsconfig'} --version`;
  84. if (lc($opts->{'insource'}) eq "true") {
  85. $Params{'LIBS'} = "-L../../snmplib/.libs -L../../snmplib/ " . $Params{'LIBS'};
  86. $Params{'CCFLAGS'} = "-I../../include " . $Params{'CCFLAGS'};
  87. # } else {
  88. # $Params{'PREREQ_PM'} = { 'NetSNMP::default_store' => 0.01 };
  89. }
  90. $Params{'CCFLAGS'} =~ s/ -W(all|inline|strict-prototypes|write-strings|cast-qual|no-char-subscripts)//g; # ignore developer warnings
  91. if (!$ENV{'NETSNMP_PREFIX'}) {
  92. $prefix = `$opts->{'nsconfig'} --prefix`;
  93. chomp($prefix);
  94. $sep = '/';
  95. } else {
  96. $prefix = $ENV{'NETSNMP_PREFIX'};
  97. }
  98. if ($Params{'LIBS'} eq "" || $Params{'CCFLAGS'} eq "") {
  99. die "You need to install net-snmp first (I can't find net-snmp-config)";
  100. }
  101. }
  102. return(%Params);
  103. }
  104. sub GetTestInfo {
  105. my $sep = ($^O =~ /win32/i ? '\\' : '/');
  106. my $info_file = "t${sep}snmptest.cmd";
  107. my $snmpd_path1 = "${prefix}${sep}sbin";
  108. my $snmpd_path2 = "${sep}usr${sep}sbin";
  109. my $snmpd_path3 = "${sep}usr${sep}bin";
  110. my $win32_snmpd_path = $ENV{'NET-SNMP-PATH'} . $sep . "bin";
  111. open(H, ">$info_file") || die "Error: could not open file '$info_file'($!)";
  112. my ($mibdir, $snmpd, $snmptrapd);
  113. # Windows
  114. if ($Config{'osname'} eq 'MSWin32' && $ENV{'OSTYPE'} eq '') {
  115. if (lc ($opts->{'insource'}) eq "true") {
  116. $mibdir = "../../mibs";
  117. if (lc($opts->{'debug'}) eq "true") {
  118. $snmpd = "../../win32/bin/debug";
  119. $snmptrapd = "../../win32/bin/debug";
  120. }
  121. else {
  122. $snmpd = "../../win32/bin/release";
  123. $snmptrapd = "../../win32/bin/release";
  124. }
  125. } else {
  126. $mibdir = $ENV{'NET-SNMP-PATH'} . "${sep}share${sep}snmp${sep}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 = "../../mibs";
  135. $snmpd = "../../agent/snmpd";
  136. $snmptrapd = "../../apps/snmptrapd";
  137. } else {
  138. $mibdir = "${prefix}${sep}share${sep}snmp${sep}mibs";
  139. $snmpd = find_files(["snmpd"], [$snmpd_path1, $snmpd_path2]);
  140. $snmptrapd = find_files(["snmptrapd"], [$snmpd_path1, $snmpd_path2]);
  141. }
  142. }
  143. $mibdir = find_files(["NET-SNMP-MIB.txt"],[$mibdir]);
  144. $mibdir ||= prompt("Unable to locate the MIBs, Please enter the path: ",
  145. $mibdir);
  146. $snmpd ||= prompt("Unable to locate \"snmpd\". Please enter the path: ",
  147. $snmpd_path1);
  148. $snmptrapd ||=
  149. prompt("Unable to locate \"snmptrapd\". Please enter the path: ",
  150. $snmpd_path1);
  151. if ($Config{'osname'} eq 'MSWin32' && $ENV{'OSTYPE'} eq '') {
  152. $snmpd = $snmpd . $sep . "snmpd.exe";
  153. $snmptrapd = $snmptrapd . $sep . "snmptrapd.exe";
  154. }
  155. else {
  156. if ($ENV{'OSTYPE'} eq 'msys') {
  157. $snmpd =~ s/snmpd$/snmpd.exe/;
  158. $snmptrapd =~ s/snmptrapd$/snmptrapd.exe/;
  159. }
  160. else
  161. {
  162. $snmpd =~ s/($sep)?(snmpd)?$/${sep}snmpd/;
  163. $snmptrapd =~ s/($sep)?(snmptrapd)?$/${sep}snmptrapd/;
  164. }
  165. }
  166. print H "SNMPD => $snmpd\n";
  167. print H "SNMPTRAPD => $snmptrapd\n";
  168. print H "MIBDIR => $mibdir\n";
  169. if (!(lc($opts->{'insource'}) eq "true")) {
  170. if (-e $snmpd and -r $snmpd) {
  171. if (not -x $snmpd) {
  172. warn("Error: $snmpd not executable. 'make test' will not work.\n");
  173. }
  174. } else {
  175. warn("Error: $snmpd does not exist or is unreadable. 'make test' will not work.\n");
  176. }
  177. if (-e $snmptrapd and -r $snmptrapd) {
  178. if (not -x $snmptrapd) {
  179. warn("Error: $snmptrapd not executable. 'make test' will not work.\n");
  180. }
  181. } else {
  182. warn("Error: $snmptrapd does not exist or is unreadable. 'make test' will not work.\n");
  183. }
  184. }
  185. # end of else
  186. close H;
  187. }
  188. sub HasSSL {
  189. my $config_header = shift;
  190. my $has_ssl;
  191. unless (open(C,"<$config_header")) {
  192. warn("Unable to open $config_header, assuming no SSL\n");
  193. return undef;
  194. }
  195. while (<C>) {
  196. $has_ssl++, last if /^\s*#define\s+NETSNMP_USE_OPENSSL/;
  197. }
  198. close C;
  199. return $has_ssl;
  200. }
  201. # common subroutines -- DO NOT EDIT.
  202. # They are imported from the Makefile.subs.pl file
  203. sub NetSNMPGetOpts {
  204. my %ret;
  205. my $rootpath = shift;
  206. $rootpath = "../" if (!$rootpath);
  207. $rootpath .= '/' if ($rootpath !~ /\/$/);
  208. if (($Config{'osname'} eq 'MSWin32' && $ENV{'OSTYPE'} eq '')) {
  209. # Grab command line options first. Only used if environment variables are not set
  210. GetOptions("NET-SNMP-IN-SOURCE=s" => \$ret{'insource'},
  211. "NET-SNMP-PATH=s" => \$ret{'prefix'},
  212. "NET-SNMP-DEBUG=s" => \$ret{'debug'});
  213. if ($ENV{'NET-SNMP-IN-SOURCE'})
  214. {
  215. $ret{'insource'} = $ENV{'NET-SNMP-IN-SOURCE'};
  216. undef ($ret{'prefix'});
  217. }
  218. elsif ($ENV{'NET-SNMP-PATH'})
  219. {
  220. $ret{'prefix'} = $ENV{'NET-SNMP-PATH'};
  221. }
  222. if ($ENV{'NET-SNMP-DEBUG'})
  223. {
  224. $ret{'debug'} = $ENV{'NET-SNMP-DEBUG'};
  225. }
  226. # Update environment variables in case they are needed
  227. $ENV{'NET-SNMP-IN-SOURCE'} = $ret{'insource'};
  228. $ENV{'NET-SNMP-PATH'} = $ret{'prefix'};
  229. $ENV{'NET-SNMP-DEBUG'} = $ret{'debug'};
  230. $basedir = `%COMSPEC% /c cd`;
  231. chomp $basedir;
  232. $basedir =~ /(.*?)\\perl.*/;
  233. $basedir = $1;
  234. print "Net-SNMP base directory: $basedir\n";
  235. if ($basedir =~ / /) {
  236. die "\nA space has been detected in the base directory. This is not " .
  237. "supported\nPlease rename the folder and try again.\n\n";
  238. }
  239. }
  240. else
  241. {
  242. if ($ENV{'NET-SNMP-CONFIG'} &&
  243. $ENV{'NET-SNMP-IN-SOURCE'}) {
  244. # have env vars, pull from there
  245. $ret{'nsconfig'} = $ENV{'NET-SNMP-CONFIG'};
  246. $ret{'insource'} = $ENV{'NET-SNMP-IN-SOURCE'};
  247. } else {
  248. # don't have env vars, pull from command line and put there
  249. GetOptions("NET-SNMP-CONFIG=s" => \$ret{'nsconfig'},
  250. "NET-SNMP-IN-SOURCE=s" => \$ret{'insource'});
  251. if (lc($ret{'insource'}) eq "true" && $ret{'nsconfig'} eq "") {
  252. $ret{'nsconfig'}="sh ROOTPATH../net-snmp-config";
  253. } elsif ($ret{'nsconfig'} eq "") {
  254. $ret{'nsconfig'}="net-snmp-config";
  255. }
  256. $ENV{'NET-SNMP-CONFIG'} = $ret{'nsconfig'};
  257. $ENV{'NET-SNMP-IN-SOURCE'} = $ret{'insource'};
  258. }
  259. }
  260. $ret{'nsconfig'} =~ s/ROOTPATH/$rootpath/;
  261. $ret{'rootpath'} = $rootpath;
  262. \%ret;
  263. }
  264. sub find_files {
  265. my($f,$d) = @_;
  266. my ($dir,$found,$file);
  267. for $dir (@$d){
  268. $found = 0;
  269. for $file (@$f) {
  270. $found++ if -f "$dir/$file";
  271. }
  272. if ($found == @$f) {
  273. return $dir;
  274. }
  275. }
  276. }
  277. sub Check_Version {
  278. if (($Config{'osname'} ne 'MSWin32' || $ENV{'OSTYPE'} ne '')) {
  279. my $foundversion = 0;
  280. return if ($ENV{'NETSNMP_DONT_CHECK_VERSION'});
  281. open(I,"<Makefile");
  282. while (<I>) {
  283. if (/^VERSION = (.*)/) {
  284. my $perlver = $1;
  285. my $srcver = $lib_version;
  286. chomp($srcver);
  287. my $srcfloat = floatize_version($srcver);
  288. $perlver =~ s/pre/0./;
  289. # we allow for perl/CPAN-only revisions beyond the default
  290. # version formatting of net-snmp itself.
  291. $perlver =~ s/(\.\d{5}).*/\1/;
  292. $perlver =~ s/0*$//;
  293. if ($srcfloat ne $perlver) {
  294. if (!$foundversion) {
  295. print STDERR "ERROR:
  296. Net-SNMP installed version: $srcver => $srcfloat
  297. Perl Module Version: $perlver
  298. These versions must match for perfect support of the module. It is possible
  299. that different versions may work together, but it is strongly recommended
  300. that you make these two versions identical. You can get the Net-SNMP
  301. source code and the associated perl modules directly from
  302. http://www.net-snmp.org/
  303. If you want to continue anyway please set the NETSNMP_DONT_CHECK_VERSION
  304. environmental variable to 1 and re-run the Makefile.PL script.\n";
  305. exit(1);
  306. }
  307. }
  308. $foundversion = 1;
  309. last;
  310. }
  311. }
  312. close(I);
  313. die "ERROR: Couldn't find version number of this module\n"
  314. if (!$foundversion);
  315. }
  316. }
  317. sub floatize_version {
  318. my ($major, $minor, $patch, $opps) = ($_[0] =~ /^(\d+)\.(\d+)\.?(\d*)\.?(\d*)/);
  319. return $major + $minor/100 + $patch/10000 + $opps/100000;
  320. }