The unified diff between revisions [637b2e22..] and [0f5f960e..] is displayed below. It can also be downloaded as a raw diff.

This diff has been restricted to the following files: 'configure.pl'

#
#
# patch "configure.pl"
#  from [f78c7abe497df046548c1bcfce467c15c507fd38]
#    to [77d8487d93bc40c001c39cd7f0aedb01c8f38bfe]
#
============================================================
--- configure.pl	f78c7abe497df046548c1bcfce467c15c507fd38
+++ configure.pl	77d8487d93bc40c001c39cd7f0aedb01c8f38bfe
@@ -8,8 +8,8 @@ my $MAJOR_VERSION = 1;
 use File::Copy;

 my $MAJOR_VERSION = 1;
-my $MINOR_VERSION = 5;
-my $PATCH_VERSION = 11;
+my $MINOR_VERSION = 6;
+my $PATCH_VERSION = 1;

 my $VERSION_STRING = "$MAJOR_VERSION.$MINOR_VERSION.$PATCH_VERSION";

@@ -22,7 +22,7 @@ my @DOCS = (
    'api.pdf', 'tutorial.pdf', 'fips140.pdf',
    'api.tex', 'tutorial.tex', 'fips140.tex',
    'credits.txt', 'info.txt', 'license.txt', 'log.txt',
-   'thanks.txt', 'todo.txt', 'botan.rc', 'pgpkeys.asc');
+   'thanks.txt', 'todo.txt', 'pgpkeys.asc');

 my %MODULE_SETS =
     (
@@ -44,13 +44,23 @@ sub main {
 # Main Driver                                    #
 ##################################################
 sub main {
-    %CPU = read_info_files('arch', \&get_arch_info);
-    %OPERATING_SYSTEM = read_info_files('os', \&get_os_info);
-    %COMPILER = read_info_files('cc', \&get_cc_info);
-    %MODULES = read_module_files('modules');
+    my $config = {};

-    my $config = {};
+    my $base_dir = where_am_i();

+    $$config{'base-dir'} = $base_dir;
+    $$config{'config-dir'} = File::Spec->catdir($base_dir, 'misc', 'config');
+    $$config{'mods-dir'} = File::Spec->catdir($base_dir, 'modules');
+    $$config{'src-dir'} = File::Spec->catdir($base_dir, 'src');
+    $$config{'include-dir'} = File::Spec->catdir($base_dir, 'include');
+    $$config{'checks-dir'} = File::Spec->catdir($base_dir, 'checks');
+    $$config{'doc-dir'} = File::Spec->catdir($base_dir, 'doc');
+
+    %CPU = read_info_files($config, 'arch', \&get_arch_info);
+    %OPERATING_SYSTEM = read_info_files($config, 'os', \&get_os_info);
+    %COMPILER = read_info_files($config, 'cc', \&get_cc_info);
+    %MODULES = read_module_files($config);
+
     add_to($config, {
         'version_major' => $MAJOR_VERSION,
         'version_minor' => $MINOR_VERSION,
@@ -91,37 +101,37 @@ sub main {
         'build_check'   => File::Spec->catdir($$config{'build-dir'}, 'checks'),
         'build_include' =>
             File::Spec->catdir($$config{'build-dir'}, 'include'),
+        'build_include_botan' =>
+            File::Spec->catdir($$config{'build-dir'}, 'include', 'botan'),

         'modules'       => [ @modules ],
         'mp_bits'       => find_mp_bits(@modules),
         'mod_libs'      => [ using_libs($os, @modules) ],

-        'sources'       => { map_to('src', dir_list('src')) },
-        'includes'      => { map_to('include', dir_list('include')) },
-        'check_src'     => { map_to('checks',
-                                    grep { $_ ne 'keys' and !m@\.(dat|h)$@ }
-                                    dir_list('checks'))
+        'sources'       => {
+            map_to($$config{'src-dir'}, dir_list($$config{'src-dir'}))
+            },
+
+        'includes'      => {
+            map_to($$config{'include-dir'}, dir_list($$config{'include-dir'}))
+            },
+
+        'check_src'     => {
+            map_to($$config{'checks-dir'},
+                   grep { $_ ne 'keys' and !m@\.(dat|h)$@ }
+                      dir_list($$config{'checks-dir'}))
             }
         });

-    foreach my $mod (@modules) {
-        load_module($config, $MODULES{$mod});
-    }
+    load_modules($config);

-    add_to($config, {
-        'defines' => defines($config),
-
-        'build_include_botan' =>
-            File::Spec->catdir($$config{'build_include'}, 'botan')
-        });
-
     mkdirs($$config{'build-dir'},
            $$config{'build_include'}, $$config{'build_include_botan'},
            $$config{'build_lib'}, $$config{'build_check'});

     write_pkg_config($config);

-    process_template(File::Spec->catfile('misc', 'config', 'buildh.in'),
+    process_template(File::Spec->catfile($$config{'config-dir'}, 'buildh.in'),
                      File::Spec->catfile($$config{'build-dir'}, 'build.h'),
                      $config);
     $$config{'includes'}{'build.h'} = $$config{'build-dir'};
@@ -131,6 +141,13 @@ sub main {
     generate_makefile($config);
 }

+sub where_am_i {
+    my ($volume,$dir,$file) = File::Spec->splitpath($0);
+    my $src_dir = File::Spec->catpath($volume, $dir, '');
+    return $src_dir if $src_dir;
+    return File::Spec->curdir();
+}
+
 ##################################################
 # Diagnostics                                    #
 ##################################################
@@ -172,7 +189,7 @@ sub trace {
     $func1 =~ s/main:://;
     $func2 =~ s/main:://;

-    warn with_diagnostic('trace', "at $func1:$line1 -\n", @_);
+    warn with_diagnostic('trace', "at $func1:$line1 - ", @_);
 }

 ##################################################
@@ -530,11 +547,10 @@ sub my_compiler {
     my ($config) = @_;
     my $cc = $$config{'compiler'};

-    croak('my_compiler called, but no compiler set')
+    croak('my_compiler called, but no compiler set in config')
         unless defined $cc and $cc ne '';

-    croak('unknown compiler $cc')
-        unless defined $COMPILER{$cc};
+    croak("unknown compiler $cc") unless defined $COMPILER{$cc};

     return %{$COMPILER{$cc}};
 }
@@ -545,7 +561,7 @@ sub mach_opt {
     my %ccinfo = my_compiler($config);

     # Nothing we can do in that case
-    return '' unless defined($ccinfo{'mach_opt_flags'});
+    return '' unless $ccinfo{'mach_opt_flags'};

     my $submodel = $$config{'submodel'};
     my $arch = $$config{'arch'};
@@ -644,6 +660,8 @@ sub copy_include_files {

     my $include_dir = $$config{'build_include_botan'};

+    trace('Copying to ', $include_dir);
+
     foreach my $file (dir_list($include_dir)) {
         my $path = File::Spec->catfile($include_dir, $file);
         unlink $path or croak("Could not unlink $path ($!)");
@@ -666,7 +684,7 @@ sub dir_list {

 sub dir_list {
     my ($dir) = @_;
-    opendir(DIR, $dir) or croak("Couldn't read directory $dir ($!)");
+    opendir(DIR, $dir) or croak("Couldn't read directory '$dir' ($!)");

     my @listing = grep { $_ ne File::Spec->curdir() and
                          $_ ne File::Spec->updir() } readdir DIR;
@@ -779,11 +797,53 @@ sub realname {
 ##################################################
 #                                                #
 ##################################################
+sub load_modules {
+    my ($config) = @_;
+
+    my @modules = @{$$config{'modules'}};
+
+    foreach my $mod (@modules) {
+        load_module($config, $mod);
+    }
+
+    my $gen_defines = sub {
+        my $defines = '';
+
+        my $arch = $$config{'arch'};
+        if($arch ne 'generic') {
+            $arch = uc $arch;
+            $defines .= "#define BOTAN_TARGET_ARCH_IS_$arch\n";
+
+            my $submodel = $$config{'submodel'};
+            if($arch ne $submodel) {
+                $submodel = uc $submodel;
+                $submodel =~ s/-/_/g;
+                $defines .= "#define BOTAN_TARGET_CPU_IS_$submodel\n";
+            }
+        }
+
+        my @defarray;
+        foreach my $mod (@modules) {
+            my $defs = $MODULES{$mod}{'define'};
+            next unless $defs;
+
+            push @defarray, split(/,/, $defs);
+        }
+        foreach (sort @defarray) {
+            die unless(defined $_ and $_ ne '');
+            $defines .= "#define BOTAN_EXT_$_\n";
+        }
+        chomp($defines);
+        return $defines;
+    };
+
+    $$config{'defines'} = &$gen_defines();
+}
+
 sub load_module {
-    my ($config, $module_ref) = @_;
+    my ($config, $modname) = @_;

-    my %module = %{$module_ref};
-    my $modname = $module{'name'};
+    my %module = %{$MODULES{$modname}};

     my $works_on = sub {
         my ($what, @lst) = @_;
@@ -810,33 +870,34 @@ sub load_module {
     croak("Module '$modname' does not work with $cc")
         unless(&$works_on($cc, @{$module{'cc'}}));

-    sub handle_files {
-        my($modname, $config, $lst, $func) = @_;
+    my $handle_files = sub {
+        my($lst, $func) = @_;
         return unless defined($lst);
+
         foreach (sort @$lst) {
             &$func($modname, $config, $_);
         }
-    }
+    };

-    handle_files($modname, $config, $module{'replace'}, \&replace_file);
-    handle_files($modname, $config, $module{'ignore'},  \&ignore_file);
-    handle_files($modname, $config, $module{'add'},     \&add_file);
+    &$handle_files($module{'ignore'},  \&ignore_file);
+    &$handle_files($module{'add'},     \&add_file);
+    &$handle_files($module{'replace'},
+                   sub { ignore_file(@_); add_file(@_); });

-    if(defined($module{'note'})) {
-        my $realname = $module{'realname'};
-        my $note = $module{'note'};
-        warning("$modname (\"$realname\"): $note\n");
-    }
+    warning($modname, ': ', $module{'note'})
+        if(defined($module{'note'}));
 }

 ##################################################
 #                                                #
 ##################################################
 sub file_type {
-    my ($file) = @_;
+    my ($config, $file) = @_;

-    return ('sources', 'src') if($file =~ /\.cpp$/ or $file =~ /\.S$/);
-    return ('includes', 'include') if($file =~ /\.h$/);
+    return ('sources', $$config{'src-dir'})
+        if($file =~ /\.cpp$/ or $file =~ /\.S$/);
+    return ('includes', $$config{'include-dir'})
+        if($file =~ /\.h$/);

     croak('file_type() - don\'t know what sort of file ', $file, ' is');
 }
@@ -844,9 +905,9 @@ sub add_file {
 sub add_file {
     my ($modname, $config, $file) = @_;

-    check_for_file($file, $modname, $modname);
+    check_for_file($config, $file, $modname, $modname);

-    my $mod_dir = File::Spec->catdir('modules', $modname);
+    my $mod_dir = File::Spec->catdir($$config{'mods-dir'}, $modname);

     my $do_add_file = sub {
         my ($type) = @_;
@@ -857,12 +918,12 @@ sub add_file {
         $$config{$type}{$file} = $mod_dir;
     };

-    &$do_add_file(file_type($file));
+    &$do_add_file(file_type($config, $file));
 }

 sub ignore_file {
     my ($modname, $config, $file) = @_;
-    check_for_file($file, undef, $modname);
+    check_for_file($config, $file, undef, $modname);

     my $do_ignore_file = sub {
         my ($type, $ok_if_from) = @_;
@@ -877,27 +938,19 @@ sub ignore_file {
         }
     };

-    &$do_ignore_file(file_type($file));
+    &$do_ignore_file(file_type($config, $file));
 }

-# This works because ignore file always runs on files in the main source tree,
-# and add always works on the file in the modules directory.
-sub replace_file {
-   my ($modname, $config, $file) = @_;
-   ignore_file($modname, $config, $file);
-   add_file($modname, $config, $file);
-}
-
 sub check_for_file {
-   my ($file, $added_from, $modname) = @_;
+   my ($config, $file, $added_from, $modname) = @_;

    my $full_path = sub {
        my ($file,$modname) = @_;

-       return File::Spec->catfile('modules', $modname, $file)
+       return File::Spec->catfile($$config{'mods-dir'}, $modname, $file)
            if(defined($modname));

-       my @typeinfo = file_type($file);
+       my @typeinfo = file_type($config, $file);
        return File::Spec->catfile($typeinfo[1], $file);
    };

@@ -914,7 +967,7 @@ sub process_template {
 sub process_template {
     my ($in, $out, $config) = @_;

-    trace("process_template($in) -> $out");
+    trace("$in -> $out");

     my $contents = slurp_file($in);

@@ -1011,15 +1064,15 @@ sub read_info_files {
 #                                                #
 ##################################################
 sub read_info_files {
-    my ($dir, $func) = @_;
+    my ($config, $dir, $func) = @_;

-    $dir = File::Spec->catdir('misc', 'config', $dir);
+    $dir = File::Spec->catdir($$config{'config-dir'}, $dir);

     my %allinfo;
     foreach my $file (dir_list($dir)) {
         my $fullpath = File::Spec->catfile($dir, $file);

-        #trace("reading $fullpath");
+        trace("reading $fullpath");
         %{$allinfo{$file}} = &$func($file, $fullpath);
     }

@@ -1027,13 +1080,15 @@ sub read_module_files {
 }

 sub read_module_files {
-    my ($moddir) = @_;
+    my ($config) = @_;

+    my $mod_dir = $$config{'mods-dir'};
+
     my %allinfo;
-    foreach my $dir (dir_list($moddir)) {
-        my $modfile = File::Spec->catfile($moddir, $dir, 'modinfo.txt');
+    foreach my $dir (dir_list($mod_dir)) {
+        my $modfile = File::Spec->catfile($mod_dir, $dir, 'modinfo.txt');

-        #trace("reading $modfile");
+        trace("reading $modfile");
         %{$allinfo{$dir}} = get_module_info($dir, $modfile);
     }

@@ -1231,39 +1286,6 @@ sub guess_mods {
     return @usable_modules;
 }

-sub defines {
-    my ($config) = @_;
-
-    my $defines = '';
-
-    my $arch = $$config{'arch'};
-    if($arch ne 'generic') {
-        $arch = uc $arch;
-        $defines .= "#define BOTAN_TARGET_ARCH_IS_$arch\n";
-
-        my $submodel = $$config{'submodel'};
-        if($arch ne $submodel) {
-            $submodel = uc $submodel;
-            $submodel =~ s/-/_/g;
-            $defines .= "#define BOTAN_TARGET_CPU_IS_$submodel\n";
-        }
-    }
-
-    my @defarray;
-    foreach my $mod (@{$$config{'modules'}}) {
-        my $defs = $MODULES{$mod}{'define'};
-        next unless $defs;
-
-        push @defarray, split(/,/, $defs);
-    }
-    foreach (sort @defarray) {
-        next unless(defined $_ and $_ ne '');
-        $defines .= "#define BOTAN_EXT_$_\n";
-    }
-    chomp($defines);
-    return $defines;
-}
-
 ##################################################
 #                                                #
 ##################################################
@@ -1275,8 +1297,9 @@ sub write_pkg_config {

     $$config{'link_to'} = libs('-l', '', 'm', @{$$config{'mod_libs'}});

-    process_template(File::Spec->catfile('misc', 'config', 'botan-config.in'),
-                     'botan-config', $config);
+    process_template(
+       File::Spec->catfile($$config{'config-dir'}, 'botan-config.in'),
+       'botan-config', $config);
     chmod 0755, 'botan-config';

     delete $$config{'link_to'};
@@ -1469,9 +1492,15 @@ sub generate_makefile {
        'install_group' => os_info_for($os, 'install_group'),
        });

-   my $docs = file_list(undef, undef, undef, map_to('doc', @DOCS));
-   $docs .= 'readme.txt';
+   my $is_in_doc_dir =
+       sub { -e File::Spec->catfile($$config{'doc-dir'}, $_[0]) };

+   my $docs = file_list(undef, undef, undef,
+                        map_to($$config{'doc-dir'},
+                               grep { &$is_in_doc_dir($_); } @DOCS));
+
+   $docs .= File::Spec->catfile($$config{'base-dir'}, 'readme.txt');
+
    my $includes = file_list(undef, undef, undef,
                             map_to($$config{'build_include_botan'},
                                    keys %{$$config{'includes'}}));
@@ -1500,7 +1529,7 @@ sub generate_makefile {
        'include_files'   => $includes
        });

-   my $template_dir = File::Spec->catdir('misc', 'config', 'makefile');
+   my $template_dir = File::Spec->catdir($$config{'config-dir'}, 'makefile');
    my $template = undef;

    my $make_style = $$config{'make_style'};
@@ -1531,7 +1560,7 @@ sub generate_makefile {
    croak("Don't know about makefile format '$make_style'")
        unless defined $template;

-   trace("mapped type '$make_style' to template '$template'");
+   trace("'$make_style' -> '$template'");

    process_template($template, 'Makefile', $config);
 }
@@ -1544,9 +1573,6 @@ sub guess_cpu_from_this
     my $cpuinfo = lc $_[0];
     my $cpu = '';

-    $cpu = 'amd64' if($cpuinfo =~ /athlon64/);
-    $cpu = 'amd64' if($cpuinfo =~ /opteron/);
-
     $cpu = 'athlon' if($cpuinfo =~ /athlon/);
     $cpu = 'pentium4' if($cpuinfo =~ /pentium 4/);
     $cpu = 'pentium4' if($cpuinfo =~ /pentium\(r\) 4/);
@@ -1555,6 +1581,11 @@ sub guess_cpu_from_this
     $cpu = 'pentium3' if($cpuinfo =~ /pentium 3/);
     $cpu = 'pentium2' if($cpuinfo =~ /pentium 2/);

+    $cpu = 'core2duo' if($cpuinfo =~ /intel\(r\) core\(tm\)2/);
+
+    $cpu = 'amd64' if($cpuinfo =~ /athlon64/);
+    $cpu = 'amd64' if($cpuinfo =~ /opteron/);
+
     # The 32-bit SPARC stuff is impossible to match to arch type easily, and
     # anyway the uname stuff will pick up that it's a SPARC so it doesn't
     # matter. If it's an Ultra, assume a 32-bit userspace, no 64-bit code
@@ -1581,6 +1612,7 @@ sub guess_cpu_from_this
         $cpu = 'alpha-ev7' if($cpuinfo =~ /ev7/);
     }

+    trace('guessing ', $cpu) if($cpu);
     return $cpu;
 }

@@ -1609,15 +1641,11 @@ sub guess_triple

         # If we have /proc/cpuinfo, try to get nice specific information about
         # what kind of CPU we're running on.
-        if(-e '/proc/cpuinfo' and -r '/proc/cpuinfo')
-        {
-            open CPUINFO, '/proc/cpuinfo' or
-                croak("Couldn't read /proc/cpuinfo ($!)");
+        my $cpuinfo = '/proc/cpuinfo';

-            my $cpuinfo = join('', <CPUINFO>);
-            close CPUINFO;
-
-            $cpu = guess_cpu_from_this($cpuinfo);
+        if(-e $cpuinfo and -r $cpuinfo)
+        {
+            $cpu = guess_cpu_from_this(slurp_file($cpuinfo));
         }

         # `umame -p` is sometimes something stupid like unknown, but in some
@@ -1631,38 +1659,38 @@ sub guess_triple
             # If guess_cpu_from_this didn't figure it out, try it plain
             if($cpu eq '') { $cpu = lc $uname_p; }

-            my (%SUBMODEL_ALIAS, %ARCH_ALIAS, %ARCH);
+            sub known_arch {
+                my ($name) = @_;

-            foreach my $arch (keys %CPU) {
-                my %info = %{$CPU{$arch}};
+                foreach my $arch (keys %CPU) {
+                    my %info = %{$CPU{$arch}};

-                $ARCH{$arch} = $info{'name'};
-                foreach my $submodel (@{$info{'submodels'}}) {
-                    $ARCH{$submodel} = $info{'name'};
-                }
+                    return 1 if $name eq $info{'name'};
+                    foreach my $submodel (@{$info{'submodels'}}) {
+                        return 1 if $name eq $submodel;
+                    }

-                foreach my $alias (@{$info{'aliases'}}) {
-                    $ARCH_ALIAS{$alias} = $arch;
-                }
+                    foreach my $alias (@{$info{'aliases'}}) {
+                        return 1 if $name eq $alias;
+                    }

-                if(defined($info{'submodel_aliases'})) {
-                    my %submodel_aliases = %{$info{'submodel_aliases'}};
-                    foreach my $sm_alias (keys %submodel_aliases) {
-                        $SUBMODEL_ALIAS{$sm_alias} =
-                            $submodel_aliases{$sm_alias};
+                    if(defined($info{'submodel_aliases'})) {
+                        my %submodel_aliases = %{$info{'submodel_aliases'}};
+                        foreach my $sm_alias (keys %submodel_aliases) {
+                            return 1 if $name eq $sm_alias;
+                        }
                     }
                 }
+                return 0;
             }

-            if(!defined $ARCH{$cpu} && !defined $SUBMODEL_ALIAS{$cpu} &&
-               !defined $ARCH_ALIAS{$cpu})
+            if(!known_arch($cpu))
             {
                 # Nope, couldn't figure out uname -p
                 $cpu = lc `uname -m 2>/dev/null`;
                 chomp $cpu;

-                if(!defined $ARCH{$cpu} && !defined $SUBMODEL_ALIAS{$cpu} &&
-                   !defined $ARCH_ALIAS{$cpu})
+                if(!known_arch($cpu))
                 {
                     $cpu = 'generic';
                 }