1{ stdenv, fetchurl, unzip, curl, makeWrapper }:
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 makeWrapper ];
12
13 postPatch = stdenv.lib.optionalString stdenv.isDarwin ''
14 # Allow to use "clang++", commented in Makefile
15 substituteInPlace src/dmd/posix.mak \
16 --replace g++ clang++ \
17 --replace MACOSX_DEPLOYMENT_TARGET MACOSX_DEPLOYMENT_TARGET_
18
19 # Was not able to compile on darwin due to "__inline_isnanl"
20 # being undefined.
21 substituteInPlace src/dmd/root/port.c --replace __inline_isnanl __inline_isnan
22 '';
23
24 # Buid and install are based on http://wiki.dlang.org/Building_DMD
25 buildPhase = ''
26 cd src/dmd
27 make -f posix.mak INSTALL_DIR=$out
28 export DMD=$PWD/dmd
29 cd ../druntime
30 make -f posix.mak INSTALL_DIR=$out DMD=$DMD
31 cd ../phobos
32 make -f posix.mak INSTALL_DIR=$out DMD=$DMD
33 cd ../..
34 '';
35
36 installPhase = ''
37 cd src/dmd
38 mkdir $out
39 mkdir $out/bin
40 cp dmd $out/bin
41
42 cd ../druntime
43 mkdir $out/include
44 mkdir $out/include/d2
45 cp -r import/* $out/include/d2
46
47 cd ../phobos
48 mkdir $out/lib
49 ${let bits = if stdenv.is64bit then "64" else "32";
50 osname = if stdenv.isDarwin then "osx" else "linux"; in
51 "cp generated/${osname}/release/${bits}/libphobos2.a $out/lib"
52 }
53
54 cp -r std $out/include/d2
55 cp -r etc $out/include/d2
56
57 wrapProgram $out/bin/dmd \
58 --prefix PATH ":" "${stdenv.cc}/bin" \
59 --set CC "$""{CC:-$CC""}"
60
61 cd $out/bin
62 tee dmd.conf << EOF
63 [Environment]
64 DFLAGS=-I$out/include/d2 -L-L$out/lib ${stdenv.lib.optionalString (!stdenv.cc.isClang) "-L--no-warn-search-mismatch -L--export-dynamic"}
65 EOF
66 '';
67
68 meta = with stdenv.lib; {
69 description = "D language compiler";
70 homepage = http://dlang.org/;
71 license = licenses.free; # parts under different licenses
72 platforms = platforms.unix;
73 };
74}