From 8002860c8107e95efc02fa460e4b9f6d059cb158 Mon Sep 17 00:00:00 2001 From: "Kai T. Ohlhus" Date: Tue, 10 Aug 2021 15:44:57 +0900 Subject: [PATCH] Mostly adapt APA to Octave pkg system --- DESCRIPTION | 2 +- README.md | 13 +++-- doc/MEX_INTERFACE.md | 8 +-- inst/{mex => }/gmp_mpfr_interface.m | 0 inst/install_apa.m | 80 ++++++++++++++++++----------- 5 files changed, 62 insertions(+), 41 deletions(-) rename inst/{mex => }/gmp_mpfr_interface.m (100%) diff --git a/DESCRIPTION b/DESCRIPTION index 34a4eb0..a89a69d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ name: apa -version: 0.1.1 +version: 0.1.2 date: 2021-08-10 author: Kai T. Ohlhus maintainer: Kai T. Ohlhus diff --git a/README.md b/README.md index cc6ad5e..e3993ca 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/doc/MEX_INTERFACE.md b/doc/MEX_INTERFACE.md index 96d92c0..bad09b2 100644 --- a/doc/MEX_INTERFACE.md +++ b/doc/MEX_INTERFACE.md @@ -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 ``` diff --git a/inst/mex/gmp_mpfr_interface.m b/inst/gmp_mpfr_interface.m similarity index 100% rename from inst/mex/gmp_mpfr_interface.m rename to inst/gmp_mpfr_interface.m diff --git a/inst/install_apa.m b/inst/install_apa.m index 8215898..9c7b060 100644 --- a/inst/install_apa.m +++ b/inst/install_apa.m @@ -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'); @@ -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 @@ -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 (); \ No newline at end of file