17 class MatlabDocMaker {
130 static const .char DOXYFILE_TEMPLATE =
"Doxyfile.template";
142 static const .char LATEXEXTRAS_TEMPLATE =
"latexextras.template";
155 static const .char MTOCPP_CONFIGFILE =
"mtocpp.conf";
170 static function charname = getProjectName() {
193 static function chardir = getOutputDirectory() {
194 dir = MatlabDocMaker.getPref(
" outdir ");
208 static function chardir = getSourceDirectory() {
209 dir = MatlabDocMaker.getPref(
" srcdir ");
223 static function chardir = getConfigDirectory() {
224 dir = MatlabDocMaker.getPref(
" confdir ");
242 static function chardesc = getProjectDescription() {
243 desc = MatlabDocMaker.getPref(
" proj_desc ", );
258 static function setProjectDescription(
char value) {
260 error(" The description must be a
char array. ");
262 MatlabDocMaker.setPref(" proj_desc ", value);
277 static function
charversion = getProjectVersion() {
278 version = MatlabDocMaker.getPref(
" proj_ver ",
" 0 ");
296 static function setProjectVersion(
char value) {
298 error(" The project version must be a
char array. ");
300 MatlabDocMaker.setPref(" proj_ver ", value);
315 static function fullPath = getProjectLogo() {
316 logoFile = MatlabDocMaker.getPref(
" proj_logo ",);
318 if ~isempty(logoFile)
319 if isempty(fileparts(logoFile))
320 fullPath = fullfile(MatlabDocMaker.getConfigDirectory,logoFile);
324 if exist(fullPath," file ") ~= 2
325 warning(" MatlabDocMaker:getLogo ",[" Could not find logo file '%s'.\n "...
326 " No logo will be shown in documentation output. "],logoFile);
345 static function setProjectLogo(
char value) {
347 [f, p] = uigetfile(
" *.* ",
" Select project logo ", pwd);
349 value = fullfile(p,f);
351 fprintf(2,
" No file selected. Aborting.\n ");
356 error(" The project logo file must be a
char array. ");
360 if isempty(fileparts(value))
361 fullPath = fullfile(MatlabDocMaker.getConfigDirectory, value);
363 if ~exist(fullPath," file ")
364 error(" Invalid logo file: Could not find '%s' ",fullPath);
367 MatlabDocMaker.setPref(" proj_logo ", value);
389 static function open() {
390 index = fullfile(MatlabDocMaker.getOutputDirectory,
" index.html ");
394 [s, m] = system(sprintf(
" xdg-open '%s' ",index));
396 fprintf(2,
" Could not find/execute xdg-open: %s ",m);
414 ip.addParamValue(
'open',
false,@islogical);
415 ip.addParamValue(
'latex',
false,@islogical);
416 ip.parse(varargin[:]);
417 genlatex = ip.Results.latex;
420 cdir = MatlabDocMaker.getConfigDirectory;
421 srcdir = MatlabDocMaker.getSourceDirectory;
422 outdir = MatlabDocMaker.getOutputDirectory;
424 doxyfile_in = fullfile(cdir,MatlabDocMaker.DOXYFILE_TEMPLATE);
425 if exist(doxyfile_in,
" file ") ~= 2
426 error(
" No doxygen configuration file template found at '%s' ",doxyfile_in);
433 fprintf([
" Starting creation of doxygen/mtoc++ powered HTML%s documentation for '%s' (%s)\n "...
434 " Sources: %s\nOutput to: <a href='matlab:MatlabDocMaker.open'>%s</a>\nCreating config files... "],lstr,...
435 MatlabDocMaker.getProjectName,MatlabDocMaker.getProjectVersion,...
441 strs.null=
" /dev/null ";
445 strs.silencer=
" @ ";
448 error(
" Current platform not supported. ");
458 pathadd = [pathsep cdir];
459 setenv(
" PATH ",[getenv(
" PATH ") pathadd]);
461 mtoc_conf = fullfile(cdir,MatlabDocMaker.MTOCPP_CONFIGFILE);
462 filter = sprintf(
" %smtocpp ",strs.silencer);
463 if exist(mtoc_conf,
" file ")
465 strs.filter= " mtocpp_filter.sh ";
468 strs.filter= " mtocpp_filter.bat ";
471 error(" Current platform not supported. ");
474 cdir = MatlabDocMaker.getConfigDirectory;
476 filter = fullfile(cdir,strs.filter);
477 f = fopen(filter," w ");
478 fprintf(f," %smtocpp %s %s ",strs.silencer,strs.farg,mtoc_conf);
481 unix([" chmod +x " filter]);
486 cdirfwd = strrep(cdir," \ "," / ");
487 m = [" _OutputDir_ " strrep(outdir," \ "," \\ "); ...
488 " _SourceDir_ " strrep(MatlabDocMaker.getSourceDirectory," \ "," \\ ");...
489 " _ConfDir_ " strrep(cdir," \ "," \\ ");...
490 " _ConfDirFwdSlash_ " cdirfwd;...
491 " _ProjectName_ " MatlabDocMaker.getProjectName; ...
492 " _ProjectDescription_ " MatlabDocMaker.getProjectDescription; ...
493 " _ProjectLogo_ " strrep(MatlabDocMaker.getProjectLogo," \ "," \\ "); ...
494 " _ProjectVersion_ " MatlabDocMaker.getProjectVersion; ...
495 " _MTOCFILTER_ " strrep(filter," \ "," \\ "); ...
496 " _FileSep_ " filesep
500 texin = fullfile(cdir,MatlabDocMaker.LATEXEXTRAS_TEMPLATE);
502 if exist(texin," file ") == 2
503 latexstr = strrep(fileread(texin)," _ConfDir_ ",cdir);
504 latexstr = strrep(latexstr," _ConfDirFwdSlash_ ",cdirfwd);
505 latexextras = fullfile(cdir," latexextras.sty ");
506 fid = fopen(latexextras," w+ "); fprintf(fid," %s ",latexstr); fclose(fid);
510 m(end+1,:) = [" _LatexExtras_ " strrep(latexextras(1:end-4)," \ "," / ")];
515 m(end+1,:) = [" _GenLatex_ ",L];
518 [s, ~] = system(" dot -V ");
523 fprintf(" no 'dot' found... ");
525 m(end+1,:) = [" _HaveDot_ ",HD];
528 doxyfile = fullfile(cdir," Doxyfile ");
529 doxyconfstr = regexprep(fileread(doxyfile_in),m(:,1),m(:,2));
530 fid = fopen(doxyfile," w "); fprintf(fid," %s ",doxyconfstr); fclose(fid);
536 ldpath = " LD_LIBRARY_PATH= ";
539 fprintf(" running doxygen with mtoc++ filter... ");
540 [~,warn] = system(sprintf(" %sdoxygen '%s' 1>%s ",ldpath, doxyfile, strs.null));
543 fprintf(" running mtoc++ postprocessor... ");
544 [~,postwarn] = system(sprintf(" %smtocpp_post '%s' 1>%s ",ldpath,...
546 if ~isempty(postwarn)
547 warn = [warn sprintf(" mtoc++ postprocessor messages:\n ") postwarn];
554 latexdir = fullfile(outdir," latex ");
555 if exist(latexdir," dir ") == 7
556 if exist(fullfile(latexdir," refman.tex ")," file ") == 2
557 fprintf(" compiling LaTeX output... ");
559 [s, latexmsg] = system(" make ");
561 warn = [warn sprintf(" LaTeX compiler output:\n ") latexmsg];
565 fprintf(" cannot compile LaTeX output: no refman.tex found... ");
572 fprintf(" cleaning up... ");
573 if isfield(strs," filter ")
576 if ~isempty(latexextras)
584 curpath = getenv(" PATH ");
585 setenv(" PATH ",curpath(1:end-length(pathadd)));
586 fprintf(" done!\n ");
590 warn = strtrim(warn);
592 dispwarn = [warn(1:min(showchars,length(warn))) " [...] "];
593 fprintf(" First %d characters of warnings generated during documentation creation:\n%s\n ",showchars,dispwarn);
595 log = fullfile(outdir," warnings.log ");
596 f = fopen(log," w "); fprintf(f," %s ",warn); fclose(f);
597 fprintf(2," MatlabDocMaker finished with warnings!\n ");
598 fprintf(" Complete log file at <a href='matlab:edit( "" %s "" )'>%s</a>.\n ",log,log);
600 log = fullfile(outdir," _formulas.log ");
601 if exist(log," file ")
602 fprintf(" Found LaTeX formula log file. Check <a href='matlab:edit( "" %s "" )'>%s</a> for any errors.\n ",log,log);
605 if genlatex && latexerr
606 log = fullfile(latexdir," refman.log ");
607 fprintf(" There have been errors with LaTeX compilation. See log file at <a href='matlab:edit( "" %s "" )'>%s</a>.\n ",log,log);
610 fprintf(" MatlabDocMaker finished with no warnings!\n ");
633 static function setup() {
636 fprintf(
" <<<< Welcome to the MatlabDocMaker setup for your project '%s'! >>>>\n ",MatlabDocMaker.getProjectName);
640 srcdir = MatlabDocMaker.getPref(
" srcdir ",);
642 if isstruct(srcdir) || isempty(srcdir) || exist(srcdir,
" dir ") ~= 7
646 str = sprintf(
" Do you want to %s %s as your projects source directory?\n(Y)es/(N)o?: ",word,strrep(srcdir,
" \ ",
" \\ "));
647 ds = lower(input(str,
" s "));
649 d = uigetdir(srcdir," Please select the projects source directory ");
651 error(" No source directory specified. Aborting setup. ");
655 MatlabDocMaker.setPref(" srcdir ",srcdir);
658 confdir = MatlabDocMaker.getPref(" confdir ",);
660 if isstruct(confdir) || isempty(confdir) || exist(confdir," dir ") ~= 7
661 confdir = fullfile(srcdir," documentation ");
664 str = sprintf(" Do you want to %s %s as your documentation configuration files directory?\n(
Y)es/(N)o?: ",word,strrep(confdir," \ "," \\ "));
665 ds = lower(input(str," s "));
667 d = uigetdir(confdir," Please select the documentation configuration directory ");
669 error(" No documentation configuration directory specified. Aborting setup. ");
673 MatlabDocMaker.setPref(" confdir ",confdir);
676 outdir = MatlabDocMaker.getPref(" outdir ",);
678 if isstruct(outdir) || isempty(outdir) || exist(outdir," dir ") ~= 7
682 str = sprintf(" Do you want to %s %s as your documentation output directory?\n(
Y)es/(N)o?: ",word,strrep(outdir," \ "," \\ "));
683 ds = lower(input(str," s "));
685 d = uigetdir(outdir," Please select the documentation output directory ");
687 error(" No documentation output directory specified. Aborting setup. ");
691 MatlabDocMaker.setPref(" outdir ",outdir);
694 if isequal(lower(input([" Do you want to specify further project details?\n "...
695 " You can set them later using provided set methods. (
Y)es/(N)o?: "]," s "))," y ")
696 MatlabDocMaker.setPref(" proj_ver ",input(" Please specify the project version, e.g. '0.1': "," s "));
697 MatlabDocMaker.setPref(" proj_desc ",input(" Please specify a
short project description: "," s "));
698 MatlabDocMaker.setProjectLogo;
703 setenv(" PATH ",[getenv(" PATH ") pathsep confdir]);
704 fprintf(" [Required] Checking for doxygen... ");
705 [st, vers] = system(" doxygen --version ");
707 fprintf(" found %s\n ",vers(1:end-1));
709 fprintf(2," not found!\n ");
712 fprintf(" [Required] Checking for mtoc++... ");
715 ldpath = " LD_LIBRARY_PATH= ";
717 [st, vers] = system(sprintf(" %smtocpp --version ",ldpath));
719 fprintf(" found %s\n ",vers(1:end-1));
721 fprintf(2," not found!\n ");
724 fprintf(" [Recommended] Checking for dot... ");
725 [st, vers] = system(" dot -V ");
727 fprintf(" found %s\n ",vers(1:end-1));
729 fprintf(2," dot Graphviz tool not found!\nInstall dot for nicer class diagrams.\n ");
731 fprintf(" [Recommended] Checking for latex... ");
732 [st, vers] = system(" latex --version ");
734 fprintf(" found %s\n ",vers(1:strfind(vers,sprintf(" \n "))-1));
736 fprintf(2," latex not found!\nA LaTeX installation available on the system path is strongly recommended with mtoc++.\n ");
739 fprintf(" [Recommended] Checking for
ghostscript... ");
741 [st, vers] = system(" gswin32c --version ");
743 [st, vers] = system(" gswin64c --version ");
746 [st, vers] = system(" gs --version ");
749 fprintf(" found %s\n ",vers(1:strfind(vers,sprintf(" \n "))-1));
751 fprintf(2," ghostscript not found!\nCreating LaTeX formulas might not work properly.\n ");
755 fprintf(2," Please make sure
all prerequisites can be found on PATH or copy the executables into %s.\n ",confdir);
756 fprintf(" <<<< MatlabDocMaker setup finished with warnings. >>>>\n ");
758 fprintf(" <<<< MatlabDocMaker setup successful. >>>>\nYou can now create your projects documentation by running <a href='matlab:MatlabDocMaker.create( "" open "" ,true)'>MatlabDocMaker.create</a>!\n ");
771 static function value = getProjPrefTag() {
772 str = regexprep(strrep(strtrim(MatlabDocMaker.getProjectName),
" ",
" _ "),
" [^\d\w] ",);
773 value = sprintf(
" MatlabDocMaker_on_%s ",str);
784 static function value = getPref(name,
default) {
790 value = getpref(MatlabDocMaker.getProjPrefTag,name,def);
791 if nargin < 2 && isempty(value)
792 error(" MatlabDocMaker preferences not found/set correctly. (Re-)Run the MatlabDocMaker.setup method. ");
797 static function value = setPref(name,value) {
798 setpref(MatlabDocMaker.getProjPrefTag,name,value);
A variable number of input arguments.
function varargout = ghostscript(cmd)
Initialize any required system calls before calling ghostscript.