1f6ecf2ccb39b4ff5a726ef9930aae6c8c30e82c
[scilab.git] / scilab / modules / modules_manager / macros / tbx_build_cleaner.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2009-2010 - DIGITEO - Allan CORNET
3 // Copyright (C) 2010 - DIGITEO - Pierre MARECHAL
4 //
5 // This file must be used under the terms of the CeCILL.
6 // This source file is licensed as described in the file COPYING, which
7 // you should have received as part of this distribution.  The terms
8 // are also available at
9 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
10
11 // Generate a cleaner.sce script for the toolbox
12
13 function tbx_build_cleaner(name,path)
14
15     rhs = argn(2);
16
17     // Number of input arguments
18
19     if and(rhs <> [1 2]) then
20         error(msprintf(gettext("%s: Wrong number of input arguments: %d to %d expected.\n"),"tbx_build_cleaner",1,2));
21     end
22
23     // Input argument N°1
24     // → name
25
26     if type(name) <> 10 then
27         error(msprintf(gettext("%s: Wrong type for input argument #%d: A string expected.\n"),"tbx_build_cleaner",1));
28     end
29
30     if size(name,"*") <> 1 then
31         error(msprintf(gettext("%s: Wrong size for input argument #%d: A string expected.\n"),"tbx_build_cleaner",1));
32     end
33
34     // Input argument N°2
35     // → path
36
37     if rhs < 2 then
38         path = pwd();
39
40     else
41         if type(path) <> 10 then
42             error(msprintf(gettext("%s: Wrong type for input argument #%d: A string expected.\n"),"tbx_build_cleaner",2));
43         end
44
45         if size(path,"*") <> 1 then
46             error(msprintf(gettext("%s: Wrong size for input argument #%d: A string expected.\n"),"tbx_build_cleaner",2));
47         end
48
49         if ~isdir(path) then
50             error(msprintf(gettext("%s: The directory ''%s'' doesn''t exist or is not read accessible.\n"),"tbx_build_cleaner",path));
51         end
52     end
53
54     // build the cleaner file
55
56     mprintf(gettext("Generating cleaner.sce...\n"));
57
58     cleanertxt = [
59         "// This file is released under the 3-clause BSD license. See COPYING-BSD.",
60         "// Generated by builder.sce: Please, do not edit this file",
61         "",
62         "try",
63         "    getversion(""scilab"");",
64         "catch",
65         "    error(""Scilab 5.0 or more is required."");",
66         "end",
67         "function perform_clean()",
68         "    root_tlbx = get_absolute_file_path(''cleaner.sce'');",
69         "",
70         "    if isfile(root_tlbx + ''/macros/cleanmacros.sce'') then",
71         "        exec(root_tlbx+''/macros/cleanmacros.sce'');",
72         "    end",
73         "",
74         "    if isfile(root_tlbx + ''/src/cleaner_src.sce'') then",
75         "        exec(root_tlbx+''/src/cleaner_src.sce'');",
76         "    end",
77         "",
78         "    if isfile(root_tlbx + ""/sci_gateway/cleaner_gateway.sce"") then",
79         "        exec(root_tlbx + ""/sci_gateway/cleaner_gateway.sce"");",
80         "        mdelete(root_tlbx + ""/sci_gateway/cleaner_gateway.sce"");",
81         "     end",
82         "",
83         "    if isfile(root_tlbx + ""/help/cleaner_help.sce"") then",
84         "        exec(root_tlbx + ""/help/cleaner_help.sce"");",
85         "    end",
86         "",
87         "    if isfile(root_tlbx + ""/loader.sce"") then",
88         "        mdelete(root_tlbx + ""/loader.sce"");",
89         "    end",
90         "endfunction",
91         "perform_clean();",
92         "clear perform_clean;"];
93
94     cleanerfile = pathconvert(path+"/cleaner.sce",%F);
95
96     if ~mputl(cleanertxt,cleanerfile) then
97         error(msprintf(gettext("%s: The file %s cannot been created, please check if you have write access on this file.\n"),"tbx_build_cleaner",cleanerfile));
98     end
99
100 endfunction