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