buildCddlib

PURPOSE ^

% Building callCddMex

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

% Building callCddMex

 This file tries to build the interface to cddlib that is provided under
   GNU-GPL by Komei Fukuda. The mex interface itself is provided by the 
   mpt-toolbox (M. Baotic, F. Torrisi, M. Kvasnica) under GNU-GPL. See
   licencing information in the subfolders of the directory where you 
   found this file.

 This file is automatically called by configElk and must be run in the
   directory where this file is found. According to mex there are 
   relatively strict requirements on the installed MATLAB version and 
   C-compiler version. If your compiled version crashes - use a C-compiler
   with an appropriate version to compile cddlib and cddmex.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %% Building callCddMex
0002 %
0003 % This file tries to build the interface to cddlib that is provided under
0004 %   GNU-GPL by Komei Fukuda. The mex interface itself is provided by the
0005 %   mpt-toolbox (M. Baotic, F. Torrisi, M. Kvasnica) under GNU-GPL. See
0006 %   licencing information in the subfolders of the directory where you
0007 %   found this file.
0008 %
0009 % This file is automatically called by configElk and must be run in the
0010 %   directory where this file is found. According to mex there are
0011 %   relatively strict requirements on the installed MATLAB version and
0012 %   C-compiler version. If your compiled version crashes - use a C-compiler
0013 %   with an appropriate version to compile cddlib and cddmex.
0014 
0015 % The elk-library: convex geometry applied to crystallization modeling.
0016 %   Copyright (C) 2012 Alexander Reinhold
0017 %
0018 % This program is free software: you can redistribute it and/or modify it
0019 %   under the terms of the GNU General Public License as published by the
0020 %   Free Software Foundation, either version 3 of the License, or (at your
0021 %   option) any later version.
0022 %
0023 % This program is distributed in the hope that it will be useful, but
0024 %   WITHOUT ANY WARRANTY; without even the implied warranty of
0025 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0026 %   General Public License for more details.
0027 %
0028 % You should have received a copy of the GNU General Public License along
0029 %   with this program.  If not, see <http://www.gnu.org/licenses/>.
0030 
0031 %% Setup of subfolders
0032 cddlibLocation = 'cddlib-094g';
0033 cddmexLocation = 'mpt-cddmex';
0034 compiler = 'gcc-4.4';
0035 zerotol = 1e-7;
0036 % choice of zerotol: generic_paracetamol_19 in cs-decomposition causes
0037 %   cddlib errors for zerotol <= 1e-8
0038 
0039 %% Caller and m-file location
0040 callLocation = pwd;
0041 myLocation = which('buildCddlib');
0042 myLocation = myLocation(1:find(myLocation == '/', 1, 'last'));
0043 logfile = [myLocation filesep 'buildCddlib.log'];
0044 
0045 %% Write zerotolCddlib.m
0046 cd(myLocation)
0047 fileId = fopen('zerotolCddlib.m', 'w+');
0048 fprintf(fileId, 'function zerotol = zerotolCddlib\n');
0049 fprintf(fileId, '%% return zerotol that is used for compilation of cddlib\n');
0050 fprintf(fileId, ['zerotol = ' num2str(zerotol) ';']);
0051 fclose(fileId);
0052 
0053 %% Precompile cddlib
0054 type legalNoticeCddlib
0055 
0056 cd(cddlibLocation);
0057 callSystemFunction(['./configure CC=' compiler ' CFLAGS=-fPIC'], ...
0058     'logfile', logfile, ...
0059     'reset logfile', 1, ...
0060     'error type', 'elk:setup', ...
0061     'error message', 'Build of cddlib failed. See logfile above.');
0062 
0063 cd('lib-src');
0064 
0065 % Apply zerotol option
0066 command = ['sed ''s/\(#define dd_almostzero  \)\([0-9]*.[0-9]*E*-*[0-9]*\)/' ...
0067     '\1' num2str(zerotol, '%G') '/g'' cdd.h.original > cdd.h'];
0068 % system(command)
0069 callSystemFunction(command, ...
0070     'error type', 'elk:setup', ...
0071     'error message', 'Build of cddlib failed. This error cannot be found in the logfile.');
0072 
0073 callSystemFunction('make', ...
0074     'logfile', logfile, ...
0075     'error type', 'elk:setup', ...
0076     'error message', 'Build of cddlib failed. See logfile above.');
0077 
0078 %% Compile cddmex
0079 cd(myLocation)
0080 type legalNoticeMpt
0081 
0082 cd(fullfile(myLocation, cddlibLocation, 'lib-src'));
0083 callSystemFunction(['cp ' ...
0084     myLocation filesep cddmexLocation filesep 'cddmex.c .' filesep], ...
0085     'logfile', logfile, ...
0086     'error type', 'elk:setup', ...
0087     'error message', 'Build of cddlib failed. See logfile above.');
0088 
0089 try
0090     % libcdd.a is in .libs only in version 94g
0091     eval(['mex cddmex.c .libs/libcdd.a CC=' compiler]);
0092 catch thisError
0093     type(fullfile(myLocation, 'buildCddlib.log'));
0094     disp('Mex execution failed - see details far above the added log')
0095     throw(thisError);
0096 end
0097 % 94e:
0098 % gcc -O -pthread -shared -m32 -Wl,--version-script,/usr/local/MATLAB/R2011b/extern/lib/glnx86/mexFunction.map -Wl,--no-undefined -o  "cddmex.mexglx"  cddmex.o  libcdd.a -Wl,-rpath-link,/usr/local/MATLAB/R2011b/bin/glnx86 -L/usr/local/MATLAB/R2011b/bin/glnx86 -lmx -lmex -lmat -lm -lstdc++
0099 % 94f:
0100 % gcc -O -pthread -shared -m32 -Wl,--version-script,/usr/local/MATLAB/R2011b/extern/lib/glnx86/mexFunction.map -Wl,--no-undefined -o  "cddmex.mexglx"  cddmex.o  libcdd.a -Wl,-rpath-link,/usr/local/MATLAB/R2011b/bin/glnx86 -L/usr/local/MATLAB/R2011b/bin/glnx86 -lmx -lmex -lmat -lm -lstdc++
0101 callSystemFunction('rm cddmex.c', ...
0102     'logfile', logfile, ...
0103     'error type', 'elk:setup', ...
0104     'error message', 'Build of cddlib failed. See logfile above.');
0105 callSystemFunction(['mv cddmex.' mexext ' ../../callCddLib.' mexext], ...
0106     'logfile', logfile, ...
0107     'error type', 'elk:setup', ...
0108     'error message', 'Build of cddlib failed. See logfile above.');
0109 
0110 %% Copy help file
0111 cd(myLocation);
0112 callSystemFunction(['cp ' cddmexLocation '/cddmex.m ' './callCddLib.m'], ...
0113     'logfile', logfile, ...
0114     'error type', 'elk:setup', ...
0115     'error message', 'Build of cddlib failed. See logfile above.');
0116 
0117 disp('The log file of this process is stored in: ')
0118 disp(fullfile(myLocation, 'buildCddlib.log'));
0119 
0120 cd(callLocation);

Generated on Sat 18-Jul-2015 16:45:31 by m2html © 2005