Mercurial > projects > doodle
view configure.d @ 47:14f1c051c35b
Moved undo into core.
author | daveb |
---|---|
date | Tue, 03 Aug 2010 16:57:06 +0930 |
parents | d0604b062db8 |
children | 860e18c87255 |
line wrap: on
line source
// Configure script, to be run with rdmd. // // Checks dependencies, sets up a build directory, builds // a local copy of the builder into the build directory, // and puts assorted scripts into the build directory to // facilitate building. // // If your project depends on installed libraries, you need to // add an options file containing command-line options such as: // -L-lgtkd // You also need to install the libraries somewhere that the compiler // can find them. Two simple options are: // * In the dmd installation directory, or // * Elsewhere, and edit dmd.conf to point to there. // // // The source paths you depend on need to be listed in a uses file. // Uses files are not transitive - only the one in the directory // you execute the configure script applies. // // Usage: rdmd configure.d <target-path> // // eg: rdmd configure.d ~/builds/myproject // import std.stdio; import std.path; import std.file; import std.string; import std.stdio; import std.process; int main(string[] args) { string source_path = getcwd; // parse command-line options if (args.length < 2) { writefln("Error - usage is: rdmd <configure.d-path> <build-path>"); return -1; } string target_path = args[1]; // check that source_path looks like a source tree by making sure // that a README and options file are present writefln("Examining source"); if (!source_path.join("README").exists || !source_path.join("options").exists) { writefln("Error - current directory must contain README and options"); return -1; } // ensure that target_path exists writefln("Establishing build directory"); if (target_path.exists) { writefln("Error - %s exists - abandoning configure", target_path); return -1; } target_path.mkdirRecurse; string bin_path = target_path.join("bin"); bin_path.mkdir; // compile builder into bin_path writefln("Building the builder"); int ret = system(format("dmd -w -wi %s -O -of%s", source_path.join("builder.d"), bin_path.join("builder"))); if (ret) { writefln("Error - builder failed to compile"); return -1; } bin_path.join("builder.o").remove; // set up scripts { auto file = File(target_path.join("environment"), "w"); file.writefln("SOURCE_PATH=%s", source_path); file.writefln("TARGET_PATH=%s", target_path); } { auto file = File(target_path.join("build"), "w"); file.writefln("#!/bin/bash"); file.writefln("source %s", target_path.join("environment")); file.writefln("%s %s %s", bin_path.join("builder"), source_path, target_path); } system("chmod +x " ~ target_path.join("build")); writefln("All done"); return 0; }