comparison configure.d @ 59:860e18c87255

Stylistics
author "David Bryant <bagnose@gmail.com>"
date Mon, 09 Aug 2010 21:50:16 +0930
parents d0604b062db8
children 6c3993f4c3eb
comparison
equal deleted inserted replaced
58:c63719604adb 59:860e18c87255
32 import std.process; 32 import std.process;
33 33
34 34
35 int main(string[] args) { 35 int main(string[] args) {
36 36
37 string source_path = getcwd; 37 string sourcePath = getcwd;
38 38
39 // parse command-line options 39 // parse command-line options
40 if (args.length < 2) { 40 if (args.length < 2) {
41 writefln("Error - usage is: rdmd <configure.d-path> <build-path>"); 41 writefln("Error - usage is: rdmd <configure.d-path> <build-path>");
42 return -1; 42 return -1;
43 } 43 }
44 string target_path = args[1]; 44 string targetPath = args[1];
45 45
46 // check that source_path looks like a source tree by making sure 46 // check that source_path looks like a source tree by making sure
47 // that a README and options file are present 47 // that a README and options file are present
48 writefln("Examining source"); 48 writefln("Examining source");
49 if (!source_path.join("README").exists || !source_path.join("options").exists) { 49 if (!sourcePath.join("README").exists || !sourcePath.join("options").exists) {
50 writefln("Error - current directory must contain README and options"); 50 writefln("Error - current directory must contain README and options");
51 return -1; 51 return -1;
52 } 52 }
53 53
54 // ensure that target_path exists 54 // ensure that target_path exists
55 writefln("Establishing build directory"); 55 writefln("Establishing build directory");
56 if (target_path.exists) { 56 if (targetPath.exists) {
57 writefln("Error - %s exists - abandoning configure", target_path); 57 writefln("Error - %s exists - abandoning configure", targetPath);
58 return -1; 58 return -1;
59 } 59 }
60 target_path.mkdirRecurse; 60 targetPath.mkdirRecurse;
61 string bin_path = target_path.join("bin"); 61 string binPath = targetPath.join("bin");
62 bin_path.mkdir; 62 binPath.mkdir;
63 63
64 // compile builder into bin_path 64 // compile builder into bin_path
65 writefln("Building the builder"); 65 writefln("Building the builder");
66 int ret = system(format("dmd -w -wi %s -O -of%s", 66 int ret = system(format("dmd -w -wi %s -O -of%s",
67 source_path.join("builder.d"), bin_path.join("builder"))); 67 sourcePath.join("builder.d"), binPath.join("builder")));
68 if (ret) { 68 if (ret) {
69 writefln("Error - builder failed to compile"); 69 writefln("Error - builder failed to compile");
70 return -1; 70 return -1;
71 } 71 }
72 bin_path.join("builder.o").remove; 72 binPath.join("builder.o").remove;
73 73
74 // set up scripts 74 // set up scripts
75 { 75 {
76 auto file = File(target_path.join("environment"), "w"); 76 auto file = File(targetPath.join("environment"), "w");
77 file.writefln("SOURCE_PATH=%s", source_path); 77 file.writefln("SOURCE_PATH=%s", sourcePath);
78 file.writefln("TARGET_PATH=%s", target_path); 78 file.writefln("TARGET_PATH=%s", targetPath);
79 } 79 }
80 { 80 {
81 auto file = File(target_path.join("build"), "w"); 81 auto file = File(targetPath.join("build"), "w");
82 file.writefln("#!/bin/bash"); 82 file.writefln("#!/bin/bash");
83 file.writefln("source %s", target_path.join("environment")); 83 file.writefln("source %s", targetPath.join("environment"));
84 file.writefln("%s %s %s", bin_path.join("builder"), source_path, target_path); 84 file.writefln("%s %s %s", binPath.join("builder"), sourcePath, targetPath);
85 } 85 }
86 system("chmod +x " ~ target_path.join("build")); 86 system("chmod +x " ~ targetPath.join("build"));
87 writefln("All done"); 87 writefln("All done");
88 88
89 return 0; 89 return 0;
90 } 90 }