3
# mex compilation program for MATLAB C and Fortran language MEX-files
5
# Copyright 1984-2006 The MathWorks, Inc.
6
# $Revision: 1.108.4.19 $ $Date: 2006/06/23 19:04:11 $
7
#____________________________________________________________________________
11
abort='rm -rf $files_to_remove $basename.o > /dev/null 2>&1; \
13
echo " mex: interrupted."; \
16
trap "eval $abort; exit 1" 1 2 3 15
18
#========================= archlist.sh (start) ============================
22
# abstract: This Bourne Shell script creates the variable ARCH_LIST.
24
# note(s): 1. This file is always imbedded in another script
26
# Copyright 1997-2005 The MathWorks, Inc.
27
# $Revision: 1.9.4.5 $ $Date: 2005/10/07 14:01:06 $
28
#----------------------------------------------------------------------------
30
ARCH_LIST='sol2 glnx86 glnxa64 mac maci'
31
#=======================================================================
34
#=======================================================================
35
check_archlist () { # Sets ARCH. If first argument contains a valid
36
# arch then ARCH is set to that value else
37
# an empty string. If there is a second argument
38
# do not output any warning message. The most
39
# common forms of the first argument are:
45
# Always returns a 0 status.
47
# usage: check_archlist arch=[-]value [noprint]
50
arch_in=`expr "$1" : '.*=\(.*\)'`
51
if [ "$arch_in" != "" ]; then
52
ARCH=`echo "$ARCH_LIST EOF $arch_in" | awk '
53
#-----------------------------------------------------------------------
54
{ for (i = 1; i <= NF; i = i + 1)
57
for (i = 1; i <= narch; i = i + 1)
58
if ($i == $NF || "-" $i == $NF) {
63
#-----------------------------------------------------------------------
64
if [ "$ARCH" = "" -a $# -eq 1 ]; then
65
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
67
echo " Warning: $1 does not specify a valid architecture - ignored . . ."
69
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
80
#=======================================================================
81
#========================= archlist.sh (end) ==============================
83
#========================== version.sh (start) ============================
85
# usage: version [-b | -f | -p]
87
# abstract: This POSIX Shell script function returns the MATLAB
88
# release version. Any bad options are ignored without
91
# The version is assumed to be of the form:
93
# R<integer>[<noninteger>]
97
# b - return just R<integer> or the base version.
98
# f - return full version, e.g. R14SP5
99
# p - return previous full version, e.g. R14SP4
101
# note(s): 1. This file is always imbedded in another script
103
# Copyright 1992-2005 The MathWorks, Inc.
104
# $Revision: 1.1.6.4 $ $Date: 2005/12/01 02:16:52 $
105
#----------------------------------------------------------------------------
108
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
112
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
113
if [ $# -eq 1 ]; then
114
if [ "$1" = '-b' ]; then
115
expr "$ver" : '\(R[0-9]*\).*$'
118
if [ "$1" = '-f' ]; then
122
if [ "$1" = '-p' ]; then
130
#========================== version.sh (end) ==============================
131
REL_VERSION=`version -f`
133
#============================================================================
134
# FUNCTION DEFINITIONS
135
#============================================================================
137
#****************************************************************************
139
# NOTE: A call to cleanup MUST precede any call to exit within this script,
140
# except for within trap calls.
143
# Clean up temporary and intermediate files (usually in preparation
146
trap "eval $abort; exit 1" 1 2 3 15
147
rm -rf $files_to_remove > /dev/null 2>&1
151
#****************************************************************************
154
helpTextFileName="$MATLAB/bin/util/mex/mexHelp.txt"
155
cat $helpTextFileName
159
#****************************************************************************
166
echo 'Internal error 1: We could not determine the path of the'
167
echo ' MATLAB root directory.'
169
echo " original command path = $arg0_"
170
echo " current command path = $filename"
172
echo ' Please contact:'
174
echo ' MathWorks Technical Support'
176
echo ' for further assistance.'
181
echo 'Internal error 2: Could not determine the path of the'
182
echo ' MATLAB root directory.'
184
echo " original command path = $filename"
185
echo " current command path = $filename"
187
echo ' Please contact:'
189
echo ' MathWorks Technical Support'
191
echo ' for further assistance.'
196
echo 'Internal error 3: More than $maxlinks links in path to'
197
echo " this script. That's too many!"
199
echo " original command path = $filename"
200
echo " current command path = $filename"
202
echo ' Please contact:'
204
echo ' MathWorks Technical Support'
206
echo ' for further assistance.'
209
unknown_architecture)
211
echo ' Sorry! We could not determine the machine architecture'
212
echo ' for your host. Please contact:'
214
echo ' MathWorks Technical Support'
216
echo ' for further assistance.'
221
echo ' Sorry! We could not determine the machine architecture'
222
echo ' for your host, because one of the utilities'
224
echo ' $MATLAB/bin/util/arch.sh'
228
echo ' $MATLAB/bin/util/oscheck.sh'
230
echo ' could not be found. Please make sure that your'
231
echo ' installation is not corrupted. If you specified'
232
echo ' the value of $MATLAB in the command line, please'
233
echo ' make sure you specified the right value.'
237
echo " MATLAB = $MATLAB"
239
echo ' Please contact:'
241
echo ' MathWorks Technical Support'
243
echo ' if you need assistance.'
248
echo " mex: machine architecture '$Arch' not supported."
251
invalid_options_file)
253
echo ' Error: An invalid options file name was specified:'
254
echo " $2 is not a normal file or does not exist."
259
echo ' Sorry! No options file was found for mex.'
260
echo ' The mex script must be able to source'
261
echo ' an options file to define compiler flags'
262
echo ' and other settings. This options file'
263
echo " is normally found in MATLAB/bin/$OPTSFILE_NAME."
264
echo ' Please check to make sure that your installation'
265
echo ' is complete and includes this file.'
269
echo " MATLAB = $MATLAB"
271
echo ' Please contact:'
273
echo ' MathWorks Technical Support'
275
echo ' for further assistance.'
279
if [ "$SOURCE_DIR" = "none" ]; then
280
echo '----------------------------------------------------------------'
281
echo "-> options file specified on command line:"
282
echo " FILE = $OPTIONS_FILE"
283
elif [ "$SOURCE_DIR" != "" ]; then
284
echo "-> $OPTSFILE_NAME sourced from directory (DIR = $SOURCE_DIR)"
285
echo " FILE = $SOURCE_DIReval/$OPTSFILE_NAME"
287
echo "-> options file not found ($OPTSFILE_NAME looked for)."
289
echo '----------------------------------------------------------------'
290
echo "-> MATLAB = $MATLAB"
293
echo " CFLAGS = $CFLAGS"
294
echo " CDEBUGFLAGS = $CDEBUGFLAGS"
295
echo " COPTIMFLAGS = $COPTIMFLAGS"
296
echo " CLIBS = $CLIBS"
297
echo " arguments = $cc_flags"
300
echo " CXXFLAGS = $CXXFLAGS"
301
echo " CXXDEBUGFLAGS = $CXXDEBUGFLAGS"
302
echo " CXXOPTIMFLAGS = $CXXOPTIMFLAGS"
303
echo " CXXLIBS = $CXXLIBS"
304
echo " arguments = $cxx_flags"
307
echo " FFLAGS = $FFLAGS"
308
echo " FDEBUGFLAGS = $FDEBUGFLAGS"
309
echo " FOPTIMFLAGS = $FOPTIMFLAGS"
310
echo " FLIBS = $FLIBS"
311
echo " arguments = $fc_flags"
313
echo "-> Link flags:"
314
echo " LDFLAGS = $LDFLAGS"
315
echo " LDDEBUGFLAGS = $LDDEBUGFLAGS"
316
echo " LDOPTIMFLAGS = $LDOPTIMFLAGS"
317
echo " LDEXTENSION = $LDEXTENSION"
318
echo " arguments = $libs"
319
echo "-> LDCXX = $LDCXX"
320
echo "-> Link flags:"
321
echo " LDCXXFLAGS = $LDCXXFLAGS"
322
echo " LDCXXDEBUGFLAGS = $LDCXXDEBUGFLAGS"
323
echo " LDCXXOPTIMFLAGS = $LDCXXOPTIMFLAGS"
324
echo " LDCXXEXTENSION = $LDCXXEXTENSION"
325
echo " arguments = $libs"
326
echo '----------------------------------------------------------------'
331
echo ' Warning: No source files in argument list.'
333
echo ' Assuming C source code. To override this assumption, use'
339
meaningless_output_flag)
341
echo ' Warning: -output ignored (no MEX-file is being created).'
345
echo ' Assuming MATLAB 7.0 32-bit compatibility mode.'
346
echo ' To override this assumption, use -largeArrayDims.'
357
MEX [option1 ... optionN] sourcefile1 [... sourcefileN]
358
[objectfile1 ... objectfileN] [libraryfile1 ... libraryfileN]
360
or (to build an Ada S-function):
361
MEX [-v] [-g] -ada <sfcn>.ads
363
Use the -help option for more information, or consult the MATLAB External Interfaces Guide.
369
echo " mex: $file not a normal file or does not exist."
373
echo "-> $compile_command"
378
echo " mex: compile of '$file' failed."
382
echo "-> $LD $LDFLAGS -o $mex_file $libetc"
387
echo " mex: link of '$mex_file' failed."
391
echo "-> $POSTLINK_CMDS"
396
echo ' Error: An invalid Ada S-function file name was specified:'
397
echo " $2 is not a normal file or does not exist."
402
echo ' Error: Need GNU make properly installed and available on path '
403
echo " to build Ada S-function '$ada_sfcn'"
408
echo " mex: Failed to build Ada S-Function '$ada_sfcn'"
411
fortran_cannot_change_entrypt)
413
echo ' Warning: -entrypt ignored (FORTRAN entry point cannot be overridden).'
416
cannot_create_outdir)
418
echo " Error: Could not create OUTDIR = $OUTDIR"
423
echo " Error: Could not create TEMP = $TEMP"
428
echo " Internal error 4: unimplemented message $1"
435
#****************************************************************************
439
# Return a quoted version of the input string if it has spaces in it.
441
if [ $# -gt 1 ]; then
449
#****************************************************************************
453
# Determine the path of the MATLAB root directory - always one directory
454
# up from the path to this command.
458
# Now it is either a file or a link to a file.
462
# Follow up to 8 links before giving up. Same as BSD 4.3
466
while [ $n -le $maxlinks ]
469
# Get directory correctly!
471
newdir=`echo "$filename" | awk '
473
np = index (tail, "/")
475
tail = substr (tail, np + 1, length (tail) - np)
476
if (tail == "" ) break
477
np = index (tail, "/")
479
head = substr ($0, 1, length ($0) - length (tail))
480
if ( tail == "." || tail == "..")
485
if [ ! "$newdir" ]; then
488
(cd $newdir) > /dev/null 2>&1
489
if [ $? -ne 0 ]; then
490
describe internal_error_1 >&2
496
# Need the function pwd - not the built in one
500
newbase=`expr //$filename : '.*/\(.*\)' \| $filename`
501
lscmd=`ls -l $newbase 2>/dev/null`
502
if [ ! "$lscmd" ]; then
503
describe internal_error_2 >&2
508
# Check for link portably
510
if [ `expr "$lscmd" : '.*->.*'` -ne 0 ]; then
511
filename=`echo "$lscmd" | awk '{ print $NF }'`
520
MATLAB=`/bin/pwd`; export MATLAB
525
if [ $n -gt $maxlinks ]; then
526
describe internal_error_3 >&2
533
# end get_root_dir ()
535
#****************************************************************************
539
# Set up the entry point based on the input argument
541
if [ "$1" = "FORTRAN" ]; then
543
# The gateway routine is in Fortran; use Fortran entry point
545
MAPFILE='fexport.map'
548
# C, C++ and Ada entry points are the same
550
MAPFILE=$entrypt'.map'
556
#****************************************************************************
558
determine_options_file () {
559
# Source options file (default is $OPTSFILE_NAME) and get values for the
560
# following local variables
562
# MATLAB (MATLAB root directory)
564
# CFLAGS (C compiler options)
565
# COPTIMFLAGS (Compiler optimization flags)
566
# CDEBUGFLAGS (Compiler debugging flags)
567
# CLIBS (C libraries for linking)
569
# CXXFLAGS (C++ compiler options)
570
# CXXOPTIMFLAGS (Compiler optimization flags)
571
# CXXDEBUGFLAGS (Compiler debugging flags)
572
# CXXLIBS (C++ libraries for linking)
573
# FC (Fortran compiler)
574
# FFLAGS (Fortran options)
575
# FOPTIMFLAGS (Compiler optimization flags)
576
# FDEBUGFLAGS (Compiler debugging flags)
577
# FLIBS (Fortran libraries for linking)
578
# LD (Linker command)
579
# LDFLAGS (Linker options)
580
# LDOPTIMFLAGS (Compiler optimization flags)
581
# LDDEBUGFLAGS (Compiler debugging flags)
582
# LDEXTENSION (Extension to add to output filename)
584
# The search order for the options file is:
586
# -f optionsfile (file specified with -f command line option)
587
# ./$OPTSFILE_NAME ($OPTSFILE_NAME in current directory)
588
# $HOME/.matlab/<rel_version>/$OPTSFILE_NAME ($OPTSFILE_NAME in user's matlab preferences directory)
589
# $MATLAB/bin/$OPTSFILE_NAME ($OPTSFILE_NAME file in MATLAB bin directory)
592
if [ -f ./$OPTSFILE_NAME ]; then
595
OPTIONS_FILE="./$OPTSFILE_NAME"
596
elif [ -f $HOME/.matlab/$REL_VERSION/$OPTSFILE_NAME ]; then
597
SOURCE_DIR='$HOME/.matlab/$REL_VERSION'
598
SOURCE_DIReval=$HOME/.matlab/$REL_VERSION
599
OPTIONS_FILE="$HOME/.matlab/$REL_VERSION/$OPTSFILE_NAME"
600
elif [ -f $MATLAB/bin/$OPTSFILE_NAME ]; then
602
# NOTE: At this point we will use the MATLAB determined earlier to
603
# source the file. After that the value in that file if not
606
SOURCE_DIR='$MATLAB/bin'
607
SOURCE_DIReval=$MATLAB/bin
608
OPTIONS_FILE="$MATLAB/bin/$OPTSFILE_NAME"
610
describe no_options_file >&2
615
# end determine_options_file ()
617
#****************************************************************************
620
if [ "$ARCH" = "" ]; then # No command line override given
621
if [ ! -f $MATLAB/bin/util/arch.sh ]; then
622
describe no_util_scripts >&2
626
. $MATLAB/bin/util/arch.sh
627
if [ "$Arch" = "unknown" ]; then
628
describe unknown_architecture >&2
632
else # Use command line override
635
if [ ! -f $MATLAB/bin/util/oscheck.sh ]; then
636
describe no_util_scripts >&2
640
if [ "$verbose" = "1" ]; then
641
. $MATLAB/bin/util/oscheck.sh
642
if [ "$oscheck_status" = "1" ]; then
650
#****************************************************************************
652
eval_assignments () {
654
# eval command line overrides of argument variables, name=[def]
656
eval "$cmd_line_overrides"
659
# Make sure that LD is fully evaluated to handle LD=$COMPILER assignment
660
# Some platforms also use the special LDCXX variable for C++ files
663
LDCXX="`eval echo $LDCXX`"
666
# If TEMP is defined be sure that TEMP has been created.
668
if [ "$TEMP" != "" ]; then
669
(cd $TEMP) > /dev/null 2>&1
670
if [ $? -ne 0 ]; then
671
mkdir -p $TEMP 2>/dev/null
672
if [ $? -ne 0 ]; then
673
describe cannot_create_temp >&2
680
# end eval_assignments ()
682
#****************************************************************************
684
build_ada_s_function () {
687
mex_ext=`expr $LDEXTENSION : '\.\(.*\)'`
688
ada_build_args="MATLAB_ROOT=$MATLAB ARCH=$ARCH MEX_EXT=$mex_ext "
689
ada_build_args="$ada_build_args ADA_SFCN=$ada_sfcn "
691
# Determine GNAT Compiler Version
693
gnatVer=`gnatmake -v 2>&1 | grep GNATMAKE | awk '{print $2}'`
694
ada_build_args="$ada_build_args GNAT_VER=$gnatVer "
696
if [ "$debug" = "1" ]; then
697
ada_build_args="$ada_build_args DEBUG=1 "
700
if [ "$verbose" = "1" ]; then
701
ada_build_args="$ada_build_args VERBOSE=1 "
704
if [ "$OUTDIR" != "" ]; then
705
ada_build_args="$ada_build_args OUTPUT_DIR=$OUTDIR "
708
if [ "$include_dirs" != "" ]; then
709
ada_build_args="$ada_build_args INCLUDES=\"$include_dirs\" "
711
makefile="$MATLAB/simulink/ada/interface/gnat_unix.mk"
713
# Verify that make exists and is gnu make
715
makeVer='make --version | paste -s -d" " -'
716
makeOk='expr "$makeVer" : "^GNU Make version .*"'
717
if [ "$makeOk" = "0" ]; then
718
describe ada_needs_gnu_make >&2
723
echo "### Starting build for Ada S-function $ada_sfcn"
724
ada_build_cmd="make -f $makefile $ada_build_args"
725
if [ "$verbose" = "1" ]; then
727
echo " $ada_build_cmd"
730
eval "$ada_build_cmd"
731
if [ $? -ne 0 ]; then
732
describe ada_build_failure >&2
736
echo "### Successfully built Ada S-function $ada_sfcn"
740
# end build_ada_s_function ()
742
#****************************************************************************
746
# Check for errors in calling syntax
748
if [ "$argcheck" = "1" -a "$cfiles" != "1" ]; then
749
stat="Argument checking not possible without C source files."
751
if [ "$inlined" = "1" -a "$cfiles" != "1" ]; then
752
stat="Inlining not possible without C source files."
754
if [ "$argcheck" = "1" -a "$inlined" = "1" ]; then
755
stat="Argument checking and inlining are mutually exclusive."
757
if [ "$files" != "" -a "$cfiles" != "1" -a "$cxxfiles" != "1" -a "$ffiles" != "1" ]; then
759
if [ "$verbose" != "" ]; then
760
describe assuming_c_source
761
if [ "$v7_compat" = "1" ]; then
762
describe assuming_matlab_7
766
if [ "$stat" != "OK" ]; then # An error occurred.
767
if [ "$stat" != "" ]; then
777
#****************************************************************************
781
# If there is already a mex name, -output was used: supply an appropriate
782
# MEX-file extension if necessary. (Warn if -c was also used.)
783
# Otherwise, use the first file name to determine the MEX-file name.
784
# If there are no files, don't complain (error_check comes later).
786
if [ "$mex_file" != "" ]; then # This case is if -output was used
787
if [ "$compile_only" = "1" ]; then
788
describe meaningless_output_flag
790
# Keep only the name and ext (not path) if linking and no OUTDIR set
791
if [ "$compile_only" != "1" -a "$OUTDIR" != "" -a \
792
`expr "$mex_file" : '.*\/.*'` != 0 ]; then
793
mex_file=`expr "$mex_file" : '.*\/\(.*\)$'`
795
ext=`expr "$mex_file" : ".*$LDEXTENSION$"`
796
if [ "$ext" = "0" ]; then
797
mex_file=$mex_file$LDEXTENSION
799
elif [ "$1" != "" ]; then # This case sets mex_file using the SOURCE name from $1
800
ext=`expr "$1" : '\.*[^.].*\.\([^.]*\)$'`
801
mex_file=`expr "//$1" : ".*/\(.*\)\.${ext}$" \| "//$1" : ".*/\(.*\)"`
802
mex_file=$mex_file$LDEXTENSION
804
if [ "$OUTDIR" != "" ]; then
805
mex_file="$OUTDIR/$mex_file"
807
mex_file=`smart_quote $mex_file`
811
#****************************************************************************
815
# Determine which include directories to specify
817
include_dirs="$include_dirs -I`smart_quote $MATLAB/$MEX_INCLUDE_DIR`"
818
if [ -d $MATLAB/simulink ]; then
819
include_dirs="$include_dirs -I`smart_quote $MATLAB/simulink/include`"
821
if [ -d $MATLAB/codegen ]; then
822
include_dirs="$include_dirs -I`smart_quote $MATLAB/codegen/external/common`"
825
# end get_includes ()
827
#****************************************************************************
830
trap "eval $abort; exit 1" 1 2 3 15
832
# For each file, compile source files and add other files
833
# to the list of link options.
836
if [ ! -f "$file" ]; then
837
describe file_not_found >&2
842
# determine extension and basename
844
ext=`expr "$file" : '\.*[^.].*\.\([^.]*\)$'`
845
if [ "$ext" = "" ]; then
846
ext=`expr "$file" : '\.*[^.].*\.\(so\)[.0-9]*$'`
848
basename=`expr "//$file" : ".*/\(.*\)\.${ext}$" \| //$file : ".*/\(.*\)"`
850
if [ "$TEMP" != "" -a "$compile_only" != "1" ]; then
851
basename=$TEMP/$basename$$
852
elif [ "$OUTDIR" != "" ]; then
853
basename=$OUTDIR/$basename
856
basename=`smart_quote $basename`
858
# Source file extensions: .c .C .cc .cxx .cpp .f .for .F .f90 .F90
861
c |cu ) # c source file.
863
# determine whether to optimize or debug
865
if [ "$debug" != "1" ]; then
867
elif [ "$optimize" = "1" ]; then
868
flags="$CDEBUGFLAGS $COPTIMFLAGS"
873
# Determine final compile command for C source code.
875
flags="-DMATLAB_MEX_FILE $CFLAGS $cc_flags $flags"
876
compile_command="$CC -c $include_dirs $flags $file"
878
cc | cpp | cxx | C) # C++ source file
880
# determine whether to optimize or debug
882
if [ "$debug" != "1" ]; then
883
flags="$CXXOPTIMFLAGS"
884
elif [ "$optimize" = "1" ]; then
885
flags="$CXXDEBUGFLAGS $CXXOPTIMFLAGS"
887
flags="$CXXDEBUGFLAGS"
890
# Determine final compile command for C++ source code.
892
flags="-DMATLAB_MEX_FILE $CXXFLAGS $cxx_flags $flags"
893
compile_command="$CXX -c $include_dirs $flags $file"
895
f | for | F | f90 | F90) # Fortran source file.
897
# determine whether to optimize or debug
899
if [ "$debug" != "1" ]; then
901
elif [ "$optimize" = "1" ]; then
902
flags="$FDEBUGFLAGS $FOPTIMFLAGS"
907
# Determine final compile command for Fortran source code.
909
flags="$FFLAGS $fc_flags $flags"
910
compile_command="$FC -c $include_dirs $flags $file"
914
# Object files: Don't need to do anything except add to compiled list
921
if [ "$TEMP" != "" -a "$compile_only" != "1" ]; then
922
compile_command="$compile_command -o $basename.o"
923
elif [ "$OUTDIR" != "" ]; then
924
compile_command="$compile_command -o $basename.o"
927
if [ "$verbose" = "1" -o "$no_execute" = "true" ]; then
928
describe compile_stage
931
if [ "$no_execute" != "true" ]; then eval "$compile_command"; fi
932
if [ $? -ne 0 ]; then
933
describe failed_compile >&2
937
if [ "$compile_only" != "1" ]; then
938
files_to_remove="$files_to_remove $basename.o"
940
objs="$objs $basename.o"
944
#****************************************************************************
947
trap "eval $abort; exit 1" 1 2 3 15
951
if [ "$cfiles" = "1" ]; then
954
if [ "$cxxfiles" = "1" ]; then
955
libs="$libs $CXXLIBS"
957
if [ "$ffiles" = "1" ]; then
963
# determine whether to optimize or debug
965
if [ "$debug" != "1" ]; then
966
LDFLAGS="$LDOPTIMFLAGS $LDFLAGS"
967
elif [ "$optimize" = "1" ]; then
968
LDFLAGS="$LDDEBUGFLAGS $LDOPTIMFLAGS $LDFLAGS"
970
LDFLAGS="$LDDEBUGFLAGS $LDFLAGS"
972
if [ "$verbose" = "1" -o "$no_execute" = "true" ]; then
975
if [ "$no_execute" != "true" ]; then eval "$LD $LDFLAGS $ld_flags -o $mex_file $libetc"; fi
976
if [ $? -ne 0 ]; then
977
describe failed_link >&2
985
perform_check=`echo $CC | awk '
989
/gcc$/{isGcc = "yes";exit 0 }
990
/g\+\+$/{isGcc = "yes";exit 0 }
995
#We have a gcc compiler, so we need to check the version.
996
if [ $perform_check "=" "yes" ];then
997
$CC --version | head -n 1 | awk '
999
allowable_versions[1]="glnx86,3.4.0,3.4.5"
1000
allowable_versions[2]="glnxa64,3.4.0,3.4.5"
1003
# Figure out what version of gcc we are dealing with.
1004
# Set version_number to the version of gcc.
1006
for (i = 1; i <= NF; i++)
1008
if ($i ~ /^[0-9]+\./)
1011
exit 0 # This sends you to the end block
1017
# Find the array member of allowable_versions that corresponds to the
1018
# architecture of the local machine.
1020
for(i = 1; i <= 2; i++)
1022
# This uses the shell interpreter to substitute for arch.
1024
if (allowable_versions[i] ~ /^'"$Arch"'/)
1026
string_of_test_versions = allowable_versions[i]
1031
# If there is no match, we are dealing with gcc on
1032
# an architecture not in the table. Assume it is ok and
1033
# quit checking the version.
1035
if (string_of_test_versions == "")
1039
split(string_of_test_versions, versions, ",")
1040
size_of_min_version = split(versions[2], min_version_array, ".")
1041
number_of_digits = split(version_number, gcc_version_array, ".")
1043
# Check if the version is smaller than the minimum version. If it is,
1044
# print a warning message and exit.
1046
for (i = 1; i <= size_of_min_version; i++)
1048
if ( i > number_of_digits)
1054
curr_num = gcc_version_array[i]
1056
if (curr_num < min_version_array[i])
1058
printf("Warning: You are using gcc version \"%s\". The earliest gcc version supported\nwith mex is \"%s\". The latest version tested for use with mex is \"%s\".\nTo download a different version of gcc, visit http://gcc.gnu.org \n", version_number, versions[2], versions[3]);
1061
if (curr_num > min_version_array[i])
1067
# If the version is not smaller than the minimum version, check if
1068
# it is larger than the maximum version.
1070
size_of_max_version = split(versions[3], max_version_array, ".")
1071
for (i = 1; i <= size_of_max_version; i++)
1073
if (i > number_of_digits)
1079
curr_num = gcc_version_array[i]
1081
if (curr_num > max_version_array[i])
1083
printf("Warning: You are using gcc version \"%s\". The earliest gcc version supported\nwith mex is \"%s\". The latest version tested for use with mex is \"%s\".\nTo download a different version of gcc, visit http://gcc.gnu.org \n", version_number, versions[2], versions[3]);
1086
if (curr_num < max_version_array[i])
1096
#****************************************************************************
1098
# On sol2 add the C++ Template Repository to the remove list under the
1101
# Sun uses a template repository to store template instances between
1102
# separate compilations so that template instances are compiled only when
1105
# It is controlled by the directory of the output file.
1107
# Note: if TEMP and OUTDIR are both defined TEMP takes precedence.
1109
# Necessary conditions for deletion:
1111
# 1. Must compile at least one C++ file. ($cxxfiles = "1")
1112
# 2. Must link. ($compile_only != "!")
1114
# case 1: SUNWS_CACHE_NAME is undefined
1116
# ./SunWS_cache - No TEMP or OUTDIR defined
1117
# $TEMP/SunWS_cache - TEMP defined
1118
# $OUTDIR/SunWS_cache - TEMP not defined but OUTDIR defined
1120
# case 2: SUNWS_CACHE_NAME is defined
1122
# ./$SUNWS_CACHE_NAME - No TEMP or OUTDIR defined
1123
# $TEMP/$SUNWS_CACHE_NAME - TEMP defined
1124
# $OUTDIR/$SUNWS_CACHE_NAME - TEMP not defined but OUTDIR defined
1126
add_template_to_rmlist () { # If the conditions are right add the template
1127
# repository to the files_to_remove list.
1128
# Used only on sol2.
1130
if [ "$cxxfiles" = "1" -a "$compile_only" != "1" ]; then
1131
if [ "$SUNWS_CACHE_NAME" != "" ]; then
1132
cache_name=$SUNWS_CACHE_NAME
1134
cache_name=SunWS_cache
1136
if [ "$TEMP" = "" -a "$OUTDIR" = "" ]; then
1137
files_to_remove="$files_to_remove ./$cache_name"
1138
elif [ "$TEMP" != "" ]; then
1139
files_to_remove="$files_to_remove $TEMP/$cache_name"
1141
files_to_remove="$files_to_remove $OUTDIR/$cache_name"
1145
#****************************************************************************
1150
# Initialize some variables
1152
OPTSFILE_NAME='mexopts.sh'
1154
MEX_INCLUDE_DIR='extern/include'
1162
# Define $MATLAB if it's not defined.
1163
if [ ! "$MATLAB" ]; then # If no MATLAB='' was used
1168
# Use a C entry point by default
1173
# Current default is V7 (32-bit)
1177
cmd_line_overrides=":"
1178
while [ "$stat" = "OK" -a $# -gt 0 ]; do
1180
# Parse input arguments. The routine may need the next two arguments,
1181
# as in -f optionsfile and -o mexfilename.
1184
-compatibleArrayDims)
1192
cc_flags="$cc_flags -DARGCHECK"
1193
cxx_flags="$cxx_flags -DARGCHECK"
1198
-D*) # Compiler flags.
1199
lhs=`expr "$1" : '\(-D[a-zA-Z0-9_]*\).*'`
1200
mid=`expr "$1" : '-D[a-zA-Z0-9_]*\([=\#]\).*$'`
1201
rhs=`expr "$1" : '-D[a-zA-Z0-9_]*[=\#]\(.*\)$'`
1203
if [ "$mid" != "" ]; then
1207
cc_flags="$cc_flags $lhs$mid$rhs"
1208
cxx_flags="$cxx_flags $lhs$mid$rhs"
1209
fc_flags="$fc_flags $lhs$mid$rhs"
1211
if [ "$lhs" = "-DV5_COMPAT" ]; then
1212
stat="Please use -V5 rather than directly passing"
1213
stat="$stat -DV5_COMPAT."
1215
if [ "$lhs" = "-DARRAY_ACCESS_INLINING" ]; then
1216
stat="Please use -inline rather than directly passing"
1217
stat="$stat -DARRAY_ACCESS_INLINING."
1220
-U*) # Compiler flags.
1221
cc_flags="$cc_flags $1"
1222
cxx_flags="$cxx_flags $1"
1223
fc_flags="$fc_flags $1"
1225
-I* | -isystem*) # Include directories
1226
include_dirs="$include_dirs `smart_quote $1`"
1229
if [ -f "$2" ]; then
1233
describe invalid_options_file >& 2
1245
gateway_lang=FORTRAN
1247
-[g]*) # Use debugging flags.
1250
-h | -help) # -help: Help option.
1256
cc_flags="$cc_flags -DARRAY_ACCESS_INLINING"
1257
cxx_flags="$cxx_flags -DARRAY_ACCESS_INLINING"
1263
-Wl* | -R*) # allow other linker options
1269
-nohg) # ignored for compatibility with mbuild
1271
-o | -output) # mexfile name
1275
-outdir) # output directory
1276
if [ $# -lt 2 ]; then
1282
(cd $OUTDIR) > /dev/null 2>&1
1283
if [ $? -ne 0 ]; then
1284
mkdir -p $OUTDIR 2>/dev/null
1285
if [ $? -ne 0 ]; then
1286
describe cannot_create_outdir >&2
1293
-O) # Use optimization flags.
1297
if [ $arg_count -ne 2 -a $arg_count -ne 1 ]; then
1302
SETUP_OPTIONS_FILE=$2
1305
# source the setup_options_file finction declaration
1307
. $MATLAB/bin/optsetup.sh
1309
setup_options_file $SETUP_OPTIONS_FILE
1314
-silent) # really not verbose - undocumented
1321
stat="The -v3.5 option is no longer supported."
1324
stat="The -v4 option is no longer supported."
1327
cc_flags="$cc_flags -DV5_COMPAT"
1328
cxx_flags="$cxx_flags -DV5_COMPAT"
1332
if [ -f "$2" ]; then
1335
describe invalid_ada_flag >& 2
1342
if [ "$2" != "mexFunction" -a "$2" != "mexLibrary" ]; then
1343
stat="-entrypt argument must be either 'mexFunction' or 'mexLibrary'"
1349
check_archlist argument=$1 noprint
1350
if [ "$ARCH" = "" ]; then
1351
stat="$1 not a valid option."
1355
rhs=`expr "$1" : '[a-zA-Z0-9_]*[=\#]\(.*\)$'`
1356
ARCH="`eval echo $rhs`"
1359
mlrhs=`expr "$1" : '[a-zA-Z0-9_]*[=\#]\(.*\)$'`
1360
MATLAB="`eval echo $mlrhs`"
1363
lhs=`expr "$1" : '\([a-zA-Z0-9_]*\)[=\#].*'`
1364
rhs=`expr "$1" : '[a-zA-Z0-9_]*[=\#]\(.*\)$'`
1365
cmd_line_overrides="$cmd_line_overrides; $lhs="'"'"$rhs"'"'
1367
*.c | *.cu) # c source file.
1371
*.C | *.cc | *.cpp | *.cxx) # C++ source file.
1375
*.f | *.for | *.F | *.f90 | *.F90) # FORTRAN source file.
1376
if [ "$ffiles" != "1" -a "$cfiles" != "1" -a "$cxxfiles" != "1" ]; then
1377
gateway_lang=FORTRAN
1386
libs="$libs `smart_quote $1`"
1391
if [ $v7_compat -eq 1 ] ; then
1392
fc_flags="$fc_flags -DMX_COMPAT_32"
1393
cc_flags="$cc_flags -DMX_COMPAT_32"
1394
cxx_flags="$cxx_flags -DMX_COMPAT_32"
1396
if [ $# -eq 0 -a "$files" = "" -a "$stat" = "OK" ]; then
1397
stat="no file name given."
1399
if [ "$gateway_lang" = "FORTRAN" -a "$entrypt" != "mexFunction" ]; then
1400
describe fortran_cannot_change_entrypt
1404
# It is now safe to use functions, since we have parsed all of the
1405
# input arguments. (The use of functions corrupts $# and $* on
1406
# HP-UX 9.0x systems.)
1408
if [ ! "$OPTIONS_FILE" ]; then # If no -f optionsfile was used
1409
determine_options_file
1412
. $OPTIONS_FILE # Source file to determine $MATLAB
1413
get_arch # Call $MATLAB/bin/util/arch.sh
1415
get_entrypt $gateway_lang # Determine MEX-file entry pt
1417
if [ "$ffiles" = "1" ]; then
1419
elif [ "$cxxfiles" = "1" ]; then
1425
. $OPTIONS_FILE # Source options file
1427
eval_assignments # Evaluate VAR=value arguments
1429
get_name $files # Determine MEX-file name
1434
if [ "$gateway_lang" = "ADA" ]; then
1435
build_ada_s_function
1440
if [ "$verbose" = "1" ]; then
1441
describe final_options
1444
error_check # Check calling syntax errors
1446
get_includes # Determine include directories
1448
if [ "$compile_only" != "1" ]; then
1449
if [ "$gateway_lang" = "C" ]; then
1450
files="$files $MATLAB/extern/src/mexversion.c"
1452
files="$files $MATLAB/extern/lib/$Arch/version4.o"
1455
if [ "$argcheck" = "1" ]; then
1456
files="$files $MATLAB/extern/src/mwdebug.c"
1459
# On sol2 add the C++ template repository to the remove list under
1460
# the right conditions.
1462
if [ "$Arch" = "sol2" ]; then
1463
add_template_to_rmlist
1465
# Check the version of gcc if we are using gcc to warn about possible
1469
# From this point on, we need to put traps in each function. The IBM
1470
# resets traps on entry to each function, so we need to safeguard
1471
# any functions we call after compiling. This includes compile(),
1472
# link(), and cleanup().
1477
compile $file # Process each file in list
1480
if [ "$compile_only" != "1" ]; then
1481
link # Perform linking
1483
# Perform any POSTLINK_CMDS; ":" is the empty/null command which
1484
# we initialize POSTLINK_CMDS to in order to allow for concatenation
1485
# of multiple postlink commands such as
1487
# POSTLINK_CMDS='$POSTLINK_CMDS;my_command'
1489
# if POSTLINK_CMDS were initially empty in the above command, the
1490
# result would be ";my_command" which isn't legal.
1491
if [ "$POSTLINK_CMDS" != ":" -a "$POSTLINK_CMDS" != "" ]; then
1492
if [ "$verbose" = "1" -o "$no_execute" = "true" ]; then
1493
describe postlink_stage
1495
if [ "$no_execute" != "true" ]; then
1496
eval "$POSTLINK_CMDS";
1504
#****************************************************************************