SETUPMEXSFTP Build mex file for internal functions of SFTP object methods. Syntax: SETUPMEXSFTP() Description: SETUPMEXSFTP() builds a mex file interface to perform operations through an SFTP connection to a remote server using the API provided by the library libssh. This interface is used in the implementation of the SFTP methods. If libssh is installed from the official repositories on Debian based distributions, the mex file is built using the following attributes: TARGET: /path/to/@sftp/private/mexsftp.mex(a64) SOURCES: /path/to/@sftp/private/mexsftp.c INCLUDES: none LIBRARIES: -l ssh Alternatively, it is possible to build the mex file using precompiled versions of the library for other platforms available at the web site, or a version of the library compiled from sources locally. The header files and the binary files should be located in the respective directories 'libssh/include/libssh' and 'libssh/lib' in the same directory than the mex file source. TARGET: /path/to/@sftp/private/mexsftp.mex(a64) SOURCES: /path/to/@sftp/private/mexsftp.c INCLUDES: -I /path/to/@sftp/private/libssh/include LIBRARIES: -L /path/to/@sftp/private/libssh/lib -Wl,-rpath=$ORIGIN/libssh/lib -l ssh Notes: The libssh library provides a client API for the SFTP protocol. The official web site of the library is: <https://www.libssh.org/> On Debian based systems, the libssh library may be installed from the main section of the official repositories running the following command as root: apt-get install libssh-dev This function uses the function MEX to build the target. On GNU/Linux systems, the build process might fail after a warning if the compiler version is newer than the latest version supported by MATLAB, even though running the same MEX command on a system shell builds the target properly. The reason is that MATLAB may extend or overwrite the environment variable LD_LIBRARY_PATH to point to its own version of the standard libraries, causing an incompatibility with the version of the compiler. To solve the problem, either build the target from the shell or temporarily overwrite the environment variable LD_LIBRARY_PATH from the MATLAB session. References: Aris Adamantiadis and Andreas Schneider, libssh library: <http://www.libssh.org/> Examples: % Check that libssh is properly installed on the system % or locally in the private/libssh directory of the @sftp class. setupMexSFTP() % Incompatible versions of system compiler and libraries shipped with the % the interpreter may cause build failure. % Try to build the target against system libraries instead of shipped ones. ld_library_path = getenv('LD_LIBRARY_PATH') setenv('LD_LIBRARY_PATH') setupMexSFTP() setenv('LD_LIBRARY_PATH', ld_library_path) clear('ld_library_path') See also: MEXSFTP SFTP Authors: Joan Pau Beltran <joanpau.beltran@socib.cat>
0001 function setupMexSFTP() 0002 %SETUPMEXSFTP Build mex file for internal functions of SFTP object methods. 0003 % 0004 % Syntax: 0005 % SETUPMEXSFTP() 0006 % 0007 % Description: 0008 % SETUPMEXSFTP() builds a mex file interface to perform operations through an 0009 % SFTP connection to a remote server using the API provided by the library 0010 % libssh. This interface is used in the implementation of the SFTP methods. 0011 % If libssh is installed from the official repositories on Debian based 0012 % distributions, the mex file is built using the following attributes: 0013 % TARGET: 0014 % /path/to/@sftp/private/mexsftp.mex(a64) 0015 % SOURCES: 0016 % /path/to/@sftp/private/mexsftp.c 0017 % INCLUDES: 0018 % none 0019 % LIBRARIES: 0020 % -l ssh 0021 % Alternatively, it is possible to build the mex file using precompiled 0022 % versions of the library for other platforms available at the web site, 0023 % or a version of the library compiled from sources locally. 0024 % The header files and the binary files should be located in the respective 0025 % directories 'libssh/include/libssh' and 'libssh/lib' in the same directory 0026 % than the mex file source. 0027 % TARGET: 0028 % /path/to/@sftp/private/mexsftp.mex(a64) 0029 % SOURCES: 0030 % /path/to/@sftp/private/mexsftp.c 0031 % INCLUDES: 0032 % -I /path/to/@sftp/private/libssh/include 0033 % LIBRARIES: 0034 % -L /path/to/@sftp/private/libssh/lib 0035 % -Wl,-rpath=$ORIGIN/libssh/lib 0036 % -l ssh 0037 % 0038 % Notes: 0039 % The libssh library provides a client API for the SFTP protocol. 0040 % The official web site of the library is: 0041 % <https://www.libssh.org/> 0042 % 0043 % On Debian based systems, the libssh library may be installed from the main 0044 % section of the official repositories running the following command as root: 0045 % apt-get install libssh-dev 0046 % 0047 % This function uses the function MEX to build the target. On GNU/Linux 0048 % systems, the build process might fail after a warning if the compiler 0049 % version is newer than the latest version supported by MATLAB, even though 0050 % running the same MEX command on a system shell builds the target properly. 0051 % The reason is that MATLAB may extend or overwrite the environment variable 0052 % LD_LIBRARY_PATH to point to its own version of the standard libraries, 0053 % causing an incompatibility with the version of the compiler. 0054 % To solve the problem, either build the target from the shell or temporarily 0055 % overwrite the environment variable LD_LIBRARY_PATH from the MATLAB session. 0056 % 0057 % References: 0058 % Aris Adamantiadis and Andreas Schneider, libssh library: 0059 % <http://www.libssh.org/> 0060 % 0061 % Examples: 0062 % % Check that libssh is properly installed on the system 0063 % % or locally in the private/libssh directory of the @sftp class. 0064 % setupMexSFTP() 0065 % 0066 % % Incompatible versions of system compiler and libraries shipped with the 0067 % % the interpreter may cause build failure. 0068 % % Try to build the target against system libraries instead of shipped ones. 0069 % ld_library_path = getenv('LD_LIBRARY_PATH') 0070 % setenv('LD_LIBRARY_PATH') 0071 % setupMexSFTP() 0072 % setenv('LD_LIBRARY_PATH', ld_library_path) 0073 % clear('ld_library_path') 0074 % 0075 % See also: 0076 % MEXSFTP 0077 % SFTP 0078 % 0079 % Authors: 0080 % Joan Pau Beltran <joanpau.beltran@socib.cat> 0081 0082 % Copyright (C) 2014-2016 0083 % ICTS SOCIB - Servei d'observacio i prediccio costaner de les Illes Balears 0084 % <http://www.socib.es> 0085 % 0086 % This program is free software: you can redistribute it and/or modify 0087 % it under the terms of the GNU General Public License as published by 0088 % the Free Software Foundation, either version 3 of the License, or 0089 % (at your option) any later version. 0090 % 0091 % This program is distributed in the hope that it will be useful, 0092 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0093 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0094 % GNU General Public License for more details. 0095 % 0096 % You should have received a copy of the GNU General Public License 0097 % along with this program. If not, see <http://www.gnu.org/licenses/>. 0098 0099 error(nargchk(0, 0, nargin, 'struct')); 0100 0101 funcname = 'mexsftp'; 0102 funcpath = which('@sftp/private/mexsftp'); 0103 0104 if isempty(funcpath) 0105 error('glider_toolbox:setup:NotFound', ... 0106 'Could not find location of %s.', funcname); 0107 end 0108 0109 prefix = fileparts(funcpath); 0110 target = fullfile(prefix, [funcname '.' mexext()]); 0111 sources = fullfile(prefix, [funcname '.c']); 0112 libssh = 'ssh'; 0113 libsshdir = fullfile(prefix, 'libssh'); 0114 includedir = fullfile(libsshdir, 'include'); 0115 librarydir = fullfile(libsshdir, 'lib'); 0116 rpath = fullfile('\\\$ORIGIN', 'libssh', 'lib'); 0117 0118 if exist(libsshdir, 'dir') 0119 mex('-output', target, ... 0120 ['-I' includedir], ... 0121 ['-L' librarydir], ... 0122 ['-l' libssh], ... 0123 ['-Wl,-rpath=' rpath], ... 0124 sources); 0125 else 0126 mex('-output', target, ['-l' libssh], sources); 0127 end 0128 0129 end