~ubuntu-branches/ubuntu/trusty/net-snmp/trusty

« back to all changes in this revision

Viewing changes to perl/agent/Makefile.PL

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2004-09-13 12:06:21 UTC
  • Revision ID: james.westby@ubuntu.com-20040913120621-g952ntonlleihcvm
Tags: upstream-5.1.1
ImportĀ upstreamĀ versionĀ 5.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
use ExtUtils::MakeMaker;
 
2
require 5;
 
3
use Config;
 
4
use Getopt::Long;
 
5
my %MakeParams = ();
 
6
 
 
7
%MakeParams = InitMakeParams();
 
8
 
 
9
WriteMakefile(%MakeParams);
 
10
 
 
11
sub InitMakeParams {
 
12
    my $opts;
 
13
    my %Params = (
 
14
                  'NAME'                => 'NetSNMP::agent',
 
15
                  'VERSION_FROM'        => 'agent.pm', # finds $VERSION
 
16
                  'XSPROTOARG'          => '-prototypes',
 
17
                  'PM'                => { 
 
18
                      'agent.pm' => '$(INST_LIBDIR)/agent.pm',
 
19
                      'netsnmp_request_infoPtr.pm' =>
 
20
                          '$(INST_LIBDIR)/agent/netsnmp_request_infoPtr.pm'
 
21
                  },
 
22
                  'PREREQ_PM'           => {},
 
23
                  );
 
24
 
 
25
    if ($ENV{'OSTYPE'} eq 'msys') {
 
26
      $Params{'DEFINE'} = "-DMINGW_PERL";
 
27
    }
 
28
                                   
 
29
    my ($snmp_lib, $snmp_llib, $sep);
 
30
    if (($Config{'osname'} eq 'MSWin32' && $ENV{'OSTYPE'} ne 'msys')) {
 
31
      $opts = NetSNMPGetOpts(); 
 
32
      $Params{'DEFINE'} = "-DMSVC_PERL";
 
33
      $sep = '\\';
 
34
      $snmp_lib_file = 'netsnmp.lib';
 
35
      $snmp_link_lib = 'netsnmp';
 
36
      $agent_link_lib = 'netsnmpagent';
 
37
      $helpers_link_lib = 'netsnmphelpers';
 
38
      $mibs_link_lib = 'netsnmpmibs';
 
39
 
 
40
      if (lc($opts->{'debug'}) eq "true") {
 
41
        $lib_dir = 'lib\\debug';
 
42
      }
 
43
      else {
 
44
        $lib_dir = 'lib\\release';
 
45
      }
 
46
    
 
47
      if (lc($opts->{'insource'}) eq "true") {
 
48
        $Params{'LIBS'} = "-L$basedir\\win32\\$lib_dir\\ -l$snmp_link_lib -l$agent_link_lib -l$helpers_link_lib " .
 
49
                "-l$mibs_link_lib";
 
50
      }
 
51
      else {
 
52
        my @LibDirs = split (';',$ENV{LIB});
 
53
        my $LibDir;
 
54
        if ($opts->{'prefix'}) {
 
55
          push (@LibDirs,"$ENV{'NET-SNMP-PATH'}${sep}lib");
 
56
        }
 
57
        $noLibDir = 1;
 
58
        while ($noLibDir) {
 
59
          $LibDir = find_files(["$snmp_lib_file"],\@LibDirs);
 
60
          if ($LibDir ne '') {
 
61
            $noLibDir = 0;
 
62
            # Put quotes around LibDir to allow spaces in paths
 
63
            $LibDir = '"' . $LibDir . '"';          
 
64
          }
 
65
          else
 
66
          {
 
67
            @LibDirs = ();
 
68
            @LibDirs[0] = prompt("The Net-SNMP library ($snmp_lib_file) could not be found.\nPlease enter the directory where it is located:");
 
69
            @LibDirs[0] =~ s/\\$//;
 
70
          }
 
71
        }
 
72
        $Params{LIBS} = "-L$LibDir -l$snmp_link_lib -l$agent_link_lib -l$helpers_link_lib -l$mibs_link_lib";
 
73
      }
 
74
 
 
75
      $Params{'INC'} = "-I$basedir\\include\\ -I$basedir\\include\\net-snmp\\ -I$basedir\\win32\\ ";
 
76
    }
 
77
    else {
 
78
        $opts = NetSNMPGetOpts();
 
79
        $Params{'LIBS'}    = `$opts->{'nsconfig'} --agent-libs`;
 
80
        chomp($Params{'LIBS'});
 
81
        $Params{'CCFLAGS'} = `$opts->{'nsconfig'} --cflags`;
 
82
        chomp($Params{'CCFLAGS'});
 
83
        $Params{'CCFLAGS'} .= " " . $Config{'ccflags'};
 
84
        if (lc($opts->{'insource'}) eq "true") {
 
85
            $Params{'LIBS'} = "-L../../snmplib/.libs -L../../snmplib/ -L../../agent/.libs -L../../agent/ -L../../agent/helpers/.libs -L../../agent/helpers/ " . $Params{'LIBS'};
 
86
            $Params{'CCFLAGS'} = "-I../../include " . $Params{'CCFLAGS'};
 
87
#       } else {
 
88
#           $Params{'PREREQ_PM'} = {'NetSNMP::OID' => '0.1'};
 
89
        }
 
90
        $Params{'CCFLAGS'} =~ s/ -W[-\w]+//g; # ignore developer warnings
 
91
        if ($Params{'LIBS'} eq "" || $Params{'CCFLAGS'} eq "") {
 
92
            die "You need to install net-snmp first (I can't find net-snmp-config)";
 
93
        }
 
94
    }
 
95
 
 
96
    return(%Params);
 
97
}
 
98
# common subroutines -- DO NOT EDIT.
 
99
# They are imported from the Makefile.subs.pl file
 
100
sub NetSNMPGetOpts {
 
101
    my %ret;
 
102
    my $rootpath = shift;
 
103
    $rootpath = "../" if (!$rootpath);
 
104
    $rootpath .= '/' if ($rootpath !~ /\/$/);
 
105
    
 
106
    if (($Config{'osname'} eq 'MSWin32' && $ENV{'OSTYPE'} ne 'msys')) {
 
107
 
 
108
      # Grab command line options first.  Only used if environment variables are not set
 
109
      GetOptions("NET-SNMP-IN-SOURCE=s" => \$ret{'insource'},
 
110
        "NET-SNMP-PATH=s"      => \$ret{'prefix'},          
 
111
        "NET-SNMP-DEBUG=s"     => \$ret{'debug'});
 
112
 
 
113
      if ($ENV{'NET-SNMP-IN-SOURCE'})
 
114
      {
 
115
        $ret{'insource'} = $ENV{'NET-SNMP-IN-SOURCE'};
 
116
        undef ($ret{'prefix'});
 
117
      }
 
118
      elsif ($ENV{'NET-SNMP-PATH'})
 
119
      {
 
120
        $ret{'prefix'} = $ENV{'NET-SNMP-PATH'};
 
121
      }
 
122
 
 
123
      if ($ENV{'NET-SNMP-DEBUG'})
 
124
      {
 
125
        $ret{'debug'} = $ENV{'NET-SNMP-DEBUG'};
 
126
      }
 
127
 
 
128
      # Update environment variables in case they are needed
 
129
      $ENV{'NET-SNMP-IN-SOURCE'}    = $ret{'insource'};
 
130
      $ENV{'NET-SNMP-PATH'}         = $ret{'prefix'};
 
131
      $ENV{'NET-SNMP-DEBUG'}        = $ret{'debug'};        
 
132
     
 
133
      $basedir = `%COMSPEC% /c cd`;
 
134
      chomp $basedir;
 
135
      $basedir =~ /(.*?)\\perl.*/;
 
136
      $basedir = $1;
 
137
      print "Net-SNMP base directory: $basedir\n";
 
138
 
 
139
    }
 
140
    else
 
141
    {
 
142
      if ($ENV{'NET-SNMP-CONFIG'} && 
 
143
        $ENV{'NET-SNMP-IN-SOURCE'}) {
 
144
        # have env vars, pull from there
 
145
        $ret{'nsconfig'} = $ENV{'NET-SNMP-CONFIG'};
 
146
        $ret{'insource'} = $ENV{'NET-SNMP-IN-SOURCE'};
 
147
      } else {
 
148
        # don't have env vars, pull from command line and put there
 
149
        GetOptions("NET-SNMP-CONFIG=s" => \$ret{'nsconfig'},
 
150
                   "NET-SNMP-IN-SOURCE=s" => \$ret{'insource'});
 
151
 
 
152
        if (lc($ret{'insource'}) eq "true" && $ret{'nsconfig'} eq "") {
 
153
            $ret{'nsconfig'}="sh ROOTPATH../net-snmp-config";
 
154
        } elsif ($ret{'nsconfig'} eq "") {
 
155
            $ret{'nsconfig'}="net-snmp-config";
 
156
        }
 
157
 
 
158
        $ENV{'NET-SNMP-CONFIG'}    = $ret{'nsconfig'};
 
159
        $ENV{'NET-SNMP-IN-SOURCE'} = $ret{'insource'};
 
160
      }
 
161
    }   
 
162
    
 
163
    $ret{'nsconfig'} =~ s/ROOTPATH/$rootpath/;
 
164
 
 
165
    $ret{'rootpath'} = $rootpath;
 
166
 
 
167
    \%ret;
 
168
}
 
169
 
 
170
sub find_files {
 
171
    my($f,$d) = @_;
 
172
    my ($dir,$found,$file);
 
173
    for $dir (@$d){
 
174
        $found = 0;
 
175
        for $file (@$f) {
 
176
            $found++ if -f "$dir/$file";
 
177
        }
 
178
        if ($found == @$f) {
 
179
            return $dir;
 
180
        }
 
181
    }
 
182
}
 
183