5 ## Configure -- OpenSSL source tree configuration script
6 ## If editing this file, run this command before committing
7 ## make -f Makefile.in TABLE
13 use File::Spec::Functions;
15 # see INSTALL for instructions.
17 my $usage="Usage: Configure [no-<cipher> ...] [enable-<cipher> ...] [experimental-<cipher> ...] [-Dxxx] [-lxxx] [-Lxxx] [-fxxx] [-Kxxx] [no-hw-xxx|no-hw] [[no-]threads] [[no-]shared] [[no-]zlib|zlib-dynamic] [no-asm] [no-dso] [no-egd] [sctp] [386] [--prefix=DIR] [--openssldir=OPENSSLDIR] [--with-xxx[=vvv]] [--config=FILE] os/compiler[:flags]\n";
21 # --config add the given configuration file, which will be read after
22 # any "Configurations*" files that are found in the same
23 # directory as this script.
24 # --prefix prefix for the OpenSSL installation, which includes the
25 # directories bin, lib, include, share/man, share/doc/openssl
26 # This becomes the value of INSTALLTOP in Makefile
27 # (Default: /usr/local)
28 # --openssldir OpenSSL data area, such as openssl.cnf, certificates and keys.
29 # If it's a relative directory, it will be added on the directory
30 # given with --prefix.
31 # This becomes the value of OPENSSLDIR in Makefile and in C.
32 # (Default: PREFIX/ssl)
34 # --install_prefix Additional prefix for package builders (empty by
35 # default). This needn't be set in advance, you can
36 # just as well use "make INSTALL_PREFIX=/whatever install".
38 # --cross-compile-prefix Add specified prefix to binutils components.
40 # --api One of 0.9.8, 1.0.0 or 1.1.0. Do not compile support for
41 # interfaces deprecated as of the specified OpenSSL version.
43 # no-hw-xxx do not compile support for specific crypto hardware.
44 # Generic OpenSSL-style methods relating to this support
45 # are always compiled but return NULL if the hardware
46 # support isn't compiled.
47 # no-hw do not compile support for any crypto hardware.
48 # [no-]threads [don't] try to create a library that is suitable for
49 # multithreaded applications (default is "threads" if we
51 # [no-]shared [don't] try to create shared libraries when supported.
52 # no-asm do not use assembler
53 # no-dso do not compile in any native shared-library methods. This
54 # will ensure that all methods just return NULL.
55 # no-egd do not compile support for the entropy-gathering daemon APIs
56 # [no-]zlib [don't] compile support for zlib compression.
57 # zlib-dynamic Like "zlib", but the zlib library is expected to be a shared
58 # library and will be loaded in run-time by the OpenSSL library.
59 # sctp include SCTP support
60 # 386 generate 80386 code
61 # no-sse2 disables IA-32 SSE2 code, above option implies no-sse2
62 # no-<cipher> build without specified algorithm (rsa, idea, rc5, ...)
63 # -<xxx> +<xxx> compiler options are passed through
65 # DEBUG_SAFESTACK use type-safe stacks to enforce type-safety on stack items
66 # provided to stack calls. Generates unique stack functions for
67 # each possible stack type.
68 # BN_LLONG use the type 'long long' in crypto/bn/bn.h
69 # RC4_CHAR use 'char' instead of 'int' for RC4_INT in crypto/rc4/rc4.h
70 # Following are set automatically by this script
72 # MD5_ASM use some extra md5 assember,
73 # SHA1_ASM use some extra sha1 assember, must define L_ENDIAN for x86
74 # RMD160_ASM use some extra ripemd160 assember,
75 # SHA256_ASM sha256_block is implemented in assembler
76 # SHA512_ASM sha512_block is implemented in assembler
77 # AES_ASM ASE_[en|de]crypt is implemented in assembler
79 # Minimum warning options... any contributions to OpenSSL should at least get
82 my $gcc_devteam_warn = "-Wall -pedantic -DPEDANTIC -Wno-long-long -Wsign-compare -Wmissing-prototypes -Wshadow -Wformat -Wtype-limits -Werror -DREF_CHECK -DDEBUG_UNUSED";
84 # These are used in addition to $gcc_devteam_warn when the compiler is clang.
85 # TODO(openssl-team): fix problems and investigate if (at least) the
86 # following warnings can also be enabled:
87 # -Wswitch-enum, -Wunused-macros, -Wmissing-field-initializers,
89 # -Wunreachable-code -Wunused-parameter -Wlanguage-extension-token
91 my $clang_devteam_warn = "-Wno-unused-parameter -Wno-missing-field-initializers -Wno-language-extension-token -Wno-extended-offsetof -Wconditional-uninitialized -Qunused-arguments -Wincompatible-pointer-types-discards-qualifiers -Wmissing-variable-declarations";
93 # Warn that "make depend" should be run?
94 my $warn_make_depend = 0;
96 # These are used in addition to $gcc_devteam_warn unless this is a mingw build.
97 # This adds backtrace information to the memory leak info.
98 my $memleak_devteam_backtrace = "-rdynamic -DCRYPTO_MDEBUG_BACKTRACE";
100 my $strict_warnings = 0;
102 # As for $BSDthreads. Idea is to maintain "collective" set of flags,
103 # which would cover all BSD flavors. -pthread applies to them all,
104 # but is treated differently. OpenBSD expands is as -D_POSIX_THREAD
105 # -lc_r, which is sufficient. FreeBSD 4.x expands it as -lc_r,
106 # which has to be accompanied by explicit -D_THREAD_SAFE and
107 # sometimes -D_REENTRANT. FreeBSD 5.x expands it as -lc_r, which
108 # seems to be sufficient?
109 my $BSDthreads="-pthread -D_THREAD_SAFE -D_REENTRANT";
112 # API compability name to version number mapping.
114 my $maxapi = "1.1.0"; # API for "no-deprecated" builds
116 "1.1.0" => "0x10100000L",
117 "1.0.0" => "0x10000000L",
118 "0.9.8" => "0x00908000L",
121 my $base_target = "BASE"; # The template that all other inherit from
125 # Forward declarations ###############################################
127 # read_config(filename)
129 # Reads a configuration file and populates %table with the contents
130 # (which the configuration file places in %targets).
133 # resolve_config(target)
135 # Resolves all the late evalutations, inheritances and so on for the
136 # chosen target and any target it inherits from.
140 # Information collection #############################################
142 # Collect version numbers
143 $config{version} = "unknown";
144 $config{version_num} = "unknown";
145 $config{shlib_version_number} = "unknown";
146 $config{shlib_version_history} = "unknown";
149 '<include/openssl/opensslv.h',
151 qr/OPENSSL.VERSION.TEXT.*OpenSSL (\S+) / => sub { $config{version} = $1; },
152 qr/OPENSSL.VERSION.NUMBER.*(0x\S+)/ => sub { $config{version_num}=$1 },
153 qr/SHLIB_VERSION_NUMBER *"([^"]+)"/ => sub { $config{shlib_version_number}=$1 },
154 qr/SHLIB_VERSION_HISTORY *"([^"]*)"/ => sub { $config{shlib_version_history}=$1 }
156 if ($config{shlib_version_history} ne "") { $config{shlib_version_history} .= ":"; }
158 ($config{major}, $config{minor})
159 = ($config{version} =~ /^([0-9]+)\.([0-9\.]+)/);
160 ($config{shlib_major}, $config{shlib_minor})
161 = ($config{shlib_version_number} =~ /^([0-9]+)\.([0-9\.]+)/);
162 die "erroneous version information in opensslv.h: ",
163 "$config{major}, $config{minor}, $config{shlib_major}, $config{shlib_minor}\n"
164 if ($config{major} eq "" || $config{minor} eq ""
165 || $config{shlib_major} eq "" || $config{shlib_minor} eq "");
167 # Collect target configurations
169 my ($vol, $dir, $dummy) = File::Spec->splitpath($0);
170 my $pattern = File::Spec->catpath($vol, $dir, "Configurations/*.conf");
171 foreach (sort glob($pattern) ) {
176 print "Configuring OpenSSL version $config{version} (0x$config{version_num})\n";
180 $config{openssldir}="";
181 $config{processor}="";
183 $config{install_prefix}= "$ENV{'INSTALL_PREFIX'}";
184 $config{cross_compile_prefix}="";
185 $config{fipslibdir}="/usr/local/ssl/fips-2.0/lib/";
186 my $nofipscanistercheck=0;
187 $config{baseaddr}="0xFB00000";
190 $config{no_shared}=0; # but "no-shared" is default
191 my $zlib=1; # but "no-zlib" is default
198 # Top level directories to build
199 $config{dirs} = [ "crypto", "ssl", "engines", "apps", "test", "tools" ];
200 # crypto/ subdirectories to build
203 "md2", "md4", "md5", "sha", "mdc2", "hmac", "ripemd", "whrlpool", "poly1305",
204 "des", "aes", "rc2", "rc4", "rc5", "idea", "bf", "cast", "camellia", "seed", "chacha", "modes",
205 "bn", "ec", "rsa", "dsa", "dh", "dso", "engine",
206 "buffer", "bio", "stack", "lhash", "rand", "err",
207 "evp", "asn1", "pem", "x509", "x509v3", "conf", "txt_db", "pkcs7", "pkcs12", "comp", "ocsp", "ui",
208 "cms", "ts", "jpake", "srp", "store", "cmac", "ct", "async", "kdf"
211 # Known TLS and DTLS protocols
212 my @tls = qw(ssl3 tls1 tls1_1 tls1_2);
213 my @dtls = qw(dtls1 dtls1_2);
215 # Explicitelly known options that are possible to disable. They can
216 # be regexps, and will be used like this: /^no-${option}$/
217 # For developers: keep it sorted alphabetically
244 "ec_nistp_64_gcc_128",
252 "locking", # Really???
269 "rijndael", # Old AES name
294 foreach my $proto ((@tls, @dtls))
296 push(@disablables, $proto);
297 push(@disablables, "$proto-method");
300 # All of the following is disabled by default (RC5 was enabled before 0.9.8):
302 my %disabled = ( # "what" => "comment" [or special keyword "experimental"]
303 "ec_nistp_64_gcc_128" => "default",
305 "jpake" => "experimental",
309 "shared" => "default",
310 "ssl-trace" => "default",
311 "store" => "experimental",
312 "unit-test" => "default",
314 "zlib-dynamic" => "default",
315 "crypto-mdebug" => "default",
317 my @experimental = ();
319 # Note: => pair form used for aesthetics, not to truly make a hash table
320 my @disable_cascades = (
321 # "what" => [ "cascade", ... ]
322 sub { $config{processor} eq "386" }
325 "ssl3-method" => [ "ssl3" ],
326 "zlib" => [ "zlib-dynamic" ],
327 "rijndael" => [ "aes" ],
329 "ec" => [ "ecdsa", "ecdh" ],
330 "psk" => [ "jpake" ],
332 "dgram" => [ "dtls" ],
335 # SSL 3.0, (D)TLS 1.0 and TLS 1.1 require MD5 and SHA
336 "md5" => [ "ssl", "tls1", "tls1_1", "dtls1" ],
337 "sha" => [ "ssl", "tls1", "tls1_1", "dtls1" ],
339 # Additionally, SSL 3.0 requires either RSA or DSA+DH
341 && ($disabled{dsa} || $disabled{dh}); }
344 # (D)TLS 1.0 and TLS 1.1 also require either RSA or DSA+DH
345 # or ECDSA + ECDH. (D)TLS 1.2 has this requirement as well.
346 # (XXX: We don't support PSK-only builds).
348 && ($disabled{dsa} || $disabled{dh})
349 && ($disabled{ecdsa} || $disabled{ecdh}); }
350 => [ "tls1", "tls1_1", "tls1_2",
351 "dtls1", "dtls1_2" ],
355 # SRP and HEARTBEATS require TLSEXT
356 "tlsext" => [ "srp", "heartbeats" ],
359 # Avoid protocol support holes. Also disable all versions below N, if version
360 # N is disabled while N+1 is enabled.
362 my @list = (reverse @tls);
363 while ((my $first, my $second) = (shift @list, shift @list)) {
365 push @disable_cascades, ( sub { !$disabled{$first} && $disabled{$second} }
367 unshift @list, $second;
369 my @list = (reverse @dtls);
370 while ((my $first, my $second) = (shift @list, shift @list)) {
372 push @disable_cascades, ( sub { !$disabled{$first} && $disabled{$second} }
374 unshift @list, $second;
377 # Construct the string of what $config{depflags} should look like with the defaults
378 # from %disabled above. (we need this to see if we should advise the user
379 # to run "make depend"):
380 my $default_depflags = join(" ",
381 map { my $x = $_; $x =~ tr{[a-z]-}{[A-Z]_}; "-DOPENSSL_NO_$x"; }
382 grep { $disabled{$_} !~ /\(no-depflags\)$/ }
383 sort keys %disabled);
385 # Explicit "no-..." options will be collected in %disabled along with the defaults.
386 # To remove something from %disabled, use "enable-foo" (unless it's experimental).
387 # For symmetry, "disable-foo" is a synonym for "no-foo".
389 # For features called "experimental" here, a more explicit "experimental-foo" is needed to enable.
390 # We will collect such requests in @experimental.
391 # To avoid accidental use of experimental features, applications will have to use -DOPENSSL_EXPERIMENTAL_FOO.
396 &usage if ($#ARGV < 0);
399 $config{depflags}="";
400 $config{openssl_experimental_defines}=[];
401 $config{openssl_api_defines}=[];
402 $config{openssl_algorithm_defines}=[];
403 $config{openssl_thread_defines}=[];
404 $config{openssl_sys_defines}=[];
405 $config{openssl_other_defines}=[];
411 my $build_prefix = "release_";
415 if (grep /^reconf(igure)?$/, @argvcopy) {
416 if (-f "./configdata.pm") {
417 my $file = "./configdata.pm";
418 unless (my $return = do $file) {
419 die "couldn't parse $file: $@" if $@;
420 die "couldn't do $file: $!" unless defined $return;
421 die "couldn't run $file" unless $return;
424 @argvcopy = defined($configdata::config{perlargv}) ?
425 @{$configdata::config{perlargv}} : ();
426 die "Incorrect data to reconfigure, please do a normal configuration\n"
427 if (grep(/^reconf/,@argvcopy));
428 $ENV{CROSS_COMPILE} = $configdata::config{cross_compile_prefix}
429 if defined($configdata::config{cross_compile_prefix});
430 $ENV{CROSS_COMPILE} = $configdata::config{cc}
431 if defined($configdata::config{cc});
433 print "Reconfiguring with: ", join(" ",@argvcopy), "\n";
434 print " CROSS_COMPILE = ",$ENV{CROSS_COMPILE},"\n"
435 if $ENV{CROSS_COMPILE};
436 print " CC = ",$ENV{CC},"\n" if $ENV{CC};
437 } elsif (open IN, "<Makefile") {
439 # THIS SECTION IS TEMPORARY, it helps transitioning from Makefile
440 # centered information gathering the reading configdata.pm
444 if (/^CONFIGURE_ARGS=\s*(.*)\s*/) {
445 # Older form, we split the string and hope for the best
446 @argvcopy = split /\s+/, $_;
447 die "Incorrect data to reconfigure, please do a normal configuration\n"
448 if (grep(/^reconf/,@argvcopy));
449 } elsif (/^CROSS_COMPILE=\s*(.*)/) {
450 $ENV{CROSS_COMPILE}=$1;
451 } elsif (/^CC=\s*(?:\$\(CROSS_COMPILE\))?(.*?)$/) {
456 # END OF TEMPORARY SECTION
459 die "Insufficient data to reconfigure, please do a normal configuration\n";
463 $config{perlargv} = [ @argvcopy ];
465 my %unsupported_options = ();
468 s /^-no-/no-/; # some people just can't read the instructions
470 # rewrite some options in "enable-..." form
471 s /^-?-?shared$/enable-shared/;
472 s /^sctp$/enable-sctp/;
473 s /^threads$/enable-threads/;
474 s /^zlib$/enable-zlib/;
475 s /^zlib-dynamic$/enable-zlib-dynamic/;
477 if (/^(no|disable|enable|experimental)-(.+)$/)
480 if (!grep { $word =~ /^${_}$/ } @disablables)
482 $unsupported_options{$_} = 1;
486 if (/^no-(.+)$/ || /^disable-(.+)$/)
488 if (!($disabled{$1} eq "experimental"))
490 foreach my $proto ((@tls, @dtls))
492 if ($1 eq "$proto-method")
494 $disabled{"$proto"} = "option($proto-method)";
500 foreach my $proto (@dtls)
502 $disabled{$proto} = "option(dtls)";
507 # Last one of its kind
508 $disabled{"ssl3"} = "option(ssl)";
512 # XXX: Tests will fail if all SSL/TLS
513 # protocols are disabled.
514 foreach my $proto (@tls)
516 $disabled{$proto} = "option(tls)";
521 $disabled{$1} = "option";
525 elsif (/^enable-(.+)$/ || /^experimental-(.+)$/)
528 if ($disabled{$algo} eq "experimental")
530 die "You are requesting an experimental feature; please say 'experimental-$algo' if you are sure\n"
531 unless (/^experimental-/);
532 push @experimental, $algo;
534 delete $disabled{$algo};
536 $threads = 1 if ($algo eq "threads");
538 elsif (/^--strict-warnings$/)
540 $strict_warnings = 1;
544 $build_prefix = "debug_";
546 elsif (/^--release$/)
548 $build_prefix = "release_";
551 { $config{processor}=386; }
558 # No RSAref support any more since it's not needed.
559 # The check for the option is there so scripts aren't
562 elsif (/^nofipscanistercheck$/)
565 $nofipscanistercheck = 1;
569 if (/^--prefix=(.*)$/)
573 elsif (/^--api=(.*)$/)
577 elsif (/^--libdir=(.*)$/)
581 elsif (/^--openssldir=(.*)$/)
583 $config{openssldir}=$1;
585 elsif (/^--install.prefix=(.*)$/)
587 $config{install_prefix}=$1;
589 elsif (/^--with-zlib-lib=(.*)$/)
591 $withargs{"zlib-lib"}=$1;
593 elsif (/^--with-zlib-include=(.*)$/)
595 $withargs{"zlib-include"}="-I$1";
597 elsif (/^--with-fipslibdir=(.*)$/)
599 $config{fipslibdir}="$1/";
601 elsif (/^--with-baseaddr=(.*)$/)
603 $config{baseaddr}="$1";
605 elsif (/^--cross-compile-prefix=(.*)$/)
607 $config{cross_compile_prefix}=$1;
609 elsif (/^--config=(.*)$/)
613 elsif (/^-[lL](.*)$/ or /^-Wl,/)
617 else # common if (/^[-+]/), just pass down...
619 $_ =~ s/%([0-9a-f]{1,2})/chr(hex($1))/gei;
623 elsif ($_ =~ /^([^:]+):(.+)$/)
625 eval "\$table{\$1} = \"$2\""; # allow $xxx constructs in the string
630 die "target already defined - $target (offending arg: $_)\n" if ($target ne "");
633 unless ($_ eq $target || /^no-/ || /^disable-/)
635 # "no-..." follows later after implied disactivations
636 # have been derived. (Don't take this too seroiusly,
637 # we really only write OPTIONS to the Makefile out of
640 if ($config{options} eq "")
641 { $config{options} = $_; }
643 { $config{options} .= " ".$_; }
646 if (defined($config{api}) && !exists $apitable->{$config{api}}) {
647 die "***** Unsupported api compatibility level: $config{api}\n",
650 if (keys %unsupported_options)
652 die "***** Unsupported options: ",
653 join(", ", keys %unsupported_options), "\n";
659 delete $disabled{"shared"} if ($disabled{"shared"} =~ /^default/);
663 @{$config{dirs}} = grep !/^fips$/, @{$config{dirs}};
666 my @tocheckfor = (keys %disabled);
667 while (@tocheckfor) {
668 my %new_tocheckfor = ();
669 my @cascade_copy = (@disable_cascades);
670 while (@cascade_copy) {
671 my ($test, $descendents) = (shift @cascade_copy, shift @cascade_copy);
672 if (ref($test) eq "CODE" ? $test->() : defined($disabled{$test})) {
674 $new_tocheckfor{$_} => 1; $disabled{$_} = "forced";
675 } grep { !defined($disabled{$_}) } @$descendents;
678 @tocheckfor = (keys %new_tocheckfor);
681 if ($target eq "TABLE") {
682 foreach (sort keys %table) {
683 print_table_entry($_, "TABLE");
688 if ($target eq "LIST") {
689 foreach (sort keys %table) {
690 print $_,"\n" unless $table{$_}->{template};
695 if ($target eq "HASH") {
696 print "%table = (\n";
697 foreach (sort keys %table) {
698 print_table_entry($_, "HASH");
703 # Backward compatibility?
704 if ($target =~ m/^CygWin32(-.*)$/) {
705 $target = "Cygwin".$1;
708 foreach (sort (keys %disabled))
710 $config{options} .= " no-$_";
712 printf " no-%-12s %-10s", $_, "[$disabled{$_}]";
719 { $config{no_shared} = 1; }
722 elsif (/^static-engine$/)
724 elsif (/^zlib-dynamic$/)
729 { @{$config{dirs}} = grep !/^engine$/, @{$config{dirs}}; }
733 ($ALGO = $algo = $_) =~ tr/[\-a-z]/[_A-Z]/;
735 if (/^asm$/ || /^err$/ || /^hw$/ || /^hw-/)
737 push @{$config{openssl_other_defines}}, "OPENSSL_NO_$ALGO";
738 print " OPENSSL_NO_$ALGO";
740 if (/^err$/) { $flags .= "-DOPENSSL_NO_ERR "; }
741 elsif (/^asm$/) { $no_asm = 1; }
745 ($ALGO,$algo) = ("RMD160","rmd160") if ($algo eq "ripemd");
747 push @{$config{openssl_algorithm_defines}}, "OPENSSL_NO_$ALGO";
748 $config{depflags} .= " -DOPENSSL_NO_$ALGO";
749 print " OPENSSL_NO_$ALGO";
751 # fix-up crypto/directory name(s)
752 $algo="whrlpool" if $algo eq "whirlpool";
753 $algo="ripemd" if $algo eq "rmd160";
754 @{$config{sdirs}} = grep { $_ ne $algo} @{$config{sdirs}};
765 foreach (sort @experimental)
768 ($ALGO = $_) =~ tr/[a-z]/[A-Z]/;
770 # opensslconf.h will set OPENSSL_NO_... unless OPENSSL_EXPERIMENTAL_... is defined
771 push @{$config{openssl_experimental_defines}}, "OPENSSL_NO_$ALGO";
772 $exp_cflags .= " -DOPENSSL_EXPERIMENTAL_$ALGO";
775 print "Configuring for $target\n";
777 # Support for legacy targets having a name starting with 'debug-'
778 my ($d, $t) = $target =~ m/^(debug-)?(.*)$/;
780 $build_prefix = "debug_";
782 # If we do not find debug-foo in the table, the target is set to foo.
783 if (!$table{$target}) {
787 $config{target} = $target;
788 delete $table{$base_target}->{template}; # or the next test will fail.
789 my %target = ( %{$table{$base_target}}, resolve_config($target) );
791 &usage if (!%target || $target{template});
793 $target{exe_extension}="";
794 $target{exe_extension}=".exe" if ($config{target} eq "Cygwin" || $config{target} eq "DJGPP" || $config{target} =~ /^mingw/);
795 $target{exe_extension}=".nlm" if ($config{target} =~ /netware/);
796 $target{exe_extension}=".pm" if ($config{target} =~ /vos/);
798 $default_ranlib = which("ranlib") || "true";
799 $config{perl} = $ENV{'PERL'} || which("perl5") || which("perl") || "perl";
800 my $make = $ENV{'MAKE'} || "make";
802 $config{cross_compile_prefix} = $ENV{'CROSS_COMPILE'}
803 if $config{cross_compile_prefix} eq "";
805 $config{prefix} = "/usr/local" if !$config{prefix};
806 $config{openssldir} = "ssl" if !$config{openssldir};
807 $config{openssldir} = catdir($config{prefix}, $config{openssldir})
808 unless file_name_is_absolute($config{openssldir});
810 # Allow environment CC to override compiler...
811 $target{cc} = $ENV{CC} || $target{cc};
813 # For cflags, lflags and ex_libs, add the debug_ or release_ attributes
814 # Do it in such a way that no spurious space is appended (hence the grep).
815 $config{cflags} = join(" ",
816 grep { $_ ne "" } ($target{cflags},
817 $target{$build_prefix."cflags"}));
818 $config{lflags} = join(" ",
819 grep { $_ ne "" } ($target{lflags},
820 $target{$build_prefix."lflags"}));
821 $config{ex_libs} = join(" ",
822 grep { $_ ne "" } ($target{ex_libs},
823 $target{$build_prefix."ex_libs"}));
825 $target{ranlib} = $ENV{'RANLIB'} || $target{ranlib} || $default_ranlib;
826 $target{ar} = $ENV{'AR'} || "ar";
827 $target{arflags} = "" if !defined($target{arflags});
829 # Make sure build_scheme is consistent.
830 $target{build_scheme} = [ $target{build_scheme} ]
831 if ref($target{build_scheme}) ne "ARRAY";
833 # if $config{prefix}/lib$target{multilib} is not an existing directory, then
834 # assume that it's not searched by linker automatically, in
835 # which case adding $target{multilib} suffix causes more grief than
836 # we're ready to tolerate, so don't...
837 $target{multilib}="" if !-d "$config{prefix}/lib$target{multilib}";
839 $config{libdir}="lib$target{multilib}" if $config{libdir} eq "";
840 $config{enginesdir}=$config{prefix} . "/" . $config{libdir} . "/engines";
842 $config{cflags} .= "$exp_cflags";
844 if ($target =~ /^mingw/ && `$target{cc} --target-help 2>&1` !~ m/-mno-cygwin/m)
846 $config{cflags} =~ s/-mno-cygwin\s*//;
847 $target{shared_ldflag} =~ s/-mno-cygwin\s*//;
850 if ($target =~ /linux.*-mips/ && !$no_asm && $flags !~ /-m(ips|arch=)/) {
851 # minimally required architecture flags for assembly modules
852 $config{cflags}="-mips2 $config{cflags}" if ($target =~ /mips32/);
853 $config{cflags}="-mips3 $config{cflags}" if ($target =~ /mips64/);
856 my $no_shared_warn=0;
857 my $no_user_cflags=0;
859 if ($flags ne "") { $config{cflags}="$flags$config{cflags}"; }
860 else { $no_user_cflags=1; }
862 # The DSO code currently always implements all functions so that no
863 # applications will have to worry about that from a compilation point
864 # of view. However, the "method"s may return zero unless that platform
865 # has support compiled in for them. Currently each method is enabled
866 # by a define "DSO_<name>" ... we translate the "dso_scheme" config
867 # string entry into using the following logic;
869 if (!$no_dso && $target{dso_scheme} ne "")
871 $target{dso_scheme} =~ tr/[a-z]/[A-Z]/;
872 if ($target{dso_scheme} eq "DLFCN")
874 $dso_cflags = "-DDSO_DLFCN -DHAVE_DLFCN_H";
876 elsif ($target{dso_scheme} eq "DLFCN_NO_H")
878 $dso_cflags = "-DDSO_DLFCN";
882 $dso_cflags = "-DDSO_$target{dso_scheme}";
884 $config{cflags} = "$dso_cflags $config{cflags}";
887 my $thread_cflags = "";
889 if ($target{thread_cflag} ne "(unknown)" && !$no_threads)
891 # If we know how to do it, support threads by default.
894 if ($target{thread_cflag} eq "(unknown)" && $threads)
896 # If the user asked for "threads", [s]he is also expected to
897 # provide any system-dependent compiler options that are
901 print "You asked for multi-threading support, but didn't\n";
902 print "provide any system-specific compiler options\n";
905 $thread_cflags="-DOPENSSL_THREADS" ;
906 push @thread_defines, "OPENSSL_THREADS";
910 $thread_cflags="-DOPENSSL_THREADS $target{thread_cflag}";
911 push @thread_defines, "OPENSSL_THREADS";
914 $config{ex_libs}="$libs$config{ex_libs}" if ($libs ne "");
918 $config{cflags}=~s/-D[BL]_ENDIAN// if ($config{fips});
923 $config{cflags} = "$thread_cflags $config{cflags}" if $thread_cflags;
924 push @{$config{openssl_thread_defines}}, @thread_defines;
929 $config{cflags} = "-DZLIB $config{cflags}";
930 if (defined($disabled{"zlib-dynamic"}))
932 if (defined($withargs{"zlib-lib"}))
934 $config{ex_libs} .= " -L" . $withargs{"zlib-lib"} . " -lz";
938 $config{ex_libs} .= " -lz";
943 $config{cflags} = "-DZLIB_SHARED $config{cflags}";
947 # With "deprecated" disable all deprecated features.
948 if (defined($disabled{"deprecated"})) {
949 $config{api} = $maxapi;
952 if ($target{shared_target} eq "")
954 $no_shared_warn = 1 if !$config{no_shared} && !$config{fips};
955 $config{no_shared} = 1;
957 if (!$config{no_shared})
959 if ($target{shared_cflag} ne "")
961 $config{cflags} = "$target{shared_cflag} -DOPENSSL_PIC $config{cflags}";
965 if ($target{build_scheme}->[0] ne "mk1mf")
967 # add {no-}static-engine to options to allow mkdef.pl to work without extra arguments
968 if ($config{no_shared})
970 push @{$config{openssl_other_defines}}, "OPENSSL_NO_DYNAMIC_ENGINE";
971 $config{options}.=" static-engine";
975 push @{$config{openssl_other_defines}}, "OPENSSL_NO_STATIC_ENGINE";
976 $config{options}.=" no-static-engine";
983 # Unlike other OSes (like Solaris, Linux, Tru64, IRIX) BSD run-time
984 # linkers (tested OpenBSD, NetBSD and FreeBSD) "demand" RPATH set on
985 # .so objects. Apparently application RPATH is not global and does
986 # not apply to .so linked with other .so. Problem manifests itself
987 # when libssl.so fails to load libcrypto.so. One can argue that we
988 # should engrave this into Makefile.shared rules or into BSD-* config
989 # lines above. Meanwhile let's try to be cautious and pass -rpath to
990 # linker only when --prefix is not /usr.
991 if ($target =~ /^BSD-/)
993 $target{shared_ldflag}.=" -Wl,-rpath,\$\$(LIBRPATH)" if ($config{prefix} !~ m|^/usr[/]*$|);
996 if ($target{sys_id} ne "")
998 #$config{cflags}="-DOPENSSL_SYS_$target{sys_id} $config{cflags}";
999 push @{$config{openssl_sys_defines}}, "OPENSSL_SYS_$target{sys_id}";
1002 if ($target{ranlib} eq "")
1004 $target{ranlib} = $default_ranlib;
1008 $target{cpuid_obj}=$table{BASE}->{cpuid_obj} if ($config{processor} eq "386");
1009 $target{cpuid_obj}.=" uplink.o uplink-x86.o" if ($config{cflags} =~ /-DOPENSSL_USE_APPLINK/);
1011 $target{bn_obj} =~ s/\w+-gf2m.o// if (defined($disabled{ec2m}));
1013 # bn-586 is the only one implementing bn_*_part_words
1014 $config{cflags}.=" -DOPENSSL_BN_ASM_PART_WORDS" if ($target{bn_obj} =~ /bn-586/);
1015 $config{cflags}.=" -DOPENSSL_IA32_SSE2" if (!$no_sse2 && $target{bn_obj} =~ /86/);
1017 $config{cflags}.=" -DOPENSSL_BN_ASM_MONT" if ($target{bn_obj} =~ /-mont/);
1018 $config{cflags}.=" -DOPENSSL_BN_ASM_MONT5" if ($target{bn_obj} =~ /-mont5/);
1019 $config{cflags}.=" -DOPENSSL_BN_ASM_GF2m" if ($target{bn_obj} =~ /-gf2m/);
1021 if ($config{fips}) {
1022 push @{$config{openssl_other_defines}}, "OPENSSL_FIPS";
1025 if ($target{sha1_obj} =~ /\.o$/) {
1026 $config{cflags}.=" -DSHA1_ASM" if ($target{sha1_obj} =~ /sx86/ || $target{sha1_obj} =~ /sha1/);
1027 $config{cflags}.=" -DSHA256_ASM" if ($target{sha1_obj} =~ /sha256/);
1028 $config{cflags}.=" -DSHA512_ASM" if ($target{sha1_obj} =~ /sha512/);
1029 if ($target{sha1_obj} =~ /sse2/) {
1031 $target{sha1_obj} =~ s/\S*sse2\S+//;
1032 } elsif ($config{cflags} !~ /OPENSSL_IA32_SSE2/) {
1033 $config{cflags}.=" -DOPENSSL_IA32_SSE2";
1037 if ($target{md5_obj} =~ /\.o$/) {
1038 $config{cflags}.=" -DMD5_ASM";
1040 $target{cast_obj}=$table{BASE}->{cast_obj} if (!$config{no_shared}); # CAST assembler is not PIC
1041 if ($target{rmd160_obj} =~ /\.o$/) {
1042 $config{cflags}.=" -DRMD160_ASM";
1044 if ($target{aes_obj} =~ /\.o$/) {
1045 $config{cflags}.=" -DAES_ASM" if ($target{aes_obj} =~ m/\baes-/);;
1046 # aes-ctr.o is not a real file, only indication that assembler
1047 # module implements AES_ctr32_encrypt...
1048 $config{cflags}.=" -DAES_CTR_ASM" if ($target{aes_obj} =~ s/\s*aes-ctr\.o//);
1049 # aes-xts.o indicates presence of AES_xts_[en|de]crypt...
1050 $config{cflags}.=" -DAES_XTS_ASM" if ($target{aes_obj} =~ s/\s*aes-xts\.o//);
1051 $target{aes_obj} =~ s/\s*(vpaes|aesni)-x86\.o//g if ($no_sse2);
1052 $config{cflags}.=" -DVPAES_ASM" if ($target{aes_obj} =~ m/vpaes/);
1053 $config{cflags}.=" -DBSAES_ASM" if ($target{aes_obj} =~ m/bsaes/);
1055 if ($target{wp_obj} =~ /mmx/) {
1056 if ($config{processor} eq "386") {
1057 $target{wp_obj}=$table{BASE}->{wp_obj};
1058 } elsif (!$disabled{"whirlpool"}) {
1059 $config{cflags}.=" -DWHIRLPOOL_ASM";
1062 if ($target{modes_obj} =~ /ghash-/) {
1063 $config{cflags}.=" -DGHASH_ASM";
1065 if ($target{ec_obj} =~ /ecp_nistz256/) {
1066 $config{cflags}.=" -DECP_NISTZ256_ASM";
1068 if ($target{poly1305_obj} =~ /\.o$/) {
1069 $config{cflags}.=" -DPOLY1305_ASM";
1073 my $ecc = $target{cc};
1074 $ecc = "clang" if `$target{cc} --version 2>&1` =~ /clang/;
1076 $config{makedepprog} =
1077 $ecc eq "gcc" || $ecc eq "clang" ? $target{cc} : "makedepend";
1078 $config{depflags} =~ s/^\s*//;
1081 # Deal with bn_ops ###################################################
1084 $config{export_var_as_fn} =0;
1085 my $def_int="unsigned int";
1086 $config{rc4_int} =$def_int;
1087 ($config{b64l},$config{b64},$config{b32})=(0,0,1);
1090 foreach (sort split(/\s+/,$target{bn_ops})) {
1091 $count++ if /SIXTY_FOUR_BIT|SIXTY_FOUR_BIT_LONG|THIRTY_TWO_BIT/;
1092 $config{export_var_as_fn}=1 if $_ eq 'EXPORT_VAR_AS_FN';
1093 $config{bn_ll}=1 if $_ eq 'BN_LLONG';
1094 $config{rc4_int}="unsigned char" if $_ eq 'RC4_CHAR';
1095 ($config{b64l},$config{b64},$config{b32})
1096 =(0,1,0) if $_ eq 'SIXTY_FOUR_BIT';
1097 ($config{b64l},$config{b64},$config{b32})
1098 =(1,0,0) if $_ eq 'SIXTY_FOUR_BIT_LONG';
1099 ($config{b64l},$config{b64},$config{b32})
1100 =(0,0,1) if $_ eq 'THIRTY_TWO_BIT';
1102 die "Exactly one of SIXTY_FOUR_BIT|SIXTY_FOUR_BIT_LONG|THIRTY_TWO_BIT can be set in bn_ops\n"
1106 # Hack cflags for better warnings (dev option) #######################
1108 # "Stringify" the C flags string. This permits it to be made part of a string
1109 # and works as well on command lines.
1110 $config{cflags} =~ s/([\\\"])/\\\1/g;
1112 if (defined($config{api})) {
1113 $config{openssl_api_defines} = [ "OPENSSL_MIN_API=".$apitable->{$config{api}} ];
1114 my $apiflag = sprintf("-DOPENSSL_API_COMPAT=%s", $apitable->{$config{api}});
1115 $default_depflags .= " $apiflag";
1116 $config{cflags} .= " $apiflag";
1119 if ($strict_warnings)
1122 die "ERROR --strict-warnings requires gcc or clang" unless ($ecc =~ /gcc(-\d(\.\d)*)?$/ or $ecc =~ /clang$/);
1123 foreach $wopt (split /\s+/, $gcc_devteam_warn)
1125 $config{cflags} .= " $wopt" unless ($config{cflags} =~ /(^|\s)$wopt(\s|$)/)
1127 if ($ecc eq "clang")
1129 foreach $wopt (split /\s+/, $clang_devteam_warn)
1131 $config{cflags} .= " $wopt" unless ($config{cflags} =~ /(^|\s)$wopt(\s|$)/)
1134 if ($target !~ /^mingw/)
1136 foreach $wopt (split /\s+/, $memleak_devteam_backtrace)
1138 $config{cflags} .= " $wopt" unless ($config{cflags} =~ /(^|\s)$wopt(\s|$)/)
1140 if ($target =~ /^BSD-/)
1142 $config{ex_libs} .= " -lexecinfo";
1147 # Write down our configuration where it fits #########################
1149 open(OUT,">configdata.pm") || die "unable to create configdata.pm: $!\n";
1157 #use vars qw(\@ISA \@EXPORT);
1158 our \@ISA = qw(Exporter);
1159 our \@EXPORT = qw(\%config \%target %withargs);
1162 print OUT "our %config = (\n";
1163 foreach (sort keys %config) {
1164 if (ref($config{$_}) eq "ARRAY") {
1165 print OUT " ", $_, " => [ ", join(", ",
1166 map { quotify("perl", $_) }
1167 @{$config{$_}}), " ],\n";
1169 print OUT " ", $_, " => ", quotify("perl", $config{$_}), ",\n"
1176 print OUT "our %target = (\n";
1177 foreach (sort keys %target) {
1178 if (ref($target{$_}) eq "ARRAY") {
1179 print OUT " ", $_, " => [ ", join(", ",
1180 map { quotify("perl", $_) }
1181 @{$target{$_}}), " ],\n";
1183 print OUT " ", $_, " => ", quotify("perl", $target{$_}), ",\n"
1190 print OUT "our \%available_protocols = (\n";
1191 print OUT " tls => [ ", join(", ", map { quotify("perl", $_) } @tls), " ],\n";
1192 print OUT " dtls => [ ", join(", ", map { quotify("perl", $_) } @dtls), " ],\n";
1197 print OUT "our \%disabled = (\n";
1198 foreach (sort keys %disabled) {
1199 print OUT " ", quotify("perl", $_), " => ", quotify("perl", $disabled{$_}), ",\n";
1205 print OUT "our %withargs = (\n";
1206 foreach (sort keys %withargs) {
1207 if (ref($withargs{$_}) eq "ARRAY") {
1208 print OUT " ", $_, " => [ ", join(", ",
1209 map { quotify("perl", $_) }
1210 @{$withargs{$_}}), " ],\n";
1212 print OUT " ", $_, " => ", quotify("perl", $withargs{$_}), ",\n"
1222 print "IsMK1MF =", ($target{build_scheme}->[0] eq "mk1mf" ? "yes" : "no"), "\n";
1223 print "CC =$target{cc}\n";
1224 print "CFLAG =$config{cflags}\n";
1225 print "LFLAGS =$config{lflags}\n";
1226 print "EX_LIBS =$config{ex_libs}\n";
1227 print "CPUID_OBJ =$target{cpuid_obj}\n";
1228 print "BN_ASM =$target{bn_obj}\n";
1229 print "EC_ASM =$target{ec_obj}\n";
1230 print "DES_ENC =$target{des_obj}\n";
1231 print "AES_ENC =$target{aes_obj}\n";
1232 print "BF_ENC =$target{bf_obj}\n";
1233 print "CAST_ENC =$target{cast_obj}\n";
1234 print "RC4_ENC =$target{rc4_obj}\n";
1235 print "RC5_ENC =$target{rc5_obj}\n";
1236 print "MD5_OBJ_ASM =$target{md5_obj}\n";
1237 print "SHA1_OBJ_ASM =$target{sha1_obj}\n";
1238 print "RMD160_OBJ_ASM=$target{rmd160_obj}\n";
1239 print "CMLL_ENC =$target{cmll_obj}\n";
1240 print "MODES_OBJ =$target{modes_obj}\n";
1241 print "PADLOCK_OBJ =$target{padlock_obj}\n";
1242 print "CHACHA_ENC =$target{chacha_obj}\n";
1243 print "POLY1305_OBJ =$target{poly1305_obj}\n";
1244 print "PROCESSOR =$config{processor}\n";
1245 print "RANLIB =$target{ranlib}\n";
1246 print "ARFLAGS =$target{arflags}\n";
1247 print "PERL =$config{perl}\n";
1249 print "SIXTY_FOUR_BIT_LONG mode\n" if $config{b64l};
1250 print "SIXTY_FOUR_BIT mode\n" if $config{b64};
1251 print "THIRTY_TWO_BIT mode\n" if $config{b32};
1252 print "BN_LLONG mode\n" if $config{bn_ll};
1253 print "RC4 uses $config{rc4_int}\n" if $config{rc4_int} != $def_int;
1255 run_dofile("Makefile.in","Makefile");
1257 run_dofile("util/domd.in", "util/domd");
1258 chmod 0755, "util/domd";
1260 run_dofile("include/openssl/opensslconf.h.in", "include/openssl/opensslconf.h");
1262 foreach my $alg ( 'bn' ) {
1263 run_dofile("crypto/include/internal/${alg}_conf.h.in",
1264 "crypto/include/internal/${alg}_conf.h");
1267 # Copy all Makefile.in to Makefile (except top-level)
1276 return if ($_ ne "Makefile.in" || $File::Find::dir eq ".");
1277 my $in = IO::File->new($_, "r") or
1278 die sprintf "Error reading Makefile.in in %s: !$\n",
1280 my $out = IO::File->new("Makefile", "w") or
1281 die sprintf "Error writing Makefile in %s: !$\n",
1283 print $out "# Generated from $_, do not edit\n";
1284 while (my $line = <$in>) { print $out $line }
1286 die sprintf "Error reading Makefile.in in %s: !$\n",
1289 die sprintf "Error writing Makefile in %s: !$\n",
1297 my $make_command = "$make PERL=\'$config{perl}\'";
1298 my $make_targets = "";
1299 $make_targets .= " depend" if $config{depflags} ne $default_depflags && $make_depend;
1300 (system $make_command.$make_targets) == 0 or die "make $make_targets failed"
1301 if $make_targets ne "";
1302 if ($config{depflags} ne $default_depflags && !$make_depend) {
1303 $warn_make_depend++;
1307 open (OUT,">crypto/buildinf.h") || die "Can't open buildinf.h";
1310 /* auto-generated by Configure for crypto/cversion.c:
1311 * for Unix builds, crypto/Makefile.ssl generates functional definitions;
1312 * Windows builds (and other mk1mf builds) compile cversion.c with
1313 * -DMK1MF_BUILD and use definitions added to this file by util/mk1mf.pl. */
1314 #error "Windows builds (PLATFORM=$target) use mk1mf.pl-created Makefiles"
1319 # create the ms/version32.rc file if needed
1320 if (! grep /^netware/, @{$target{build_scheme}}) {
1321 my ($v1, $v2, $v3, $v4);
1322 if ($config{version_num} =~ /^0x([0-9a-f]{1})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{1})L$/i) {
1328 open (OUT,">ms/version32.rc") || die "Can't open ms/version32.rc";
1335 FILEVERSION $v1,$v2,$v3,$v4
1336 PRODUCTVERSION $v1,$v2,$v3,$v4
1343 FILEOS VOS__WINDOWS32
1347 BLOCK "StringFileInfo"
1352 VALUE "CompanyName", "The OpenSSL Project, http://www.openssl.org/\\0"
1353 VALUE "FileDescription", "OpenSSL Shared Library\\0"
1354 VALUE "FileVersion", "$config{version}\\0"
1356 VALUE "InternalName", "libeay32\\0"
1357 VALUE "OriginalFilename", "libeay32.dll\\0"
1359 VALUE "InternalName", "ssleay32\\0"
1360 VALUE "OriginalFilename", "ssleay32.dll\\0"
1362 VALUE "ProductName", "The OpenSSL Toolkit\\0"
1363 VALUE "ProductVersion", "$config{version}\\0"
1365 //VALUE "Comments", "\\0"
1366 VALUE "LegalCopyright", "Copyright © 1998-2015 The OpenSSL Project. Copyright © 1995-1998 Eric A. Young, Tim J. Hudson. All rights reserved.\\0"
1367 //VALUE "LegalTrademarks", "\\0"
1368 //VALUE "PrivateBuild", "\\0"
1369 //VALUE "SpecialBuild", "\\0"
1374 VALUE "Translation", 0x409, 0x4b0
1383 my ($builder, @builder_opts) = @{$target{build_scheme}};
1384 $builders{$builder}->(@builder_opts);
1388 Configured for $target.
1391 print <<"EOF" if (!$no_threads && !$threads);
1393 The library could not be configured for supporting multi-threaded
1394 applications as the compiler options required on this system are not known.
1395 See file INSTALL for details if you need multi-threading.
1398 print <<"EOF" if ($no_shared_warn);
1400 You gave the option 'shared', which is not supported on this platform, so
1401 we will pretend you gave the option 'no-shared'. If you know how to implement
1402 shared libraries, please let us know (but please first make sure you have
1403 tried with a current version of OpenSSL).
1406 print <<"EOF" if ($warn_make_depend);
1408 *** Because of configuration changes, you MUST do the following before
1416 ######################################################################
1418 # Helpers and utility functions
1421 # Configuration file reading #########################################
1423 # Helper function to implement conditional inheritance depending on the
1424 # value of $no_asm. Used in inherit_from values as follows:
1426 # inherit_from => [ "template", asm("asm_tmpl") ]
1435 # Helper function to implement adding values to already existing configuration
1436 # values. It handles elements that are ARRAYs, CODEs and scalars
1438 my $separator = shift;
1440 # If there's any ARRAY in the collection of values, we will return
1441 # an ARRAY of combined values, otherwise a string of joined values
1442 # with $separator as the separator.
1443 my $found_array = 0;
1447 if (ref($_) eq "ARRAY") {
1458 join($separator, @values);
1462 my $separator = shift;
1464 sub { _add($separator, @x, @_) };
1467 my $separator = shift;
1469 sub { _add($separator, @_, @x) };
1472 # configuration reader, evaluates the input file as a perl script and expects
1473 # it to fill %targets with target configurations. Those are then added to
1477 open(CONFFILE, "< $fname")
1478 or die "Can't open configuration file '$fname'!\n";
1481 my $content = <CONFFILE>;
1486 local %table = %::table; # Protect %table from tampering
1492 # For each target, check that it's configured with a hash table.
1493 foreach (keys %targets) {
1494 if (ref($targets{$_}) ne "HASH") {
1495 if (ref($targets{$_}) eq "") {
1496 warn "Deprecated target configuration for $_, ignoring...\n";
1498 warn "Misconfigured target configuration for $_ (should be a hash table), ignoring...\n";
1500 delete $targets{$_};
1504 %table = (%table, %targets);
1508 # configuration resolver. Will only resolve all the lazy evalutation
1509 # codeblocks for the chozen target and all those it inherits from,
1511 sub resolve_config {
1513 my @breadcrumbs = @_;
1515 if (grep { $_ eq $target } @breadcrumbs) {
1516 die "inherit_from loop! target backtrace:\n "
1517 ,$target,"\n ",join("\n ", @breadcrumbs),"\n";
1520 if (!defined($table{$target})) {
1521 warn "Warning! target $target doesn't exist!\n";
1524 # Recurse through all inheritances. They will be resolved on the
1525 # fly, so when this operation is done, they will all just be a
1526 # bunch of attributes with string values.
1527 # What we get here, though, are keys with references to lists of
1528 # the combined values of them all. We will deal with lists after
1529 # this stage is done.
1530 my %combined_inheritance = ();
1531 if ($table{$target}->{inherit_from}) {
1533 map { ref($_) eq "CODE" ? $_->() : $_ } @{$table{$target}->{inherit_from}};
1534 foreach (@inherit_from) {
1535 my %inherited_config = resolve_config($_, $target, @breadcrumbs);
1537 # 'template' is a marker that's considered private to
1538 # the config that had it.
1539 delete $inherited_config{template};
1542 if (!$combined_inheritance{$_}) {
1543 $combined_inheritance{$_} = [];
1545 push @{$combined_inheritance{$_}}, $inherited_config{$_};
1546 } keys %inherited_config;
1550 # We won't need inherit_from in this target any more, since we've
1551 # resolved all the inheritances that lead to this
1552 delete $table{$target}->{inherit_from};
1554 # Now is the time to deal with those lists. Here's the place to
1555 # decide what shall be done with those lists, all based on the
1556 # values of the target we're currently dealing with.
1557 # - If a value is a coderef, it will be executed with the list of
1558 # inherited values as arguments.
1559 # - If the corresponding key doesn't have a value at all or is the
1560 # emoty string, the inherited value list will be run through the
1561 # default combiner (below), and the result becomes this target's
1563 # - Otherwise, this target's value is assumed to be a string that
1564 # will simply override the inherited list of values.
1565 my $default_combiner = add(" ");
1568 map { $_ => 1 } (keys %combined_inheritance,
1569 keys %{$table{$target}});
1570 foreach (sort keys %all_keys) {
1572 # Current target doesn't have a value for the current key?
1573 # Assign it the default combiner, the rest of this loop body
1574 # will handle it just like any other coderef.
1575 if (!exists $table{$target}->{$_}) {
1576 $table{$target}->{$_} = $default_combiner;
1579 my $valuetype = ref($table{$target}->{$_});
1580 if ($valuetype eq "CODE") {
1581 # CODE reference, execute it with the inherited values as
1583 $table{$target}->{$_} =
1584 $table{$target}->{$_}->(@{$combined_inheritance{$_}});
1585 } elsif ($valuetype eq "ARRAY" || $valuetype eq "") {
1586 # ARRAY or Scalar, just leave it as is.
1588 # Some other type of reference that we don't handle.
1589 # Better to abort at this point.
1590 die "cannot handle reference type $valuetype,"
1591 ," found in target $target -> $_\n";
1595 # Finally done, return the result.
1596 return %{$table{$target}};
1601 print STDERR $usage;
1602 print STDERR "\npick os/compiler from:\n";
1606 foreach $i (sort keys %table)
1608 next if $table{$i}->{template};
1609 next if $i =~ /^debug/;
1610 $k += length($i) + 1;
1616 print STDERR $i . " ";
1618 foreach $i (sort keys %table)
1620 next if $table{$i}->{template};
1621 next if $i !~ /^debug/;
1622 $k += length($i) + 1;
1628 print STDERR $i . " ";
1630 print STDERR "\n\nNOTE: If in doubt, on Unix-ish systems use './config'.\n";
1639 unlink $out || warn "Can't remove $out, $!"
1641 die "Can't open $in, $!" unless -f $in;
1642 system("$config{perl} -I. -Mconfigdata util/dofile.pl -o\"Configure\" $in > $out.new");
1644 rename("$out.new", $out) || die "Can't rename $out.new, $!";
1647 # Configuration printer ##############################################
1649 sub print_table_entry
1652 my %target = resolve_config($target);
1655 # Don't print the templates
1656 return if $target{template};
1705 if ($type eq "TABLE") {
1707 print "*** $target\n";
1708 printf "\$%-12s = %s\n", $_, $target{$_} foreach (@sequence);
1709 } elsif ($type eq "HASH") {
1711 length((sort { length($a) <=> length($b) } @sequence)[-1]);
1712 print " '$target' => {\n";
1713 foreach (@sequence) {
1715 print " '",$_,"'"," " x ($largest - length($_))," => '",$target{$_},"',\n";
1722 # Utility routines ###################################################
1728 foreach $path (split /:/, $ENV{PATH})
1730 if (-f "$path/$name$target{exe_extension}" and -x _)
1732 return "$path/$name$target{exe_extension}" unless ($name eq "perl" and
1733 system("$path/$name$target{exe_extension} -e " . '\'exit($]<5.0);\''));
1740 perl => sub { my $x = shift;
1741 $x =~ s/([\\\$\@"])/\\$1/g;
1742 return '"'.$x.'"'; },
1746 defined($processors{$for}) ? $processors{$for} : sub { shift; };
1748 map { $processor->($_); } @_;
1751 # collect_information($filename, $line_continue, $regexp => $CODEref, ...)
1752 # $filename is the file to read.
1753 # $line_continue is either undef (which is a noop), or two arguments, where
1754 # the first is a regexp detecting a line continuation ending, and the
1755 # following argument is a CODEref that takes care of concatenating two
1757 # All following arguments are regex/CODEref pairs, where the regexp detects a
1758 # line and the CODEref does something with the result of the regexp.
1759 sub collect_information {
1760 my $filename = shift;
1761 my $line_continue_re = shift;
1762 my $line_concat = defined($line_continue_re) ? shift : undef;
1763 my %collectors = @_;
1765 my $saved_line = "";
1766 open IN, $filename || die "unable to read $filename: $!\n";
1769 if (defined $line_concat) {
1770 $_ = $line_concat->($saved_line, $_);
1772 if (defined $line_continue_re && /$line_continue_re/) {
1776 foreach my $re (keys %collectors) {
1777 if (/$re/) { $collectors{$re}->() };