@@ -1,4 +1,4 @@
1−{ stdenv, fetchurl, fetchpatch, perl, gdb }:
1+{ stdenv, fetchurl, fetchpatch, perl, gdb, llvm, cctools, xnu, bootstrap_cmds }:
22
33stdenv.mkDerivation rec {
44 name = "valgrind-3.12.0";
@@ -14,11 +14,13 @@ stdenv.mkDerivation rec {
1414
1515 # Perl is needed for `cg_annotate'.
1616 # GDB is needed to provide a sane default for `--db-command'.
17− buildInputs = [ perl ] ++ stdenv.lib.optional (!stdenv.isDarwin) gdb;
17+ buildInputs = [ perl gdb ] ++ stdenv.lib.optionals (stdenv.isDarwin) [ bootstrap_cmds xnu ];
1818
1919 enableParallelBuilding = true;
2020
21− postPatch =
21+ patches = stdenv.lib.optionals (stdenv.isDarwin) [ ./valgrind-bzero.patch ];
22+
23+ postPatch = stdenv.lib.optionalString (stdenv.isDarwin)
2224 # Apple's GCC doesn't recognize `-arch' (as of version 4.2.1, build 5666).
2325 ''
2426 echo "getting rid of the \`-arch' GCC option..."
@@ -27,6 +29,23 @@ stdenv.mkDerivation rec {
2729
2830 sed -i coregrind/link_tool_exe_darwin.in \
2931 -e 's/^my \$archstr = .*/my $archstr = "x86_64";/g'
32+
33+ echo "substitute hardcoded /usr/include/mach with ${xnu}/include/mach"
34+ substituteInPlace coregrind/Makefile.in \
35+ --replace /usr/include/mach ${xnu}/include/mach
36+
37+ echo "substitute hardcoded dsymutil with ${llvm}/bin/llvm-dsymutil"
38+ find -name "Makefile.in" | while read file; do
39+ substituteInPlace "$file" \
40+ --replace dsymutil ${llvm}/bin/llvm-dsymutil
41+ done
42+
43+ substituteInPlace coregrind/m_debuginfo/readmacho.c \
44+ --replace /usr/bin/dsymutil ${llvm}/bin/llvm-dsymutil
45+
46+ echo "substitute hardcoded /usr/bin/ld with ${cctools}/bin/ld"
47+ substituteInPlace coregrind/link_tool_exe_darwin.in \
48+ --replace /usr/bin/ld ${cctools}/bin/ld
3049 '';
3150
3251 configureFlags =
@@ -58,6 +77,6 @@ stdenv.mkDerivation rec {
5877 license = stdenv.lib.licenses.gpl2Plus;
5978
6079 maintainers = [ stdenv.lib.maintainers.eelco ];
61− platforms = stdenv.lib.platforms.linux;
80+ platforms = stdenv.lib.platforms.unix;
6281 };
6382}