📄 mex.pl
字号:
# up the main body of code.
local($_) = $_[0];
DESCRIPTION: {
/^help$/ && print(<<'end_help_mb') && last DESCRIPTION;
MBUILD [option1 ... optionN] sourcefile1 [... sourcefileN]
[objectfile1 ... objectfileN] [libraryfile1 ... libraryfileN]
[exportfile1 ... exportfileN]
Description:
MBUILD compiles and links source files that call functions in the MATLAB
C/C++ Math Library or MATLAB C/C++ Graphics Library into a stand-alone
executable or shared library.
The first file name given (less any file name extension) will be the name
of the resulting executable. Additional source, object, or library files
can be given to satisfy external references. Either C or C++ source files
can be specified when building executables. In addition, both C and C++
source files can be specified at the same time as long as the C files are
C++ compatible, and the -lang cpp option is specified (see -lang below).
Both an options file and command line options affect the behavior of
MBUILD. The options file contains a list of variables that are passed as
arguments to various tools such as the compiler, linker, and other
platform-dependent tools (such as the resource linker on Windows). Command
line options to MBUILD may also affect what arguments are passed to these
tools, or may control other aspects of MBUILD's behavior.
Command Line Options:
Options available on all platforms:
-c
Compile only. Creates an object file but not an executable.
-D<name>
Define a symbol name to the C/C++ preprocessor. Equivalent to a
"#define <name>" directive in the source.
-D<name>#<value>
Define a symbol name and value to the C/C++ preprocessor. Equivalent
to a "#define <name> <value>" directive in the source.
-f <optionsfile>
Specify location and name of options file to use. Overrides MBUILD's
default options file search mechanism.
-g
Create a debuggable executable. If this option is specified, MBUILD
appends the value of options file variables ending in DEBUGFLAGS with
their corresponding base variable. (For example, the value of
LINKDEBUGFLAGS would be appended to the LINKFLAGS variable before
calling the linker.) This option also disables MBUILD's default
behavior of optimizing built object code.
-h[elp]
Print this message.
-I<pathname>
Add <pathname> to the list of directories to search for #include
files.
-inline
Inline matrix accessor functions (mx*). The executable generated may
not be compatible with future versions of the MATLAB C/C++ Math
Library or MATLAB C/C++ Graphics Library.
-lang <language>
Specify compiler language. <language> can be c or cpp. By
default, MBUILD determines which compiler (C or C++) to use by
inspection of the source file's extension. This option overrides that
mechanism.
-n
No execute mode. Print out any commands that MBUILD would otherwise
have executed, but do not actually execute any of them.
-O
Optimize the object code by including the optimization flags listed in
the options file. If this option is specified, MBUILD appends the
value of options file variables ending in OPTIMFLAGS with their
corresponding base variable. (For example, the value of LINKOPTIMFLAGS
would be appended to the LINKFLAGS variable before calling the
linker.) Note that optimizations are enabled by default, are disabled
by the -g option, but are reenabled by -O.
-outdir <dirname>
Place all output files in directory <dirname>.
-output <resultname>
Create executable named <resultname> (an appropriate executable
extension is automatically appended). Overrides MBUILD's default
executable naming mechanism.
-setup
Interactively specify the compiler options file to use as default for
future invocations of MBUILD by placing it in
"<UserProfile>\Application Data\MathWorks\MATLAB\R12" (for Windows) or
$HOME/.matlab/R12 (for UNIX). When this option is specified, no other
command line input is accepted.
-U<name>
Remove any initial definition of the C preprocessor symbol <name>.
(Inverse of the -D option.)
-v
Print the values for important internal variables after the options
file is processed and all command line arguments are considered.
Prints each compile step and final link step fully evaluated to see
which options and files were used. Very useful for debugging.
<name>#<value>
Override an options file variable for variable <name>. See the
platform-dependent discussion of options files below for more details.
This option is processed after the options file is processed and all
command line arguments are considered.
Additional options available on Windows platforms:
@<rspfile>
Include contents of the text file <rspfile> as command line arguments
to MBUILD.
Additional options available on Unix platforms:
-<arch>
Assume local host has architecture <arch>. Possible values for <arch>
include sol2, hpux, hp700, alpha, ibm_rs, sgi, and glnx86.
-D<name>=<value>
Define a symbol name and value to the C preprocessor. Equivalent to a
"#define <name> <value>" directive in the source.
-l<name>
Link with object library "lib<name>" (for "ld(1)").
-L<directory>
Add <directory> to the list of directories containing object-library
routines (for linking using "ld(1)").
<name>=<value>
Override an options file variable for variable <name>. See the
platform-dependent discussion of options files below for more details.
Shared Libraries and Exports Files:
MBUILD can also create shared libraries from C source code. If a file or
files with the extension ".exports" is passed to MBUILD, then it builds a
shared library. The .exports file must be a flat text file, with each line
containing either an exported symbol name, or starting with a # or * in
the first column (in which case it is treated as a comment line). If
multiple .exports files are specified, then all symbol names in all
specified .exports files are exported.
Options File Details:
On Windows:
The options file is written as a DOS batch file. If the -f option is not
used to specify the options file name and location, then MBUILD searches
for an options file named compopts.bat in the following directories: the
current directory, then the directory "<UserProfile>\Application
Data\MathWorks\MATLAB\R12". Any variable specified in the options file
can be overridden at the command line by use of the <name>#<value>
command line argument. If <value> has spaces in it, then it should be
wrapped in double quotes (e.g., COMPFLAGS#"opt1 opt2"). The definition
can rely on other variables defined in the options file; in this case
the variable referenced should have a prepended "$" (e.g.,
COMPFLAGS#"$COMPFLAGS opt2").
On UNIX:
The options file is written as a UNIX shell script. If the -f option is
not used to specify the options file name and location, then MBUILD
searches for an options file named mbuildopts.sh in the following
directories: the current directory (.), then $HOME/.matlab/R12, then
$MATLAB/bin. Any variable specified in the options file can be
overridden at the command line by use of the <name>=<def> command line
argument. If <def> has spaces in it, then it should be wrapped in single
quotes (e.g., CFLAGS='opt1 opt2'). The definition can rely on other
variables defined in the options file; in this case the variable
referenced should have a prepended "$" (e.g., CFLAGS='$CFLAGS opt2').
Examples:
The following command will compile "myprog.c" into "myprog.exe" (when
run under Windows):
mbuild myprog.c
When debugging, it is often useful to use "verbose" mode as well
as include symbolic debugging information:
mbuild -v -g myprog.c
The following command will compile "mylib.c" into "mylib.dll" (when run
under Windows). "mylib.dll" will export the symbols listed in
"mylib.exports":
mbuild mylib.c mylib.exports
end_help_mb
/^usage$/ && print(<<'end_usage_mb') && last DESCRIPTION;
Usage:
MBUILD [option1 ... optionN] sourcefile1 [... sourcefileN]
[objectfile1 ... objectfileN] [libraryfile1 ... libraryfileN]
[exportfile1 ... exportfileN]
Use the -help option for more information, or consult the MATLAB C/C++ Math
Library User's Guide.
end_usage_mb
/^general_info$/ && print(<<"end_general_info_mb") && last DESCRIPTION;
This is mbuild Copyright 1984-2001 The MathWorks, Inc.
end_general_info_mb
/^invalid_options_file$/ && print(<<"end_invalid_options_file_mb") && last DESCRIPTION;
Warning: An options file for MBUILD.BAT was found but the
value for 'COMPILER' was not set. This could mean that the
value is not specified within the options file, or it could
mean that there is a syntax error within the file.
end_invalid_options_file_mb
/^final_options$/ && print(<<"end_final_options_mb") && last DESCRIPTION;
$sourced_msg
----------------------------------------------------------------
-> Options file = $OPTFILE_NAME
-> COMPILER = $COMPILER
-> Compiler flags:
COMPFLAGS = $COMPFLAGS
OPTIMFLAGS = $OPTIMFLAGS
DEBUGFLAGS = $DEBUGFLAGS
arguments = $ARG_FLAGS
Name switch = $NAME_OBJECT
-> Pre-linking commands = $PRELINK_CMDS
-> LINKER = $LINKER
-> Link directives:
LINKFLAGS = $LINKFLAGS
LINKFLAGSPOST = $LINKFLAGSPOST
Name directive = $NAME_OUTPUT
File link directive = $LINK_FILE
Lib. link directive = $LINK_LIB
Rsp file indicator = $RSP_FILE_INDICATOR
----------------------------------------------------------------
end_final_options_mb
/^file_not_found$/ && print(<<"end_file_not_found_mb") && last DESCRIPTION;
$main::cmd_name: $filename not a normal file or does not exist.
end_file_not_found_mb
/^meaningless_output_flag$/ && print(<<"end_meaningless_output_flag_mb") && last DESCRIPTION;
Warning: -output ignored (no MBUILD application is being created).
end_meaningless_output_flag_mb
/^compiler_not_found$/ && print(<<"end_compiler_not_found_mb") && last DESCRIPTION;
Could not find the compiler "$COMPILER" on the DOS path.
Use mbuild -setup to configure your environment properly.
end_compiler_not_found_mb
/^outdir_missing_name_object$/ && print(<<"end_outdir_missing_name_object_mb") && last DESCRIPTION;
Warning: The -outdir switch requires the mbuild options file to define
NAME_OBJECT. Make sure you are using the latest version of
your compiler's mbuildopts file.
end_outdir_missing_name_object_mb
/^bad_lang_option$/ && print(<<"end_bad_lang_option_mb") && last DESCRIPTION;
Unrecognized language specified. Please use -lang cpp (for C++) or
-lang c (for C).
end_bad_lang_option_mb
/^bad_link_option$/ && print(<<"end_bad_link_option_mb") && last DESCRIPTION;
Unrecognized link target specified. Please use -link exe (for an executable)
or -link shared (for a shared/dynamically linked library).
end_bad_link_option_mb
do {
print "Internal error: Description for $_[0] not implemented\n";
last DESCRIPTION;
};
}
}
sub tool_name
{
if ($main::mbuild eq "yes")
{
"mbuild";
}
else
{
"mex";
}
}
sub find_options_file
{
# inputs:
my ($OPTFILE_NAME, $language, $no_setup) = @_;
# outputs:
# $OPTFILE_NAME
my ($source_dir, $sourced_msg);
# locals:
my ($REGISTERED_COMPILER, @JUNK);
if (-e ".\\$OPTFILE_NAME")
{
chop($source_dir = `cd`);
}
elsif (-e &get_user_profile_dir . "\\$OPTFILE_NAME")
{
$source_dir = &get_user_profile_dir;
}
elsif (-e "$main::script_directory\\$OPTFILE_NAME")
{
$source_dir = "$main::script_directory";
}
else
{
if (!$no_setup)
{
# No options file found, so try to detect the compiler
&setup(&tool_name, $main::script_directory, [uc($lang)], 1); # 1 == automode
}
if (-e &get_user_profile_dir . "\\$OPTFILE_NAME")
{
$source_dir = &get_user_profile_dir;
}
else
{
&expire("Error: No compiler options file could be found to compile source code. Please run \"" . &tool_name . " -setup\" to rectify.");
}
}
$OPTFILE_NAME = "$source_dir\\$OPTFILE_NAME";
$sourced_msg = "-> Default options filename found in $source_dir";
($OPTFILE_NAME, $source_dir, $sourced_msg);
} # find_options_file
#######################################################################
# Run a single command
#######################################################################
sub RunCmd {
my ($cmd) = @_;
my ($rc, $messages);
$cmd = "\"$cmd\"" if ( $] >= 5.00503 && $ENV{OS} eq 'Windows_NT' );
print "\n--> $cmd\n\n" if ($verbose || $main::no_execute);
if (! $main::no_execute)
{
$messages = `$cmd`;
$rc = $?;
print $messages if $verbose;
$rc = $rc >> 8 if $rc;
}
else
{
$messages = "";
$rc = 0;
}
wantarray ? ($messages, $rc) : $messages;
} # RunCmd
# Search DOS PATH environment variable for $binary_name. Return
# the directory containing the binary if found on the path, or an
# empty path otherwise.
sub search_path {
my ($binary_name) = @_;
my (@path, $path_entry, $found);
foreach ( split(/;/,$ENV{'PATH'}) ) {
print "checking existence of: $_\\$binary_name\n" if $ENV{MEX_DEBUG};
if ( -e "$_\\$binary_name" ) {
print "search_path found: $_\\$binary_name\n" if $ENV{MEX_DEBUG};
return $_;
}
}
'';
} # search_path
sub expire {
# Expire: Issue message and exit. This is like "die" except that
# it cleans up intermediate files before exiting.
# &expire("normally") exits normally (doesn't die).
# Clean up compiled files, unless we're only compiling
unlink @FILES_TO_REMOVE;
# clean up _lib? files in any case.
my $outdir = $ENV{'OUTDIR'};
if ($outdir eq "")
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -