Building dmd from source guid

monarch_dodra monarchdodra at gmail.com
Thu Dec 6 06:50:04 PST 2012


I'm trying to write a complete guide to building the alpha
version of dmd.

I myself am using something that only partially works, and
requires a lot of hacks by hand.

I thought that I'd post what I have, and with the help of the
news group, make it better and once it is 100% accurate and full,
post it to the wiki, or (maybe better yet) submit it to the
How-tos/Articles section of dlang.

...Anyways..., I'll start from the start:

==== STEP 0                   ====
==== PREPARE YOUR ENVIRONMENT ====

Our goal is to mostly replicate what you get when you download a
release version of D. We'll start by creating a root directory
for our instal. In this how-to, we'll create the directory called
"C:\D2". We will set this path as DM_HOME:
set DM_HOME=C:\D2

You can use any path you want, but it is EXTREMELLY important
that you set this variable, as the makefiles rely on it.
Inside this directory, we want to create two subdirectories:
* %DM_HOME%\dm
* %DM_HOME%\dmd2

inside dm, we want to put the digital mars C compiler. This can
be obtained from the digital mars website:
http://www.digitalmars.com/. Extract it inside %DM_HOME% to the
dm folder.

inside dmd2, we want to create these folders:
* %DM_HOME%\dmd2\windows
* %DM_HOME%\dmd2\windows\bin
* %DM_HOME%\dmd2\windows\lib
* %DM_HOME%\dmd2\src

That's just about it actually...

==== STEP 1         ====
==== GET YOUR FILES ====
What we want to do is get the sources. To do this, we use github.
You need to instal github shell.

    From the github shell, navigate to "C:\dmd2\src". Our goal is 
to
clone the dmd, druntime, phobos and tools repositories. Simply
type these commands, and wait for completion.

git clone https://github.com/D-Programming-Language/dmd
git clone https://github.com/D-Programming-Language/druntime
git clone https://github.com/D-Programming-Language/phobos
git clone https://github.com/D-Programming-Language/tools

This should give you the structure:

* %DM_HOME%\dmd2\windows
* %DM_HOME%\dmd2\windows\bin
* %DM_HOME%\dmd2\windows\lib
* %DM_HOME%\dmd2\src
* %DM_HOME%\dmd2\src\dmd
* %DM_HOME%\dmd2\src\druntime
* %DM_HOME%\dmd2\src\phobos
* %DM_HOME%\dmd2\src\tools

==== STEP 2   ====
==== MAKE DMD ====
First, we need to set up our paths variables and environment.
First, our path variable. To make sure we don't have any noise,
we just set it to the only two paths that are of interest to us:
the C compiler, and our bin path:
set path=C:\D2\dm\bin;C:\D2\dmd2\windows\bin;
Don't forget to set your DM_HOME environment variable.

Once this is done, making dmd is pretty straight forward. First,
we navigate to %DM_HOME%\dmd2\src\dmd\src:
cd %DM_HOME%\dmd2\src\dmd\src
and make dmd:
make -fwin32.mak release
And that should be all there is to do. I recommend you build the
compiler in release directly.

Once this is done, we copy the new files to our bin path. The
make file has options to do this automatically, but for now,
we'll do it by hand the first time:
copy *.exe %DM_HOME%\dmd2\windows\bin

==== STEP 2.5 ====
==== sc.ini   ====
First, we navigate to our bin path. Our goal is to write the
sc.ini which will tell dmd where to look for its libs and stuff.
YOu can either give it abosulte paths that start at %DM_HOME%, or
use relative paths. Relative paths are harder to get right, but
they don't rely on env variables either. Anyways, your file
should look like either of:

```
[Environment]
LIB="%DM_HOME%\dmd2\windows\lib"
DFLAGS="-I%DM_HOME%\dmd2\src\phobos"
"-I%DM_HOME%\dmd2\src\druntime\import"
LINKCMD=%DM_HOME%\dm\bin\link.exe
```

```
[Environment]
LIB="%@P%\..\lib"
DFLAGS="-I%@P%\..\..\src\phobos"
"-I%@P%\..\..\src\druntime\import"
LINKCMD=%@P%\..\..\..\dm\bin\link.exe
```

================
I'll stop here because this is where my first doubts start:
The packaged dmd defines LIB as:
LIB="%@P%\..\lib";\dm\lib

What exactly is "\dm\lib"? I understand it is *meant* to link to
the C compiler's lib, but the path is just bogus...

Other than that, any feed back before I continue?


More information about the Digitalmars-d mailing list