Configure 85.1 KB
Newer Older
1 2
#!/usr/bin/perl
#
3
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
4
#
5 6
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
7
# file, you can obtain one at https://mozilla.org/MPL/2.0/.
8 9 10
#
# See the COPYRIGHT file distributed with this work for additional
# information regarding copyright ownership.
11 12 13 14 15 16

# Configure
#
# This script builds nmake and visual studio build files
#

17 18 19
require 5.18.0;
no warnings 'experimental::smartmatch';

20 21 22 23 24
use strict;
use File::Spec;

# files to configure

25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
my $configfile = "../config.h";
my $platformfile = "../lib/isc/win32/include/isc/platform.h";
my @confshlist = ("../bin/tests/system/conf.sh",
		  "../bin/tests/system/run.sh",
		  "../bin/tests/system/start.sh",
		  "../bin/tests/system/stop.sh");

my @filelist = ("../lib/dns/win32/libdns.def",
                "../lib/isc/win32/libisc.def");

my @projectlist = ("../bin/check/win32/checkconf.vcxproj",
                   "../bin/check/win32/checkconf.vcxproj.filters",
                   "../bin/check/win32/checktool.vcxproj",
                   "../bin/check/win32/checktool.vcxproj.filters",
                   "../bin/check/win32/checkzone.vcxproj",
                   "../bin/check/win32/checkzone.vcxproj.filters",
                   "../bin/confgen/win32/confgentool.vcxproj",
                   "../bin/confgen/win32/confgentool.vcxproj.filters",
43 44
                   "../bin/confgen/win32/tsigkeygen.vcxproj",
                   "../bin/confgen/win32/tsigkeygen.vcxproj.filters",
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
                   "../bin/confgen/win32/rndcconfgen.vcxproj",
                   "../bin/confgen/win32/rndcconfgen.vcxproj.filters",
                   "../bin/delv/win32/delv.vcxproj",
                   "../bin/delv/win32/delv.vcxproj.filters",
                   "../bin/dig/win32/dig.vcxproj",
                   "../bin/dig/win32/dig.vcxproj.filters",
                   "../bin/dig/win32/dighost.vcxproj",
                   "../bin/dig/win32/dighost.vcxproj.filters",
                   "../bin/dig/win32/host.vcxproj",
                   "../bin/dig/win32/host.vcxproj.filters",
                   "../bin/dig/win32/nslookup.vcxproj",
                   "../bin/dig/win32/nslookup.vcxproj.filters",
                   "../bin/dnssec/win32/cds.vcxproj",
                   "../bin/dnssec/win32/cds.vcxproj.filters",
                   "../bin/dnssec/win32/dnssectool.vcxproj",
                   "../bin/dnssec/win32/dnssectool.vcxproj.filters",
                   "../bin/dnssec/win32/dsfromkey.vcxproj",
                   "../bin/dnssec/win32/dsfromkey.vcxproj.filters",
                   "../bin/dnssec/win32/importkey.vcxproj",
                   "../bin/dnssec/win32/importkey.vcxproj.filters",
                   "../bin/dnssec/win32/keyfromlabel.vcxproj",
                   "../bin/dnssec/win32/keyfromlabel.vcxproj.filters",
                   "../bin/dnssec/win32/keygen.vcxproj",
                   "../bin/dnssec/win32/keygen.vcxproj.filters",
                   "../bin/dnssec/win32/revoke.vcxproj",
                   "../bin/dnssec/win32/revoke.vcxproj.filters",
                   "../bin/dnssec/win32/settime.vcxproj",
                   "../bin/dnssec/win32/settime.vcxproj.filters",
                   "../bin/dnssec/win32/signzone.vcxproj",
                   "../bin/dnssec/win32/signzone.vcxproj.filters",
                   "../bin/dnssec/win32/verify.vcxproj",
                   "../bin/dnssec/win32/verify.vcxproj.filters",
                   "../bin/named/win32/named.vcxproj",
                   "../bin/named/win32/named.vcxproj.filters",
                   "../bin/nsupdate/win32/nsupdate.vcxproj",
                   "../bin/nsupdate/win32/nsupdate.vcxproj.filters",
                   "../bin/pkcs11/win32/pk11destroy.vcxproj",
                   "../bin/pkcs11/win32/pk11destroy.vcxproj.filters",
                   "../bin/pkcs11/win32/pk11keygen.vcxproj",
                   "../bin/pkcs11/win32/pk11keygen.vcxproj.filters",
                   "../bin/pkcs11/win32/pk11list.vcxproj",
                   "../bin/pkcs11/win32/pk11list.vcxproj.filters",
                   "../bin/pkcs11/win32/pk11tokens.vcxproj",
                   "../bin/pkcs11/win32/pk11tokens.vcxproj.filters",
                   "../bin/rndc/win32/rndc.vcxproj",
                   "../bin/rndc/win32/rndc.vcxproj.filters",
                   "../bin/tools/win32/arpaname.vcxproj",
                   "../bin/tools/win32/arpaname.vcxproj.filters",
                   "../bin/tools/win32/journalprint.vcxproj",
                   "../bin/tools/win32/journalprint.vcxproj.filters",
                   "../bin/tools/win32/mdig.vcxproj",
                   "../bin/tools/win32/mdig.vcxproj.filters",
                   "../bin/tools/win32/nsec3hash.vcxproj",
                   "../bin/tools/win32/nsec3hash.vcxproj.filters",
                   "../bin/tools/win32/rrchecker.vcxproj",
                   "../bin/tools/win32/rrchecker.vcxproj.filters",
Michal Nowak's avatar
Michal Nowak committed
101 102
                   "../bin/tests/system/win32/bigkey.vcxproj",
                   "../bin/tests/system/win32/bigkey.vcxproj.filters",
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
                   "../bin/tests/system/win32/feature-test.vcxproj",
                   "../bin/tests/system/win32/feature-test.vcxproj.filters",
                   "../bin/tests/system/win32/gencheck.vcxproj",
                   "../bin/tests/system/win32/gencheck.vcxproj.filters",
                   "../bin/tests/system/win32/keycreate.vcxproj",
                   "../bin/tests/system/win32/keycreate.vcxproj.filters",
                   "../bin/tests/system/win32/keydelete.vcxproj",
                   "../bin/tests/system/win32/keydelete.vcxproj.filters",
                   "../bin/tests/system/win32/pipequeries.vcxproj",
                   "../bin/tests/system/win32/pipequeries.vcxproj.filters",
                   "../bin/tests/system/win32/makejournal.vcxproj",
                   "../bin/tests/system/win32/makejournal.vcxproj.filters",
                   "../bin/win32/BINDInstall/BINDInstall.vcxproj",
                   "../bin/win32/BINDInstall/BINDInstall.vcxproj.filters",
                   "../lib/bind9/win32/libbind9.vcxproj",
                   "../lib/bind9/win32/libbind9.vcxproj.filters",
                   "../lib/dns/win32/gen.vcxproj",
                   "../lib/dns/win32/gen.vcxproj.filters",
                   "../lib/dns/win32/libdns.vcxproj",
                   "../lib/dns/win32/libdns.vcxproj.filters",
                   "../lib/irs/win32/libirs.vcxproj",
                   "../lib/irs/win32/libirs.vcxproj.filters",
                   "../lib/isc/win32/libisc.vcxproj",
                   "../lib/isc/win32/libisc.vcxproj.filters",
                   "../lib/isccc/win32/libisccc.vcxproj",
                   "../lib/isccc/win32/libisccc.vcxproj.filters",
                   "../lib/isccfg/win32/libisccfg.vcxproj",
                   "../lib/isccfg/win32/libisccfg.vcxproj.filters",
                   "../lib/ns/win32/libns.vcxproj",
                   "../lib/samples/win32/resolve.vcxproj",
                   "../lib/samples/win32/resolve.vcxproj.filters",
                   "../lib/samples/win32/async.vcxproj",
                   "../lib/samples/win32/async.vcxproj.filters",
                   "../lib/samples/win32/update.vcxproj",
                   "../lib/samples/win32/update.vcxproj.filters",
                   "../lib/samples/win32/request.vcxproj",
                   "../lib/samples/win32/request.vcxproj.filters",
                   "../lib/samples/win32/nsprobe.vcxproj",
                   "../lib/samples/win32/nsprobe.vcxproj.filters",
                   "../lib/win32/bindevt/bindevt.vcxproj",
                   "../lib/win32/bindevt/bindevt.vcxproj.filters",
144 145 146 147 148 149
                   "bind9.sln");

# for config.h

my %configdefh;

150 151 152 153 154 155 156 157 158 159 160 161
my @substdefh = ("PACKAGE_VERSION_MAJOR",
                 "PACKAGE_VERSION_MINOR",
                 "PACKAGE_VERSION_PATCH",
                 "PACKAGE_VERSION_EXTRA",
                 "PACKAGE_VERSION",
                 "PACKAGE_NAME",
                 "PACKAGE_DESCRIPTION",
                 "PACKAGE_SRCID",
                 "PACKAGE_CONFIGARGS",
                 "PACKAGE_BUILDER",
                 "PACKAGE_STRING",
                 "MAPAPI",
162
                 "DNS_RDATASET_FIXED",
163
                 "HAVE_GEOIP2",
164 165 166 167 168 169 170
                 "HAVE_GSSAPI",
                 "HAVE_GSSAPI_H",
                 "HAVE_GSSAPI_KRB5_H",
                 "HAVE_KRB5_H",
                 "HAVE_GSSAPI_GSSAPI_H",
                 "HAVE_GSSAPI_GSSAPI_KRB5_H",
                 "HAVE_KRB5_KRB5_H",
171
                 "HAVE_LIBXML2",
172 173
                 "HAVE_OPENSSL_ED25519",
                 "HAVE_OPENSSL_ED448",
174 175 176 177 178 179
                 "HAVE_DH_GET0_KEY",
                 "HAVE_ECDSA_SIG_GET0",
                 "HAVE_RSA_SET0_KEY",
                 "USE_BACKTRACE",
                 "USE_OPENSSL",
                 "USE_PKCS11",
180
                 "HAVE_READLINE",
Francis Dupont's avatar
Francis Dupont committed
181
                 "HAVE_ZLIB",
182
                 "ISC_LIST_CHECKINIT",
183
                 "TUNE_LARGE",
184
                 "WANT_QUERYTRACE",
185
                 "WITH_IDN",
186
                 "CPU_RELAX",
187
                 "VALIDATION_DEFAULT",
188 189 190 191 192 193 194 195 196 197
                 "HAVE_CRYPTO_ZALLOC",
                 "HAVE_EVP_CIPHER_CTX_FREE",
                 "HAVE_EVP_CIPHER_CTX_NEW",
                 "HAVE_EVP_MD_CTX_FREE",
                 "HAVE_EVP_MD_CTX_NEW",
                 "HAVE_EVP_MD_CTX_RESET",
                 "HAVE_HMAC_CTX_FREE",
                 "HAVE_HMAC_CTX_GET_MD",
                 "HAVE_HMAC_CTX_NEW",
                 "HAVE_HMAC_CTX_RESET",
198 199 200
                 "HAVE_UV_HANDLE_GET_DATA",
                 "HAVE_UV_HANDLE_SET_DATA",
                 "HAVE_UV_IMPORT",
201
    );
202 203 204 205 206

# for platform.h

my %configdefp;

207
my @substdefp = ();
208

209 210 211 212
# for conf.sh

my %configtest;

213
my @substtest = ("CRYPTO",
214
                 "DEVELOPER_MODE",
215 216 217 218 219
                 "DNSTAP",
                 "FSTRM_CAPTURE",
                 "JSONSTATS",
                 "NZD_TOOLS",
                 "XMLSTATS",
220 221 222 223 224 225 226 227 228
                 "ZLIB",
		 "builddir",
		 "srcdir",
		 "abs_builddir",
		 "abs_srcdir",
		 "top_builddir",
		 "top_srcdir",
		 "abs_top_builddir",
		 "abs_top_srcdir");
229

230 231 232 233 234 235 236 237
# includes

my %configinc;

my @substinc = ("GSSAPI_INC",
                "GEOIP_INC",
                "IDN_INC",
                "LIBXML2_INC",
238
                "LIBUV_INC",
239
                "NGHTTP2_INC",
240
                "OPENSSL_INC",
Francis Dupont's avatar
Francis Dupont committed
241 242
                "READLINE_INC",
                "ZLIB_INC");
243 244 245 246 247 248 249 250 251 252

# libraries

my %configlib;

my @substlib = ("GSSAPI_LIB",
                "GEOIP_LIB",
                "IDN_LIB",
                "KRB5_LIB",
                "LIBXML2_LIB",
253
                "LIBUV_LIB",
254
                "NGHTTP2_LIB",
255 256
                "OPENSSL_LIBCRYPTO",
                "OPENSSL_LIBSSL",
257
                "READLINE_LIB",
Francis Dupont's avatar
Francis Dupont committed
258 259
                "READLINE_LIBD",
                "ZLIB_LIB");
260 261 262 263 264 265 266 267 268 269 270 271

# DLLs

my %configdll;

my @substdll = ("COMERR_DLL",
                "GSSAPI_DLL",
                "ICONV_DLL",
                "IDN_DLL",
                "KRB5_DLL",
                "K5SPRT_DLL",
                "LIBXML2_DLL",
272
                "LIBUV_DLL",
273
                "NGHTTP2_DLL",
274 275
                "OPENSSL_DLLCRYPTO",
                "OPENSSL_DLLSSL",
Francis Dupont's avatar
Francis Dupont committed
276 277
                "WSHELP_DLL",
                "ZLIB_DLL");
278 279 280

# variables

281
my %configvar = (
282
        "TOOLS_VERSION" => "4.0",
283
);
284

Francis Dupont's avatar
Francis Dupont committed
285 286
my @substvar = ("BIND9_VERSION",
                "BUILD_MACHINE",
287 288 289 290 291 292
                "BUILD_PLATFORM",
                "COPTI",
                "COPTML",
                "COPTMLD",
                "COPTX",
                "COPTY",
293 294
                "DLZ_SYSTEM_TEST",
                "EXEEXT",
295 296 297 298
                "INTRINSIC",
                "MACHINE",
                "OPENSSL_PATH",
                "PLATFORM",
299
                "PLATFORM_TOOLSET",
300
                "prefix",
301
                "PSSUSPEND",
302
                "PYTHON",
303 304
                "TOOLS_VERSION",
                "VCREDIST_PATH",
305
                "WINDOWS_TARGET_PLATFORM_VERSION");
306 307 308 309 310

# defines

my %configdefd;

311
my @substdefd = ("PK11_LIB_LOCATION",
312
                 "USE_PYTHON");
313 314 315 316 317

# conditions

my %configcond;

318
my @substcond = ("ATOMIC",
319 320 321 322 323 324 325
                 "GSSAPI",
                 "GEOIP",
                 "IDNKIT",
                 "LIBXML2",
                 "OPENSSL",
                 "PKCS11",
                 "PYTHON",
326
                 "SAMPLES",
327
                 "STESTS",
328
                 "TESTS",
Francis Dupont's avatar
Francis Dupont committed
329 330 331
                 "ZLIB");

my @allcond = (@substcond, "NOTYET", "NOLONGER");
332

333 334 335 336 337 338 339
# paths

my $top_builddir = File::Spec->updir();
my $top_srcdir = File::Spec->updir();
my $abs_top_builddir = File::Spec->rel2abs($top_builddir);
my $abs_top_srcdir = File::Spec->rel2abs($top_srcdir);

340 341 342 343
# arguments

# enable-xxx/disable-xxx

344
my @enablelist = ("developer",
345 346
                  "fixed-rrset",
                  "intrinsics",
Evan Hunt's avatar
Evan Hunt committed
347
                  "native-pkcs11",
348
                  "openssl-hash",
349
                  "querytrace");
350 351 352

# with-xxx/without-xxx

353 354
my @withlist = ("aes",
                "cross-compile",
355 356
                "extra-tests",
                "gssapi",
357
                "geoip2",
358 359 360 361
                "iconv",
                "idn",
                "openssl",
                "libxml2",
362
                "nghttp2",
363
                "pkcs11",
364
                "pssuspend",
365 366
                "python",
                "readline",
367
                "samples",
368
                "system-tests",
369
                "tests",
370
                "tuning",
371
                "libuv",
Francis Dupont's avatar
Francis Dupont committed
372 373
                "vcredist",
                "zlib");
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397

# general arguments

my @optionlist = ("help", "verbose", "legacy", "win32", "x64", "clean");

# usage

my @usage = ("Usage: perl Configure help\n",
             "       perl Configure options* win32|x64\n",
             "       perl Configure clean\n");

# help

my @help = (
"'Configure' configures BIND9 build files.\n\n",
@usage,
"\nGeneral Options and Commands:\n",
"  verbose               (options) print messages\n",
"  help                  (command) print this help\n",
"  win32                 (command) configure for Win32 platform\n",
"  x64                   (command) configure for x64 platform\n",
"  clean                 (command) clean up generated files\n",
"  <none>                (command) print a summary of the configuration\n",
"\nOptional Features:\n",
398
"  enable-intrinsics     enable intrinsic/atomic functions [default=yes]\n",
Evan Hunt's avatar
Evan Hunt committed
399
"  enable-native-pkcs11  use native PKCS#11 for all crypto [default=no]\n",
400
"  enable-openssl-hash   use OpenSSL for hash functions [default=yes]\n",
401 402
"  enable-fixed-rrset    enable fixed rrset ordering [default=no]\n",
"  enable-developer      enable developer build settings [default=no]\n",
403
"  enable-querytrace     enable very verbose query trace [default=no]\n",
404 405 406
"\nOptional Packages:\n",
"  with-tests            build with test suite\n",
"  with-extra-tests      build with extra test suite\n",
407
"  with-system-tests     build with system test suite\n",
408
"  with-samples          build with sample programs\n",
409
"  with-openssl[=PATH]   build with OpenSSL yes|path (mandatory)\n",
410
"  with-libuv[=PATH]     build with libuv yes|path (mandatory)\n",
411
"  with-nghttp2[=PATH]   build with nghttp2 yes|path (mandatory)\n",
412 413 414
"  with-pkcs11[=PATH]    build with PKCS#11 support yes|no|provider-path\n",
"  with-gssapi[=PATH]    build with MIT KfW GSSAPI yes|no|path\n",
"  with-libxml2[=PATH]   build with libxml2 library yes|no|path\n",
415
"  with-geoip2[=PATH]    build with GeoIP2 support yes|no|path\n",
416
"  with-pssuspend[=COMMAND] specify pssuspend command\n",
417 418 419 420
"  with-python[=COMMAND] specify python interpreter python|command\n",
"  with-readline[=PATH]  build with readline library support yes|no|path\n",
"  with-idn[=PATH]       build with IDN kit support yes|no|path\n",
"  with-iconv[=PATH]     path of the iconv DLL [default=same than idn]\n",
Francis Dupont's avatar
Francis Dupont committed
421
"  with-zlib[=PATH]      build with zlib library yes|no|path\n",
Evan Hunt's avatar
Evan Hunt committed
422
"  with-vcredist[=PATH]  visual C++ redistributable package yes|path\n",
423
"  with-tuning=OPTION    tune for platform size (small|default)\n",
424 425 426 427 428
"  with-cross-compile    32 / 64 bit build / host platforms\n",
"\nOptional Visual Studio project parameters:\n",
"  with-tools-version=VERSION     set the ToolsVersion attribute to VERSION\n",
"  with-platform-toolset=VERSION  use supplied toolset VERSION for building\n",
"  with-platform-version=VERSION  use supplied Windows SDK VERSION for building\n");
429 430 431 432 433 434 435 436 437 438 439 440

# Parse arguments

my $verbose = 0;
my $legacy_only = 0;
my $want_help = "no";
my $want_win32 = "no";
my $want_x64 = "no";
my $want_clean = "no";
my $want_unknown = "no";
my $unknown_value;
my $enable_intrinsics = "yes";
Evan Hunt's avatar
Evan Hunt committed
441
my $cryptolib = "";
Evan Hunt's avatar
Evan Hunt committed
442
my $enable_native_pkcs11 = "no";
Evan Hunt's avatar
Evan Hunt committed
443
my $enable_crypto_rand = "yes";
444 445
my $enable_fixed_rrset = "no";
my $enable_developer = "no";
446
my $enable_querytrace = "no";
447 448 449
my $enable_rpz_nsip = "yes";
my $enable_rpz_nsdname = "yes";
my $use_tests = "no";
450
my $use_stests = "no";
451
my $use_samples = "no";
452
my $use_libuv = "auto";
453
my $libuv_path = "../../";
454 455
my $nghttp2_path = "../../";
my $use_nghttp2 = "auto";
456
my $use_openssl = "auto";
457
my $openssl_path = "../../";
458 459
my $use_pkcs11 = "no";
my $pkcs11_path = "unknown";
460
my $use_aes = "auto";
461
my $use_gssapi = "no";
462
my $validation_default = "auto";
463
my $gssapi_path = "C:/Program\ Files/MIT/Kerberos/";
464 465
my $use_geoip2 = "no";
my $geoip2_path = "";
466
my $use_libxml2 = "auto";
467
my $libxml2_path = "../../";
468 469
my $with_pssuspend = "no";
my $pssuspend_command = "pssuspend.exe";
470
my $use_python = "auto";
471
my $python_command = "python.exe";
472
my $use_readline = "no";
473
my $readline_path = "../../";
474
my $use_idn = "no";
475
my $idn_path = "../../";
476
my $iconv_path = " --idn-- ";
Francis Dupont's avatar
Francis Dupont committed
477
my $use_zlib = "no";
478
my $zlib_path = "../../";
479 480 481
my $use_vcredist = "yes";
my $vcredist_path = " --infer-- ";
my $cross_compile = "no";
482
my $tuning = "default";
483
my $want_checkfiles = "no";
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503

# no arguments -> usage

if ($#ARGV < 0) {
    foreach (@usage) {
        print $_;
    }
    exit 1;
}

# parse arguments

foreach (@ARGV) {
    if (/^verbose$/i) {
        $verbose = 1;
    } elsif (/^help$/i) {
        $want_help = "yes";
    } elsif (/^disable-(.*)$/i) {
        appargs($_);
        myenable($1, "no");
Francis Dupont's avatar
Francis Dupont committed
504
    } elsif (/^enable-(.*)$/i) {
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524
        appargs($_);
        myenable($1, "yes");
    } elsif (/^without-(.*)$/i) {
        appargs($_);
        mywith($1, "no");
    } elsif (/^with-(.*)=(.*)$/i) {
        appargs($_);
        mywith($1, $2);
    } elsif (/^with-(.*)$/i) {
        appargs($_);
        mywith($1, "yes");
    } elsif (/^legacy$/i) {
        $legacy_only = 1;
    } elsif (/^win32$/i) {
        $want_win32 = "yes";
    } elsif (/^x64$/i) {
        appargs($_);
        $want_x64 = "yes";
    } elsif (/^clean$/i) {
        $want_clean = "yes";
525 526
    } elsif (/^checkfiles$/i) {
        $want_checkfiles = "yes";
527 528 529 530 531 532
    } else {
        $want_unknown = "yes";
        $unknown_value = $_;
    }
}

533
# old legacy mode
534

535 536
if ($legacy_only) {
    print "legacy mode is obsolete (so ignored)\n";
537 538
}

539
if ($want_checkfiles eq "yes") {
540
        my $status=0;
541
        foreach (@filelist) {
542
                my $name = $_;
543
                $name =~ s/\\/\//g;
544 545 546
                next if -r $_ . ".in";
                s/\\/\//g;
                next if -r $_ . ".in";
547 548
                print "remove '$name' from filelist in win32utils/Configure or add to repository\n";
                $status = 1;
549 550
        }
        foreach (@projectlist) {
551
                my $name = $_;
552
                $name =~ s/\\/\//g;
553 554 555
                next if -r $_ . ".in";
                s/\\/\//g;
                next if -r $_ . ".in";
556 557
                print "remove '$name' from projectlist in win32utils/Configure or add to repository\n";
                $status = 1;
558
        }
559
        exit($status);
560 561
}

562 563 564 565 566 567 568 569 570 571 572 573 574 575 576
# configure the platform

if (($want_win32 eq "yes") && ($want_x64 eq "yes")) {
    die "can't ask for both Win32 and x64 platforms\n";
} elsif ($want_win32 eq "yes") {
    $configvar{"PLATFORM"} = "Win32";
    $configvar{"BUILD_PLATFORM"} = "Win32";
    $configvar{"MACHINE"} = "/machine:X86";
    $configvar{"BUILD_MACHINE"} = "/machine:X86";
} elsif ($want_x64 eq "yes") {
    $configvar{"PLATFORM"} = "x64";
    $configvar{"BUILD_PLATFORM"} = "x64";
    $configvar{"MACHINE"} = "/machine:X64";
    $configvar{"BUILD_MACHINE"} = "/machine:X64";
}
577 578
# Standard configure variable
$configvar{"EXEEXT"} = ".exe";
579

580 581 582
$configtest{"builddir"} = kw(".");
$configtest{"srcdir"} = kw(".");
$configtest{"abs_top_builddir"} = kw($abs_top_builddir);
583
$configtest{"abs_top_builddir"} =~ s/\\/\//g;
584
$configtest{"abs_top_srcdir"} = kw($abs_top_srcdir);
585
$configtest{"abs_top_srcdir"} =~ s/\\/\//g;
586

587 588 589 590 591 592 593 594 595 596 597 598 599 600 601
# Mimic AC_INIT() from autoconf by loading values from configure.ac

sub ac_init {
    my $package_name;
    my $package_bugreport;
    my $package_url;
    my $package_version;
    my $package_version_major;
    my $package_version_minor;
    my $package_version_patch;
    my $package_version_extra;
    my $package_description;
    my $package_srcid;
    my $mapapi;

602
    open V, "../configure.ac" || die $!;
Francis Dupont's avatar
Francis Dupont committed
603 604
    while (<V>) {
        chomp;
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620
        if (/^AC_INIT\(\[(.*?)\],\s*bind_PKG_VERSION,\s*\[(.*?)\],\s*\[(.*?)\],\s*\[(.*?)\]\)$/) {
	    $package_name = $1;
	    $package_bugreport = $2;
	    $package_url = $4;
        } elsif (/m4_define\(\[bind_VERSION_MAJOR\],\s*(.*?)\)/) {
	    $package_version_major = $1;
        } elsif (/m4_define\(\[bind_VERSION_MINOR\],\s*(.*?)\)/) {
	    $package_version_minor = $1;
        } elsif (/m4_define\(\[bind_VERSION_PATCH\],\s*(.*?)\)/) {
	    $package_version_patch = $1;
        } elsif (/m4_define\(\[bind_VERSION_EXTRA\],\s*(.*?)\)/) {
	    $package_version_extra = $1;
        } elsif (/m4_define\(\[bind_DESCRIPTION\],\s*\[(.*?)\]\)/) {
	    $package_description = $1;
        } elsif (/AC_DEFINE\(\[MAPAPI\],\s*\[(.*?)\],\s*\[.*?\]\)/) {
	    $mapapi = $1;
Francis Dupont's avatar
Francis Dupont committed
621 622 623 624
        }
    }
    close V;

625 626
    $package_version = "${package_version_major}.${package_version_minor}.${package_version_patch}${package_version_extra}";

627
    my $srcid_fn = "../srcid";
628 629 630 631 632 633 634 635

    if (-f $srcid_fn) {
        open(my $fh, '<', $srcid_fn) or die "cannot open file $srcid_fn";
        {
            local $/;
            $package_srcid = <$fh>;
        }
	close($fh);
636
    } elsif (-d "../.git") {
637 638 639
        $package_srcid = substr(`git rev-list --max-count=1 HEAD`, 0, 7);
    } else {
        $package_srcid = "";
Francis Dupont's avatar
Francis Dupont committed
640
    }
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665
    chomp($package_srcid);

    if (length($package_srcid) == 0) {
        $package_srcid = "unset_id";
    }
    if ($verbose) {
        print "BIND SRCID: $package_srcid\n";
    }

    # Now define those in config.h

    $configdefh{'PACKAGE_NAME'} = "\"$package_name\"";
    $configdefh{'PACKAGE_BUGREPORT'} = "\"$package_bugreport\"";
    $configdefh{'PACKAGE_URL'} = "\"$package_url\"";

    $configdefh{'PACKAGE_VERSION_MAJOR'} = "\"$package_version_major\"";
    $configdefh{'PACKAGE_VERSION_MINOR'} = "\"$package_version_minor\"";
    $configdefh{'PACKAGE_VERSION_PATCH'} = "\"$package_version_patch\"";
    $configdefh{'PACKAGE_VERSION_EXTRA'} = "\"$package_version_extra\"";
    $configdefh{'PACKAGE_DESCRIPTION'} = "\" $package_description\"";
    $configdefh{'PACKAGE_SRCID'} = "\"$package_srcid\"";

    $configdefh{'PACKAGE_VERSION'} = "\"$package_version\"";
    $configdefh{'PACKAGE_STRING'} = "\"$package_name $package_version\"";
    $configdefh{'MAPAPI'} = $mapapi;
Francis Dupont's avatar
Francis Dupont committed
666 667
}

668
ac_init();
Francis Dupont's avatar
Francis Dupont committed
669

670 671 672 673
# append seen args to CONFIGARGS define

sub appargs {
    my $arg = $_[0];
674 675 676
    # escape backslashes and double quotes
    $arg =~ s/([\\"])/\\$1/g;
    $arg =~ s/([\s])/\\\\$1/g;
677 678
    if (defined($configdefh{"PACKAGE_CONFIGARGS"})) {
        $configdefh{"PACKAGE_CONFIGARGS"} .= " " . $arg;
679
    } else {
680
        $configdefh{"PACKAGE_CONFIGARGS"} = $arg;
681 682 683
    }
}

684
if (!$configdefh{"PACKAGE_CONFIGARGS"}) {
685
    # CONFIGARGS default is "default"
686
    $configdefh{"PACKAGE_CONFIGARGS"} = "\"default\"";
687
} else {
688 689
    my $val = $configdefh{"PACKAGE_CONFIGARGS"};
    $configdefh{"PACKAGE_CONFIGARGS"} = "\"'$val'\"";
690 691 692 693 694 695 696 697 698 699 700 701
}

# parse enable/disable

sub myenable {
    my $key = $_[0];
    my $val = $_[1];

    if ($key =~ /^intrinsics$/i) {
        if ($val =~ /^no$/i) {
            $enable_intrinsics = "no";
        }
Evan Hunt's avatar
Evan Hunt committed
702 703 704 705
    } elsif ($key =~ /^native-pkcs11$/i) {
        if ($val =~ /^yes$/i) {
            $enable_native_pkcs11 = "yes";
        }
706 707 708 709 710 711 712 713
    } elsif ($key =~ /^fixed-rrset$/i) {
        if ($val =~ /^yes$/i) {
            $enable_fixed_rrset = "yes";
        }
    } elsif ($key =~ /^developer$/i) {
        if ($val =~ /^yes$/i) {
            $enable_developer = "yes";
        }
714 715 716 717
    } elsif ($key =~ /^querytrace$/i) {
        if ($val =~ /^yes$/i) {
            $enable_querytrace = "yes";
        }
718
    } elsif ($key =~ /^auto-validation$/i) {
719 720 721
        if ($val =~ /^no$/i) {
            $validation_default = "yes";
        }
722 723 724 725 726 727 728 729 730 731 732 733 734
    } else {
        $want_unknown = "yes";
        if ($val eq "no") {
            $unknown_value = "disable-" . $key;
        } else {
            $unknown_value = "enable-". $key;
        }
    }
}

# enable-developer expansion now

if ($enable_developer eq "yes") {
735
    $configtest{"DEVELOPER_MODE"} = "yes";
736
    $configdefh{"ISC_LIST_CHECKINIT"} = 1;
737
    $enable_querytrace = "yes";
738 739 740 741
    # no atf on WIN32
    $enable_fixed_rrset = "yes";
    # TODO: dlz filesystem
    $use_tests = "yes";
742
    $use_stests = "yes";
743
    $use_samples = "yes";
744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759
}

# parse with/without

sub mywith {
    my $key = $_[0];
    my $val = $_[1];

    if ($key =~ /^tests$/i) {
        if ($val =~ /^yes$/i) {
            $use_tests = "yes";
        }
    } elsif ($key =~ /^extra-tests$/i) {
        if ($val =~ /^yes$/i) {
            $use_tests = "yes";
        }
760 761 762 763 764
    } elsif ($key =~ /^system-tests$/i) {
        if ($val =~ /^yes$/i) {
            $use_tests = "yes";
            $use_stests = "yes";
        }
765 766 767 768
    } elsif ($key =~ /^samples$/i) {
        if ($val =~ /^yes$/i) {
            $use_samples = "yes";
        }
769 770
    } elsif ($key =~ /^openssl$/i) {
        if ($val =~ /^no$/i) {
771
            die "OpenSSL support is now mandatory\n";
772 773 774 775
        } elsif ($val !~ /^yes$/i) {
            $use_openssl = "yes";
            $openssl_path = $val;
        }
776 777 778 779 780 781 782
    } elsif ($key =~ /^libuv$/i) {
        if ($val =~ /^no$/i) {
            die "libuv is required\n";
        } elsif ($val !~ /^yes$/i) {
            $use_libuv = "yes";
            $libuv_path = $val;
        }
783 784 785 786 787 788 789
    } elsif ($key =~ /^nghttp2$/i) {
        if ($val =~ /^no$/i) {
            die "nghttp2 is required\n";
        } elsif ($val !~ /^yes$/i) {
            $use_nghttp2 = "yes";
            $nghttp2_path = $val;
        }
790 791 792 793 794 795 796 797
    } elsif ($key =~ /^pkcs11$/i) {
        if ($val =~ /^yes$/i) {
            $use_pkcs11 = "yes";
        } elsif ($val !~ /^no$/i) {
            $use_pkcs11= "yes";
            $pkcs11_path = $val;
            $pkcs11_path =~ s/\.dll$//i;
        }
798 799 800 801 802 803
    } elsif ($key =~ /^aes$/i) {
        if ($val =~ /^no$/i) {
            $use_aes = "no";
        } elsif ($val =~ /^yes$/i) {
            $use_aes = "yes";
        }
804 805 806 807 808 809 810 811 812 813 814 815 816 817
    } elsif ($key =~ /^gssapi$/i) {
        if ($val !~ /^no$/i) {
            $use_gssapi = "yes";
            if ($val !~ /^yes$/i) {
                $gssapi_path = $val;
            }
        }
    } elsif ($key =~ /^libxml2$/i) {
        if ($val =~ /^no$/i) {
            $use_libxml2 = "no";
        } elsif ($val !~ /^yes$/i) {
            $use_libxml2 = "yes";
            $libxml2_path = $val;
        }
818
    } elsif ($key =~ /^geoip2$/i) {
819
        if ($val !~ /^no$/i) {
820
            $use_geoip2 = "yes";
821
            if ($val !~ /^yes$/i) {
822 823
                $geoip2_path = $val;
            } else {
824
                $geoip2_path = "../../GeoIP2";
825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847
            }
        }
    } elsif ($key =~ /^readline$/i) {
        if ($val !~ /^no$/i) {
            $use_readline = "yes";
            if ($val !~ /^yes$/i) {
                $readline_path = $val;
            }
        }
    } elsif ($key =~ /^idn$/i) {
        if ($val !~ /^no$/i) {
            $use_idn = "yes";
            if ($val !~ /^yes$/i) {
                $idn_path = $val;
            }
        }
    } elsif ($key =~ /^iconv$/i) {
        if ($val =~ /^no$/i) {
            $want_unknown = "yes";
            $unknown_value = "without-iconv doesn't make sense)";
        } elsif ($val !~ /^yes$/i) {
            $iconv_path = $val;
        }
Francis Dupont's avatar
Francis Dupont committed
848 849 850 851 852 853 854
    } elsif ($key =~ /^zlib$/i) {
        if ($val !~ /^no$/i) {
            $use_zlib = "yes";
            if ($val !~ /^yes$/i) {
                $zlib_path = $val;
            }
        }
855
    } elsif ($key =~ /^pssuspend$/i) {
856 857 858 859 860 861
        if ($val =~ /^no$/i) {
            $with_pssuspend = "no";
        } else {
            if ($val !~ /^yes$/i) {
                $pssuspend_command = $val;
            }
862
        }
863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882
    } elsif ($key =~ /^python$/i) {
        if ($val =~ /^no$/i) {
            $use_python = "no";
        } else {
            $use_python = "yes";
            if ($val !~ /^yes$/i) {
                $python_command = $val;
            }
        }
    } elsif ($key =~ /^vcredist$/i) {
        if ($val =~ /^no$/i) {
            $want_unknown = "yes";
            $unknown_value = "without-vcredist (vcredist is required)";
        } elsif ($val !~ /^yes$/i) {
            $vcredist_path = $val;
        }
    } elsif ($key =~ /^cross-compile$/i) {
        if ($val =~ /^yes$/i) {
            $cross_compile = "yes";
        }
883
    } elsif ($key =~ /^tuning$/i) {
884 885
        if ($val =~ /^small$/i) {
            $tuning = "small";
886
        }
887 888 889 890 891 892
    } elsif ($key =~ /^tools-version$/i) {
        $configvar{"TOOLS_VERSION"} = $val;
    } elsif ($key =~ /^platform-version$/i) {
        $configvar{"WINDOWS_TARGET_PLATFORM_VERSION"} = "<WindowsTargetPlatformVersion>$val</WindowsTargetPlatformVersion>";
    } elsif ($key =~ /^platform-toolset$/i) {
        $configvar{"PLATFORM_TOOLSET"} = "<PlatformToolset>$val</PlatformToolset>";
893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912
    } else {
        $want_unknown = "yes";
        if ($val eq "no") {
            $unknown_value = "without-" . $key;
        } else {
            $unknown_value = "with-" . $key;
        }
    }
}

if ($want_help ne "no") {
    foreach (@help) {
        print $_;
    }
    exit 1;
}

# clean up and exit if requested
if ($want_clean eq "yes") {
    my $file;
913 914 915

    unlink($configfile);
    unlink($platformfile);
916 917 918 919

    foreach $file (@confshlist) {
	unlink($file);
    }
920

921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958
    foreach $file (@filelist) {
        unlink($file);
    }

    foreach $file (@projectlist) {
        unlink($file);
    }

    exit 0;
}

if ($want_unknown ne "no") {
    print STDERR "can't parse $unknown_value\n";
    exit 1;
}

if ($verbose) {
    if ($want_win32 eq "yes") {
        print "configure for win32\n";
    }
    if ($want_x64 eq "yes") {
        print "configure for x64\n";
    }
    if ($cross_compile eq "yes") {
        print "cross compiling";
        if ($want_x64 eq "yes") {
            print ": build on win32 for x64 host\n";
        } elsif ($want_win32 eq "yes") {
            print ": build on x64 for win32 host\n";
        } else {
            print "\n";
        }
    }
    if ($enable_intrinsics eq "yes") {
        print "intrinsics: enabled\n";
    } else {
        print "intrinsics: disabled\n";
    }
Evan Hunt's avatar
Evan Hunt committed
959 960 961 962 963
    if ($enable_native_pkcs11 eq "yes") {
        print "native-pkcs11: enabled\n";
    } else {
        print "native-pkcs11: disabled\n";
    }
Ondřej Surý's avatar
Ondřej Surý committed
964
    print "openssl-hash: enabled\n";
965 966 967 968 969 970 971 972 973 974
    if ($enable_fixed_rrset eq "yes") {
        print "fixed-rrset: enabled\n";
    } else {
        print "fixed-rrset: disabled\n";
    }
    if ($enable_developer eq "yes") {
        print "developer: enabled\n";
    } else {
        print "developer: disabled\n";
    }
975 976 977 978 979
    if ($enable_querytrace eq "yes") {
        print "querytrace: enabled\n";
    } else {
        print "querytrace: disabled\n";
    }
980
    print "libuv-path: $libuv_path\n";
981
    print "nghttp2-path: $nghttp2_path\n";
Ondřej Surý's avatar
Ondřej Surý committed
982
    print "openssl-path: $openssl_path\n";
983 984 985
    if ($use_tests eq "yes") {
        print "tests: enabled\n";
    }
986 987 988
    if ($use_stests eq "yes") {
        print "system tests: enabled\n";
    }
989 990 991
    if ($use_samples eq "yes") {
        print "sample programs: enabled\n";
    }
992 993 994 995 996
    if ($use_pkcs11 eq "no") {
        print "pkcs11: disabled\n";
    } else {
        print "pkcs11-provider-path: $pkcs11_path\n";
    }
997 998 999 1000 1001
    if ($use_aes eq "no") {
        print "aes: disabled\n";
    } else {
        print "aes: enabled\n";
    }
1002 1003 1004 1005 1006 1007 1008 1009 1010 1011
    if ($use_gssapi eq "no") {
        print "gssapi: disabled\n";
    } else {
        print "gssapi-path: $gssapi_path\n";
    }
    if ($use_libxml2 eq "no") {
        print "libxml2: disabled\n";
    } else {
        print "libxml2-path: $libxml2_path\n";
    }
1012 1013
    if ($use_geoip2 eq "no") {
        print "geoip2: disabled\n";
1014
    } else {
1015
        print "geoip2-path: $geoip2_path\n";
1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029
    }
    if ($use_readline eq "no") {
        print "readline: disabled\n";
    } else {
        print "readline-path: $readline_path\n";
    }
    if ($use_idn eq "no") {
        print "idn: disabled\n";
    } else {
        print "idn-path: $idn_path\n";
        if ($iconv_path ne " --idn-- ") {
            print "iconv-path: $iconv_path\n";
        }
    }
Francis Dupont's avatar
Francis Dupont committed
1030 1031 1032 1033 1034
    if ($use_zlib eq "no") {
        print "zlib: disabled\n";
    } else {
        print "zlib-path: $zlib_path\n";
    }
1035 1036 1037 1038 1039
    if ($with_pssuspend eq "no") {
        print "pssuspend: disabled\n";
    } else {
        print "pssuspend-command: $pssuspend_command\n";
    }
1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054
    if ($use_python eq "no") {
        print "python: disabled\n";
    } else {
        print "python-command: $python_command\n";
    }
    print "vcredist-path: $vcredist_path\n";
}

# Check environment

# infer vcredist when not given
if ($vcredist_path eq " --infer-- ") {
    if ($verbose) {
        print "trying to infer vcredist path from build environment\n";
    }
1055 1056 1057

    my @vcpaths = {};
    push(@vcpaths, $ENV{"VCRedistPath"}) if ($ENV{"VCRedistPath"} ne "");
1058
    push(@vcpaths, File::Spec->catdir( File::Spec->curdir(), "..", ".." ));
1059 1060

    if ($ENV{"FrameworkSDKDir"} ne "" && $want_win32 eq "yes") {
1061
        push(@vcpaths, File::Spec->catdir($ENV{"FrameworkSDKDir"},
1062 1063 1064
                                           "BootStrapper", "Packages",
                                           "vcredist_x86"));
    } elsif ($ENV{"FrameworkSDKDir"} ne "" && $want_x64 eq "yes") {
1065
        push(@vcpaths, File::Spec->catdir($ENV{"FrameworkSDKDir"},
1066 1067 1068 1069 1070
                                           "BootStrapper", "Packages",
                                           "vcredist_x64"));
    }

    if ($ENV{"WindowsSDKDir"} ne "" && $want_win32 eq "yes") {
1071
        push(@vcpaths, File::Spec->catdir($ENV{"WindowsSDKDir"},
1072 1073 1074
                                           "BootStrapper", "Packages",
                                           "vcredist_x86"));
    } elsif ($ENV{"WindowsSDKDir"} ne "" && $want_x64 eq "yes") {
1075
        push(@vcpaths, File::Spec->catdir($ENV{"WindowsSDKDir"},
1076 1077 1078 1079 1080
                                           "BootStrapper", "Packages",
                                           "vcredist_x64"));
    }

    if ($ENV{"WindowsSDKDir_old"} ne "" && $want_win32 eq "yes") {
1081
        push(@vcpaths, File::Spec->catdir($ENV{"WindowsSDKDir_old"},
1082 1083 1084
                                           "BootStrapper", "Packages",
                                           "vcredist_x86"));
    } elsif ($ENV{"WindowsSDKDir_old"} ne "" && $want_x64 eq "yes") {
1085
        push(@vcpaths, File::Spec->catdir($ENV{"WindowsSDKDir_old"},
1086 1087 1088 1089 1090
                                           "BootStrapper", "Packages",
                                           "vcredist_x64"));
    }

    if ($ENV{"VCINSTALLDIR"}) {
1091
        push(@vcpaths, File::Spec->catdir($ENV{"VCINSTALLDIR"},
1092 1093 1094
                                           "redist", "1033"));
    }

1095 1096 1097 1098 1099
    # 'VCToolsRedistDir' is available since Visual Studio 2017.
    if ($ENV{"VCToolsRedistDir"}) {
        push(@vcpaths, $ENV{"VCToolsRedistDir"});
    }

1100 1101 1102
    my $rfile;
    if ($want_win32 eq "yes") {
        $rfile = "vcredist_x86.exe";
1103
    } else {
1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115
        $rfile = "vcredist_x64.exe";
    }

    foreach (@vcpaths) {
        my $vp = File::Spec->catfile($_, $rfile);
        if (-f $vp) {
            $vcredist_path = $vp;
            last;
        }
    }

    if ($vcredist_path eq " --infer-- ") {
1116 1117
        die "with-vcredist is REQUIRED\n";
    }
1118 1119 1120 1121

    if ($verbose) {
        print "found vcredist at " . $vcredist_path . "\n";
    }
1122 1123 1124 1125 1126 1127 1128