/normxcorr/trunk

To get this branch, use:
bzr branch http://suren.me/webbzr/normxcorr/trunk

« back to all changes in this revision

Viewing changes to cuda/nvmex

  • Committer: Suren A. Chilingaryan
  • Date: 2009-01-15 13:50:29 UTC
  • Revision ID: csa@dside.dyndns.org-20090115135029-wleapicg9a4593tp
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
#
 
3
#     mex    compilation program for MATLAB C and Fortran language MEX-files
 
4
#
 
5
# Copyright 1984-2006 The MathWorks, Inc.
 
6
# $Revision: 1.108.4.19 $  $Date: 2006/06/23 19:04:11 $
 
7
#____________________________________________________________________________
 
8
    arg0_=$0
 
9
 
 
10
#
 
11
    abort='rm -rf $files_to_remove $basename.o > /dev/null 2>&1; \
 
12
          echo ""; \
 
13
          echo "    mex:  interrupted."; \
 
14
          echo ""'
 
15
#
 
16
    trap "eval $abort; exit 1" 1 2 3 15
 
17
#
 
18
#========================= archlist.sh (start) ============================
 
19
#
 
20
# usage:        archlist.sh
 
21
#
 
22
# abstract:     This Bourne Shell script creates the variable ARCH_LIST.
 
23
#
 
24
# note(s):      1. This file is always imbedded in another script
 
25
#
 
26
# Copyright 1997-2005 The MathWorks, Inc.
 
27
# $Revision: 1.9.4.5 $  $Date: 2005/10/07 14:01:06 $
 
28
#----------------------------------------------------------------------------
 
29
#
 
30
    ARCH_LIST='sol2 glnx86 glnxa64 mac maci'
 
31
#=======================================================================
 
32
# Functions:
 
33
#   check_archlist ()
 
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:
 
40
                        #
 
41
                        #     ARCH=arch
 
42
                        #     MATLAB_ARCH=arch
 
43
                        #     argument=-arch
 
44
                        #
 
45
                        # Always returns a 0 status.
 
46
                        #
 
47
                        # usage: check_archlist arch=[-]value [noprint]
 
48
                        #
 
49
        if [ $# -gt 0 ]; then
 
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)
 
55
              if ($i == "EOF")
 
56
                  narch = i - 1
 
57
          for (i = 1; i <= narch; i = i + 1)
 
58
                if ($i == $NF || "-" $i == $NF) {
 
59
                    print $i
 
60
                    exit
 
61
                }
 
62
        }'`
 
63
#-----------------------------------------------------------------------
 
64
               if [ "$ARCH" = "" -a $# -eq 1 ]; then
 
65
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
66
echo ' '
 
67
echo "    Warning: $1 does not specify a valid architecture - ignored . . ."
 
68
echo ' '
 
69
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
70
               fi
 
71
            else
 
72
                ARCH=""
 
73
            fi
 
74
        else
 
75
            ARCH=""
 
76
        fi
 
77
#
 
78
        return 0
 
79
    }
 
80
#=======================================================================
 
81
#========================= archlist.sh (end) ==============================
 
82
#
 
83
#========================== version.sh (start) ============================
 
84
#
 
85
# usage:        version [-b | -f | -p]
 
86
#
 
87
# abstract:     This POSIX Shell script function returns the MATLAB
 
88
#               release version. Any bad options are ignored without
 
89
#               warning.
 
90
#
 
91
#               The version is assumed to be of the form:
 
92
#
 
93
#                   R<integer>[<noninteger>]
 
94
#
 
95
#               options:
 
96
#
 
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
 
100
#
 
101
# note(s):      1. This file is always imbedded in another script
 
102
#
 
103
# Copyright 1992-2005 The MathWorks, Inc.
 
104
# $Revision: 1.1.6.4 $  $Date: 2005/12/01 02:16:52 $
 
105
#----------------------------------------------------------------------------
 
106
#
 
107
version () {
 
108
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
109
    ver='R2006b'
 
110
    full_ver='R2006b'
 
111
    prev_ver='R2006a'
 
112
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
113
    if [ $# -eq 1 ]; then
 
114
        if [ "$1" = '-b' ]; then
 
115
            expr "$ver" : '\(R[0-9]*\).*$'
 
116
            return $?
 
117
        fi
 
118
        if [ "$1" = '-f' ]; then
 
119
            echo "$full_ver"
 
120
            return 0
 
121
        fi
 
122
        if [ "$1" = '-p' ]; then
 
123
            echo "$prev_ver"
 
124
            return 0
 
125
        fi
 
126
    fi
 
127
    echo "$ver"
 
128
    return 0
 
129
}
 
130
#========================== version.sh (end) ==============================
 
131
    REL_VERSION=`version -f`
 
132
#
 
133
#============================================================================
 
134
#  FUNCTION DEFINITIONS
 
135
#============================================================================
 
136
#
 
137
#****************************************************************************
 
138
#
 
139
# NOTE: A call to cleanup MUST precede any call to exit within this script,
 
140
#       except for within trap calls.
 
141
  cleanup () {
 
142
#
 
143
# Clean up temporary and intermediate files (usually in preparation
 
144
# for exiting)
 
145
#
 
146
    trap "eval $abort; exit 1" 1 2 3 15
 
147
    rm -rf $files_to_remove > /dev/null 2>&1
 
148
    }
 
149
#   end cleanup ()
 
150
#
 
151
#****************************************************************************
 
152
#
 
153
  printHelp () {
 
154
      helpTextFileName="$MATLAB/bin/util/mex/mexHelp.txt"
 
155
      cat $helpTextFileName
 
156
      echo ''
 
157
  }
 
158
 
 
159
#****************************************************************************
 
160
#
 
161
  describe () {
 
162
#
 
163
    case "$1" in
 
164
        internal_error_1)
 
165
    echo ''
 
166
    echo 'Internal error 1: We could not determine the path of the'
 
167
    echo '                  MATLAB root directory.'
 
168
    echo ''
 
169
    echo "                  original command path = $arg0_"
 
170
    echo "                  current  command path = $filename"
 
171
    echo ''
 
172
    echo '                  Please contact:'
 
173
    echo '' 
 
174
    echo '                      MathWorks Technical Support'
 
175
    echo ''
 
176
    echo '                  for further assistance.'
 
177
    echo ''
 
178
            ;;
 
179
        internal_error_2)
 
180
    echo ''
 
181
    echo 'Internal error 2: Could not determine the path of the'
 
182
    echo '                  MATLAB root directory.'
 
183
    echo ''
 
184
    echo "                  original command path = $filename"
 
185
    echo "                  current  command path = $filename"
 
186
    echo ''
 
187
    echo '                  Please contact:'
 
188
    echo '' 
 
189
    echo '                      MathWorks Technical Support'
 
190
    echo ''
 
191
    echo '                  for further assistance.'
 
192
    echo ''
 
193
            ;;
 
194
        internal_error_3)
 
195
    echo ''
 
196
    echo 'Internal error 3: More than $maxlinks links in path to'
 
197
    echo "                  this script. That's too many!"
 
198
    echo ''
 
199
    echo "                  original command path = $filename"
 
200
    echo "                  current  command path = $filename"
 
201
    echo ''
 
202
    echo '                  Please contact:'
 
203
    echo '' 
 
204
    echo '                      MathWorks Technical Support'
 
205
    echo ''
 
206
    echo '                  for further assistance.'
 
207
    echo ''
 
208
            ;;        
 
209
        unknown_architecture)
 
210
    echo ''
 
211
    echo '    Sorry! We could not determine the machine architecture'
 
212
    echo '           for your host. Please contact:'
 
213
    echo ''
 
214
    echo '               MathWorks Technical Support'
 
215
    echo ''
 
216
    echo '           for further assistance.'
 
217
    echo ''
 
218
            ;;
 
219
        no_util_scripts)
 
220
    echo ''
 
221
    echo '    Sorry! We could not determine the machine architecture'
 
222
    echo '           for your host, because one of the utilities'
 
223
    echo ''
 
224
    echo '               $MATLAB/bin/util/arch.sh'
 
225
    echo ''
 
226
    echo '           or'
 
227
    echo ''
 
228
    echo '               $MATLAB/bin/util/oscheck.sh'
 
229
    echo ''
 
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.'
 
234
    echo ''
 
235
    echo '           Here'
 
236
    echo ''
 
237
    echo "               MATLAB = $MATLAB"
 
238
    echo ''
 
239
    echo '           Please contact:'
 
240
    echo ''
 
241
    echo '               MathWorks Technical Support'
 
242
    echo ''
 
243
    echo '           if you need assistance.'
 
244
    echo ''
 
245
            ;;
 
246
        unknown_arch)
 
247
    echo ''
 
248
    echo "    mex:  machine architecture '$Arch' not supported."
 
249
    echo ''
 
250
            ;;
 
251
        invalid_options_file)
 
252
    echo ''
 
253
    echo '    Error: An invalid options file name was specified:'
 
254
    echo "           $2 is not a normal file or does not exist."
 
255
    echo ''
 
256
            ;;
 
257
        no_options_file)
 
258
    echo ''
 
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.'
 
266
    echo ''
 
267
    echo '           Here'
 
268
    echo ''
 
269
    echo "               MATLAB = $MATLAB"
 
270
    echo ''
 
271
    echo '           Please contact:'
 
272
    echo ''
 
273
    echo '               MathWorks Technical Support'
 
274
    echo ''
 
275
    echo '           for further assistance.'
 
276
    echo ''
 
277
            ;;
 
278
        final_options)
 
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"
 
286
            else
 
287
    echo "-> options file not found ($OPTSFILE_NAME looked for)."
 
288
            fi
 
289
    echo '----------------------------------------------------------------'
 
290
    echo "->    MATLAB                = $MATLAB"
 
291
    echo "->    CC                    = $CC"
 
292
    echo "->    CC flags:"
 
293
    echo "         CFLAGS             = $CFLAGS"
 
294
    echo "         CDEBUGFLAGS        = $CDEBUGFLAGS"
 
295
    echo "         COPTIMFLAGS        = $COPTIMFLAGS"
 
296
    echo "         CLIBS              = $CLIBS"
 
297
    echo "         arguments          = $cc_flags"
 
298
    echo "->    CXX                   = $CXX"
 
299
    echo "->    CXX flags:"
 
300
    echo "         CXXFLAGS           = $CXXFLAGS"
 
301
    echo "         CXXDEBUGFLAGS      = $CXXDEBUGFLAGS"
 
302
    echo "         CXXOPTIMFLAGS      = $CXXOPTIMFLAGS"
 
303
    echo "         CXXLIBS            = $CXXLIBS"
 
304
    echo "         arguments          = $cxx_flags"
 
305
    echo "->    FC                    = $FC"
 
306
    echo "->    FC flags:"
 
307
    echo "         FFLAGS             = $FFLAGS"
 
308
    echo "         FDEBUGFLAGS        = $FDEBUGFLAGS"
 
309
    echo "         FOPTIMFLAGS        = $FOPTIMFLAGS"
 
310
    echo "         FLIBS              = $FLIBS"
 
311
    echo "         arguments          = $fc_flags"
 
312
    echo "->    LD                    = $LD"
 
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 '----------------------------------------------------------------'
 
327
    echo ''
 
328
            ;;
 
329
        assuming_c_source)
 
330
    echo ''
 
331
    echo '    Warning: No source files in argument list.'
 
332
    echo ''
 
333
    echo '      Assuming C source code. To override this assumption, use'
 
334
    echo '      -fortran.'
 
335
    echo '      or'
 
336
    echo '      -cxx'
 
337
    echo ''
 
338
            ;;
 
339
        meaningless_output_flag)
 
340
    echo ''
 
341
    echo '    Warning: -output ignored (no MEX-file is being created).'
 
342
    echo ''
 
343
            ;;
 
344
        assuming_matlab_7)
 
345
    echo '      Assuming MATLAB 7.0 32-bit compatibility mode.'
 
346
    echo '      To override this assumption, use -largeArrayDims.'
 
347
    echo ''
 
348
            ;;
 
349
        status)
 
350
    echo ""
 
351
    echo "    mex:  $stat"
 
352
            ;;
 
353
        usage)
 
354
    cat<<'EOF'
 
355
 
 
356
    Usage:
 
357
      MEX [option1 ... optionN] sourcefile1 [... sourcefileN]
 
358
          [objectfile1 ... objectfileN] [libraryfile1 ... libraryfileN]
 
359
 
 
360
    or (to build an Ada S-function):
 
361
      MEX [-v] [-g] -ada <sfcn>.ads
 
362
 
 
363
    Use the -help option for more information, or consult the MATLAB External Interfaces Guide.
 
364
 
 
365
EOF
 
366
            ;;
 
367
        file_not_found)
 
368
    echo ''
 
369
    echo "    mex:  $file not a normal file or does not exist."
 
370
    echo ''
 
371
            ;;
 
372
        compile_stage)
 
373
    echo "-> $compile_command"
 
374
    echo ''
 
375
            ;;
 
376
        failed_compile)
 
377
    echo ''
 
378
    echo "    mex: compile of '$file' failed."
 
379
    echo ''
 
380
            ;;
 
381
        link_stage)
 
382
    echo "-> $LD $LDFLAGS -o $mex_file $libetc"
 
383
    echo ''
 
384
            ;;
 
385
        failed_link)
 
386
    echo ''
 
387
    echo "    mex: link of '$mex_file' failed."
 
388
    echo ''
 
389
            ;;
 
390
        postlink_stage)
 
391
    echo "-> $POSTLINK_CMDS"
 
392
    echo ''
 
393
            ;;
 
394
        invalid_ada_flag)
 
395
    echo ''
 
396
    echo '    Error: An invalid Ada S-function file name was specified:'
 
397
    echo "           $2 is not a normal file or does not exist."
 
398
    echo ''
 
399
            ;;
 
400
        ada_needs_gnu_make)
 
401
    echo ''
 
402
    echo '    Error: Need GNU make properly installed and available on path '
 
403
    echo "           to build Ada S-function '$ada_sfcn'"
 
404
    echo ''
 
405
            ;;
 
406
        ada_build_failure)
 
407
    echo ''
 
408
    echo "    mex: Failed to build Ada S-Function '$ada_sfcn'"
 
409
    echo ''
 
410
            ;;
 
411
        fortran_cannot_change_entrypt)
 
412
    echo ''
 
413
    echo '    Warning: -entrypt ignored (FORTRAN entry point cannot be overridden).'
 
414
    echo ''
 
415
            ;;
 
416
        cannot_create_outdir)
 
417
    echo ''
 
418
    echo "    Error: Could not create OUTDIR = $OUTDIR"
 
419
    echo ''
 
420
            ;;
 
421
        cannot_create_temp)
 
422
    echo ''
 
423
    echo "    Error: Could not create TEMP = $TEMP"
 
424
    echo ''
 
425
            ;;
 
426
        *)
 
427
    echo ''
 
428
    echo " Internal error 4: unimplemented message $1"
 
429
    echo ''
 
430
            ;;
 
431
    esac
 
432
  }
 
433
# end describe ()
 
434
#
 
435
#****************************************************************************
 
436
#
 
437
  smart_quote () {
 
438
#
 
439
# Return a quoted version of the input string if it has spaces in it.
 
440
#
 
441
    if [ $# -gt 1 ]; then
 
442
        echo \"$*\"
 
443
    else
 
444
        echo $1
 
445
    fi   
 
446
  }
 
447
# end smart_quote ()
 
448
#
 
449
#****************************************************************************
 
450
#
 
451
  get_root_dir () {
 
452
#
 
453
#   Determine the path of the MATLAB root directory - always one directory
 
454
#   up from the path to this command.
 
455
#
 
456
    filename=$1
 
457
#
 
458
# Now it is either a file or a link to a file.
 
459
#
 
460
    cpath=`pwd`
 
461
#
 
462
# Follow up to 8 links before giving up. Same as BSD 4.3
 
463
#
 
464
    n=1
 
465
    maxlinks=8
 
466
    while [ $n -le $maxlinks ]
 
467
    do
 
468
#
 
469
# Get directory correctly!
 
470
#
 
471
        newdir=`echo "$filename" | awk '
 
472
                        { tail = $0
 
473
                          np = index (tail, "/")
 
474
                          while ( np != 0 ) {
 
475
                             tail = substr (tail, np + 1, length (tail) - np)
 
476
                             if (tail == "" ) break
 
477
                             np = index (tail, "/")
 
478
                          }
 
479
                          head = substr ($0, 1, length ($0) - length (tail))
 
480
                          if ( tail == "." || tail == "..")
 
481
                             print $0
 
482
                          else
 
483
                             print head
 
484
                        }'`
 
485
        if [ ! "$newdir" ]; then
 
486
            newdir="."
 
487
        fi
 
488
        (cd $newdir) > /dev/null 2>&1
 
489
        if [ $? -ne 0 ]; then
 
490
            describe internal_error_1 >&2
 
491
            cleanup
 
492
            exit 1
 
493
        fi
 
494
        cd $newdir
 
495
#
 
496
# Need the function pwd - not the built in one
 
497
#
 
498
        newdir=`/bin/pwd`
 
499
#
 
500
        newbase=`expr //$filename : '.*/\(.*\)' \| $filename`
 
501
        lscmd=`ls -l $newbase 2>/dev/null`
 
502
        if [ ! "$lscmd" ]; then
 
503
            describe internal_error_2 >&2
 
504
            cleanup
 
505
            exit 1
 
506
        fi
 
507
#
 
508
# Check for link portably
 
509
#
 
510
        if [ `expr "$lscmd" : '.*->.*'` -ne 0 ]; then
 
511
            filename=`echo "$lscmd" | awk '{ print $NF }'`
 
512
        else
 
513
#
 
514
# It's a file
 
515
#
 
516
            dir="$newdir"
 
517
            command="$newbase"
 
518
#
 
519
            cd $dir/..
 
520
            MATLAB=`/bin/pwd`; export MATLAB
 
521
            break
 
522
        fi
 
523
        n=`expr $n + 1`
 
524
    done
 
525
    if [ $n -gt $maxlinks ]; then
 
526
        describe internal_error_3 >&2
 
527
        cleanup
 
528
        exit 1
 
529
    fi
 
530
#       
 
531
    cd $cpath
 
532
  }
 
533
#   end get_root_dir ()
 
534
#
 
535
#****************************************************************************
 
536
#
 
537
  get_entrypt () {
 
538
#
 
539
#   Set up the entry point based on the input argument
 
540
#
 
541
    if [ "$1" = "FORTRAN" ]; then
 
542
#
 
543
#   The gateway routine is in Fortran; use Fortran entry point
 
544
#
 
545
        MAPFILE='fexport.map'
 
546
    else
 
547
#
 
548
#   C, C++ and Ada entry points are the same
 
549
#
 
550
        MAPFILE=$entrypt'.map'
 
551
        ENTRYPOINT=$entrypt
 
552
    fi
 
553
  }
 
554
# end get_entrypt ()
 
555
#
 
556
#****************************************************************************
 
557
#
 
558
  determine_options_file () {
 
559
# Source options file (default is $OPTSFILE_NAME) and get values for the
 
560
# following local variables
 
561
 
562
#       MATLAB                  (MATLAB root directory)
 
563
#       CC                      (C compiler)
 
564
#       CFLAGS                  (C compiler options)
 
565
#       COPTIMFLAGS             (Compiler optimization flags)
 
566
#       CDEBUGFLAGS             (Compiler debugging flags)
 
567
#       CLIBS                   (C libraries for linking)
 
568
#       CXX                     (C++ compiler)
 
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)
 
583
#
 
584
# The search order for the options file is:
 
585
#
 
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)
 
590
#
 
591
#
 
592
    if [ -f ./$OPTSFILE_NAME ]; then
 
593
        SOURCE_DIR='.'
 
594
        SOURCE_DIReval=`pwd`
 
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
 
601
#
 
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
 
604
#       null will be used.
 
605
#
 
606
        SOURCE_DIR='$MATLAB/bin'
 
607
        SOURCE_DIReval=$MATLAB/bin
 
608
        OPTIONS_FILE="$MATLAB/bin/$OPTSFILE_NAME"
 
609
    else
 
610
        describe no_options_file >&2
 
611
        cleanup
 
612
        exit 1
 
613
    fi
 
614
  }
 
615
# end determine_options_file ()
 
616
#
 
617
#****************************************************************************
 
618
#
 
619
  get_arch () {
 
620
    if [ "$ARCH" = "" ]; then # No command line override given
 
621
        if [ ! -f $MATLAB/bin/util/arch.sh ]; then
 
622
            describe no_util_scripts >&2
 
623
            cleanup
 
624
            exit 1
 
625
        fi
 
626
        . $MATLAB/bin/util/arch.sh
 
627
        if [ "$Arch" = "unknown" ]; then
 
628
            describe unknown_architecture >&2
 
629
            cleanup
 
630
            exit 1
 
631
        fi
 
632
    else # Use command line override
 
633
        Arch=$ARCH
 
634
    fi
 
635
    if [ ! -f $MATLAB/bin/util/oscheck.sh ]; then
 
636
        describe no_util_scripts >&2
 
637
        cleanup
 
638
        exit 1
 
639
    fi
 
640
    if [ "$verbose" = "1" ]; then
 
641
        . $MATLAB/bin/util/oscheck.sh
 
642
        if [ "$oscheck_status" = "1" ]; then
 
643
            cleanup
 
644
            exit 1
 
645
        fi
 
646
    fi
 
647
  }
 
648
# end get_arch ()
 
649
#
 
650
#****************************************************************************
 
651
#
 
652
  eval_assignments () {
 
653
#
 
654
# eval command line overrides of argument variables, name=[def]
 
655
#
 
656
    eval "$cmd_line_overrides"
 
657
 
 
658
#
 
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
 
661
#
 
662
    LD="`eval echo $LD`"
 
663
    LDCXX="`eval echo $LDCXX`"
 
664
 
 
665
#
 
666
# If TEMP is defined be sure that TEMP has been created.
 
667
#
 
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
 
674
                cleanup
 
675
                exit 1
 
676
            fi
 
677
        fi
 
678
    fi
 
679
  }
 
680
# end eval_assignments ()
 
681
#
 
682
#****************************************************************************
 
683
#
 
684
  build_ada_s_function () {
 
685
#
 
686
#
 
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 "
 
690
#
 
691
#   Determine GNAT Compiler Version
 
692
#
 
693
    gnatVer=`gnatmake -v 2>&1 | grep GNATMAKE | awk '{print $2}'`
 
694
    ada_build_args="$ada_build_args GNAT_VER=$gnatVer "
 
695
#
 
696
    if [ "$debug" = "1" ]; then
 
697
        ada_build_args="$ada_build_args DEBUG=1 "
 
698
    fi
 
699
#
 
700
    if [ "$verbose" = "1" ]; then
 
701
        ada_build_args="$ada_build_args VERBOSE=1 "
 
702
    fi
 
703
#
 
704
    if [ "$OUTDIR" != "" ]; then
 
705
        ada_build_args="$ada_build_args OUTPUT_DIR=$OUTDIR "
 
706
    fi
 
707
#
 
708
    if [ "$include_dirs" != "" ]; then
 
709
        ada_build_args="$ada_build_args INCLUDES=\"$include_dirs\" "
 
710
    fi
 
711
    makefile="$MATLAB/simulink/ada/interface/gnat_unix.mk"
 
712
#
 
713
#   Verify that make exists and is gnu make
 
714
#
 
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
 
719
        cleanup
 
720
        exit 1
 
721
    fi
 
722
    echo " "
 
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
 
726
        echo " "
 
727
        echo "    $ada_build_cmd"
 
728
        echo " "
 
729
    fi
 
730
    eval "$ada_build_cmd"
 
731
    if [ $? -ne 0 ]; then
 
732
        describe ada_build_failure >&2
 
733
        cleanup
 
734
        exit 1
 
735
    else
 
736
        echo "### Successfully built Ada S-function $ada_sfcn"
 
737
        echo " "
 
738
    fi
 
739
  }
 
740
# end build_ada_s_function ()
 
741
#
 
742
#****************************************************************************
 
743
#
 
744
  error_check () {
 
745
#
 
746
#   Check for errors in calling syntax
 
747
#
 
748
    if [ "$argcheck" = "1" -a "$cfiles" != "1" ]; then
 
749
        stat="Argument checking not possible without C source files."
 
750
    fi
 
751
    if [ "$inlined" = "1" -a "$cfiles" != "1" ]; then
 
752
        stat="Inlining not possible without C source files."
 
753
    fi
 
754
    if [ "$argcheck" = "1" -a "$inlined" = "1" ]; then
 
755
        stat="Argument checking and inlining are mutually exclusive."
 
756
    fi
 
757
    if [ "$files" != "" -a "$cfiles" != "1" -a "$cxxfiles" != "1" -a "$ffiles" != "1" ]; then
 
758
        cfiles=1
 
759
        if [ "$verbose" != "" ]; then
 
760
            describe assuming_c_source
 
761
            if [ "$v7_compat" = "1" ]; then
 
762
                describe assuming_matlab_7
 
763
            fi
 
764
        fi
 
765
    fi
 
766
    if [ "$stat" != "OK" ]; then                  # An error occurred.
 
767
        if [ "$stat" != "" ]; then
 
768
            describe status >&2
 
769
        fi
 
770
        describe usage >&2
 
771
        cleanup
 
772
        exit 1
 
773
    fi
 
774
  }
 
775
# end error_check ()
 
776
#
 
777
#****************************************************************************
 
778
#
 
779
  get_name () {
 
780
#
 
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).
 
785
#
 
786
    if [ "$mex_file" != "" ]; then          # This case is if -output was used
 
787
        if [ "$compile_only" = "1" ]; then
 
788
            describe meaningless_output_flag
 
789
        fi
 
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" : '.*\/\(.*\)$'`
 
794
        fi
 
795
        ext=`expr "$mex_file" : ".*$LDEXTENSION$"`
 
796
        if [ "$ext" = "0" ]; then
 
797
            mex_file=$mex_file$LDEXTENSION
 
798
        fi
 
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
 
803
    fi
 
804
    if [ "$OUTDIR" != "" ]; then
 
805
        mex_file="$OUTDIR/$mex_file"
 
806
    fi
 
807
    mex_file=`smart_quote $mex_file`
 
808
  }
 
809
# end get_name ()
 
810
#
 
811
#****************************************************************************
 
812
#
 
813
  get_includes () {
 
814
#
 
815
#   Determine which include directories to specify
 
816
#
 
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`"
 
820
    fi
 
821
    if [ -d $MATLAB/codegen ]; then
 
822
        include_dirs="$include_dirs -I`smart_quote $MATLAB/codegen/external/common`"
 
823
    fi
 
824
  }
 
825
# end get_includes ()
 
826
#
 
827
#****************************************************************************
 
828
#
 
829
  compile () {
 
830
    trap "eval $abort; exit 1" 1 2 3 15
 
831
#
 
832
#   For each file, compile source files and add other files
 
833
#   to the list of link options.
 
834
#
 
835
    file="$1"
 
836
    if [ ! -f "$file" ]; then
 
837
        describe file_not_found >&2
 
838
        cleanup
 
839
        exit 1
 
840
    fi
 
841
#
 
842
# determine extension and basename
 
843
#
 
844
    ext=`expr "$file" : '\.*[^.].*\.\([^.]*\)$'`
 
845
    if [ "$ext" = "" ]; then
 
846
        ext=`expr "$file" : '\.*[^.].*\.\(so\)[.0-9]*$'`
 
847
    fi
 
848
    basename=`expr "//$file" : ".*/\(.*\)\.${ext}$" \| //$file : ".*/\(.*\)"`
 
849
#
 
850
    if [ "$TEMP" != "" -a "$compile_only" != "1" ]; then
 
851
        basename=$TEMP/$basename$$
 
852
    elif [ "$OUTDIR" != "" ]; then
 
853
        basename=$OUTDIR/$basename
 
854
    fi
 
855
 
 
856
    basename=`smart_quote $basename`
 
857
#
 
858
# Source file extensions: .c .C .cc .cxx .cpp .f .for .F .f90 .F90
 
859
#
 
860
    case "$ext" in
 
861
        c |cu ) # c source file.
 
862
#
 
863
# determine whether to optimize or debug
 
864
#
 
865
            if [ "$debug" != "1" ]; then
 
866
                flags="$COPTIMFLAGS"
 
867
            elif [ "$optimize" = "1" ]; then
 
868
                flags="$CDEBUGFLAGS $COPTIMFLAGS"
 
869
            else
 
870
                flags="$CDEBUGFLAGS"
 
871
            fi
 
872
#
 
873
# Determine final compile command for C source code.
 
874
#
 
875
            flags="-DMATLAB_MEX_FILE $CFLAGS $cc_flags $flags"
 
876
            compile_command="$CC -c $include_dirs $flags $file"
 
877
            ;;
 
878
        cc | cpp | cxx | C) # C++ source file
 
879
#
 
880
# determine whether to optimize or debug
 
881
#
 
882
            if [ "$debug" != "1" ]; then
 
883
                flags="$CXXOPTIMFLAGS"
 
884
            elif [ "$optimize" = "1" ]; then
 
885
                flags="$CXXDEBUGFLAGS $CXXOPTIMFLAGS"
 
886
            else
 
887
                flags="$CXXDEBUGFLAGS"
 
888
            fi
 
889
#
 
890
# Determine final compile command for C++ source code.
 
891
#
 
892
            flags="-DMATLAB_MEX_FILE $CXXFLAGS $cxx_flags $flags"
 
893
            compile_command="$CXX -c $include_dirs $flags $file"
 
894
            ;;   
 
895
        f | for | F | f90 | F90)            # Fortran source file.
 
896
#
 
897
# determine whether to optimize or debug
 
898
#
 
899
            if [ "$debug" != "1" ]; then
 
900
                flags="$FOPTIMFLAGS"
 
901
            elif [ "$optimize" = "1" ]; then
 
902
                flags="$FDEBUGFLAGS $FOPTIMFLAGS"
 
903
            else
 
904
                flags="$FDEBUGFLAGS"
 
905
            fi
 
906
#
 
907
# Determine final compile command for Fortran source code.
 
908
#
 
909
            flags="$FFLAGS $fc_flags $flags"
 
910
            compile_command="$FC -c $include_dirs $flags $file"
 
911
            ;;
 
912
        *)
 
913
#
 
914
# Object files: Don't need to do anything except add to compiled list
 
915
#
 
916
            objs="$objs $file"
 
917
            return 0
 
918
            ;;
 
919
    esac
 
920
#
 
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"
 
925
    fi
 
926
#
 
927
    if [ "$verbose" = "1" -o "$no_execute" = "true" ]; then
 
928
        describe compile_stage
 
929
    fi
 
930
#
 
931
    if [ "$no_execute" != "true" ]; then eval "$compile_command"; fi
 
932
    if [ $? -ne 0 ]; then
 
933
        describe failed_compile >&2
 
934
        cleanup
 
935
        exit 1
 
936
    fi
 
937
    if [ "$compile_only" != "1" ]; then
 
938
        files_to_remove="$files_to_remove $basename.o"
 
939
    fi
 
940
    objs="$objs $basename.o"
 
941
  }
 
942
# end compile ()
 
943
#
 
944
#****************************************************************************
 
945
#
 
946
  link () {
 
947
    trap "eval $abort; exit 1" 1 2 3 15
 
948
#
 
949
#   Link stage
 
950
#
 
951
    if [ "$cfiles" = "1" ]; then
 
952
        libs="$libs $CLIBS"
 
953
    fi
 
954
    if [ "$cxxfiles" = "1" ]; then
 
955
        libs="$libs $CXXLIBS"
 
956
    fi
 
957
    if [ "$ffiles" = "1" ]; then
 
958
        libs="$libs $FLIBS"
 
959
    fi
 
960
    libetc="$objs $libs"
 
961
 
 
962
#
 
963
# determine whether to optimize or debug
 
964
#
 
965
    if [ "$debug" != "1" ]; then
 
966
        LDFLAGS="$LDOPTIMFLAGS $LDFLAGS"
 
967
    elif [ "$optimize" = "1" ]; then
 
968
        LDFLAGS="$LDDEBUGFLAGS $LDOPTIMFLAGS $LDFLAGS"
 
969
    else
 
970
        LDFLAGS="$LDDEBUGFLAGS $LDFLAGS"
 
971
    fi
 
972
    if [ "$verbose" = "1" -o "$no_execute" = "true" ]; then
 
973
        describe link_stage
 
974
    fi
 
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
 
978
        cleanup
 
979
        exit 1
 
980
    fi
 
981
  }
 
982
# end link ()
 
983
  check_gcc()
 
984
  {
 
985
      perform_check=`echo $CC | awk '
 
986
      BEGIN{
 
987
         isGcc = "no"
 
988
      }
 
989
         /gcc$/{isGcc = "yes";exit 0 }
 
990
         /g\+\+$/{isGcc = "yes";exit 0 }
 
991
      END{
 
992
         print isGcc
 
993
      }
 
994
      '`
 
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 '
 
998
      BEGIN{
 
999
         allowable_versions[1]="glnx86,3.4.0,3.4.5"
 
1000
         allowable_versions[2]="glnxa64,3.4.0,3.4.5"
 
1001
      }
 
1002
      {
 
1003
         # Figure out what version of gcc we are dealing with. 
 
1004
         # Set version_number to the version of gcc.
 
1005
   
 
1006
         for (i = 1; i <= NF; i++)
 
1007
         {
 
1008
            if ($i ~ /^[0-9]+\./)
 
1009
            {
 
1010
               version_number=$i
 
1011
               exit 0 # This sends you to the end block 
 
1012
            }
 
1013
         }
 
1014
      }
 
1015
      END{
 
1016
   
 
1017
         # Find the array member of allowable_versions that corresponds to the
 
1018
         # architecture of the local machine.
 
1019
   
 
1020
         for(i = 1; i <= 2; i++)
 
1021
         {
 
1022
            # This uses the shell interpreter to substitute for arch.
 
1023
 
 
1024
            if (allowable_versions[i] ~ /^'"$Arch"'/)
 
1025
            {
 
1026
               string_of_test_versions = allowable_versions[i]
 
1027
               break
 
1028
            }
 
1029
         }
 
1030
   
 
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.
 
1034
 
 
1035
         if (string_of_test_versions == "")
 
1036
         {
 
1037
            exit 0;
 
1038
         }
 
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, ".")
 
1042
   
 
1043
         # Check if the version is smaller than the minimum version.  If it is,
 
1044
         # print a warning message and exit.
 
1045
 
 
1046
         for (i = 1; i <= size_of_min_version; i++)
 
1047
         {
 
1048
            if ( i > number_of_digits)
 
1049
            {
 
1050
               curr_num = 0
 
1051
            }
 
1052
            else
 
1053
            {
 
1054
               curr_num = gcc_version_array[i]
 
1055
            }
 
1056
            if (curr_num < min_version_array[i])
 
1057
            {
 
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]);
 
1059
               exit 0
 
1060
            }
 
1061
            if (curr_num > min_version_array[i])
 
1062
            {
 
1063
               break
 
1064
            }
 
1065
         }
 
1066
   
 
1067
         # If the version is not smaller than the minimum version, check if
 
1068
         # it is larger than the maximum version.
 
1069
 
 
1070
         size_of_max_version = split(versions[3], max_version_array, ".")
 
1071
         for (i = 1; i <= size_of_max_version; i++)
 
1072
         {
 
1073
            if (i > number_of_digits)
 
1074
            {
 
1075
               curr_num = 0
 
1076
            }
 
1077
            else
 
1078
            {
 
1079
               curr_num = gcc_version_array[i]
 
1080
            }
 
1081
            if (curr_num > max_version_array[i])
 
1082
            {
 
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]);
 
1084
               exit 0
 
1085
            }
 
1086
            if (curr_num < max_version_array[i])
 
1087
            {
 
1088
               exit 0
 
1089
            }
 
1090
         }
 
1091
      }'
 
1092
      fi
 
1093
}
 
1094
 
 
1095
#
 
1096
#****************************************************************************
 
1097
#
 
1098
# On sol2 add the C++ Template Repository to the remove list under the
 
1099
# right conditions.
 
1100
#
 
1101
# Sun uses a template repository to store template instances between
 
1102
# separate compilations so that template instances are compiled only when
 
1103
# necessary.
 
1104
#
 
1105
# It is controlled by the directory of the output file.
 
1106
#
 
1107
# Note: if TEMP and OUTDIR are both defined TEMP takes precedence.
 
1108
#
 
1109
# Necessary conditions for deletion:
 
1110
#
 
1111
#       1. Must compile at least one C++ file. ($cxxfiles = "1")
 
1112
#       2. Must link.                          ($compile_only != "!")
 
1113
#
 
1114
# case 1: SUNWS_CACHE_NAME is undefined
 
1115
#
 
1116
#       ./SunWS_cache             - No TEMP or OUTDIR defined
 
1117
#       $TEMP/SunWS_cache         - TEMP defined
 
1118
#       $OUTDIR/SunWS_cache       - TEMP not defined but OUTDIR defined
 
1119
#
 
1120
# case 2: SUNWS_CACHE_NAME is defined
 
1121
#
 
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
 
1125
#
 
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.
 
1129
#
 
1130
        if [ "$cxxfiles" = "1" -a "$compile_only" != "1" ]; then
 
1131
            if [ "$SUNWS_CACHE_NAME" != "" ]; then
 
1132
                cache_name=$SUNWS_CACHE_NAME
 
1133
            else
 
1134
                cache_name=SunWS_cache
 
1135
            fi
 
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"
 
1140
            else
 
1141
                files_to_remove="$files_to_remove $OUTDIR/$cache_name"
 
1142
            fi
 
1143
        fi
 
1144
  }
 
1145
#****************************************************************************
 
1146
#
 
1147
# Main routine
 
1148
#
 
1149
#
 
1150
#  Initialize some variables
 
1151
#
 
1152
    OPTSFILE_NAME='mexopts.sh'
 
1153
#
 
1154
    MEX_INCLUDE_DIR='extern/include'
 
1155
#
 
1156
    stat="OK"
 
1157
#
 
1158
    ARCH=
 
1159
    Arch='Undetermined'
 
1160
    verbose=0
 
1161
 
 
1162
    # Define $MATLAB if it's not defined. 
 
1163
    if [ ! "$MATLAB" ]; then            # If no MATLAB='' was used
 
1164
        get_root_dir $arg0_
 
1165
    fi
 
1166
 
 
1167
#
 
1168
#  Use a C entry point by default
 
1169
#
 
1170
    gateway_lang=C
 
1171
    entrypt=mexFunction
 
1172
#
 
1173
#   Current default is V7 (32-bit)
 
1174
    v7_compat=1
 
1175
 
 
1176
    arg_count=$#
 
1177
    cmd_line_overrides=":"
 
1178
    while [ "$stat" = "OK" -a  $# -gt 0 ]; do
 
1179
#
 
1180
# Parse input arguments.  The routine may need the next two arguments,
 
1181
# as in -f optionsfile and -o mexfilename.
 
1182
#
 
1183
        case "$1" in
 
1184
            -compatibleArrayDims)
 
1185
                v7_compat=1
 
1186
                ;;
 
1187
            -largeArrayDims)
 
1188
                v7_compat=0
 
1189
                ;;
 
1190
            -argcheck)
 
1191
                argcheck=1
 
1192
                cc_flags="$cc_flags -DARGCHECK"
 
1193
                cxx_flags="$cxx_flags -DARGCHECK"
 
1194
                ;;
 
1195
            -c)
 
1196
                compile_only=1
 
1197
                ;;
 
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_]*[=\#]\(.*\)$'`
 
1202
                
 
1203
                if [ "$mid" != "" ]; then
 
1204
                    mid="="
 
1205
                fi
 
1206
 
 
1207
                cc_flags="$cc_flags $lhs$mid$rhs"
 
1208
                cxx_flags="$cxx_flags $lhs$mid$rhs"
 
1209
                fc_flags="$fc_flags $lhs$mid$rhs"
 
1210
 
 
1211
                if [ "$lhs" = "-DV5_COMPAT" ]; then
 
1212
                    stat="Please use -V5 rather than directly passing"
 
1213
                    stat="$stat -DV5_COMPAT."
 
1214
                fi
 
1215
                if [ "$lhs" = "-DARRAY_ACCESS_INLINING" ]; then
 
1216
                    stat="Please use -inline rather than directly passing"
 
1217
                    stat="$stat -DARRAY_ACCESS_INLINING."
 
1218
                fi
 
1219
                ;;
 
1220
            -U*)                         # Compiler flags.
 
1221
                cc_flags="$cc_flags $1"
 
1222
                cxx_flags="$cxx_flags $1"
 
1223
                fc_flags="$fc_flags $1"
 
1224
                ;;
 
1225
            -I* | -isystem*)             # Include directories
 
1226
                include_dirs="$include_dirs `smart_quote $1`"
 
1227
                ;;
 
1228
            -f)
 
1229
                if [ -f "$2" ]; then
 
1230
                    OPTIONS_FILE="$2"
 
1231
                    SOURCE_DIR='none'
 
1232
                else
 
1233
                    describe invalid_options_file >& 2
 
1234
                    cleanup
 
1235
                    exit 1
 
1236
                fi
 
1237
                shift
 
1238
                ;;
 
1239
            -cxx)
 
1240
                cxxfiles=1
 
1241
                gateway_lang=C
 
1242
                ;;    
 
1243
            -fortran)
 
1244
                ffiles=1
 
1245
                gateway_lang=FORTRAN
 
1246
                ;;
 
1247
            -[g]*)                          # Use debugging flags.
 
1248
                debug=1
 
1249
                ;;
 
1250
            -h | -help)                     # -help: Help option.
 
1251
                printHelp
 
1252
                cleanup
 
1253
                exit 0
 
1254
                ;;
 
1255
            -inline)
 
1256
                cc_flags="$cc_flags -DARRAY_ACCESS_INLINING"
 
1257
                cxx_flags="$cxx_flags -DARRAY_ACCESS_INLINING"
 
1258
                inlined=1
 
1259
                ;;
 
1260
            -[Ll]*)
 
1261
                libs="$libs $1"
 
1262
                ;;
 
1263
            -Wl* | -R*)                     # allow other linker options
 
1264
                libs="$libs $1"
 
1265
                ;;
 
1266
            -n)                             # output name
 
1267
                no_execute="true"
 
1268
                ;;
 
1269
            -nohg)                          # ignored for compatibility with mbuild
 
1270
                ;;
 
1271
            -o | -output)                   # mexfile name
 
1272
                mex_file=$2
 
1273
                shift
 
1274
                ;;
 
1275
            -outdir)                        # output directory
 
1276
                if [ $# -lt 2 ]; then
 
1277
                    describe usage >&2
 
1278
                    cleanup
 
1279
                    exit 1
 
1280
                fi
 
1281
                OUTDIR=$2
 
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
 
1287
                        cleanup
 
1288
                        exit 1
 
1289
                    fi
 
1290
                fi
 
1291
                shift
 
1292
                ;;
 
1293
            -O)                             # Use optimization flags.
 
1294
                optimize=1
 
1295
                ;;
 
1296
            -setup)
 
1297
                if [ $arg_count -ne 2 -a $arg_count -ne 1 ]; then
 
1298
                    describe usage >&2
 
1299
                    cleanup
 
1300
                    exit 1
 
1301
                else
 
1302
                    SETUP_OPTIONS_FILE=$2
 
1303
                    TMW_ROOT=$MATLAB
 
1304
                    #
 
1305
                    # source the setup_options_file finction declaration  
 
1306
                    #
 
1307
                    . $MATLAB/bin/optsetup.sh
 
1308
                    #
 
1309
                    setup_options_file $SETUP_OPTIONS_FILE
 
1310
                    cleanup
 
1311
                    exit 0
 
1312
                fi
 
1313
                ;;
 
1314
            -silent)            # really not verbose - undocumented
 
1315
                verbose=
 
1316
                ;;
 
1317
            -v)
 
1318
                verbose=1
 
1319
                ;;
 
1320
            -v3.5)
 
1321
                stat="The -v3.5 option is no longer supported."
 
1322
                ;;
 
1323
            -v4)
 
1324
                stat="The -v4 option is no longer supported."
 
1325
                ;;
 
1326
            -V5)
 
1327
                cc_flags="$cc_flags -DV5_COMPAT"
 
1328
                cxx_flags="$cxx_flags -DV5_COMPAT"
 
1329
                ;;
 
1330
            -ada)
 
1331
                gateway_lang=ADA
 
1332
                if [ -f "$2" ]; then
 
1333
                    ada_sfcn=$2
 
1334
                else
 
1335
                    describe invalid_ada_flag >& 2
 
1336
                    cleanup
 
1337
                    exit 1
 
1338
                fi
 
1339
                shift
 
1340
                ;;
 
1341
            -entrypt)
 
1342
                if [ "$2" != "mexFunction" -a "$2" != "mexLibrary" ]; then
 
1343
                     stat="-entrypt argument must be either 'mexFunction' or 'mexLibrary'"
 
1344
                fi
 
1345
                entrypt=$2
 
1346
                shift
 
1347
                ;;
 
1348
            -*)
 
1349
                check_archlist argument=$1 noprint
 
1350
                if [ "$ARCH" = "" ]; then
 
1351
                    stat="$1 not a valid option."
 
1352
                fi
 
1353
                ;;
 
1354
            ARCH[=\#]*)
 
1355
                rhs=`expr "$1" : '[a-zA-Z0-9_]*[=\#]\(.*\)$'`
 
1356
                ARCH="`eval echo $rhs`"
 
1357
                ;;
 
1358
            MATLAB[=\#]*)
 
1359
                mlrhs=`expr "$1" : '[a-zA-Z0-9_]*[=\#]\(.*\)$'`
 
1360
                MATLAB="`eval echo $mlrhs`"
 
1361
                ;;
 
1362
            *[=\#]*)
 
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"'"'
 
1366
                ;;
 
1367
            *.c | *.cu) # c source file.
 
1368
                cfiles='1'
 
1369
                files="$files $1"
 
1370
                ;;
 
1371
            *.C | *.cc | *.cpp | *.cxx) # C++ source file.
 
1372
                cxxfiles='1'
 
1373
                files="$files $1"
 
1374
                ;;
 
1375
            *.f | *.for | *.F | *.f90 | *.F90)      # FORTRAN source file.
 
1376
                if [ "$ffiles" != "1" -a "$cfiles" != "1" -a "$cxxfiles" != "1" ]; then
 
1377
                    gateway_lang=FORTRAN
 
1378
                fi
 
1379
                ffiles='1'
 
1380
                files="$files $1"
 
1381
                ;;
 
1382
            *.o)                              # object files
 
1383
                files="$files $1"
 
1384
                ;;
 
1385
            *)                                # other files
 
1386
                libs="$libs `smart_quote $1`"
 
1387
                ;;
 
1388
        esac
 
1389
    shift
 
1390
    done
 
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"
 
1395
    fi  
 
1396
    if [ $# -eq 0 -a "$files" = "" -a "$stat" = "OK" ]; then
 
1397
        stat="no file name given."
 
1398
    fi
 
1399
    if [ "$gateway_lang" = "FORTRAN" -a "$entrypt" != "mexFunction" ]; then
 
1400
        describe fortran_cannot_change_entrypt
 
1401
        entrypt=mexFunction
 
1402
    fi
 
1403
#
 
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.)
 
1407
#
 
1408
    if [ ! "$OPTIONS_FILE" ]; then      # If no -f optionsfile was used
 
1409
        determine_options_file
 
1410
    fi
 
1411
#
 
1412
    . $OPTIONS_FILE                     # Source file to determine $MATLAB
 
1413
    get_arch                            # Call $MATLAB/bin/util/arch.sh
 
1414
#
 
1415
    get_entrypt $gateway_lang           # Determine MEX-file entry pt
 
1416
#
 
1417
    if [ "$ffiles" = "1" ]; then
 
1418
        COMPILER='$FC'
 
1419
    elif [ "$cxxfiles" = "1" ]; then
 
1420
        COMPILER='$CXX'
 
1421
    else
 
1422
        COMPILER='$CC'
 
1423
    fi
 
1424
#
 
1425
    . $OPTIONS_FILE                     # Source options file
 
1426
#
 
1427
    eval_assignments                    # Evaluate VAR=value arguments
 
1428
 
 
1429
    get_name $files                     # Determine MEX-file name
 
1430
 
 
1431
#
 
1432
#   Ada
 
1433
#
 
1434
    if [ "$gateway_lang" = "ADA" ]; then
 
1435
        build_ada_s_function
 
1436
        cleanup
 
1437
        exit 0
 
1438
    fi
 
1439
#
 
1440
    if [ "$verbose" = "1" ]; then
 
1441
        describe final_options
 
1442
    fi
 
1443
#
 
1444
    error_check                         # Check calling syntax errors
 
1445
#
 
1446
    get_includes                        # Determine include directories
 
1447
#
 
1448
    if [ "$compile_only" != "1" ]; then
 
1449
        if [ "$gateway_lang" = "C" ]; then
 
1450
            files="$files $MATLAB/extern/src/mexversion.c"
 
1451
        else
 
1452
            files="$files $MATLAB/extern/lib/$Arch/version4.o"
 
1453
        fi
 
1454
    fi
 
1455
    if [ "$argcheck" = "1" ]; then
 
1456
        files="$files $MATLAB/extern/src/mwdebug.c"
 
1457
    fi
 
1458
#
 
1459
# On sol2 add the C++ template repository to the remove list under
 
1460
# the right conditions.
 
1461
#
 
1462
    if [ "$Arch" = "sol2" ]; then
 
1463
        add_template_to_rmlist
 
1464
    fi
 
1465
# Check the version of gcc if we are using gcc to warn about possible
 
1466
# version conflicts
 
1467
    check_gcc
 
1468
#
 
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().
 
1473
#
 
1474
    set $files
 
1475
    for file in $*
 
1476
    do
 
1477
        compile $file                   # Process each file in list
 
1478
    done
 
1479
#
 
1480
    if [ "$compile_only" != "1" ]; then
 
1481
        link                            # Perform linking
 
1482
 
 
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 
 
1486
        #
 
1487
        # POSTLINK_CMDS='$POSTLINK_CMDS;my_command'
 
1488
        #
 
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
 
1494
            fi
 
1495
            if [ "$no_execute" != "true" ]; then 
 
1496
                eval "$POSTLINK_CMDS"; 
 
1497
            fi
 
1498
        fi
 
1499
    fi
 
1500
#
 
1501
    cleanup
 
1502
    exit 0
 
1503
#
 
1504
#****************************************************************************