1{ stdenv, lib, fetchurl, fetchpatch, makeWrapper
2, coq, ocamlPackages, coq2html
3, tools ? stdenv.cc
4}:
5
6assert lib.versionAtLeast ocamlPackages.ocaml.version "4.02";
7assert lib.versionAtLeast coq.coq-version "8.6.1";
8
9let
10 ocaml-pkgs = with ocamlPackages; [ ocaml findlib menhir ];
11 ccomp-platform = if stdenv.isDarwin then "x86_64-macosx" else "x86_64-linux";
12in
13stdenv.mkDerivation rec {
14 name = "compcert-${version}";
15 version = "3.4";
16
17 src = fetchurl {
18 url = "http://compcert.inria.fr/release/${name}.tgz";
19 sha256 = "12gchwvkzhd2bhrnwzfb4a06wc4hgv98z987k06vj7ga31ii763h";
20 };
21
22 nativeBuildInputs = [ makeWrapper ];
23 buildInputs = ocaml-pkgs ++ [ coq coq2html ];
24 enableParallelBuilding = true;
25
26 patchPhase = ''
27 substituteInPlace ./configure \
28 --replace '{toolprefix}gcc' '{toolprefix}cc'
29 '';
30
31 configurePhase = ''
32 ./configure -clightgen \
33 -prefix $out \
34 -toolprefix ${tools}/bin/ \
35 ${ccomp-platform}
36 '';
37
38 installTargets = "documentation install";
39 postInstall = ''
40 # move man into place
41 mkdir -p $man/share
42 mv $out/share/man/ $man/share/
43
44 # move docs into place
45 mkdir -p $doc/share/doc/compcert
46 mv doc/html $doc/share/doc/compcert/
47
48 # install compcert lib files; remove copy from $out, too
49 mkdir -p $lib/lib/coq/${coq.coq-version}/user-contrib/compcert/
50 mv backend cfrontend common cparser driver flocq x86 x86_64 lib \
51 $lib/lib/coq/${coq.coq-version}/user-contrib/compcert/
52 rm -rf $out/lib/compcert/coq
53
54 # wrap ccomp to undefine _FORTIFY_SOURCE; ccomp invokes cc1 which sets
55 # _FORTIFY_SOURCE=2 by default, but undefines __GNUC__ (as it should),
56 # which causes a warning in libc. this suppresses it.
57 for x in ccomp clightgen; do
58 wrapProgram $out/bin/$x --add-flags "-U_FORTIFY_SOURCE"
59 done
60 '';
61
62 outputs = [ "out" "lib" "doc" "man" ];
63
64 meta = with stdenv.lib; {
65 description = "Formally verified C compiler";
66 homepage = "http://compcert.inria.fr";
67 license = licenses.inria-compcert;
68 platforms = [ "x86_64-linux" "x86_64-darwin" ];
69 maintainers = with maintainers; [ thoughtpolice jwiegley vbgl ];
70 };
71}