Boost logo

Boost-Build :

From: ianfasel (ianfasel_at_[hidden])
Date: 2005-11-15 07:46:46


Hi all,
I'm trying to improve the mex generator you helped me with in
http://groups.yahoo.com/group/jamboost/message/7327
This generator turns CPP files into MEX files (mex is actually just a shellscript that exports
some environment variables based on platform, then invokes gcc to create a special
shared library). My problem is if a mex target depends on a library, the <includes>
propagated from the library appear correct, but the other features don't seem to have
been propagated. For example, suppose my Jamfile has:

use-project /b : ../src ;
mex a_mex : a_mex.cpp : <library>/b//b ;

Assuming that b has a Jamfile in the directory ../src like this:

project b : usage-requirements <include>. ;
lib b : b.cpp ;

The command that finally gets sent to the shell is:
$MATLAB/bin/mex -O a_mex.cpp -DMATLAB -I../src -I$MATLAB/extern/include-L
$MATLAB/extern/lib/mac -lmat -lm -o bin/darwin-3.3/release/a_mex.mexmac

so it seems that the linkpath and libraries all are empty, and aren't getting propagated.
I'm not sure where to go from here.

If it would help for me to explain mex a bit more I'd be glad to. The mex script is already
trying to achieve some platform independence, so maybe it's not really possible to do what
I'm trying to do without essentially re-creating those mex scripts (but I'll do precisely that
if I need to :-).

Many thanks for any help!
-Ian Fasel

# Generator for MATLAB mex files. We assume the user has an environment
# variable $MATLAB for their installation. Normal mex usage would be like this:
#
# MEX [option1 ... optionN] sourcefile1 [... sourcefileN]
# [objectfile1 ... objectfileN] [libraryfile1 ... libraryfileN]
#
#

import os ;
import type ;

# Matlab adds an extension to the .mex file and uses it in the path for headers, etc.
switch [ os.name ]
{
# ... abbreviated for space...
case MACOSX :
{
MEXEXTEN = mexmac ;
MEXLIBPATH = mac ;
}
case * :
{
MEXEXTEN = mexglx ;
MEXLIBPATH = glnx86 ;
}
}

type.register MEX : $(MEXEXTEN) : ;

import generators ;
generators.register-composing mex.mex : CPP LIB : MEX ;

# I think all this stuff is slightly (or completely) wrong, as it doesn't seem to work right.
import toolset : flags ;
flags mex.mex OPTIONS <debug-symbols>on : -g ;
flags mex.mex OPTIONS <optimization>off : ;
flags mex.mex OPTIONS <optimization>speed : -O ;
flags mex.mex LINKPATH <library-path> ;
flags mex.mex INCLUDES <include> ;
flags mex.mex FINDLIBS-ST <find-static-library> ;
flags mex.mex FINDLIBS-SA <find-shared-library> ;
flags mex.mex LIBRARIES <library-file> ;

actions mex
{
$MATLAB/bin/mex $(OPTIONS) $(>) -I$(INCLUDES) -I$MATLAB/extern/include -L$
(LINKPATH) -L$MATLAB/extern/lib/$(MEXLIBPATH) -l$(FINDLIBS-SA) -l$(FINDLIBS-ST) -l$
(LIBRARIES) -lmat -lm -o $(<)
}


Boost-Build list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk