0001 function [ ] = makehelper( type, optmake, varargin )
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
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']));
0085
0086
0087
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
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
0107
0108 automatic_model_detection_integrator();
0109
0110 warning off all
0111
0112
0113 [HEADER_PATHS, SRC, BIN, BINFOLDER, SRCMEX, BINMEX, BINFOLDERMEX] = objects(type);
0114 BIN_FOLDER = 'bin/';
0115 IFLAGS = [ '-I. ', HEADER_PATHS ];
0116
0117
0118
0119 if (ispc)
0120
0121 CPPFLAGS = [ IFLAGS, ' -D__cpluplus -D__MATLAB__ -Dsnprintf=_snprintf -Dround=acadoRound -O ' ];
0122 else
0123
0124 CPPFLAGS = [ IFLAGS, ' -D__cpluplus -D__MATLAB__ -O ' ];
0125 end
0126 counter = 0 ;
0127
0128
0129
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
0141 if (ispc)
0142 ext = '.obj' ;
0143 else
0144 ext = '.o' ;
0145 end
0146
0147 extmex = ['.' mexext] ;
0148
0149
0150
0151
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
0159
0160 fprintf (1, 'Removing ACADO folders from Matlab path... \n') ;
0161 rmpath(genpath([pwd filesep BIN_FOLDER]));
0162 rmpath(genpath([pwd filesep 'shared']));
0163 rmpath(genpath([pwd filesep 'integrator']));
0164 rmpath(genpath([pwd filesep 'acado']));
0165
0166 fprintf (1, 'Clean completed. \n') ;
0167 end
0168
0169
0170
0171
0172 if (MAKE)
0173 fprintf (1, 'Making ACADO... \n') ;
0174
0175
0176
0177
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 ''''] ;
0188 end
0189
0190
0191
0192
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
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
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
0225 addpath(genpath([pwd filesep BIN_FOLDER]));
0226 addpath(genpath([pwd filesep 'shared']));
0227
0228 if (type == 0 || type == 1)
0229 addpath([pwd filesep 'integrator']);
0230 end
0231
0232 if (type == 0 || type == 2 || type == 3)
0233 addpath([pwd filesep 'acado']);
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