I’ve recently been having a deeper look into the D programming language, because writing a JIT on top of .NET turned out to be extremely hard without interfering with the .NET runtime. I didn’t quite want to use C, as that’s too low-level for the stuff I’m doing, and C++ is just broken. D seems to be both languages done right, and so I settled on that.
You can program D perfectly fine with the latest Digital Mars D (DMD) release, but I ended up having to contribute some patches to the standard libraries, and figured I might as well build everything from source.
First, you’re going to need Git, as everything is hosted on GitHub.
Next, do the following clones:
- /usr/src/dmd -> https://github.com/D-Programming-Language/dmd.git
- /usr/src/druntime -> https://github.com/D-Programming-Language/druntime.git
- /usr/src/phobos -> https://github.com/D-Programming-Language/phobos.git
- /usr/src/dtools -> https://github.com/D-Programming-Language/tools.git
In all of the makefiles, the MODEL variable specifies what bitness to build for. Here, I’m going to build for x86-64, so I’ll use 64. To build for x86, just use 32.
To build DMD, do:
cd /usr/src/dmd/src; gmake -f posix.mak MODEL=64;
Everything should Just Work in the compile process. I’m using gmake because the makefiles are designed for GNU Make, and some systems don’t map make to that by default.
Unfortunately, DMD (and related repositories) don’t have any standard install target that we can use, so we’re just going to copy things into the file system. I’m using /usr/local/bin, /usr/local/lib, and /usr/local/include:
cp dmd /usr/local/bin;
Verify that you have a DMD matching your system’s bitness:
This should print:
DMD64 D Compiler v2.055
DMD32 should be printed for a 32-bit installation.
You need to add a configuration file for DMD. Add the following to /etc/dmd.conf:
[Environment] DFLAGS=-I/usr/local/include/d2 -L-L/usr/local/lib -L--no-warn-search-mismatch -L--export-dynamic
Now to build the core runtime libraries:
cd /usr/src/druntime; gmake -f posix.mak MODEL=64 DMD=../dmd/src/dmd;
If the build succeeds, we can copy the resulting interface files to our file system:
mkdir /usr/local/include/d2; cp -r import/* /usr/local/include/d2;
Next, we build Phobos, which is the standard library containing facilities for concurrency, regular expressions, I/O, signals, math, text manipulation, and so on:
cd /usr/src/phobos; gmake -f posix.mak MODEL=64 DMD=../dmd/src/dmd;
Again, we copy library and interface files:
cp generated/linux/release/64/libphobos2.a /usr/local/lib; cp -r std /usr/local/include/d2; cp -r etc /usr/local/include/d2;
In the copy command for libphobos2.a, replace 64 with 32 if you built for x86.
With these in place, we should be able to build the additional D utilities:
cd /usr/src/dtools; dmd ddemangle.d; dmd rdmd.d; cp ddemangle /usr/local/bin; cp rdmd /usr/local/bin;
You should now have a fully functional installation of DMD! Feel free to post here if you run into trouble, or have some tip you’d like added to this tutorial.
I’d like to extend a thank you to everyone on #d @ irc.freenode.net for putting up with my questions. You guys are awesome. :)