1{
2 lib,
3 stdenv,
4 fetchFromBitbucket,
5 mlton,
6 pkg-config,
7 getopt,
8 boehmgc,
9 darwin,
10 libbacktrace,
11 libpng,
12 ncurses,
13 readline,
14 unstableGitUpdater,
15}:
16
17stdenv.mkDerivation rec {
18 pname = "c0";
19 version = "0-unstable-2023-09-05";
20
21 src = fetchFromBitbucket {
22 owner = "c0-lang";
23 repo = "c0";
24 rev = "608f97eef5d81bb85963d66f955730dd93996f67";
25 hash = "sha256-lRIEtclx+NKxAO72nsvnxVeEGCEe6glC6w8MXh1HEwY=";
26 };
27
28 patches = [
29 ./use-system-libraries.patch
30 ];
31
32 postPatch = ''
33 substituteInPlace cc0/Makefile \
34 --replace '$(shell ./get_version.sh)' '${version}'
35 substituteInPlace cc0/compiler/bin/buildid \
36 --replace '`../get_version.sh`' '${version}' \
37 --replace '`date`' '1970-01-01T00:00:00Z' \
38 --replace '`hostname`' 'nixpkgs'
39 ''
40 + lib.optionalString stdenv.hostPlatform.isDarwin ''
41 for f in cc0/compiler/bin/coin-o0-support cc0/compiler/bin/cc0-o0-support; do
42 substituteInPlace $f --replace '$(brew --prefix gnu-getopt)' '${getopt}'
43 done
44 '';
45
46 preConfigure = ''
47 cd cc0/
48 '';
49
50 nativeBuildInputs = [
51 getopt
52 mlton
53 pkg-config
54 ]
55 ++ lib.optionals stdenv.hostPlatform.isDarwin [ darwin.sigtool ];
56
57 buildInputs = [
58 boehmgc
59 libbacktrace
60 libpng
61 ncurses
62 readline
63 ];
64
65 strictDeps = true;
66
67 installFlags = [ "PREFIX=$(out)" ];
68
69 postInstall = ''
70 mkdir -p $out/share/emacs/site-lisp
71 mv $out/c0-mode/ $out/share/emacs/site-lisp/
72 '';
73
74 passthru.updateScript = unstableGitUpdater {
75 url = "https://bitbucket.org/c0-lang/c0.git";
76 };
77
78 meta = with lib; {
79 description = "Small safe subset of the C programming language, augmented with contracts";
80 homepage = "https://c0.cs.cmu.edu/";
81 license = licenses.mit;
82 maintainers = [ ];
83 platforms = platforms.unix;
84 # line 1: ../../bin/wrappergen: cannot execute: required file not found
85 # make[2]: *** [../../lib.mk:83:
86 broken = stdenv.hostPlatform.isLinux;
87 };
88}