| 1 |
/** |
|---|
| 2 |
* Main DSSS entry location |
|---|
| 3 |
* |
|---|
| 4 |
* Authors: |
|---|
| 5 |
* Gregor Richards |
|---|
| 6 |
* |
|---|
| 7 |
* License: |
|---|
| 8 |
* Copyright (c) 2006, 2007 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.main; |
|---|
| 30 |
|
|---|
| 31 |
import std.file; |
|---|
| 32 |
import std.path; |
|---|
| 33 |
import std.stdio; |
|---|
| 34 |
import std.string; |
|---|
| 35 |
|
|---|
| 36 |
import sss.build; |
|---|
| 37 |
import sss.clean; |
|---|
| 38 |
import sss.conf; |
|---|
| 39 |
import sss.genconfig; |
|---|
| 40 |
import sss.install; |
|---|
| 41 |
import sss.net; |
|---|
| 42 |
import sss.uninstall; |
|---|
| 43 |
|
|---|
| 44 |
const char[] DSSS_VERSION = "0.13"; |
|---|
| 45 |
|
|---|
| 46 |
private { |
|---|
| 47 |
/** Possible commands */ |
|---|
| 48 |
enum cmd_t { |
|---|
| 49 |
NONE, |
|---|
| 50 |
BUILD, |
|---|
| 51 |
CLEAN, |
|---|
| 52 |
DISTCLEAN, |
|---|
| 53 |
INSTALL, |
|---|
| 54 |
UNINSTALL, |
|---|
| 55 |
INSTALLED, |
|---|
| 56 |
NET, |
|---|
| 57 |
GENCONFIG |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
/** The command in use */ |
|---|
| 61 |
cmd_t command; |
|---|
| 62 |
} |
|---|
| 63 |
|
|---|
| 64 |
int main(char[][] args) |
|---|
| 65 |
{ |
|---|
| 66 |
bool commandSet = false; |
|---|
| 67 |
|
|---|
| 68 |
/** Elements to build/install/something */ |
|---|
| 69 |
char[][] buildElems; |
|---|
| 70 |
|
|---|
| 71 |
for (int i = 1; i < args.length; i++) { |
|---|
| 72 |
char[] arg = args[i]; |
|---|
| 73 |
|
|---|
| 74 |
/** A simple function to check for any help-type option */ |
|---|
| 75 |
bool argIsHelp() { |
|---|
| 76 |
return (arg == "--help" || |
|---|
| 77 |
arg == "-help" || |
|---|
| 78 |
arg == "-h" || |
|---|
| 79 |
arg == "-?"); |
|---|
| 80 |
} |
|---|
| 81 |
|
|---|
| 82 |
/** Parse an argument */ |
|---|
| 83 |
bool parseArg(char[] arg, char[] expect, bool takesVal, char[]* val = null) { |
|---|
| 84 |
if (takesVal) { |
|---|
| 85 |
if (arg.length > expect.length + 2 && |
|---|
| 86 |
arg[0 .. (expect.length + 3)] == "--" ~ expect ~ "=") { |
|---|
| 87 |
*val = arg[(expect.length + 3) .. $]; |
|---|
| 88 |
return true; |
|---|
| 89 |
} else if (arg.length > expect.length + 1 && |
|---|
| 90 |
arg[0 .. (expect.length + 2)] == "-" ~ expect ~ "=") { |
|---|
| 91 |
*val = arg[(expect.length + 2) .. $]; |
|---|
| 92 |
return true; |
|---|
| 93 |
} |
|---|
| 94 |
return false; |
|---|
| 95 |
} else { |
|---|
| 96 |
if (arg == "--" ~ expect || |
|---|
| 97 |
arg == "-" ~ expect) return true; |
|---|
| 98 |
return false; |
|---|
| 99 |
} |
|---|
| 100 |
} |
|---|
| 101 |
|
|---|
| 102 |
if (!commandSet) { |
|---|
| 103 |
// no command set yet, DSSS options |
|---|
| 104 |
if (argIsHelp()) { |
|---|
| 105 |
usage(); |
|---|
| 106 |
return 0; |
|---|
| 107 |
|
|---|
| 108 |
} else if (arg == "build") { |
|---|
| 109 |
commandSet = true; |
|---|
| 110 |
command = cmd_t.BUILD; |
|---|
| 111 |
|
|---|
| 112 |
} else if (arg == "clean") { |
|---|
| 113 |
commandSet = true; |
|---|
| 114 |
command = cmd_t.CLEAN; |
|---|
| 115 |
|
|---|
| 116 |
} else if (arg == "distclean") { |
|---|
| 117 |
commandSet = true; |
|---|
| 118 |
command = cmd_t.DISTCLEAN; |
|---|
| 119 |
|
|---|
| 120 |
} else if (arg == "install") { |
|---|
| 121 |
commandSet = true; |
|---|
| 122 |
command = cmd_t.INSTALL; |
|---|
| 123 |
|
|---|
| 124 |
} else if (arg == "uninstall") { |
|---|
| 125 |
commandSet = true; |
|---|
| 126 |
command = cmd_t.UNINSTALL; |
|---|
| 127 |
|
|---|
| 128 |
} else if (arg == "installed") { |
|---|
| 129 |
commandSet = true; |
|---|
| 130 |
command = cmd_t.INSTALLED; |
|---|
| 131 |
|
|---|
| 132 |
} else if (arg == "net") { |
|---|
| 133 |
commandSet = true; |
|---|
| 134 |
command = cmd_t.NET; |
|---|
| 135 |
|
|---|
| 136 |
} else if (arg == "genconfig") { |
|---|
| 137 |
commandSet = true; |
|---|
| 138 |
command = cmd_t.GENCONFIG; |
|---|
| 139 |
|
|---|
| 140 |
} |
|---|
| 141 |
|
|---|
| 142 |
} else if (command == cmd_t.GENCONFIG || |
|---|
| 143 |
command == cmd_t.UNINSTALL) { |
|---|
| 144 |
/* commands with no special options (put them in their own else-if |
|---|
| 145 |
* if they gain options */ |
|---|
| 146 |
if (argIsHelp()) { |
|---|
| 147 |
usage(); |
|---|
| 148 |
return 0; |
|---|
| 149 |
|
|---|
| 150 |
} else { |
|---|
| 151 |
// a binary or library |
|---|
| 152 |
buildElems ~= arg; |
|---|
| 153 |
} |
|---|
| 154 |
|
|---|
| 155 |
} else if (command == cmd_t.CLEAN || |
|---|
| 156 |
command == cmd_t.DISTCLEAN || |
|---|
| 157 |
command == cmd_t.INSTALLED) { |
|---|
| 158 |
/* commands that take no options whatsoever */ |
|---|
| 159 |
if (argIsHelp()) { |
|---|
| 160 |
usage(); |
|---|
| 161 |
return 0; |
|---|
| 162 |
|
|---|
| 163 |
} else { |
|---|
| 164 |
writefln("ERROR: Command takes no arguments."); |
|---|
| 165 |
} |
|---|
| 166 |
|
|---|
| 167 |
} else if (command == cmd_t.NET) { |
|---|
| 168 |
// dsss net takes both --prefix and --use |
|---|
| 169 |
char[] val; |
|---|
| 170 |
|
|---|
| 171 |
if (argIsHelp()) { |
|---|
| 172 |
usage(); |
|---|
| 173 |
return 0; |
|---|
| 174 |
|
|---|
| 175 |
} else if (parseArg(arg, "use", true, &val)) { |
|---|
| 176 |
// force a use-dir |
|---|
| 177 |
useDirs ~= val; |
|---|
| 178 |
|
|---|
| 179 |
} else if (parseArg(arg, "prefix", true, &val)) { |
|---|
| 180 |
// force a prefix |
|---|
| 181 |
forcePrefix = val; |
|---|
| 182 |
|
|---|
| 183 |
} else if (arg.length >= 1 && |
|---|
| 184 |
arg[0] == '-') { |
|---|
| 185 |
// pass through to build |
|---|
| 186 |
dsss_buildOptions ~= arg ~ " "; |
|---|
| 187 |
|
|---|
| 188 |
} else { |
|---|
| 189 |
buildElems ~= arg; |
|---|
| 190 |
|
|---|
| 191 |
} |
|---|
| 192 |
|
|---|
| 193 |
} else if (command == cmd_t.BUILD) { |
|---|
| 194 |
char[] val; |
|---|
| 195 |
|
|---|
| 196 |
if (argIsHelp()) { |
|---|
| 197 |
usage(); |
|---|
| 198 |
return 0; |
|---|
| 199 |
|
|---|
| 200 |
} else if (parseArg(arg, "use", true, &val)) { |
|---|
| 201 |
// force a use-dir |
|---|
| 202 |
useDirs ~= val; |
|---|
| 203 |
|
|---|
| 204 |
} else if (arg.length >= 1 && |
|---|
| 205 |
arg[0] == '-') { |
|---|
| 206 |
// pass through to build |
|---|
| 207 |
dsss_buildOptions ~= arg ~ " "; |
|---|
| 208 |
|
|---|
| 209 |
} else { |
|---|
| 210 |
buildElems ~= arg; |
|---|
| 211 |
|
|---|
| 212 |
} |
|---|
| 213 |
|
|---|
| 214 |
} else if (command == cmd_t.INSTALL) { |
|---|
| 215 |
char[] val; |
|---|
| 216 |
|
|---|
| 217 |
if (argIsHelp()) { |
|---|
| 218 |
usage(); |
|---|
| 219 |
return 0; |
|---|
| 220 |
|
|---|
| 221 |
} else if (parseArg(arg, "prefix", true, &val)) { |
|---|
| 222 |
// force a prefix |
|---|
| 223 |
forcePrefix = val; |
|---|
| 224 |
|
|---|
| 225 |
} else { |
|---|
| 226 |
buildElems ~= arg; |
|---|
| 227 |
} |
|---|
| 228 |
} |
|---|
| 229 |
} |
|---|
| 230 |
|
|---|
| 231 |
if (!commandSet) { |
|---|
| 232 |
usage(); |
|---|
| 233 |
return 0; |
|---|
| 234 |
} |
|---|
| 235 |
|
|---|
| 236 |
// Before running anything, get our prefix |
|---|
| 237 |
getPrefix(args[0]); |
|---|
| 238 |
|
|---|
| 239 |
// add useDirs |
|---|
| 240 |
foreach (dir; useDirs) { |
|---|
| 241 |
dsss_build ~= "-I" ~ dir ~ std.path.sep ~ |
|---|
| 242 |
"include" ~ std.path.sep ~ |
|---|
| 243 |
"d -L" ~ dir ~ std.path.sep ~ |
|---|
| 244 |
"lib "; |
|---|
| 245 |
} |
|---|
| 246 |
|
|---|
| 247 |
switch (command) { |
|---|
| 248 |
case cmd_t.BUILD: |
|---|
| 249 |
return sss.build.build(buildElems); |
|---|
| 250 |
break; |
|---|
| 251 |
|
|---|
| 252 |
case cmd_t.CLEAN: |
|---|
| 253 |
return sss.clean.clean(); |
|---|
| 254 |
break; |
|---|
| 255 |
|
|---|
| 256 |
case cmd_t.DISTCLEAN: |
|---|
| 257 |
return sss.clean.distclean(); |
|---|
| 258 |
break; |
|---|
| 259 |
|
|---|
| 260 |
case cmd_t.INSTALL: |
|---|
| 261 |
return sss.install.install(buildElems); |
|---|
| 262 |
break; |
|---|
| 263 |
|
|---|
| 264 |
case cmd_t.UNINSTALL: |
|---|
| 265 |
return sss.uninstall.uninstall(buildElems); |
|---|
| 266 |
break; |
|---|
| 267 |
|
|---|
| 268 |
case cmd_t.INSTALLED: |
|---|
| 269 |
return sss.uninstall.installed(); |
|---|
| 270 |
break; |
|---|
| 271 |
|
|---|
| 272 |
case cmd_t.NET: |
|---|
| 273 |
return sss.net.net(buildElems); |
|---|
| 274 |
break; |
|---|
| 275 |
|
|---|
| 276 |
case cmd_t.GENCONFIG: |
|---|
| 277 |
return sss.genconfig.genconfig(buildElems); |
|---|
| 278 |
break; |
|---|
| 279 |
} |
|---|
| 280 |
|
|---|
| 281 |
return 0; |
|---|
| 282 |
} |
|---|
| 283 |
|
|---|
| 284 |
void usage() |
|---|
| 285 |
{ |
|---|
| 286 |
if (command == cmd_t.NONE) { |
|---|
| 287 |
writefln( |
|---|
| 288 |
`DSSS version ` ~ DSSS_VERSION ~ ` |
|---|
| 289 |
Usage: dsss [dsss options] <command> [command options] |
|---|
| 290 |
DSSS Options: |
|---|
| 291 |
--help|-h: Display this help. |
|---|
| 292 |
Commands: |
|---|
| 293 |
build: build all or some binaries or libraries |
|---|
| 294 |
clean: clean up object files from all or some builds |
|---|
| 295 |
distclean: clean up all files from all or some builds |
|---|
| 296 |
install: install all or some binaries or libraries |
|---|
| 297 |
uninstall: uninstall a specified tool or library |
|---|
| 298 |
installed: list installed software |
|---|
| 299 |
net: Internet-based installation and package management |
|---|
| 300 |
genconfig: generate a config file |
|---|
| 301 |
Each command has its own set of options, which are not listed here. To list |
|---|
| 302 |
the options for a command: |
|---|
| 303 |
dsss <command> --help` |
|---|
| 304 |
); |
|---|
| 305 |
|
|---|
| 306 |
} else if (command == cmd_t.BUILD) { |
|---|
| 307 |
writefln( |
|---|
| 308 |
`Usage: dsss [dsss options] build [build options] [sources, binaries or packages] |
|---|
| 309 |
Build Options: |
|---|
| 310 |
--use=<directory containing import library includes and libs> |
|---|
| 311 |
All other options are passed through to build and ultimately the compiler.` |
|---|
| 312 |
); |
|---|
| 313 |
|
|---|
| 314 |
} else if (command == cmd_t.CLEAN) { |
|---|
| 315 |
writefln( |
|---|
| 316 |
`Usage: dsss [dsss options] clean [clean options] [sources, binaries or packages] |
|---|
| 317 |
Clean Options: |
|---|
| 318 |
[none yet]` |
|---|
| 319 |
); |
|---|
| 320 |
|
|---|
| 321 |
} else if (command == cmd_t.DISTCLEAN) { |
|---|
| 322 |
writefln( |
|---|
| 323 |
`Usage: dsss [dsss options] distclean [distclean options] [sources, binaries or packages] |
|---|
| 324 |
Distclean Options: |
|---|
| 325 |
[none yet]` |
|---|
| 326 |
); |
|---|
| 327 |
|
|---|
| 328 |
} else if (command == cmd_t.INSTALL) { |
|---|
| 329 |
writefln( |
|---|
| 330 |
`Usage: dsss [dsss options] install [install options] [sources, binaries or packages] |
|---|
| 331 |
Install Options: |
|---|
| 332 |
--prefix=<prefix>: set the install prefix` |
|---|
| 333 |
); |
|---|
| 334 |
|
|---|
| 335 |
} else if (command == cmd_t.UNINSTALL) { |
|---|
| 336 |
writefln( |
|---|
| 337 |
`Usage: dsss [dsss options] uninstall [uninstall options] [tools or libraries] |
|---|
| 338 |
Uninstall Options: |
|---|
| 339 |
[none yet]` |
|---|
| 340 |
); |
|---|
| 341 |
|
|---|
| 342 |
} else if (command == cmd_t.INSTALLED) { |
|---|
| 343 |
writefln( |
|---|
| 344 |
`Usage: dsss [dsss options] installed` |
|---|
| 345 |
); |
|---|
| 346 |
|
|---|
| 347 |
} else if (command == cmd_t.NET) { |
|---|
| 348 |
writefln( |
|---|
| 349 |
`Usage: dsss [dsss options] net <net command> [options] <package name> |
|---|
| 350 |
Net Commands: |
|---|
| 351 |
deps: install (from the network source) dependencies of the present |
|---|
| 352 |
package |
|---|
| 353 |
install: install a package via the network source |
|---|
| 354 |
fetch: fetch but do not compile or install a package |
|---|
| 355 |
list: list all installable packages |
|---|
| 356 |
search: find an installable package by name |
|---|
| 357 |
Net Options: |
|---|
| 358 |
--prefix=<prefix>: set the install prefix |
|---|
| 359 |
--use=<directory containing import library includes and libs> |
|---|
| 360 |
All other options are passed through to build and ultimately the compiler.` |
|---|
| 361 |
); |
|---|
| 362 |
|
|---|
| 363 |
|
|---|
| 364 |
} else if (command == cmd_t.GENCONFIG) { |
|---|
| 365 |
writefln( |
|---|
| 366 |
`Usage: dsss [dsss options] genconfig [install options] [sources, binaries or packages] |
|---|
| 367 |
Genconfig Options: |
|---|
| 368 |
[none yet]` |
|---|
| 369 |
); |
|---|
| 370 |
|
|---|
| 371 |
} |
|---|
| 372 |
} |
|---|