1 /*
2 Copyright (c) 2011-2014 Timur Gafarov 
3 
4 Boost Software License - Version 1.0 - August 17th, 2003
5 
6 Permission is hereby granted, free of charge, to any person or organization
7 obtaining a copy of the software and accompanying documentation covered by
8 this license (the "Software") to use, reproduce, display, distribute,
9 execute, and transmit the Software, and to prepare derivative works of the
10 Software, and to permit third-parties to whom the Software is furnished to
11 do so, all subject to the following:
12 
13 The copyright notices in the Software and this entire statement, including
14 the above license grant, this restriction and the following disclaimer,
15 must be included in all copies of the Software, in whole or in part, and
16 all derivative works of the Software, unless such copies or derivative
17 works are solely in the form of machine-executable object code generated by
18 a source language processor.
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, TITLE AND NON-INFRINGEMENT. IN NO EVENT
23 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
24 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
25 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 DEALINGS IN THE SOFTWARE.
27 */
28 
29 module main;
30 
31 import std.stdio;
32 import std.process: executeShell;
33 import std..string;
34 import std.path;
35 
36 import project;
37 import cmdopt;
38 import conf;
39 import dmodule;
40 import session;
41 import exdep;
42 
43 static string versionString = "2.1.3";
44 
45 void main(string[] args)
46 {
47     CmdOptions ops = new CmdOptions(args);
48 
49     if (ops.help)
50     {
51         printHelp(ops.program, versionString);
52         return;
53     }
54 
55     Config conf = new Config();
56     BuildSession bs = new BuildSession(ops, conf);
57 
58     Project proj = new Project(ops, conf);
59     foreach(exd; proj.exdeps)
60     {
61         exd.fetch(ops);
62         conf.append("project.external", format("%s ", exd.srcDir));
63         conf.append("cflags", format(" -I%s ", exd.srcDir));
64     }
65     
66     bs.build(proj);
67 }
68 
69 void printHelp(string programName, string programVersion)
70 {
71     writeln
72     (
73         "Cook2 ", programVersion, "\n",
74         "A tool for building projects in D programming language\n",
75         "\n",
76         "Usage:\n",
77         "cook [MAINMODULE] [OPTIONS]\n",
78         "\n",
79         "OPTIONS:\n",
80         "\n",
81         "--help        Display this information\n",
82         "--emulate     Don't write anything to disk\n",
83         "--quiet       Don't print messages\n",
84         "--rebuild     Force rebuilding all modules\n",
85         "--nocache     Disable reading/writing module cache\n",
86         "--lib         Build a static library instead of an executable\n",
87         "--release     Compile modules in release mode\n",
88         "--noconsole   Under Windows, hide application console window\n",
89         "--strip       Remove debug symbols from resulting binary using \"strip\"\n",
90         "              (currently works only under Linux)\n",
91         "-o FILE       Compile to specified filename\n",
92         "--clean       Remove temporary data (object files, cache, etc.)\n",
93         "--cache FILE  Use specified cache file\n",
94         "--rc FILE     Under Windows, compile and link specified resource file\n",
95       "-c\"...\"       Pass specified option(s) to compiler\n",
96       "-l\"...\"       Pass specified option(s) to linker\n",
97         "--run         Run program after compilation (does't work in emulation mode)\n",
98         "--dc FILE     Specify default configuration file (default \"default.conf\")\n",
99         "--https       Use HTTPS instead of SSH when fetching remote dependencies\n",
100         "--rsp         Pass object file names to linker via responce file\n",
101         "              instead of command line\n",
102         "--local       Store temporary data in cwd instead of home directory\n"
103     );
104 }
105