#!/bin/sh # # Name: # # mcc script file for invoking MCC # # Usage: # # mcc [arguments] -help | [arguments] -? | # [-arch] [-v] # [-Y license_file] arguments ... # # Description: # # This Bourne Shell script invokes the MATLAB compiler. # # Options: # # -help - Help. It prints this help, then the mcc # backend help. The optional arguments # control the backend help. # # -? - Prints the mcc backend help only. The # optional arguments control the help. # # # -arch - Assume local host has architecture arch # # -v - Verbose mode. The mcc backend also # supports this argument, and it is passed # through to the mcc backend. # # -Y license_file - Override default license file with # license_file. license_file can be a colon # separated list of files or port@host entries. # The mcc backend also supports this argument. # # arguments ... - These are arguments to the mcc backend. # Use -help or -? for the syntax. # # Copyright 1998-2017 The MathWorks, Inc. #__________________________________________________________________________ # arg0_=$0 tmpbase=/tmp/mcc.$LOGNAME.$$ # trap "rm -f $tmpbase.[a-e]; rm_trash_shfile; exit 1" 1 2 3 15 # cache_body=$tmpbase.b # # For oscheck.sh # temp_file=$tmpbase.c # # Do not use ARCH if it exists in the environment # ARCH="" # # Use ~ iff HOME is undefined. # HOME=${HOME=~} # #========================= archlist.sh (start) ============================ # # usage: archlist.sh # # abstract: This Bourne Shell script creates the variable ARCH_LIST. # # note(s): 1. This file is always imbedded in another script # # Copyright 1997-2013 The MathWorks, Inc. #---------------------------------------------------------------------------- # ARCH_LIST='glnxa64 maci64' #======================================================================= # Functions: # check_archlist () #======================================================================= check_archlist () { # Sets ARCH. If first argument contains a valid # arch then ARCH is set to that value else # an empty string. If there is a second argument # do not output any warning message. The most # common forms of the first argument are: # # ARCH=arch # MATLAB_ARCH=arch # argument=-arch # # Always returns a 0 status. # # usage: check_archlist arch=[-]value [noprint] # if [ $# -gt 0 ]; then arch_in=`expr "$1" : '.*=\(.*\)'` if [ "$arch_in" != "" ]; then ARCH=`echo "$ARCH_LIST EOF $arch_in" | awk ' #----------------------------------------------------------------------- { for (i = 1; i <= NF; i = i + 1) if ($i == "EOF") narch = i - 1 for (i = 1; i <= narch; i = i + 1) if ($i == $NF || "-" $i == $NF) { print $i exit } }'` #----------------------------------------------------------------------- if [ "$ARCH" = "" -a $# -eq 1 ]; then #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ echo ' ' echo " Warning: $1 does not specify a valid architecture - ignored . . ." echo ' ' #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ fi else ARCH="" fi else ARCH="" fi # return 0 } #======================================================================= #========================= archlist.sh (end) ============================== # #======================================================================= # Functions: # scriptpath () # gethostname () # dirpath_arg0 () # get_arch () # set_mcc_env () # check_env () # check_matlab_bin () # check_mcc # set_os_env () # build_arglist () # # rm_trash_shfile () #======================================================================= scriptpath () { # Returns path of this script as a directory, # ROOTDIR, and command name, CMDNAME. # # Returns a 0 status unless an error. # # usage: scriptpath # # filename=$arg0_ # # Now it is either a file or a link to a file. # cpath=`pwd` # # Follow up to 8 links before giving up. Same as BSD 4.3 # n=1 maxlinks=8 while [ $n -le $maxlinks ] do # # Get directory correctly! # newdir=`echo "$filename" | awk ' { tail = $0 np = index (tail, "/") while ( np != 0 ) { tail = substr (tail, np + 1, length (tail) - np) if (tail == "" ) break np = index (tail, "/") } head = substr ($0, 1, length ($0) - length (tail)) if ( tail == "." || tail == "..") print $0 else print head }'` if [ ! "$newdir" ]; then newdir="." fi (cd $newdir) > /dev/null 2>&1 if [ $? -ne 0 ]; then #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ echo '' echo 'Internal error 1: We could not determine the path of' echo ' this command.' echo '' echo " original command path = $arg0_" echo " current command path = $filename" echo '' echo ' Please contact' echo '' echo ' MathWorks Technical Support' echo '' echo ' for further assistance.' echo '' #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ return 1 fi cd $newdir # # Need the function pwd - not the built in one # newdir=`/bin/pwd` # newbase=`expr //$filename : '.*/\(.*\)' \| $filename` lscmd=`ls -l $newbase 2>/dev/null` if [ ! "$lscmd" ]; then #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ echo '' echo 'Internal error 2: Could not determine the path of' echo ' this command.' echo '' echo " original command path = $filename" echo " current command path = $filename" echo '' echo ' Please contact' echo '' echo ' MathWorks Technical Support' echo '' echo ' for further assistance.' echo '' #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ return 1 fi # # Check for link portably # if [ `expr "$lscmd" : '.*->.*'` -ne 0 ]; then filename=`echo "$lscmd" | awk '{ print $NF }'` else # # It's a file # dir="$newdir" CMDNAME="$newbase" # cd $dir/.. MATLAB=`/bin/pwd`; export MATLAB break fi n=`expr $n + 1` done if [ $n -gt $maxlinks ]; then #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ echo '' echo 'Internal error 3: More than $maxlinks links in path to' echo " this script. That's too many!" echo '' echo " original command path = $filename" echo " current command path = $filename" echo '' echo ' Please contact' echo '' echo ' MathWorks Technical Support' echo '' echo ' for further assistance.' echo '' #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ return 1 fi cd "$cpath" return 0 } #======================================================================= gethostname () { # Returns the hostname as follows: # # 1. HOSTNAME # 2. hostname (on path) # 3. uname -a (2nd field) # # Always returns a 0 status. # # usage: getusername # if [ "$HOSTNAME" != "" ]; then echo $HOSTNAME return 0 fi name=`hostname 2>/dev/null` if [ "$name" = "" ]; then name=`uname -a` # # Take 2nd field # name=`expr "$uname" : '[^ ]*[ ]*\([^ ]*\)'` fi echo $name # return 0 } #======================================================================= dirpath_arg0 () { # Outputs the full directory name of $0 (arg0_) # # Always returns a 0 status. # # usage: dirpath_arg0 arg0 # if [ `expr "$1" : '/*'` -ne 0 ]; then dirname $1 else cd `dirname $1` /bin/pwd cd $cpath fi return 0 } #======================================================================= get_arch () { # Determine the value of ARCH. MATLAB is assumed # to be defined. # # Returns a 0 status unless it could not determine it. # # usage: get_arch # if [ "$ARCH" = "" ]; then . $MATLAB/bin/util/arch.sh export ARCH fi if [ "$ARCH" = "unknown" ]; then #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ echo ' ' echo 'Error: Invalid machine architecture . . .' echo ' ' #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ return 1 fi return 0 } #======================================================================= set_mcc_env () { # Execute the MATLAB script with the -e option # which returns all the environment variables and # their values without executing MATLAB. Use # these values to fill out the cache body template # to make the cache body and source it to set the # values in the environment. # # Returns a 0 status unless it failed for some # reason. # # usage: set_mcc_env # # # Determine ARCH # get_arch if [ $? -ne 0 ]; then return 1 fi export ARCH # # Call the MATLAB script to get the environment variables and their # values. # echo "n" > $tmpbase.e ($MATLAB/bin/matlab -$ARCH -e > $tmpbase.a status=$? if [ $status -ne 0 ]; then #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ echo ' ' echo 'Error: The MATLAB script returned a bad status while determining' echo ' environment variables. There appears to be a problem' echo ' with your MATLAB installation. You must fix the problem' echo ' before mcc can work. Any messages from the script' echo ' follow . . . ' echo ' ' #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ cat $tmpbase.a | awk ' #------------------------------------------------------------------------------ {if (index($0,"=") != 0) next; print }' #------------------------------------------------------------------------------ return $status fi) < $tmpbase.e || return $? # # Fill out the cache file template with the values # echo "EOF" >> $tmpbase.a cache_body_template >> $tmpbase.a # cat $tmpbase.a | awk ' #------------------------------------------------------------------------------ BEGIN {state = 0 squote = sprintf ("%c", 39) # set single quote } $1 == "EOF" {state = 1; next} state == 0 {i = index($0,"=") name = substr($0,1,i-1) value = substr($0,i+1) new[name] = value; next } state == 1 {i = match($0,"=\\$[A-Za-z_][A-Za-z0-9_]*") if (i == 0) { print; next } name = substr($0,i+2,RLENGTH-2); print substr($0,1,i) squote new[name] squote substr($0,i+RLENGTH) }' > $cache_body #------------------------------------------------------------------------------ . $cache_body > /dev/null 2>&1 # # Check the environment # check_env # rm -f $tmpbase.a rm -f $cache_body rm -f $tmpbase.e return $? } #======================================================================= check_env () { # Do a check on the environment. Check: # # 1. OS check # 2. MATLAB bin directory check # 3. mcc binary check # # Returns a 0 status unless a problem occurred. # # usage: check_env # # # Check OS version # if [ -f $MATLAB/bin/util/oscheck.sh ]; then . $MATLAB/bin/util/oscheck.sh if [ "$oscheck_status" = "1" ]; then return 1 fi fi # check_matlab_bin if [ $? -ne 0 ]; then return 1 fi # check_mcc if [ $? -ne 0 ]; then return 1 fi # return 0 } #======================================================================= check_matlab_bin () { # Check that MATLAB bin directory exists for # current architecture. # # Returns a 0 status unless it does not exist. # # usage: check_matlab_bin # if [ ! -d $MATLAB/bin/$ARCH ]; then #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ echo "-----------------------------------------------------------------" echo "Error: No MATLAB bin directory for this machine architecture." echo " ARCH = $ARCH" echo "-----------------------------------------------------------------" #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ return 1 fi return 0 } #======================================================================= check_mcc () { # Check that mcc binary exists. # # Returns a 0 status unless it does not exist. # # usage: check_mcc # if [ ! -f $MATLAB/bin/$ARCH/mcc ]; then #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ echo "-----------------------------------------------------------------" echo "Error: No MCC executable for this machine architecture." echo " $MATLAB/bin/$ARCH/mcc does not exist!" echo "-----------------------------------------------------------------" #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ return 1 fi return 0 } #======================================================================= set_os_env () { # Do any setting of OS environment parameters. # # Always returns a 0 status. # # usage: set_os_env return 0 } #======================================================================= cache_body_template () { # Output the cache body template to standard # output. # # Always returns a 0 status # # usage: cache_body_template # #----------------------------------------------------------------------- echo "#" echo 'DISPLAY=$DISPLAY; export DISPLAY' echo "#" echo 'ARCH=$ARCH; export ARCH' echo "#" echo 'MATLAB=$MATLAB; export MATLAB' echo "#" echo 'AUTOMOUNT_MAP=$AUTOMOUNT_MAP; export AUTOMOUNT_MAP' echo "#" # case "$ARCH" in maci64) if [ "$DYLD_FALLBACK_LIBRARY_PATH" != "" ]; then echo 'DYLD_FALLBACK_LIBRARY_PATH=$DYLD_FALLBACK_LIBRARY_PATH; export DYLD_FALLBACK_LIBRARY_PATH' fi echo 'DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH; export DYLD_LIBRARY_PATH' DYLD_FRAMEWORK_PATH="`eval echo $DYLD_FRAMEWORK_PATH`" LDPATH_MATLAB=$MATLAB/bin/$ARCH if [ "$DYLD_FRAMEWORK_PATH" != "" ]; then DYLD_FRAMEWORK_PATH=$LDPATH_MATLAB:$DYLD_FRAMEWORK_PATH else DYLD_FRAMEWORK_PATH=$LDPATH_MATLAB fi export DYLD_FRAMEWORK_PATH ;; *) echo 'LD_LIBRARY_PATH=$LD_LIBRARY_PATH; export LD_LIBRARY_PATH' ;; esac echo "#" echo 'MATLABPATH=$MATLABPATH; export MATLABPATH' echo "#" echo 'BASEMATLABPATH=$BASEMATLABPATH; export BASEMATLABPATH' echo "#" echo 'TOOLBOX=$TOOLBOX; export TOOLBOX' echo "#" echo 'XFILESEARCHPATH=$XFILESEARCHPATH; export XFILESEARCHPATH' echo "#________________________________________________________________" #----------------------------------------------------------------------- return 0 } #======================================================================= build_arglist () { # The variable arglist is the input which has # arguments separated by newlines. It outputs # a single string correctly quoted to be evaluated. # # Always returns a 0 status # # usage: build_arglist # echo "$arglist" | awk ' #---------------------------------------------------------------------------- BEGIN { squote = sprintf ("%c", 39) # set single quote dquote = sprintf ("%c", 34) # set double quote } NF != 0 { newarg=squote # initialize output string to # single quote lookquote=squote # look for single quote oldarg = $0 while ((i = index (oldarg, lookquote))) { newarg = newarg substr (oldarg, 1, i - 1) lookquote oldarg = substr (oldarg, i, length (oldarg) - i + 1) if (lookquote == squote) lookquote = dquote else lookquote = squote newarg = newarg lookquote } printf " %s", newarg oldarg lookquote }' #---------------------------------------------------------------------------- return 0 } #======================================================================= rm_trash_shfile () { # On many platforms there is a shell bug which # leaves around a /tmp/sh$$* file for a here # document. We will attempt to remove the file # on any platform without checking for the ARCH. # # We have observed the following: # # hpux: # /tmp/sh$$.1 # # Always returns a 0 status. # # usage: rm_trash_shfile # rm -f /tmp/sh$$0 /tmp/sh$$.* > /dev/null 2>&1 return 0 } #======================================================================= set_mcc_cmd () { mcc_cmd="$MATLAB/bin/$ARCH/mcc" } #======================================================================= # #************************************************************************** # RCSHEADER=' ' REVISION=`expr "$RCSHEADER" : '[^ ]* \([^ ]*\)'` # # Parse the arguments # stat="OK" help=0 backend_help=0 verbose=0 bin_echo=/bin/echo if [ "`echo '\n' | awk 'NF == 1 { print 1 }'`" = "1" ]; then use_bin_echo=1 fi if [ "$use_bin_echo" = "1" ]; then # # -e is a required option on Redhat Linux only. Otherwise no option. # echo_option=`$bin_echo -e | awk 'NF == 0 { print "-e"}'` if [ "`$bin_echo $echo_option '\n' | awk 'NF == 1 { print 1 }'`" = "1" ]; then bin_echo=printf fi arglist=`$bin_echo $echo_option '\n'` else arglist='\n' fi narg=$# # # No arguments is equivalent to help # if [ "$narg" = "0" ]; then help=1 stat="" fi while [ "$stat" = "OK" -a $# -gt 0 ]; do case "$1" in -cache) echo "***warning*** cacheing is no longer supported, cache will not be printed" if [ "$narg" = "1" ]; then exit 0 fi ;; -rmcache) echo "***warning*** caching is no longer supported, rmcache ignored" exit 0 ;; -nocache) echo "***warning*** caching is no longer supported, nocache now always active" ;; -help) help=1 stat="" ;; -\?) backend_help=1 stat="" ;; #========================= ARCH_LIST (start) ============================== -glnxa64) ARCH=glnxa64 ;; -maci64) ARCH=maci64 ;; #========================= ARCH_LIST (end) ================================ -D*) debugger=`expr "$1" : '-D\(.*\)'` if [ "$debugger" = "" ]; then if [ "$use_bin_echo" = "1" ]; then arglist=`$bin_echo $echo_option "${arglist}\n$1"` else arglist="${arglist}\n$1" fi else MATLAB_DEBUG=`expr "//$debugger" : ".*/\(.*\)"` fi ;; -*v*) verbose=1 if [ "$use_bin_echo" = "1" ]; then arglist=`$bin_echo $echo_option "${arglist}\n$1"` else arglist="${arglist}\n$1" fi ;; *) if [ "$use_bin_echo" = "1" ]; then arglist=`$bin_echo $echo_option "${arglist}\n$1"` else arglist="${arglist}\n$1" fi ;; esac shift done if [ "$stat" = "" ]; then scriptpath if [ $? -ne 0 ]; then exit 1 fi cat /dev/null > $tmpbase.d if [ "$msg" != "" ]; then ( #----------------------------------------------------------------------- echo " " echo " Error: $msg" echo " " echo "-----------------------------------------------------------------" #----------------------------------------------------------------------- ) >> $tmpbase.d fi if [ "$backend_help" = "0" ]; then ( #----------------------------------------------------------------------- echo "-----------------------------------------------------------------" echo "help for mcc frontend . . ." echo "-----------------------------------------------------------------" echo " " echo " Usage: mcc [arguments] -help | [arguments] -? |" echo " [-arch]" echo " [-v] [-Y license_file] arguments ..." echo " " echo " -help - Help. Print this help, then the" echo " mcc backend help. The optional" echo " arguments control the backend help." echo " " echo " -? - Print the mcc backend help only. The" echo " optional arguments control the help." echo " " echo " -arch - Assume local host has architecture arch." echo " Rebuilds the cache file unless -nocache" echo " is used." echo " " echo " -v - Verbose mode. This argument is" echo " passed through to the mcc backend." echo " " echo " -Y license_file - Override default license file with" echo " license_file. license_file can be a" echo " colon separated list of files or" echo " port@host entries. The mcc backend" echo " also supports this argument." echo " " echo " arguments ... - Arguments to the mcc backend." echo " " echo " " echo " The Bourne Shell frontend to the MATLAB Compiler." echo " The" echo " arguments ... are passed to the backend." echo " " #----------------------------------------------------------------------- ) >> $tmpbase.d fi # # Output the options for the backend # if [ "$help" = "1" -o "$backend_help" = "1" ]; then set_mcc_env if [ $? -ne 0 ]; then rm -f $cache_body exit 1 fi # # Parse any remaining arguments # while [ $# -gt 0 ]; do case "$1" in -help|-\?) : ;; #========================= ARCH_LIST (start) ============================== -glnxa64) : ;; -maci64) : ;; #========================= ARCH_LIST (end) ================================ *) if [ "$use_bin_echo" = "1" ]; then arglist=`$bin_echo $echo_option "${arglist}\n$1"` else arglist="${arglist}\n$1" fi ;; esac shift done if [ "$backend_help" = "0" ]; then ( #----------------------------------------------------------------------- echo "-----------------------------------------------------------------" echo "help for mcc backend . . ." echo "-----------------------------------------------------------------" #----------------------------------------------------------------------- ) >> $tmpbase.d fi # ( #----------------------------------------------------------------------- set_mcc_cmd eval $mcc_cmd `build_arglist` -? echo "-----------------------------------------------------------------" #----------------------------------------------------------------------- ) >> $tmpbase.d more $tmpbase.d rm -f $tmpbase.d else #----------------------------------------------------------------------- echo "-----------------------------------------------------------------" >> $tmpbase.d #----------------------------------------------------------------------- more $tmpbase.d rm -f $tmpbase.d fi exit 1 fi scriptpath if [ $? -ne 0 ]; then exit 1 fi set_mcc_env if [ $? -ne 0 ]; then exit 1 fi set_os_env # # Guarantee that mbuild is available, though it should # be, since mbuild is in the same directory as mcc. # PATH=$MATLAB/bin:$PATH; export PATH # # Work around shell bug on alpha with "here" documents. # rm_trash_shfile # set_mcc_cmd if [ "$debugger" != "" ]; then if [ "$MATLAB_DEBUG" = "gdb" -o "$MATLAB_DEBUG" = "xxgdb" ]; then SHELL=/bin/sh; export SHELL fi eval exec $debugger $mcc_cmd `build_arglist` else eval exec $mcc_cmd `build_arglist` fi