{ fetchurl, stdenv }:

stdenv.mkDerivation rec {
  name = "talloc-2.0.1";

  src = fetchurl {
    url = "http://samba.org/ftp/talloc/${name}.tar.gz";
    sha256 = "1d694zyi451a5zr03l5yv0n8yccyr3r8pmzga17xaaaz80khb0av";
  };

  configureFlags = "--enable-talloc-compat1 --enable-largefile";
  
  # https://bugzilla.samba.org/show_bug.cgi?id=7000
  postConfigure = if stdenv.isDarwin then ''
    substituteInPlace "Makefile" --replace "SONAMEFLAG = #" "SONAMEFLAG = -install_name"
  '' else "";

  meta = {
    description = "Hierarchical pool based memory allocator with destructors";
    homepage = http://tdb.samba.org/;
    license = stdenv.lib.licenses.gpl3;
    platforms = stdenv.lib.platforms.all;
  };
}

{ fetchurl, stdenv }:

stdenv.mkDerivation rec {
  name = "talloc-2.0.1";

  src = fetchurl {
    url = "http://samba.org/ftp/talloc/${name}.tar.gz";
    sha256 = "1d694zyi451a5zr03l5yv0n8yccyr3r8pmzga17xaaaz80khb0av";
  };

  configureFlags = "--enable-talloc-compat1 --enable-largefile";
  
  # https://bugzilla.samba.org/show_bug.cgi?id=7000
  postConfigure = if stdenv.isDarwin then ''
    substituteInPlace "Makefile" --replace "SONAMEFLAG = #" "SONAMEFLAG = -Wl,-install_name,"
  '' else "";

  meta = {
    description = "Hierarchical pool based memory allocator with destructors";
    homepage = http://tdb.samba.org/;
    license = stdenv.lib.licenses.gpl3;
    platforms = stdenv.lib.platforms.all;
  };
}

Fix linker flags on darwin.
talloc: Fix linker flags on darwin.

Before this patch, building talloc on darwin (OS X 10.8.5) results in:

gcc -dynamiclib -Wl,-search_paths_first -undefined error -o libtalloc.dylib.2.0.1 ./talloc.o  ./libreplace/replace.o ./libreplace/snprintf.o ./libreplace/getpass.o ./libreplace/strptime.o   -install_namelibtalloc.dylib.2
gcc: error: unrecognized command line option '-install_namelibtalloc.dylib.2'
make: *** [libtalloc.dylib.2.0.1] Error 1

Setting SONAMEFLAG to either "-install_name " (note trailing space), or
"-Wl,-install_name," results in a successful build. The latter seems
more clear.
