Merge remote-tracking branch 'origin/6.1'
[scilab.git] / scilab / modules / dynamic_link / macros / ilib_gen_cleaner.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) DIGITEO - 2009-2011 - Allan CORNET
3 //
4 // Copyright (C) 2012 - 2016 - Scilab Enterprises
5 //
6 // This file is hereby licensed under the terms of the GNU GPL v2.0,
7 // pursuant to article 5.3.4 of the CeCILL v.2.1.
8 // This file was originally licensed under the terms of the CeCILL v2.1,
9 // and continues to be available under such terms.
10 // For more information, see the COPYING file which you should have received
11 // along with this program.
12 //=============================================================================
13 function ilib_gen_cleaner(makename,loadername,files)
14
15     [lhs,rhs] = argn(0);
16
17     if (rhs < 1) then
18         makename = "makelib";
19     end
20
21     if (rhs < 2) then
22         loadername = "loader.sce";
23     end
24
25     if (rhs < 3) then
26         files = [];
27     end
28
29     cleanername = "cleaner.sce";
30
31     fd = mopen(cleanername,"wt");
32     mfprintf(fd,"// This file is released under the 3-clause BSD license. See COPYING-BSD.\n");
33     mfprintf(fd,"// Generated by builder.sce : Please, do not edit this file\n");
34     mfprintf(fd,"// cleaner.sce\n");
35     mfprintf(fd,"// ------------------------------------------------------\n");
36     mfprintf(fd,"curdir = pwd();\n");
37     mfprintf(fd,"cleaner_path = get_file_path(''cleaner.sce'');\n");
38     mfprintf(fd,"chdir(cleaner_path);\n");
39     mfprintf(fd,"// ------------------------------------------------------\n");
40     mfprintf(fd,"if fileinfo(''%s'') <> [] then\n",loadername);
41     mfprintf(fd,"  mdelete(''%s'');\n",loadername);
42     mfprintf(fd,"end\n");
43     mfprintf(fd,"// ------------------------------------------------------\n");
44
45     if getos() == "Windows" then
46         // Load dynamic_link Internal lib if it"s not already loaded
47         if ~ exists("dynamic_linkwindowslib") then
48             load("SCI/modules/dynamic_link/macros/windows/lib");
49         end
50
51         dlwGenerateCleaner(fd, makename);
52     end
53
54     if getos() == "Windows" then
55         mfprintf(fd,"if isdir(''Debug'') then\n");
56         mfprintf(fd,"  rmdir(''Debug'',''s'');\n");
57         mfprintf(fd,"end\n");
58         mfprintf(fd,"// ------------------------------------------------------\n");
59         mfprintf(fd,"if isdir(''Release'') then\n");
60         mfprintf(fd,"  rmdir(''Release'',''s'');\n");
61         mfprintf(fd,"end\n");
62         mfprintf(fd,"// ------------------------------------------------------\n");
63     end
64
65     if files <> [] then
66         for i = 1:size(files,"*")
67             if ( files(i) <> "" ) then
68                 mfprintf(fd,"if fileinfo(''%s'') <> [] then\n", files(i));
69                 mfprintf(fd,"  mdelete(''%s'');\n", files(i));
70                 mfprintf(fd,"end\n");
71                 mfprintf(fd,"// ------------------------------------------------------\n");
72             end
73         end
74     end
75
76     mfprintf(fd,"chdir(curdir);\n");
77     mfprintf(fd,"// ------------------------------------------------------\n");
78     mclose(fd);
79
80     if ilib_verbose() > 1 then
81         disp(mgetl("cleaner.sce"));
82     end
83 endfunction
84 //=============================================================================