summaryrefslogtreecommitdiff
path: root/win32/build.pl
blob: 196b779d549dde0048c660b85340badbf8f6a600 (plain)
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
#!/usr/bin/perl
# 
# Build script for Net-SNMP and MSVC
# Written by Alex Burger - alex_b@users.sourceforge.net
# March 12th, 2004
#
use strict;
my $openssl = "disabled";
my $b_ipv6 = "disabled";
my $b_winextdll = "disabled";
my $sdk = "disabled";
my $default_install_base = "c:/usr";
my $install_base = $default_install_base;
my $install = "enabled";
my $install_devel = "disabled";
my $perl = "disabled";
my $perl_install = "disabled";
my $logging = "enabled";
my $debug = "disabled";
my $configOpts = "";
my $cTmp = "";
my $linktype = "static";
my $option;

# Prepend win32\ if running from main directory
my $current_pwd = `%COMSPEC% /c cd`;
chomp $current_pwd;
if (! ($current_pwd =~ /\\win32$/)) {
  chdir ("win32");
  $current_pwd = `%COMSPEC% /c cd`;
  chomp $current_pwd;
}

if ( -d $ENV{MSVCDir} || -d $ENV{VCINSTALLDIR}) {
}
else {
  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. "\n";
  print "2.  Platform SDK support:           " . $sdk . "\n";
  print "\n";
  print "3.  Install path:                   " . $install_base . "\n";
  print "4.  Install after build:            " . $install . "\n";
  print "\n";
  print "5.  Perl modules:                   " . $perl . "\n";
  print "6.  Install perl modules:           " . $perl_install . "\n";
  print "\n";
  print "7.  Quiet build (logged):           " . $logging . "\n";
  print "8.  Debug mode:                     " . $debug . "\n";
  print "\n";
  print "9.  IPv6 transports (requires SDK): " . $b_ipv6 . "\n";
  print "10. winExtDLL agent (requires SDK): " . $b_winextdll . "\n";
  print "\n";
  print "11. Link type:                      " . $linktype . "\n";
  print "\n";
  print "12. Install development files       " . $install_devel . "\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") {
    if ($openssl eq "enabled") {
      $openssl = "disabled";
    }
    else {
      $openssl = "enabled";
    }
  }
  elsif ($option eq "2") {
    if ($sdk eq "enabled") {
      $sdk = "disabled";
    }
    else {
      $sdk = "enabled";
    }
  }
  elsif ($option eq "9") {
    if ($b_ipv6 eq "enabled") {
      $b_ipv6 = "disabled";
    }
    else {
      $b_ipv6 = "enabled";
      if ($sdk = "disabled") {
        print "\n\n* SDK required for IPv6 and has been automatically enabled";
        $sdk = "enabled";
      }
    }
  }
  elsif ($option eq "10") {
    if ($b_winextdll eq "enabled") {
      $b_winextdll = "disabled";
    }
    else {
      $b_winextdll = "enabled";
      if ($sdk = "disabled") {
        print "\n\n* SDK required for IPv6 and has been automatically enabled";
        $sdk = "enabled";
      }
    }
  }
  elsif ($option eq "3") {
    print "Please enter the new install path [$default_install_base]: ";
    chomp ($install_base = <>);
    if ($install_base eq "") {
      $install_base = $default_install_base;
    }
    $install_base =~ s/\\/\//g;
  }
  elsif ($option eq "4") {
    if ($install eq "enabled") {
      $install = "disabled";
    }
    else {
      $install = "enabled";
    }
  }
  elsif ($option eq "12") {
    if ($install_devel eq "enabled") {
      $install_devel = "disabled";
    }
    else {
      $install_devel = "enabled";
    }
  }
  elsif ($option eq "5") {
    if ($perl eq "enabled") {
      $perl = "disabled";
    }
    else {
      $perl = "enabled";
    }
  }
  elsif ($option eq "6") {
    if ($perl_install eq "enabled") {
      $perl_install = "disabled";
    }
    else {
      $perl_install = "enabled";
    }
  }
  elsif ($option eq "7") {
    if ($logging eq "enabled") {
      $logging = "disabled";
    }
    else {
      $logging = "enabled";
    }
  }
  elsif ($option eq "8") {
    if ($debug eq "enabled") {
      $debug = "disabled";
    }
    else {
      $debug = "enabled";
    }
  }
  elsif ($option eq "11") {
    if ($linktype eq "static") {
      $linktype = "dynamic";
    }
    else {
      $linktype = "static";
    }
  }
  elsif (lc($option) eq "f") {
    last;
  }
  elsif (lc($option) eq "q") {
    exit;
  }
}

$cTmp = ($openssl eq "enabled" ? "--with-ssl" : "" );
$configOpts = "$cTmp";
$cTmp = ($sdk eq "enabled" ? "--with-sdk" : "" );
$configOpts = "$configOpts $cTmp";
$cTmp = ($b_ipv6 eq "enabled" ? "--with-ipv6" : "" );
$configOpts = "$configOpts $cTmp";
$cTmp = ($b_winextdll eq "enabled" ? "--with-winextdll" : "" );
$configOpts = "$configOpts $cTmp";
$cTmp = ($debug eq "enabled" ? "--config=debug" : "--config=release" );
$configOpts = "$configOpts $cTmp";

# 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} = "$current_pwd\\bin\\" . ($debug eq "enabled" ? "debug" : "release" ) . ";$ENV{PATH}";

# Set MIBDIRS environment variable so Perl make tests can locate the mibs
my $temp_mibdir = "$current_pwd/../mibs";
$temp_mibdir =~ s/\\/\//g;
$ENV{MIBDIRS}=$temp_mibdir;

# 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";$ENV{SNMPCONFPATH};

print "\nBuilding...\n";

if ($logging eq "enabled") {
  print "\nCreating *.out log files.\n\n";
}

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

  # Delete net-snmp-config.h from main include folder just in case it was created by a Cygwin or MinGW build
  system("del ..\\include\\net-snmp\\net-snmp-config.h > NUL: 2>&1");
  unlink "../snmplib/transports/snmp_transport_inits.h";
  
  print "Running Configure...\n";
  system("perl Configure $configOpts --linktype=$linktype --prefix=\"$install_base\" > configure.out 2>&1") == 0 || die "Build error (see configure.out)";

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

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

  if ($perl eq "enabled") {
    if ($linktype eq "static") {
      print "Running Configure for DLL...\n";
      system("perl Configure $configOpts --linktype=dynamic --prefix=\"$install_base\" > perlconfigure.out 2>&1") == 0 || die "Build error (see perlconfigure.out)";
      
      print "Cleaning libraries...\n";
      system("nmake /nologo libs_clean >> clean.out 2>&1") == 0 || die "Build error (see clean.out)";
      
      print "Building DLL libraries...\n";
      system("nmake /nologo libs > dll.out 2>&1") == 0 || die "Build error (see dll.out)";
    }
   
    print "Cleaning Perl....\n";
    system("nmake /nologo perl_clean >> 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 > perlmake.out 2>&1") == 0 || die "Build error (see perlmake.out)";

    print "Testing Perl modules...\n";
    system("nmake /nologo perl_test > perltest.out 2>&1"); # Don't die if all the tests don't pass..
    
    if ($perl_install eq "enabled") {
      print "Installing Perl modules...\n";
      system("nmake /nologo perl_install > perlinstall.out 2>&1") == 0 || die "Build error (see perlinstall.out)";
    }
      
    print "\nSee perltest.out for Perl test results\n";
  }

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

  if ($install_devel eq "enabled") {
    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_install eq "disabled" && $perl eq "enabled") {
    print "Type nmake perl_install to install the Perl modules\n";
  }
}
else {
  system("del *.out");

  # Delete net-snmp-config.h from main include folder just in case it was created by a Cygwin or MinGW build
  system("del ..\\include\\net-snmp\\net-snmp-config.h > NUL: 2>&1");

  system("perl Configure $configOpts --linktype=$linktype --prefix=\"$install_base\"") == 0 || die "Build error (see above)";
  system("nmake /nologo clean") == 0 || die "Build error (see above)";
  system("nmake /nologo") == 0 || die "Build error (see above)";
  
  if ($perl eq "enabled") {
    if ($linktype eq "static") {      
      system("perl Configure $configOpts --linktype=dynamic --prefix=\"$install_base\"") == 0 || die "Build error (see above)";
      system("nmake /nologo libs_clean") == 0 || die "Build error (see above)";
      system("nmake /nologo libs") == 0 || die "Build error (see above)";
    }
      
    system("nmake /nologo perl_clean"); # If already cleaned, Makefile is gone so don't worry about errors!
    system("nmake /nologo perl") == 0 || die "Build error (see above)";

    my $path_old = $ENV{PATH};
    $ENV{PATH} = "$current_pwd\\bin\\" . ($debug eq "enabled" ? "debug" : "release" ) . ";$ENV{PATH}";
    system("nmake /nologo perl_test"); # Don't die if all the tests don't pass..
    $ENV{PATH} = $path_old;
    
    if ($perl_install eq "enabled") {      
      print "Installing Perl modules...\n";
      system("nmake /nologo perl_install") == 0 || die "Build error (see above)";
    }
  }

  print "\n";
  if ($install eq "enabled") {
    print "Installing main package...\n";
    system("nmake /nologo install") == 0 || die "Build error (see above)";
  }
  else {
    print "Type nmake install to install the package to $install_base\n";
  }

  if ($install_devel eq "enabled") {
    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_install eq "disabled" && $perl eq "enabled") {
    print "Type nmake perl_install to install the Perl modules\n";
  }
}

print "\nDone!\n";