I am building a system that intensively uses MEX files to
optimize for speed. I have been storing all the MEX commands
in a Makefile.m so, when I need to recompile, I can just invoke
>> Makefile
In the command window.
A problem arises however, when the amount of MEX files to be
compiled is large. I was searching for a way of checking the
timestamp of the produced mex* (mexmaci in my case) against
the *.cpp file that generate it.
I searched the doc but the only element regarding timestamp
that I found was:
>> h = dir();
>> h.timestamp
This would allow me to create a .m based Makefile but with a
bit of scripting work to do. Do you have any other suggestion?
"Andrea Tagliasacchi" <ata2@nospam.cs.sfu.ca> wrote in
message <fq4hfq$ikj$1@fred.mathworks.com>...
> Hello there,
>
> I am building a system that intensively uses MEX files to
> optimize for speed. I have been storing all the MEX commands
> in a Makefile.m so, when I need to recompile, I can just
invoke
>
> >> Makefile
>
> In the command window.
>
> A problem arises however, when the amount of MEX files to be
> compiled is large. I was searching for a way of checking the
> timestamp of the produced mex* (mexmaci in my case) against
> the *.cpp file that generate it.
>
> I searched the doc but the only element regarding timestamp
> that I found was:
>
> >> h = dir();
> >> h.timestamp
>
> This would allow me to create a .m based Makefile but with a
> bit of scripting work to do. Do you have any other suggestion?
>
> Thanks, Andrea
>
>
I have built the following simple script that represents a
Makefile. It works perfectly on my machine, but, as I well
know is dependent on the architecture and folder used for
the make. Also instead of common commands like:
p.s. they should really allow file attachments in here :)
================= CODE BEGINS HERE =====================
% [ Copyright ? 2007 Andrea Tagliasacchi - ata2 at cs dot
sfu dot ca - All rights reserved ]
%
% SYNOPSIS
% - PWD = mesh_compute_pair_wise_distances( M, selection_par )
%
% DESCRIPTION
% - MAKEFILE that compiles all the MEX function in the util
folder
%
% INPUT
% - TYPE:
% 'all': builds all the files in the folder
% 'clean': remove all mex compiled files from the folder
%
function Makefile( TYPE )
% if nothing is specified make all
if ~exist( 'TYPE','var' )
TYPE = 'all';
end
% clear screen
clc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% MAKE ALL %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if strcmp( TYPE, 'all' )
cpp_files = dir('./util/*.cpp');
for i=1:length( cpp_files )
% extract name
cpp_file = cpp_files(i);
cpp_filename = cpp_file.name;
"Andrea Tagliasacchi" <ata2@nospam.cs.sfu.ca> wrote in message
news:fq4kmu$ai1$1@fred.mathworks.com...
> "Andrea Tagliasacchi" <ata2@nospam.cs.sfu.ca> wrote in
> message <fq4hfq$ikj$1@fred.mathworks.com>...
>> Hello there,
>>
>> I am building a system that intensively uses MEX files to
>> optimize for speed. I have been storing all the MEX commands
>> in a Makefile.m so, when I need to recompile, I can just
> invoke
>>
>> >> Makefile
>>
>> In the command window.
>>
>> A problem arises however, when the amount of MEX files to be
>> compiled is large. I was searching for a way of checking the
>> timestamp of the produced mex* (mexmaci in my case) against
>> the *.cpp file that generate it.
>>
>> I searched the doc but the only element regarding timestamp
>> that I found was:
>>
>> >> h = dir();
>> >> h.timestamp
>>
>> This would allow me to create a .m based Makefile but with a
>> bit of scripting work to do. Do you have any other suggestion?
>>
>> Thanks, Andrea
>>
>>
>
> I have built the following simple script that represents a
> Makefile. It works perfectly on my machine, but, as I well
> know is dependent on the architecture and folder used for
> the make. Also instead of common commands like:
>
> make
> make all
> make clean
>
> it needs something like:
>
>>> Makefile
>>> Makefile('all')
>>> Makefile('clean')
Through command-function duality, "make clean" is equivalent to
"make('clean')".
> Any suggestion is welcome.
>
> Cheers, Andrea.
>
>
> p.s. they should really allow file attachments in here :)
The standard procedure for Usenet newsgroups that do not include the word
"binary" in their names, like comp.soft-sys.matlab, is text only -- and if
you're going to post a text attachment, why not just include it in your
message?
> ================= CODE BEGINS HERE =====================
> % [ Copyright ? 2007 Andrea Tagliasacchi - ata2 at cs dot
> sfu dot ca - All rights reserved ]
> %
> % SYNOPSIS
> % - PWD = mesh_compute_pair_wise_distances( M, selection_par )
Did you perhaps copy and paste the M-file help from another function and
forget to modify it? :)
> %
> % DESCRIPTION
> % - MAKEFILE that compiles all the MEX function in the util
> folder
> %
> % INPUT
> % - TYPE:
> % 'all': builds all the files in the folder
> % 'clean': remove all mex compiled files from the folder
> %
> function Makefile( TYPE )
>
> % if nothing is specified make all
> if ~exist( 'TYPE','var' )
> TYPE = 'all';
> end
> This would allow me to create a .m based Makefile but with a
> bit of scripting work to do. Do you have any other suggestion?
Why do you want to reinvent the wheel? make(1) provides all the
facilities you want.
I utilize the GNU build system (Autoconf, Automake, Libtool) for
maintaining my projects. Together with a proper cross-compilation
environment I'm able to rebuild a complete toolbox (approximately
100 MEX-files) for various Matlab versions (6.1, 6.5.1, and 7.1)
and Matlab architectures (Windows, Linux, HP-UX, and Solaris) by
just typing
> Why do you want to reinvent the wheel? make(1) provides
all the
> facilities you want.
>
> I utilize the GNU build system (Autoconf, Automake,
Libtool) for
> maintaining my projects. Together with a proper
cross-compilation
> environment I'm able to rebuild a complete toolbox
(approximately
> 100 MEX-files) for various Matlab versions (6.1, 6.5.1,
and 7.1)
> and Matlab architectures (Windows, Linux, HP-UX, and
Solaris) by
> just typing
>
> $ make world
Hello Ralph,
make would have to be used outside Matlab though. What I
wanted was something integrated inside Matlab, for which
users wouldn't have to access an external shell. Consider
also that I am not distributing binaries, but source, and
users need to be able to easily compile it.
"Andrea Tagliasacchi" <ata2@nospam.cs.sfu.ca> wrote in
message <fq7mrp$ekq$1@fred.mathworks.com>...
> > Why do you want to reinvent the wheel? make(1) provides
> all the
> > facilities you want.
> >
> > I utilize the GNU build system (Autoconf, Automake,
> Libtool) for
> > maintaining my projects. Together with a proper
> cross-compilation
> > environment I'm able to rebuild a complete toolbox
> (approximately
> > 100 MEX-files) for various Matlab versions (6.1, 6.5.1,
> and 7.1)
> > and Matlab architectures (Windows, Linux, HP-UX, and
> Solaris) by
> > just typing
> >
> > $ make world
>
> Hello Ralph,
>
> make would have to be used outside Matlab though. What I
> wanted was something integrated inside Matlab, for which
> users wouldn't have to access an external shell. Consider
> also that I am not distributing binaries, but source, and
> users need to be able to easily compile it.
>
> --
> Andrea
Try taking a look at the cs_make.m file in CSparse; it
checks the timestamps of the files and only compiles what's
needed, just like "make". It doesn't use the "make"
Unix/Linux/GNU/... command, so you can type "cs_make" on
Windows without requiring the user to install Cygwin.
> Try taking a look at the cs_make.m file in CSparse; it
> checks the timestamps of the files and only compiles what's
> needed, just like "make". It doesn't use the "make"
> Unix/Linux/GNU/... command, so you can type "cs_make" on
> Windows without requiring the user to install Cygwin.
Thanks! This is exactly what I meant :)
Unfortunately I tried to locate it in my system and I don't
have that file :(
> Thanks! This is exactly what I meant :)
> Unfortunately I tried to locate it in my system and I don't
> have that file :(
Try these. I don't use them for coding up build scripts,
therefore I didn't think at it in the first place. Usage:
if make(['foo', mexext], 'foo.c')
mex foo.c
end
% Copyright (C) 2007, 2008 Ralph Schleicher
% This program is free software; you can redistribute it and/or
% modify it under the terms of the GNU General Public License as
% published by the Free Software Foundation; either version 2,
% or (at your option) any later version.
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
% You should have received a copy of the GNU General Public License
% along with this program; see the file COPYING. If not, write to
% the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
% Boston, MA 02111-1307, USA.
% As a special exception, Ralph Schleicher gives permission to link
% the code of this program with MATLAB from The Mathworks, Inc. (or
% with modified versions of MATLAB that use the same license as
% MATLAB), and distribute linked combinations including the two.
% You must obey the GNU General Public License in all respects for
% all of the code used other than with MATLAB. If you modify this
% file, you may extend this exception to your version of the file,
% but you are not obligated to do so. If you do not wish to do so,
% delete this exception statement from your version.
% make
%
% p = make(target, ...)
%
% Return non-zero if a file is out of date.
%
% First argument TARGET is the dependent file.
% Remaining arguments are the required files.
function p = make(target, varargin)
% Dependencies.
if nargin == 2
dep = varargin{1};
if ischar(dep)
dep = cellstr(dep);
end
else
dep = varargin;
end
try
% Dependent file modification times.
t1 = mtime(target);
% Rebuild if the newest required file is newer than
% the oldest dependent file.
if isempty(dep)
p = 0;
else
p = max(t0) > min(t1);
end
catch
p = 1;
end
% mtime
%
% t = mtime(filename)
%
% Return the file modification time as a serial date number.
%
% Argument FILENAME is either a string, a character array, or a cell
% array of strings.
function t = mtime(filename)
if ischar(filename)
filename = cellstr(filename);
end
t = zeros(size(filename));
for i = 1:numel(filename)
dirent = dir(filename{i});
if isempty(dirent)
error(sprintf('%s: no such file or directory', filename{i}));
end
t(i) = datenum(dirent.date);
end
Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central. Read the complete Disclaimer prior to use.