% Make static version of mdsipmex from latest libraries
% Basil P. DUVAL SPC/EPFL, February 2021, Lausanne, Switzerland
% (Use Shared flag to employ distribution in /usr/local/mdsplus and then link statically)
%Note: for mdsconnect('ssh://XyZ') to function, mdsip-client-ssh must be put into $PATH
%clear all;setenv('MDSPLUS',[getenv('HOME'),'/PLAY/mdsplus']);make_mdsipmex_static2
%clear all;setenv('MDSPLUS',[getenv('HOME'),'/NoTivoli/mdsplus']);make_mdsipmex_static2
%
MDSPLUS=getenv('MDSPLUS');dirs='/';
if(length(MDSPLUS)==0);MDSPLUS='/usr/local/mdsplus';end

%r={'libMdsIpShr.a','libTreeShr.a','libMdsShr.a','libTdiShr.a'};
r={'libMdsIpShr.a','libTreeShr.a','libTdiShr.a','libMdsLib.a','libTreeShr.a','libMdsShr.a'};
r={'libMdsIpShr.a','libTreeShr.a','libTdiShr.a','libMdsLib.a','libMdsShr.a'};
r={'libMdsIpShr.a','libTreeShr.a','libMdsLib.a','libMdsShr.a'};
r={'libMdsIpShr.a','libTreeShr.a','libMdsShr.a'};

%
%comm = sprintf('mex -DPASSWD -DSHARED mdsipmex.c LoadIo.c xmlbits.c -I%s%sinclude -I%s%smdstcpip ',...
%comm = sprintf('mex -DPASSWD -DSHARED mdsipmex.c xmlbits.c IoRoutinesTcp.c IoRoutinesTunnel.c IoRoutinesThread.c -I%s%sinclude -I%s%smdstcpip ',...
%comm = sprintf('mex -DPASSWD -DSHARED mdsipmex.c LoadIo.c xmlbits.c %s%smdstcpip/IoRoutinesTcp.c -I%s%sinclude -I%s%smdstcpip ',...
%comm = sprintf('mex -DPASSWD -DSHARED -DNODL mdsipmex.c LoadIo.c xmlbits.o %s%smdstcpip/IoRoutinesTcp.c -I%s%sinclude -I%s%smdstcpip ',...
comm = sprintf('mex -DPASSWD -DSHARED -DNODL mdsipmex.c LoadIo.c xmlbits.c %s%smdstcpip/IoRoutinesTcp.c -I%s%sinclude -I%s%smdstcpip ',...
       MDSPLUS,dirs,MDSPLUS,dirs,MDSPLUS,dirs);

% add all the routines using the given path
for(i=1:length(r))
   comm = sprintf('%s %s/lib/%s',comm,MDSPLUS,char(r(i)));end
%comm = [comm,' -ldl'];
disp(comm);eval(comm);

%mex -DPASSWD mdsipmex.c xmlbits.c -I/usr/local/mdsplus/include -I/usr/local/mdsplus/mdstcpip  -DSHARED /usr/local/mdsplus/lib/libMdsIpShr.a /usr/local/mdsplus/lib/libTreeShr.a /usr/local/mdsplus/lib/libMdsShr.a -ldl
%mex -v CFLAGS='$CFLAGS -fPIC' -DPASSWD mdsipmex.c -I/usr/local/mdsplus/include -I/usr/local/mdsplus/mdstcpip  -DSHARED /usr/local/mdsplus/lib/libMdsIpShr.a /usr/local/mdsplus/lib/libTreeShr.a /usr/local/mdsplus/lib/libMdsShr.a /root/rpmbuild/BUILD/libxml2-2.9.10/py3/.libs/libxml2.a -ldl
%mex -v CFLAGS='$CFLAGS -fPIC' -DPASSWD mdsipmex.c -I/usr/local/mdsplus/include -I/usr/local/mdsplus/mdstcpip  -DSHARED /usr/local/mdsplus/lib/libMdsIpShr.a /usr/local/mdsplus/lib/libTreeShr.a /usr/local/mdsplus/lib/libMdsShr.a /usr/lib64/libxml2.a -ldl
%mex -DPASSWD mdsipmex.c -I/usr/local/mdsplus/include -I/usr/local/mdsplus/mdstcpip  -DSHARED /usr/local/mdsplus/lib/libMdsIpShr.a /usr/local/mdsplus/lib/libTreeShr.a /usr/local/mdsplus/lib/libMdsShr.a -lxml2 -ldl
%mex -c  -DPASSWD mdsipmex.c -I/usr/local/mdsplus/include -I/usr/local/mdsplus/mdstcpip  -DSHARED
%mex mdsipmex.o /usr/local/mdsplus/lib/libMdsIpShr.a /usr/local/mdsplus/lib/libTreeShr.a /usr/local/mdsplus/lib/libMdsShr.a -lxml2 -ldl
%
% complete link.. incase further dependencies appear 
% mex mdsipmex.o /usr/local/mdsplus/lib/libhdf5tdi.a /usr/local/mdsplus/lib/libIdlMdsEvent.a /usr/local/mdsplus/lib/libIdlMdsWidgets.a /usr/local/mdsplus/lib/libMdsIpShr.a /usr/local/mdsplus/lib/libMdsLib.a /usr/local/mdsplus/lib/libMdsLib_client.a /usr/local/mdsplus/lib/libMdsMisc.a /usr/local/mdsplus/lib/libMdsObjectsCppShr.a /usr/local/mdsplus/lib/libMdsServerShr.a /usr/local/mdsplus/lib/libMdsSql.a /usr/local/mdsplus/lib/libMitDevices.a /usr/local/mdsplus/lib/libRoam_gcc64.a /usr/local/mdsplus/lib/libTdiShr.a /usr/local/mdsplus/lib/libTdiShrExt.a /usr/local/mdsplus/lib/libTreeShr.a /usr/local/mdsplus/lib/libXmdsShr.a /usr/local/mdsplus/lib/libXTreeShr.a /usr/local/mdsplus/lib/libMdsShr.a -lxml2 -ldl
