view configure.d @ 94:deb9d9fae854

Added my .hgrc file and tweaked README
author David Bryant <bagnose@gmail.com>
date Thu, 26 Aug 2010 16:08:21 +0930
parents 6c3993f4c3eb
children 0d427170a805
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 (!sourcePath.join("README").exists || !sourcePath.join("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 = targetPath.join("bin");
    binPath.mkdir;

    // compile builder into bin_path
    writefln("Building the builder");
    int ret = system(format("dmd -w -wi %s -O -of%s",
                            sourcePath.join("builder.d"), binPath.join("builder")));
    if (ret) {
        writefln("Error - builder failed to compile");
        return -1;
    }
    binPath.join("builder.o").remove;

    // set up scripts
    {
        auto file = File(targetPath.join("build"), "w");
        file.writefln("#!/bin/bash");
        file.writefln("%s %s %s", binPath.join("builder"), sourcePath, targetPath);
    }
    system("chmod +x " ~ targetPath.join("build"));
    writefln("All done");

    return 0;
}