Mercurial > projects > doodle
view configure.d @ 133:9e1a313d8003
Merge
author | David Bryant <bagnose@gmail.com> |
---|---|
date | Thu, 02 Aug 2012 15:34:17 +0930 |
parents | bc5baa585b32 5920bb2ddd0f |
children | 89e8b0d92f36 |
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 sourcePath = getcwd; // parse command-line options if (args.length < 2) { writefln("Error - usage is: rdmd <configure.d-path> <build-path>"); return -1; } string targetPath = 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 (!buildPath(sourcePath, "README").exists || !buildPath(sourcePath, "options").exists) { writefln("Error - current directory must contain README and options"); return -1; } // ensure that target_path exists writefln("Establishing build directory"); if (targetPath.exists) { writefln("Error - %s exists - abandoning configure", targetPath); return -1; } targetPath.mkdirRecurse; string binPath = buildPath(targetPath, "bin"); binPath.mkdir; // compile builder into bin_path writefln("Building the builder"); int ret = system(format("dmd -m64 -w -wi %s -O -of%s", buildPath(sourcePath, "builder.d"), buildPath(binPath, "builder"))); if (ret) { writefln("Error - builder failed to compile"); return -1; } buildPath(binPath, "builder.o").remove; // set up scripts { auto file = File(buildPath(targetPath, "build"), "w"); file.writefln("#!/bin/bash"); file.writefln("%s %s %s", buildPath(binPath, "builder"), sourcePath, targetPath); } system("chmod +x " ~ buildPath(targetPath, "build")); writefln("All done"); return 0; }