root/branches/bud/sss/install.d

Revision 248, 6.2 kB (checked in by Gregor, 2 years ago)

sss/build.d, sss/clean.d, sss/conf.d, sss/install.d, docs/README.software_engineers: Support for eval, set and add.

sss/build.d: Carry over buildflags in subdir builds.

Line 
1 /**
2  * DSSS command "install"
3  *
4  * Authors:
5  *  Gregor Richards
6  *
7  * License:
8  *  Copyright (c) 2006  Gregor Richards
9  * 
10  *  Permission is hereby granted, free of charge, to any person obtaining a
11  *  copy of this software and associated documentation files (the "Software"),
12  *  to deal in the Software without restriction, including without limitation
13  *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  *  and/or sell copies of the Software, and to permit persons to whom the
15  *  Software is furnished to do so, subject to the following conditions:
16  * 
17  *  The above copyright notice and this permission notice shall be included in
18  *  all copies or substantial portions of the Software.
19  * 
20  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21  *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23  *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  *  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  *  DEALINGS IN THE SOFTWARE.
27  */
28
29 module sss.install;
30
31 import std.file;
32 import std.stdio;
33 import std.string;
34
35 import hcf.path;
36 import hcf.process;
37
38 import sss.conf;
39
40 /** Entry into the "install" command */
41 int install(char[][] buildElems, char[][]* subManifest = null)
42 {
43     // get the configuration
44     DSSSConf conf = readConfig(buildElems);
45    
46     // get the corresponding sources
47     char[][] buildSources = sourcesByElems(buildElems, conf);
48    
49     // prepare to make a manifest
50     char[][] manifest;
51     char[] manifestFile;
52     manifestFile = manifestPrefix ~ std.path.sep ~ conf.settings[""]["name"] ~ ".manifest";
53     manifest ~= "share" ~ std.path.sep ~ "dsss" ~ std.path.sep ~ "manifest" ~ std.path.sep ~
54         conf.settings[""]["name"] ~ ".manifest";
55    
56     /// Copy in the file and add it to the manifest
57     void copyAndManifest(char[] file, char[] prefix, char[] from = "")
58     {
59         copyInFile(file, prefix, from);
60        
61         // if the prefix starts with the installation prefix, strip it
62         if (prefix.length > forcePrefix.length &&
63             prefix[0..forcePrefix.length] == forcePrefix)
64             prefix = prefix[forcePrefix.length + 1 .. $];
65        
66         manifest ~= prefix ~ std.path.sep ~ file;
67     }
68    
69     // now install the requested things
70     foreach (build; buildSources) {
71         char[][char[]] settings = conf.settings[build];
72        
73         // basic info
74         char[] type = settings["type"];
75         char[] target = settings["target"];
76        
77         // say what we're doing
78         writefln("Installing %s", target);
79        
80         // do preinstall
81         if ("preinstall" in settings) {
82             manifest ~= dsssScriptedStep(conf, settings["preinstall"]);
83         }
84        
85         // figure out what it is
86         if (type == "library") {
87             // far more complicated
88            
89             // 1) copy in library files
90             version (GNU_or_Posix) {
91                 // copy in the .a and .so/.dll files
92                
93                 // 1) .a
94                 copyAndManifest("libS" ~ target ~ ".a", libPrefix);
95                
96                 char[] shlibname = getShLibName(settings);
97                
98                 if (shLibSupport() &&
99                     ("shared" in settings)) {
100                     version (Posix) {
101                         // 2) .so
102                         char[][] shortshlibnames = getShortShLibNames(settings);
103                
104                         // copy in
105                         copyAndManifest(shlibname, libPrefix);
106                
107                         // make softlinks
108                         foreach (ssln; shortshlibnames) {
109                             // make it
110                             saySystemDie("ln -sf " ~ shlibname ~ " " ~
111                                          libPrefix ~ std.path.sep ~ ssln);
112                             manifest ~= libPrefix ~ std.path.sep ~ ssln;
113                         }
114                     } else version (Windows) {
115                         // 2) .dll
116                         copyAndManifest(shlibname, libPrefix);
117                     } else {
118                         static assert(0);
119                     }
120                 }
121             } else version (Windows) {
122                 // copy in the .lib and .dll files
123                
124                 // 1) .lib
125                 copyAndManifest("S" ~ target ~ ".lib", libPrefix);
126                
127                 char[] shlibname = getShLibName(settings);
128                
129                 if (shLibSupport() &&
130                     ("shared" in settings)) {
131                     // 2) .dll
132                     copyAndManifest(shlibname, libPrefix);
133                 }
134             } else {
135                 static assert(0);
136             }
137            
138             // 2) generate .di files
139             char[][] srcFiles = targetToFiles(build, conf);
140             foreach (file; srcFiles) {
141                 // install the .di file
142                 copyAndManifest(getBaseName(file ~ "i"),
143                                 includePrefix ~ std.path.sep ~ getDirName(file),
144                                 getDirName(file) ~ std.path.sep);
145             }
146            
147         } else if (type == "binary") {
148             // fairly easy
149             version (Posix) {
150                 copyAndManifest(target, binPrefix);
151             } else {
152                 copyAndManifest(target ~ ".exe", binPrefix);
153             }
154         } else if (type == "subdir") {
155             // recurse
156             char[] origcwd = getcwd();
157             chdir(build);
158             int installret = install(null, &manifest);
159             if (installret) return installret;
160             chdir(origcwd);
161         }
162        
163         // do postinstall
164         if ("postinstall" in settings) {
165             manifest ~= dsssScriptedStep(conf, settings["postinstall"]);
166         }
167        
168         // install the manifest itself
169         if (subManifest) {
170             (*subManifest) ~= manifest;
171         } else {
172             mkdirP(manifestPrefix);
173             std.file.write(manifestFile, std.string.join(manifest, "\n") ~ "\n");
174         }
175        
176         // extra line for clarity
177         writefln("");
178     }
179    
180     return 0;
181 }
Note: See TracBrowser for help on using the browser.