⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mex.pl

📁 此程序是本人编写的在MFC环境下调用Matlab函数进行编程的实例
💻 PL
📖 第 1 页 / 共 5 页
字号:
      };
      /^-mb$/ && do {
          $main::mbuild = "yes";
	  $OPTFILE_NAME = "compopts.bat";
	  $main::script_directory =~ s/mexopts/mbuildopts/g;
	  $main::cmd_name = "MBUILD.BAT";
          last ARGTYPE;
      };
      /^-n$/ && do {
          $main::no_execute = 1; # global used by RunCmd
          last ARGTYPE;
      };
      /^-nohg$/ && do {
          # This is an undocumented feature which is subject to change
          $nohg = 1;
          last ARGTYPE;
      };
      /^-no_mmfile$/ && do {
          # This is an undocumented feature which is subject to change
          $no_mmfile = 1;
          last ARGTYPE;
      };
      /^-no_mwsglm$/ && do {
          # This is an undocumented feature which is subject to change
          $no_mwsglm = 1;
          last ARGTYPE;
      };
      /^-no_setup$/ && do {
          # This is an undocumented feature which is subject to change
          $no_setup = 1;
          last ARGTYPE;
      };
      /^[A-Za-z0-9_]+\#.*$/ && do {
          push(@CMD_LINE_OVERRIDES, $_);
          last ARGTYPE;
      };
      /^-ada$/ && ($main::mbuild eq "no") && do {
          if ($ada_sfunction ne "" || $#ARGV == -1) {
              &expire("Error: Invalid use of -ada option");
          }
          $ada_sfunction = shift(@ARGV);
          if ( !(-e $ada_sfunction) ) {
              &expire("Error: File '$ada_sfunction' not found");
          }
          $lang_override = "ada";
          last ARGTYPE;
      };
      /^-aI.*$/ && ($main::mbuild eq "no") && do {
          $ada_include_dirs .= " " . $_;
          last ARGTYPE;
      };
      /^-entrypt$/ && ($mbuild eq "no") && do {
          $ENV{'ENTRYPOINT'} = shift(@ARGV);
          if ($ENV{'ENTRYPOINT'} ne "mexFunction" &&
              $ENV{'ENTRYPOINT'} ne "mexLibrary")
          {
              &expire("Error: -entrypt argument must be either 'mexFunction'\n  or 'mexLibrary'");
          }
          last ARGTYPE;
      };
      /^-.*$/ && do {
	  if ($main::mbuild eq "no") {
	      &describe("usage");
	  } else {
	      &describe_mb("usage");
	  }
          &expire("Error: Unrecognized switch: $_.");
          last ARGTYPE;
      };
      /^@(.*)$/ && do {
          @NEW_ARGS = &process_response_file($1);

          # Expand possible wildcards in the arguments for perl >= 5.00503
          if ($] >= 5.00503) {
              my (@a) = map { /\*/ ? glob($_) : $_ } @NEW_ARGS;
              @NEW_ARGS = @a;
          }

          unshift(@ARGV, @NEW_ARGS);
          last ARGTYPE;
      };
      /^.*\.exports$/ && ($main::mbuild eq "yes") && do {
          push(@EXPORT_FILES, $_);
          last ARGTYPE;
      };
      do {
          # Remove quotes put there by mex.m
          tr/"//d;

          if (/(.*)\.dll$/)
          {
              &expire("Error: " . &tool_name() . " cannot link to '$_' directly.\n" .
                      "  Instead, you must link to the file '$1.lib' which corresponds " .
                      "to '$_'.");
          }

          if (!/\.lib$/ && !-e $_) {
	      &expire("Error: '$_' not found.");
          }
          # Put file in list of files to compile
	  push(@FILES, $_);

	  # Try to determine compiler (C or C++) to use from file extension.
          if (/\.(cpp|cxx|cc)$/i)
          {
              $lang = "cpp";
          }
          if (/\.c$/i)
          {
              $lang = "c";
          }
          if (/\.(f|for|f90)$/i)
          {
              $lang = "fortran";
          }

          last ARGTYPE;
      };
  };
}

if ($lang_override) { $lang = $lang_override; }

#
# Fix for Windows NT/2000 systemroot bug
#
$ENV{'PATH'} =~ s/\%systemroot\%/$ENV{'systemroot'}/ig;

if ($lang eq "fortran" && $ENV{'ENTRYPOINT'} ne "mexFunction")
{
    &describe("fortran_cannot_change_entrypt");
    $ENV{'ENTRYPOINT'} = "mexFunction";
}

################################################################################
# Ada S-Functions
#
if ($lang eq "ada")
{
    build_ada_s_function($ada_sfunction, $ada_include_dirs);
    # we expire from the above function
}
################################################################################


if ($link eq "unspecified" && $main::mbuild eq "yes")
{
    if (@EXPORT_FILES > 0)
    {
        $link = "shared";
    }
    else
    {
        $link = "exe";
    }
}

# it doesn't mean anything to redirect the output if we aren't creating a MEX-file
if ($compile_only && $output_flag){
    if ($main::mbuild eq "no") {
	&describe("meaningless_output_flag");
    } else {
	&describe_mb("meaningless_output_flag");
    }
}
#&describe("meaningless_output_flag") if ($compile_only && $output_flag);

# check to see if we're only setting up the compiler locations
if ($setup)
{
    &setup(&tool_name, $main::script_directory, ['ANY'], 0); # 0 == no automode
    exit(0);
}

# get mex-file name and source file type from 1st file argument
($derived_name, $EXTENSION) = ($FILES[0] =~ /([ \w]*)\.(\w*)$/);
$ENV{'MEX_NAME'} = $derived_name if (!($ENV{'MEX_NAME'}));
my $fortran = "yes"
    if ($EXTENSION =~ /^(f|for|f90)$/i);

# Set up the DLL_NAME environment variable, so it can be filled in
# later when it is known.

$ENV{'DLL_NAME'}  = "none";

$RC_LINKER = " ";
$RC_COMPILER = " ";

#
# Create a unique name for the created import library
#
$ENV{'LIB_NAME'} = &smart_quote("$ENV{'OUTDIR'}\_lib$$");

#
# Create the name of the master exports file which mex will generate.
# This is an "input" to the options file so it needs to be set before we
# process the options file.
#
if ($makefilename)
{
    # _nq => not quoted
    $base_exports_file_nq     = "$ENV{'OUTDIR'}$ENV{'MEX_NAME'}_master.exports";
    $ENV{'BASE_EXPORTS_FILE'} = &smart_quote($base_exports_file_nq);
    $ENV{'DEF_FILE'}          = &smart_quote("$ENV{'OUTDIR'}$ENV{'MEX_NAME'}_master.def");
}
else
{
    $base_exports_file_nq     = "$ENV{'OUTDIR'}$$\_tmp.exports";
    $ENV{'BASE_EXPORTS_FILE'} = &smart_quote($base_exports_file_nq);
    $ENV{'DEF_FILE'}          = "$ENV{'LIB_NAME'}.def";
}
$BASE_EXPORTS_FILE = $ENV{'BASE_EXPORTS_FILE'};
$DEF_FILE          = $ENV{'DEF_FILE'};

#######################################################################
# Source options file
#######################################################################

# If VISUAL_STUDIO is set and MSVCDir is not, set MSVCDir based on
# VISUAL_STUDIO.  If DevStudio is set and MSVCDir is not, set MSVCDir
#  based on DevStudio.
#
# NOTE:  VISUAL_STUDIO and DevStudio are MathWorks specific environment
#        variables and are not set by Microsoft's compiler(s).
#
if ($ENV{'VISUAL_STUDIO'} ne "" && $ENV{'MSVCDir'} eq "" &&
    ! grep /msvc50/, $OPTFILE_NAME) {
    print("Setting MSVCDir for use with MSVC 6.0 (MathWorks-only diagnostic - do not geck)\n");
    $ENV{'MSVCDir'} = $ENV{'VISUAL_STUDIO'} . "\\VC98";
} elsif ($ENV{'DevStudio'} ne "" && $ENV{'MSVCDir'} eq "") {
    print("Setting MSVCDir for use with MSVC 5.0(MathWorks-only diagnostic - do not geck)\n");
    $ENV{'MSVCDir'} = $ENV{'DevStudio'} . "\\VC";
}

# If we don't already know what to use as the options file, search
# default locations.
if ($sourced_msg eq 'none')
{
    ($OPTFILE_NAME, $source_dir, $sourced_msg) = &find_options_file($OPTFILE_NAME, $lang, $no_setup);
}

# The DOS batch language is too limited for our purposes.
# Instead, we will parse the batch files on our own.
open (OPTIONSFILE, $OPTFILE_NAME) || &expire("Error: Can't open file '$OPTFILE_NAME': $!");
while ($_ = <OPTIONSFILE>) {
    chomp;
    next if (!(/^\s*set /));      # Ignore everything but set commands
    s/^\s*set //;                 # Remove "set " command itself
    s/\s+$//;                     # Remove trailing whitespace
    s/\\$//g;                     # Remove trailing \'s
    s/\\/\\\\/g;                  # Escape all other \'s with another \
    s/%(\w+)%/'.\$ENV{'$1'}.'/g;  # Replace %VAR% with $ENV{'VAR'}
    s/%%/%/g;                     # Replace %%s with %s
    my $perlvar = '$' . $_ . "\';";
    $perlvar =~ s/=/='/;
    my $dosvar = '$ENV{'."'".$_."';";
    $dosvar =~ s/=/'}='/;
    eval($perlvar);
    eval($dosvar);

    # We need a special case for the WATCOM compiler because it can't handle
    # directories with spaces or quotes in their names. So only put the quotes
    # around the MATLAB directory name if it has spaces in it.
    $ML_DIR = &smart_quote($MATLAB);

    # Set the special MATLAB_BIN environment variable
    if ( (! $ENV{'MATLAB'} eq "") && $ENV{'MATLAB_BIN'} eq "" )
    {
	$ENV{'MATLAB_BIN'} = "$ML_DIR\\bin\\win32";
    }

    # Set the special MATLAB_EXTLIB environment variable
    if ( (! $ENV{'MATLAB'} eq "") && $ENV{'MATLAB_EXT'} eq "" )
    {
	$ENV{'MATLAB_EXTLIB'} = "$ML_DIR\\extern\\lib\\win32";
    }
}

# Determine whether or not we should do Graphics-library specific tasks
if ($main::mbuild eq "yes" && !$nohg 
    && -e "$main::script_directory\\..\\sgl.dll") {
    $usehg = 1;
} else {
    $usehg = 0;
}

# Based on the language we're using, possibly adjust the flags
if ($lang eq "cpp" && $CPPCOMPFLAGS ne "")
{
    $COMPFLAGS = $CPPCOMPFLAGS;
    $LINKFLAGS = $CPPLINKFLAGS;
    if ($usehg) {
        $LINKFLAGS = $HGCPPLINKFLAGS;
    }
    $DEBUGFLAGS = $CPPDEBUGFLAGS;
    $OPTIMFLAGS = $CPPOPTIMFLAGS;
}
elsif ($link eq "shared")
{
    if ($DLLCOMPFLAGS eq "")
    {
        &expire("Error: The current options file is not configured to create DLLs. "
                . "You can use\n" . &tool_name() . " -setup to set up an options file "
                . "which is configured to create DLLs.");
    }

    $COMPFLAGS = $DLLCOMPFLAGS;
    $LINKFLAGS = $DLLLINKFLAGS;
    $LINKFLAGSPOST = $DLLLINKFLAGSPOST;
    if ($usehg) {
        $LINKFLAGS = $HGDLLLINKFLAGS;
        $LINKFLAGSPOST = $HGDLLLINKFLAGSPOST;
    }
    $NAME_OUTPUT = $DLL_NAME_OUTPUT;

    # copy all exported symbols into one master export file
    open(EXPORT_FILE, ">$base_exports_file_nq") ||
	&expire("Could not open file '$base_exports_file_nq': $!");
    push(@FILES_TO_REMOVE, "$base_exports_file_nq") if (!$makefilename);
    foreach my $an_export_file (@EXPORT_FILES)
    {
        open(AN_EXPORT_FILE, "$an_export_file") ||
            &expire("Could not open file '$an_export_file': $!");
        while (<AN_EXPORT_FILE>)
        {
            # Strip out lines that only contain whitespace and
            # lines that start with '#' or '*' (comments)
            if (/\S/ && !/^[\#*]/)
            {
                print EXPORT_FILE $_;
            }
        }
        close(AN_EXPORT_FILE);
    }
    close(EXPORT_FILE);
} else {
    if ($usehg) {
        $LINKFLAGS = $HGLINKFLAGS;
        $LINKFLAGSPOST = $HGLINKFLAGSPOST;
    }
}

if ($no_mmfile)
{
    $LINKFLAGS =~ s/$ENV{'LINK_LIB'} *libmmfile.lib//g;
    $LINKFLAGSPOST =~ s/$ENV{'LINK_LIB'} *libmmfile.lib//g;
}
if ($no_mwsglm)
{
    $LINKFLAGS =~ s/$ENV{'LINK_LIB'} *libmwsglm.lib//g;
    $LINKFLAGSPOST  =~ s/$ENV{'LINK_LIB'} *libmwsglm.lib//g;
}


# Process command line overrides
foreach $override (@CMD_LINE_OVERRIDES)
{
    $override =~ /^([A-Za-z0-9_]+)[\#](.*)$/;
    $lhs = $1;
    $rhs = $2;

    $rhs =~ s/\\/\\\\/g;              # Escape all other \'s with another \
    $rhs =~ s/"/\\"/g;
    $rhs =~ s/\$([A-Za-z0-9_]+)/\$ENV{'$1'}/g;  # Replace $VAR with $ENV{'VAR'}

    my $perlvar = '$' . $lhs . " = \"" . $rhs . "\";";
    my $dosvar = "\$ENV{\'" . $lhs . "\'} = \"" . $rhs . "\";";

    eval($perlvar);
    eval($dosvar);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -