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 # DES_PTR use pointer lookup vs arrays in the DES in crypto/des/des_locl.h
69 # DES_RISC1 use different DES_ENCRYPT macro that helps reduce register
70 # dependancies but needs to more registers, good for RISC CPU's
71 # DES_RISC2 A different RISC variant.
72 # DES_UNROLL unroll the inner DES loop, sometimes helps, somtimes hinders.
73 # DES_INT use 'int' instead of 'long' for DES_LONG in crypto/des/des.h
74 # This is used on the DEC Alpha where long is 8 bytes
76 # BN_LLONG use the type 'long long' in crypto/bn/bn.h
77 # MD2_CHAR use 'char' instead of 'int' for MD2_INT in crypto/md2/md2.h
78 # MD2_LONG use 'long' instead of 'int' for MD2_INT in crypto/md2/md2.h
79 # IDEA_SHORT use 'short' instead of 'int' for IDEA_INT in crypto/idea/idea.h
80 # IDEA_LONG use 'long' instead of 'int' for IDEA_INT in crypto/idea/idea.h
81 # RC2_SHORT use 'short' instead of 'int' for RC2_INT in crypto/rc2/rc2.h
82 # RC2_LONG use 'long' instead of 'int' for RC2_INT in crypto/rc2/rc2.h
83 # RC4_CHAR use 'char' instead of 'int' for RC4_INT in crypto/rc4/rc4.h
84 # RC4_LONG use 'long' instead of 'int' for RC4_INT in crypto/rc4/rc4.h
85 # RC4_INDEX define RC4_INDEX in crypto/rc4/rc4_locl.h. This turns on
86 # array lookups instead of pointer use.
87 # RC4_CHUNK enables code that handles data aligned at long (natural CPU
89 # RC4_CHUNK_LL enables code that handles data aligned at long long boundary
90 # (intended for 64-bit CPUs running 32-bit OS).
91 # BF_PTR use 'pointer arithmatic' for Blowfish (unsafe on Alpha).
92 # BF_PTR2 intel specific version (generic version is more efficient).
94 # Following are set automatically by this script
96 # MD5_ASM use some extra md5 assember,
97 # SHA1_ASM use some extra sha1 assember, must define L_ENDIAN for x86
98 # RMD160_ASM use some extra ripemd160 assember,
99 # SHA256_ASM sha256_block is implemented in assembler
100 # SHA512_ASM sha512_block is implemented in assembler
101 # AES_ASM ASE_[en|de]crypt is implemented in assembler
103 # Minimum warning options... any contributions to OpenSSL should at least get
106 my $gcc_devteam_warn = "-Wall -pedantic -DPEDANTIC -Wno-long-long -Wsign-compare -Wmissing-prototypes -Wshadow -Wformat -Wtype-limits -Werror -DREF_CHECK -DDEBUG_UNUSED";
108 # These are used in addition to $gcc_devteam_warn when the compiler is clang.
109 # TODO(openssl-team): fix problems and investigate if (at least) the
110 # following warnings can also be enabled:
111 # -Wswitch-enum, -Wunused-macros, -Wmissing-field-initializers,
113 # -Wunreachable-code -Wunused-parameter -Wlanguage-extension-token
114 # -Wextended-offsetof
115 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";
117 # Warn that "make depend" should be run?
118 my $warn_make_depend = 0;
120 # These are used in addition to $gcc_devteam_warn unless this is a mingw build.
121 # This adds backtrace information to the memory leak info.
122 my $memleak_devteam_backtrace = "-rdynamic -DCRYPTO_MDEBUG_BACKTRACE";
125 my $strict_warnings = 0;
127 my $x86_gcc_des="DES_PTR DES_RISC1 DES_UNROLL";
129 # MD2_CHAR slags pentium pros
130 my $x86_gcc_opts="RC4_INDEX MD2_INT";
132 # As for $BSDthreads. Idea is to maintain "collective" set of flags,
133 # which would cover all BSD flavors. -pthread applies to them all,
134 # but is treated differently. OpenBSD expands is as -D_POSIX_THREAD
135 # -lc_r, which is sufficient. FreeBSD 4.x expands it as -lc_r,
136 # which has to be accompanied by explicit -D_THREAD_SAFE and
137 # sometimes -D_REENTRANT. FreeBSD 5.x expands it as -lc_r, which
138 # seems to be sufficient?
139 my $BSDthreads="-pthread -D_THREAD_SAFE -D_REENTRANT";
142 # API compability name to version number mapping.
144 my $maxapi = "1.1.0"; # API for "no-deprecated" builds
146 "1.1.0" => "0x10100000L",
147 "1.0.0" => "0x10000000L",
148 "0.9.8" => "0x00908000L",
151 my $base_target = "BASE"; # The template that all other inherit from
155 # Forward declarations ###############################################
157 # read_config(filename)
159 # Reads a configuration file and populates %table with the contents
160 # (which the configuration file places in %targets).
163 # resolve_config(target)
165 # Resolves all the late evalutations, inheritances and so on for the
166 # chosen target and any target it inherits from.
170 # Information collection #############################################
172 # Collect version numbers
173 $config{version} = "unknown";
174 $config{version_num} = "unknown";
175 $config{shlib_version_number} = "unknown";
176 $config{shlib_version_history} = "unknown";
179 '<include/openssl/opensslv.h',
181 qr/OPENSSL.VERSION.TEXT.*OpenSSL (\S+) / => sub { $config{version} = $1; },
182 qr/OPENSSL.VERSION.NUMBER.*(0x\S+)/ => sub { $config{version_num}=$1 },
183 qr/SHLIB_VERSION_NUMBER *"([^"]+)"/ => sub { $config{shlib_version_number}=$1 },
184 qr/SHLIB_VERSION_HISTORY *"([^"]*)"/ => sub { $config{shlib_version_history}=$1 }
186 if ($config{shlib_version_history} ne "") { $config{shlib_version_history} .= ":"; }
188 ($config{major}, $config{minor})
189 = ($config{version} =~ /^([0-9]+)\.([0-9\.]+)/);
190 ($config{shlib_major}, $config{shlib_minor})
191 = ($config{shlib_version_number} =~ /^([0-9]+)\.([0-9\.]+)/);
192 die "erroneous version information in opensslv.h: ",
193 "$config{major}, $config{minor}, $config{shlib_major}, $config{shlib_minor}\n"
194 if ($config{major} eq "" || $config{minor} eq ""
195 || $config{shlib_major} eq "" || $config{shlib_minor} eq "");
197 # Collect target configurations
199 my ($vol, $dir, $dummy) = File::Spec->splitpath($0);
200 my $pattern = File::Spec->catpath($vol, $dir, "Configurations/*.conf");
201 foreach (sort glob($pattern) ) {
206 print "Configuring OpenSSL version $config{version} (0x$config{version_num})\n";
210 $config{openssldir}="";
211 $config{processor}="";
213 $config{install_prefix}= "$ENV{'INSTALL_PREFIX'}";
214 $config{cross_compile_prefix}="";
215 $config{fipslibdir}="/usr/local/ssl/fips-2.0/lib/";
216 my $nofipscanistercheck=0;
217 $config{baseaddr}="0xFB00000";
220 $config{no_shared}=0; # but "no-shared" is default
221 my $zlib=1; # but "no-zlib" is default
225 my $Makefile="Makefile";
229 # Top level directories to build
230 $config{dirs} = [ "crypto", "ssl", "engines", "apps", "test", "tools" ];
231 # crypto/ subdirectories to build
234 "md2", "md4", "md5", "sha", "mdc2", "hmac", "ripemd", "whrlpool", "poly1305",
235 "des", "aes", "rc2", "rc4", "rc5", "idea", "bf", "cast", "camellia", "seed", "chacha", "modes",
236 "bn", "ec", "rsa", "dsa", "dh", "dso", "engine",
237 "buffer", "bio", "stack", "lhash", "rand", "err",
238 "evp", "asn1", "pem", "x509", "x509v3", "conf", "txt_db", "pkcs7", "pkcs12", "comp", "ocsp", "ui",
239 "cms", "ts", "jpake", "srp", "store", "cmac", "ct", "async", "kdf"
242 # Known TLS and DTLS protocols
243 my @tls = qw(ssl3 tls1 tls1_1 tls1_2);
244 my @dtls = qw(dtls1 dtls1_2);
246 # Explicitelly known options that are possible to disable. They can
247 # be regexps, and will be used like this: /^no-${option}$/
248 # For developers: keep it sorted alphabetically
275 "ec_nistp_64_gcc_128",
283 "locking", # Really???
300 "rijndael", # Old AES name
325 foreach my $proto ((@tls, @dtls))
327 push(@disablables, $proto);
328 push(@disablables, "$proto-method");
331 # All of the following is disabled by default (RC5 was enabled before 0.9.8):
333 my %disabled = ( # "what" => "comment" [or special keyword "experimental"]
334 "ec_nistp_64_gcc_128" => "default",
336 "jpake" => "experimental",
340 "shared" => "default",
341 "ssl-trace" => "default",
342 "store" => "experimental",
343 "unit-test" => "default",
345 "zlib-dynamic" => "default",
346 "crypto-mdebug" => "default",
348 my @experimental = ();
350 # Note: => pair form used for aesthetics, not to truly make a hash table
351 my @disable_cascades = (
352 # "what" => [ "cascade", ... ]
353 sub { $config{processor} eq "386" }
356 "ssl3-method" => [ "ssl3" ],
357 "zlib" => [ "zlib-dynamic" ],
358 "rijndael" => [ "aes" ],
360 "ec" => [ "ecdsa", "ecdh" ],
361 "psk" => [ "jpake" ],
363 "dgram" => [ "dtls" ],
366 # SSL 3.0, (D)TLS 1.0 and TLS 1.1 require MD5 and SHA
367 "md5" => [ "ssl", "tls1", "tls1_1", "dtls1" ],
368 "sha" => [ "ssl", "tls1", "tls1_1", "dtls1" ],
370 # Additionally, SSL 3.0 requires either RSA or DSA+DH
372 && ($disabled{dsa} || $disabled{dh}); }
375 # (D)TLS 1.0 and TLS 1.1 also require either RSA or DSA+DH
376 # or ECDSA + ECDH. (D)TLS 1.2 has this requirement as well.
377 # (XXX: We don't support PSK-only builds).
379 && ($disabled{dsa} || $disabled{dh})
380 && ($disabled{ecdsa} || $disabled{ecdh}); }
381 => [ "tls1", "tls1_1", "tls1_2",
382 "dtls1", "dtls1_2" ],
386 # SRP and HEARTBEATS require TLSEXT
387 "tlsext" => [ "srp", "heartbeats" ],
390 # Avoid protocol support holes. Also disable all versions below N, if version
391 # N is disabled while N+1 is enabled.
393 my @list = (reverse @tls);
394 while ((my $first, my $second) = (shift @list, shift @list)) {
396 push @disable_cascades, ( sub { !$disabled{$first} && $disabled{$second} }
398 unshift @list, $second;
400 my @list = (reverse @dtls);
401 while ((my $first, my $second) = (shift @list, shift @list)) {
403 push @disable_cascades, ( sub { !$disabled{$first} && $disabled{$second} }
405 unshift @list, $second;
408 # Construct the string of what $config{depflags} should look like with the defaults
409 # from %disabled above. (we need this to see if we should advise the user
410 # to run "make depend"):
411 my $default_depflags = join(" ",
412 map { my $x = $_; $x =~ tr{[a-z]-}{[A-Z]_}; "-DOPENSSL_NO_$x"; }
413 grep { $disabled{$_} !~ /\(no-depflags\)$/ }
414 sort keys %disabled);
416 # Explicit "no-..." options will be collected in %disabled along with the defaults.
417 # To remove something from %disabled, use "enable-foo" (unless it's experimental).
418 # For symmetry, "disable-foo" is a synonym for "no-foo".
420 # For features called "experimental" here, a more explicit "experimental-foo" is needed to enable.
421 # We will collect such requests in @experimental.
422 # To avoid accidental use of experimental features, applications will have to use -DOPENSSL_EXPERIMENTAL_FOO.
427 &usage if ($#ARGV < 0);
430 $config{depflags}="";
431 $config{openssl_experimental_defines}=[];
432 $config{openssl_api_defines}=[];
433 $config{openssl_algorithm_defines}=[];
434 $config{openssl_thread_defines}=[];
435 $config{openssl_sys_defines}=[];
436 $config{openssl_other_defines}=[];
442 my $build_prefix = "release_";
446 if (grep /^reconf(igure)?$/, @argvcopy) {
447 if (-f "./configdata.pm") {
448 my $file = "./configdata.pm";
449 unless (my $return = do $file) {
450 die "couldn't parse $file: $@" if $@;
451 die "couldn't do $file: $!" unless defined $return;
452 die "couldn't run $file" unless $return;
455 @argvcopy = defined($configdata::config{perlargv}) ?
456 @{$configdata::config{perlargv}} : ();
457 die "Incorrect data to reconfigure, please do a normal configuration\n"
458 if (grep(/^reconf/,@argvcopy));
459 $ENV{CROSS_COMPILE} = $configdata::config{cross_compile_prefix}
460 if defined($configdata::config{cross_compile_prefix});
461 $ENV{CROSS_COMPILE} = $configdata::config{cc}
462 if defined($configdata::config{cc});
464 print "Reconfiguring with: ", join(" ",@argvcopy), "\n";
465 print " CROSS_COMPILE = ",$ENV{CROSS_COMPILE},"\n"
466 if $ENV{CROSS_COMPILE};
467 print " CC = ",$ENV{CC},"\n" if $ENV{CC};
468 } elsif (open IN, "<Makefile") {
470 # THIS SECTION IS TEMPORARY, it helps transitioning from Makefile
471 # centered information gathering the reading configdata.pm
475 if (/^CONFIGURE_ARGS=\s*(.*)\s*/) {
476 # Older form, we split the string and hope for the best
477 @argvcopy = split /\s+/, $_;
478 die "Incorrect data to reconfigure, please do a normal configuration\n"
479 if (grep(/^reconf/,@argvcopy));
480 } elsif (/^CROSS_COMPILE=\s*(.*)/) {
481 $ENV{CROSS_COMPILE}=$1;
482 } elsif (/^CC=\s*(?:\$\(CROSS_COMPILE\))?(.*?)$/) {
487 # END OF TEMPORARY SECTION
490 die "Insufficient data to reconfigure, please do a normal configuration\n";
494 $config{perlargv} = [ @argvcopy ];
496 my %unsupported_options = ();
499 s /^-no-/no-/; # some people just can't read the instructions
501 # rewrite some options in "enable-..." form
502 s /^-?-?shared$/enable-shared/;
503 s /^sctp$/enable-sctp/;
504 s /^threads$/enable-threads/;
505 s /^zlib$/enable-zlib/;
506 s /^zlib-dynamic$/enable-zlib-dynamic/;
508 if (/^(no|disable|enable|experimental)-(.+)$/)
511 if (!grep { $word =~ /^${_}$/ } @disablables)
513 $unsupported_options{$_} = 1;
517 if (/^no-(.+)$/ || /^disable-(.+)$/)
519 if (!($disabled{$1} eq "experimental"))
521 foreach my $proto ((@tls, @dtls))
523 if ($1 eq "$proto-method")
525 $disabled{"$proto"} = "option($proto-method)";
531 foreach my $proto (@dtls)
533 $disabled{$proto} = "option(dtls)";
538 # Last one of its kind
539 $disabled{"ssl3"} = "option(ssl)";
543 # XXX: Tests will fail if all SSL/TLS
544 # protocols are disabled.
545 foreach my $proto (@tls)
547 $disabled{$proto} = "option(tls)";
552 $disabled{$1} = "option";
556 elsif (/^enable-(.+)$/ || /^experimental-(.+)$/)
559 if ($disabled{$algo} eq "experimental")
561 die "You are requesting an experimental feature; please say 'experimental-$algo' if you are sure\n"
562 unless (/^experimental-/);
563 push @experimental, $algo;
565 delete $disabled{$algo};
567 $threads = 1 if ($algo eq "threads");
569 elsif (/^--strict-warnings$/)
571 $strict_warnings = 1;
575 $build_prefix = "debug_";
577 elsif (/^--release$/)
579 $build_prefix = "release_";
582 { $config{processor}=386; }
589 # No RSAref support any more since it's not needed.
590 # The check for the option is there so scripts aren't
593 elsif (/^nofipscanistercheck$/)
596 $nofipscanistercheck = 1;
600 if (/^--prefix=(.*)$/)
604 elsif (/^--api=(.*)$/)
608 elsif (/^--libdir=(.*)$/)
612 elsif (/^--openssldir=(.*)$/)
614 $config{openssldir}=$1;
616 elsif (/^--install.prefix=(.*)$/)
618 $config{install_prefix}=$1;
620 elsif (/^--with-zlib-lib=(.*)$/)
622 $withargs{"zlib-lib"}=$1;
624 elsif (/^--with-zlib-include=(.*)$/)
626 $withargs{"zlib-include"}="-I$1";
628 elsif (/^--with-fipslibdir=(.*)$/)
630 $config{fipslibdir}="$1/";
632 elsif (/^--with-baseaddr=(.*)$/)
634 $config{baseaddr}="$1";
636 elsif (/^--cross-compile-prefix=(.*)$/)
638 $config{cross_compile_prefix}=$1;
640 elsif (/^--config=(.*)$/)
644 elsif (/^-[lL](.*)$/ or /^-Wl,/)
648 else # common if (/^[-+]/), just pass down...
650 $_ =~ s/%([0-9a-f]{1,2})/chr(hex($1))/gei;
654 elsif ($_ =~ /^([^:]+):(.+)$/)
656 eval "\$table{\$1} = \"$2\""; # allow $xxx constructs in the string
661 die "target already defined - $target (offending arg: $_)\n" if ($target ne "");
664 unless ($_ eq $target || /^no-/ || /^disable-/)
666 # "no-..." follows later after implied disactivations
667 # have been derived. (Don't take this too seroiusly,
668 # we really only write OPTIONS to the Makefile out of
671 if ($config{options} eq "")
672 { $config{options} = $_; }
674 { $config{options} .= " ".$_; }
677 if (defined($config{api}) && !exists $apitable->{$config{api}}) {
678 die "***** Unsupported api compatibility level: $config{api}\n",
681 if (keys %unsupported_options)
683 die "***** Unsupported options: ",
684 join(", ", keys %unsupported_options), "\n";
690 delete $disabled{"shared"} if ($disabled{"shared"} =~ /^default/);
694 @{$config{dirs}} = grep !/^fips$/, @{$config{dirs}};
697 my @tocheckfor = (keys %disabled);
698 while (@tocheckfor) {
699 my %new_tocheckfor = ();
700 my @cascade_copy = (@disable_cascades);
701 while (@cascade_copy) {
702 my ($test, $descendents) = (shift @cascade_copy, shift @cascade_copy);
703 if (ref($test) eq "CODE" ? $test->() : defined($disabled{$test})) {
705 $new_tocheckfor{$_} => 1; $disabled{$_} = "forced";
706 } grep { !defined($disabled{$_}) } @$descendents;
709 @tocheckfor = (keys %new_tocheckfor);
712 if ($target eq "TABLE") {
713 foreach (sort keys %table) {
714 print_table_entry($_, "TABLE");
719 if ($target eq "LIST") {
720 foreach (sort keys %table) {
721 print $_,"\n" unless $table{$_}->{template};
726 if ($target eq "HASH") {
727 print "%table = (\n";
728 foreach (sort keys %table) {
729 print_table_entry($_, "HASH");
734 # Backward compatibility?
735 if ($target =~ m/^CygWin32(-.*)$/) {
736 $target = "Cygwin".$1;
739 foreach (sort (keys %disabled))
741 $config{options} .= " no-$_";
743 printf " no-%-12s %-10s", $_, "[$disabled{$_}]";
750 { $config{no_shared} = 1; }
753 elsif (/^static-engine$/)
755 elsif (/^zlib-dynamic$/)
760 { @{$config{dirs}} = grep !/^engine$/, @{$config{dirs}}; }
764 ($ALGO = $algo = $_) =~ tr/[\-a-z]/[_A-Z]/;
766 if (/^asm$/ || /^err$/ || /^hw$/ || /^hw-/)
768 push @{$config{openssl_other_defines}}, "OPENSSL_NO_$ALGO";
769 print " OPENSSL_NO_$ALGO";
771 if (/^err$/) { $flags .= "-DOPENSSL_NO_ERR "; }
772 elsif (/^asm$/) { $no_asm = 1; }
776 ($ALGO,$algo) = ("RMD160","rmd160") if ($algo eq "ripemd");
778 push @{$config{openssl_algorithm_defines}}, "OPENSSL_NO_$ALGO";
779 $config{depflags} .= " -DOPENSSL_NO_$ALGO";
780 print " OPENSSL_NO_$ALGO";
782 # fix-up crypto/directory name(s)
783 $algo="whrlpool" if $algo eq "whirlpool";
784 $algo="ripemd" if $algo eq "rmd160";
785 @{$config{sdirs}} = grep { $_ ne $algo} @{$config{sdirs}};
796 foreach (sort @experimental)
799 ($ALGO = $_) =~ tr/[a-z]/[A-Z]/;
801 # opensslconf.h will set OPENSSL_NO_... unless OPENSSL_EXPERIMENTAL_... is defined
802 push @{$config{openssl_experimental_defines}}, "OPENSSL_NO_$ALGO";
803 $exp_cflags .= " -DOPENSSL_EXPERIMENTAL_$ALGO";
806 print "Configuring for $target\n";
808 # Support for legacy targets having a name starting with 'debug-'
809 my ($d, $t) = $target =~ m/^(debug-)?(.*)$/;
811 $build_prefix = "debug_";
813 # If we do not find debug-foo in the table, the target is set to foo.
814 if (!$table{$target}) {
818 $config{target} = $target;
819 delete $table{$base_target}->{template}; # or the next test will fail.
820 my %target = ( %{$table{$base_target}}, resolve_config($target) );
822 &usage if (!%target || $target{template});
824 $target{exe_extension}="";
825 $target{exe_extension}=".exe" if ($config{target} eq "Cygwin" || $config{target} eq "DJGPP" || $config{target} =~ /^mingw/);
826 $target{exe_extension}=".nlm" if ($config{target} =~ /netware/);
827 $target{exe_extension}=".pm" if ($config{target} =~ /vos/);
829 $default_ranlib = which("ranlib") || "true";
830 $config{perl} = $ENV{'PERL'} || which("perl5") || which("perl") || "perl";
831 my $make = $ENV{'MAKE'} || "make";
833 $config{cross_compile_prefix} = $ENV{'CROSS_COMPILE'}
834 if $config{cross_compile_prefix} eq "";
836 $config{prefix} = "/usr/local" if !$config{prefix};
837 $config{openssldir} = "ssl" if !$config{openssldir};
838 $config{openssldir} = catdir($config{prefix}, $config{openssldir})
839 unless file_name_is_absolute($config{openssldir});
841 # Allow environment CC to override compiler...
842 $target{cc} = $ENV{CC} || $target{cc};
844 # For cflags and lflags, add the debug_ or release_ attributes
845 # Do it in such a way that no spurious space is appended (hence the grep).
846 $config{cflags} = join(" ",
847 grep { $_ ne "" } ($target{cflags},
848 $target{$build_prefix."cflags"}));
849 $config{lflags} = join(" ",
850 grep { $_ ne "" } ($target{lflags},
851 $target{$build_prefix."lflags"}));
853 $target{ranlib} = $ENV{'RANLIB'} || $target{ranlib} || $default_ranlib;
854 $target{ar} = $ENV{'AR'} || "ar";
855 $target{arflags} = "" if !defined($target{arflags});
857 # Make sure build_scheme is consistent.
858 $target{build_scheme} = [ $target{build_scheme} ]
859 if ref($target{build_scheme}) ne "ARRAY";
861 # if $config{prefix}/lib$target{multilib} is not an existing directory, then
862 # assume that it's not searched by linker automatically, in
863 # which case adding $target{multilib} suffix causes more grief than
864 # we're ready to tolerate, so don't...
865 $target{multilib}="" if !-d "$config{prefix}/lib$target{multilib}";
867 $config{libdir}="lib$target{multilib}" if $config{libdir} eq "";
868 $config{enginesdir}=$config{prefix} . "/" . $config{libdir} . "/engines";
870 $config{cflags} .= "$exp_cflags";
872 # '%' in $config{lflags} is used to split flags to "pre-" and post-flags
873 my ($pre,$post)=split('%',$config{lflags});
874 if (defined($post)) { $config{prelflags}=$pre; $config{lflags}=$post; }
875 else { $config{prelflags}=""; $config{lflags}=$pre; }
877 if ($target =~ /^mingw/ && `$target{cc} --target-help 2>&1` !~ m/-mno-cygwin/m)
879 $config{cflags} =~ s/-mno-cygwin\s*//;
880 $target{shared_ldflag} =~ s/-mno-cygwin\s*//;
883 if ($target =~ /linux.*-mips/ && !$no_asm && $flags !~ /-m(ips|arch=)/) {
884 # minimally required architecture flags for assembly modules
885 $config{cflags}="-mips2 $config{cflags}" if ($target =~ /mips32/);
886 $config{cflags}="-mips3 $config{cflags}" if ($target =~ /mips64/);
889 my $no_shared_warn=0;
890 my $no_user_cflags=0;
892 if ($flags ne "") { $config{cflags}="$flags$config{cflags}"; }
893 else { $no_user_cflags=1; }
895 # The DSO code currently always implements all functions so that no
896 # applications will have to worry about that from a compilation point
897 # of view. However, the "method"s may return zero unless that platform
898 # has support compiled in for them. Currently each method is enabled
899 # by a define "DSO_<name>" ... we translate the "dso_scheme" config
900 # string entry into using the following logic;
902 if (!$no_dso && $target{dso_scheme} ne "")
904 $target{dso_scheme} =~ tr/[a-z]/[A-Z]/;
905 if ($target{dso_scheme} eq "DLFCN")
907 $dso_cflags = "-DDSO_DLFCN -DHAVE_DLFCN_H";
909 elsif ($target{dso_scheme} eq "DLFCN_NO_H")
911 $dso_cflags = "-DDSO_DLFCN";
915 $dso_cflags = "-DDSO_$target{dso_scheme}";
917 $config{cflags} = "$dso_cflags $config{cflags}";
922 if ($target{thread_cflag} ne "(unknown)" && !$no_threads)
924 # If we know how to do it, support threads by default.
927 if ($target{thread_cflag} eq "(unknown)" && $threads)
929 # If the user asked for "threads", [s]he is also expected to
930 # provide any system-dependent compiler options that are
934 print "You asked for multi-threading support, but didn't\n";
935 print "provide any system-specific compiler options\n";
938 $thread_cflags="-DOPENSSL_THREADS $config{cflags}" ;
939 push @thread_defines, "OPENSSL_THREADS";
943 $thread_cflags="-DOPENSSL_THREADS $target{thread_cflag} $config{cflags}";
944 push @thread_defines, "OPENSSL_THREADS";
946 # foreach $def (split ' ',$target{thread_cflag})
948 # if ($def =~ s/^-D// && $def !~ /^_/)
950 # push @thread_defines, "$def";
955 $config{lflags}="$libs$config{lflags}" if ($libs ne "");
959 $config{cflags}=~s/-D[BL]_ENDIAN// if ($config{fips});
960 $thread_cflags=~s/-D[BL]_ENDIAN// if ($config{fips});
965 $config{cflags}=$thread_cflags;
966 push @{$config{openssl_thread_defines}}, @thread_defines;
971 $config{cflags} = "-DZLIB $config{cflags}";
972 if (defined($disabled{"zlib-dynamic"}))
974 if (defined($withargs{"zlib-lib"}))
976 $config{lflags} .= " -L" . $withargs{"zlib-lib"} . " -lz";
980 $config{lflags} .= " -lz";
985 $config{cflags} = "-DZLIB_SHARED $config{cflags}";
989 # With "deprecated" disable all deprecated features.
990 if (defined($disabled{"deprecated"})) {
991 $config{api} = $maxapi;
994 if ($target{shared_target} eq "")
996 $no_shared_warn = 1 if !$config{no_shared} && !$config{fips};
997 $config{no_shared} = 1;
999 if (!$config{no_shared})
1001 if ($target{shared_cflag} ne "")
1003 $config{cflags} = "$target{shared_cflag} -DOPENSSL_PIC $config{cflags}";
1007 if ($target{build_scheme}->[0] ne "mk1mf")
1009 # add {no-}static-engine to options to allow mkdef.pl to work without extra arguments
1010 if ($config{no_shared})
1012 push @{$config{openssl_other_defines}}, "OPENSSL_NO_DYNAMIC_ENGINE";
1013 $config{options}.=" static-engine";
1017 push @{$config{openssl_other_defines}}, "OPENSSL_NO_STATIC_ENGINE";
1018 $config{options}.=" no-static-engine";
1025 if ($target =~ /-icc$/) # Intel C compiler
1028 if (open(FD,"$target{cc} -V 2>&1 |"))
1030 while(<FD>) { $iccver=$1 if (/Version ([0-9]+)\./); }
1035 $config{cflags}=~s/-KPIC/-fPIC/;
1036 # Eliminate unnecessary dependency from libirc.a. This is
1037 # essential for shared library support, as otherwise
1038 # apps/openssl can end up in endless loop upon startup...
1039 $config{cflags}.=" -Dmemcpy=__builtin_memcpy -Dmemset=__builtin_memset";
1043 $config{lflags}.=" -i-static";
1044 $config{lflags}=~s/-no_cpprt/-no-cpprt/;
1048 $config{lflags}=~s/-i-static/-static-intel/;
1052 $config{cflags}.=" -no-intel-extensions"; # disable Cilk
1053 $config{lflags}=~s/-no-cpprt/-no-cxxlib/;
1057 # Unlike other OSes (like Solaris, Linux, Tru64, IRIX) BSD run-time
1058 # linkers (tested OpenBSD, NetBSD and FreeBSD) "demand" RPATH set on
1059 # .so objects. Apparently application RPATH is not global and does
1060 # not apply to .so linked with other .so. Problem manifests itself
1061 # when libssl.so fails to load libcrypto.so. One can argue that we
1062 # should engrave this into Makefile.shared rules or into BSD-* config
1063 # lines above. Meanwhile let's try to be cautious and pass -rpath to
1064 # linker only when --prefix is not /usr.
1065 if ($target =~ /^BSD-/)
1067 $target{shared_ldflag}.=" -Wl,-rpath,\$\$(LIBRPATH)" if ($config{prefix} !~ m|^/usr[/]*$|);
1070 if ($target{sys_id} ne "")
1072 #$config{cflags}="-DOPENSSL_SYS_$target{sys_id} $config{cflags}";
1073 push @{$config{openssl_sys_defines}}, "OPENSSL_SYS_$target{sys_id}";
1076 if ($target{ranlib} eq "")
1078 $target{ranlib} = $default_ranlib;
1082 $target{cpuid_obj}=$table{BASE}->{cpuid_obj} if ($config{processor} eq "386");
1083 $target{cpuid_obj}.=" uplink.o uplink-x86.o" if ($config{cflags} =~ /-DOPENSSL_USE_APPLINK/);
1085 $target{bn_obj} =~ s/\w+-gf2m.o// if (defined($disabled{ec2m}));
1087 # bn-586 is the only one implementing bn_*_part_words
1088 $config{cflags}.=" -DOPENSSL_BN_ASM_PART_WORDS" if ($target{bn_obj} =~ /bn-586/);
1089 $config{cflags}.=" -DOPENSSL_IA32_SSE2" if (!$no_sse2 && $target{bn_obj} =~ /86/);
1091 $config{cflags}.=" -DOPENSSL_BN_ASM_MONT" if ($target{bn_obj} =~ /-mont/);
1092 $config{cflags}.=" -DOPENSSL_BN_ASM_MONT5" if ($target{bn_obj} =~ /-mont5/);
1093 $config{cflags}.=" -DOPENSSL_BN_ASM_GF2m" if ($target{bn_obj} =~ /-gf2m/);
1095 if ($config{fips}) {
1096 push @{$config{openssl_other_defines}}, "OPENSSL_FIPS";
1099 if ($target{sha1_obj} =~ /\.o$/) {
1100 $config{cflags}.=" -DSHA1_ASM" if ($target{sha1_obj} =~ /sx86/ || $target{sha1_obj} =~ /sha1/);
1101 $config{cflags}.=" -DSHA256_ASM" if ($target{sha1_obj} =~ /sha256/);
1102 $config{cflags}.=" -DSHA512_ASM" if ($target{sha1_obj} =~ /sha512/);
1103 if ($target{sha1_obj} =~ /sse2/) {
1105 $target{sha1_obj} =~ s/\S*sse2\S+//;
1106 } elsif ($config{cflags} !~ /OPENSSL_IA32_SSE2/) {
1107 $config{cflags}.=" -DOPENSSL_IA32_SSE2";
1111 if ($target{md5_obj} =~ /\.o$/) {
1112 $config{cflags}.=" -DMD5_ASM";
1114 $target{cast_obj}=$table{BASE}->{cast_obj} if (!$config{no_shared}); # CAST assembler is not PIC
1115 if ($target{rmd160_obj} =~ /\.o$/) {
1116 $config{cflags}.=" -DRMD160_ASM";
1118 if ($target{aes_obj} =~ /\.o$/) {
1119 $config{cflags}.=" -DAES_ASM" if ($target{aes_obj} =~ m/\baes-/);;
1120 # aes-ctr.o is not a real file, only indication that assembler
1121 # module implements AES_ctr32_encrypt...
1122 $config{cflags}.=" -DAES_CTR_ASM" if ($target{aes_obj} =~ s/\s*aes-ctr\.o//);
1123 # aes-xts.o indicates presence of AES_xts_[en|de]crypt...
1124 $config{cflags}.=" -DAES_XTS_ASM" if ($target{aes_obj} =~ s/\s*aes-xts\.o//);
1125 $target{aes_obj} =~ s/\s*(vpaes|aesni)-x86\.o//g if ($no_sse2);
1126 $config{cflags}.=" -DVPAES_ASM" if ($target{aes_obj} =~ m/vpaes/);
1127 $config{cflags}.=" -DBSAES_ASM" if ($target{aes_obj} =~ m/bsaes/);
1129 if ($target{wp_obj} =~ /mmx/ && $config{processor} eq "386") {
1130 $target{wp_obj}=$table{BASE}->{wp_obj};
1131 } elsif (!$disabled{"whirlpool"}) {
1132 $config{cflags}.=" -DWHIRLPOOL_ASM";
1134 if ($target{modes_obj} =~ /ghash-/) {
1135 $config{cflags}.=" -DGHASH_ASM";
1137 if ($target{ec_obj} =~ /ecp_nistz256/) {
1138 $config{cflags}.=" -DECP_NISTZ256_ASM";
1140 if ($target{poly1305_obj} =~ /\.o$/) {
1141 $config{cflags}.=" -DPOLY1305_ASM";
1145 $config{makedepprog} = "makedepend";
1146 if ($target{cc} eq "gcc" || ($target{cc} eq 'cc' && $config{target} =~ /darwin/)) {
1147 $config{makedepprog} = $target{cc};
1149 # On different platforms, shared library suffixes takes interesting forms.
1150 # On Most Unixen, it's .so.{version} or .sl.{version}, while on MacOS X,
1151 # it's .{version}.dylib. We're want to separate the two so we can calculate
1153 # FIXME: is this actually needed any more? Makefile.shared seems to just
1154 # symlink a file name without SOVER to the file with full SOVER, nothing in
1156 if ($target{shared_extension} =~ /^(|(?<e>\.s[ol])(?<v>\..*)|(?<v>\..*)(?<e>\.dylib))$/) {
1157 my @vernums = split /\./, $+{v};
1158 shift @vernums; # Because the initial period in shlib_extension.
1162 push @s, join(".", $+{e} eq ".dylib" ? "" : $+{e},
1164 $+{e} eq ".dylib" ? $+{e} : () );
1166 $config{shared_link_extensions} = join(" ", @s);
1168 $config{shared_link_extensions} = "";
1170 $config{depflags} =~ s/^\s*//;
1173 # Deal with bn_ops ###################################################
1175 $config{des_ptr} =0;
1176 $config{des_risc1} =0;
1177 $config{des_risc2} =0;
1178 $config{des_unroll} =0;
1180 $config{rc4_idx} =0;
1182 $config{export_var_as_fn} =0;
1183 my $def_int="unsigned int";
1184 $config{rc4_int} =$def_int;
1185 $config{rc4_chunk} ="";
1186 $config{md2_int} =$def_int;
1187 $config{idea_int} =$def_int;
1188 $config{rc2_int} =$def_int;
1189 ($config{b64l},$config{b64},$config{b32},$config{b16},$config{b8})=(0,0,1,0,0);
1191 $config{des_int} = "unsigned long";
1193 foreach (sort split(/\s+/,$target{bn_ops})) {
1194 $config{des_ptr}=1 if /DES_PTR/;
1195 $config{des_risc1}=1 if /DES_RISC1/;
1196 $config{des_risc2}=1 if /DES_RISC2/;
1197 $config{des_unroll}=1 if /DES_UNROLL/;
1198 $config{des_int}="unsigned int" if /DES_INT/;
1199 $config{bn_ll}=1 if /BN_LLONG/;
1200 $config{rc4_int}="unsigned char" if /RC4_CHAR/;
1201 $config{rc4_int}="unsigned long" if /RC4_LONG/;
1202 $config{rc4_idx}=1 if /RC4_INDEX/;
1203 $config{rc4_chunk}="unsigned long" if /RC4_CHUNK/;
1204 $config{rc4_chunk}="unsigned long long" if /RC4_CHUNK_LL/;
1205 $config{md2_int}="unsigned char" if /MD2_CHAR/;
1206 $config{md2_int}="unsigned long" if /MD2_LONG/;
1207 $config{idea_int}="unsigned char" if /IDEA_CHAR/;
1208 $config{idea_int}="unsigned long" if /IDEA_LONG/;
1209 $config{rc2_int}="unsigned char" if /RC2_CHAR/;
1210 $config{rc2_int}="unsigned long" if /RC2_LONG/;
1211 $config{bf_ptr}=1 if $_ eq "BF_PTR";
1212 $config{bf_ptr}=2 if $_ eq "BF_PTR2";
1213 ($config{b64l},$config{b64},$config{b32},$config{b16},$config{b8})
1214 =(0,1,0,0,0) if /SIXTY_FOUR_BIT/;
1215 ($config{b64l},$config{b64},$config{b32},$config{b16},$config{b8})
1216 =(1,0,0,0,0) if /SIXTY_FOUR_BIT_LONG/;
1217 ($config{b64l},$config{b64},$config{b32},$config{b16},$config{b8})
1218 =(0,0,1,0,0) if /THIRTY_TWO_BIT/;
1219 ($config{b64l},$config{b64},$config{b32},$config{b16},$config{b8})
1220 =(0,0,0,1,0) if /SIXTEEN_BIT/;
1221 ($config{b64l},$config{b64},$config{b32},$config{b16},$config{b8})
1222 =(0,0,0,0,1) if /EIGHT_BIT/;
1223 $config{export_var_as_fn}=1 if /EXPORT_VAR_AS_FN/;
1227 # Hack cflags for better warnings (dev option) #######################
1229 # "Stringify" the C flags string. This permits it to be made part of a string
1230 # and works as well on command lines.
1231 $config{cflags} =~ s/([\\\"])/\\\1/g;
1233 if (defined($config{api})) {
1234 $config{openssl_api_defines} = [ "OPENSSL_MIN_API=".$apitable->{$config{api}} ];
1235 my $apiflag = sprintf("-DOPENSSL_API_COMPAT=%s", $apitable->{$config{api}});
1236 $default_depflags .= " $apiflag";
1237 $config{cflags} .= " $apiflag";
1240 my $ecc = $target{cc};
1241 $ecc = "clang" if `$target{cc} --version 2>&1` =~ /clang/;
1243 if ($strict_warnings)
1246 die "ERROR --strict-warnings requires gcc or clang" unless ($ecc =~ /gcc(-\d(\.\d)*)?$/ or $ecc =~ /clang$/);
1247 foreach $wopt (split /\s+/, $gcc_devteam_warn)
1249 $config{cflags} .= " $wopt" unless ($config{cflags} =~ /(^|\s)$wopt(\s|$)/)
1251 if ($ecc eq "clang")
1253 foreach $wopt (split /\s+/, $clang_devteam_warn)
1255 $config{cflags} .= " $wopt" unless ($config{cflags} =~ /(^|\s)$wopt(\s|$)/)
1258 if ($target !~ /^mingw/)
1260 foreach $wopt (split /\s+/, $memleak_devteam_backtrace)
1262 $config{cflags} .= " $wopt" unless ($config{cflags} =~ /(^|\s)$wopt(\s|$)/)
1264 if ($target =~ /^BSD-/)
1266 $config{lflags} .= " -lexecinfo";
1271 # Write down our configuration where it fits #########################
1273 open(OUT,">configdata.pm") || die "unable to create configdata.pm: $!\n";
1281 #use vars qw(\@ISA \@EXPORT);
1282 our \@ISA = qw(Exporter);
1283 our \@EXPORT = qw(\%config \%target %withargs);
1286 print OUT "our %config = (\n";
1287 foreach (sort keys %config) {
1288 if (ref($config{$_}) eq "ARRAY") {
1289 print OUT " ", $_, " => [ ", join(", ",
1290 map { quotify("perl", $_) }
1291 @{$config{$_}}), " ],\n";
1293 print OUT " ", $_, " => ", quotify("perl", $config{$_}), ",\n"
1300 print OUT "our %target = (\n";
1301 foreach (sort keys %target) {
1302 if (ref($target{$_}) eq "ARRAY") {
1303 print OUT " ", $_, " => [ ", join(", ",
1304 map { quotify("perl", $_) }
1305 @{$target{$_}}), " ],\n";
1307 print OUT " ", $_, " => ", quotify("perl", $target{$_}), ",\n"
1314 print OUT "our %withargs = (\n";
1315 foreach (sort keys %withargs) {
1316 if (ref($withargs{$_}) eq "ARRAY") {
1317 print OUT " ", $_, " => [ ", join(", ",
1318 map { quotify("perl", $_) }
1319 @{$withargs{$_}}), " ],\n";
1321 print OUT " ", $_, " => ", quotify("perl", $withargs{$_}), ",\n"
1331 print "IsMK1MF =", ($target{build_scheme}->[0] eq "mk1mf" ? "yes" : "no"), "\n";
1332 print "CC =$target{cc}\n";
1333 print "CFLAG =$config{cflags}\n";
1334 print "EX_LIBS =$config{lflags}\n";
1335 print "CPUID_OBJ =$target{cpuid_obj}\n";
1336 print "BN_ASM =$target{bn_obj}\n";
1337 print "EC_ASM =$target{ec_obj}\n";
1338 print "DES_ENC =$target{des_obj}\n";
1339 print "AES_ENC =$target{aes_obj}\n";
1340 print "BF_ENC =$target{bf_obj}\n";
1341 print "CAST_ENC =$target{cast_obj}\n";
1342 print "RC4_ENC =$target{rc4_obj}\n";
1343 print "RC5_ENC =$target{rc5_obj}\n";
1344 print "MD5_OBJ_ASM =$target{md5_obj}\n";
1345 print "SHA1_OBJ_ASM =$target{sha1_obj}\n";
1346 print "RMD160_OBJ_ASM=$target{rmd160_obj}\n";
1347 print "CMLL_ENC =$target{cmll_obj}\n";
1348 print "MODES_OBJ =$target{modes_obj}\n";
1349 print "ENGINES_OBJ =$target{engines_obj}\n";
1350 print "CHACHA_ENC =$target{chacha_obj}\n";
1351 print "POLY1305_OBJ =$target{poly1305_obj}\n";
1352 print "PROCESSOR =$config{processor}\n";
1353 print "RANLIB =$target{ranlib}\n";
1354 print "ARFLAGS =$target{arflags}\n";
1355 print "PERL =$config{perl}\n";
1357 run_dofile("$Makefile.in","$Makefile");
1359 run_dofile("include/openssl/opensslconf.h.in", "include/openssl/opensslconf.h");
1361 foreach my $alg ( 'bf', 'bn', 'des', 'rc4' ) {
1362 run_dofile("crypto/include/internal/${alg}_conf.h.in",
1363 "crypto/include/internal/${alg}_conf.h");
1368 print "SIXTY_FOUR_BIT_LONG mode\n" if $config{b64l};
1369 print "SIXTY_FOUR_BIT mode\n" if $config{b64};
1370 print "THIRTY_TWO_BIT mode\n" if $config{b32};
1371 print "SIXTEEN_BIT mode\n" if $config{b16};
1372 print "EIGHT_BIT mode\n" if $config{b8};
1373 print "DES_PTR used\n" if $config{des_ptr};
1374 print "DES_RISC1 used\n" if $config{des_risc1};
1375 print "DES_RISC2 used\n" if $config{des_risc2};
1376 print "DES_UNROLL used\n" if $config{des_unroll};
1377 print "DES_INT used\n" if $config{des_int} =~ / int$/;
1378 print "BN_LLONG mode\n" if $config{bn_ll};
1379 print "RC4 uses $config{rc4_int}\n" if $config{rc4_int} != $def_int;
1380 print "RC4_INDEX mode\n" if $config{rc4_idx};
1381 print "RC4_CHUNK is undefined\n" unless $config{rc4_chunk};
1382 print "RC4_CHUNK is $config{rc4_chunk}\n" if $config{rc4_chunk};
1383 print "MD2 uses $config{md2_int}\n" if $config{md2_int} != $def_int;
1384 print "IDEA uses $config{idea_int}\n" if $config{idea_int} != $def_int;
1385 print "RC2 uses $config{rc2_int}\n" if $config{rc2_int} != $def_int;
1386 print "BF_PTR used\n" if $config{bf_ptr} == 1;
1387 print "BF_PTR2 used\n" if $config{bf_ptr} == 2;
1389 # Copy all Makefile.in to Makefile (except top-level)
1393 return if ($_ ne "Makefile.in" || $File::Find::dir eq ".");
1394 my $in = IO::File->new($_, "r") or
1395 die sprintf "Error reading Makefile.in in %s: !$\n",
1397 my $out = IO::File->new("Makefile", "w") or
1398 die sprintf "Error writing Makefile in %s: !$\n",
1400 print $out "# Generated from $_, do not edit\n";
1401 while (my $line = <$in>) { print $out $line }
1403 die sprintf "Error reading Makefile.in in %s: !$\n",
1406 die sprintf "Error writing Makefile in %s: !$\n",
1412 my $make_command = "$make PERL=\'$config{perl}\'";
1413 my $make_targets = "";
1414 $make_targets .= " depend" if $config{depflags} ne $default_depflags && $make_depend;
1415 (system $make_command.$make_targets) == 0 or die "make $make_targets failed"
1416 if $make_targets ne "";
1417 if ($config{depflags} ne $default_depflags && !$make_depend) {
1418 $warn_make_depend++;
1422 open (OUT,">crypto/buildinf.h") || die "Can't open buildinf.h";
1425 /* auto-generated by Configure for crypto/cversion.c:
1426 * for Unix builds, crypto/Makefile.ssl generates functional definitions;
1427 * Windows builds (and other mk1mf builds) compile cversion.c with
1428 * -DMK1MF_BUILD and use definitions added to this file by util/mk1mf.pl. */
1429 #error "Windows builds (PLATFORM=$target) use mk1mf.pl-created Makefiles"
1434 # create the ms/version32.rc file if needed
1435 if (! grep /^netware/, @{$target{build_scheme}}) {
1436 my ($v1, $v2, $v3, $v4);
1437 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) {
1443 open (OUT,">ms/version32.rc") || die "Can't open ms/version32.rc";
1450 FILEVERSION $v1,$v2,$v3,$v4
1451 PRODUCTVERSION $v1,$v2,$v3,$v4
1458 FILEOS VOS__WINDOWS32
1462 BLOCK "StringFileInfo"
1467 VALUE "CompanyName", "The OpenSSL Project, http://www.openssl.org/\\0"
1468 VALUE "FileDescription", "OpenSSL Shared Library\\0"
1469 VALUE "FileVersion", "$config{version}\\0"
1471 VALUE "InternalName", "libeay32\\0"
1472 VALUE "OriginalFilename", "libeay32.dll\\0"
1474 VALUE "InternalName", "ssleay32\\0"
1475 VALUE "OriginalFilename", "ssleay32.dll\\0"
1477 VALUE "ProductName", "The OpenSSL Toolkit\\0"
1478 VALUE "ProductVersion", "$config{version}\\0"
1480 //VALUE "Comments", "\\0"
1481 VALUE "LegalCopyright", "Copyright © 1998-2015 The OpenSSL Project. Copyright © 1995-1998 Eric A. Young, Tim J. Hudson. All rights reserved.\\0"
1482 //VALUE "LegalTrademarks", "\\0"
1483 //VALUE "PrivateBuild", "\\0"
1484 //VALUE "SpecialBuild", "\\0"
1489 VALUE "Translation", 0x409, 0x4b0
1498 my ($builder, @builder_opts) = @{$target{build_scheme}};
1499 $builders{$builder}->(@builder_opts);
1503 Configured for $target.
1506 print <<"EOF" if (!$no_threads && !$threads);
1508 The library could not be configured for supporting multi-threaded
1509 applications as the compiler options required on this system are not known.
1510 See file INSTALL for details if you need multi-threading.
1513 print <<"EOF" if ($no_shared_warn);
1515 You gave the option 'shared', which is not supported on this platform, so
1516 we will pretend you gave the option 'no-shared'. If you know how to implement
1517 shared libraries, please let us know (but please first make sure you have
1518 tried with a current version of OpenSSL).
1521 print <<"EOF" if ($warn_make_depend);
1523 *** Because of configuration changes, you MUST do the following before
1531 ######################################################################
1533 # Helpers and utility functions
1536 # Configuration file reading #########################################
1538 # Helper function to implement conditional inheritance depending on the
1539 # value of $no_asm. Used in inherit_from values as follows:
1541 # inherit_from => [ "template", asm("asm_tmpl") ]
1550 # Helper function to implement adding values to already existing configuration
1551 # values. It handles elements that are ARRAYs, CODEs and scalars
1553 my $separator = shift;
1555 # If there's any ARRAY in the collection of values, we will return
1556 # an ARRAY of combined values, otherwise a string of joined values
1557 # with $separator as the separator.
1558 my $found_array = 0;
1562 if (ref($_) eq "ARRAY") {
1573 join($separator, @values);
1577 my $separator = shift;
1579 sub { _add($separator, @x, @_) };
1582 my $separator = shift;
1584 sub { _add($separator, @_, @x) };
1587 # configuration reader, evaluates the input file as a perl script and expects
1588 # it to fill %targets with target configurations. Those are then added to
1592 open(CONFFILE, "< $fname")
1593 or die "Can't open configuration file '$fname'!\n";
1596 my $content = <CONFFILE>;
1601 local %table = %::table; # Protect %table from tampering
1607 # For each target, check that it's configured with a hash table.
1608 foreach (keys %targets) {
1609 if (ref($targets{$_}) ne "HASH") {
1610 if (ref($targets{$_}) eq "") {
1611 warn "Deprecated target configuration for $_, ignoring...\n";
1613 warn "Misconfigured target configuration for $_ (should be a hash table), ignoring...\n";
1615 delete $targets{$_};
1619 %table = (%table, %targets);
1623 # configuration resolver. Will only resolve all the lazy evalutation
1624 # codeblocks for the chozen target and all those it inherits from,
1626 sub resolve_config {
1628 my @breadcrumbs = @_;
1630 if (grep { $_ eq $target } @breadcrumbs) {
1631 die "inherit_from loop! target backtrace:\n "
1632 ,$target,"\n ",join("\n ", @breadcrumbs),"\n";
1635 if (!defined($table{$target})) {
1636 warn "Warning! target $target doesn't exist!\n";
1639 # Recurse through all inheritances. They will be resolved on the
1640 # fly, so when this operation is done, they will all just be a
1641 # bunch of attributes with string values.
1642 # What we get here, though, are keys with references to lists of
1643 # the combined values of them all. We will deal with lists after
1644 # this stage is done.
1645 my %combined_inheritance = ();
1646 if ($table{$target}->{inherit_from}) {
1648 map { ref($_) eq "CODE" ? $_->() : $_ } @{$table{$target}->{inherit_from}};
1649 foreach (@inherit_from) {
1650 my %inherited_config = resolve_config($_, $target, @breadcrumbs);
1652 # 'template' is a marker that's considered private to
1653 # the config that had it.
1654 delete $inherited_config{template};
1657 if (!$combined_inheritance{$_}) {
1658 $combined_inheritance{$_} = [];
1660 push @{$combined_inheritance{$_}}, $inherited_config{$_};
1661 } keys %inherited_config;
1665 # We won't need inherit_from in this target any more, since we've
1666 # resolved all the inheritances that lead to this
1667 delete $table{$target}->{inherit_from};
1669 # Now is the time to deal with those lists. Here's the place to
1670 # decide what shall be done with those lists, all based on the
1671 # values of the target we're currently dealing with.
1672 # - If a value is a coderef, it will be executed with the list of
1673 # inherited values as arguments.
1674 # - If the corresponding key doesn't have a value at all or is the
1675 # emoty string, the inherited value list will be run through the
1676 # default combiner (below), and the result becomes this target's
1678 # - Otherwise, this target's value is assumed to be a string that
1679 # will simply override the inherited list of values.
1680 my $default_combiner = add(" ");
1683 map { $_ => 1 } (keys %combined_inheritance,
1684 keys %{$table{$target}});
1685 foreach (sort keys %all_keys) {
1687 # Current target doesn't have a value for the current key?
1688 # Assign it the default combiner, the rest of this loop body
1689 # will handle it just like any other coderef.
1690 if (!exists $table{$target}->{$_}) {
1691 $table{$target}->{$_} = $default_combiner;
1694 my $valuetype = ref($table{$target}->{$_});
1695 if ($valuetype eq "CODE") {
1696 # CODE reference, execute it with the inherited values as
1698 $table{$target}->{$_} =
1699 $table{$target}->{$_}->(@{$combined_inheritance{$_}});
1700 } elsif ($valuetype eq "ARRAY" || $valuetype eq "") {
1701 # ARRAY or Scalar, just leave it as is.
1703 # Some other type of reference that we don't handle.
1704 # Better to abort at this point.
1705 die "cannot handle reference type $valuetype,"
1706 ," found in target $target -> $_\n";
1710 # Finally done, return the result.
1711 return %{$table{$target}};
1716 print STDERR $usage;
1717 print STDERR "\npick os/compiler from:\n";
1721 foreach $i (sort keys %table)
1723 next if $table{$i}->{template};
1724 next if $i =~ /^debug/;
1725 $k += length($i) + 1;
1731 print STDERR $i . " ";
1733 foreach $i (sort keys %table)
1735 next if $table{$i}->{template};
1736 next if $i !~ /^debug/;
1737 $k += length($i) + 1;
1743 print STDERR $i . " ";
1745 print STDERR "\n\nNOTE: If in doubt, on Unix-ish systems use './config'.\n";
1754 # should we remove $out ?
1755 system("$config{perl} -I. -Mconfigdata util/dofile.pl <$in >$out.new");
1757 rename("$out.new", $out) || die "Can't rename $out.new, $!";
1760 # Configuration printer ##############################################
1762 sub print_table_entry
1765 my %target = resolve_config($target);
1768 # Don't print the templates
1769 return if $target{template};
1810 if ($type eq "TABLE") {
1812 print "*** $target\n";
1813 printf "\$%-12s = %s\n", $_, $target{$_} foreach (@sequence);
1814 } elsif ($type eq "HASH") {
1816 length((sort { length($a) <=> length($b) } @sequence)[-1]);
1817 print " '$target' => {\n";
1818 foreach (@sequence) {
1820 print " '",$_,"'"," " x ($largest - length($_))," => '",$target{$_},"',\n";
1827 # Utility routines ###################################################
1833 foreach $path (split /:/, $ENV{PATH})
1835 if (-f "$path/$name$target{exe_extension}" and -x _)
1837 return "$path/$name$target{exe_extension}" unless ($name eq "perl" and
1838 system("$path/$name$target{exe_extension} -e " . '\'exit($]<5.0);\''));
1845 perl => sub { my $x = shift;
1846 $x =~ s/([\\\$\@"])/\\$1/g;
1847 return '"'.$x.'"'; },
1851 defined($processors{$for}) ? $processors{$for} : sub { shift; };
1853 map { $processor->($_); } @_;
1856 # collect_information($filename, $line_continue, $regexp => $CODEref, ...)
1857 # $filename is the file to read.
1858 # $line_continue is either undef (which is a noop), or two arguments, where
1859 # the first is a regexp detecting a line continuation ending, and the
1860 # following argument is a CODEref that takes care of concatenating two
1862 # All following arguments are regex/CODEref pairs, where the regexp detects a
1863 # line and the CODEref does something with the result of the regexp.
1864 sub collect_information {
1865 my $filename = shift;
1866 my $line_continue_re = shift;
1867 my $line_concat = defined($line_continue_re) ? shift : undef;
1868 my %collectors = @_;
1870 my $saved_line = "";
1871 open IN, $filename || die "unable to read $filename: $!\n";
1874 if (defined $line_concat) {
1875 $_ = $line_concat->($saved_line, $_);
1877 if (defined $line_continue_re && /$line_continue_re/) {
1881 foreach my $re (keys %collectors) {
1882 if (/$re/) { $collectors{$re}->() };