Debian Codegraph @

win32/Configure

raw
1 #!/usr/bin/perl
2 #
3 # Configure script for Net-SNMP and MSVC
4 # Written by Alex Burger
5 # March 5th, 2004
6 #
7 use strict;
8 use warnings;
9 use ExtUtils::Embed;
10 use Getopt::Long;
11
12 my $version = "unknown";
13 my $config;
14 my $sdk = 0;
15 my $linktype;
16 my $blumenthal_aes;
17 my $prefix;
18 my $prefixdos;
19 my $openssl = 0;
20 my $opensslincdir;
21 my $openssllibdir;
22 my $b_ipv6 = 0;
23 my $b_winextdll = 0;
24 my $help = 0;
25
26 GetOptions ('config=s' => \$config,
27 'with-sdk' => \$sdk,
28 'linktype=s' => \$linktype,
29 'destdir=s' => \$prefix,
30 'enable-blumenthal-aes' => \$blumenthal_aes,
31 'prefix=s' => \$prefix,
32 'with-ssl' => \$openssl,
33 'with-sslincdir=s' => \$opensslincdir,
34 'with-ssllibdir=s' => \$openssllibdir,
35 'with-ipv6' => \$b_ipv6,
36 'with-winextdll' => \$b_winextdll,
37 'help' => \$help);
38
39 if ($help == 1 || !defined($config) || !defined($linktype) ||
40 !defined($b_ipv6) || !defined($b_winextdll)) {
41 my $USAGE = qq/
42 Usage:
43 perl Configure [<options>]
44
45 Options:
46
47 --config=[release | debug] Compile as release or with debug symbols
48 --with-sdk Link against MS Platform SDK
49 --linktype=[static | dynamic] Build static or dynamic (DLL)
50 --prefix=\"path\" Set INSTALL_BASE path (install path)
51 --destdir=\"path\" Same as --prefix
52 --enable-blumenthal-aes Enable Blumenthal AES support
53 --with-ssl Link against OpenSSL
54 --with-sslincdir=\"path\" OpenSSL include path
55 --with-ssllibdir=\"path\" OpenSSL library path
56 --with-ipv6 Build in IPv6 transports (enables SDK)
57 --with-winextdll Build winExtDLL agent (enables SDK, see README.win32)
58 --help This help screen
59 /;
60
61 print $USAGE;
62
63 exit(0);
64
65 }
66
67 $config = lc($config);
68 if (($config ne "debug") && ($config ne "release")) {
69 $config = "release";
70 }
71
72 $linktype = lc($linktype);
73 if (($linktype ne "static") && ($linktype ne "dynamic")) {
74 $linktype = "static";
75 }
76
77 if (!$prefix) {
78 $prefix = "c:/usr";
79 }
80
81 # Make sure prefix only contains forward slashes
82 $prefix =~ s/\\/\//g;
83
84 $prefixdos = "\"$prefix\"";
85 # Make sure prefixdos only contains backward slashes
86 $prefixdos =~ s/\//\\/g;
87
88 # Enable SDK for IPV6 and winExtDLL
89 if ($b_ipv6 == 1) {
90 $sdk = 1;
91 }
92 if ($b_winextdll == 1) {
93 $sdk = 1;
94 }
95
96 print "\n\n";
97
98 ###############################################
99 #
100 # Determine version from unix configure script
101 #
102 ###############################################
103
104 my $unix_configure_in = "../configure";
105
106 open (UNIX_CONFIGURE_IN, "<$unix_configure_in") || die "Can't Open $unix_configure_in\n";
107
108 while (<UNIX_CONFIGURE_IN>)
109 {
110 chomp;
111 if (/PACKAGE_VERSION='(.*)'/) {
112 $version = $1;
113 last;
114 }
115 }
116
117 # Arguments:
118 # $1: Name of output file
119 # $2: Name of input file
120 # $3: Reference to a hash with substitutions. A substitution is an array with
121 # two elements where element [0] is the pattern to search for and element
122 # [1] the replacement text.
123 sub substitute
124 {
125 my $out = shift;
126 my $in = shift;
127 my $subs = shift;
128
129 open (OUT, ">$out") || die "Can't open $out\n";
130 open (IN, "<$in") || die "Can't open $in\n";
131
132 print "creating $out\n";
133
134 while (<IN>) {
135 chomp;
136 foreach my $e (keys %$subs) {
137 my $p = $$subs{$e}[0];
138 my $q = $$subs{$e}[1];
139 s/$p/$q/;
140 }
141 print OUT $_ . "\n";
142 }
143
144 close IN;
145 close OUT;
146 }
147
148 ###############################################
149 #
150 # Perform substitutions
151 #
152 ###############################################
153
154 my @programs = qw
155 /
156 encode_keychange
157 snmpbulkget
158 snmpbulkwalk
159 snmpdelta
160 snmpdf
161 snmpget
162 snmpgetnext
163 snmpset
164 snmpstatus
165 snmptable
166 snmptest
167 snmptranslate
168 snmptrap
169 snmpusm
170 snmpvacm
171 snmpwalk
172 /;
173
174 my @apps=sort("snmpnetstat", @programs);
175 my @apps_clean;
176 foreach my $app (@apps) {
177 push @apps_clean, $app . "_clean";
178 }
179
180 my $perl_define =
181 "/D NETSNMP_REMOVE_U64 " .
182 "/D VC_EXTRALEAN " .
183 "/D WIN32 " .
184 "/D _CONSOLE " .
185 "/D _CRT_NONSTDC_NO_WARNINGS " .
186 "/D _CRT_SECURE_NO_WARNINGS " .
187 "/D _MBCS " .
188 "/D _WIN32_WINNT=0xffff " .
189 "/D _WINSOCK_DEPRECATED_NO_WARNINGS";
190
191 my $perl_inc = $opensslincdir ? "/I $opensslincdir" : "";
192
193 my $perl_cflags = ExtUtils::Embed::ccopts();
194 # Do not use $perl_cflags if these come from a Perl executable built with gcc.
195 $perl_cflags = "" if $perl_cflags =~ / -pipe/;
196
197 my %makefile_subs = (
198 "app" => [ "^APPS=", "APPS=" . join(" ", @apps) ],
199 "apc" => [ "^APPS_CLEAN=", "APPS_CLEAN=" . join(" ", @apps_clean)],
200 "cfg" => [ "^CFG=", "CFG=$config" ],
201 "int" => [ "^INTDIR=", "INTDIR=.\\$config" ],
202 "lnk" => [ "^LINKTYPE=", "LINKTYPE=$linktype" ],
203 "out" => [ "^OUTDIR=", "OUTDIR=.\\$config" ],
204 "pfx" => [ "^PREFIX=", "PREFIX=$prefix" ],
205 "dos" => [ "^PREFIX_DOS=", "PREFIX_DOS=$prefixdos" ],
206 "ssl" => [ "^OPENSSL=", $openssl ? "OPENSSL=true" : "OPENSSL=false" ],
207 "sdk" => [ "^SDK=", $sdk == 1 ? "SDK=true" : "SDK=false" ],
208 "pin" => [ "^PERL_DEFINE=","PERL_DEFINE=$perl_define" ],
209 "pdf" => [ "^PERL_INC=", "PERL_INC=$perl_inc" ],
210 "pcf" => [ "^PERL_CFLAGS=","PERL_CFLAGS=$perl_cflags" ],
211 "cfl" => [ "^CFLAGS=", "CFLAGS=$perl_define " .
212 "/D WIN32_LEAN_AND_MEAN " .
213 "/EHsc " .
214 "/FD " .
215 "/FR\$(INTDIR)\\ " .
216 "/Fd\$(INTDIR)\\\$(PROGNAME).pdb " .
217 "/Fo\$(INTDIR)\\ " .
218 "$perl_inc " .
219 "$perl_cflags " .
220 "/c " .
221 "/W3 " .
222 "/Zi " .
223 "/nologo " .
224 ($config eq "release" ?
225 "/MD /D NDEBUG /O2 " :
226 "/MDd /D _DEBUG /Od /Gm ")
227 ],
228 "lfl" => [ "^LDFLAGS=", "LDFLAGS=" .
229 ($config eq "debug" ? "/debug " : "") .
230 ($openssllibdir ? "/libpath:$openssllibdir" :
231 "") . " " .
232 "/MANIFEST:EMBED"
233 ],
234 "rsc" => [ "^RSCFLAGS=", "RSCFLAGS=/l 0x409 " .
235 ($config eq "release" ? "/d NDEBUG" :
236 "/d _DEBUG")
237 ],
238 );
239
240 substitute("Makefile", "Makefile.in", \%makefile_subs);
241 substitute("local/Makefile", "local/Makefile.in", \%makefile_subs);
242
243 foreach my $progName (@programs) {
244 $makefile_subs{"prg"} = [ "^PROGNAME=", "PROGNAME=$progName" ];
245 substitute("$progName/Makefile", "Makefile-apps.in", \%makefile_subs);
246 }
247
248 foreach my $progName ("libagent", "libnetsnmptrapd", "local",
249 "netsnmpmibs", "snmpd", "snmptrapd", "snmpnetstat",
250 $linktype eq "dynamic" ? "libsnmp_dll" : "libsnmp") {
251 $makefile_subs{"prg"} = [ "^PROGNAME=", "PROGNAME=$progName" ];
252 substitute("$progName/Makefile", "$progName/Makefile.in", \%makefile_subs);
253 }
254
255 my %snmpconf_subs = (
256 "env" => [ "\@ENV_SEPARATOR\@", ";" ]
257 );
258
259 substitute("../local/snmpconf", "../local/snmpconf.in", \%snmpconf_subs);
260
261
262 my %net_snmp_config_subs = (
263 "ver" => [ "^#define PACKAGE_VERSION.*",
264 "#define PACKAGE_VERSION \"$version\"" ]
265 );
266 if ($prefix ne "") {
267 $net_snmp_config_subs{"pfx"} = [ "^#define INSTALL_BASE.*", "#define INSTALL_BASE \"$prefix\"" ];
268 }
269 if ($linktype eq "dynamic") {
270 $net_snmp_config_subs{"dll"} = [ "^.*#undef NETSNMP_USE_DLL.*", "#define NETSNMP_USE_DLL 1" ];
271 }
272 if ($sdk == 1) {
273 $net_snmp_config_subs{"sdk"} = [ "^.*#undef HAVE_WIN32_PLATFORM_SDK.*", "#define HAVE_WIN32_PLATFORM_SDK 1" ];
274 }
275 if ($openssl == 1) {
276 $net_snmp_config_subs{"ssl"} = [ "^.*#undef NETSNMP_USE_OPENSSL.*", "#define NETSNMP_USE_OPENSSL 1" ];
277 } else {
278 $net_snmp_config_subs{"ssl"} = [ "^.*#undef NETSNMP_USE_INTERNAL_MD5.*", "#define NETSNMP_USE_INTERNAL_MD5 1" ];
279 }
280 if ($blumenthal_aes) {
281 $net_snmp_config_subs{"baes"} = [ "^.*#undef NETSNMP_DRAFT_BLUMENTHAL_AES_04.*", "#define NETSNMP_DRAFT_BLUMENTHAL_AES_04 1" ];
282 }
283 if ($b_ipv6 == 1) {
284 $net_snmp_config_subs{"ipv6"} = [ "^.*#undef NETSNMP_ENABLE_IPV6.*", "#define NETSNMP_ENABLE_IPV6 1" ];
285 }
286 if ($b_winextdll == 1) {
287 $net_snmp_config_subs{"winextdll"} = [ "^.*#undef USING_WINEXTDLL_MODULE.*", "#define USING_WINEXTDLL_MODULE 1" ];
288 }
289
290 substitute("net-snmp/net-snmp-config.h", "net-snmp/net-snmp-config.h.in",
291 \%net_snmp_config_subs);
292
293 print qq/
294 ---------------------------------------------------------
295 Net-SNMP configuration summary:
296 ---------------------------------------------------------
297
298 /;
299
300 if ($version eq "unknown") {
301 $version = "unknown - Could not determine version from ../configure!";
302 }
303
304 print " Version: $version\n";
305 print " Config type: $config\n";
306 print " SDK: " . ($sdk == 1 ? "enabled" : "disabled") . "\n";
307 print " Link type: $linktype\n";
308 print " Prefix / Destdir: " . ($prefix ne "" ? $prefix : "(default)") . "\n";
309 print " OpenSSL: " . ($openssl == 1 ? "enabled" : "disabled") . "\n";
310 print " Blumenthal AES: " . ($blumenthal_aes ? "enabled" : "disabled") . "\n";
311 print " IPv6 transport: " . ($b_ipv6 == 1 ? "enabled" : "disabled") . "\n";
312 print " winExtDLL agent: " . ($b_winextdll == 1 ? "enabled" : "disabled") . "\n";
313
314 if ($ENV{INCLUDE} eq "") {
315 print "\n\nVisual Studio environment not detected. Please run VCVARS32.BAT before\n";
316 print "running nmake\n\n";
317 }
318