xref: /minix3/external/bsd/bind/dist/win32utils/Configure (revision 00b67f09dd46474d133c95011a48590a8e8f94c7)
1#!/usr/bin/perl
2#
3# Copyright (C) 2013-2015  Internet Systems Consortium, Inc. ("ISC")
4#
5# Permission to use, copy, modify, and/or distribute this software for any
6# purpose with or without fee is hereby granted, provided that the above
7# copyright notice and this permission notice appear in all copies.
8#
9# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11# AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15# PERFORMANCE OF THIS SOFTWARE.
16
17# Configure
18#
19# This script builds nmake and visual studio build files
20#
21
22require 5.000;
23use strict;
24use File::Spec;
25use Cwd;
26
27# files to configure
28
29my $configfilein = "..\\config.h.win32";
30my $configfileout = ">..\\config.h";
31my $platformfile = "..\\lib\\isc\\win32\\include\\isc\\platform.h";
32
33my @filelist = ("..\\bin\\check\\win32\\checktool.dsp",
34                "..\\bin\\check\\win32\\checkconf.dsp",
35                "..\\bin\\check\\win32\\checkconf.mak",
36                "..\\bin\\check\\win32\\checkzone.dsp",
37                "..\\bin\\check\\win32\\checkzone.mak",
38                "..\\bin\\confgen\\win32\\confgentool.dsp",
39                "..\\bin\\confgen\\win32\\ddnsconfgen.dsp",
40                "..\\bin\\confgen\\win32\\ddnsconfgen.mak",
41                "..\\bin\\confgen\\win32\\rndcconfgen.dsp",
42                "..\\bin\\confgen\\win32\\rndcconfgen.mak",
43                "..\\bin\\delv\\win32\\delv.dsp",
44                "..\\bin\\delv\\win32\\delv.mak",
45                "..\\bin\\dig\\win32\\dig.dsp",
46                "..\\bin\\dig\\win32\\dig.mak",
47                "..\\bin\\dig\\win32\\dighost.dsp",
48                "..\\bin\\dig\\win32\\host.dsp",
49                "..\\bin\\dig\\win32\\host.mak",
50                "..\\bin\\dig\\win32\\nslookup.dsp",
51                "..\\bin\\dig\\win32\\nslookup.mak",
52                "..\\bin\\dnssec\\win32\\dnssectool.dsp",
53                "..\\bin\\dnssec\\win32\\dsfromkey.dsp",
54                "..\\bin\\dnssec\\win32\\dsfromkey.mak",
55                "..\\bin\\dnssec\\win32\\importkey.dsp",
56                "..\\bin\\dnssec\\win32\\importkey.mak",
57                "..\\bin\\dnssec\\win32\\keyfromlabel.dsp",
58                "..\\bin\\dnssec\\win32\\keyfromlabel.mak",
59                "..\\bin\\dnssec\\win32\\keygen.dsp",
60                "..\\bin\\dnssec\\win32\\keygen.mak",
61                "..\\bin\\dnssec\\win32\\revoke.dsp",
62                "..\\bin\\dnssec\\win32\\revoke.mak",
63                "..\\bin\\dnssec\\win32\\settime.dsp",
64                "..\\bin\\dnssec\\win32\\settime.mak",
65                "..\\bin\\dnssec\\win32\\signzone.dsp",
66                "..\\bin\\dnssec\\win32\\signzone.mak",
67                "..\\bin\\dnssec\\win32\\verify.dsp",
68                "..\\bin\\dnssec\\win32\\verify.mak",
69                "..\\bin\\named\\win32\\named.dsp",
70                "..\\bin\\named\\win32\\named.mak",
71                "..\\bin\\nsupdate\\win32\\nsupdate.dsp",
72                "..\\bin\\nsupdate\\win32\\nsupdate.mak",
73                "..\\bin\\pkcs11\\win32\\pk11destroy.dsp",
74                "..\\bin\\pkcs11\\win32\\pk11destroy.mak",
75                "..\\bin\\pkcs11\\win32\\pk11keygen.dsp",
76                "..\\bin\\pkcs11\\win32\\pk11keygen.mak",
77                "..\\bin\\pkcs11\\win32\\pk11list.dsp",
78                "..\\bin\\pkcs11\\win32\\pk11list.mak",
79                "..\\bin\\pkcs11\\win32\\pk11tokens.dsp",
80                "..\\bin\\pkcs11\\win32\\pk11tokens.mak",
81                "..\\bin\\python\\dnssec-checkds.py",
82                "..\\bin\\python\\dnssec-coverage.py",
83                "..\\bin\\rndc\\win32\\rndc.dsp",
84                "..\\bin\\rndc\\win32\\rndc.mak",
85                "..\\bin\\rndc\\win32\\rndcutil.dsp",
86                "..\\bin\\tools\\win32\\arpaname.dsp",
87                "..\\bin\\tools\\win32\\arpaname.mak",
88                "..\\bin\\tools\\win32\\genrandom.dsp",
89                "..\\bin\\tools\\win32\\genrandom.mak",
90                "..\\bin\\tools\\win32\\ischmacfixup.dsp",
91                "..\\bin\\tools\\win32\\ischmacfixup.mak",
92                "..\\bin\\tools\\win32\\journalprint.dsp",
93                "..\\bin\\tools\\win32\\journalprint.mak",
94                "..\\bin\\tools\\win32\\nsec3hash.dsp",
95                "..\\bin\\tools\\win32\\nsec3hash.mak",
96                "..\\bin\\tools\\win32\\rrchecker.dsp",
97                "..\\bin\\tools\\win32\\rrchecker.mak",
98                "..\\bin\\tests\\atomic\\win32\\t_atomic.dsp",
99                "..\\bin\\tests\\atomic\\win32\\t_atomic.mak",
100                "..\\bin\\tests\\db\\win32\\t_db.dsp",
101                "..\\bin\\tests\\db\\win32\\t_db.mak",
102                "..\\bin\\tests\\dst\\win32\\t_dst.dsp",
103                "..\\bin\\tests\\dst\\win32\\t_dst.mak",
104                "..\\bin\\tests\\master\\win32\\t_master.dsp",
105                "..\\bin\\tests\\master\\win32\\t_master.mak",
106                "..\\bin\\tests\\mem\\win32\\t_mem.dsp",
107                "..\\bin\\tests\\mem\\win32\\t_mem.mak",
108                "..\\bin\\tests\\hashes\\win32\\t_hashes.dsp",
109                "..\\bin\\tests\\hashes\\win32\\t_hashes.mak",
110                "..\\bin\\tests\\names\\win32\\t_names.dsp",
111                "..\\bin\\tests\\names\\win32\\t_names.mak",
112                "..\\bin\\tests\\rbt\\win32\\t_rbt.dsp",
113                "..\\bin\\tests\\rbt\\win32\\t_rbt.mak",
114                "..\\bin\\tests\\resolver\\win32\\t_resolver.dsp",
115                "..\\bin\\tests\\resolver\\win32\\t_resolver.mak",
116                "..\\bin\\tests\\sockaddr\\win32\\t_sockaddr.dsp",
117                "..\\bin\\tests\\sockaddr\\win32\\t_sockaddr.mak",
118                "..\\bin\\tests\\tasks\\win32\\t_tasks.dsp",
119                "..\\bin\\tests\\tasks\\win32\\t_tasks.mak",
120                "..\\bin\\tests\\timers\\win32\\t_timers.dsp",
121                "..\\bin\\tests\\timers\\win32\\t_timers.mak",
122                "..\\bin\\tests\\win32\\backtrace_test.dsp",
123                "..\\bin\\tests\\win32\\backtrace_test.mak",
124                "..\\bin\\tests\\win32\\inter_test.dsp",
125                "..\\bin\\tests\\win32\\inter_test.mak",
126                "..\\bin\\tests\\win32\\rwlock_test.dsp",
127                "..\\bin\\tests\\win32\\rwlock_test.mak",
128                "..\\bin\\tests\\win32\\shutdown_test.dsp",
129                "..\\bin\\tests\\win32\\shutdown_test.mak",
130                "..\\bin\\tests\\win32\\sock_test.dsp",
131                "..\\bin\\tests\\win32\\sock_test.mak",
132                "..\\bin\\tests\\win32\\task_test.dsp",
133                "..\\bin\\tests\\win32\\task_test.mak",
134                "..\\bin\\tests\\win32\\timer_test.dsp",
135                "..\\bin\\tests\\win32\\timer_test.mak",
136                "..\\bin\\tests\\win32\\inter_test.dsp",
137                "..\\bin\\tests\\win32\\inter_test.mak",
138                "..\\bin\\tests\\win32\\rwlock_test.dsp",
139                "..\\bin\\tests\\win32\\rwlock_test.mak",
140                "..\\bin\\tests\\win32\\shutdown_test.dsp",
141                "..\\bin\\tests\\win32\\shutdown_test.mak",
142                "..\\bin\\tests\\win32\\sock_test.dsp",
143                "..\\bin\\tests\\win32\\sock_test.mak",
144                "..\\bin\\tests\\win32\\task_test.dsp",
145                "..\\bin\\tests\\win32\\task_test.mak",
146                "..\\bin\\tests\\win32\\timer_test.dsp",
147                "..\\bin\\tests\\win32\\timer_test.mak",
148                "..\\bin\\win32\\BINDInstall\\BINDInstall.dsp",
149                "..\\bin\\win32\\BINDInstall\\BINDInstall.mak",
150                "..\\lib\\bind9\\win32\\libbind9.dsp",
151                "..\\lib\\bind9\\win32\\libbind9.mak",
152                "..\\lib\\dns\\win32\\gen.dsp",
153                "..\\lib\\dns\\win32\\gen.mak",
154                "..\\lib\\dns\\win32\\libdns.def",
155                "..\\lib\\dns\\win32\\libdns.dsp",
156                "..\\lib\\dns\\win32\\libdns.mak",
157                "..\\lib\\irs\\win32\\libirs.dsp",
158                "..\\lib\\irs\\win32\\libirs.mak",
159                "..\\lib\\isc\\win32\\libisc.def",
160                "..\\lib\\isc\\win32\\libisc.dsp",
161                "..\\lib\\isc\\win32\\libisc.mak",
162                "..\\lib\\isccc\\win32\\libisccc.dsp",
163                "..\\lib\\isccc\\win32\\libisccc.mak",
164                "..\\lib\\isccfg\\win32\\libisccfg.dsp",
165                "..\\lib\\isccfg\\win32\\libisccfg.mak",
166                "..\\lib\\lwres\\win32\\liblwres.dsp",
167                "..\\lib\\lwres\\win32\\liblwres.mak",
168                "..\\lib\\samples\\win32\\async.dsp",
169                "..\\lib\\samples\\win32\\async.mak",
170                "..\\lib\\samples\\win32\\gai.dsp",
171                "..\\lib\\samples\\win32\\gai.mak",
172                "..\\lib\\samples\\win32\\nsprobe.dsp",
173                "..\\lib\\samples\\win32\\nsprobe.mak",
174                "..\\lib\\samples\\win32\\request.dsp",
175                "..\\lib\\samples\\win32\\request.mak",
176                "..\\lib\\samples\\win32\\resolve.dsp",
177                "..\\lib\\samples\\win32\\resolve.mak",
178                "..\\lib\\samples\\win32\\update.dsp",
179                "..\\lib\\samples\\win32\\update.mak",
180                "..\\lib\\tests\\win32\\libtests.dsp",
181                "..\\lib\\tests\\win32\\libtests.mak",
182                "..\\lib\\win32\\bindevt\\bindevt.dsp",
183                "..\\lib\\win32\\bindevt\\bindevt.mak",
184                "legacy\\BINDBuild.dsw",
185                "legacy\\BuildAll.bat",
186                "legacy\\BuildPost.bat",
187                "legacy\\BuildSetup.bat");
188
189my @projectlist = ("..\\bin\\check\\win32\\checkconf.vcxproj",
190                   "..\\bin\\check\\win32\\checkconf.vcxproj.filters",
191                   "..\\bin\\check\\win32\\checktool.vcxproj",
192                   "..\\bin\\check\\win32\\checktool.vcxproj.filters",
193                   "..\\bin\\check\\win32\\checkzone.vcxproj",
194                   "..\\bin\\check\\win32\\checkzone.vcxproj.filters",
195                   "..\\bin\\confgen\\win32\\confgentool.vcxproj",
196                   "..\\bin\\confgen\\win32\\confgentool.vcxproj.filters",
197                   "..\\bin\\confgen\\win32\\ddnsconfgen.vcxproj",
198                   "..\\bin\\confgen\\win32\\ddnsconfgen.vcxproj.filters",
199                   "..\\bin\\confgen\\win32\\rndcconfgen.vcxproj",
200                   "..\\bin\\confgen\\win32\\rndcconfgen.vcxproj.filters",
201                   "..\\bin\\delv\\win32\\delv.vcxproj",
202                   "..\\bin\\delv\\win32\\delv.vcxproj.filters",
203                   "..\\bin\\dig\\win32\\dig.vcxproj",
204                   "..\\bin\\dig\\win32\\dig.vcxproj.filters",
205                   "..\\bin\\dig\\win32\\dighost.vcxproj",
206                   "..\\bin\\dig\\win32\\dighost.vcxproj.filters",
207                   "..\\bin\\dig\\win32\\host.vcxproj",
208                   "..\\bin\\dig\\win32\\host.vcxproj.filters",
209                   "..\\bin\\dig\\win32\\nslookup.vcxproj",
210                   "..\\bin\\dig\\win32\\nslookup.vcxproj.filters",
211                   "..\\bin\\dnssec\\win32\\dnssectool.vcxproj",
212                   "..\\bin\\dnssec\\win32\\dnssectool.vcxproj.filters",
213                   "..\\bin\\dnssec\\win32\\dsfromkey.vcxproj",
214                   "..\\bin\\dnssec\\win32\\dsfromkey.vcxproj.filters",
215                   "..\\bin\\dnssec\\win32\\importkey.vcxproj",
216                   "..\\bin\\dnssec\\win32\\importkey.vcxproj.filters",
217                   "..\\bin\\dnssec\\win32\\keyfromlabel.vcxproj",
218                   "..\\bin\\dnssec\\win32\\keyfromlabel.vcxproj.filters",
219                   "..\\bin\\dnssec\\win32\\keygen.vcxproj",
220                   "..\\bin\\dnssec\\win32\\keygen.vcxproj.filters",
221                   "..\\bin\\dnssec\\win32\\revoke.vcxproj",
222                   "..\\bin\\dnssec\\win32\\revoke.vcxproj.filters",
223                   "..\\bin\\dnssec\\win32\\settime.vcxproj",
224                   "..\\bin\\dnssec\\win32\\settime.vcxproj.filters",
225                   "..\\bin\\dnssec\\win32\\signzone.vcxproj",
226                   "..\\bin\\dnssec\\win32\\signzone.vcxproj.filters",
227                   "..\\bin\\dnssec\\win32\\verify.vcxproj",
228                   "..\\bin\\dnssec\\win32\\verify.vcxproj.filters",
229                   "..\\bin\\named\\win32\\named.vcxproj",
230                   "..\\bin\\named\\win32\\named.vcxproj.filters",
231                   "..\\bin\\nsupdate\\win32\\nsupdate.vcxproj",
232                   "..\\bin\\nsupdate\\win32\\nsupdate.vcxproj.filters",
233                   "..\\bin\\pkcs11\\win32\\pk11destroy.vcxproj",
234                   "..\\bin\\pkcs11\\win32\\pk11destroy.vcxproj.filters",
235                   "..\\bin\\pkcs11\\win32\\pk11keygen.vcxproj",
236                   "..\\bin\\pkcs11\\win32\\pk11keygen.vcxproj.filters",
237                   "..\\bin\\pkcs11\\win32\\pk11list.vcxproj",
238                   "..\\bin\\pkcs11\\win32\\pk11list.vcxproj.filters",
239                   "..\\bin\\pkcs11\\win32\\pk11tokens.vcxproj",
240                   "..\\bin\\pkcs11\\win32\\pk11tokens.vcxproj.filters",
241                   "..\\bin\\rndc\\win32\\rndc.vcxproj",
242                   "..\\bin\\rndc\\win32\\rndc.vcxproj.filters",
243                   "..\\bin\\rndc\\win32\\rndcutil.vcxproj",
244                   "..\\bin\\rndc\\win32\\rndcutil.vcxproj.filters",
245                   "..\\bin\\tools\\win32\\arpaname.vcxproj",
246                   "..\\bin\\tools\\win32\\arpaname.vcxproj.filters",
247                   "..\\bin\\tools\\win32\\genrandom.vcxproj",
248                   "..\\bin\\tools\\win32\\genrandom.vcxproj.filters",
249                   "..\\bin\\tools\\win32\\ischmacfixup.vcxproj",
250                   "..\\bin\\tools\\win32\\ischmacfixup.vcxproj.filters",
251                   "..\\bin\\tools\\win32\\journalprint.vcxproj",
252                   "..\\bin\\tools\\win32\\journalprint.vcxproj.filters",
253                   "..\\bin\\tools\\win32\\nsec3hash.vcxproj",
254                   "..\\bin\\tools\\win32\\nsec3hash.vcxproj.filters",
255                   "..\\bin\\tools\\win32\\rrchecker.vcxproj",
256                   "..\\bin\\tools\\win32\\rrchecker.vcxproj.filters",
257                   "..\\bin\\tests\\atomic\\win32\\t_atomic.vcxproj",
258                   "..\\bin\\tests\\atomic\\win32\\t_atomic.vcxproj.filters",
259                   "..\\bin\\tests\\db\\win32\\t_db.vcxproj",
260                   "..\\bin\\tests\\db\\win32\\t_db.vcxproj.filters",
261                   "..\\bin\\tests\\dst\\win32\\t_dst.vcxproj",
262                   "..\\bin\\tests\\dst\\win32\\t_dst.vcxproj.filters",
263                   "..\\bin\\tests\\master\\win32\\t_master.vcxproj",
264                   "..\\bin\\tests\\master\\win32\\t_master.vcxproj.filters",
265                   "..\\bin\\tests\\mem\\win32\\t_mem.vcxproj",
266                   "..\\bin\\tests\\mem\\win32\\t_mem.vcxproj.filters",
267                   "..\\bin\\tests\\hashes\\win32\\t_hashes.vcxproj",
268                   "..\\bin\\tests\\hashes\\win32\\t_hashes.vcxproj.filters",
269                   "..\\bin\\tests\\names\\win32\\t_names.vcxproj",
270                   "..\\bin\\tests\\names\\win32\\t_names.vcxproj.filters",
271                   "..\\bin\\tests\\rbt\\win32\\t_rbt.vcxproj",
272                   "..\\bin\\tests\\rbt\\win32\\t_rbt.vcxproj.filters",
273                   "..\\bin\\tests\\resolver\\win32\\t_resolver.vcxproj",
274                   "..\\bin\\tests\\resolver\\win32\\t_resolver.vcxproj.filters",
275                   "..\\bin\\tests\\sockaddr\\win32\\t_sockaddr.vcxproj",
276                   "..\\bin\\tests\\sockaddr\\win32\\t_sockaddr.vcxproj.filters",
277                   "..\\bin\\tests\\tasks\\win32\\t_tasks.vcxproj",
278                   "..\\bin\\tests\\tasks\\win32\\t_tasks.vcxproj.filters",
279                   "..\\bin\\tests\\timers\\win32\\t_timers.vcxproj",
280                   "..\\bin\\tests\\timers\\win32\\t_timers.vcxproj.filters",
281                   "..\\bin\\tests\\win32\\backtrace_test.vcxproj",
282                   "..\\bin\\tests\\win32\\backtrace_test.vcxproj.filters",
283                   "..\\bin\\tests\\win32\\inter_test.vcxproj",
284                   "..\\bin\\tests\\win32\\inter_test.vcxproj.filters",
285                   "..\\bin\\tests\\win32\\rwlock_test.vcxproj",
286                   "..\\bin\\tests\\win32\\rwlock_test.vcxproj.filters",
287                   "..\\bin\\tests\\win32\\shutdown_test.vcxproj",
288                   "..\\bin\\tests\\win32\\shutdown_test.vcxproj.filters",
289                   "..\\bin\\tests\\win32\\sock_test.vcxproj",
290                   "..\\bin\\tests\\win32\\sock_test.vcxproj.filters",
291                   "..\\bin\\tests\\win32\\task_test.vcxproj",
292                   "..\\bin\\tests\\win32\\task_test.vcxproj.filters",
293                   "..\\bin\\tests\\win32\\timer_test.vcxproj",
294                   "..\\bin\\tests\\win32\\timer_test.vcxproj.filters",
295                   "..\\bin\\tests\\win32\\inter_test.vcxproj",
296                   "..\\bin\\tests\\win32\\inter_test.vcxproj.filters",
297                   "..\\bin\\tests\\win32\\rwlock_test.vcxproj",
298                   "..\\bin\\tests\\win32\\rwlock_test.vcxproj.filters",
299                   "..\\bin\\tests\\win32\\shutdown_test.vcxproj",
300                   "..\\bin\\tests\\win32\\shutdown_test.vcxproj.filters",
301                   "..\\bin\\tests\\win32\\sock_test.vcxproj",
302                   "..\\bin\\tests\\win32\\sock_test.vcxproj.filters",
303                   "..\\bin\\tests\\win32\\task_test.vcxproj",
304                   "..\\bin\\tests\\win32\\task_test.vcxproj.filters",
305                   "..\\bin\\tests\\win32\\timer_test.vcxproj",
306                   "..\\bin\\tests\\win32\\timer_test.vcxproj.filters",
307                   "..\\bin\\win32\\BINDInstall\\BINDInstall.vcxproj",
308                   "..\\bin\\win32\\BINDInstall\\BINDInstall.vcxproj.filters",
309                   "..\\lib\\bind9\\win32\\libbind9.vcxproj",
310                   "..\\lib\\bind9\\win32\\libbind9.vcxproj.filters",
311                   "..\\lib\\dns\\win32\\gen.vcxproj",
312                   "..\\lib\\dns\\win32\\gen.vcxproj.filters",
313                   "..\\lib\\dns\\win32\\libdns.vcxproj",
314                   "..\\lib\\dns\\win32\\libdns.vcxproj.filters",
315                   "..\\lib\\irs\\win32\\libirs.vcxproj",
316                   "..\\lib\\irs\\win32\\libirs.vcxproj.filters",
317                   "..\\lib\\isc\\win32\\libisc.vcxproj",
318                   "..\\lib\\isc\\win32\\libisc.vcxproj.filters",
319                   "..\\lib\\isccc\\win32\\libisccc.vcxproj",
320                   "..\\lib\\isccc\\win32\\libisccc.vcxproj.filters",
321                   "..\\lib\\isccfg\\win32\\libisccfg.vcxproj",
322                   "..\\lib\\isccfg\\win32\\libisccfg.vcxproj.filters",
323                   "..\\lib\\lwres\\win32\\liblwres.vcxproj",
324                   "..\\lib\\lwres\\win32\\liblwres.vcxproj.filters",
325                   "..\\lib\\samples\\win32\\resolve.vcxproj",
326                   "..\\lib\\samples\\win32\\resolve.vcxproj.filters",
327                   "..\\lib\\samples\\win32\\async.vcxproj",
328                   "..\\lib\\samples\\win32\\async.vcxproj.filters",
329                   "..\\lib\\samples\\win32\\gai.vcxproj",
330                   "..\\lib\\samples\\win32\\gai.vcxproj.filters",
331                   "..\\lib\\samples\\win32\\update.vcxproj",
332                   "..\\lib\\samples\\win32\\update.vcxproj.filters",
333                   "..\\lib\\samples\\win32\\request.vcxproj",
334                   "..\\lib\\samples\\win32\\request.vcxproj.filters",
335                   "..\\lib\\samples\\win32\\nsprobe.vcxproj",
336                   "..\\lib\\samples\\win32\\nsprobe.vcxproj.filters",
337                   "..\\lib\\tests\\win32\\libtests.vcxproj",
338                   "..\\lib\\tests\\win32\\libtests.vcxproj.filters",
339                   "..\\lib\\win32\\bindevt\\bindevt.vcxproj",
340                   "..\\lib\\win32\\bindevt\\bindevt.vcxproj.filters",
341                   "bind9.sln");
342
343# for config.h
344
345my %configdefh;
346
347my @substdefh = ("AES_SIT",
348                 "ALLOW_FILTER_AAAA",
349                 "CONFIGARGS",
350                 "DNS_RDATASET_FIXED",
351                 "ENABLE_RPZ_NSDNAME",
352                 "ENABLE_RPZ_NSIP",
353                 "HAVE_EVP_SHA256",
354                 "HAVE_EVP_SHA384",
355                 "HAVE_EVP_SHA512",
356                 "HAVE_GEOIP",
357                 "HAVE_GEOIP_CITY_V6",
358                 "HAVE_GEOIP_V6",
359                 "HAVE_LIBXML2",
360                 "HAVE_OPENSSL_AES",
361                 "HAVE_OPENSSL_DSA",
362                 "HAVE_OPENSSL_ECDSA",
363                 "HAVE_OPENSSL_EVP_AES",
364                 "HAVE_OPENSSL_GOST",
365                 "HAVE_PKCS11_ECDSA",
366                 "HAVE_PKCS11_GOST",
367                 "HAVE_READLINE",
368                 "HMAC_RETURN_INT",
369                 "HMAC_SHA1_SIT",
370                 "HMAC_SHA256_SIT",
371                 "ISC_LIST_CHECKINIT",
372                 "PREFER_GOSTASN1",
373                 "TUNE_LARGE",
374                 "WITH_IDN");
375
376# for platform.h
377
378my %configdefp;
379
380my @substdefp = ("ISC_PLATFORM_HAVEATOMICSTORE",
381                 "ISC_PLATFORM_HAVECMPXCHG",
382                 "ISC_PLATFORM_HAVEXADD",
383                 "ISC_PLATFORM_HAVEXADDQ",
384                 "ISC_PLATFORM_NEEDSTRCASESTR",
385                 "ISC_PLATFORM_USEBACKTRACE",
386                 "ISC_PLATFORM_USESIT",
387                 "ISC_PLATFORM_WANTAES");
388
389# includes
390
391my %configinc;
392
393my @substinc = ("GSSAPI_INC",
394                "GEOIP_INC",
395                "IDN_INC",
396                "LIBXML2_INC",
397                "OPENSSL_INC",
398                "READLINE_INC");
399
400# libraries
401
402my %configlib;
403
404my @substlib = ("GSSAPI_LIB",
405                "GEOIP_LIB",
406                "IDN_LIB",
407                "KRB5_LIB",
408                "LIBXML2_LIB",
409                "OPENSSL_LIB",
410                "READLINE_LIB",
411                "READLINE_LIBD");
412
413# DLLs
414
415my %configdll;
416
417my @substdll = ("COMERR_DLL",
418                "GSSAPI_DLL",
419                "GEOIP_DLL",
420                "ICONV_DLL",
421                "IDN_DLL",
422                "KRB5_DLL",
423                "K5SPRT_DLL",
424                "LIBXML2_DLL",
425                "OPENSSL_DLL",
426                "WSHELP_DLL");
427
428# variables
429
430my %configvar;
431
432my @substvar = ("BUILD_MACHINE",
433                "BUILD_PLATFORM",
434                "COPTI",
435                "COPTML",
436                "COPTMLD",
437                "COPTX",
438                "COPTY",
439                "INTRINSIC",
440                "MACHINE",
441                "OPENSSL_PATH",
442                "PLATFORM",
443                "PKCS11_TOOLS",
444                "prefix",
445                "PYTHON",
446                "VCREDIST_PATH"),
447
448# defines
449
450my %configdefd;
451
452my @substdefd = ("CRYPTO",
453                 "PK11_LIB_LOCATION",
454                 "USE_GSSAPI",
455                 "USE_PKCS11",
456                 "USE_PYTHON",
457                 "USE_ISC_SPNEGO");
458
459# conditions
460
461my %configcond;
462
463my @substcond = ("AES",
464                 "ATOMIC",
465                 "GSSAPI",
466                 "GEOIP",
467                 "IDNKIT",
468                 "LIBXML2",
469                 "OPENSSL",
470                 "PKCS11",
471                 "PYTHON",
472                 "SAMPLES",
473                 "TESTS",
474                 "XTESTS");
475
476# arguments
477
478# enable-xxx/disable-xxx
479
480my @enablelist = ("developer",
481                  "fixed-rrset",
482                  "intrinsics",
483                  "isc-spnego",
484                  "native-pkcs11",
485                  "openssl-hash",
486                  "filter-aaaa",
487                  "rpz-nsdname",
488                  "rpz-nsip",
489                  "sit");
490
491# with-xxx/without-xxx
492
493my @withlist = ("aes",
494                "cross-compile",
495                "ecdsa",
496                "extra-tests",
497                "gssapi",
498                "geoip",
499                "gost",
500                "iconv",
501                "idn",
502                "openssl",
503                "libxml2",
504                "pkcs11",
505                "python",
506                "readline",
507                "samples",
508                "sit-alg",
509                "tests",
510                "tuning",
511                "vcredist");
512
513# general arguments
514
515my @optionlist = ("help", "verbose", "legacy", "win32", "x64", "clean");
516
517# usage
518
519my @usage = ("Usage: perl Configure help\n",
520             "       perl Configure options* win32|x64\n",
521             "       perl Configure clean\n");
522
523# help
524
525my @help = (
526"'Configure' configures BIND9 build files.\n\n",
527@usage,
528"\nGeneral Options and Commands:\n",
529"  verbose               (options) print messages\n",
530"  help                  (command) print this help\n",
531"  legacy                (options) process only files for legacy build\n",
532"  win32                 (command) configure for Win32 platform\n",
533"  x64                   (command) configure for x64 platform\n",
534"  clean                 (command) clean up generated files\n",
535"  <none>                (command) print a summary of the configuration\n",
536"\nOptional Features:\n",
537"  enable-intrinsics     enable instrinsic/atomic functions [default=yes]\n",
538"  enable-native-pkcs11  use native PKCS#11 for all crypto [default=no]\n",
539"  enable-openssl-hash   use OpenSSL for hash functions [default=yes]\n",
540"  enable-isc-spnego     use SPNEGO from lib/dns [default=yes]\n",
541"  enable-filter-aaaa    enable filtering of AAAA records [default=no]\n",
542"  enable-fixed-rrset    enable fixed rrset ordering [default=no]\n",
543"  enable-developer      enable developer build settings [default=no]\n",
544"  enable-rpz-nsip       enable rpz-nsip rules [default=yes]\n",
545"  enable-rpz-nsdname    enable rpz-nsdname rules [default=yes]\n",
546"  enable-sit            enable source identity token [default=yes]\n",
547"\nOptional Packages:\n",
548"  with-tests            build with test suite\n",
549"  with-extra-tests      build with extra test suite\n",
550"  with-samples          build with sample programs\n",
551"  with-openssl[=PATH]   build with OpenSSL yes|no|path\n",
552"  with-pkcs11[=PATH]    build with PKCS#11 support yes|no|provider-path\n",
553"  with-ecdsa            crypto ECDSA\n",
554"  with-gost[=ENC]       crypto GOST yes|no|raw|ans1\n",
555"  with-aes              crypto AES\n",
556"  with-sit-alg          choose the algorithm for SIT aes|sha1|sha256\n",
557"  with-gssapi[=PATH]    build with MIT KfW GSSAPI yes|no|path\n",
558"  with-libxml2[=PATH]   build with libxml2 library yes|no|path\n",
559"  with-geoip[=PATH]     build with GeoIP support yes|no|path\n",
560"  with-python[=COMMAND] specify python interpreter python|command\n",
561"  with-readline[=PATH]  build with readline library support yes|no|path\n",
562"  with-idn[=PATH]       build with IDN kit support yes|no|path\n",
563"  with-iconv[=PATH]     path of the iconv DLL [default=same than idn]\n",
564"  with-vcredist[=PATH]  visual C++ redistributable package yes|path\n",
565"  with-tuning=OPTION    tune for plaform size (large|default)\n",
566"  with-cross-compile    32 / 64 bit build / host plaforms\n");
567
568# Parse arguments
569
570my $verbose = 0;
571my $legacy_only = 0;
572my $want_help = "no";
573my $want_win32 = "no";
574my $want_x64 = "no";
575my $want_clean = "no";
576my $want_unknown = "no";
577my $unknown_value;
578my $enable_intrinsics = "yes";
579my $enable_native_pkcs11 = "no";
580my $enable_openssl_hash = "auto";
581my $enable_filter_aaaa = "no";
582my $enable_isc_spnego = "yes";
583my $enable_fixed_rrset = "no";
584my $enable_developer = "no";
585my $enable_rpz_nsip = "yes";
586my $enable_rpz_nsdname = "yes";
587my $enable_sit = "yes";
588my $use_tests = "no";
589my $use_xtests = "no";
590my $use_samples = "no";
591my $use_openssl = "auto";
592my $openssl_path = "..\\..\\";
593my $use_pkcs11 = "no";
594my $pkcs11_path = "unknown";
595my $use_ecdsa = "auto";
596my $use_gost = "auto";
597my $gost_encoding = "raw";
598my $use_aes = "auto";
599my $sit_algorithm = "aes";
600my $use_gssapi = "no";
601my $gssapi_path = "C:\\Program\ Files\\MIT\\Kerberos\\";
602my $use_geoip = "no";
603my $geoip_path = "";
604my $use_libxml2 = "auto";
605my $libxml2_path = "..\\..\\";
606my $use_python = "auto";
607my $python_command = "python";
608my $use_readline = "no";
609my $readline_path = "..\\..\\";
610my $use_idn = "no";
611my $idn_path = "..\\..\\";
612my $iconv_path = " --idn-- ";
613my $use_vcredist = "yes";
614my $vcredist_path = " --infer-- ";
615my $cross_compile = "no";
616my $tuning = "default";
617
618# no arguments -> usage
619
620if ($#ARGV < 0) {
621    foreach (@usage) {
622        print $_;
623    }
624    exit 1;
625}
626
627# parse arguments
628
629foreach (@ARGV) {
630    if (/^verbose$/i) {
631        $verbose = 1;
632    } elsif (/^help$/i) {
633        $want_help = "yes";
634    } elsif (/^disable-(.*)$/i) {
635        appargs($_);
636        myenable($1, "no");
637    } elsif (/^enable-(.*)$/i) {
638        appargs($_);
639        myenable($1, "yes");
640    } elsif (/^without-(.*)$/i) {
641        appargs($_);
642        mywith($1, "no");
643    } elsif (/^with-(.*)=(.*)$/i) {
644        appargs($_);
645        mywith($1, $2);
646    } elsif (/^with-(.*)$/i) {
647        appargs($_);
648        mywith($1, "yes");
649    } elsif (/^legacy$/i) {
650        $legacy_only = 1;
651    } elsif (/^win32$/i) {
652        $want_win32 = "yes";
653    } elsif (/^x64$/i) {
654        appargs($_);
655        $want_x64 = "yes";
656    } elsif (/^clean$/i) {
657        $want_clean = "yes";
658    } else {
659        $want_unknown = "yes";
660        $unknown_value = $_;
661    }
662}
663
664# legacy default to win32
665
666if ($legacy_only && ($want_x64 ne "yes")) {
667    $want_win32 = "yes";
668}
669
670# configure the platform
671
672if (($want_win32 eq "yes") && ($want_x64 eq "yes")) {
673    die "can't ask for both Win32 and x64 platforms\n";
674} elsif ($want_win32 eq "yes") {
675    $configvar{"PLATFORM"} = "Win32";
676    $configvar{"BUILD_PLATFORM"} = "Win32";
677    $configvar{"MACHINE"} = "/machine:X86";
678    $configvar{"BUILD_MACHINE"} = "/machine:X86";
679} elsif ($want_x64 eq "yes") {
680    $configvar{"PLATFORM"} = "x64";
681    $configvar{"BUILD_PLATFORM"} = "x64";
682    $configvar{"MACHINE"} = "/machine:X64";
683    $configvar{"BUILD_MACHINE"} = "/machine:X64";
684}
685
686# append seen args to CONFIGARGS define
687
688sub appargs {
689    my $arg = $_[0];
690    # escape backslashes, spaces and double quotes
691    $arg =~ s/([\\ "])/\\$1/g;
692    if (defined($configdefh{"CONFIGARGS"})) {
693        $configdefh{"CONFIGARGS"} .= " " . $arg;
694    } else {
695        $configdefh{"CONFIGARGS"} = $arg;
696    }
697}
698
699if (!$configdefh{"CONFIGARGS"}) {
700    # CONFIGARGS default is "default"
701    $configdefh{"CONFIGARGS"} = "\"default\"";
702} else {
703    my $val = $configdefh{"CONFIGARGS"};
704    $configdefh{"CONFIGARGS"} = "\"'$val'\"";
705}
706
707# parse enable/disable
708
709sub myenable {
710    my $key = $_[0];
711    my $val = $_[1];
712
713    if ($key =~ /^intrinsics$/i) {
714        if ($val =~ /^no$/i) {
715            $enable_intrinsics = "no";
716        }
717    } elsif ($key =~ /^native-pkcs11$/i) {
718        if ($val =~ /^yes$/i) {
719            $enable_native_pkcs11 = "yes";
720        }
721    } elsif ($key =~ /^openssl-hash$/i) {
722        if ($val =~ /^yes$/i) {
723            $enable_openssl_hash = "yes";
724        } elsif ($val =~ /^no$/i) {
725            $enable_openssl_hash = "no";
726        }
727    } elsif ($key =~ /^isc-spnego$/i) {
728        if ($val =~ /^no$/i) {
729            $enable_isc_spnego = "no";
730        }
731    } elsif ($key =~ /^filter-aaaa$/i) {
732        if ($val =~ /^yes$/i) {
733            $enable_filter_aaaa = "yes";
734        }
735    } elsif ($key =~ /^fixed-rrset$/i) {
736        if ($val =~ /^yes$/i) {
737            $enable_fixed_rrset = "yes";
738        }
739    } elsif ($key =~ /^developer$/i) {
740        if ($val =~ /^yes$/i) {
741            $enable_developer = "yes";
742        }
743    } elsif ($key =~ /^rpz-nsip$/i) {
744        if ($val =~ /^no$/i) {
745            $enable_rpz_nsip = "no";
746        }
747    } elsif ($key =~ /^rpz-nsdname$/i) {
748        if ($val =~ /^no$/i) {
749            $enable_rpz_nsdname = "no";
750        }
751    } elsif ($key =~ /^sit$/i) {
752        if ($val =~ /^no$/i) {
753            $enable_sit = "no";
754        }
755    } else {
756        $want_unknown = "yes";
757        if ($val eq "no") {
758            $unknown_value = "disable-" . $key;
759        } else {
760            $unknown_value = "enable-". $key;
761        }
762    }
763}
764
765# enable-developer expansion now
766
767if ($enable_developer eq "yes") {
768    $configdefh{"ISC_LIST_CHECKINIT"} = 1;
769    $enable_filter_aaaa = "yes";
770    # no atf on WIN32
771    $enable_fixed_rrset = "yes";
772    # TODO: dlz filesystem
773    $use_tests = "yes";
774    $use_samples = "yes";
775    $enable_sit = "yes";
776}
777
778# parse with/without
779
780sub mywith {
781    my $key = $_[0];
782    my $val = $_[1];
783
784    if ($key =~ /^tests$/i) {
785        if ($val =~ /^yes$/i) {
786            $use_tests = "yes";
787        }
788    } elsif ($key =~ /^extra-tests$/i) {
789        if ($val =~ /^yes$/i) {
790            $use_tests = "yes";
791            $use_xtests = "yes";
792        }
793    } elsif ($key =~ /^samples$/i) {
794        if ($val =~ /^yes$/i) {
795            $use_samples = "yes";
796        }
797    } elsif ($key =~ /^openssl$/i) {
798        if ($val =~ /^no$/i) {
799            $use_openssl = "no";
800        } elsif ($val !~ /^yes$/i) {
801            $use_openssl = "yes";
802            $openssl_path = $val;
803        }
804    } elsif ($key =~ /^pkcs11$/i) {
805        if ($val =~ /^yes$/i) {
806            $use_pkcs11 = "yes";
807        } elsif ($val !~ /^no$/i) {
808            $use_pkcs11= "yes";
809            $pkcs11_path = $val;
810            $pkcs11_path =~ s/\.dll$//i;
811        }
812    } elsif ($key =~ /^ecdsa$/i) {
813        if ($val =~ /^no$/i) {
814            $use_ecdsa = "no";
815        } elsif ($val =~ /^yes$/i) {
816            $use_ecdsa = "yes";
817        }
818    } elsif ($key =~ /^gost$/i) {
819        if ($val =~ /^no$/i) {
820            $use_gost = "no";
821        } elsif ($val =~ /^yes$/i) {
822            $use_gost = "yes";
823            $gost_encoding = $val;
824        }
825    } elsif ($key =~ /^aes$/i) {
826        if ($val =~ /^no$/i) {
827            $use_aes = "no";
828        } elsif ($val =~ /^yes$/i) {
829            $use_aes = "yes";
830        }
831    } elsif ($key =~ /^sit-alg$/i) {
832        $sit_algorithm = $val;
833    } elsif ($key =~ /^gssapi$/i) {
834        if ($val !~ /^no$/i) {
835            $use_gssapi = "yes";
836            if ($val !~ /^yes$/i) {
837                $gssapi_path = $val;
838            }
839        }
840    } elsif ($key =~ /^libxml2$/i) {
841        if ($val =~ /^no$/i) {
842            $use_libxml2 = "no";
843        } elsif ($val !~ /^yes$/i) {
844            $use_libxml2 = "yes";
845            $libxml2_path = $val;
846        }
847    } elsif ($key =~ /^geoip$/i) {
848        if ($val !~ /^no$/i) {
849            $use_geoip = "yes";
850            if ($val !~ /^yes$/i) {
851                $geoip_path = $val;
852            }
853        }
854    } elsif ($key =~ /^readline$/i) {
855        if ($val !~ /^no$/i) {
856            $use_readline = "yes";
857            if ($val !~ /^yes$/i) {
858                $readline_path = $val;
859            }
860        }
861    } elsif ($key =~ /^idn$/i) {
862        if ($val !~ /^no$/i) {
863            $use_idn = "yes";
864            if ($val !~ /^yes$/i) {
865                $idn_path = $val;
866            }
867        }
868    } elsif ($key =~ /^iconv$/i) {
869        if ($val =~ /^no$/i) {
870            $want_unknown = "yes";
871            $unknown_value = "without-iconv doesn't make sense)";
872        } elsif ($val !~ /^yes$/i) {
873            $iconv_path = $val;
874        }
875    } elsif ($key =~ /^python$/i) {
876        if ($val =~ /^no$/i) {
877            $use_python = "no";
878        } else {
879            $use_python = "yes";
880            if ($val !~ /^yes$/i) {
881                $python_command = $val;
882            }
883        }
884    } elsif ($key =~ /^vcredist$/i) {
885        if ($val =~ /^no$/i) {
886            $want_unknown = "yes";
887            $unknown_value = "without-vcredist (vcredist is required)";
888        } elsif ($val !~ /^yes$/i) {
889            $vcredist_path = $val;
890        }
891    } elsif ($key =~ /^cross-compile$/i) {
892        if ($val =~ /^yes$/i) {
893            $cross_compile = "yes";
894        }
895    } elsif ($key =~ /^tuning$/i) {
896        if ($val =~ /^large$/i) {
897            $tuning = "large";
898        }
899    } else {
900        $want_unknown = "yes";
901        if ($val eq "no") {
902            $unknown_value = "without-" . $key;
903        } else {
904            $unknown_value = "with-" . $key;
905        }
906    }
907}
908
909# resolve enable-openssl-hash
910if ($enable_openssl_hash eq "auto") {
911    if ($use_openssl ne "no") {
912        if ($enable_native_pkcs11 eq "yes") {
913            $enable_openssl_hash="no";
914        } else {
915            $enable_openssl_hash="yes";
916        }
917    } else {
918        $enable_openssl_hash="no";
919    }
920}
921
922if ($want_help ne "no") {
923    foreach (@help) {
924        print $_;
925    }
926    exit 1;
927}
928
929# clean up and exit if requested
930if ($want_clean eq "yes") {
931    my $file;
932    foreach $file (@filelist) {
933        unlink($file);
934    }
935
936    foreach $file (@projectlist) {
937        unlink($file);
938    }
939
940    exit 0;
941}
942
943if ($want_unknown ne "no") {
944    print STDERR "can't parse $unknown_value\n";
945    exit 1;
946}
947
948if ($verbose) {
949    if ($want_win32 eq "yes") {
950        print "configure for win32\n";
951    }
952    if ($want_x64 eq "yes") {
953        print "configure for x64\n";
954    }
955    if ($cross_compile eq "yes") {
956        print "cross compiling";
957        if ($want_x64 eq "yes") {
958            print ": build on win32 for x64 host\n";
959        } elsif ($want_win32 eq "yes") {
960            print ": build on x64 for win32 host\n";
961        } else {
962            print "\n";
963        }
964    }
965    if ($enable_intrinsics eq "yes") {
966        print "intrinsics: enabled\n";
967    } else {
968        print "intrinsics: disabled\n";
969    }
970    if ($enable_native_pkcs11 eq "yes") {
971        print "native-pkcs11: enabled\n";
972    } else {
973        print "native-pkcs11: disabled\n";
974    }
975    if ($enable_openssl_hash eq "yes") {
976        print "openssl-hash: enabled\n";
977    } else {
978        print "openssl-hash: disabled\n";
979    }
980    if ($enable_isc_spnego eq "yes") {
981        print "isc-spnego: enabled\n";
982    } else {
983        print "isc-spnego: disabled\n";
984    }
985    if ($enable_filter_aaaa eq "yes") {
986        print "filter-aaaa: enabled\n";
987    } else {
988        print "filter-aaaa: disabled\n";
989    }
990    if ($enable_fixed_rrset eq "yes") {
991        print "fixed-rrset: enabled\n";
992    } else {
993        print "fixed-rrset: disabled\n";
994    }
995    if ($enable_developer eq "yes") {
996        print "developer: enabled\n";
997    } else {
998        print "developer: disabled\n";
999    }
1000    if ($enable_rpz_nsip eq "yes") {
1001        print "rpz-nsip: enabled\n";
1002    } else {
1003        print "rpz-nsip: disabled\n";
1004    }
1005    if ($enable_rpz_nsdname eq "yes") {
1006        print "rpz-nsdname: enabled\n";
1007    } else {
1008        print "rpz-nsdname: disabled\n";
1009    }
1010    if ($enable_sit eq "yes") {
1011        print "sit: enabled\n";
1012        print "sit algorithm: $sit_algorithm\n";
1013    } else {
1014        print "sit: disabled\n";
1015    }
1016    if ($use_openssl eq "no") {
1017        print "openssl: disabled\n";
1018    } else {
1019        print "openssl-path: $openssl_path\n";
1020    }
1021    if ($use_tests eq "yes") {
1022        print "tests: enabled\n";
1023    }
1024    if ($use_xtests eq "yes") {
1025        print "extra tests: enabled\n";
1026    }
1027    if ($use_samples eq "yes") {
1028        print "sample programs: enabled\n";
1029    }
1030    if ($use_pkcs11 eq "no") {
1031        print "pkcs11: disabled\n";
1032    } else {
1033        print "pkcs11-provider-path: $pkcs11_path\n";
1034    }
1035    if ($use_ecdsa eq "no") {
1036        print "ecdsa: disabled\n";
1037    } else {
1038        print "ecdsa: enabled\n";
1039    }
1040    if ($use_gost eq "no") {
1041        print "gost: disabled\n";
1042    } else {
1043        print "gost: enabled\n";
1044        print "gost private key encoding: $gost_encoding\n";
1045    }
1046    if ($use_aes eq "no") {
1047        print "aes: disabled\n";
1048    } else {
1049        print "aes: enabled\n";
1050    }
1051    if ($use_gssapi eq "no") {
1052        print "gssapi: disabled\n";
1053    } else {
1054        print "gssapi-path: $gssapi_path\n";
1055    }
1056    if ($use_libxml2 eq "no") {
1057        print "libxml2: disabled\n";
1058    } else {
1059        print "libxml2-path: $libxml2_path\n";
1060    }
1061    if ($use_geoip eq "no") {
1062        print "geoip: disabled\n";
1063    } else {
1064        print "geoip-path: $geoip_path\n";
1065    }
1066    if ($use_readline eq "no") {
1067        print "readline: disabled\n";
1068    } else {
1069        print "readline-path: $readline_path\n";
1070    }
1071    if ($use_idn eq "no") {
1072        print "idn: disabled\n";
1073    } else {
1074        print "idn-path: $idn_path\n";
1075        if ($iconv_path ne " --idn-- ") {
1076            print "iconv-path: $iconv_path\n";
1077        }
1078    }
1079    if ($use_python eq "no") {
1080        print "python: disabled\n";
1081    } else {
1082        print "python-command: $python_command\n";
1083    }
1084    print "vcredist-path: $vcredist_path\n";
1085}
1086
1087# Check environment
1088
1089# infer vcredist when not given
1090if ($vcredist_path eq " --infer-- ") {
1091    if ($verbose) {
1092        print "trying to infer vcredist path from build environment\n";
1093    }
1094
1095    my @vcpaths = {};
1096    push(@vcpaths, $ENV{"VCRedistPath"}) if ($ENV{"VCRedistPath"} ne "");
1097    push(@vcpaths, File::Spec->catfile( cwd(), "..", ".." ));
1098
1099    if ($ENV{"FrameworkSDKDir"} ne "" && $want_win32 eq "yes") {
1100        push(@vcpaths, File::Spec->catfile($ENV{"FrameworkSDKDir"},
1101                                           "BootStrapper", "Packages",
1102                                           "vcredist_x86"));
1103    } elsif ($ENV{"FrameworkSDKDir"} ne "" && $want_x64 eq "yes") {
1104        push(@vcpaths, File::Spec->catfile($ENV{"FrameworkSDKDir"},
1105                                           "BootStrapper", "Packages",
1106                                           "vcredist_x64"));
1107    }
1108
1109    if ($ENV{"WindowsSDKDir"} ne "" && $want_win32 eq "yes") {
1110        push(@vcpaths, File::Spec->catfile($ENV{"WindowsSDKDir"},
1111                                           "BootStrapper", "Packages",
1112                                           "vcredist_x86"));
1113    } elsif ($ENV{"WindowsSDKDir"} ne "" && $want_x64 eq "yes") {
1114        push(@vcpaths, File::Spec->catfile($ENV{"WindowsSDKDir"},
1115                                           "BootStrapper", "Packages",
1116                                           "vcredist_x64"));
1117    }
1118
1119    if ($ENV{"WindowsSDKDir_old"} ne "" && $want_win32 eq "yes") {
1120        push(@vcpaths, File::Spec->catfile($ENV{"WindowsSDKDir_old"},
1121                                           "BootStrapper", "Packages",
1122                                           "vcredist_x86"));
1123    } elsif ($ENV{"WindowsSDKDir_old"} ne "" && $want_x64 eq "yes") {
1124        push(@vcpaths, File::Spec->catfile($ENV{"WindowsSDKDir_old"},
1125                                           "BootStrapper", "Packages",
1126                                           "vcredist_x64"));
1127    }
1128
1129    if ($ENV{"VCINSTALLDIR"}) {
1130        push(@vcpaths, File::Spec->catfile($ENV{"VCINSTALLDIR"},
1131                                           "redist", "1033"));
1132    }
1133
1134    my $rfile;
1135    if ($want_win32 eq "yes") {
1136        $rfile = "vcredist_x86.exe";
1137    } else {
1138        $rfile = "vcredist_x64.exe";
1139    }
1140
1141    foreach (@vcpaths) {
1142        my $vp = File::Spec->catfile($_, $rfile);
1143        if (-f $vp) {
1144            $vcredist_path = $vp;
1145            last;
1146        }
1147    }
1148
1149    if ($vcredist_path eq " --infer-- ") {
1150        die "with-vcredist is REQUIRED\n";
1151    }
1152
1153    if ($verbose) {
1154        print "found vcredist at " . $vcredist_path . "\n";
1155    }
1156}
1157
1158my $msc_ver = 0;
1159
1160open F, ">mscver.c" || die $!;
1161print F << 'EOF';
1162#include <windows.h>
1163#include <stdio.h>
1164
1165int
1166main(void)
1167{
1168        printf("%d\n", _MSC_VER);
1169        return(0);
1170}
1171EOF
1172close F;
1173my $compret = `cl /nologo /MD mscver.c`;
1174if (grep { -f and -x } ".\\mscver.exe") {
1175    $msc_ver = `.\\mscver.exe`;
1176} else {
1177    die "can't get _MSC_VER value: $compret\n";
1178}
1179if ($verbose) {
1180    print "_MSV_VER == $msc_ver\n";
1181}
1182if ($msc_ver < 1600) {
1183    print STDERR "warning: old version of C++ compiler/Visual Studio\n";
1184    print STDERR "only the legacy (cf legacy\\win32-build.txt) will work\n";
1185}
1186
1187# gen single threaded for < VS 2005
1188
1189if ($msc_ver < 1400) {
1190    $configvar{"COPTML"} = "/ML";
1191    $configvar{"COPTMLD"} = "/MLD";
1192}
1193
1194# /GX deprecated in VS 2005
1195
1196if ($msc_ver < 1400) {
1197    $configvar{"COPTX"} = "/GX";
1198} else {
1199    $configvar{"COPTX"} = "/EHsc";
1200}
1201
1202# /YX for < VS 2005
1203
1204if ($msc_ver < 1400) {
1205    $configvar{"COPTY"} = "/YX";
1206}
1207
1208# backtrace for >= VS 2012
1209
1210if ($msc_ver >= 1700) {
1211    $configdefp{"ISC_PLATFORM_USEBACKTRACE"} = 1;
1212}
1213
1214# no version of MSVS supports strcasestr() yet
1215$configdefp{"ISC_PLATFORM_NEEDSTRCASESTR"} = 1;
1216
1217# warn when cross compiling
1218
1219if ($cross_compile eq "yes") {
1220    if ($want_x64 eq "yes") {
1221        $configvar{"BUILD_PLATFORM"} = "Win32";
1222        $configvar{"BUILD_MACHINE"} = "/machine:X86";
1223    }
1224    if ($want_win32 eq "yes") {
1225        $configvar{"BUILD_PLATFORM"} = "x64";
1226        $configvar{"BUILD_MACHINE"} = "/machine:X64";
1227    }
1228} elsif ($want_win32 eq "yes") {
1229    open F, ">cross.c" || die $!;
1230    print F << 'EOF';
1231#include <windows.h>
1232#include <stdio.h>
1233
1234int
1235main(void)
1236{
1237#ifdef _WIN64
1238        fprintf(stderr, "compiling for x64 when win32 was asked?!\n");
1239#endif
1240        return(0);
1241}
1242EOF
1243    close F;
1244    my $compret = `cl /nologo /MD cross.c`;
1245    if (grep { -f and -x } ".\\cross.exe") {
1246        my $cross = `.\\cross.exe`;
1247        if ($cross) {
1248            print STDERR $cross;
1249        }
1250    } else {
1251        print STDERR "can't check cross compile: $compret\n";
1252    }
1253} else {
1254    open F, ">cross.c" || die $!;
1255    print F << 'EOF';
1256#include <windows.h>
1257#include <stdio.h>
1258
1259int
1260main(void)
1261{
1262#ifndef _WIN64
1263        fprintf(stderr, "compiling in 32 bits when x64 was asked?!\n");
1264#endif
1265        return(0);
1266}
1267EOF
1268    close F;
1269    my $compret = `cl /nologo /MD cross.c`;
1270    if (grep { -f and -x } ".\\cross.exe") {
1271        my $cross = `.\\cross.exe`;
1272        if ($cross) {
1273            print STDERR $cross;
1274        }
1275    } else {
1276        print STDERR "can't check cross compile: $compret\n";
1277    }
1278}
1279
1280# Process arguments
1281
1282# enable-intrinsics
1283if ($enable_intrinsics eq "yes") {
1284    $configcond{"ATOMIC"} = 1;
1285    $configvar{"INTRINSIC"} = "true";
1286    $configvar{"COPTI"} = "/Oi";
1287    $configdefp{"ISC_PLATFORM_HAVEXADD"} = 1;
1288    if ($want_x64 eq "yes") {
1289        $configdefp{"ISC_PLATFORM_HAVEXADDQ"} = 1;
1290    }
1291    $configdefp{"ISC_PLATFORM_HAVEATOMICSTORE"} = 1;
1292    $configdefp{"ISC_PLATFORM_HAVECMPXCHG"} = 1;
1293} else {
1294    $configvar{"INTRINSIC"} = "false";
1295}
1296
1297# enable-native-pkcs11
1298if ($enable_native_pkcs11 eq "yes") {
1299    if ($use_openssl eq "auto") {
1300        $use_openssl = "no";
1301    }
1302    if ($use_openssl ne "no") {
1303        die "can't have both OpenSSL and native PKCS#11\n";
1304    }
1305    if ($use_pkcs11 ne "yes") {
1306        if ($verbose) {
1307            print "native PKCS#11 support: force with-pkcs11\n";
1308        }
1309        $use_pkcs11 = "yes";
1310    }
1311    if ($pkcs11_path eq "unknown") {
1312        if ($verbose) {
1313            print "native PKCS#11 support: no PKCS#11 provider defined?\n";
1314        }
1315    }
1316    $configdefd{"CRYPTO"} = "PKCS11CRYPTO";
1317    if ($use_ecdsa eq "no") {
1318        if ($verbose) {
1319            print "no ECDSA support in native PKCS#11\n";
1320        }
1321    } else {
1322        if ($verbose) {
1323            print "enabled ECDSA support in native PKCS#11\n";
1324        }
1325        $configdefh{"HAVE_PKCS11_ECDSA"} = 1;
1326    }
1327    if ($use_gost eq "no") {
1328        if ($verbose) {
1329            print "no GOST support in native PKCS#11\n";
1330        }
1331    } else {
1332        if ($verbose) {
1333            print "enabled GOST support in native PKCS#11\n";
1334        }
1335        $configdefh{"HAVE_PKCS11_GOST"} = 1;
1336    }
1337    if ($use_aes eq "no") {
1338        if ($verbose) {
1339            print "no AES support in native PKCS#11\n";
1340        }
1341    } else {
1342        if ($verbose) {
1343            print "enabled AES support in native PKCS#11\n";
1344        }
1345        $use_aes = "pkcs11";
1346    }
1347}
1348
1349# enable-filter-aaaa
1350if ($enable_filter_aaaa eq "yes") {
1351    $configdefh{"ALLOW_FILTER_AAAA"} = 1;
1352}
1353
1354# enable-fixed-rrset
1355if ($enable_fixed_rrset eq "yes") {
1356    $configdefh{"DNS_RDATASET_FIXED"} = 1;
1357}
1358
1359# enable-rpz-nsip
1360if ($enable_rpz_nsip ne "no") {
1361    $configdefh{"ENABLE_RPZ_NSIP"} = 1;
1362}
1363
1364# enable-rpz-nsdname
1365if ($enable_rpz_nsdname ne "no") {
1366    $configdefh{"ENABLE_RPZ_NSDNAME"} = 1;
1367}
1368
1369# enable-sit
1370if ($enable_sit ne "no") {
1371    $configdefp{"ISC_PLATFORM_USESIT"} = 1;
1372}
1373
1374# with-tests
1375if ($use_tests eq "yes") {
1376    $configcond{"TESTS"} = 1;
1377}
1378
1379# with-extra-tests
1380if ($use_xtests eq "yes") {
1381    $configcond{"XTESTS"} = 1;
1382}
1383
1384# with-samples
1385if ($use_samples eq "yes") {
1386    $configcond{"SAMPLES"} = 1;
1387}
1388
1389# with-openssl
1390if ($use_openssl eq "no") {
1391    if ($verbose) {
1392        print "OpenSSL library is disabled\n";
1393    }
1394} elsif ($use_openssl eq "auto") {
1395    if ($verbose) {
1396        print "checking for an OpenSSL built directory at sibling root\n";
1397    }
1398    opendir DIR, $openssl_path || die "No Directory: $!\n";
1399    my @dirlist = grep (/^openssl-[0-9]+\.[0-9]+\.[0-9]+[a-z]{0,1}$/i,
1400                        readdir(DIR));
1401    closedir(DIR);
1402
1403    # Make sure we have something
1404    if (scalar(@dirlist) == 0) {
1405        die "can't find an OpenSSL at sibling root\n";
1406    }
1407    # Now see if we have a directory or just a file.
1408    # Make sure we are case insensitive
1409    my $file;
1410    foreach $file (sort {uc($b) cmp uc($a)} @dirlist) {
1411        if (-f File::Spec->catfile($openssl_path,
1412                                   $file,
1413                                   "inc32\\openssl",
1414                                   "opensslv.h")) {
1415            $openssl_path = File::Spec->catdir($openssl_path, $file);
1416            $use_openssl = "yes";
1417            last;
1418        }
1419    }
1420
1421    # If we have one use it otherwise report the error
1422    if ($use_openssl eq "auto") {
1423        die "can't find an OpenSSL built directory at sibling root\n";
1424    }
1425}
1426# falls into (so no else)
1427if ($use_openssl eq "yes") {
1428    $openssl_path = File::Spec->rel2abs($openssl_path);
1429    if ($verbose) {
1430        print "checking for OpenSSL built directory at \"$openssl_path\"\n";
1431    }
1432    if (!-f File::Spec->catfile($openssl_path,
1433                                "inc32\\openssl",
1434                                "opensslv.h")) {
1435        die "can't find OpenSSL opensslv.h include\n";
1436    }
1437    if (!-f File::Spec->catfile($openssl_path, "out32dll", "libeay32.lib")) {
1438        die "can't find OpenSSL libeay32.lib library\n";
1439    }
1440    if (!-f File::Spec->catfile($openssl_path, "out32dll", "libeay32.dll")) {
1441        die "can't find OpenSSL libeay32.dll DLL\n";
1442    }
1443    my $openssl_inc = File::Spec->catdir($openssl_path, "inc32");
1444    my $openssl_libdir = File::Spec->catdir($openssl_path, "out32dll");
1445    my $openssl_lib = File::Spec->catfile($openssl_libdir, "libeay32.lib");
1446    my $openssl_dll = File::Spec->catfile($openssl_libdir, "libeay32.dll");
1447
1448    $configcond{"OPENSSL"} = 1;
1449    $configdefd{"CRYPTO"} = "OPENSSL";
1450    $configvar{"OPENSSL_PATH"} = "$openssl_path";
1451    $configinc{"OPENSSL_INC"} = "$openssl_inc";
1452    $configlib{"OPENSSL_LIB"} = "$openssl_lib";
1453    $configdll{"OPENSSL_DLL"} = "$openssl_dll";
1454    if (-f File::Spec->catfile($openssl_inc, "openssl", "dsa.h")) {
1455        $configdefh{"HAVE_OPENSSL_DSA"} = 1;
1456    } elsif ($verbose) {
1457        print "OpenSSL DSA support is disabled\n";
1458    }
1459}
1460
1461# check OpenSSL
1462if ($use_openssl eq "yes") {
1463    if ($verbose) {
1464        print "checking whether linking with OpenSSL works\n";
1465    }
1466    my $dll = $configdll{"OPENSSL_DLL"};
1467    my $ret = `copy "$dll" .`;
1468    if ($? != 0) {
1469        die "Can't copy OpenSSL DLL to working directory: $ret\n";
1470    }
1471    open F, ">testossl.c" || die $!;
1472    print F << 'EOF';
1473#include <openssl/err.h>
1474
1475int
1476main(void)
1477{
1478        ERR_clear_error();
1479        return(0);
1480}
1481EOF
1482    close F;
1483    my $include = $configinc{"OPENSSL_INC"};
1484    my $library = $configlib{"OPENSSL_LIB"};
1485    $compret = `cl /nologo /MD /I "$include" testossl.c "$library"`;
1486    if (grep { -f and -x } ".\\testossl.exe") {
1487        `.\\testossl.exe`;
1488        if ($? != 0) {
1489            die "OpenSSL test failed\n";
1490        }
1491    } else {
1492        die "can't compile OpenSSL test: $compret\n";
1493    }
1494}
1495
1496# check OpenSSL version
1497if ($use_openssl eq "yes") {
1498    if ($verbose) {
1499        printf "checking OpenSSL library version\n";
1500    }
1501    open F, ">testosslv.c" || die $!;
1502    print F << 'EOF';
1503#include <stdio.h>
1504#include <openssl/opensslv.h>
1505
1506int main() {
1507        if ((OPENSSL_VERSION_NUMBER >= 0x009070cfL &&
1508             OPENSSL_VERSION_NUMBER < 0x00908000L) ||
1509             OPENSSL_VERSION_NUMBER >= 0x0090804fL)
1510                return (0);
1511        printf("\n\nFound   OPENSSL_VERSION_NUMBER %#010x\n",
1512               OPENSSL_VERSION_NUMBER);
1513        printf("Require OPENSSL_VERSION_NUMBER 0x009070cf or greater (0.9.7l)\n"
1514               "Require OPENSSL_VERSION_NUMBER 0x0090804f or greater (0.9.8d)\n\n");
1515        return (1);
1516}
1517EOF
1518    close F;
1519    my $include = $configinc{"OPENSSL_INC"};
1520    my $library = $configlib{"OPENSSL_LIB"};
1521    $compret = `cl /nologo /MD /I "$include" testosslv.c "$library"`;
1522    if (grep { -f and -x } ".\\testosslv.exe") {
1523        `.\\testosslv.exe`;
1524        if ($? != 0) {
1525            die "OpenSSL version test failed\n";
1526        }
1527    } else {
1528        die "can't compile OpenSSL version test: $compret\n";
1529    }
1530}
1531
1532# check EVP_sha256 / EVP_sha384 / EVP_sha512
1533
1534if ($use_openssl eq "yes") {
1535    if ($verbose) {
1536        printf "checking for EVP_sha256\n";
1537    }
1538    open F, ">testsha256.c" || die $!;
1539    print F << 'EOF';
1540extern void *EVP_sha256();
1541
1542int main() {
1543        return EVP_sha256() != 0;
1544}
1545EOF
1546    close F;
1547    my $library = $configlib{"OPENSSL_LIB"};
1548    $compret = `cl /nologo /MD testsha256.c "$library"`;
1549    if (grep { -f and -x } ".\\testsha256.exe") {
1550        `.\\testsha256.exe`;
1551        if ($? == 0) {
1552            if ($verbose) {
1553                print "EVP_sha256 test failed: disabling EVP_sha256\n";
1554            }
1555            $use_ecdsa = "no";
1556            $enable_openssl_hash = "no";
1557        } else {
1558            $configdefh{"HAVE_EVP_SHA256"} = 1;
1559        }
1560    } else {
1561        if ($verbose) {
1562            print "can't compile EVP_sha256 test: $compret\n";
1563            print "disabling EVP_sha256\n";
1564        }
1565        $use_ecdsa = "no";
1566        $enable_openssl_hash = "no";
1567    }
1568
1569    if ($verbose) {
1570        printf "checking for EVP_sha384\n";
1571    }
1572    open F, ">testsha384.c" || die $!;
1573    print F << 'EOF';
1574extern void *EVP_sha384();
1575
1576int main() {
1577        return EVP_sha384() != 0;
1578}
1579EOF
1580    close F;
1581    $compret = `cl /nologo /MD testsha384.c "$library"`;
1582    if (grep { -f and -x } ".\\testsha384.exe") {
1583        `.\\testsha384.exe`;
1584        if ($? == 0) {
1585            if ($verbose) {
1586                print "EVP_sha384 test failed: disabling EVP_sha384\n";
1587            }
1588            $use_ecdsa = "no";
1589            $enable_openssl_hash = "no";
1590        } else {
1591            $configdefh{"HAVE_EVP_SHA384"} = 1;
1592        }
1593    } else {
1594        if ($verbose) {
1595            print "can't compile EVP_sha384 test: $compret\n";
1596            print "disabling EVP_sha384\n";
1597        }
1598        $use_ecdsa = "no";
1599        $enable_openssl_hash = "no";
1600    }
1601
1602    if ($verbose) {
1603        printf "checking for EVP_sha512\n";
1604    }
1605    open F, ">testsha512.c" || die $!;
1606    print F << 'EOF';
1607extern void *EVP_sha512();
1608
1609int main() {
1610        return EVP_sha512() != 0;
1611}
1612EOF
1613    close F;
1614    $compret = `cl /nologo /MD testsha512.c "$library"`;
1615    if (grep { -f and -x } ".\\testsha512.exe") {
1616        `.\\testsha512.exe`;
1617        if ($? == 0) {
1618            if ($verbose) {
1619                print "EVP_sha512 test failed: disabling EVP_sha512\n";
1620            }
1621        } else {
1622            $configdefh{"HAVE_EVP_SHA512"} = 1;
1623        }
1624    } else {
1625        if ($verbose) {
1626            print "can't compile EVP_sha512 test: $compret\n";
1627            print "disabling EVP_sha512\n";
1628        }
1629    }
1630}
1631
1632# with-ecdsa
1633if ($use_openssl eq "no") {
1634    $use_ecdsa = "no";
1635}
1636if ($use_ecdsa eq "auto") {
1637    if ($verbose) {
1638        print "checking for OpenSSL ECDSA support\n";
1639    }
1640    open F, ">testecdsa.c" || die $!;
1641    print F << 'EOF';
1642#include <openssl/ecdsa.h>
1643#include <openssl/objects.h>
1644
1645int
1646main(void)
1647{
1648        EC_KEY *ec256, *ec384;
1649
1650        ec256 = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
1651        ec384 = EC_KEY_new_by_curve_name(NID_secp384r1);
1652        if (ec256 == NULL || ec384 == NULL)
1653                return (2);
1654        return (0);
1655}
1656EOF
1657    close F;
1658    my $include = $configinc{"OPENSSL_INC"};
1659    my $library = $configlib{"OPENSSL_LIB"};
1660    $compret = `cl /nologo /MD /I "$include" testecdsa.c "$library"`;
1661    if (grep { -f and -x } ".\\testecdsa.exe") {
1662        `.\\testecdsa.exe`;
1663        if ($? != 0) {
1664            if ($verbose) {
1665                print "ECDSA test failed: disabling ECDSA\n";
1666            }
1667            $use_ecdsa = "no";
1668        }
1669    } else {
1670        if ($verbose) {
1671            print "can't compile ECDSA test: $compret\n";
1672            print "disabling ECDSA\n";
1673        }
1674    $use_ecdsa = "no";
1675    }
1676}
1677
1678if ($use_ecdsa ne "no") {
1679    $use_ecdsa = "yes";
1680    $configdefh{"HAVE_OPENSSL_ECDSA"} = 1;
1681}
1682
1683# with-gost
1684if ($use_openssl eq "no") {
1685    $use_gost = "no";
1686}
1687if ($use_gost eq "auto") {
1688    if ($verbose) {
1689        print "checking for OpenSSL GOST support\n";
1690    }
1691    open F, ">testgost.c" || die $!;
1692    print F << 'EOF';
1693#include <openssl/conf.h>
1694#include <openssl/engine.h>
1695
1696int
1697main(void)
1698{
1699#if (OPENSSL_VERSION_NUMBER >= 0x10000000L)
1700        ENGINE *e;
1701        EC_KEY *ek;
1702
1703        ek = NULL;
1704        OPENSSL_config(NULL);
1705
1706        e = ENGINE_by_id("gost");
1707        if (e == NULL)
1708                return (1);
1709        if (ENGINE_init(e) <= 0)
1710                return (1);
1711        return (0);
1712#else
1713        return (1);
1714#endif
1715}
1716EOF
1717    close F;
1718    my $include = $configinc{"OPENSSL_INC"};
1719    my $library = $configlib{"OPENSSL_LIB"};
1720    $compret = `cl /nologo /MD /I "$include" testgost.c "$library"`;
1721    if (grep { -f and -x } ".\\testgost.exe") {
1722        `.\\testgost.exe`;
1723        if ($? != 0) {
1724            if ($verbose) {
1725                print "GOST test failed: disabling GOST\n";
1726            }
1727            $use_gost = "no";
1728        }
1729    } else {
1730        if ($verbose) {
1731            print "can't compile GOST test: $compret\n";
1732            print "disabling GOST\n";
1733        }
1734    $use_gost = "no";
1735    }
1736}
1737
1738if ($use_gost ne "no") {
1739    $use_gost = "yes";
1740    $configdefh{"HAVE_OPENSSL_GOST"} = 1;
1741}
1742
1743if ($gost_encoding eq "ans1") {
1744    $configdefh{"PREFER_GOSTASN1"} = 1;
1745} elsif ($gost_encoding ne "raw") {
1746    die "Unrecognized GOST private key encoding: $gost_encoding\n";
1747}
1748
1749# with-aes
1750if ($use_openssl eq "no") {
1751    if ($use_aes ne "pkcs11") {
1752        $use_aes = "no";
1753    }
1754}
1755if ($use_aes eq "auto") {
1756    if ($verbose) {
1757        print "checking for OpenSSL EVP AES support\n";
1758    }
1759    $use_aes = "evp";
1760    open F, ">testevpaes.c" || die $!;
1761    print F << 'EOF';
1762#include <openssl/evp.h>
1763
1764int
1765main(void)
1766{
1767        EVP_CIPHER *aes128, *aes192, *aes256;
1768
1769        aes128 = EVP_aes_128_ecb();
1770        aes192 = EVP_aes_192_ecb();
1771        aes256 = EVP_aes_256_ecb();
1772        if (aes128 == NULL || aes192 == NULL || aes256 == NULL)
1773                return (1);
1774        return (0);
1775}
1776EOF
1777    close F;
1778    my $include = $configinc{"OPENSSL_INC"};
1779    my $library = $configlib{"OPENSSL_LIB"};
1780    $compret = `cl /nologo /MD /I "$include" testevpaes.c "$library"`;
1781    if (grep { -f and -x } ".\\testevpaes.exe") {
1782        `.\\testevpaes.exe`;
1783        if ($? != 0) {
1784            if ($verbose) {
1785                print "EVP AES test failed: disabling EVP AES\n";
1786            }
1787            $use_aes = "auto";
1788        }
1789    } else {
1790        if ($verbose) {
1791            print "can't compile EVP AES test: $compret\n";
1792            print "disabling EVP AES\n";
1793        }
1794        $use_aes = "auto";
1795    }
1796}
1797
1798if ($use_aes eq "auto") {
1799    if ($verbose) {
1800        print "checking for OpenSSL native AES support\n";
1801    }
1802    $use_aes = "native";
1803    open F, ">testaes.c" || die $!;
1804    print F << 'EOF';
1805#include <openssl/aes.h>
1806
1807AES_KEY k;
1808const unsigned char bufin[16];
1809unsigned char bufout[16];
1810
1811int
1812main(void)
1813{
1814        AES_encrypt(bufin, bufout, &k);
1815        return (0);
1816}
1817EOF
1818    close F;
1819    my $include = $configinc{"OPENSSL_INC"};
1820    my $library = $configlib{"OPENSSL_LIB"};
1821    $compret = `cl /nologo /MD /I "$include" testaes.c "$library"`;
1822    if (grep { -f and -x } ".\\testaes.exe") {
1823        `.\\testaes.exe`;
1824        if ($? != 0) {
1825            if ($verbose) {
1826                print "native AES test failed: disabling AES\n";
1827            }
1828            $use_aes = "no";
1829        }
1830    } else {
1831        if ($verbose) {
1832            print "can't compile native AES test: $compret\n";
1833            print "disabling AES\n";
1834        }
1835        $use_aes = "no";
1836    }
1837}
1838
1839if ($use_aes eq "yes") {
1840    $configdefh{"HAVE_OPENSSL_EVP_AES"} = 1;
1841} elsif ($use_aes eq "evp") {
1842    $configdefh{"HAVE_OPENSSL_EVP_AES"} = 1;
1843    $use_aes = "yes";
1844} elsif ($use_aes eq "native") {
1845    $configdefh{"HAVE_OPENSSL_AES"} = 1;
1846    $use_aes = "yes";
1847} elsif ($use_aes eq "pkcs11") {
1848    $use_aes = "yes";
1849}
1850
1851if ($use_aes eq "yes") {
1852    $configdefp{"ISC_PLATFORM_WANTAES"} = 1;
1853    $configcond{"AES"} = 1;
1854}
1855
1856# with-sit-alg
1857if ($enable_sit ne "no") {
1858    if ($sit_algorithm eq "aes") {
1859        if ($use_aes ne "yes") {
1860            $sit_algorithm = "sha256";
1861        } else {
1862            $configdefh{"AES_SIT"} = 1;
1863        }
1864    }
1865    if ($sit_algorithm eq "sha1") {
1866        $configdefh{"HMAC_SHA1_SIT"} = 1;
1867    } elsif ($sit_algorithm eq "sha256") {
1868        $configdefh{"HMAC_SHA256_SIT"} = 1;
1869    } elsif ($sit_algorithm ne "aes") {
1870        die "Unrecognized SIT algorithm: $sit_algorithm\n";
1871    }
1872}
1873
1874# enable-openssl-hash
1875if ($enable_openssl_hash eq "yes") {
1876    if ($use_openssl eq "no") {
1877        die "No OpenSSL for hash functions\n";
1878    }
1879    $configdefp{"ISC_PLATFORM_OPENSSLHASH"} = 1;
1880    if ($verbose) {
1881        print "checking HMAC_Init() return type\n";
1882    }
1883    open F, ">testhmac.c" || die $!;
1884    print F << 'EOF';
1885#include <openssl/hmac.h>
1886
1887int
1888main(void)
1889{
1890        HMAC_CTX ctx;
1891        int n = HMAC_Init(&ctx, NULL, 0, NULL);
1892        n += HMAC_Update(&ctx, NULL, 0);
1893        n += HMAC_Final(&ctx, NULL, NULL);
1894        return(n);
1895}
1896EOF
1897    close F;
1898    my $include = $configinc{"OPENSSL_INC"};
1899    my $library = $configlib{"OPENSSL_LIB"};
1900    $compret = `cl /nologo /MD /I "$include" testhmac.c "$library"`;
1901    if (grep { -f and -x } ".\\testhmac.exe") {
1902        $configdefh{"HMAC_RETURN_INT"} = 1;
1903    }
1904}
1905
1906# with-pkcs11
1907if ($use_pkcs11 ne "no") {
1908    $configcond{"PKCS11"} = 1;
1909    $configdefd{"USE_PKCS11"} = "USE_PKCS11";
1910    $configvar{"PKCS11_TOOLS"} = "pkcs11";
1911    $configdefd{"PK11_LIB_LOCATION"} = "PK11_LIB_LOCATION=\"$pkcs11_path\"";
1912}
1913
1914# with-gssapi
1915if ($use_gssapi eq "no") {
1916    if ($verbose) {
1917        print "gssapi library is disabled\n";
1918    }
1919} else {
1920    $gssapi_path = File::Spec->rel2abs($gssapi_path);
1921    if ($verbose) {
1922        print "checking for gssapi directory at \"$gssapi_path\"\n";
1923    }
1924    $configcond{"GSSAPI"} = 1;
1925    $configdefd{"USE_GSSAPI"} = "GSSAPI";
1926    if (!-f File::Spec->catfile($gssapi_path, "include",
1927                                "gssapi", "gssapi.h")) {
1928        die "can't find gssapi.h include\n";
1929    }
1930    if (!-f File::Spec->catfile($gssapi_path, "include",
1931                                "gssapi", "gssapi_krb5.h")) {
1932        die "can't find gssapi_krb5.h include\n";
1933    }
1934    if (!-f File::Spec->catfile($gssapi_path, "include",
1935                                "krb5", "krb5.h")) {
1936        die "can't find krb5.h include\n";
1937    }
1938    $configinc{"GSSAPI_INC"} = File::Spec->catdir($gssapi_path, "include");
1939    my $bits = "32";
1940    my $gssapi_lib;
1941    my $krb5_lib;
1942    if ($want_win32 eq "yes") {
1943        $bits = "32";
1944        if (!-f File::Spec->catfile($gssapi_path, "lib", "i386",
1945                                    "gssapi${bits}.lib")) {
1946            die "can't find gssapi${bits}.lib library\n";
1947        }
1948        $gssapi_lib = File::Spec->catfile($gssapi_path, "lib", "i386",
1949                                          "gssapi${bits}.lib");
1950        if (!-f File::Spec->catfile($gssapi_path, "lib", "i386",
1951                                    "krb5_${bits}.lib")) {
1952            die "can't find krb5_${bits}.lib library\n";
1953        }
1954        $krb5_lib = File::Spec->catfile($gssapi_path, "lib", "i386",
1955                                             "krb5_${bits}.lib");
1956    } elsif ($want_x64 eq "yes") {
1957        $bits = "64";
1958        if (!-f File::Spec->catfile($gssapi_path, "lib", "amd64",
1959                                    "gssapi${bits}.lib")) {
1960            die "can't find gssapi${bits}.lib library\n";
1961        }
1962        $gssapi_lib = File::Spec->catfile($gssapi_path, "lib", "amd64",
1963                                             "gssapi${bits}.lib");
1964        if (!-f File::Spec->catfile($gssapi_path, "lib", "amd64",
1965                                    "krb5_${bits}.lib")) {
1966            die "can't find krb5_${bits}.lib library\n";
1967        }
1968        $krb5_lib = File::Spec->catfile($gssapi_path, "lib", "amd64",
1969                                        "krb5_${bits}.lib");
1970    } else {
1971        die "can't happen: no choice between Win32 and x64\n";
1972    }
1973    if (!-f File::Spec->catfile($gssapi_path, "bin", "gssapi${bits}.dll")) {
1974        die "can't find gssapi${bits}.dll DLL\n";
1975    }
1976    if (!-f File::Spec->catfile($gssapi_path, "bin", "krb5_${bits}.dll")) {
1977        die "can't find krb5_${bits}.dll DLL\n";
1978    }
1979    if (!-f File::Spec->catfile($gssapi_path, "bin", "comerr${bits}.dll")) {
1980        die "can't find comerr${bits}.dll DLL\n";
1981    }
1982    if (!-f File::Spec->catfile($gssapi_path, "bin", "k5sprt${bits}.dll")) {
1983        die "can't find k5sprt${bits}.dll DLL\n";
1984    }
1985    if (!-f File::Spec->catfile($gssapi_path, "bin", "wshelp${bits}.dll")) {
1986        die "can't find wshelp${bits}.dll DLL\n";
1987    }
1988    $configlib{"GSSAPI_LIB"} = "$gssapi_lib";
1989    $configlib{"KRB5_LIB"} = "$krb5_lib";
1990    my $gssapi_dll = File::Spec->catfile($gssapi_path, "bin",
1991                                         "gssapi${bits}.dll");
1992    $configdll{"GSSAPI_DLL"} = "$gssapi_dll";
1993    my $krb5_dll = File::Spec->catfile($gssapi_path, "bin",
1994                                         "krb5_${bits}.dll");
1995    $configdll{"KRB5_DLL"} = "$krb5_dll";
1996    my $comerr_dll = File::Spec->catfile($gssapi_path, "bin",
1997                                         "comerr${bits}.dll");
1998    $configdll{"COMERR_DLL"} = "$comerr_dll";
1999    my $k5sprt_dll = File::Spec->catfile($gssapi_path, "bin",
2000                                         "k5sprt${bits}.dll");
2001    $configdll{"K5SPRT_DLL"} = "$k5sprt_dll";
2002    my $wshelp_dll = File::Spec->catfile($gssapi_path, "bin",
2003                                         "wshelp${bits}.dll");
2004    $configdll{"WSHELP_DLL"} = "$wshelp_dll";
2005}
2006
2007# enable-isc-spnego
2008if ($use_gssapi ne "yes") {
2009    $enable_isc_spnego = "no";
2010} elsif ($enable_isc_spnego eq "yes") {
2011    if ($use_gssapi eq "no") {
2012        die "No GSSAPI for SPNEGO\n";
2013    }
2014    $configdefd{"USE_ISC_SPNEGO"} = "USE_ISC_SPNEGO";
2015}
2016
2017# with-geoip
2018if ($use_geoip eq "no") {
2019    if ($verbose) {
2020        print "geoip library is disabled\n";
2021    }
2022} else {
2023    $configcond{"GEOIP"} = 1;
2024    $geoip_path = File::Spec->rel2abs($geoip_path);
2025    if ($verbose) {
2026        print "checking for geoip directory at \"$geoip_path\"\n";
2027    }
2028    if (!-f File::Spec->catfile($geoip_path, "GeoIP.h")) {
2029        die "can't find GeoIP.h include\n";
2030    }
2031    if (!-f File::Spec->catfile($geoip_path, "GeoIP.lib")) {
2032        die "can't find Geoip.lib library\n";
2033    }
2034    if (!-f File::Spec->catfile($geoip_path, "GeoIP.dll")) {
2035        die "can't find Geoip.dll DLL\n";
2036    }
2037    $configinc{"GEOIP_INC"} = "$geoip_path";
2038    my $geoip_lib = File::Spec->catfile($geoip_path, "GeoIP.lib");
2039    $configlib{"GEOIP_LIB"} = "$geoip_lib";
2040    my $geoip_dll = File::Spec->catfile($geoip_path, "GeoIP.dll");
2041    $configdll{"GEOIP_DLL"} = "$geoip_dll";
2042
2043    if ($verbose) {
2044        print "checking for GeoIP support\n";
2045    }
2046    my $ret = `copy "$geoip_dll" .`;
2047    if ($? != 0) {
2048        die "Can't copy GeoIP DLL to working directory: $ret\n";
2049    }
2050    open F, ">testgeoip.c" || die $!;
2051    print F << 'EOF';
2052extern void *GeoIP_open();
2053
2054int main() {
2055        return GeoIP_open != 0;
2056}
2057EOF
2058    close F;
2059    $compret = `cl /nologo /MD testgeoip.c "$geoip_lib"`;
2060    if (grep { -f and -x } ".\\testgeoip.exe") {
2061        `.\\testgeoip.exe`;
2062        if ($? == 0) {
2063            die "GeoIP test failed\n";
2064        }
2065    } else {
2066        die "can't compile GeoIP test: $compret\n";
2067    }
2068    $configdefh{"HAVE_GEOIP"} = 1;
2069
2070    if ($verbose) {
2071        print "checking for GeoIP Country IPv6 support\n";
2072    }
2073    my $geoip_inc = qq(/I "$geoip_path");
2074    my $geoip_libs = qq("$geoip_lib" ws2_32.lib);
2075    open F, ">testgeoip1.c" || die $!;
2076    print F << 'EOF';
2077#include <GeoIP.h>
2078
2079struct in6_addr in6;
2080int flag = 1;
2081
2082int main() {
2083        if (flag)
2084                return 1;
2085        return GeoIP_country_name_by_ipnum_v6(NULL, in6) != NULL;
2086}
2087EOF
2088    close F;
2089    $compret = `cl /nologo $geoip_inc /MD testgeoip1.c $geoip_libs`;
2090    if (grep { -f and -x } ".\\testgeoip1.exe") {
2091        `.\\testgeoip1.exe`;
2092        if ($? == 0) {
2093            die "GeoIP Country IPv6 test failed\n";
2094        }
2095    } else {
2096        die "can't compile GeoIP Country IPv6 test: $compret\n";
2097    }
2098    $configdefh{"HAVE_GEOIP_V6"} = 1;
2099
2100    if ($verbose) {
2101        print "checking for GeoIP City IPv6 support\n";
2102    }
2103    open F, ">testgeoip2.c" || die $!;
2104    print F << 'EOF';
2105#include <GeoIP.h>
2106#include <GeoIPCity.h>
2107
2108struct in6_addr in6;
2109int i = GEOIP_CITY_EDITION_REV0_V6;
2110int flag = 1;
2111
2112int main() {
2113        if (flag)
2114                return 1;
2115        return GeoIP_record_by_ipnum_v6(NULL, in6) != NULL;
2116}
2117EOF
2118    close F;
2119    $compret = `cl /nologo $geoip_inc /MD testgeoip2.c $geoip_libs`;
2120    if (grep { -f and -x } ".\\testgeoip2.exe") {
2121        `.\\testgeoip2.exe`;
2122        if ($? == 0) {
2123            die "GeoIP City IPv6 test failed\n";
2124        }
2125    } else {
2126        die "can't compile GeoIP City IPv6 test: $compret\n";
2127    }
2128    $configdefh{"HAVE_GEOIP_CITY_V6"} = 1;
2129}
2130
2131# with-readline
2132if ($use_readline eq "no") {
2133    if ($verbose) {
2134        print "readline library is disabled\n";
2135    }
2136} else {
2137    $readline_path = File::Spec->rel2abs($readline_path);
2138    if ($verbose) {
2139        print "checking for readline directory at \"$readline_path\"\n";
2140    }
2141    if (!-f File::Spec->catfile($readline_path, "readline", "readline.h")) {
2142        die "can't find readline.h include\n";
2143    }
2144    if (!-f File::Spec->catfile($readline_path, "readline", "readline.lib")) {
2145        die "can't find readline.lib library\n";
2146    }
2147    $configdefh{"HAVE_READLINE"} = 1;
2148    $configinc{"READLINE_INC"} = "$readline_path";
2149    my $readline_lib = File::Spec->catfile($readline_path,
2150                                           "readline", "readline.lib");
2151    $configlib{"READLINE_LIB"} = "$readline_lib";
2152    if (-f File::Spec->catfile($readline_path, "readline", "readlineD.lib")) {
2153        my $readline_libd = File::Spec->catfile($readline_path,
2154                                                "readline", "readlineD.lib");
2155        $configlib{"READLINE_LIBD"} = "$readline_libd";
2156    } else {
2157        $configlib{"READLINE_LIBD"} = "$readline_lib";
2158    }
2159}
2160
2161# with-idn (including with-iconv)
2162if ($use_idn eq "no") {
2163    if ($verbose) {
2164        print "IDN kit is disabled\n";
2165    }
2166} else {
2167    $idn_path = File::Spec->rel2abs($idn_path);
2168    if ($verbose) {
2169        print "checking for IDN kit directory at \"$idn_path\"\n";
2170    }
2171    if (!-f File::Spec->catfile($idn_path, "idn", "api.h")) {
2172        die "can't find idn\\api.h include\n";
2173    }
2174    if (!-f File::Spec->catfile($idn_path, "idn", "idnkit.lib")) {
2175        die "can't find idnkit.lib library\n";
2176    }
2177    if (!-f File::Spec->catfile($idn_path, "idn", "idnkit.dll")) {
2178        die "can't find idnkit.dll DLL\n";
2179    }
2180    $configcond{"IDNKIT"} = 1;
2181    $configdefh{"WITH_IDN"} = 1;
2182    $configinc{"IDN_INC"} = "$idn_path";
2183    my $idn_lib = File::Spec->catfile($idn_path, "idn", "idnkit.lib");
2184    $configlib{"IDN_LIB"} = "$idn_lib";
2185    my $idn_dll = File::Spec->catfile($idn_path, "idn", "idnkit.dll");
2186    $configdll{"IDN_DLL"} = "$idn_dll";
2187    if ($iconv_path eq " --idn-- ") {
2188        my $iconv_dll = File::Spec->catfile($idn_path, "idn", "iconv.dll");
2189        $configdll{"ICONV_DLL"} = "$iconv_dll";
2190    } else {
2191        my $iconv_dll =File::Spec->catfile($iconv_path, "iconv.dll");
2192        $configdll{"ICONV_DLL"} = "$iconv_dll";
2193    }
2194}
2195
2196# with-libxml2
2197if ($use_libxml2 eq "no") {
2198    if ($verbose) {
2199        print "libxml2 library is disabled\n";
2200    }
2201} elsif ($use_libxml2 eq "auto") {
2202    if ($verbose) {
2203        print "checking for a libxml2 built directory at sibling root\n";
2204    }
2205    opendir DIR, $libxml2_path || die "No Directory: $!\n";
2206    my @dirlist = grep (/^libxml2-[0-9]+\.[0-9]+\.[0-9]+[a-z]*/i,
2207                        readdir(DIR));
2208    closedir(DIR);
2209
2210    # Make sure we have something
2211    if (scalar(@dirlist) == 0) {
2212        die "can't find a libxml2 at sibling root\n";
2213    }
2214    # Now see if we have a directory or just a file.
2215    # Make sure we are case insensitive
2216    my $file;
2217    foreach $file (sort {uc($b) cmp uc($a)} @dirlist) {
2218        if (-f File::Spec->catfile($libxml2_path,
2219                                   $file,
2220                                   "include\\libxml",
2221                                   "xmlversion.h")) {
2222            $libxml2_path = File::Spec->catdir($libxml2_path, $file);
2223            $use_libxml2 = "yes";
2224            last;
2225        }
2226    }
2227
2228    # If we have one use it otherwise report the error
2229    if ($use_libxml2 eq "auto") {
2230        die "can't find a libxml2 built directory at sibling root\n";
2231    }
2232}
2233# falls into (so no else)
2234if ($use_libxml2 eq "yes") {
2235    $libxml2_path = File::Spec->rel2abs($libxml2_path);
2236    if ($verbose) {
2237        print "checking for libxml2 built directory at \"$libxml2_path\"\n";
2238    }
2239    if (!-f File::Spec->catfile($libxml2_path,
2240                                "include\\libxml",
2241                                "xmlversion.h")) {
2242        die "can't find libxml2 xmlversion.h include\n";
2243    }
2244    if (!-f File::Spec->catfile($libxml2_path,
2245                                "win32\\bin.msvc",
2246                                "libxml2.lib")) {
2247        die "can't find Libxml2 libxml2.lib library\n";
2248    }
2249    if (!-f File::Spec->catfile($libxml2_path,
2250                                "win32\\bin.msvc",
2251                                "libxml2.dll")) {
2252        die "can't find Libxml2 DLL\n";
2253    }
2254    $configcond{"LIBXML2"} = 1;
2255    $configdefh{"HAVE_LIBXML2"} = 1;
2256    my $libxml2_inc = File::Spec->catdir($libxml2_path, "include");
2257    $configinc{"LIBXML2_INC"} = "$libxml2_inc";
2258    my $libxml2_libdir = File::Spec->catdir($libxml2_path, "win32\\bin.msvc");
2259    my $libxml2_lib = File::Spec->catfile($libxml2_libdir, "libxml2.lib");
2260    $configlib{"LIBXML2_LIB"} = "$libxml2_lib";
2261    my $libxml2_dll = File::Spec->catfile($libxml2_libdir, "libxml2.dll");
2262    $configdll{"LIBXML2_DLL"} = "$libxml2_dll";
2263}
2264
2265# with-python
2266if ($use_python eq "no") {
2267    if ($verbose) {
2268        print "python is disabled\n";
2269    }
2270} elsif ($use_python eq "auto") {
2271    if ($verbose) {
2272        print "checking for python in path\n";
2273    }
2274    my $pythonret = `python -c "quit()" 2>&1`;
2275    if ($? != 0) {
2276        die "can't launch the python interpreter: $pythonret\n";
2277    }
2278    $use_python = "yes";
2279}
2280if ($use_python ne "no") {
2281    if ($verbose) {
2282        my $pythonret = `"$python_command" -c "quit()" 2>&1`;
2283        if ($? != 0) {
2284            print STDERR
2285                "can't lanch the local python interpreter: $pythonret\n";
2286        }
2287    }
2288    $configcond{"PYTHON"} = 1;
2289    $configdefd{"USE_PYTHON"} = "USE_PYTHON";
2290    $configvar{"PYTHON"} = "$python_command";
2291    # Only a default!
2292    $configvar{"prefix"} = "C:\\Program Files\ISC BIND 9";
2293}
2294
2295# with-vcredist
2296$vcredist_path = File::Spec->rel2abs($vcredist_path);
2297if (!grep { -f and -x } $vcredist_path) {
2298    die "$vcredist_path is not correct\n";
2299} else {
2300    $configvar{"VCREDIST_PATH"} = "$vcredist_path";
2301}
2302
2303# tuning
2304if ($tuning eq "large") {
2305    $configdefh{"TUNE_LARGE"} = 1;
2306}
2307
2308# setup config.h with %configdefh
2309
2310sub setupconfigh {
2311    my $line;
2312    my @Lines;
2313
2314    open F, $configfilein || die $!;
2315    @Lines = <F>;
2316    close F;
2317
2318    foreach $line (@Lines) {
2319        chomp $line;
2320        if ($line =~ /^@([^@]+)\@$/) {
2321            if (defined($configdefh{$1})) {
2322                $line = "#define $1 $configdefh{$1}";
2323            } else {
2324                $line = "/* #undef $1 */";
2325            }
2326        }
2327    }
2328
2329    open F, $configfileout || die $!;
2330    if ($verbose) {
2331        print "Setting up config.h\n";
2332    }
2333    foreach $line (@Lines) {
2334        print F $line . "\n";
2335    }
2336    close F;
2337}
2338
2339# setup platform.h with %configdefp
2340
2341sub setupplatformh {
2342    my $line;
2343    my @Lines;
2344
2345    open F, $platformfile . ".in" || die $!;
2346    @Lines = <F>;
2347    close F;
2348
2349    foreach $line (@Lines) {
2350        chomp $line;
2351        if ($line =~ /^@([^@]+)\@$/) {
2352            if (defined($configdefp{$1})) {
2353                $line = "#define $1 $configdefp{$1}";
2354            } else {
2355                $line = "/* #undef $1 */";
2356            }
2357        }
2358    }
2359
2360    open F, ">" . $platformfile || die $!;
2361    if ($verbose) {
2362        print "Setting up platform.h\n";
2363    }
2364    foreach $line (@Lines) {
2365        print F $line . "\n";
2366    }
2367    close F;
2368}
2369
2370# escape spaces
2371
2372sub kw {
2373    if ($_[0] =~ / /) {
2374        return "\"$_[0]\"";
2375    } else {
2376        return "$_[0]";
2377    }
2378}
2379
2380# setup a file with %configcond stack and %config{var,defd,inc,lib,dll}
2381
2382sub setupfile {
2383    my $line;
2384    my @Linesin;
2385    my @Linesout;
2386    my $filename = $_[0];
2387    my $cond;
2388    my @conds;
2389    my $pass = 1;
2390    my @passes;
2391    my $val;
2392
2393    open F, $filename . ".in" || die $!;
2394    @Linesin = <F>;
2395    close F;
2396
2397    foreach $line (@Linesin) {
2398        chomp $line;
2399        if ($line =~ /^\@IF (.*)$/) {
2400            if (defined($cond)) {
2401                unshift(@conds, $cond);
2402                unshift(@passes, $pass);
2403            }
2404            $cond = $1;
2405            if (defined($configcond{$cond})) {
2406                # do nothing
2407            } else {
2408                $pass = 0;
2409            }
2410            next;
2411        } elsif ($line =~ /^\@ELSE (.*)$/) {
2412            if ($cond ne $1) {
2413                die "\@ELSE $1 mismatch in $filename\n";
2414            }
2415            if (defined($configcond{$cond})) {
2416                $pass = 0;
2417            } else {
2418                if (scalar(@conds) > 0) {
2419                    $pass = $passes[0];
2420                } else {
2421                    $pass = 1;
2422                }
2423            }
2424            next;
2425        } elsif ($line =~ /^\@END (.*)$/) {
2426            if ($cond ne $1) {
2427                die "\@END $1 mismatch in $filename\n";
2428            }
2429            $cond = shift(@conds);
2430            if (scalar(@passes) > 0) {
2431                $pass = shift(@passes);
2432            } else {
2433                $pass = 1;
2434            }
2435            next;
2436        }
2437        if ($pass == 0) {
2438            next;
2439        }
2440        while ($line =~ /@([^@ ]*)@/) {
2441            if ($1 ~~ @substvar) {
2442                if (defined($configvar{$1})) {
2443                    $val = kw($configvar{$1});
2444                    $line = "$`$val$'";
2445                } else {
2446                    $line = "$`$'";
2447                }
2448            } elsif ($1 ~~ @substdefd) {
2449                if (defined($configdefd{$1})) {
2450                    my $def = $configdefd{$1};
2451                    my $pre = "$`";
2452                    my $post = "$'";
2453                    $def =~ s/([\\ "])/\\$1/g;
2454                    $line = qq($pre/D "$def"$post);
2455                } else {
2456                    $line = "$`$'";
2457                }
2458            } elsif ($1 ~~ @substinc) {
2459                if (defined($configinc{$1})) {
2460                    $line = qq($`/I "$configinc{$1}"$');
2461                } else {
2462                    $line = "$`$'";
2463                }
2464            } elsif ($1 ~~ @substlib) {
2465                if (defined($configlib{$1})) {
2466                    $val = kw($configlib{$1});
2467                    $line = "$`$val$'";
2468                } else {
2469                    $line = "$`$'";
2470                }
2471            } elsif ($1 ~~ @substdll) {
2472                if (defined($configdll{$1})) {
2473                    $val = kw($configdll{$1});
2474                    $line = "$`$val$'";
2475                } else {
2476                    $line = "$`$'";
2477                }
2478            } else {
2479                die "unknown control $& in $filename\n";
2480            }
2481        }
2482        push @Linesout, $line;
2483    }
2484
2485    open F, ">" . $filename || die $!;
2486    if ($verbose) {
2487        print "Setting up $filename\n";
2488    }
2489    foreach $line (@Linesout) {
2490        print F $line . "\n";
2491    }
2492    close F;
2493}
2494
2495# setup a project with %configcond stack and %config{var,defd,inc,lib,dll}
2496
2497sub setupproject {
2498    my $line;
2499    my @Linesin;
2500    my @Linesout;
2501    my $projectname = $_[0];
2502    my $cond;
2503    my @conds;
2504    my $pass = 1;
2505    my @passes;
2506    my $val;
2507
2508    open F, $projectname . ".in" || die $!;
2509    @Linesin = <F>;
2510    close F;
2511
2512    foreach $line (@Linesin) {
2513        chomp $line;
2514        if ($line =~ /^\@IF (.*)$/) {
2515            if (defined($cond)) {
2516                unshift(@conds, $cond);
2517                unshift(@passes, $pass);
2518            }
2519            $cond = $1;
2520            if (defined($configcond{$cond})) {
2521                # do nothing
2522            } else {
2523                $pass = 0;
2524            }
2525            next;
2526        } elsif ($line =~ /^\@ELSE (.*)$/) {
2527            if ($cond ne $1) {
2528                die "\@ELSE $1 mismatch in $projectname\n";
2529            }
2530            if (defined($configcond{$cond})) {
2531                $pass = 0;
2532            } else {
2533                if (scalar(@conds) > 0) {
2534                    $pass = $passes[0];
2535                } else {
2536                    $pass = 1;
2537                }
2538            }
2539            next;
2540        } elsif ($line =~ /^\@END (.*)$/) {
2541            if ($cond ne $1) {
2542                die "\@END $1 mismatch in $projectname\n";
2543            }
2544            $cond = shift(@conds);
2545            if (scalar(@passes) > 0) {
2546                $pass = shift(@passes);
2547            } else {
2548                $pass = 1;
2549            }
2550            next;
2551        }
2552        if ($pass == 0) {
2553            next;
2554        }
2555        while ($line =~ /@([^@ ]*)@/) {
2556            if ($1 ~~ @substvar) {
2557                if (defined($configvar{$1})) {
2558                    $val = kw($configvar{$1});
2559                    $line = "$`$val$'";
2560                } else {
2561                    $line = "$`$'";
2562                }
2563            } elsif ($1 ~~ @substdefd) {
2564                if (defined($configdefd{$1})) {
2565                    $val = kw($configdefd{$1});
2566                    $line = "$`$val;$'";
2567                } else {
2568                    $line = "$`$'";
2569                }
2570            } elsif ($1 ~~ @substinc) {
2571                if (defined($configinc{$1})) {
2572                    $val = kw($configinc{$1});
2573                    $line = "$`$val;$'";
2574                } else {
2575                    $line = "$`$'";
2576                }
2577            } elsif ($1 ~~ @substlib) {
2578                if (defined($configlib{$1})) {
2579                    $val = kw($configlib{$1});
2580                    $line = "$`$val;$'";
2581                } else {
2582                    $line = "$`$'";
2583                }
2584            } elsif ($1 ~~ @substdll) {
2585                if (defined($configdll{$1})) {
2586                    $val = kw($configdll{$1});
2587                    $line = "$`$val$'";
2588                } else {
2589                    $line = "$`$'";
2590                }
2591            } else {
2592                die "unknown control $& in $projectname\n";
2593            }
2594        }
2595        push @Linesout, $line;
2596    }
2597
2598    open F, ">" . $projectname || die $!;
2599    if ($verbose) {
2600        print "Setting up $projectname\n";
2601    }
2602    foreach $line (@Linesout) {
2603        print F $line . "\n";
2604    }
2605    close F;
2606}
2607
2608# make versions.h
2609
2610sub makeversion {
2611    # List of directories with version files
2612
2613    my @dirlist = ("isc", "dns", "isccc", "isccfg", "lwres", "bind9", "irs");
2614    my %LibMacros = (
2615        "bind9"   => "LIBBIND9_EXPORTS",
2616        "dns"     => "LIBDNS_EXPORTS",
2617        "irs"     => "LIBIRS_EXPORTS",
2618        "isc"     => "LIBISC_EXPORTS",
2619        "isccc"   => "LIBISCCC_EXPORTS",
2620        "isccfg"  => "LIBISCCFG_EXPORTS",
2621        "lwres"   => "LIBLWRES_EXPORTS");
2622    my @VersionNames = ("LIBINTERFACE", "LIBREVISION", "LIBAGE");
2623    my %Versions;
2624    my $Version;
2625    my %ApiVersions;
2626    my $Mapapi;
2627    my $versionfile = "versions.h";
2628    my $versionpath = "..\\$versionfile";
2629
2630    my $data;
2631    my $name;
2632    my $value;
2633
2634    # First get the version information
2635
2636    open V, "..\\version" || die $!;
2637    while (<V>) {
2638        chomp;
2639        ($data) = split(/\#/);
2640        if ($data) {
2641            ($name, $value) = split(/=/, $data);
2642            ($name) = split(/\s+/, $name);
2643            if ($name eq 'PRODUCT' || $name eq 'DESCRIPTION') {
2644                ($value) =~ s/^["\s]+//;
2645                ($value) =~ s/["\s]+$//;
2646            } else {
2647                ($value) = split(/\s+/, $value);
2648            }
2649            $Versions{$name} = $value;
2650        }
2651    }
2652    close V;
2653
2654    # And the mapapi one
2655
2656    open M, "..\\lib\\dns\\mapapi" || die $!;
2657    while (<M>) {
2658        chomp;
2659        ($data) = split(/\#/);
2660        if ($data) {
2661            ($name, $value) = split(/=/, $data);
2662            ($name) = split(/\s+/, $name);
2663            if ($name eq 'MAPAPI') {
2664                ($value) =~ s/^["\s]+//;
2665                ($value) =~ s/["\s]+$//;
2666            } else {
2667                ($value) = split(/\s+/, $value);
2668            }
2669            $Mapapi = $value;
2670        }
2671    }
2672    close M;
2673
2674    # Now set up the output version file
2675
2676    my $ThisDate = scalar localtime();
2677    open O, ">$versionpath" ||
2678        die "Can't open output file $versionpath: $!\n";
2679
2680    # Standard Header
2681
2682    print O '/*
2683 * Copyright (C) 2001  Internet Software Consortium.
2684 *
2685 * Permission to use, copy, modify, and distribute this software for any
2686 * purpose with or without fee is hereby granted, provided that the above
2687 * copyright notice and this permission notice appear in all copies.
2688 *
2689 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
2690 * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
2691 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
2692 * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
2693 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
2694 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
2695 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
2696 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2697 */
2698
2699';
2700
2701    print O "/*\n";
2702    print O " * $versionfile.";
2703    print O "  Generated automatically by Configure.pl.\n";
2704    print O " * Date generated: $ThisDate\n";
2705    print O " */\n\n";
2706
2707    print O '
2708#ifndef  VERSIONS_H
2709#define VERSIONS_H 1
2710
2711';
2712
2713    $Version = "$Versions{'MAJORVER'}.$Versions{'MINORVER'}";
2714    if ($Versions{'PATCHVER'} != "") {
2715        $Version = "$Version.$Versions{'PATCHVER'}";
2716    }
2717    $Version = "$Version$Versions{'RELEASETYPE'}$Versions{'RELEASEVER'}";
2718    $Version = "$Version$Versions{'EXTENSIONS'}";
2719    if ($verbose) {
2720        print "BIND Version: $Version\n";
2721    }
2722
2723    print O "#define VERSION \"$Version\"\n";
2724    print O "#define PRODUCT \"$Versions{'PRODUCT'}\"\n\n";
2725    print O "#define DESCRIPTION \"$Versions{'DESCRIPTION'}\"\n\n";
2726    print O
2727        "#define MAJOR \"$Versions{'MAJORVER'}.$Versions{'MINORVER'}\"\n\n";
2728    print O "#define MAPAPI \"$Mapapi\"\n\n";
2729
2730    my $dir;
2731    my $apifile;
2732    foreach $dir (@dirlist) {
2733        $apifile = "..\\lib\\$dir\\api";
2734        open A, $apifile || die $!;
2735        while (<A>) {
2736            chomp;
2737            ($data) = split(/\#/);
2738            if ($data) {
2739                ($name, $value) = split(/=/, $data);
2740                $name =~ s/\s+//;
2741                $value =~ s/\s+//;
2742                $ApiVersions{$name} = $value;
2743            }
2744        }
2745        close A;
2746
2747        print O "\n#ifdef $LibMacros{$dir}\n";
2748        foreach $name (@VersionNames) {
2749            print O "#define $name\t$ApiVersions{$name}\n";
2750        }
2751        print O "#endif\n\n";
2752    }
2753
2754    print O "#endif /* VERSIONS_H */\n";
2755    close O;
2756}
2757
2758# make srcid.h
2759
2760sub makesrcid {
2761    my $data;
2762    my $name;
2763    my $value;
2764    my $srcid = "unset";
2765
2766    open SOUT, ">..\\srcid.h" || die "cannot open srcid.h: $!\n";
2767    if (open (SIN, "..\\srcid")) {
2768      LOOP: while (<SIN>) {
2769          chomp;
2770          ($data) = split(/\#/);
2771          if ($data) {
2772              ($name, $value) = split(/=/, $data);
2773              ($name) = split(/\s+/, $name);
2774              ($value) = split(/\s+/, $value);
2775              next LOOP if ($name != "SRCID");
2776              $srcid = $value;
2777          }
2778        }
2779        close SIN;
2780    }
2781
2782    # Now set up the output version file
2783
2784    my $ThisDate = scalar localtime();
2785
2786    # Standard Header
2787
2788    print SOUT '/*
2789 * Copyright (C) 2012  Internet Software Consortium.
2790 *
2791 * Permission to use, copy, modify, and distribute this software for any
2792 * purpose with or without fee is hereby granted, provided that the above
2793 * copyright notice and this permission notice appear in all copies.
2794 *
2795 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
2796 * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
2797 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
2798 * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
2799 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
2800 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
2801 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
2802 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2803 */
2804
2805';
2806
2807    print SOUT "/*\n";
2808    print SOUT " * srcid.h";
2809    print SOUT " * Generated automatically by Configure.pl.\n";
2810    print SOUT " * Date generated: $ThisDate\n";
2811    print SOUT " */\n\n";
2812
2813    print SOUT '
2814#ifndef  SRCID_H
2815#define SRCID_H 1
2816';
2817
2818    if ($verbose) {
2819        print "BIND SRCID: $srcid\n";
2820    }
2821
2822    print SOUT "#define SRCID\t\"$srcid\"\n";
2823    print SOUT "#endif /* SRCID_H */\n";
2824    close SOUT;
2825}
2826
2827# Status
2828
2829if ($verbose) {
2830    my $name;
2831
2832    print "Configuration Status\n";
2833
2834    print "\tconfig.h:\n";
2835    foreach $name (@substdefh) {
2836        if (defined($configdefh{$name})) {
2837            print qq(\t\t$name defined to "$configdefh{$name}"\n);
2838        } else {
2839            printf qq(\t\t$name undefined\n);
2840        }
2841    }
2842
2843    print "\tplatform.h:\n";
2844    foreach $name (@substdefp) {
2845        if (defined($configdefp{$name})) {
2846            print qq(\t\t$name defined to "$configdefp{$name}"\n);
2847        } else {
2848            printf qq(\t\t$name undefined\n);
2849        }
2850    }
2851
2852    print "\tconditions:\n";
2853    foreach $name (@substcond) {
2854        if (defined($configcond{$name})) {
2855            print "\t\t$name is true\n";
2856        } else {
2857            print "\t\t$name is false\n";
2858        }
2859    }
2860
2861    print "\tsubstitutions:\n";
2862    foreach $name (@substvar) {
2863        if (defined($configvar{$name})) {
2864            print qq(\t\t$name -> "$configvar{$name}"\n);
2865        }
2866    }
2867
2868    print "\tdefines:\n";
2869    foreach $name (@substdefd) {
2870        if (defined($configdefd{$name})) {
2871            print qq(\t\t/D "$configdefd{$name}"\n);
2872        }
2873    }
2874
2875    print "\tincludes:\n";
2876    foreach $name (@substinc) {
2877        if (defined($configinc{$name})) {
2878            print qq(\t\t/I "$configinc{$name}"\n);
2879        }
2880    }
2881
2882    print "\tlibraries:\n";
2883    foreach $name (@substlib) {
2884        if (defined($configlib{$name})) {
2885            print "\t\t$configlib{$name}\n";
2886        }
2887    }
2888
2889    print "\tDLLs:\n";
2890    foreach $name (@substdll) {
2891        if (defined($configdll{$name})) {
2892            print "\t\t$configdll{$name}\n";
2893        }
2894    }
2895
2896    print "\n";
2897}
2898
2899# Setup
2900if (($want_win32 eq "yes") || ($want_x64 eq "yes")) {
2901    setupconfigh();
2902
2903    setupplatformh();
2904
2905    my $file;
2906    foreach $file (@filelist) {
2907        setupfile($file);
2908    }
2909
2910    if (!$legacy_only) {
2911        foreach $file (@projectlist) {
2912            setupproject($file);
2913        }
2914    }
2915
2916    makeversion();
2917
2918    makesrcid();
2919
2920    print "Configured.\n";
2921} else {
2922    print "add win32 or x64 to commit configuration to build files\n";
2923}
2924
2925exit 0;
2926
2927# Notes: Unix configure.in options
2928#  --enable-developer partially supported
2929#  --enable-newstats (9.9/9.9sub only)
2930#  --enable-native-pkcs11 supported
2931#  --enable-openssl-version-check included without a way to disable it
2932#  --enable-openssl-hash supported
2933#  --enable-threads included without a way to disable it
2934#  --enable-backtrace backtrace included without a way to disable it
2935#  --enable-symtable incompatible with DLLs (or libtool)
2936#  --enable-exportlib TODO (obsolete)
2937#  --enable-ipv6 included without a way to disable it
2938#  --enable-atomic supported (renamed to intrinsic)
2939#  --enable-spnego support (part of GSSAPI)
2940#  --enable-fixed-rrset supported
2941#  --disable-rpz-nsip supported
2942#  --disable-rpz-nsdname supported
2943#  --enable-filter-aaaa supported
2944#  --enable-sit supported
2945#  --enable-full-report supported by verbose
2946#  --with-python supported
2947#  --with-openssl supported
2948#  --with-pkcs11 supported
2949#  --with-ecdsa supported
2950#  --with-gost supported
2951#  --with-aes supported
2952#  --with-sit-alg supported
2953#  --with-geoip supported
2954#  --with-gssapi supported with MIT (K)erberos (f)or (W)indows
2955#  --with-libxml2 supported
2956#  --with-libjson not supported on WIN32 (package not available on WIN32)
2957#  --with-purify ? (package available on WIN32 but for free?)
2958#  --with-gperftools-profiler (package not available on WIN32)
2959#  --with-libtool not supported on WIN32 (never)
2960#  --with-locktype not supported on WIN32 (not yet available on WIN32)
2961#  --with-readline supported
2962#  --with-idn support
2963#  --with-[lib]iconv (part of IDN)
2964#  --with-atf not supported on WIN32 (package not available on WIN32)
2965#  --with-tuning supported
2966#  --with-dlopen included without a way to disable it
2967#  --with-dlz-* ?
2968#
2969# Notes: MSVC versions
2970# MSVC 14.0 _MSC_VER == 1900 (VS 14 (2014))
2971# MSVC 12.0 _MSC_VER == 1800 (VS 2013)
2972# MSVC 11.0 _MSC_VER == 1700 (VS 2012)
2973# MSVC 10.0 _MSC_VER == 1600 (VS 2010)
2974# MSVC 9.0  _MSC_VER == 1500 (VS 2008)
2975# MSVC 8.0  _MSC_VER == 1400 (VS 2005)
2976# MSVC 7.1  _MSC_VER == 1310 (VS .NET 2003)
2977# MSVC 7.0  _MSC_VER == 1300 (VS .NET (2002))
2978# MSVC 6.0  _MSC_VER == 1200 (VS 6.0 (1998))
2979# MSVC 5.0  _MSC_VER == 1100 (VS 97)
2980