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

« back to all changes in this revision

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