Home > matlab > makehelper.m

makehelper

PURPOSE ^

This function is a helper file for "make", "makeocp", "makesimulation" and

SYNOPSIS ^

function [ ] = makehelper( type, optmake, varargin )

DESCRIPTION ^

  This function is a helper file for "make", "makeocp", "makesimulation" and
  "makeintegrators". See help of these files and use these files directly
  instead of this one.
 
  see also make, makeocp, makesimulation, makeintegrators

  Licence:
    This file is part of ACADO Toolkit  - (http://www.acadotoolkit.org/)

    ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
    Copyright (C) 2008-2009 by Boris Houska and Hans Joachim Ferreau, K.U.Leuven.
    Developed within the Optimization in Engineering Center (OPTEC) under
    supervision of Moritz Diehl. All rights reserved.

    ACADO Toolkit is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 3 of the License, or (at your option) any later version.

    ACADO Toolkit 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
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with ACADO Toolkit; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

    Author: David Ariens
    Date: 2009

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [ ] = makehelper( type, optmake, varargin )
0002 %  This function is a helper file for "make", "makeocp", "makesimulation" and
0003 %  "makeintegrators". See help of these files and use these files directly
0004 %  instead of this one.
0005 %
0006 %  see also make, makeocp, makesimulation, makeintegrators
0007 %
0008 %  Licence:
0009 %    This file is part of ACADO Toolkit  - (http://www.acadotoolkit.org/)
0010 %
0011 %    ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
0012 %    Copyright (C) 2008-2009 by Boris Houska and Hans Joachim Ferreau, K.U.Leuven.
0013 %    Developed within the Optimization in Engineering Center (OPTEC) under
0014 %    supervision of Moritz Diehl. All rights reserved.
0015 %
0016 %    ACADO Toolkit is free software; you can redistribute it and/or
0017 %    modify it under the terms of the GNU Lesser General Public
0018 %    License as published by the Free Software Foundation; either
0019 %    version 3 of the License, or (at your option) any later version.
0020 %
0021 %    ACADO Toolkit is distributed in the hope that it will be useful,
0022 %    but WITHOUT ANY WARRANTY; without even the implied warranty of
0023 %    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0024 %    Lesser General Public License for more details.
0025 %
0026 %    You should have received a copy of the GNU Lesser General Public
0027 %    License along with ACADO Toolkit; if not, write to the Free Software
0028 %    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
0029 %
0030 %    Author: David Ariens
0031 %    Date: 2009
0032 %
0033 
0034 
0035 %% SETTINGS
0036     if (nargin == 2)
0037         DEBUG = 0;
0038         CLEANUP = 0;
0039         MAKE = 1;
0040         FORCE = 0;
0041         
0042     elseif (nargin == 3 && length(varargin{1}) == 1 && strcmp(varargin{1}{1}, 'clean'))
0043         DEBUG = 0;
0044         CLEANUP = 1;
0045         MAKE = 0;
0046         FORCE = 0;
0047         
0048     elseif (nargin == 3 && length(varargin{1}) == 1 && strcmp(varargin{1}{1}, 'debug'))
0049         DEBUG = 1;
0050         CLEANUP = 0;
0051         MAKE = 1;
0052         FORCE = 0;
0053         
0054     elseif (nargin == 3 && length(varargin{1}) == 1 && strcmp(varargin{1}{1}, 'all'))
0055         DEBUG = 0;
0056         CLEANUP = 0;
0057         MAKE = 1;
0058         FORCE = 1;
0059         
0060     elseif (nargin == 3 && length(varargin{1}) == 2 && strcmp(varargin{1}{1}, 'all') && strcmp(varargin{1}{2}, 'debug'))
0061         DEBUG = 1;
0062         CLEANUP = 0;
0063         MAKE = 1;
0064         FORCE = 1;
0065         
0066     elseif (nargin == 3 && length(varargin{1}) == 2 && strcmp(varargin{1}{1}, 'clean') && strcmp(varargin{1}{2}, 'all'))
0067         DEBUG = 0;
0068         CLEANUP = 1;
0069         MAKE = 1;
0070         FORCE = 1;
0071         
0072     elseif (nargin == 3 && length(varargin{1}) == 3 && strcmp(varargin{1}{1}, 'clean') && strcmp(varargin{1}{2}, 'all') && strcmp(varargin{1}{3}, 'debug'))
0073         DEBUG = 1;
0074         CLEANUP = 1;
0075         MAKE = 1;
0076         FORCE = 1;
0077     
0078     else
0079         disp( 'Could not understand command. Run "help make".' );
0080         return;       
0081     end
0082     
0083 
0084     addpath(genpath([pwd filesep 'shared']));       % ADD SHARED ASSETS TO PATH
0085  
0086         
0087     % DEBUG WARNINGS
0088     if ( DEBUG == 1 && ~ispc )
0089         disp( 'WARNING: Debug mode has been designed for use with gcc only!' );
0090         disp( 'More information about how to debug: see doc/debugging.txt' );
0091     elseif (DEBUG == 1 && ispc)
0092         disp( 'More information about how to debug: see doc/debugging.txt' );
0093     end
0094 
0095    
0096 
0097     % CONSISTENCY CHECK:
0098     if ( exist( [pwd, '/make.m'],'file' ) == 0 )
0099          disp( 'ERROR: Run this make script directly within the directory' );
0100          disp( '       <ACADOtoolkit-inst-dir>/interfaces/matlab/, please.' );
0101          return;
0102     end
0103 
0104 
0105     
0106     % RUN THE AUTOMATIC MODEL DETECTION:
0107     % (CREATES THE FILE: integrator/model_include.hpp)
0108     automatic_model_detection_integrator();
0109 
0110     warning off all   
0111     
0112     % GET FILES
0113     [HEADER_PATHS, SRC, BIN, BINFOLDER, SRCMEX, BINMEX, BINFOLDERMEX] = objects(type);
0114     BIN_FOLDER = 'bin/';
0115     IFLAGS    = [ '-I. ', HEADER_PATHS           ];
0116     
0117     
0118     %COMPILER FLAGS
0119     if (ispc)
0120         % Microsoft Visual C++ (express) compiler
0121         CPPFLAGS  = [ IFLAGS, ' -D__cpluplus -D__MATLAB__ -Dsnprintf=_snprintf -Dround=acadoRound -O ' ];    
0122     else
0123         % Other compilers
0124         CPPFLAGS  = [ IFLAGS, ' -D__cpluplus -D__MATLAB__ -O ' ];
0125     end
0126     counter = 0 ;
0127     
0128     
0129     % DEBUG FLAGS
0130     DEBUGFLAGS = '';
0131     if ( DEBUG == 1 )
0132        if (ispc)
0133            DEBUGFLAGS = '-g';
0134        else
0135            DEBUGFLAGS = '-g CXXDEBUGFLAGS=''$CXXDEBUGFLAGS -Wall -pedantic -Wfloat-equal -Wshadow';
0136        end
0137     end
0138           
0139     
0140     % Extensions
0141     if (ispc)
0142         ext = '.obj' ;
0143     else
0144         ext = '.o' ;
0145     end
0146         
0147     extmex = ['.' mexext] ;  %mexext is a buildin function
0148     
0149     
0150     
0151 %% CLEANUP
0152     if (CLEANUP)
0153         fprintf (1, 'Cleaning up all ACADO files... \n') ;
0154         delete([BIN_FOLDER 'qpOASES' filesep '*' ext]);
0155         delete([BIN_FOLDER 'src' filesep '*' ext]);
0156         delete([BIN_FOLDER 'csparse' filesep '*' ext]);
0157         delete(['integrator' filesep '*' extmex '*']);
0158         %delete(['acado' filesep '*' extmex '*']);
0159         
0160         fprintf (1, 'Removing ACADO folders from Matlab path... \n') ;
0161         rmpath(genpath([pwd filesep BIN_FOLDER]));      % REMOVE BIN FOLDER FROM PATH
0162         rmpath(genpath([pwd filesep 'shared']));        % REMOVE SHARED ASSETS FROM PATH
0163         rmpath(genpath([pwd filesep 'integrator']));    % REMOVE INTEGRATORS FROM PATH
0164         rmpath(genpath([pwd filesep 'acado']));         % REMOVE OCP FROM PATH
0165         
0166         fprintf (1, 'Clean completed. \n') ;
0167     end
0168     
0169     
0170 
0171 %% MAKING
0172     if (MAKE)
0173         fprintf (1, 'Making ACADO... \n') ;
0174         
0175        
0176         
0177         % C++ files
0178         CBINFILES = [];
0179         for i = 1:length (SRC)
0180             force_compilation = check_to_compile (SRC{i}, [BIN_FOLDER, BINFOLDER{i} BIN{i}, ext], FORCE) ;
0181             if (force_compilation)
0182                 cmd = sprintf ('mex -O -c %s -outdir %s %s %s', ...
0183                     DEBUGFLAGS, [BIN_FOLDER BINFOLDER{i}], CPPFLAGS, SRC{i}) ;
0184                 counter = execute_command (cmd, counter, DEBUG, SRC{i}) ;
0185             end
0186 
0187             CBINFILES = [CBINFILES ' ' '''' pwd filesep BIN_FOLDER BINFOLDER{i} BIN{i} ext ''''] ; %#ok<AGROW>
0188         end
0189 
0190 
0191 
0192         % Mex files
0193         for i = 1:length (SRCMEX)
0194             force_compilation = check_to_compile (SRCMEX{i}, [BINFOLDERMEX{i}, BINMEX{i}, extmex], FORCE) ;
0195             if (force_compilation || counter > 0 || strcmp(BINMEX{i}, 'ACADOintegrators'))  
0196                 cmd = sprintf ('mex -O %s %s %s %s -outdir %s -output %s', ...
0197                     DEBUGFLAGS, CPPFLAGS, SRCMEX{i}, CBINFILES, BINFOLDERMEX{i}, [BINMEX{i}, extmex]) ;
0198                 counter = execute_command (cmd, counter, DEBUG, SRCMEX{i}) ;
0199             end
0200         end
0201 
0202         
0203         % Compile option files with "makemex"
0204         if (~isempty(optmake) && ~isempty(optmake.mexfile) && ~isempty(optmake.outputname))
0205             cmd = sprintf ('mex -O %s %s %s %s -outdir %s -output %s', ...
0206                 DEBUGFLAGS, CPPFLAGS, optmake.mexfile, CBINFILES, optmake.outputdir, [optmake.outputname, extmex]) ;
0207             counter = execute_command (cmd, counter, DEBUG, optmake.mexfile) ;
0208         end
0209  
0210         % Store important variables in globals.m file
0211         file = fopen('shared/acadoglobals.m','w');
0212         fprintf(file,'%% This file is autogenerated while executing the make command.\n');
0213         fprintf(file,'global ACADO_; ACADO_=[];\n');
0214         fwrite(file,['ACADO_.pwd = ''',pwd,''';']);
0215         fprintf(file,'\nACADO_.problemname = '''';');
0216         fprintf(file,'\nACADO_.modelactive = 0;');
0217         fprintf(file,sprintf('\nACADO_.mexcall = ''mex -O %s %s %s %s -output %s'';', ...
0218             DEBUGFLAGS, regexprep(regexprep(CPPFLAGS, '\\', '\\\\'), '''', ''''''), '%%s', regexprep(regexprep(CBINFILES, '\\', '\\\\'), '''', ''''''), ['%%s', extmex]));
0219         
0220         fclose(file);
0221         
0222         
0223         
0224         % PATHS
0225         addpath(genpath([pwd filesep BIN_FOLDER]));     % ADD BIN FOLDER TO PATH (and subfolders)
0226         addpath(genpath([pwd filesep 'shared']));       % ADD SHARED ASSETS TO PATH
0227         
0228         if (type == 0 || type == 1)
0229             addpath([pwd filesep 'integrator']);   % ADD INTEGRATORS TO PATH. Only add top folder to path!
0230         end
0231         
0232         if (type == 0 || type == 2 || type == 3)
0233             addpath([pwd filesep 'acado']);   % ADD acado TO PATH. Only add top folder to path!
0234             addpath([pwd filesep 'acado' filesep 'functions']);
0235             addpath( genpath([pwd filesep 'acado' filesep 'packages']) );
0236         end
0237         
0238         fprintf (1, sprintf('\nACADO successfully compiled.\nNeeded to compile %d file(s).\n\n', counter)) ;
0239         fprintf (1, 'If you need to restart Matlab, run this make file again \n') ;
0240         fprintf (1, 'to set all paths or run savepath in your console to \n') ;
0241         fprintf (1, 'save the current search path for future sessions.\n') ;
0242          
0243     end
0244     
0245     warning on all
0246 end
0247 
0248 
0249 function counter = execute_command (s, counter, full_logging, shorthand)
0250     s = strrep (s, '/', filesep) ;
0251     if (full_logging)
0252         fprintf (1, '%s  -->  %s\n', shorthand, s);
0253     else
0254         if (mod (counter, 20) == 0)
0255             fprintf (1, '\n') ;
0256         end
0257         fprintf (1, '.') ;
0258     end
0259     counter = counter + 1 ;
0260     eval (s) ;
0261 end
0262 
0263 
0264 function [force_compilation] = check_to_compile (src, bin, force_make)
0265 
0266     d_bin = dir (bin);
0267     if (force_make || isempty (d_bin))  
0268         force_compilation = 1;
0269     else
0270         d_src = dir (src);
0271         try
0272           force_compilation = (datenum(d_bin.date) < datenum(d_src.date)) ;
0273         catch
0274           force_compilation = 1;
0275           disp('Warning: datenum is not working on your system. See http://www.acadotoolkit.org/matlab/faq/datenum.php');
0276         end
0277     end
0278     
0279 end

www.acadotoolkit.org/matlab
Generated on Tue 01-Jun-2010 20:14:12 by m2html © 2005