Skip to content

Commit

Permalink
Mostly adapt APA to Octave pkg system
Browse files Browse the repository at this point in the history
  • Loading branch information
siko1056 committed Aug 10, 2021
1 parent 2e49d4c commit 8002860
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 41 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: apa
version: 0.1.1
version: 0.1.2
date: 2021-08-10
author: Kai T. Ohlhus <[email protected]>
maintainer: Kai T. Ohlhus <[email protected]>
Expand Down
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@
From the Octave command-line run:

```octave
pkg install 'https://github.com/gnu-octave/apa/releases/download/v0.1.1/apa-0.1.1.zip'
pkg install 'https://github.com/gnu-octave/apa/releases/download/v0.1.2/apa-0.1.2.zip'
pkg load apa
install_apa
test_apa
pkg test_apa
```

From the Matlab command-line run (also works for Octave):

```matlab
urlwrite ('https://github.com/gnu-octave/apa/releases/download/v0.1.1/apa-0.1.1.zip', ...
'apa-0.1.1.zip');
unzip ('apa-0.1.1.zip');
cd (fullfile ('apa-0.1.1', 'inst'))
urlwrite ('https://github.com/gnu-octave/apa/releases/download/v0.1.2/apa-0.1.2.zip', ...
'apa-0.1.2.zip');
unzip ('apa-0.1.2.zip');
cd (fullfile ('apa-0.1.2', 'inst'))
install_apa
test_apa
```
Expand Down
8 changes: 4 additions & 4 deletions doc/MEX_INTERFACE.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ If those pre-compiled libraries are missing or not working, please read below.
From the Octave/Matlab command-line run:

```matlab
urlwrite ('https://github.com/gnu-octave/apa/releases/download/v0.1.1/apa-0.1.1.zip', ...
'apa-0.1.1.zip');
unzip ('apa-0.1.1.zip');
cd (fullfile ('apa-0.1.1', 'inst'))
urlwrite ('https://github.com/gnu-octave/apa/releases/download/v0.1.2/apa-0.1.2.zip', ...
'apa-0.1.2.zip');
unzip ('apa-0.1.2.zip');
cd (fullfile ('apa-0.1.2', 'inst'))
install_apa
test_apa
```
Expand Down
File renamed without changes.
80 changes: 51 additions & 29 deletions inst/install_apa.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
function install_apa ()
function install_apa (cmd)
% Install GMP and MPFR MEX interface.
%
% 'rebuild' - Rebuild and overwrite the MEX interface.
%

if (nargin < 1)
cmd = '';
end

[apa_dir, ~, ~] = fileparts (mfilename ('fullpath'));
mex_dir = fullfile (apa_dir, 'mex');
Expand All @@ -10,41 +17,43 @@ function install_apa ()

old_dir = cd (mex_dir);

if (is_complete (pwd (), [header, libs]))
cflags{end+1} = '-I.';
ldflags = libs;
elseif (ismac () && is_complete (fullfile (pwd (), 'macos'), [header, libs]))
cflags{end+1} = '-Imacos';
ldflags = fullfile ('macos', libs);
elseif (ispc () && is_complete (fullfile (pwd (), 'mswin'), [header, libs]))
cflags{end+1} = '-Imswin';
ldflags = fullfile ('mswin', libs);
elseif (isunix () && is_complete (fullfile (pwd (), 'unix'), [header, libs]))
cflags{end+1} = '-Iunix';
ldflags = fullfile ('unix', libs);
else
error (['Could not find pre-built GMP or MPFR libraries. ', ...
'Please run the Makefile in the "mex" directory.']);
end

try
if (exist('OCTAVE_VERSION', 'builtin') == 5)
mex (cflags{:}, 'gmp_mpfr_interface.c', ldflags{:});
if (strcmp (cmd, 'rebuild') || exist ('gmp_mpfr_interface', 'file') ~= 3)
if (is_complete (pwd (), [header, libs]))
cflags{end+1} = '-I.';
ldflags = libs;
elseif (ismac () && is_complete (fullfile (pwd (), 'macos'), [header, libs]))
cflags{end+1} = '-Imacos';
ldflags = fullfile ('macos', libs);
elseif (ispc () && is_complete (fullfile (pwd (), 'mswin'), [header, libs]))
cflags{end+1} = '-Imswin';
ldflags = fullfile ('mswin', libs);
elseif (isunix () && is_complete (fullfile (pwd (), 'unix'), [header, libs]))
cflags{end+1} = '-Iunix';
ldflags = fullfile ('unix', libs);
else
mex (['CFLAGS="$CFLAGS ', strjoin(cflags, ' '), '"'], ...
'gmp_mpfr_interface.c', ldflags{:});
error (['Could not find pre-built GMP or MPFR libraries. ', ...
'Please run the Makefile in the "mex" directory.']);
end

try
if (exist('OCTAVE_VERSION', 'builtin') == 5)
mex (cflags{:}, 'gmp_mpfr_interface.c', ldflags{:});
else
mex (['CFLAGS="$CFLAGS ', strjoin(cflags, ' '), '"'], ...
'gmp_mpfr_interface.c', ldflags{:});
end
movefile (['gmp_mpfr_interface.', mexext()], '..');
catch
cd (old_dir);
error ('MEX interface creation failed. APA cannot be used.');
end
catch
cd (old_dir);
error ('MEX interface creation failed. APA cannot be used.');

disp ('APA is ready to use.');
end

cd (old_dir);

add_to_path_if_not_exists (apa_dir);
add_to_path_if_not_exists (mex_dir);

disp ('APA is ready to use.');

end

Expand Down Expand Up @@ -76,3 +85,16 @@ function add_to_path_if_not_exists (p)
end

end



% The following PKG_ADD directive is used for the Octave pkg-system, such that
% "pkg (un)load" or addition to the manual addition to the load path ensures
% the mex file installation.
%{
## PKG_ADD: install_apa ();
%}

% Adapter for Octave to run the test suite for "pkg test".
%!test
% test_apa ();

0 comments on commit 8002860

Please sign in to comment.