diff options
author | lloyd <[email protected]> | 2006-09-02 23:05:19 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2006-09-02 23:05:19 +0000 |
commit | 56f23576dcf9576c40034b2241334fe94f397fa3 (patch) | |
tree | 09f9725561acf25fd194ec224b0d31cfbf31b2ec /configure.pl | |
parent | b36a8abe3d6c59c89ef96e51460e0b513ba3f9ed (diff) |
Put all of the code into a function of some sort (mostly by moving
the code that formed the main part of the script into a new main function).
Diffstat (limited to 'configure.pl')
-rwxr-xr-x | configure.pl | 392 |
1 files changed, 182 insertions, 210 deletions
diff --git a/configure.pl b/configure.pl index 25c93e6f1..3a67dcd19 100755 --- a/configure.pl +++ b/configure.pl @@ -119,6 +119,8 @@ my %CC_SUPPORTS_ARCH = %$CC_SUPPORTS_ARCH; my %CC_AR_COMMAND = %$CC_AR_COMMAND; my %MAKEFILE_STYLE = %$MAKEFILE_STYLE; +my %MODULES; + my $debug = 0; my $no_shared = 0; my $make_style = ''; @@ -130,240 +132,210 @@ my $build_dir = ''; my $local_config = ''; my @using_mods; my ($doc_dir, $lib_dir); +my (%ignored_src, %ignored_include, %added_src, %added_include); +my ($CPP_INCLUDE_DIR, $BUILD_LIB_DIR, $BUILD_CHECK_DIR); +my (%lib_src, %check_src, %include); + +sub main() { + %MODULES = get_modules_list($MOD_DIR); + + GetOptions('debug' => sub { $debug = 1; }, + 'disable-shared' => sub { $no_shared = 1; }, + 'noauto' => sub { $autoconfig = 0 }, + 'gcc295x' => sub { $dumb_gcc = 1; }, + 'dumb-gcc' => sub { $dumb_gcc = 1; }, + 'make-style=s' => \$make_style, + 'modules=s' => \@using_mods, + 'module-set=s' => \$module_set, + 'prefix=s' => \$user_set_root, + 'docdir=s' => \$doc_dir, + 'libdir=s' => \$lib_dir, + 'build-dir=s' => \$build_dir, + 'local-config=s' => \$local_config, + 'help' => sub { help(); } + ); + + if($^O eq 'MSWin32' or $^O eq 'dos' or $^O eq 'cygwin') { + print "Disabling use of symlink()/link() due to Win FS limitations\n"; + $FORCE_COPY = 1; + } -my %MODULES = get_modules_list($MOD_DIR); - -################################################## -# Parse command line options # -################################################## -GetOptions('debug' => sub { $debug = 1; }, - 'disable-shared' => sub { $no_shared = 1; }, - 'noauto' => sub { $autoconfig = 0 }, - 'gcc295x' => sub { $dumb_gcc = 1; }, - 'dumb-gcc' => sub { $dumb_gcc = 1; }, - 'make-style=s' => \$make_style, - 'modules=s' => \@using_mods, - 'module-set=s' => \$module_set, - 'prefix=s' => \$user_set_root, - 'docdir=s' => \$doc_dir, - 'libdir=s' => \$lib_dir, - 'build-dir=s' => \$build_dir, - 'local-config=s' => \$local_config, - 'help' => sub { help(); } - ); - -if($^O eq 'MSWin32' or $^O eq 'dos' or $^O eq 'cygwin') { - print "Disabling use of symlink()/link() due to Win32 FS limitations\n"; - $FORCE_COPY = 1; -} - -my $cc_os_cpu_set = ''; -if($#ARGV == 0) { $cc_os_cpu_set = $ARGV[0]; } -elsif($autoconfig) { - $cc_os_cpu_set = guess_triple(); - print "(autoconfig): Guessing your system config is $cc_os_cpu_set\n"; -} -else { help(); } + my $cc_os_cpu_set = ''; + if($#ARGV == 0) { $cc_os_cpu_set = $ARGV[0]; } + elsif($autoconfig) { + $cc_os_cpu_set = guess_triple(); + print "(autoconfig): Guessing your system config is $cc_os_cpu_set\n"; + } + else { help(); } -my ($cc,$os,$submodel) = split(/-/,$cc_os_cpu_set,3); -if(!defined($cc) or !defined($os) or !defined($submodel)) { help(); } + my ($cc,$os,$submodel) = split(/-/,$cc_os_cpu_set,3); + if(!defined($cc) or !defined($os) or !defined($submodel)) { help(); } -if($build_dir ne '') -{ - $BUILD_DIR = $build_dir; - $BUILD_INCLUDE_DIR = $build_dir . '/include'; -} + if($build_dir ne '') + { + $BUILD_DIR = $build_dir; + $BUILD_INCLUDE_DIR = $build_dir . '/include'; + } -################################################## -# Some special hacks # -################################################## -if($cc eq 'gcc' && $dumb_gcc != 1) -{ - my $gcc_version = ''; + # hacks + if($cc eq 'gcc' && $dumb_gcc != 1) + { + my $gcc_version = ''; - # Stupid Apple. At least they fixed it after 10.2 - if($os eq 'darwin') { $gcc_version = `c++ -v 2>&1`; } - else { $gcc_version = `g++ -v 2>&1`; } + # Stupid Apple. At least they fixed it after 10.2 + if($os eq 'darwin') { $gcc_version = `c++ -v 2>&1`; } + else { $gcc_version = `g++ -v 2>&1`; } - $gcc_version = '' if not defined $gcc_version; + $gcc_version = '' if not defined $gcc_version; - # GCC 2.95.x and 3.[34] are busted in handling long long in C++. The third - # check is because on Cygwin (at least for me) $gcc_version doesn't get the - # output from g++, not sure what's up with that. If it's Cygwin and we - # didn't get output, assume it's a buggy GCC. There is no reduction in code - # quality, etc, so even if we're wrong it's no big deal. + # GCC 2.95.x and 3.[34] are busted in handling long long in + # C++. The third check is because on Cygwin (at least for me) + # $gcc_version doesn't get the output from g++, not sure + # what's up with that. If it's Cygwin and we didn't get + # output, assume it's a buggy GCC. There is no reduction in + # code quality, etc, so even if we're wrong it's no big deal. - if(($gcc_version =~ /4\.[01]/) || - ($gcc_version =~ /3\.[34]/) || - ($gcc_version =~ /2\.95\.[0-4]/) || - ($gcc_version eq '' && $^O eq 'cygwin')) - { - warn "(note): Enabling -fpermissive to work around possible GCC issues\n"; - $dumb_gcc = 1; - } - if($gcc_version =~ /2\.95\.[0-4]/) - { - print "(note): GCC 2.95.x issues a lot of warnings for things in\n" . - " Botan; either ignore the warnings or upgrade to 3.x\n"; + if(($gcc_version =~ /4\.[01]/) || + ($gcc_version =~ /3\.[34]/) || + ($gcc_version =~ /2\.95\.[0-4]/) || + ($gcc_version eq '' && $^O eq 'cygwin')) + { + warn "(note): Enabling -fpermissive to work around " . + "possible GCC issues\n"; + $dumb_gcc = 1; + } + if($gcc_version =~ /2\.95\.[0-4]/) + { + print "(note): GCC 2.95.x issues a lot of warnings for \n" . + " Botan; either ignore the warnings or upgrade to 3.x\n"; + } } -} -################################################## -# Check input # -################################################## -$os = $OS_ALIAS{$os} if(defined $OS_ALIAS{$os}); + $os = $OS_ALIAS{$os} if(defined $OS_ALIAS{$os}); -die "(error): Compiler $cc isn't known\n" unless defined($CC_BINARY_NAME{$cc}); + die "(error): Compiler $cc isn't known\n" + unless defined($CC_BINARY_NAME{$cc}); -die "(error): OS $os isn't known\n" unless - (defined($OS_SUPPORTS_ARCH{$os}) or $os eq 'generic'); + die "(error): OS $os isn't known\n" unless + (defined($OS_SUPPORTS_ARCH{$os}) or $os eq 'generic'); -# Get the canonical submodel name (like r8k -> r8000) -$submodel = $SUBMODEL_ALIAS{$submodel} if(defined($SUBMODEL_ALIAS{$submodel})); + # Get the canonical submodel name (like r8k -> r8000) + $submodel = $SUBMODEL_ALIAS{$submodel} + if(defined($SUBMODEL_ALIAS{$submodel})); -my $arch = undef; -# Convert an arch alias to it's real name (like axp -> alpha) -if(defined($ARCH_ALIAS{$submodel})) - { $arch = $ARCH_ALIAS{$submodel}; $submodel = $arch; } -# If it's a regular submodel type, figure out what arch it is -elsif(defined($ARCH{$submodel})) - { $arch = $ARCH{$submodel}; } -elsif($submodel eq 'generic') { $arch = 'generic'; } -else { die "(error): Arch $submodel isn't known\n"; } + my $arch = undef; + # Convert an arch alias to it's real name (like axp -> alpha) + if(defined($ARCH_ALIAS{$submodel})) { + $arch = $ARCH_ALIAS{$submodel}; + $submodel = $arch; + } + # If it's a regular submodel type, figure out what arch it is + elsif(defined($ARCH{$submodel})) { + $arch = $ARCH{$submodel}; + } + elsif($submodel eq 'generic') { $arch = 'generic'; } + else { die "(error): Arch $submodel isn't known\n"; } -# If we got a generic family name as the model type -if($submodel eq $arch and $submodel ne 'generic') { - $submodel = $DEFAULT_SUBMODEL{$arch}; + # If we got a generic family name as the model type + if($submodel eq $arch and $submodel ne 'generic') { + $submodel = $DEFAULT_SUBMODEL{$arch}; - warn "(note): Using $submodel as default type for family ", + warn "(note): Using $submodel as default type for family ", $REALNAME{$arch},"\n" if($submodel ne $arch); -} + } -$make_style = $MAKEFILE_STYLE{$cc} unless($make_style); + $make_style = $MAKEFILE_STYLE{$cc} unless($make_style); -die "(error): Module set $module_set isn't known\n" - if($module_set && !defined($MODULE_SETS{$module_set})); + die "(error): Module set $module_set isn't known\n" + if($module_set && !defined($MODULE_SETS{$module_set})); -if($module_set) { - foreach (@{ $MODULE_SETS{$module_set} }) { push @using_mods,$_; } -} + if($module_set) { + foreach (@{ $MODULE_SETS{$module_set} }) { push @using_mods,$_; } + } -@using_mods = grep {/./} split(/,/,join(',',@using_mods)); + @using_mods = grep {/./} split(/,/,join(',',@using_mods)); -if($autoconfig) -{ - foreach (guess_mods($cc,$os,$arch,$submodel)) + if($autoconfig) { - # Print a notice, *unless* it was enabled explicitly or via module set - my $picked_by_user = 0; - foreach my $x (@using_mods) { $picked_by_user = 1 if($_ eq $x); } + foreach (guess_mods($cc,$os,$arch,$submodel)) + { + # Print a notice, unless it was enabled explicitly or + # via module set + my $picked_by_user = 0; + foreach my $x (@using_mods) { $picked_by_user = 1 if($_ eq $x); } - print " (autoconfig): Enabling module $_\n" if(!$picked_by_user); - push @using_mods, $_; + print " (autoconfig): Enabling module $_\n" if(!$picked_by_user); + push @using_mods, $_; + } } -} - -# Uniqify @using_mods -my %uniqed_mods; -foreach my $mod (@using_mods) { $uniqed_mods{$mod} = 0; } -@using_mods = sort keys %uniqed_mods; -foreach (@using_mods) { - die "(error): Module $_ isn't known (try --help)\n" - unless(exists($MODULES{$_})); -} - -################################################## -# Does the OS support the arch? # -################################################## -die "(error): $REALNAME{$os} doesn't run on $arch ($submodel)\n" - unless($arch eq 'generic' or $os eq 'generic' or - in_array($OS_SUPPORTS_ARCH{$os}, $arch)); + # Uniqify @using_mods + my %uniqed_mods; + foreach my $mod (@using_mods) { $uniqed_mods{$mod} = 0; } + @using_mods = sort keys %uniqed_mods; -################################################## -# Does the compiler support the arch? # -################################################## -die "(error): $REALNAME{$cc} doesn't run on $arch ($submodel)\n" - unless($arch eq 'generic' or (in_array($CC_SUPPORTS_ARCH{$cc}, $arch))); + foreach (@using_mods) { + die "(error): Module $_ isn't known (try --help)\n" + unless(exists($MODULES{$_})); + } -################################################## -# Does the compiler support the OS? # -################################################## -die "(error): $REALNAME{$cc} doesn't run on $REALNAME{$os}\n" - unless($os eq 'generic' or (in_array($CC_SUPPORTS_OS{$cc}, $os))); + die "(error): $REALNAME{$os} doesn't run on $arch ($submodel)\n" + unless($arch eq 'generic' or $os eq 'generic' or + in_array($OS_SUPPORTS_ARCH{$os}, $arch)); -################################################## -# Check for conflicts in the module selections # -################################################## -check_for_conflicts(@using_mods); -my (%ignored_src, %ignored_include, %added_src, %added_include); -foreach (@using_mods) { - load_module($_, $cc, $os, $arch, $submodel, %{ $MODULES{$_} }); -} + die "(error): $REALNAME{$cc} doesn't run on $arch ($submodel)\n" + unless($arch eq 'generic' or + (in_array($CC_SUPPORTS_ARCH{$cc}, $arch))); -################################################## -# Print some source files # -################################################## -print_pkg_config($os, $MAJOR_VERSION, $MINOR_VERSION, $PATCH_VERSION, - using_libs($os, @using_mods)); + die "(error): $REALNAME{$cc} doesn't run on $REALNAME{$os}\n" + unless($os eq 'generic' or (in_array($CC_SUPPORTS_OS{$cc}, $os))); -################################################## -# Figure out the files involved # -################################################## -my $CPP_INCLUDE_DIR = catdir($BUILD_INCLUDE_DIR, $CPP_INCLUDE_DIR_DIRNAME); -my $BUILD_LIB_DIR = catdir($BUILD_DIR, $BUILD_DIR_LIB); -my $BUILD_CHECK_DIR = catdir($BUILD_DIR, $BUILD_DIR_CHECKS); + check_for_conflicts(@using_mods); + foreach (@using_mods) { + load_module($_, $cc, $os, $arch, $submodel, %{ $MODULES{$_} }); + } -my %lib_src = list_dir($SRC_DIR, \%ignored_src); -my %check_src = list_dir($CHECK_DIR, undef); + print_pkg_config($os, $MAJOR_VERSION, $MINOR_VERSION, $PATCH_VERSION, + using_libs($os, @using_mods)); -my %include = list_dir($INCLUDE_DIR, \%ignored_include); + $CPP_INCLUDE_DIR = + File::Spec->catdir($BUILD_INCLUDE_DIR, $CPP_INCLUDE_DIR_DIRNAME); + $BUILD_LIB_DIR = File::Spec->catdir($BUILD_DIR, $BUILD_DIR_LIB); + $BUILD_CHECK_DIR = File::Spec->catdir($BUILD_DIR, $BUILD_DIR_CHECKS); -################################################## -# Set up the build tree # -################################################## -mkdirs(($BUILD_DIR, - $BUILD_INCLUDE_DIR, $CPP_INCLUDE_DIR, - $BUILD_LIB_DIR, $BUILD_CHECK_DIR)); -clean_out_dirs(($CPP_INCLUDE_DIR)); + %lib_src = list_dir($SRC_DIR, \%ignored_src); + %check_src = list_dir($CHECK_DIR, undef); -################################################## -# Generate the config.h header # -################################################## -my $CONFIG_H_FILE = catfile($BUILD_DIR, $CONFIG_HEADER); + %include = list_dir($INCLUDE_DIR, \%ignored_include); -print_config_h($MAJOR_VERSION, $MINOR_VERSION, $PATCH_VERSION, - $os, $arch, $submodel, - find_mp_bits(@using_mods), defines(@using_mods), - defines_base(@using_mods)); + mkdirs(($BUILD_DIR, + $BUILD_INCLUDE_DIR, $CPP_INCLUDE_DIR, + $BUILD_LIB_DIR, $BUILD_CHECK_DIR)); + clean_out_dirs(($CPP_INCLUDE_DIR)); -$added_include{$CONFIG_HEADER} = $BUILD_DIR; + my $config_h = File::Spec->catfile($BUILD_DIR, $CONFIG_HEADER); -################################################## -# Copy all headers # -################################################## -copy_files($CPP_INCLUDE_DIR, \%include, \%added_include); + print_config_h($MAJOR_VERSION, $MINOR_VERSION, $PATCH_VERSION, + $config_h, $local_config, $os, $arch, $submodel, + find_mp_bits(@using_mods), defines(@using_mods), + defines_base(@using_mods)); -################################################## -# Print the makefile # -################################################## -my %all_includes = list_dir($CPP_INCLUDE_DIR); + $added_include{$CONFIG_HEADER} = $BUILD_DIR; -generate_makefile($make_style, - $cc, $os, $submodel, $arch, - $debug, $no_shared, $dumb_gcc, - \%lib_src, \%check_src, \%all_includes, - \%added_src, using_libs($os, @using_mods)); + copy_files($CPP_INCLUDE_DIR, \%include, \%added_include); -exit; + my %all_includes = list_dir($CPP_INCLUDE_DIR); -sub catfile { - return File::Spec->catfile(@_); + generate_makefile($make_style, + $cc, $os, $submodel, $arch, + $debug, $no_shared, $dumb_gcc, + \%lib_src, \%check_src, \%all_includes, + \%added_src, using_libs($os, @using_mods)); } -sub catdir { - return File::Spec->catdir(@_); -} +# Run stuff, quit +main(); +exit; sub process { my $l = $_[0]; @@ -495,7 +467,7 @@ sub clean_out_dirs { foreach my $dir (@dirs) { my %files = list_dir($dir); foreach my $file (keys %files) { - my $path = catfile($dir, $file); + my $path = File::Spec->catfile($dir, $file); unlink $path or die "Could not unlink $path ($!)\n"; } } @@ -540,7 +512,7 @@ sub find_mp_bits } sub print_config_h { - my ($major, $minor, $patch, $os, $arch, $cpu, + my ($major, $minor, $patch, $config_h, $local_config, $os, $arch, $cpu, $mp_bits, $defines_ref, $defines_base_ref) = @_; my @defines = @{ $defines_ref }; @@ -564,8 +536,8 @@ sub print_config_h if($defines) { $defines = "\n" . $defines . "\n"; } - open CONFIG_H, ">$CONFIG_H_FILE" or - die "Couldn't write $CONFIG_H_FILE ($!)\n"; + open CONFIG_H, ">$config_h" or + die "Couldn't write $config_h ($!)\n"; print CONFIG_H <<END_OF_CONFIG_H; /************************************************* @@ -665,7 +637,7 @@ sub get_module_info { my ($MODULE, $MOD_DIR) = @_; my %HASH; - my $mod_dirname = catfile($MOD_DIR,$MODULE); + my $mod_dirname = File::Spec->catfile($MOD_DIR,$MODULE); my $mod_dir = new DirHandle $mod_dirname; if(!defined $mod_dir) { die "(error): Couldn't open dir $mod_dirname ($!)\n"; } @@ -682,7 +654,7 @@ sub get_module_info die "(error): Module $MODULE does not seem to have a description file\n" unless $have_config_file; - my $desc_file = catfile($MOD_DIR,$MODULE,$mod_info_name); + my $desc_file = File::Spec->catfile($MOD_DIR,$MODULE,$mod_info_name); open MODFILE, "<$desc_file" or die "(error): Couldn't open file $desc_file, ($!)\n"; @@ -825,12 +797,12 @@ sub handle_files { sub full_path { my ($file,$modname) = @_; if(defined($modname)) - { return catfile ($MOD_DIR, $modname, $file); } + { return File::Spec->catfile ($MOD_DIR, $modname, $file); } else { if($file =~ /\.h$/) - { return catfile ($INCLUDE_DIR, $file); } + { return File::Spec->catfile ($INCLUDE_DIR, $file); } elsif($file =~ /\.cpp$/ or $file =~ /\.s$/ or $file =~ /\.S$/) - { return catfile ($SRC_DIR, $file); } + { return File::Spec->catfile ($SRC_DIR, $file); } else { die "(internal error): Not sure where to put $file\n"; } } } @@ -839,9 +811,9 @@ sub add_file { my ($modname,$file) = @_; check_for_file(full_path($file, $modname), $modname); if($file =~ /\.cpp$/ or $file =~ /\.s$/ or $file =~ /\.S$/) - { $added_src{$file} = catdir($MOD_DIR, $modname); } + { $added_src{$file} = File::Spec->catdir($MOD_DIR, $modname); } elsif($file =~ /\.h$/) - { $added_include{$file} = catdir($MOD_DIR, $modname); } + { $added_include{$file} = File::Spec->catdir($MOD_DIR, $modname); } else { die "Not sure where to put $file\n"; } } @@ -1306,7 +1278,7 @@ sub generate_makefile { $ar_needs_ranlib, \%all_lib_srcs, $check_src, - \%all_includes, + $all_includes, \%DOCS, $install_root, $header_dir, @@ -1409,7 +1381,7 @@ sub print_unix_makefile { { $list .= "\\\n" . ' 'x$spaces; $len = $spaces; } if(defined($from) and defined($to)) { $file =~ s/$from/$to/; } if(defined($dir)) - { $list .= catfile ($dir, $file) . ' '; + { $list .= File::Spec->catfile ($dir, $file) . ' '; $len += length($file) + length($dir); } else { $list .= $file . ' '; @@ -1525,8 +1497,8 @@ END_OF_SHARED_LIB_DECL sub print_build_cmds { my ($fh, $dir, $flags, $obj_suffix, %files) = @_; foreach (sort keys %files) { - my $src_file = catfile ($files{$_}, $_); - my $obj_file = catfile ($dir, $_); + my $src_file = File::Spec->catfile ($files{$_}, $_); + my $obj_file = File::Spec->catfile ($dir, $_); $obj_file =~ s/\.cpp$/.$obj_suffix/; $obj_file =~ s/\.s$/.$obj_suffix/; $obj_file =~ s/\.S$/.$obj_suffix/; @@ -1754,8 +1726,8 @@ END_OF_FILE_LISTS sub print_build_cmds_nmake { my ($fh, $dir, $flags, $obj_suffix, %files) = @_; foreach (sort keys %files) { - my $src_file = catfile ($files{$_}, $_); - my $obj_file = catfile ($dir, $_); + my $src_file = File::Spec->catfile ($files{$_}, $_); + my $obj_file = File::Spec->catfile ($dir, $_); $obj_file =~ s/.cpp/.$obj_suffix/; print $fh "$obj_file: $src_file\n", "\t\$(CXX) -I$BUILD_INCLUDE_DIR $flags /c \$? /Fo\$@\n\n"; @@ -1906,7 +1878,7 @@ sub arch_defines { while(defined($_ = $dir->read)) { next if($_ eq '.' or $_ eq '..'); my $arch = $_; - my $filename = catfile($_[0], $arch); + my $filename = File::Spec->catfile($_[0], $arch); open ARCHFILE, "<$filename" or die "Couldn't open $filename, ($!)"; $ARCH{$arch} = $arch; @@ -1975,7 +1947,7 @@ sub os_defines { next if($_ eq '.' or $_ eq '..'); my $os = $_; - my $filename = catfile($_[0], $os); + my $filename = File::Spec->catfile($_[0], $os); open OSFILE, "<$filename" or die "Couldn't open $filename, ($!)"; $OS_SHARED_SUFFIX{$os} = ''; $OS_AR_COMMAND{$os} = ''; @@ -2068,7 +2040,7 @@ sub cc_defines { while(defined($_ = $dir->read)) { next if($_ eq '.' or $_ eq '..'); my $cc = $_; - my $filename = catfile($_[0], $cc); + my $filename = File::Spec->catfile($_[0], $cc); open CCFILE, "<$filename" or die "Couldn't open $filename, ($!)"; # Default to empty values, so they don't have to be explicitly set |