📄 mexsetup.pm
字号:
} else { printf "\nOptions file not changed.\n"; return 1; } } # Open the target output file, and write the template file into it. # when the Root Environment Variable (root_var) is assigned to, burn in # the compiler location. open (OPTIONSFILE, ">$destOptsFile") || die "Error: Can't open $destOptsFile"; my $done=0; foreach (@OptionsFile) { if (!$done && /^\s*set $record->{"root_var"}=/) { s/%\w+%/$root_val/; $done=1; } print OPTIONSFILE "$_"; } close(OPTIONSFILE); return 0;}# This is the main routine for mexsetup. Only &setup can be called from outside of # this module. This routine queries the user for the default compiler to be used with mex# or mbuild and installs the appropriate options file into the user's user profile # directory.sub setup{ my ($tool_name, # "mex" or "mbuild" $opts_dir, # The directory containing the .stp setup files and .bat opts files $desired_languages, # An array reference containing uppercase strings of the # desired programming language for which to set up. All # compilers are listed if any of these strings are 'ANY'. $automode # if true, automatically search for compilers, and if only one is # found, install it without bothering the user ) = @_; my @filenames; my $filename; my $i; my $record; my @optfile_records; my $compiler_location; my $ask_no_questions; # Turn off buffered output. my $old_pipe = $|; $| = 1; if (!$automode) { print "Please choose your compiler "; if ($tool_name eq "mex") { print "for building external interface (MEX) files:\n\n"; } else { print "for building standalone MATLAB applications:\n\n"; } } my $matlab_bin = $opts_dir . "\\.."; while ($matlab_bin =~ s/\\[^\\.]+\\\.\.//) {} # This structure is passed to the compiler setup function at initialization. my $optfile_inputs = { 'matlab_bin' => $matlab_bin, 'registry_lookup' => \®istry_lookup, 'search_path' => \&search_path }; # Get a list of all the *.stp files in $opts_dir. opendir OPTSDIR, "$opts_dir" || die "Error: Couldn't find $opts_dir"; @filenames = grep /^*.stp$/i, readdir OPTSDIR; @filenames = map { lc $_ } @filenames; closedir OPTSDIR; # For each .stp file, dynamically include it and call its initialization # routine (whose name must be the same as the .stp file minus the ".stp". foreach $filename (@filenames) { require "$opts_dir\\$filename"; $filename =~ s/.stp//; # remove .stp extension # $filename is a string containing the name of a function to call, # a so-called "symbolic reference". 'Use strict' disallows this normally, # so the no strict/use strict stuff below temporarily allows it. no strict 'refs'; $record = &$filename($optfile_inputs); use strict 'refs'; my $language_handled_fcn = $record->{"language_handled"}; my $language; # Only add the record to the master list (optfile_records) if it # can handle at least one of the requested language. foreach $language (@$desired_languages) { if ($language eq "ANY" || &$language_handled_fcn($language)) { push(@optfile_records, $record); last; } } } if ($#optfile_records == -1) { my $errmsg = "Error: Could not detect a compiler on local system"; if ($automode) { $errmsg .= "\nwhich can compile the specified input file(s)"; } die $errmsg; } my $status; if ($automode) { $status eq "yes"; } else { print "Would you like $tool_name to locate installed compilers [y]/n? "; chop($status=<STDIN>); } $status = lc(substr($status, 0, 1)); if ($status ne "n") { # User wants us to try to find local compilers. my @found_compiler_locations = (); my @found_compilers=(); my $group_id; my @curr_group_found_compiler_locations = (); my @curr_group_found_compilers = (); @optfile_records = sort by_group_and_serial @optfile_records; $group_id = ""; foreach $record (@optfile_records) { if ($record->{"group_id"} ne $group_id) { # Processing a new group; push all info from old group onto main # "found" lists, and clear out "curr_group" lists. push(@found_compiler_locations, @curr_group_found_compiler_locations); push(@found_compilers, @curr_group_found_compilers); @curr_group_found_compiler_locations = (); @curr_group_found_compilers = (); $group_id = $record->{"group_id"}; } # Call the locate function for the current record: my $locate_fcn = $record->{"locate"}; my @locations = &$locate_fcn; my $location; # The locate function can return an array of directories. Check each # directory against the list of directories already identified by # later records for the same group (remember, the list was sorted # by group and then by serial number.) As soon as we find a directory # not already "claimed" by a newer/later compiler record, remember it # as the directory where a compiler for $record was found. foreach $location (@locations) { if (!is_in($location, \@curr_group_found_compiler_locations)) { push(@curr_group_found_compiler_locations, $location); push(@curr_group_found_compilers, $record); last; } } } # Push the info from the last group on the master list onto main "found" lists. push(@found_compiler_locations, @curr_group_found_compiler_locations); push(@found_compilers, @curr_group_found_compilers); my $compiler; if ($automode && $#found_compilers == 0) { # only one compiler found and we're in automode, so just choose it. $compiler = 1; } else { if ($automode) { print "Please choose your compiler "; if ($tool_name eq "mex") { print "for building external interface (MEX) files:\n\n"; } else { print "for building standalone MATLAB applications:\n\n"; } } print "\nSelect a compiler:\n"; my $count = 1; foreach $record (@found_compilers) { print "[$count] " . $record->{"vendor_name"} . " version " . $record->{"version"} . " in $found_compiler_locations[$count-1]\n"; $count++; } print "\n[0] None\n\n"; print "Compiler: "; $compiler=&query_info(0, $count - 1, "Please select from 0-" . ($count-1), "Compiler: "); if ($compiler == 0) { print "\n $tool_name: No compiler selected. No action taken.\n\n"; return; } } $record = $found_compilers[$compiler-1]; $compiler_location = $found_compiler_locations[$compiler-1]; $ask_no_questions = $automode && $#found_compilers == 0; } else { # User wants a list of all the compilers we know about. @optfile_records = sort by_vendor_and_serial @optfile_records; print "\nSelect a compiler:\n"; my $count = 1; foreach $record (@optfile_records) { print "[$count] " . $record->{"vendor_name"} . " version " . $record->{"version"} . "\n"; $count++; } print "\n[0] None\n\n"; print "Compiler: "; my $compiler=&query_info(0, $count - 1, "Please select from 0-" . ($count-1), "Compiler: "); if ($compiler == 0) { print "\n $tool_name: No compiler selected. No action taken.\n\n"; return; } $record = $optfile_records[$compiler - 1]; # Try to be helpful by "locating" a compiler of the type selected by the user. # This makes an ideal default setting. my $locate_fcn = $record->{"locate"}; my @locations = &$locate_fcn; my $chosen_location = ""; if ($locations[0] ne "" && -e $locations[0]) { print "\nYour machine has a ". $record->{"vendor_name"} . " compiler located at\n$locations[0]. "; print "Do you want to use this compiler [y]/n? "; chop($status=<STDIN>); if (!($status eq "n") && !($status eq "no")) { $chosen_location = $locations[0]; } } else { print "\nThe default location for " . $record->{"vendor_name"} . " compilers is " . $record->{"default_location"} . ",\nbut that directory does not exist on this machine. \n\n" . "Use " . $record->{"default_location"} ." anyway [y]/n? "; chop($status=<STDIN>); $status = lc(substr($status, 0, 1)); if ($status ne "n") { $chosen_location = $record->{"default_location"}; } } if ($chosen_location eq "") { print "Please enter the location of your compiler: " . "[" . $record->{"default_location"} . "] "; chop($chosen_location = <STDIN>); } if ($chosen_location eq "") { $chosen_location = $record->{"default_location"}; } $compiler_location = $chosen_location; $ask_no_questions = 0; } # Now that we have a compiler selected by the user and a # setup record for it, call install_options_file to copy the # template options file to the correct location. if (!&install_options_file($tool_name, $record, $opts_dir, $compiler_location, $ask_no_questions)) { # If the record for the installed compiler has a post_setup_hook # entry, call it (but only if install was successful). my $post_setup_fcn = $record->{"post_setup_hook"}; if ($post_setup_fcn) { &$post_setup_fcn(); } } # Restore old $| (buffered output) setting: $| = $old_pipe;}1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -