File: build.pl

package info (click to toggle)
net-snmp 5.9.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 37,540 kB
  • sloc: ansic: 282,201; perl: 17,710; sh: 12,006; makefile: 2,712; python: 735; xml: 663; pascal: 62; sql: 47
file content (256 lines) | stat: -rw-r--r-- 9,574 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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#!/usr/bin/perl
#
# Build script for Net-SNMP and MSVC
# Written by Alex Burger - alex_b@users.sourceforge.net
# March 12th, 2004
#
use strict;
use warnings;
use Config;
use Cwd 'abs_path';
use File::Basename;
use constant false => 0;
use constant true => 1;
my $target_arch = $ENV{TARGET_CPU} ? $ENV{TARGET_CPU} : $ENV{Platform} ?
                  $ENV{Platform} : "x86";
$target_arch = lc $target_arch;
if ($target_arch ne "x86" && $target_arch ne "x64") {
    print "Error: unsupported target architecture $target_arch\n";
    die;
}
my @perl_arch = split(/-/, $Config{archname});
my $openssl = false;
my $default_openssldir = $target_arch eq "x64" ?
    "C:\\Progra~1\\OpenSSL-Win64" : "C:\\Progra~1\\OpenSSL-Win32";
my $default_opensslincdir = $default_openssldir . "\\include";
my $opensslincdir = $default_opensslincdir;
my $default_openssllibdir = $default_openssldir . "\\lib\\VC";
my $openssllibdir = $default_openssllibdir;
my $b_ipv6 = false;
my $b_winextdll = false;
my $sdk = true;
my $default_install_base = "c:/usr";
my $install_base = $default_install_base;
my $install = true;
my $install_devel = false;
my $perl = false;
my $perl_install = false;
my $logging = true;
my $debug = false;
my $configOpts;
my $link_dynamic = false;
my $option;

# Path of this script (source tree path + "win32").
my $current_pwd = dirname(abs_path($0));

if (!defined($ENV{MSVCDir}) && !defined($ENV{VCINSTALLDIR}) &&
    !defined($ENV{TARGET_CPU})) {
  print "\nPlease run VCVARS32.BAT first to set up the Visual Studio build\n" .
        "environment.\n\n";
  system("pause");
  exit;
}

while (1) {
  print "\n\nNet-SNMP build and install options\n";
  print "==================================\n\n";
  print "1.  OpenSSL support:                " . ($openssl ? "enabled" : "disabled"). "\n";
  print "2.  OpenSSL include directory:      " . $opensslincdir. "\n";
  print "3.  OpenSSL library director:       " . $openssllibdir. "\n";
  print "\n";
  print "4.  Install path:                   " . $install_base . "\n";
  print "5.  Install after build:            " . ($install ? "enabled" : "disabled") . "\n";
  print "\n";
  print "6.  Perl modules:                   " . ($perl ? "enabled" : "disabled") . "\n";
  print "7.  Install perl modules:           " . ($perl_install ? "enabled" : "disabled") . "\n";
  print "\n";
  print "8.  Quiet build (logged):           " . ($logging ? "enabled" : "disabled") . "\n";
  print "9.  Debug mode:                     " . ($debug ? "enabled" : "disabled") . "\n";
  print "\n";
  print "10. IPv6 transports:                " . ($b_ipv6 ? "enabled" : "disabled") . "\n";
  print "11. winExtDLL agent:                " . ($b_winextdll ? "enabled" : "disabled") . "\n";
  print "\n";
  print "12. Link type:                      " . ($link_dynamic ? "dynamic" : "static") . "\n";
  print "\n";
  print "13. Install development files       " . ($install_devel ? "enabled" : "disabled") . "\n";
  print "\nF.  Finished - start build\n";
  print "Q.  Quit - abort build\n\n";
  print "Select option to set / toggle: ";

  chomp ($option = <>);
  if ($option eq "1") {
    $openssl = !$openssl;
  }
  elsif ($option eq "2") {
    print "Please enter the OpenSSL include directory [$opensslincdir]: ";
    chomp ($opensslincdir = <>);
    $opensslincdir =~ s/\\/\//g;
    $opensslincdir = $default_opensslincdir if ($opensslincdir eq "");
  }
  elsif ($option eq "3") {
    print "Please enter the OpenSSL library directory [$openssllibdir]: ";
    chomp ($openssllibdir = <>);
    $openssllibdir =~ s/\\/\//g;
    $openssllibdir = $default_openssllibdir if ($openssllibdir eq "");
  }
  elsif ($option eq "10") {
    $b_ipv6 = !$b_ipv6;
    if ($b_ipv6 && !$sdk) {
      print "\n\n* SDK required for IPv6 and has been automatically enabled";
      $sdk = true;
    }
  }
  elsif ($option eq "11") {
    $b_winextdll = !$b_winextdll;
    if ($b_winextdll && !$sdk) {
      print "\n\n* SDK required for IPv6 and has been automatically enabled";
      $sdk = true;
    }
  }
  elsif ($option eq "4") {
    print "Please enter the new install path [$default_install_base]: ";
    chomp ($install_base = <>);
    $install_base =~ s/\\/\//g;
    $install_base = $default_install_base if ($install_base eq "");
  }
  elsif ($option eq "5") {
    $install = !$install;
  }
  elsif ($option eq "13") {
    $install_devel = !$install_devel;
  }
  elsif ($option eq "6") {
    $perl = !$perl;
  }
  elsif ($option eq "7") {
    $perl_install = !$perl_install;
  }
  elsif ($option eq "8") {
    $logging = !$logging;
  }
  elsif ($option eq "9") {
    $debug = !$debug;
  }
  elsif ($option eq "12") {
    $link_dynamic = !$link_dynamic;
  }
  elsif (lc($option) eq "f") {
    last;
  }
  elsif (lc($option) eq "q") {
    exit;
  }
}

if ($perl && $perl_arch[1] ne $target_arch) {
    print "perl_arch = $perl_arch[1] does not match target_arch = $target_arch\n";
    die;
}

my $linktype = $link_dynamic ? "dynamic" : "static";
$configOpts = (($openssl ? "--with-ssl --enable-blumenthal-aes" : "")	 . " " .
               ($opensslincdir ? "--with-sslincdir=$opensslincdir" : "") . " " .
               ($openssllibdir ? "--with-ssllibdir=$openssllibdir" : "") . " " .
               ($sdk ? "--with-sdk" : "")		. " " .
               ($b_ipv6 ? "--with-ipv6" : "")		. " " .
               ($b_winextdll ? "--with-winextdll" : "") . " " .
               ($debug ? "--config=debug" : "--config=release"));

# Set environment variables

# Set to not search for non-existent ".dep" files
$ENV{NO_EXTERNAL_DEPS}="1";

# Set PATH environment variable so Perl make tests can locate the DLL
$ENV{PATH} = File::Spec->catdir($current_pwd, "bin", $debug ? "debug" : "release") . ";$ENV{PATH}";

# Set MIBDIRS environment variable so Perl make tests can locate the mibs
$ENV{MIBDIRS} = File::Spec->catdir(dirname($current_pwd), "mibs");

# Set SNMPCONFPATH environment variable so Perl conf.t test can locate
# the configuration files.
# See the note about environment variables in the Win32 section of
# perl/SNMP/README for details on why this is needed.
$ENV{SNMPCONFPATH}="t";

print "\nBuilding...\n";

print "\nCreating *.out log files.\n\n";

print "Deleting old log files...\n";
system("del *.out" . ($logging ? " > NUL: 2>&1" : ""));

# Delete net-snmp-config.h from main include folder just in case it was created by a Cygwin or MinGW build
unlink "../include/net-snmp/net-snmp-config.h";
unlink "../snmplib/transports/snmp_transport_inits.h";

print "Running Configure...\n";
system("perl Configure $configOpts --linktype=$linktype --prefix=\"$install_base\"" . ($logging ? " > configure.out 2>&1" : "")) == 0 || die ($logging ? "Build error (see configure.out)" : "Build error (see above)");

print "Cleaning...\n";
system("nmake /nologo clean" . ($logging ? " > clean.out 2>&1" : "")) == 0 || die ($logging ? "Build error (see clean.out)" : "Build error (see above)");

print "Building main package...\n";
system("nmake /nologo" . ($logging ? " > make.out 2>&1" : "")) == 0 || die ($logging ? "Build error (see make.out)" : "Build error (see above)");

if ($perl) {
  if ($Config{'ccname'} =~ /^gcc/) {
    die "The perl interpreter has been built with gcc instead of MSVC. Giving up.\n";
  }
  if (!$link_dynamic) {
    print "Running Configure for DLL...\n";
    system("perl Configure $configOpts --linktype=dynamic --prefix=\"$install_base\"" . ($logging ? " > perlconfigure.out 2>&1" : "")) == 0 || die ($logging ? "Build error (see perlconfigure.out)" : "Build error (see above)");

    print "Cleaning libraries...\n";
    system("nmake /nologo libs_clean" . ($logging ? " >> clean.out 2>&1" : "")) == 0 || die ($logging ? "Build error (see clean.out)" : "Build error (see above)");

    print "Building DLL libraries...\n";
    system("nmake /nologo libs" . ($logging ? " > dll.out 2>&1" : "")) == 0 || die ($logging ? "Build error (see dll.out)" : "Build error (see above)");
  }

  print "Cleaning Perl....\n";
  system("nmake /nologo perl_clean" . ($logging ? " >> clean.out 2>&1" : "")); # If already cleaned, Makefile is gone so don't worry about errors!

  print "Building Perl modules...\n";
  system("nmake /nologo perl" . ($logging ? " > perlmake.out 2>&1" : "")) == 0 || die ($logging ? "Build error (see perlmake.out)" : "Build error (see above)");

  print "Testing Perl modules...\n";
  system("nmake /nologo perl_test" . ($logging ? " > perltest.out 2>&1" : "")); # Don't die if all the tests don't pass..

  if ($perl_install) {
    print "Installing Perl modules...\n";
    system("nmake /nologo perl_install" . ($logging ? " > perlinstall.out 2>&1" : "")) == 0 || die ($logging ? "Build error (see perlinstall.out)" : "Build error (see above)");
  }

  print "\nSee perltest.out for Perl test results\n";
}

print "\n";
if ($install) {
  print "Installing main package...\n";
  system("nmake /nologo install" . ($logging ? " > install.out 2>&1" : "")) == 0 || die ($logging ? "Build error (see install.out)" : "Build error (see above)");
}
else {
  print "Type nmake install to install the package to $install_base\n";
}

if ($install_devel) {
  print "Installing development files...\n";
  system("nmake /nologo install_devel > install_devel.out 2>&1") == 0 || die "Build error (see install_devel.out)";
}
else {
  print "Type nmake install_devel to install the development files to $install_base\n";
}

if ($perl && !$perl_install) {
  print "Type nmake perl_install to install the Perl modules\n";
}

print "\nDone!\n";

# Local Variables:
# mode: perl
# perl-indent-level: 2
# indent-tabs-mode: nil
# End: