From 9f8f73f53063db9a1d9a615b4d261282858e5c93 Mon Sep 17 00:00:00 2001 From: edmccard Date: Tue, 24 Apr 2012 10:11:16 -0400 Subject: [PATCH] New build.d --- README.md | 6 +++++ src/Makefile | 2 +- src/build.d | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 src/build.d diff --git a/README.md b/README.md index b123341..9c75296 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,12 @@ Build by running `make` in the `src` directory; if the dependencies aren't insta make GTKD=/path/to/gtkd DERELICT=/path/to/Derelict2 ``` +Alternatively, you can run `build.d` from the `src` directory: +``` +cd src +rdmd build.d --gtkd=/path/to/gtkd --derelict=/path/to/Derelict2 +``` + ### Testing There are tests for the 6502/65C02 emulation: diff --git a/src/Makefile b/src/Makefile index b9e86b3..c6ef2e2 100644 --- a/src/Makefile +++ b/src/Makefile @@ -7,7 +7,7 @@ LINK_OPTS = -L-lpthread -L-lGL -L-ldl -L-lX11 \ -L-L$(GTKD) -L-lgtkd -L-lgtkdgl \ -L-L$(DERELICT)/lib -L-lDerelictSDL -L-lDerelictUtil -ALL_SRC = $(shell find -name "*.d" \! -name "ctfe*") +ALL_SRC = $(shell find -name "*.d" \! -name "ctfe*" \! -name "build.d") all: ${ALL_SRC} dmd $(COMPILE_OPTS) ${ALL_SRC} -oftwoapple ${LINK_OPTS} diff --git a/src/build.d b/src/build.d new file mode 100644 index 0000000..02701bb --- /dev/null +++ b/src/build.d @@ -0,0 +1,66 @@ +import std.algorithm, std.array, std.exception, std.getopt, std.process, + std.stdio; + + +string GTKD = ""; +string DERELICT = ""; + + +version(GNU) + string OPMODE = " -version=OpSwitch "; +else version(DigitalMars) + string OPMODE = " -version=OpNestedSwitch "; +else + static assert(0, "Unsupported compiler"); + + +bool notGTKD(string a) +{ + return indexOf(a, GTKD) == -1; +} +bool compilable(string a) +{ + return endsWith(a, ".d") && indexOf(a, "ctfe") == -1; +} + + +int main(string[] args) +{ + getopt( + args, + "gtkd", >KD, + "derelict", &DERELICT); + + string opts = "-Jdata " ~ OPMODE; + if (GTKD.length) + opts ~= " -I" ~ GTKD ~ "/src -I" ~ GTKD ~ "/srcgl "; + if (DERELICT.length) + opts ~= " -I" ~ DERELICT ~ "/import "; + try + { + auto deps = split(shell("rdmd --makedepend " ~ opts ~ " twoapple.d")); + auto d_files = array(filter!compilable(deps)); + auto without_gtkd = array(filter!notGTKD(d_files)); + opts = " -inline -release -O -noboundscheck " ~ opts ~ + " -d -L-lGL -L-ldl -L-lX11 " ~ + " -L-L" ~ DERELICT ~ "/lib -L-lDerelictSDL -L-lDerelictUtil "; + version(DigitalMars) + { + if (GTKD.length) + opts ~= " -L-L" ~ GTKD ~ " -L-lgtkd -L-lgtkdgl "; + auto files = join(without_gtkd, " "); + return system("dmd " ~ opts ~ " " ~ files); + } + else version(GNU) + { + auto files = join(d_files, " "); + return system("gdmd " ~ opts ~ " " ~ files); + } + } + catch (ErrnoException e) + { + return 1; + } + + return 0; +}