Refactor file writing - Adapt util/mkdef.pl to use configdata.pm
authorRichard Levitte <levitte@openssl.org>
Mon, 11 Jan 2016 23:17:12 +0000 (00:17 +0100)
committerRichard Levitte <richard@levitte.org>
Fri, 22 Jan 2016 22:21:30 +0000 (23:21 +0100)
For this adaptation, the variables $options and $version needed to
move to %config in Configure, and why not move all other variables
holding diverse version numbers at the same time?

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
Configure
util/mkdef.pl

index 45103ff063c4b11e267c9e8c951b6fb192ed00f3..661fe45c8f5a5b4dd58cada33b0ddaa33af1ce71 100755 (executable)
--- a/Configure
+++ b/Configure
@@ -395,7 +395,7 @@ my $openssl_sys_defines="";
 my $openssl_other_defines="";
 my $libs="";
 my $target="";
-my $options="";
+$config{options}="";
 my $api;
 my $make_depend=0;
 my %withargs=();
@@ -610,10 +610,10 @@ foreach (@argvcopy)
                # we really only write OPTIONS to the Makefile out of
                # nostalgia.)
 
-               if ($options eq "")
-                       { $options = $_; }
+               if ($config{options} eq "")
+                       { $config{options} = $_; }
                else
-                       { $options .= " ".$_; }
+                       { $config{options} .= " ".$_; }
                }
 
         if (defined($api) && !exists $apitable->{$api}) {
@@ -676,7 +676,7 @@ if ($target =~ m/^CygWin32(-.*)$/) {
 
 foreach (sort (keys %disabled))
        {
-       $options .= " no-$_";
+       $config{options} .= " no-$_";
 
        printf "    no-%-12s %-10s", $_, "[$disabled{$_}]";
 
@@ -945,12 +945,12 @@ if ($target{build_scheme}->[0] ne "mk1mf")
        if ($no_shared)
                {
                $openssl_other_defines.="#define OPENSSL_NO_DYNAMIC_ENGINE\n";
-               $options.=" static-engine";
+               $config{options}.=" static-engine";
                }
        else
                {
                $openssl_other_defines.="#define OPENSSL_NO_STATIC_ENGINE\n";
-               $options.=" no-static-engine";
+               $config{options}.=" no-static-engine";
                }
        }
 
@@ -1081,36 +1081,36 @@ if (!$no_asm) {
 # and works as well on command lines.
 $cflags =~ s/([\\\"])/\\\1/g;
 
-my $version = "unknown";
-my $version_num = "unknown";
-my $major = "unknown";
-my $minor = "unknown";
-my $shlib_version_number = "unknown";
-my $shlib_version_history = "unknown";
-my $shlib_major = "unknown";
-my $shlib_minor = "unknown";
+$config{version} = "unknown";
+$config{version_num} = "unknown";
+$config{major} = "unknown";
+$config{minor} = "unknown";
+$config{shlib_version_number} = "unknown";
+$config{shlib_version_history} = "unknown";
+$config{shlib_major} = "unknown";
+$config{shlib_minor} = "unknown";
 
 open(IN,'<include/openssl/opensslv.h') || die "unable to read opensslv.h:$!\n";
 while (<IN>)
        {
-       $version=$1 if /OPENSSL.VERSION.TEXT.*OpenSSL (\S+) /;
-       $version_num=$1 if /OPENSSL.VERSION.NUMBER.*(0x\S+)/;
-       $shlib_version_number=$1 if /SHLIB_VERSION_NUMBER *"([^"]+)"/;
-       $shlib_version_history=$1 if /SHLIB_VERSION_HISTORY *"([^"]*)"/;
+       $config{version}=$1 if /OPENSSL.VERSION.TEXT.*OpenSSL (\S+) /;
+       $config{version_num}=$1 if /OPENSSL.VERSION.NUMBER.*(0x\S+)/;
+       $config{shlib_version_number}=$1 if /SHLIB_VERSION_NUMBER *"([^"]+)"/;
+       $config{shlib_version_history}=$1 if /SHLIB_VERSION_HISTORY *"([^"]*)"/;
        }
 close(IN);
-if ($shlib_version_history ne "") { $shlib_version_history .= ":"; }
+if ($config{shlib_version_history} ne "") { $config{shlib_version_history} .= ":"; }
 
-if ($version =~ /(^[0-9]*)\.([0-9\.]*)/)
+if ($config{version} =~ /(^[0-9]*)\.([0-9\.]*)/)
        {
-       $major=$1;
-       $minor=$2;
+       $config{major}=$1;
+       $config{minor}=$2;
        }
 
-if ($shlib_version_number =~ /(^[0-9]*)\.([0-9\.]*)/)
+if ($config{shlib_version_number} =~ /(^[0-9]*)\.([0-9\.]*)/)
        {
-       $shlib_major=$1;
-       $shlib_minor=$2;
+       $config{shlib_major}=$1;
+       $config{shlib_minor}=$2;
        }
 
 if (defined($api)) {
@@ -1215,13 +1215,13 @@ while (<IN>)
        $sdirs = 0 unless /\\$/;
         s/fips // if (/^DIRS=/ && !$fips);
         s/engines // if (/^DIRS=/ && $disabled{"engine"});
-       s/^VERSION=.*/VERSION=$version/;
-       s/^MAJOR=.*/MAJOR=$major/;
-       s/^MINOR=.*/MINOR=$minor/;
-       s/^SHLIB_VERSION_NUMBER=.*/SHLIB_VERSION_NUMBER=$shlib_version_number/;
-       s/^SHLIB_VERSION_HISTORY=.*/SHLIB_VERSION_HISTORY=$shlib_version_history/;
-       s/^SHLIB_MAJOR=.*/SHLIB_MAJOR=$shlib_major/;
-       s/^SHLIB_MINOR=.*/SHLIB_MINOR=$shlib_minor/;
+       s/^VERSION=.*/VERSION=$config{version}/;
+       s/^MAJOR=.*/MAJOR=$config{major}/;
+       s/^MINOR=.*/MINOR=$config{minor}/;
+       s/^SHLIB_VERSION_NUMBER=.*/SHLIB_VERSION_NUMBER=$config{shlib_version_number}/;
+       s/^SHLIB_VERSION_HISTORY=.*/SHLIB_VERSION_HISTORY=$config{shlib_version_history}/;
+       s/^SHLIB_MAJOR=.*/SHLIB_MAJOR=$config{shlib_major}/;
+       s/^SHLIB_MINOR=.*/SHLIB_MINOR=$config{shlib_minor}/;
        s/^SHLIB_EXT=.*/SHLIB_EXT=$target{shared_extension}/;
        s/^INSTALLTOP=.*$/INSTALLTOP=$config{prefix}/;
        s/^MULTILIB=.*$/MULTILIB=$target{multilib}/;
@@ -1229,7 +1229,7 @@ while (<IN>)
        s/^LIBDIR=.*$/LIBDIR=$libdir/;
        s/^INSTALL_PREFIX=.*$/INSTALL_PREFIX=$install_prefix/;
        s/^PLATFORM=.*$/PLATFORM=$target/;
-       s/^OPTIONS=.*$/OPTIONS=$options/;
+       s/^OPTIONS=.*$/OPTIONS=$config{options}/;
        my $argvstring = "(".join(", ", map { quotify("perl", $_) } @argvcopy).")";
        s/^CONFIGURE_ARGS=.*$/CONFIGURE_ARGS=$argvstring/;
        if ($cross_compile_prefix)
@@ -1579,7 +1579,7 @@ EOF
        # create the ms/version32.rc file if needed
        if (! grep /^netware/, @{$target{build_scheme}}) {
            my ($v1, $v2, $v3, $v4);
-           if ($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) {
+           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) {
                $v1=hex $1;
                $v2=hex $2;
                $v3=hex $3;
@@ -1611,7 +1611,7 @@ BEGIN
            // Required:
            VALUE "CompanyName", "The OpenSSL Project, http://www.openssl.org/\\0"
            VALUE "FileDescription", "OpenSSL Shared Library\\0"
-           VALUE "FileVersion", "$version\\0"
+           VALUE "FileVersion", "$config{version}\\0"
 #if defined(CRYPTO)
            VALUE "InternalName", "libeay32\\0"
            VALUE "OriginalFilename", "libeay32.dll\\0"
@@ -1620,7 +1620,7 @@ BEGIN
            VALUE "OriginalFilename", "ssleay32.dll\\0"
 #endif
            VALUE "ProductName", "The OpenSSL Toolkit\\0"
-           VALUE "ProductVersion", "$version\\0"
+           VALUE "ProductVersion", "$config{version}\\0"
            // Optional:
            //VALUE "Comments", "\\0"
            VALUE "LegalCopyright", "Copyright © 1998-2015 The OpenSSL Project. Copyright © 1995-1998 Eric A. Young, Tim J. Hudson. All rights reserved.\\0"
index a2cc12619b2a7ba31fcf4270e97d12b06ad30a40..88c45c7d9b932acfe5150692a3f0aed75062ca97 100755 (executable)
@@ -38,6 +38,9 @@
 #   exclude.
 #
 
+use lib ".";
+use configdata;
+
 my $debug=0;
 
 my $crypto_num= "util/libeay.num";
@@ -128,16 +131,9 @@ foreach (@known_algorithms) {
 # disabled by default
 $disabled_algorithms{"STATIC_ENGINE"} = 1;
 
-my $options="";
-open(IN,"<Makefile") || die "unable to open Makefile!\n";
-while(<IN>) {
-    $options=$1 if (/^OPTIONS=(.*)$/);
-}
-close(IN);
-
 my $zlib;
 
-foreach (@ARGV, split(/ /, $options))
+foreach (@ARGV, split(/ /, $config{options}))
        {
        $debug=1 if $_ eq "debug";
        $W32=1 if $_ eq "32";
@@ -1177,14 +1173,7 @@ sub print_test_file
 }
 
 sub get_version {
-   local *MF;
-   my $v = '?';
-   open MF, 'Makefile' or return $v;
-   while (<MF>) {
-     $v = $1, last if /^VERSION=(.*?)\s*$/;
-   }
-   close MF;
-   return $v;
+   return $config{version};
 }
 
 sub print_def_file