1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 popt,
6 avahi,
7 pkg-config,
8 python3,
9 gtk3,
10 runCommand,
11 gcc,
12 autoconf,
13 automake,
14 which,
15 procps,
16 libiberty_static,
17 runtimeShell,
18 sysconfDir ? "", # set this parameter to override the default value $out/etc
19 static ? false,
20}:
21
22let
23 pname = "distcc";
24 version = "2021-03-11";
25 distcc = stdenv.mkDerivation {
26 inherit pname version;
27 src = fetchFromGitHub {
28 owner = "distcc";
29 repo = "distcc";
30 rev = "de21b1a43737fbcf47967a706dab4c60521dbbb1";
31 sha256 = "0zjba1090awxkmgifr9jnjkxf41zhzc4f6mrnbayn3v6s77ca9x4";
32 };
33
34 nativeBuildInputs = [
35 pkg-config
36 autoconf
37 automake
38 which
39 (python3.withPackages (p: [ p.setuptools ]))
40 ];
41 buildInputs = [
42 popt
43 avahi
44 gtk3
45 procps
46 libiberty_static
47 ];
48 preConfigure = ''
49 export CPATH=$(ls -d ${gcc.cc}/lib/gcc/*/${gcc.cc.version}/plugin/include)
50
51 configureFlagsArray=( CFLAGS="-O2 -fno-strict-aliasing"
52 CXXFLAGS="-O2 -fno-strict-aliasing"
53 --mandir=$out/share/man
54 ${lib.optionalString (sysconfDir != "") "--sysconfdir=${sysconfDir}"}
55 ${lib.optionalString static "LDFLAGS=-static"}
56 ${lib.withFeature (static == true || popt == null) "included-popt"}
57 ${lib.withFeature (avahi != null) "avahi"}
58 ${lib.withFeature (gtk3 != null) "gtk"}
59 --without-gnome
60 --enable-rfc2553
61 --disable-Werror # a must on gcc 4.6
62 )
63 installFlags="sysconfdir=$out/etc";
64
65 ./autogen.sh
66 '';
67
68 # The test suite fails because it uses hard-coded paths, i.e. /usr/bin/gcc.
69 doCheck = false;
70
71 passthru = {
72 # A derivation that provides gcc and g++ commands, but that
73 # will end up calling distcc for the given cacheDir
74 #
75 # extraConfig is meant to be sh lines exporting environment
76 # variables like DISTCC_HOSTS, DISTCC_DIR, ...
77 links =
78 extraConfig:
79 (runCommand "distcc-links" { passthru.gcc = gcc.cc; } ''
80 mkdir -p $out/bin
81 if [ -x "${gcc.cc}/bin/gcc" ]; then
82 cat > $out/bin/gcc << EOF
83 #!${runtimeShell}
84 ${extraConfig}
85 exec ${distcc}/bin/distcc gcc "\$@"
86 EOF
87 chmod +x $out/bin/gcc
88 fi
89 if [ -x "${gcc.cc}/bin/g++" ]; then
90 cat > $out/bin/g++ << EOF
91 #!${runtimeShell}
92 ${extraConfig}
93 exec ${distcc}/bin/distcc g++ "\$@"
94 EOF
95 chmod +x $out/bin/g++
96 fi
97 '');
98 };
99
100 meta = {
101 description = "Fast, free distributed C/C++ compiler";
102 homepage = "http://distcc.org";
103 license = "GPL";
104
105 platforms = lib.platforms.linux;
106 maintainers = with lib.maintainers; [ anderspapitto ];
107 };
108 };
109in
110distcc