1{ stdenv, fetchurl, unzip, curl }:
2
3stdenv.mkDerivation {
4 name = "dmd-2.067.1";
5
6 src = fetchurl {
7 url = http://downloads.dlang.org/releases/2015/dmd.2.067.1.zip;
8 sha256 = "0ny99vfllvvgcl79pwisxcdnb3732i827k9zg8c0j4s0n79k5z94";
9 };
10
11 buildInputs = [ unzip curl ];
12
13 # Allow to use "clang++", commented in Makefile
14 postPatch = stdenv.lib.optionalString stdenv.isDarwin ''
15 substituteInPlace src/dmd/posix.mak --replace g++ clang++
16 '';
17
18 # Buid and install are based on http://wiki.dlang.org/Building_DMD
19 buildPhase = ''
20 cd src/dmd
21 make -f posix.mak INSTALL_DIR=$out
22 export DMD=$PWD/dmd
23 cd ../druntime
24 make -f posix.mak INSTALL_DIR=$out DMD=$DMD
25 cd ../phobos
26 make -f posix.mak INSTALL_DIR=$out DMD=$DMD
27 cd ../..
28 '';
29
30 installPhase = ''
31 cd src/dmd
32 mkdir $out
33 mkdir $out/bin
34 cp dmd $out/bin
35
36 cd ../druntime
37 mkdir $out/include
38 mkdir $out/include/d2
39 cp -r import/* $out/include/d2
40
41 cd ../phobos
42 mkdir $out/lib
43 ${let bits = if stdenv.is64bit then "64" else "32";
44 osname = if stdenv.isDarwin then "osx" else "linux"; in
45 "cp generated/${osname}/release/${bits}/libphobos2.a $out/lib"
46 }
47
48 cp -r std $out/include/d2
49 cp -r etc $out/include/d2
50
51 cd $out/bin
52 tee dmd.conf << EOF
53 [Environment]
54 DFLAGS=-I$out/include/d2 -L-L$out/lib ${stdenv.lib.optionalString (!stdenv.cc.isClang) "-L--no-warn-search-mismatch -L--export-dynamic"}
55 EOF
56 '';
57
58 meta = with stdenv.lib; {
59 description = "D language compiler";
60 homepage = http://dlang.org/;
61 license = licenses.free; # parts under different licenses
62 platforms = platforms.unix;
63 };
64}