view inst/import_meshfunction_type.m @ 269:897e312cb440

Ensure the mkoctfile installed with running octave is used * inst/import_*.m: find the right mkoctfile and pass it through the environment * inst/private/generate_*.m: get mkoctfile from the environment
author Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
date Thu, 14 Aug 2014 17:10:29 +0200
parents 61830a4f9ab9
children f4d6ae912a08
line wrap: on
line source

## Copyright (C) 2014 Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
##
## 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 3 of the License, 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; if not, see <http://www.gnu.org/licenses/>.

## -*- texinfo -*-
## @deftypefn {Function File} {} import_meshfunction_type (@var{typename})
## Add a wrapper for dolfin::MeshFunction <@var{typename}>
## @seealso {MeshFunction}
## @end deftypefn

function import_meshfunction_type (typename)

  if (is_master_node ())
    if (nargin != 1)
      error ("import_meshfunction_type: wrong number of input parameters.");
    elseif (! ischar (typename))
      error ("import_meshfunction_type: first argument is not a valid string");
    endif

    typename = strtrim (typename);

    # Ensure that the label does not contain whitespace or symbols
    label = genvarname (strjoin (strsplit (typename), ""));

    if (! check_mf_files (typename))
      n = length (mfilename ("fullpath")) - length (mfilename ());
      path = strtrunc (mfilename ("fullpath"), n);

      private = fullfile (path, "include/");
      output = generate_mf_header (typename, label);
      output += generate_mf_constructor (label);
      output += generate_mf_save (typename, label);
      output += generate_mf_makefile (label, private);

      # Find correct mkoctfile for this version of Octave
      bindir = octave_config_info ("bindir");
      ext = octave_config_info ("EXEEXT");
      shell_script = fullfile (bindir, sprintf ("mkoctfile-%s%s", OCTAVE_VERSION, ext));

      if (output != 0)
        error ("compilation failed");
      else
        [output, textfile] = ...
          system (["MKOCTFILE=", shell_script, " make -f Makefile_", label, " all"]);
        if (output != 0)
          display (text);
          error ("compilation failed");
        endif
        [output, textfile] = system (["make -f Makefile_", label, " clean"]);
        if (output != 0)
          display (text);
          error ("compilation failed");
        endif
      endif
    endif
  endif

  barrier ();

endfunction