File: MakefileSubs.pm

package info (click to toggle)
net-snmp 5.9.4%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 38,720 kB
  • sloc: ansic: 282,878; perl: 17,704; sh: 12,151; makefile: 2,711; python: 734; xml: 663; pascal: 62; sql: 47
file content (200 lines) | stat: -rw-r--r-- 5,630 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
package MakefileSubs;

use strict;
use warnings;
use Config;
use Cwd 'abs_path';
use File::Basename;
use File::Spec;
use Getopt::Long;
use Exporter;
use vars qw(@ISA @EXPORT_OK);

our $VERSION = 1.00;
our @ISA     = qw(Exporter);
our @EXPORT  = qw(NetSNMPGetOpts AddCommonParams find_files Check_Version
                  floatize_version);
our $basedir;

BEGIN {
    $basedir = abs_path($0);
    while (1) {
	my $basename = basename($basedir);
	last if (length($basename) <= 2);
	$basedir = dirname($basedir);
	last if ($basename eq "perl");
    }
    if ($Config{'osname'} eq 'MSWin32' && $basedir =~ / /) {
        die "\nA space has been detected in the base directory.  This is not " .
            "supported\nPlease rename the folder and try again.\n\n";
    }
}

sub NetSNMPGetOpts {
    my %ret;
    my $rootpath = $basedir;

    if ($ENV{'NET-SNMP-CONFIG'} && $ENV{'NET-SNMP-IN-SOURCE'}) {
	# have env vars, pull from there
	$ret{'nsconfig'} = $ENV{'NET-SNMP-CONFIG'};
	$ret{'insource'} = $ENV{'NET-SNMP-IN-SOURCE'};
	$ret{'define'}   = $ENV{'NET-SNMP-DEFINE'};
	$ret{'inc'}      = $ENV{'NET-SNMP-INC'};
	$ret{'cflags'}   = $ENV{'NET-SNMP-CFLAGS'};
	# $ret{'prefix'} is not used on Windows.
    } else {
	# don't have env vars, pull from command line and put there
	GetOptions("NET-SNMP-CONFIG=s"    => \$ret{'nsconfig'},
	           "NET-SNMP-IN-SOURCE=s" => \$ret{'insource'},
		   "NET-SNMP-DEFINE=s"    => \$ret{'define'},
		   "NET-SNMP-INC=s"       => \$ret{'inc'},
		   "NET-SNMP-CFLAGS=s"    => \$ret{'cflags'},
		   "NET-SNMP-PATH=s"      => \$ret{'prefix'});

	my $use_default_nsconfig;

	if ($ret{'insource'}) {
	    if (lc($ret{'insource'}) eq "true" && !defined($ret{'nsconfig'})) {
		$use_default_nsconfig = 1;
	    }
	}

	if ($use_default_nsconfig) {
	    $ret{'nsconfig'}="sh " . File::Spec->catfile(${rootpath}, "..",
							 "net-snmp-config");
	} elsif (!defined($ret{'nsconfig'})) {
	    $ret{'nsconfig'}="net-snmp-config";
	}

	$ENV{'NET-SNMP-CONFIG'}    = $ret{'nsconfig'};
	$ENV{'NET-SNMP-IN-SOURCE'} = $ret{'insource'};
	$ENV{'NET-SNMP-DEFINE'}    = $ret{'define'};
	$ENV{'NET-SNMP-INC'}       = $ret{'inc'};
	$ENV{'NET-SNMP-CFLAGS'}    = $ret{'cflags'};
	$ENV{'NET-SNMP-PATH'}      = $ret{'prefix'};
    }
    
    $ret{'rootpath'} = $rootpath;
    $ret{'debug'} = 'false';

    \%ret;
}

sub append {
    if ($_[0] && $_[1]) {
	$_[0] = $_[0] . " " . $_[1];
    } elsif ($_[1]) {
	$_[0] = $_[1];
    }
}

sub AddCommonParams {
    my $Params = shift;
    my $opts = NetSNMPGetOpts();

    append($Params->{'DEFINE'},  $opts->{'define'});
    append($Params->{'INC'},     $opts->{'inc'});
    append($Params->{'CCFLAGS'}, $opts->{'cflags'});

    if ($Config{'osname'} eq 'MSWin32') {
	# Microsoft Visual Studio.
	append($Params->{'DEFINE'}, "-DMSVC_PERL -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS");
	append($Params->{'INC'},
	       "-I" . File::Spec->catdir($basedir, "include") . " " .
	       "-I" . File::Spec->catdir($basedir, "win32") . " ");
    } else {
	# Unix or MinGW.
	append($Params->{'LDDLFLAGS'}, $Config{'lddlflags'});
	my $ldflags = `$opts->{'nsconfig'} --ldflags` or
	    die "net-snmp-config failed\n";
	chomp($ldflags);
	append($Params->{'LDDLFLAGS'}, $ldflags);
	append($Params->{'CCFLAGS'},
	       "-I" . File::Spec->catdir($basedir, "include"));
	my $cflags = `$opts->{'nsconfig'} --cflags` or
	    die "net-snmp-config failed\n";
	chomp($cflags);
	# Remove -Wimplicit-fallthrough since it is not supported by older
	# versions of gcc.
	$cflags =~ s/-Wimplicit-fallthrough=[0-9]//g;
	append($Params->{'CCFLAGS'}, $cflags);
	append($Params->{'CCFLAGS'}, $Config{'ccflags'});
	# Suppress known Perl header shortcomings.
	$Params->{'CCFLAGS'} =~ s/ -W(cast-qual|write-strings)//g;
	append($Params->{'CCFLAGS'}, '-Wformat');
    }
}

sub find_files {
    my($f,$d) = @_;
    my ($dir,$found,$file);
    for $dir (@$d){
	$found = 0;
	for $file (@$f) {
	    $found++ if -f "$dir/$file";
	}
	if ($found == @$f) {
	    return $dir;
	}
    }
}


sub Check_Version {
  my $lib_version = shift;

  if ($Config{'osname'} ne 'MSWin32') {
    my $foundversion = 0;
    return if ($ENV{'NETSNMP_DONT_CHECK_VERSION'});
    open(I,"<Makefile");
    while (<I>) {
	if (/^VERSION = (.*)/) {
	    my $perlver = $1;
	    my $srcver = $lib_version;
	    chomp($srcver);
	    my $srcfloat = floatize_version($srcver);
	    $perlver =~ s/pre/0./;
	    # we allow for perl/CPAN-only revisions beyond the default
	    # version formatting of net-snmp itself.
	    $perlver =~ s/(\.\d{5}).*/$1/;
	    $perlver =~ s/0*$//;
	    if ($srcfloat ne $perlver) {
		if (!$foundversion) {
		    print STDERR "ERROR:
Net-SNMP installed version: $srcver => $srcfloat
Perl Module Version:        $perlver

These versions must match for perfect support of the module.  It is possible
that different versions may work together, but it is strongly recommended
that you make these two versions identical.  You can get the Net-SNMP
source code and the associated perl modules directly from

   http://www.net-snmp.org/

If you want to continue anyway please set the NETSNMP_DONT_CHECK_VERSION
environmental variable to 1 and re-run the Makefile.PL script.\n";
		    exit(1);
		}
	    }
	    $foundversion = 1;
	    last;
	}
    }
    close(I);
    die "ERROR: Couldn't find version number of this module\n"
      if (!$foundversion);
  }
}

sub floatize_version {
    my ($major, $minor, $patch, $opps) = ($_[0] =~ /^(\d+)\.(\d+)\.?(\d*)\.?(\d*)/);
    if (!$patch) {
        $patch = 0;
    }
    if (!$opps) {
        $opps = 0;
    }
    return $major + $minor/100 + $patch/10000 + $opps/100000;
}

1;