-
Notifications
You must be signed in to change notification settings - Fork 0
/
makeinstall.m
1872 lines (1815 loc) · 78.3 KB
/
makeinstall.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function makeinstall(varargin)
% MAKEINSTALL creates a toolbox installation file.
% Use MAKEINSTALL to create a INSTALL.M file, which
% will include a simple installation script and all the
% Matlab files which are needed for the toolbox. If the
% CONTENTS.M file is missing, it will be automatically
% created. Furthermore the command TBCLEAN will be added to
% the toolbox folder, which enables to remove the toolbox
% folder and the startup entries.
%
% Call MAKEINSTALL in the toolbox folder or specify this
% folder with MAKEINSTALL TB-FOLDER.
%
% In order to initialize some needed variables, call this
% programme the first time and then modify the entries in
% the automatically created resource file MAKEINSTALL.RC.
% You may change the entries in MAKEINSTALL.RC for your
% convenience.
%
% Please note, that further files will be automatically
% generated in the toolbox folder if they do not exist yet:
% CONTENTS.M, INFO.XML and TBCLEAN.M.
%
% The contents of CONTENTS.M will be generated from the help
% lines in the M-files. If there are no help lines or if
% this help text is not correctly placed, a warning message
% will occur. Please ensure that the help text corresponds
% with the predefined structure of M-files:
%
% function p = angle(h)
% % ANGLE Polar angle.
% % ANGLE(H) returns the phase angles, in radians, of
% % a matrix with complex elements. Use ABS for the
% % magnitudes.
% p = atan2(imag(h),real(h));
%
% where there is a first help line (H1) below the function
% line and a following help text. The H1 line is used also
% by other functions like LOOKFOR. If you like to generate
% CONTENTS.M automatically with MAKEINSTALL although
% CONTENTS.M already exists, you have to remove the old
% CONTENTS.M file. Thus, manual modifications will be kept.
%
% The contents of INFO.XML can be modified with some
% variables in the resource file MAKEINSTALL.RC. However,
% you have to remove the old INFO.XML file, if you like to
% modify it the next time with MAKEINSTALL. Thus, manual
% modifications will be preserved.
%
% This programme is free software under the BSD License.
% To view the text of this license, type
% MAKEINSTALL BSD.
% Copyright (c) 2008-2023
% Norbert Marwan, Potsdam Institute for Climate Impact Research, Germany
% https://tocsy.pik-potsdam.de/makeinstall.php
%
% Copyright (c) 2002-2008
% Norbert Marwan, Potsdam University, Germany
% http://www.agnld.uni-potsdam.de
%
% All rights reserved.
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions
% are met:
%
% * Redistributions of source code must retain the above
% copyright notice, this list of conditions and the following
% disclaimer.
% * Redistributions in binary form must reproduce the above
% copyright notice, this list of conditions and the following
% disclaimer in the documentation and/or other materials provided
% with the distribution.
% * All advertising materials mentioning features or use of this
% software must display the following acknowledgement:
% This product includes software developed by the University of
% Potsdam, Germany, the Potsdam Institute for Climate Impact
% Research (PIK), and its contributors.
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
% CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
% INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
% MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
% DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
% BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
% EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
% TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
% DATA, OR PROFITS; OR BUSINESS
%
% I'm grateful for every suggestion and hint which improves this
% programme. Thanks to Gaetan Koers of Vrije Universiteit Brussel
% for hints about Windows compatibility and improvement the help-text
% parser. Thanks also to Volkmar Glauche of University of Hamburg
% (Universitatsklinikum) and Eduard vander Zwan (Wageningen
% Universiteit) for usefule hints and comments about the
% root-folder of the toolbox and the startup.m entries.
% initialization some variables
narginchk(0,1)
olddir = pwd;
toolbox_name = ''; install_file = ''; install_path = ''; deinstall_file = ''; src_dir = '';
install_dirPC = ''; install_dirUNIX = ''; version_file = ''; version_number = ''; release = '';
infostring = ''; old_dirs = ''; ignore = ''; xml_name = ''; xml_start = ''; xml_demo = ''; xml_web = ''; restart = 0;
count_warnings = 0; include_pfiles = 0; pc_only = 0;
max_warnings = 10; % more warnings than this number will be suppressed - feel free to change this number
fid = 0;
% read the resource file
if nargin == 1
if exist(char(varargin{1}),'dir') == 7
src_dir = varargin{1};
cd(src_dir);
disp([' Change to directory ', src_dir,''])
else
toolbox_name = varargin{1};
end
elseif nargin == 2
if exist(char(varargin{2}),'dir') == 7
src_dir = varargin{2};
cd(src_dir);
disp([' Change to directory ', src_dir,''])
end
toolbox_name = varargin{1};
end
% get version number of the makeinstall-script
mi_file = which(mfilename);
mi_version = 'none';
fid = fopen(mi_file,'r');
if fid ~= -1
while ~feof(fid)
temp = fgetl(fid);
if ~isempty(temp)
if temp(1) == '%'
i = findstr(temp,'Version:');
if ~isempty(i), mi_version = temp(i(1)+9:end); break, end
i = findstr(temp,'$Revision:');
if ~isempty(i), mi_version = strtok(temp(i(1)+11:end),'$'); break, end
end
end
end
fclose(fid);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% splash the BSD License
filename = 'makeinstall';
txt = {'';'BSD LICENSE';
'';'Copyright (c) 2008-2023';
'Norbert Marwan, Potsdam Institute for Climate Impact Research, Germany';
'https://tocsy.pik-potsdam.de';
'';
'Copyright (c) 2002-2008';
'Norbert Marwan, Potsdam University, Germany';
'http://www.agnld.uni-potsdam.de';
'';
'All rights reserved.';
'';
'Redistribution and use in source and binary forms, with or without';
'modification, are permitted provided that the following conditions';
'are met:';
'';
' * Redistributions of source code must retain the above';
' copyright notice, this list of conditions and the following';
' disclaimer.';
' * Redistributions in binary form must reproduce the above';
' copyright notice, this list of conditions and the following';
' disclaimer in the documentation and/or other materials provided';
' with the distribution.';
' * Neither the name of the copyright holder nor the names of its';
' contributors may be used to endorse or promote products derived';
' from this software without specific prior written permission.';
'';
'THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS';
'“AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED';
'TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR';
'PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR';
'CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,';
'EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,';
'PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;';
'OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,';
'WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR';
'OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF';
'ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.'
};
which_res = which([filename,'.m']);
bsdrc_path = [strrep(which_res,[filename,'.m'],''), 'private'];
bsdrc_file = [bsdrc_path, filesep, '.bsd.',filename];
if ~exist(bsdrc_path,'dir')
mkdir(strrep(which_res,[filename,'.m'],''),'private');
end
if ~exist(bsdrc_file,'file') | strcmpi(varargin,'bsd')
if ~exist(bsdrc_file,'file')
disp('First click on the license to accept them.')
else
disp('Click on the license to close them.')
end
fid = fopen(bsdrc_file,'w');
fprintf(fid,'%s\n','If you delete this file, the BSD License will');
fprintf(fid,'%s','splash up at the next time the programme starts.');
fclose(fid);
h = figure('NumberTitle','off',...,
'ButtonDownFcn','close',...
'Name','BSD License');
ha = get(h,'Position');
h = uicontrol('Style','Listbox',...
'ButtonDownFcn','close',...
'CallBack','close',...
'Position',[0 0 ha(3) ha(4)],...
'Value',1,...
'FontName','Courier',...
'BackgroundColor',[.8 .8 .8],...
'String',txt);
waitfor(h)
end
if isempty(varargin) | ~strcmpi(varargin,'bsd') % create install file if not the 'bsd' is called
files = what;
if isempty(files.m)
warning on; warning('No M-files found in this directory.');
end
rc_file = fullfile(pwd,'makeinstall.rc');
time_string = datestr(now);
fid = fopen(rc_file,'r');
if fid > 0 % begin main part
disp(' Reading the resource file')
while ~feof(fid)
l = fgetl(fid);
if ~isempty(l), eval(l); end
end
fclose(fid);
if isempty(toolbox_name), [dummy toolbox_name] = fileparts(pwd); end
if isempty(install_file), install_file = 'install.m'; end
if isempty(deinstall_file), deinstall_file = 'tbclean.m'; end
if isempty(src_dir), src_dir = pwd; end
if isempty(install_dirPC), install_dirPC = pwd; end
if isempty(install_dirUNIX), install_dirUNIX = install_dirPC; end
if isempty(version_number), version_number = 'none'; end
if isempty(release), release = ' '; end
if isempty(include_pfiles), include_pfiles = 0; end
if isempty(pc_only), pc_only = 0; end
% if isempty(infostring), infostring = ''; end
old_dirs = lower(old_dirs);
if ~iscell(old_dirs), old_dirs = cellstr(old_dirs); end
if ~iscell(ignore), ignore = cellstr(ignore); end
check_for_old = '[findstr([lower(toolboxpath),''demo''],lower(p))';
check_for_old = [check_for_old,' findstr(lower(toolboxpath),lower(p))'];
for i = 1:length(old_dirs)
check_for_old = [check_for_old,' findstr(''',old_dirs{i},''',lower(p))'];
end
check_for_old = [check_for_old,']'];
% make install file
disp(' Reading the install source code')
if include_pfiles
disp(' ** Warning: p-files will be included!')
end
fid = fopen(mi_file, 'r'); warning off
i = 1; flag = 0;
while ~feof(fid)
temp = fgetl(fid);
if length(temp) > 1
if strcmpi(temp,'%<-- ASCII begins here: install -->')
eofbyte = ftell(fid);
flag = 1;
elseif strcmpi(temp,'%<-- ASCII begins here: clean -->')
eofbyte = ftell(fid)-eofbyte-1000;
flag = 2;
elseif strcmpi(temp,'%<-- ASCII ends here -->')
flag = 0; i = 1;
end
if findstr(temp(1:2),'%@') == 1
aline = repmat('-',1,length(toolbox_name)+17);
switch flag
case 1
% read install part
temp = strrep(temp,13,''); % remove the CR end of a line (if DOS style)
b(i,1) = {temp(3:end)};
b(i) = strrep(b(i),'$lines$',aline);
b(i) = strrep(b(i),'$installpath$',install_path);
b(i) = strrep(b(i),'$toolboxdirpc$',install_dirPC);
b(i) = strrep(b(i),'$toolboxdirunix$',install_dirUNIX);
b(i) = strrep(b(i),'$toolboxname$',toolbox_name);
b(i) = strrep(b(i),'$generation_date$',time_string);
b(i) = strrep(b(i),'$check_for_old$',check_for_old);
b(i) = strrep(b(i),'$mi_version$',mi_version);
if pc_only
b(i) = strrep(b(i),'$pc_only$','if ~ispc, error(''Sorry, this toolbox can be used only on a PC (Windows).''), end');
else
b(i) = strrep(b(i),'$pc_only$','');
end
if isempty(infostring)
b(i) = strrep(b(i),'$infostring$','');
else
b(i) = strrep(b(i),'$infostring$',['disp(''',infostring,''')']);
end
case 2
% read uninstall part
temp = strrep(temp,13,''); % remove the CR end of a line (if DOS style)
c(i,1) = {temp(3:end)};
c(i) = strrep(c(i),'$lines$',aline);
c(i) = strrep(c(i),'$toolboxdir$',install_dirPC);
c(i) = strrep(c(i),'$toolboxname$',toolbox_name);
c(i) = strrep(c(i),'$deinstall_file$',strtok(deinstall_file,'.'));
c(i) = strrep(c(i),'$deinstall_file_up$',strtok(upper(deinstall_file),'.'));
c(i) = strrep(c(i),'$generation_date$',time_string);
end
i = i+1;
end
end
end
fclose(fid);
if exist(fullfile(olddir,'install.m'),'file'), delete(fullfile(olddir,'install.m')); end
fid = fopen(fullfile(olddir,install_file),'w');
startbyte = eofbyte;
for i2 = 1:length(b), b(i2) = strrep(b(i2),'$startbyte$',num2str(startbyte-1000)); fprintf(fid,'%s\n',char(b(i2))); end
fclose(fid);
disp([' Source directory ', src_dir,''])
if ~exist(src_dir,'dir'), error('Predefined source directory is nonexistent. Check the resource file.'), end
cd(src_dir)
% make clean file
% if ~exist(deinstall_file)
disp([' Create ', deinstall_file,''])
fid = fopen(deinstall_file,'w');
for i2 = 1:length(c), fprintf(fid,'%s\n',char(c(i2))); end
fclose(fid);
% end
% get version number
% - test if GIT (use latest tag)
if strcmpi(version_file,'git')
if exist('.git/refs/tags','dir') ~= 7
disp(' ** Warning: No GIT repository found!')
count_warnings = count_warnings + 1;
version_number = 'none';
else
d_tags = dir('.git/refs/tags');
% remove '.' and '..'
i_remtags = cellfun(@(x)strcmp(x, '.'), {d_tags.name},'UniformOutput',false);
d_tags(find(cell2mat(i_remtags))) = [];
i_remtags = cellfun(@(x)strcmp(x, '..'), {d_tags.name},'UniformOutput',false);
d_tags(find(cell2mat(i_remtags))) = [];
% find max in datenum field (= youngest tag)
[dummy i_tag] = max([d_tags.datenum]);
if isempty(i_tag)
disp(' ** Warning: No GIT tag found!')
count_warnings = count_warnings + 1;
version_number = 'none';
else
version_number = d_tags(i_tag).name;
disp([' Found GIT tag (used as version number) '])
end
end
else
% version number from CVS/SVN tag in specified file
fid = fopen(version_file,'r');
if fid ~= -1
while ~feof(fid)
temp = fgetl(fid);
if ~isempty(temp)
if temp(1) == '%'
i = findstr(temp,'Version:');
if ~isempty(i), version_number = temp(i(1)+9:end); break, end
i = findstr(temp,'$Revision:');
if ~isempty(i), version_number = strtok(temp(i(1)+11:end),'$'); break, end
end
end
end
fclose(fid);
end
end
if strcmpi(version_number,'none')
if max_warnings && count_warnings == max_warnings
disp(' ** TOO MUCH WARNINGS!')
disp(' I give up! Following warning messages will be suppressed.')
end
if count_warnings < max_warnings
disp(' ** Warning: No version number found!')
disp(' Please provide a version file or number in the makeinstall.rc file.')
end
count_warnings = count_warnings + 1;
else
disp([' Found version number ', version_number,''])
end
if ~strcmpi(release,' ') && ~isempty(release)
disp([' Found release ', release,''])
end
if ~isempty(infostring)
if length(infostring)>40, txt = [infostring(1:37),'...']; else txt = infostring; end
disp([' Found infotext ''', txt,''''])
end
disp([' Time stamp ', time_string,''])
% make launch pad file
if ~exist(fullfile(src_dir,'info.xml'),'file') && ~isempty(xml_name)
disp(' Create info.xml')
files.m(strcmpi(files.m,'info.xml')) = [];
files.m(strcmpi(files.m,install_file)) = [];
v = version;
mrelease = str2double(v(findstr(v,'(R')+2:findstr(v,')')-1));
if mrelease>12, area = 'toolbox'; icon_path = '$toolbox/matlab/icons'; else area = 'matlab'; icon_path = '$toolbox/matlab/general'; end
fid = fopen('info.xml','w');
fprintf(fid,'%s\n','<productinfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.mathworks.com/namespace/info/v1/info.xsd">');
fprintf(fid,'%s\n\n','<?xml-stylesheet type="text/xsl" href="http://www.mathworks.com/namespace/info/v1/info.xsd"?>');
fprintf(fid,'%s\n',['<matlabrelease>',num2str(mrelease),'</matlabrelease>']);
fprintf(fid,'%s\n',['<name>',xml_name,'</name>']);
fprintf(fid,'%s\n',['<type>',area,'</type>']);
fprintf(fid,'%s\n\n',['<icon>',icon_path,'/matlabicon.gif</icon>']);
fprintf(fid,'%s\n\n','<list>');
if ~isempty(xml_start)
fprintf(fid,'%s\n','<listitem>');
fprintf(fid,'%s\n',['<label>Start ',toolbox_name,'</label>']);
fprintf(fid,'%s\n',['<callback>',xml_start,'</callback>']);
fprintf(fid,'%s\n',['<icon>',icon_path,'/figureicon.gif</icon>']);
fprintf(fid,'%s\n\n','</listitem>');
end
fprintf(fid,'%s\n','<listitem>');
fprintf(fid,'%s\n','<label>Help</label>');
if isunix
fprintf(fid,'%s\n',['<callback>helpwin ',install_dirUNIX,'/</callback>']);
else
fprintf(fid,'%s\n',['<callback>helpwin ',install_dirPC,'/</callback>']);
end
fprintf(fid,'%s\n',['<icon>',icon_path,'/bookicon.gif</icon>']);
fprintf(fid,'%s\n\n','</listitem>');
if ~isempty(xml_demo)
fprintf(fid,'%s\n','<listitem>');
fprintf(fid,'%s\n','<label>Demo</label>');
fprintf(fid,'%s\n',['<callback>',xml_demo,'</callback>']);
fprintf(fid,'%s\n',['<icon>',icon_path,'/demoicon.gif</icon>']);
fprintf(fid,'%s\n\n','</listitem>');
end
if ~isempty(xml_web)
fprintf(fid,'%s\n','<listitem>');
fprintf(fid,'%s\n','<label>Product Page (Web)</label>');
fprintf(fid,'%s\n',['<callback>web ',xml_web,' -browser;</callback>']);
fprintf(fid,'%s\n',['<icon>',icon_path,'/webicon.gif</icon>']);
fprintf(fid,'%s\n\n','</listitem>');
end
fprintf(fid,'%s\n\n','</list>');
fprintf(fid,'%s','</productinfo>');
fclose(fid);
end
% make contents file
if ~exist(fullfile(src_dir,'Contents.m'),'file')
disp(' Create Contents.m')
files.m(strcmpi(files.m,'Contents.m')) = [];
files.m(strcmpi(files.m,install_file)) = [];
fid = fopen('Contents.m','w');
fprintf(fid,'%s\n',['% ',toolbox_name]);
fprintf(fid,'%s\n',['% Version ',strrep(num2str(version_number),'v',''),' ',date]);
fprintf(fid,'%s\n','%');
for i = 1:length(files.m)
helptext = help(char(files.m{i}));
ind = findstr(char(10),helptext);
if isempty(ind)
if max_warnings && count_warnings == max_warnings
disp(' ** TOO MUCH WARNINGS!')
disp(' I give up! Following warning messages will be suppressed.')
end
if count_warnings < max_warnings
disp([' ** Warning: ',char(files.m{i}),' does not contain any helptext. It is highly',char(10),' recommended to include a helptext in every M-file.'])
end
count_warnings = count_warnings + 1;
else
helpline = deblank(helptext(1:ind(1)));
[fnname,helpstring] = strtok(helpline(2:length(helpline)));
fnname = fliplr(deblank(fliplr(fnname)));
if ~strcmpi(fnname,strtok(char(files.m{i}),'.'))
if max_warnings && count_warnings == max_warnings
disp(' ** TOO MUCH WARNINGS!')
disp(' I give up! Following warning messages will be suppressed.')
end
if count_warnings < max_warnings
disp([' ** Warning: ',char(files.m{i}),' does not have a valid helptext. Please refer ',char(10),' the Matlab manual for the correct structure of M-files.'])
end
count_warnings = count_warnings + 1;
fnname = lower(strtok(char(files.m{i}),'.'));
end
line = [lower(fnname),blanks(size(char(files.m),2)-length(fnname)-1),'- ',helpstring];
fprintf(fid,'%s\n',['% ', line]);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% this part was suggested by Gaetan Koers (Vrije Universiteit Brussel)
for i = 1:numel(files.classes)
line = [files.classes{i}, ' methods:'];
fprintf(fid,'%%\n%s\n%%\n',['% ', line]);
gk_list = dir(['@', files.classes{i}]);
for j = 1:numel(gk_list)
gk_fname = gk_list(j).name;
if ~gk_list(j).isdir %~strcmp(gk_fname, '.') && ~strcmp(gk_fname, '..')
helptext = help(fullfile(files.classes{i},gk_fname));
ind = findstr(char(10),helptext);
if isempty(ind)
if max_warnings && count_warnings == max_warnings
disp(' ** TOO MUCH WARNINGS!')
disp(' I give up! Following warning messages will be suppressed.')
end
if count_warnings < max_warnings
disp([' ** Warning: ', files.classes{i}, ' method ', char(gk_fname),' does not contain any helptext. It is highly',char(10),' recommended to include a helptext in every M-file.'])
end
count_warnings = count_warnings + 1;
else
helpline = deblank(helptext(1:ind(1)));
[fnname,helpstring] = strtok(helpline(2:length(helpline)));
fnname = fliplr(deblank(fliplr(fnname)));
if ~strcmpi(fnname,strtok(char(gk_fname),'.'))
if max_warnings && count_warnings == max_warnings
disp(' ** TOO MUCH WARNINGS!')
disp(' I give up! Following warning messages will be suppressed.')
end
if count_warnings < max_warnings
disp([' ** Warning: ', files.classes{i}, ' method ',char(gk_fname),' does not have a valid helptext. Please refer ',char(10),' the Matlab manual for the correct structure of M-files.'])
end
count_warnings = count_warnings + 1;
fnname = lower(strtok(char(gk_fname),'.'));
end
line = [lower(fnname),blanks(size(char(files.m),2)-length(fnname)-1),'- ',helpstring];
fprintf(fid,'%s\n',['% ', line]);
end
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fprintf(fid,'\n%s\n\n',['% Generated at ',time_string,' by MAKEINSTALL']);
fclose(fid);
else
% modify contents file
disp(' Modify Contents.m')
fid = fopen('Contents.m','r'); contents = '';
while ~feof(fid)
temp = fgetl(fid);
contents = [contents;{temp}];
end
fclose(fid);
if length(contents) > 1 && isempty(findstr(lower(contents{2}),'version'))
contents(3:end+1) = contents(2:end);
end
if ~strcmp(release,' ') && ~isempty(release), crelease = [' (',release,') ']; end
contents{2} = ['% Version ',strrep(version_number, 'v', ''),crelease,date];
if (isempty(contents{end}) | findstr(contents{end},'Modified at')>0); l = length(contents); else l = length(contents)+1; end
contents{l} = ['% Modified at ',time_string,' by MAKEINSTALL'];
fid = fopen('Contents.m','w');
for i = 1:length(contents)
fprintf(fid,'%s\n',contents{i});
end
fclose(fid);
end
% Update CITATION.cff file if available
if exist(fullfile(src_dir,'CITATION.cff'),'file')
disp(' Modify CITATION.cff')
fid = fopen('CITATION.cff','r'); contents = {};
while ~feof(fid)
temp = fgetl(fid);
contents{end + 1} = temp;
end
fclose(fid);
% find cells with version and release date
matches_version = cellfun(@(x) strncmp(x, 'version:', length('version:')), contents);
matches_date = cellfun(@(x) strncmp(x, 'date-released:', length('date-released:')), contents);
index_version = find(matches_version);
index_date = find(matches_date);
if ~strcmp(release,' ') && ~isempty(release), crelease = [' (',release,')']; end
contents{index_version} = ['version: ''',strrep(version_number, 'v', ''),crelease,''''];
contents{index_date} = ['date-released: ''',datestr(now,'YYYY-mm-dd'),''''];
fid = fopen('CITATION.cff','w');
for i = 1:length(contents)
fprintf(fid,'%s\n',contents{i});
end
fclose(fid);
end
% find sub-directories
dirnames = ''; filenames = '';
temp = '.:';
while ~isempty(temp)
[temp1 temp] = strtok(temp,':');
if ~isempty(temp1)
dirnames = [dirnames; {temp1}];
temp2 = strrep(temp1,'./','');
if isempty(findstr(lower(fliplr(temp2(end-min([3,length(temp2)])+1:end))), 'svc'))
x2 = dir(temp1);
for i = 1:length(x2)
if ~x2(i).isdir, filenames = [filenames; {[temp1,'/', x2(i).name]}]; end
if x2(i).isdir && ~strcmp(x2(i).name,'.') && ~strcmp(x2(i).name,'..'), temp = [temp,temp1,filesep,x2(i).name,':']; end
end
end
end
end
dirnames = strrep(dirnames,filesep,'/');
dirnames = strrep(dirnames,'./','');
filenames = strrep(filenames,filesep,'/');
filenames = strrep(filenames,'./','');
% ignore CVS, svn and git folders
remove = [];
for i = 1:length(dirnames)
if length(dirnames{i}) > 4
test_string = fliplr(dirnames{i});
if strcmpi(test_string(1:min([3,length(test_string)])),fliplr('CVS')), remove = [remove; i]; end
if strcmpi(test_string(1:min([4,length(test_string)])),fliplr('.git')), remove = [remove; i]; end
if strcmpi(test_string(1:min([4,length(test_string)])),fliplr('.svn')), remove = [remove; i]; end
if strcmpi(dirnames{i}(1:min([3,length(dirnames)])),'CVS'), remove = [remove; i]; end
if strcmpi(dirnames{i}(1:min([4,length(dirnames)])),'.git'), remove = [remove; i]; end
if strcmpi(dirnames{i}(1:min([4,length(dirnames)])),'.svn'), remove = [remove; i]; end
end
end
dirnames(remove) = [];
% ignore files specified by variable 'ignore' in makeinstall.rc and
% additionally ignore makeinstall.rc, makeinstall.m, .cvsignore, and similar files
i = 1;
ignore = [ignore, {'makeinstall.m'}, {'makeinstall.rc'}, {'.cvsignore'}, {'.git'}, {'.svn'}, {'.project'}, {'.texlipse'}, {'.sync'}, {'.DS_Store'}, {'.gitignore'}];
while i <= length(filenames)
if i < 1, i = 1; end
[~, curr_file, ext] = fileparts(filenames(i));
if ~include_pfiles
if strcmpi(ext, '.p'), filenames(i) = []; i = i-1; end,
end
for j = 1:length(ignore)
if(strcmp('.gitignore', ignore{j}))
end
if ~isempty(findstr(ignore{j},filenames{i}))
if i>=1
filenames(i) = [];
i = i-1;
if i < 1, i = 1; end
end
continue
end
end
i = i+1;
end
% read the toolbox files
i = 0;
while i <= length(filenames),
i = i+1;
if i>length(filenames), break, end
if strcmp(filenames{i},'.') | strcmp(filenames{i},'..') | strcmpi(filenames{i},install_file) | strcmpi(filenames{i},'install.m') | strncmpi(filenames{i},'private/.bsd',12)
filenames(i) = []; i = i-1;
end
end
b = []; c = []; bfile = '';
for i = 1:length(filenames)
[~, curr_file, ext] = fileparts(filenames(i));
disp([' Reading ', char(filenames{i}),''])
fid = fopen(char(filenames{i}),'r');
% ASCII data
if ...
strcmpi(ext,'.txt') || ...
strcmpi(ext,'.csv') || ...
strcmpi(ext,'.dat') || ...
strcmpi(ext,'.tex') || ...
strcmpi(ext,'.m') || ...
strcmpi(ext,'.mdl') || ...
strcmpi(ext,'.md') || ...
strcmpi(ext,'.rc') || ...
strcmpi(ext,'.xml') || ...
strcmpi(ext,'.css') || ...
strcmpi(ext,'.log') || ...
strcmpi(ext,'.js') || ...
strcmpi(ext,'.html') || ...
strcmpi(ext,'.htm')
c = [c, ['%<-- ASCII begins here: __',char(filenames{i}),'__ -->'], 10];
in = char(fread(fid)');
in = strrep(in,[char(10),char(13)],char(10));
in = strrep(in,[char(13),char(10)],char(10));
in = strrep(in,char(10),[char(10),'%@']);
in = strrep(in,char(13),[char(10),'%@']);
% while 1
% temp = fgetl(fid);
% if ~ischar(temp), break
% else
c = [c, ['%@',in],10];
% end
% end
c = [c, '%<-- ASCII ends here -->', 10];
% binary data
else
clear temp
bfile = [bfile; filenames(i)];
temp_in = fread(fid);
if ~isempty(temp_in)
temp(2,:) = temp_in';
end
temp(1,:) = '%';
temp = temp(:);
btemp = temp';
b = [b, ['%<-- Binary begins here: __',char(filenames(i)),'__ __',num2str(length(btemp)),'__ -->',10]];
b = [b, btemp, 10];
b = [b, ['%<-- Binary ends here -->',10]];
end
fclose(fid);
end
% compute a checksum
c = double([c, b]);
checksum = dec2hex(sum((1:length(c)).*c));
disp([' Checksum is ', checksum,''])
% write the archiv into the install file
disp([' Writing ', install_file,''])
fid = fopen(fullfile(olddir,install_file),'a');
fprintf(fid,'%s\n','% -------------------------------------------');
fprintf(fid,'%s\n','% GENERATED ENTRIES - DO NOT MODIFY ANYTHING!');
fprintf(fid,'%s\n','%<-- Header begins here -->');
fprintf(fid,'%s\n',['%@',checksum]);
fprintf(fid,'%s\n',['%@',time_string]);
fprintf(fid,'%s\n',['%@',version_number, release]);
fprintf(fid,'%s\n','%<-- Header ends here -->');
fwrite(fid,c);
fclose(fid);
cd(olddir)
else
% make makeinstall.rc file
if isempty(toolbox_name), [dummy toolbox_name] = fileparts(pwd); end
fid = fopen(rc_file,'w');
if fid ~= -1
warning on
disp(' ** Warning: Could not find the makeinstall resource file.')
disp(' Creating now the makeinstall resource file.')
disp(' Please modify the entries in ')
disp([' ',rc_file])
disp(' and restart if you would like to use other than the default')
disp(' settings. Now automatically restart with default settings.')
fprintf(fid,'%s\n\n','% modify the following lines for your purpose');
fprintf(fid,'%s\n\n',['toolbox_name=''',toolbox_name,'''; % name of the toolbox']);
fprintf(fid,'%s\n','install_file=''install.m''; % name of the install script');
fprintf(fid,'%s\n','deinstall_file=''tbclean.m''; % name of the deinstall script');
fprintf(fid,'%s\n','old_dirs=''''; % possible old (obsolete) toolbox folders');
fprintf(fid,'%s\n','ignore=''''; % files and folders to be ignored');
fprintf(fid,'%s\n','install_path=''''; % the root folder where the toolbox folder will be located (default is $USER$/matlab or $MATLABROOT$/toolbox, or $USERS$/octave when installing for Octave)');
fprintf(fid,'%s\n',['install_dirUNIX=''',toolbox_name,'''; % the folder where the toolbox files will be extracted (UNIX)']);
fprintf(fid,'%s\n','install_dirPC=install_dirUNIX; % the folder where the toolbox files will be extracted (PC)');
fprintf(fid,'%s\n',['src_dir=''',pwd,'''; % folder with the origin toolbox (optional, can be empty)']);
fprintf(fid,'%s\n\n','pc_only=0; % switch to 1 only if the toolbox is not working under Linux or Mac');
fprintf(fid,'%s\n\n','include_pfiles=0; % switch to ignore (=0) or include (=1) Matlab p-files');
fprintf(fid,'%s\n','version_file=''''; % there are two options: (1) include in the specified file a line like this (e.g. CVS or SVN like): % $Revision$; or (2) just write "git" here and the makeinstall will automatically use the latest GIT tag for the version number');
fprintf(fid,'%s\n','version_number=''''; % or put the version number in this variable');
fprintf(fid,'%s\n','release=''''; % the release number');
fprintf(fid,'%s\n\n','infostring=''''; % further information displayed during installation');
fprintf(fid,'%s\n','% if the info.xml does not yet exist it will be created with the following');
fprintf(fid,'%s\n','% parameters; else these parameters have no effect');
fprintf(fid,'%s\n',['xml_name=''',toolbox_name,'''; % name of the toolbox for the launch pad entry']);
fprintf(fid,'%s\n','xml_start=''''; % start programme for the launch pad entry');
fprintf(fid,'%s\n','xml_demo=''''; % demo programme for the launch pad entry');
fprintf(fid,'%s\n','xml_web=''''; % link to the toolbox web site in the launch pad entry');
fclose(fid);
restart = 1;
else
disp('Sorry. A problem during file system access occurred.')
error('Could not open the makeinstall resource file.')
end
cd(olddir)
end % end main part
end % end check 'bsd'
warning on
if restart, makeinstall(varargin{:}), end
% --------------------------------
% GENERATED ENTRIES - DO NOT EDIT!
%<-- ASCII begins here: install -->
%@function install(varargin)
%@% INSTALL Install script for $toolboxname$.
%@% INSTALL creates the $toolboxname$ folder and (optionally)
%@% the needed entries in the startup.m file.
%@%
%@% INSTALL PATH creates the $toolboxname$ folder
%@% in the specified PATH.
%@%
%@% This installation script was generated by using
%@% the MAKEINSTALL tool. For further information
%@% visit http://matlab.pucicu.de
%@
%@% Copyright (c) 2008-2018
%@% Norbert Marwan, Potsdam Institute for Climate Impact Research, Germany
%@% http://www.pik-potsdam.de
%@%
%@% Copyright (c) 2001-2008
%@% Norbert Marwan, Potsdam University, Germany
%@% http://www.agnld.uni-potsdam.de
%@%
%@% THIS IS A GENERATED INSTALL-FILE, DO NOT EDIT!
%@% Generation date: $generation_date$
%@% $Date$
%@% $Revision$
%@
%@install_file='';install_path='$installpath$';installfile_info.date='';installfile_info.bytes=[];
%@time_stamp='';checksum='';checksum_file=''; instpaths = '';
%@errcode=0;
%@
%@ $pc_only$
%@
%@try
%@ warning('off')
%@ if isoctave
%@ disp([' You are trying to install the toolbox in Octave.',10,' Some compatibility issues might appear.'])
%@ warning('off','Octave:possible-matlab-short-circuit-operator')
%@ more off
%@ end
%@ if nargin
%@ install_path = varargin{1};
%@ end
%@
%@ if exist('install.log','file') == 2, delete('install.log'), end
%@ %rehash
%@ disp('$lines$')
%@ disp(' INSTALLATION $toolboxname$');
%@ disp('$lines$')
%@ install_file=[mfilename,'.m'];
%@ currentpath=pwd; time_stamp='time_stamp not yet obtained'; checksum='checksum not yet obtained';
%@ fid = 0;
%@
%@%%%%%%% read the archive
%@%%%%%%% and look for checksum and date in archive
%@ errcode=90;
%@ disp(' Reading the archiv ')
%@ fid=fopen(install_file,'r');
%@ fseek(fid,0,'eof'); eofbyte=ftell(fid);
%@ fseek(fid,$startbyte$,'bof'); % location where the container starts
%@ while ~feof(fid)
%@ temp=fgetl(fid);
%@ startbyte=ftell(fid);
%@ if length(temp)>1
%@ if strcmpi(temp,'%<-- Header begins here -->')
%@ errcode=90.1;
%@ checksum=fgetl(fid);
%@ temp1=fgetl(fid);
%@ temp2=fgetl(fid);
%@ end
%@ if strcmpi(temp,'%<-- Header ends here -->')
%@ startbyte=ftell(fid);
%@ break
%@ end
%@ end
%@ end
%@ checksum(1:2)=[];
%@ fseek(fid,startbyte,'bof');
%@ errcode=90.2;
%@ A=fread(fid,eofbyte);
%@ errcode=90.3;
%@ checksum_file=dec2hex(sum((1:length(A))'.*A));
%@ if ~strcmpi(checksum_file,checksum)
%@ error(['The installation file is corrupt!',10,'Ensure that the archive container was ',...
%@ 'not modified (check FTP/ ',10,'proxy/ firewall settings, anti-virus scanner for emails etc.)!'])
%@ else
%@ disp([' Checksum test passed (', checksum,')'])
%@ end
%@ fclose(fid);
%@
%@ disp([' $toolboxname$ version ', temp2(3:end),''])
%@ time_stamp=temp1(3:end); disp([' $toolboxname$ time stamp ', time_stamp,'']);
%@
%@ errcode=91;
%@ if isunix
%@ toolboxpath='$toolboxdirunix$';
%@ else
%@ toolboxpath='$toolboxdirpc$';
%@ end
%@
%@
%@%%%%%%% check for older versions
%@
%@ p=path; i1=0;
%@ rem_old = '';
%@
%@ while any($check_for_old$>i1) && ~strcmpi('N',rem_old)
%@ errcode=92;
%@ i1=$check_for_old$;
%@ if ~isempty(i1)
%@ i1=i1(1);
%@ if isunix, i2=findstr(':',p); else i2=findstr(';',p); end
%@ i3=i2(i2>i1); % last index pathname
%@ if ~isempty(i3), i3=i3(1)-1; else i3=length(p); end
%@ i4=i2(i2<i1); % first index pathname
%@ if ~isempty(i4), i4=i4(end)+1; else i4=1; end
%@ oldtoolboxpath=p(i4:i3);
%@ if isempty(rem_old)
%@ disp([' Old $toolboxname$ found in ', oldtoolboxpath,''])
%@ rem_old = input('> Delete old toolbox? Y/N [Y]: ','s');
%@ end
%@ if isempty(rem_old), rem_old = 'Y'; end
%@ if strcmpi('Y',rem_old)
%@%%%%%%% removing old entries in startup-file
%@ errcode=94;
%@ rmpath(oldtoolboxpath)
%@ err = savepath;
%@ if err, disp(' ** Warning: No write access to pathdef.m file!'), end
%@ if i4>1, p(i4-1:i3)=''; else p(i4:i3)=''; end
%@ startup_exist = exist('startup','file');
%@ if isoctave startup_exist = exist(fullfile('~','.octaverc'),'file'); end
%@ if startup_exist
%@ startupfile=which('startup');
%@ startuppath=startupfile(1:findstr('startup.m',startupfile)-1);
%@ if isoctave
%@ startuppath = ['~',filesep];
%@ startupfile = fullfile('~','.octaverc');
%@ end
%@ errcode=94.1;
%@ if ~isunix
%@ if isoctave
%@ toolboxroot=fullfile(matlabroot);
%@ else
%@ toolboxroot=fullfile(matlabroot,'toolbox');
%@ end
%@ curr_pwd = pwd; home_pwd = matlabroot;
%@ else
%@ toolboxroot=startuppath;
%@ curr_pwd = pwd; cd ('~'); home_pwd = pwd; cd(curr_pwd);
%@ end
%@ fid = fopen(startupfile,'r');
%@ k = 1;
%@ while ~feof(fid)
%@ tmp = fgetl(fid);
%@ instpaths{k} = tmp;
%@ k = k + 1;
%@ end
%@ fclose(fid);
%@ k=1;
%@ while k <= length(instpaths)
%@ if findstr(oldtoolboxpath,strrep(instpaths{k},'~',home_pwd))
%@ errcode=94.2;
%@ instpaths(k)=[];
%@ else
%@ k=k+1;
%@ end
%@ end
%@ fid=fopen(startupfile,'w');
%@ errcode=94.3;
%@ if fid < 0
%@ disp([' ** Warning: Could not get access to ',startupfile,'.']);
%@ disp(' ** Could not remove toolbox from the startup.m file.');
%@ disp(' ** Ensure that you have write access!');
%@ else
%@ for i2=1:length(instpaths),
%@ fprintf(fid,'%s\n', char(instpaths{i2}));
%@ end
%@ fclose(fid);
%@ end
%@ end
%@%%%%%%% removing old paths
%@ errcode=93;
%@ if exist(oldtoolboxpath,'dir') == 7
%@ disp([' Change to ',oldtoolboxpath,''])
%@ cd(oldtoolboxpath)
%@ dirnames='';filenames='';
%@ temp='.:';
%@ errcode=93.1;
%@ while ~isempty(temp)
%@ [temp1 temp]=strtok(temp,':');
%@ if ~isempty(temp1)
%@ dirnames=[dirnames; {temp1}];
%@ x2=dir(temp1);
%@ for i=1:length(x2)
%@ if ~x2(i).isdir, filenames=[filenames; {[temp1,'/', x2(i).name]}]; end
%@ if x2(i).isdir && ~strcmp(x2(i).name,'.') && ~strcmp(x2(i).name,'..'), temp=[temp,temp1,filesep,x2(i).name,':']; end
%@ end