📄 configure.pl
字号:
while(<MODFILE>) { if($_ =~ /^realname \"(.*)\"/) { $HASH{'name'} = $1; } if($_ =~ /^note \"(.*)\"/) { $HASH{'notes'} = $1; } if($_ =~ /^patch_file ([\.\w]*) ([\.\w]*)/) { $HASH{'patch'}{$1} = $2; } if($_ =~ /^add_file ([\.\w]*)/) { $HASH{'add'}{$1} = undef; } if($_ =~ /^replace_file ([\.\w]*)/) { $HASH{'replace'}{$1} = undef; } if($_ =~ /^ignore_file ([\.\w]*)/) { $HASH{'ignore'}{$1} = undef; } if($_ =~ /^define (\w*)/) { $HASH{'define'}{$1} = undef; } if($_ =~ /^link_to (\w*)/) { $HASH{'libs'}{$1} = undef; } if($_ =~ /^needs_std (\w*)/) { $HASH{'needs_std'}{$1} = undef; } if($_ =~ /^uses_asm/) { $HASH{'uses_asm'} = 1; } # Read in a list of supported CPU types (archs and/or submodels) if($_ =~ /^<arch>$/) { while(1) { $_ = process($_ = <MODFILE>); next unless $_; last if ($_ =~ m#^</arch>$#); $HASH{'arch'}{$_} = undef; } } # Read in a list of supported OSes if($_ =~ /^<os>$/) { while(1) { $_ = process($_ = <MODFILE>); next unless $_; last if ($_ =~ m#^</os>$#); $HASH{'os'}{$_} = undef; } } # Read in a list of supported compilers if($_ =~ /^<cc>$/) { while(1) { $_ = process($_ = <MODFILE>); next unless $_; last if ($_ =~ m#^</cc>$#); $HASH{'cc'}{$_} = undef; } } } return %HASH; }sub load_module { my ($modname,$cc,$os,$arch,$sub,$no_asm,%module) = @_; # Check to see if everything is cool about system requirements if(defined($module{'os'}) and !exists($module{'os'}{$os}) and $os ne 'generic') { die "ERROR: Module '$modname' does not support $REALNAME{$os}\n"; } foreach (sort keys %{ $module{'needs_std'} }) { unless($os eq 'generic' or in_array($OS_SUPPORTS_STD{$os}, $_)) { my $stdname = $_; if($REALNAME{$stdname}) { $stdname = $REALNAME{$stdname}; } die "ERROR: Module '$modname' needs $stdname, but $REALNAME{$os} ", "doesn't support it\n"; } } if(defined($module{'arch'}) and $arch ne 'generic' and !exists($module{'arch'}{$arch}) and !exists($module{'arch'}{$sub})) { die "ERROR: Module '$modname' does not support ". "$REALNAME{$arch}/$sub\n"; } if(defined($module{'cc'}) and !exists($module{'cc'}{$cc})) { die "ERROR: Module '$modname' does not support $REALNAME{$cc}\n"; } if($no_asm and exists($module{'uses_asm'})) { print STDERR "WARNING: Module '$modname' disabled (uses assembly)\n"; return; } handle_files($modname, $module{'replace'}, \&replace_file); handle_files($modname, $module{'ignore'}, \&ignore_file); handle_files($modname, $module{'add'}, \&add_file); handle_files($modname, $module{'patch'} , \&patch_file); if(defined($module{'notes'})) { my $realname = $module{'name'}; my $note = $module{'notes'}; print STDERR "$modname (\"$realname\"): $note\n"; }}sub handle_files { my($modname, $hash_scalar, $func) = @_; return unless defined($hash_scalar); my %hash = %{ $hash_scalar }; foreach (sort keys %hash) { if(defined($hash{$_})) { &$func($modname, $_, $hash{$_}); } else { &$func($modname, $_); } }}sub full_path { my ($file,$modname) = @_; if(defined($modname)) { return catfile ($MOD_DIR, $modname, $file); } else { if($file =~ /\.h$/) { return catfile ($INCLUDE_DIR, $file); } elsif($file =~ /\.icc$/) { return catfile ($INCLUDE_DIR, $file); } elsif($file =~ /\.cpp$/) { return catfile ($SRC_DIR, $file); } else { die "ERROR (internal): Not sure where to put $file\n"; } }}sub patch_file { my ($modname,$file,$patch) = @_; ignore_file($modname, $file); # ignore the original $patch = full_path($patch, $modname); check_for_file($patch, $modname); my $patched_file = catfile ($MOD_DIR, $modname, $file); # NOTE: If the file to be patched already exists, we assume that it has # already been patched as well. This could theoretically break if, for # example, the system was configured, then one of the files the patch was # based on was edited. It seems like the Right Thing, because it prevents # the patched files from being remade every time the system is # re-configured. if( ! -e $patched_file ) { copy(full_path($file), $patched_file); my @cmds = (); if($OS_TYPE{$os} eq 'unix' or $OS_TYPE{$os} eq 'beos') { @cmds = ('patch', "$patched_file", "$patch"); } else { die "Don't know how to patch on $os\n"; } if(system(@cmds) != 0) { die "ERROR: Could not execute patch\n"; } } if($patched_file =~ /.cpp$/) { $added_src{$file} = catdir($MOD_DIR, $modname); } else { $added_include{$file} = catdir($MOD_DIR, $modname); } $patched{$file} = $modname; }sub add_file { my ($modname,$file) = @_; check_for_file(full_path($file, $modname), $modname); if($file =~ /.cpp$/) { $added_src{$file} = catdir($MOD_DIR, $modname); } else { $added_include{$file} = catdir($MOD_DIR, $modname); }}sub ignore_file { my ($modname,$file) = @_; check_for_file(full_path($file), $modname); if($file =~ /.cpp$/) { $ignored_src{$file} = 1; } else { $ignored_include{$file} = 1; }}# 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,$file) = @_; ignore_file($modname, $file); add_file($modname, $file);}sub help { print <<ENDOFHELP;Usage: $0 [options] CC-OS-CPUOptions: --debug: tune compiler flags for debugging; inferior code can result --disable-asm: disable all assembly (implied by --debug) --disable-shared: disable building shared libararies --gcc295x: change makefile flags to support GCC 2.95.x --make-style=STYLE: override the guess as to what type of makefile to use --modules=MODS: add module(s) MODS to the library. --module-set=SET: add a pre-specified set of modules. Current sets are: unixYou may use 'generic' for OS or CPU (useful if your OS or CPU isn't listed).CPU can be a generic family name or a specific model name. Common aliases aresupported but not listed. Choosing a specific submodel will usually result incode that will not run on earlier versions of that architecture.ENDOFHELP print_listing('CC', %CC_BINARY_NAME); print_listing('OS', %OS_SUPPORTS_ARCH); print_listing('CPU', %DEFAULT_SUBMODEL); if(%MODULES) { print_listing('MODS', %MODULES); } exit; }sub print_listing { my ($header, %hash) = @_; print "$header: "; my $len = length "$header: "; foreach(sort(keys %hash)) { if($len > 65) { print "\n "; $len = 3; } print "$_ "; $len += length "$_ "; } print "\n"; }################################################### Generate compiler options and print makefile ###################################################sub generate_makefile { my($make_style, $cc, $os, $submodel, $arch, $debug, $no_asm, $no_shared, $special_flag, $lib_src, $check_src, $includes, $added_src, $added_includes, $patched, @libs_used) = @_; my %all_lib_srcs = (%{ $lib_src }, %{ $added_src }); my %all_includes = (%{ $includes }, %{ $added_includes }); ################################################## # Set language options # ################################################## my $lang_flags = $CC_LANG_FLAGS{$cc}; if($special_flag & 1) { $lang_flags = "$lang_flags -fpermissive"; } ################################################## # Set basic optimization options # ################################################## my $lib_opt_flags = $CC_LIB_OPT_FLAGS{$cc}; if(!$debug and ($CC_NO_DEBUG_FLAGS{$cc})) { $lib_opt_flags .= ' '.$CC_NO_DEBUG_FLAGS{$cc}; } if($debug and ($CC_DEBUG_FLAGS{$cc})) { $lib_opt_flags .= ' '.$CC_DEBUG_FLAGS{$cc}; } ################################################## # Set machine dependent optimization options # ################################################## my $mach_opt_flags = ""; if(defined($CC_MACHINE_OPT_FLAGS{$cc}{$submodel})) { $mach_opt_flags = $CC_MACHINE_OPT_FLAGS{$cc}{$submodel}; } elsif(defined($CC_MACHINE_OPT_FLAGS{$cc}{$arch})) { $mach_opt_flags = $CC_MACHINE_OPT_FLAGS{$cc}{$arch}; my $processed_modelname = $submodel; if(defined($CC_MACHINE_OPT_FLAGS_RE{$cc}{$arch})) { $processed_modelname =~ s/$CC_MACHINE_OPT_FLAGS_RE{$cc}{$arch}//; } $mach_opt_flags =~ s/SUBMODEL/$processed_modelname/g; } ################################################## # Figure out static library creation method # ################################################## # This is a default that works on most Unix and Unix-like systems my $ar_command = "ar crs"; my $ar_needs_ranlib = 0; # almost no systems need it anymore # See if there are any over-riding methods. We presume if CC is creating # the static libs, it knows how to create the index itself. if($CC_AR_COMMAND{$cc}) { $ar_command = $CC_AR_COMMAND{$cc}; } elsif($OS_AR_COMMAND{$os}) { $ar_command = $OS_AR_COMMAND{$os}; if($OS_AR_NEEDS_RANLIB{$os}) { $ar_needs_ranlib = 1; } } ################################################## # Set shared object options # ################################################## my $so_link_flags = ""; my $so_obj_flags = $CC_SO_OBJ_FLAGS{$cc}; if($no_shared or (!in_array($OS_SUPPORTS_SHARED{$os}, 'all') and !in_array($OS_SUPPORTS_SHARED{$os}, $arch))) { $so_obj_flags = ""; } elsif(defined($CC_SO_LINK_FLAGS{$cc}{$os})) { $so_link_flags = $CC_SO_LINK_FLAGS{$cc}{$os}; } elsif(defined($CC_SO_LINK_FLAGS{$cc}{'default'})) { $so_link_flags = $CC_SO_LINK_FLAGS{$cc}{'default'}; } my $make_shared = 0; if(($so_obj_flags or $so_link_flags) and $OS_SUPPORTS_SHARED{$os}) { $make_shared = 1; } ################################################## # Set misc ABI options # ################################################## my $ccopts = ""; if(defined($CC_MACH_ABI_FLAGS{$cc}{$arch})) { $ccopts .= ' '.$CC_MACH_ABI_FLAGS{$cc}{$arch}; } if(defined($CC_MACH_ABI_FLAGS{$cc}{'all'})) { $ccopts .= ' '.$CC_MACH_ABI_FLAGS{$cc}{'all'}; } ################################################## # Where to install? # ################################################## # Stupid defaults, but what are you gonna do? my $install_root = '/usr/local'; my $header_dir = 'include'; my $lib_dir = 'lib'; my $doc_dir = 'doc'; unless($os eq 'generic') { $install_root = $INSTALL_INFO{$os}{'root'}, $header_dir = $INSTALL_INFO{$os}{'headers'}, $lib_dir = $INSTALL_INFO{$os}{'libs'}, $doc_dir = $INSTALL_INFO{$os}{'docs'}, } ################################################## # Open the makefile # ################################################## open MAKEFILE, ">$MAKE_FILE" or die "Couldn't write $MAKE_FILE ($!)\n"; ################################################## # Ready, set, print! # ################################################## my $cc_bin = $CC_BINARY_NAME{$cc}; if($os eq "darwin" and $cc eq "gcc") { $cc_bin = "c++"; } # Man that's a lot of arguments. :) my @arguments = (\*MAKEFILE, $cc_bin . $ccopts, $lib_opt_flags, $CC_CHECK_OPT_FLAGS{$cc}, $mach_opt_flags, $lang_flags, $CC_WARN_FLAGS{$cc}, $make_shared, $so_obj_flags, $so_link_flags, $OS_OBJ_SUFFIX{$os}, $OS_SHARED_SUFFIX{$os}, $OS_STATIC_SUFFIX{$os}, $ar_command, $ar_needs_ranlib, \%all_lib_srcs, $check_src, \%all_includes, $patched, \%DOCS, $install_root, $header_dir, $lib_dir, $doc_dir, \@libs_used); if($make_style eq 'unix') { print_unix_makefile(@arguments); } elsif($make_style eq 'nmake') { print_nmake_makefile(@arguments); } else { die "ERROR: This configure script does not know how to make ", "a makefile for makefile style \"$make_style\"\n"; }}################################################### Print a header for a makefile ###################################################sub print_header { my ($fh, $comment, $string) = @_; print $fh $comment x 50, "\n", "$comment $string", ' 'x(47-length($string)), "$comment\n", $comment x 50, "\n";}################################################### Print a Unix style makefile ###################################################sub print_unix_makefile { my ($makefile, $cc, $lib_opt, $check_opt, $mach_opt, $lang_flags, $warn_flags, $make_shared, $so_obj, $so_link, $obj_suffix, $so_suffix, $static_lib_suffix, $ar_command, $use_ranlib, $src_hash, $check_hash, $include_hash, $patched_hash, $docs, $install_root, $header_dir, $lib_dir, $doc_dir, $lib_list) = @_; ################################################## # Some constants # ################################################## my $__TAB__ = "\t"; my $COMMENT_CHAR = '#'; ################################################## # Convert the references to hashes # ################################################## my %src = %{ $src_hash }; my %includes = %{ $include_hash }; my %check = %{ $check_hash }; my %patched = %{ $patched_hash }; my %docs = %{ $docs }; ################################################## # Make the library linking list # ################################################## my $link_to = "-lm"; foreach my $lib (@{ $lib_list }) { $link_to .= " -l" . $lib; } ################################################## # Generate a few variables # ################################################## my $lib_flags = '$(LIB_OPT) $(MACH_OPT) $(LANG_FLAGS) $(WARN_FLAGS)'; my $libs = '$(STATIC_LIB)';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -