summaryrefslogtreecommitdiff
path: root/win32/Configure
blob: f3286bb4a0af1c5ba20d2a9755cc19faed5bef9f (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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
#!/usr/bin/perl
# 
# Configure script for Net-SNMP and MSVC
# Written by Alex Burger
# March 5th, 2004
#
use Getopt::Long;
use strict;

my $version = "unknown";
my $config;
my $sdk = 0;
my $linktype;
my $prefix;
my $prefixdos;
my $openssl = 0;
my $b_ipv6 = 0;
my $b_winextdll = 0;
my $help = 0;

GetOptions      ('config=s' => \$config,
                 'with-sdk' => \$sdk,
                 'linktype=s' => \$linktype,
                 'destdir=s' => \$prefix,
                 'prefix=s' => \$prefix,
                 'with-ssl' => \$openssl,
                 'with-ipv6' => \$b_ipv6,
                 'with-winextdll' => \$b_winextdll,
                 'help' => \$help);

if ($help == 1)
{
my $USAGE = qq/
Usage:
    perl Configure [<options>] 
    
Options:

    --config=[release | debug]       Compile as release or with debug symbols
    --with-sdk                       Link against MS Platform SDK
    --linktype=[static | dynamic]    Build static or dynamic (DLL)
    --prefix=\"path\"                  Set INSTALL_BASE path (install path)
    --destdir=\"path\"                 Same as --prefix
    --with-ssl                       Link against OpenSSL
    --with-ipv6                      Build in IPv6 transports (enables SDK)
    --with-winextdll                 Build winExtDLL agent (enables SDK, see README.win32)
    --help                           This help screen
/;

  print $USAGE;

  exit(0);

}
               
$config = lc($config);  
if (($config ne "debug") && ($config ne "release")) {
  $config = "release";
}

$linktype = lc($linktype);              
if (($linktype ne "static") && ($linktype ne "dynamic")) {
  $linktype = "static";
}

if ($prefix eq "") {
  $prefix = "c:/usr";
}

# Make sure prefix only contains forward slashes
$prefix =~ s/\\/\//g;

$prefixdos = "\"$prefix\"";
# Make sure prefixdos only contains backward slashes
$prefixdos =~ s/\//\\/g;

# Enable SDK for IPV6 and winExtDLL
if ($b_ipv6 == 1) {
  $sdk = 1;
}
if ($b_winextdll == 1) {
  $sdk = 1;
}

print "\n\n";

###############################################
#
# Determine version from unix configure script
#
###############################################
  
my $unix_configure_in = "../configure";

open (UNIX_CONFIGURE_IN, "<$unix_configure_in") || die "Can't Open $unix_configure_in\n";

while (<UNIX_CONFIGURE_IN>)
{
  chomp;
  /PACKAGE_VERSION='(.*)'/;
  if ($1 ne "") {
    $version = $1;
    last;
  }
}

###############################################
#
# Create main Makefile
#
###############################################
{  
  my $makefile_out = "Makefile";
  my $makefile_in  = "Makefile.in";

  open (MAKE_OUT, ">$makefile_out") || die "Can't Open $makefile_out\n";
  open (MAKE_IN, "<$makefile_in") || die "Can't Open $makefile_in\n";

  print "creating $makefile_out\n";
  
  while (<MAKE_IN>)
  {
    chomp;
    if ($sdk == 1) {
      s/^SDK=/SDK=true/;
    }
    else {
      s/^SDK=/SDK=false/;
    }
    
    s/^LINKTYPE=/LINKTYPE=$linktype/;
    s/^CFG=/CFG=$config/;
    s/^PREFIX=/PREFIX=$prefix/;    
    s/^PREFIX_DOS=/PREFIX_DOS=$prefixdos/;    
    s/^SSL=.*/SSL=$openssl/;

    print MAKE_OUT $_ . "\n";
  }
}

###############################################
#
# Create Makefiles for applications from 
# Makefile-apps.in
# (except for snmpnetstat)
#
###############################################
my @programs = qw 
/encode_keychange
snmpbulkget
snmpbulkwalk
snmpdelta
snmpdf
snmpget
snmpgetnext
snmpset
snmpstatus
snmptable
snmptest
snmptranslate
snmptrap
snmpusm
snmpvacm
snmpwalk
/;

foreach my $progName (@programs) {
  
  my $makefile_out = "$progName\\Makefile";
  my $makefile_in = "Makefile-apps.in";

  my $outdir = $config;
  my $intdir = $config;
  
  open (MAKE_OUT, ">$makefile_out") || die "Can't Open $makefile_out\n";
  open (MAKE_IN, "<$makefile_in") || die "Can't Open $makefile_in\n";

  print "creating $makefile_out\n";
  
  while (<MAKE_IN>)
  {
    chomp;
    
    s/^LINKTYPE=/LINKTYPE=$linktype/;
    s/^PROGNAME=/PROGNAME=$progName/;
    s/^CFG=/CFG=$config/;
    s/^OUTDIR=/OUTDIR=.\\$outdir/;
    s/^INTDIR=/INTDIR=.\\$intdir/;
    s/^SSL=.*/SSL=$openssl/;

    print MAKE_OUT $_ . "\n";
  }
}

###############################################
#
# Create Makefiles for snmpnetstat from
# snmpnetstat\Makefile.in
#
###############################################
my @programs = qw 
/snmpnetstat
/;

foreach my $progName (@programs) {
  
  my $makefile_out = "$progName\\Makefile";
  my $makefile_in = "$progName\\Makefile.in";

  my $outdir = $config;
  my $intdir = $config;
  
  open (MAKE_OUT, ">$makefile_out") || die "Can't Open $makefile_out\n";
  open (MAKE_IN, "<$makefile_in") || die "Can't Open $makefile_in\n";

  print "creating $makefile_out\n";
  
  while (<MAKE_IN>)
  {
    chomp;

    s/^LINKTYPE=/LINKTYPE=$linktype/;    
    s/^PROGNAME=/PROGNAME=$progName/;
    s/^CFG=/CFG=$config/;
    s/^OUTDIR=/OUTDIR=.\\$outdir/;
    s/^INTDIR=/INTDIR=.\\$intdir/;
    s/^SSL=.*/SSL=$openssl/;

    print MAKE_OUT $_ . "\n";
  }
}


###############################################
#
# Create Makefiles for libraries  
# from name\Makefile.in
#
###############################################
my @programs = qw 
/libagent
libnetsnmptrapd
netsnmpmibs
/;

if ($linktype eq "dynamic") {
  push (@programs, "libsnmp_dll");
}
else {
  push (@programs, "libsnmp");
}

foreach my $progName (@programs) {
  
  my $makefile_out = "$progName\\Makefile";
  my $makefile_in = "$progName\\Makefile.in";
  
  my $outdir = $config;
  my $intdir = $config;
  
  open (MAKE_OUT, ">$makefile_out") || die "Can't Open $makefile_out\n";
  open (MAKE_IN, "<$makefile_in") || die "Can't Open $makefile_in\n";

  print "creating $makefile_out\n";
  
  while (<MAKE_IN>)
  {
    chomp;
    
    if ($sdk == 1) {
      s/^SDK=/SDK=true/;
    }
    else {
      s/^SDK=/SDK=false/;
    }

    s/^PROGNAME=/PROGNAME=$progName/;
    s/^CFG=/CFG=$config/;
    s/^OUTDIR=/OUTDIR=.\\$outdir/;
    s/^INTDIR=/INTDIR=.\\$intdir/;
    s/^SSL=.*/SSL=$openssl/;
    print MAKE_OUT $_ . "\n";
  }
}

###############################################
#
# Create Makefiles for daemons
# from name\Makefile.in
#
###############################################
my @programs = qw 
/snmpd
snmptrapd
/;

foreach my $progName (@programs) {
  
  my $makefile_out = "$progName\\Makefile";
  my $makefile_in = "$progName\\Makefile.in";
  
  my $outdir = $config;
  my $intdir = $config;
  
  open (MAKE_OUT, ">$makefile_out") || die "Can't Open $makefile_out\n";
  open (MAKE_IN, "<$makefile_in") || die "Can't Open $makefile_in\n";

  print "creating $makefile_out\n";
  
  while (<MAKE_IN>)
  {
    chomp;
    
    if ($sdk == 1) {
      s/^SDK=/SDK=true/;
    }
    else {
      s/^SDK=/SDK=false/;
    }

    s/^LINKTYPE=/LINKTYPE=$linktype/;
    s/^PROGNAME=/PROGNAME=$progName/;
    s/^CFG=/CFG=$config/;
    s/^OUTDIR=/OUTDIR=.\\$outdir/;
    s/^INTDIR=/INTDIR=.\\$intdir/;
    s/^SSL=.*/SSL=$openssl/;

    print MAKE_OUT $_ . "\n";
  }
}

###############################################
#
# Create Makefile for Perl scripts in local
# from local\Makefile.in
#
###############################################
  
my $makefile_out = "local\\Makefile";
my $makefile_in = "local\\Makefile.in";

my $outdir = $config;

open (MAKE_OUT, ">$makefile_out") || die "Can't Open $makefile_out\n";
open (MAKE_IN, "<$makefile_in") || die "Can't Open $makefile_in\n";

print "creating $makefile_out\n";

while (<MAKE_IN>)
{
  chomp;
  
  s/^OUTDIR=/OUTDIR=.\\$outdir/;
  s/^PREFIX=/PREFIX=$prefix/;   
  s/^PREFIX_DOS=/PREFIX_DOS=$prefixdos/;    
  
  print MAKE_OUT $_ . "\n";
}


###############################################
#
# Create net-snmp-config.h
#
###############################################
{
  my $file_out = "net-snmp\\net-snmp-config.h";
  my $file_in = "net-snmp\\net-snmp-config.h.in";

  open (FILE_OUT, ">$file_out") || die "Can't Open $file_out\n";
  open (FILE_IN, "<$file_in") || die "Can't Open $file_in\n";
  
  print "creating $file_out\n";

  while (<FILE_IN>)
  {
    chomp;
    s/^#define PACKAGE_VERSION.*/#define PACKAGE_VERSION \"$version\"/;
    if ($prefix ne "") {
      s/^#define INSTALL_BASE.*/#define INSTALL_BASE \"$prefix\"/;
    }
    if ($linktype eq "dynamic") {
      s/^.*#undef NETSNMP_USE_DLL.*/#define NETSNMP_USE_DLL 1/;
    }
    if ($sdk == 1) {
      s/^.*#undef HAVE_WIN32_PLATFORM_SDK.*/#define HAVE_WIN32_PLATFORM_SDK 1/;
    }
    if ($openssl == 1) {
      s/^.*#undef NETSNMP_USE_OPENSSL.*/#define NETSNMP_USE_OPENSSL 1/;
    }
    if ($b_ipv6 == 1) {
      s/^.*#undef NETSNMP_ENABLE_IPV6.*/#define NETSNMP_ENABLE_IPV6 1/;
    }
    if ($b_winextdll == 1) {
      s/^.*#undef USING_WINEXTDLL_MODULE.*/#define USING_WINEXTDLL_MODULE 1/;
    }

    print FILE_OUT $_ . "\n";
  }
}


print qq/
---------------------------------------------------------
            Net-SNMP configuration summary:
---------------------------------------------------------

/;

if ($version eq "unknown") {
  $version = "unknown - Could not determine version from ../configure!";
}

print "  Version:                    $version\n";
print "  Config type:                $config\n";
print "  SDK:                        " . ($sdk == 1 ? "enabled" : "disabled") . "\n";
print "  Link type:                  $linktype\n";
print "  Prefix / Destdir:           " . ($prefix ne "" ? $prefix : "(default)") . "\n";
print "  OpenSSL:                    " . ($openssl == 1 ? "enabled" : "disabled") . "\n";
print "  IPv6 transport:             " . ($b_ipv6 == 1 ? "enabled" : "disabled") . "\n";
print "  winExtDLL agent:            " . ($b_winextdll == 1 ? "enabled" : "disabled") . "\n";

if ($ENV{INCLUDE} eq "") {
  print "\n\nVisual Studio environment not detected.  Please run VCVARS32.BAT before\n";
  print "running nmake\n\n";
}