lol
1{ stdenv, fetchurl, fetchpatch, runCommand, zlib, makeWrapper }:
2
3let ccache = stdenv.mkDerivation rec {
4 name = "ccache-${version}";
5 version = "3.3.4";
6
7 src = fetchurl {
8 sha256 = "0ks0vk408mdppfbk8v38p46fqx3p30r9a9cwiia43373i7rmpw94";
9 url = "mirror://samba/ccache/${name}.tar.xz";
10 };
11
12 buildInputs = [ zlib ];
13
14 # non to be fail on filesystems with unconventional blocksizes (zfs on Hydra?)
15 patches = [ ./skip-fs-dependent-test.patch ];
16
17 postPatch = ''
18 substituteInPlace Makefile.in --replace 'objs) $(extra_libs)' 'objs)'
19 '';
20
21 doCheck = !stdenv.isDarwin;
22
23 passthru = let
24 unwrappedCC = stdenv.cc.cc;
25 in {
26 # A derivation that provides gcc and g++ commands, but that
27 # will end up calling ccache for the given cacheDir
28 links = extraConfig: stdenv.mkDerivation rec {
29 name = "ccache-links";
30 passthru = {
31 isClang = unwrappedCC.isClang or false;
32 isGNU = unwrappedCC.isGNU or false;
33 };
34 inherit (unwrappedCC) lib;
35 nativeBuildInputs = [ makeWrapper ];
36 buildCommand = ''
37 mkdir -p $out/bin
38
39 wrap() {
40 local cname="$1"
41 if [ -x "${unwrappedCC}/bin/$cname" ]; then
42 makeWrapper ${ccache}/bin/ccache $out/bin/$cname \
43 --run ${stdenv.lib.escapeShellArg extraConfig} \
44 --add-flags ${unwrappedCC}/bin/$cname
45 fi
46 }
47
48 wrap cc
49 wrap c++
50 wrap gcc
51 wrap g++
52 wrap clang
53 wrap clang++
54
55 for executable in $(ls ${unwrappedCC}/bin); do
56 if [ ! -x "$out/bin/$executable" ]; then
57 ln -s ${unwrappedCC}/bin/$executable $out/bin/$executable
58 fi
59 done
60 for file in $(ls ${unwrappedCC} | grep -vw bin); do
61 ln -s ${unwrappedCC}/$file $out/$file
62 done
63 '';
64 };
65 };
66
67 meta = with stdenv.lib; {
68 description = "Compiler cache for fast recompilation of C/C++ code";
69 homepage = http://ccache.samba.org/;
70 downloadPage = https://ccache.samba.org/download.html;
71 license = licenses.gpl3Plus;
72 maintainers = with maintainers; [ nckx ];
73 platforms = platforms.unix;
74 };
75};
76in ccache