added files
[bcm963xx.git] / userapps / opensource / net-snmp / perl / SNMP / Makefile.PL
1 use ExtUtils::MakeMaker;
2 require 5;
3 use Config;
4 use Getopt::Long;
5
6 # See lib/ExtUtils/MakeMaker.pm for details of how to influence
7 # the contents of the Makefile that is written.
8
9 %MakeParams = InitMakeParams();
10
11 WriteMakefile(%MakeParams);
12
13 GetTestInfo();
14
15 sub InitMakeParams {
16     my $opts;
17     my %Params = (
18                   NAME         => 'SNMP',
19                   dist         => { SUFFIX => "gz", COMPRESS => "gzip -9f"},
20                   MAN3PODS => { 'SNMP.pm' => '$(INST_MAN3DIR)/SNMP.3' },
21                   XSPROTOARG   => '-noprototypes',      # XXX remove later?
22                   VERSION_FROM => 'SNMP.pm',
23                   realclean        => { FILES => 'host' },
24                   );
25
26     my ($snmp_lib, $snmp_llib, $sep);
27     if ($Config{'osname'} eq 'MSWin32') {
28         $snmp_lib = 'libnetsnmp.lib';
29         $snmp_link_lib = 'libnetsnmp';
30         $sep = '\\';
31         # XXX fix me
32     } else {
33         $opts = NetSNMPGetOpts();
34         if (!$ENV{'NETSNMP_LIBS'}) {
35             $Params{'LIBS'}    = `$opts->{'nsconfig'} --libs`;
36             chomp($Params{'LIBS'});
37         } else {
38             $Params{'LIBS'} = $ENV{'NETSNMP_LIBS'};
39         }
40         if (!$ENV{'NETSNMP_CCFLAGS'}) {
41             $Params{'CCFLAGS'} = `$opts->{'nsconfig'} --cflags`;
42             chomp($Params{'CCFLAGS'});
43             $Params{'CCFLAGS'} .= " " . $Config{'ccflags'};
44         } else {
45             $Params{'CCFLAGS'} = $ENV{'NETSNMP_CCFLAGS'};
46         }
47         if ($opts->{'insource'} eq "true") {
48             $Params{'LIBS'} = "-L../../snmplib/.libs -L../../snmplib/ " . $Params{'LIBS'};
49             $Params{'CCFLAGS'} = "-I../../include " . $Params{'CCFLAGS'};
50 #       } else {
51 #           $Params{'PREREQ_PM'} = { 'NetSNMP::default_store' => 0.01 };
52         }
53         $Params{'CCFLAGS'} =~ s/ -W[-\w]+//g; # ignore developer warnings
54         if (!$ENV{'NETSNMP_PREFIX'}) {
55             $prefix            = `$opts->{'nsconfig'} --prefix`;
56             chomp($prefix);
57             $sep = '/';
58         } else {
59             $prefix = $ENV{'NETSNMP_PREFIX'};
60         }
61         if ($Params{'LIBS'} eq "" || $Params{'CCFLAGS'} eq "") {
62             die "You need to install net-snmp first (I can't find net-snmp-config)";
63         }
64     }
65
66     return(%Params);
67
68 }
69
70 sub find_files {
71     my($f,$d) = @_;
72     my ($dir,$found,$file);
73     for $dir (@$d){
74         $found = 0;
75         for $file (@$f) {
76             $found++ if -f "$dir/$file";
77         }
78         if ($found == @$f) {
79             return $dir;
80         }
81     }
82 }
83
84 sub GetTestInfo {
85     my $sep = ($^O =~ /win32/i ? '\\' : '/');
86     my $info_file = "t${sep}snmptest.cmd";
87     my $snmpd_path1 = "${prefix}${sep}sbin";
88     my $snmpd_path2 = "${sep}usr${sep}sbin";
89     my $snmpd_path3 = "${sep}usr${sep}bin";
90     open(H, ">$info_file") || die "Error: could not open file '$info_file'($!)";
91     if($^O =~ /win32/i) {
92 #you are using WIN 32
93         my $mibdir = "${prefix}${sep}share${sep}snmp${sep}mibs";
94         print <<WIN32
95 ==================================================================
96 You are using Windows 32. The testing of Perl/SNMP API here would
97 require you to start an snmpd agent and a trap receiver using the
98 config file provided ( t\\snmptest.conf) manually.The
99 test scripts will not do this(as in unix testing). So, please
100 run those agents and enter the following information.If the data
101 about host, agent_port and trap_port are already present in your
102 snmptest.cmd file, make test will use those data for testing.
103 =================================================================
104 WIN32
105 ;
106
107         $host = prompt("Please enter the host IP address/host name: ", "localhost");
108         print H "HOST => $host\n";
109         $agent_port = prompt("Please enter the agent port number: ", 161);
110         print H "AGENT_PORT => $agent_port\n";
111         $trap_port = prompt("Please enter the trap port number: ", 162);
112         print H "TRAP_PORT => $trap_port\n";
113         $mibdir = prompt("Please enter the MIB directory: ", "/usr/mibs");
114         print H "MIBDIR => $mibdir\n";
115     } else {
116 # you are using UNIX
117         my ($mibdir, $snmpd, $snmptrapd);
118         if ($opts->{'insource'} eq "true") {
119             $mibdir = "../../mibs";
120             $snmpd = "../../agent/snmpd";
121             $snmptrapd = "../../apps/snmptrapd";
122         } else {
123             $mibdir = "${prefix}${sep}share${sep}snmp${sep}mibs";
124             $snmpd = find_files(["snmpd"], [$snmpd_path1, $snmpd_path2]);
125             $snmptrapd = find_files(["snmptrapd"], [$snmpd_path1, $snmpd_path2]);
126         }
127         $mibdir = find_files(["NET-SNMP-MIB.txt"],[$mibdir]);
128
129         $mibdir ||= prompt("Unable to locate the MIBs, Please enter the path: ",
130                            $mibdir);
131         $snmpd ||= prompt("Unable to locate \"snmpd\". Please enter the path: ",
132                           $snmpd_path1);
133         $snmptrapd ||=
134             prompt("Unable to locate \"snmptrapd\". Please enter the path: ",
135                    $snmpd_path1);
136
137         $snmpd =~ s/($sep)?(snmpd)?$/${sep}snmpd/;
138         $snmptrapd =~ s/($sep)?(snmptrapd)?$/${sep}snmptrapd/;
139
140         print H "SNMPD => $snmpd\n";
141         print H "SNMPTRAPD => $snmptrapd\n";
142         print H "MIBDIR => $mibdir\n";
143
144         if (!$opts->{'insource'}) {
145             if (-e $snmpd and -r $snmpd) {
146                 if (not -x $snmpd) {
147                     warn("Error: $snmpd not executable. 'make test' will not work.\n");
148                 }
149             } else {
150                 warn("Error: $snmpd does not exist or is unreadable. 'make test' will not work.\n");
151             }
152
153             if (-e $snmptrapd and -r $snmptrapd) {
154                 if (not -x $snmptrapd) {
155                     warn("Error: $snmptrapd not executable. 'make test' will not work.\n");
156                 }
157             } else {
158                 warn("Error: $snmptrapd does not exist or is unreadable. 'make test' will not work.\n");
159             }
160         }
161     }
162 # end of else
163     close H;
164 }
165
166 sub HasSSL {
167     my $config_header = shift;
168     my $has_ssl;
169     unless (open(C,"<$config_header")) {
170         warn("Unable to open $config_header, assuming no SSL\n");
171         return undef;
172     }
173     while (<C>) {
174         $has_ssl++, last if /^\s*#define\s+USE_OPENSSL/;
175     }
176     close C;
177     return $has_ssl;
178 }
179 # common subroutines -- DO NOT EDIT.
180 # They are imported from the Makefile.subs.pl file
181 sub NetSNMPGetOpts {
182     my %ret;
183     my $rootpath = shift;
184     $rootpath = "../" if (!$rootpath);
185     $rootpath .= '/' if ($rootpath !~ /\/$/);
186
187     if ($ENV{'NET-SNMP-CONFIG'} && 
188         $ENV{'NET-SNMP-IN-SOURCE'}) {
189         # have env vars, pull from there
190         $ret{'nsconfig'} = $ENV{'NET-SNMP-CONFIG'};
191         $ret{'insource'} = $ENV{'NET-SNMP-IN-SOURCE'};
192     } else {
193         # don't have env vars, pull from command line and put there
194         GetOptions("NET-SNMP-CONFIG=s" => \$ret{'nsconfig'},
195                    "NET-SNMP-IN-SOURCE=s" => \$ret{'insource'});
196
197         if ($ret{'insource'} eq "true" && $ret{'nsconfig'} eq "") {
198             $ret{'nsconfig'}="sh ROOTPATH../net-snmp-config";
199         } elsif ($ret{'nsconfig'} eq "") {
200             $ret{'nsconfig'}="net-snmp-config";
201         }
202
203         $ENV{'NET-SNMP-CONFIG'}    = $ret{'nsconfig'};
204         $ENV{'NET-SNMP-IN-SOURCE'} = $ret{'insource'};
205     }   
206     
207     $ret{'nsconfig'} =~ s/ROOTPATH/$rootpath/;
208
209     $ret{'rootpath'} = $rootpath;
210
211     \%ret;
212 }