From 5a59b458116cabb006dbf7362290dba0f7f68eab Mon Sep 17 00:00:00 2001 From: Daiderd Jordan Date: Mon, 18 Sep 2017 23:15:26 +0200 Subject: [PATCH] libjack2: fix darwin build (cherry picked from commit 7d98316a9745ae6538f90dc580b0873074dfd5e5) --- pkgs/misc/jackaudio/clang.patch | 22 +++++++++++++ pkgs/misc/jackaudio/darwin-cf.patch | 49 +++++++++++++++++++++++++++++ pkgs/misc/jackaudio/default.nix | 28 ++++++++++++++--- pkgs/top-level/all-packages.nix | 1 + 4 files changed, 95 insertions(+), 5 deletions(-) create mode 100644 pkgs/misc/jackaudio/clang.patch create mode 100644 pkgs/misc/jackaudio/darwin-cf.patch diff --git a/pkgs/misc/jackaudio/clang.patch b/pkgs/misc/jackaudio/clang.patch new file mode 100644 index 00000000000000..131f8c4c04dd49 --- /dev/null +++ b/pkgs/misc/jackaudio/clang.patch @@ -0,0 +1,22 @@ +diff --git a/tests/test.cpp b/tests/test.cpp +index 8a8a811..31e8459 100644 +--- a/tests/test.cpp ++++ b/tests/test.cpp +@@ -479,7 +479,7 @@ int process4(jack_nframes_t nframes, void *arg) + jack_nframes_t delta_time = cur_time - last_time; + + Log("calling process4 callback : jack_frame_time = %ld delta_time = %ld\n", cur_time, delta_time); +- if (delta_time > 0 && (jack_nframes_t)abs(delta_time - cur_buffer_size) > tolerance) { ++ if (delta_time > 0 && (jack_nframes_t)fabs(delta_time - cur_buffer_size) > tolerance) { + printf("!!! ERROR !!! jack_frame_time seems to return incorrect values cur_buffer_size = %d, delta_time = %d tolerance %d\n", cur_buffer_size, delta_time, tolerance); + } + +@@ -1064,7 +1064,7 @@ int main (int argc, char *argv[]) + } + jack_sleep(1 * 1000); + cur_buffer_size = jack_get_buffer_size(client1); +- if (abs((old_buffer_size * factor) - cur_buffer_size) > 5) { // Tolerance needed for dummy driver... ++ if (fabs((old_buffer_size * factor) - cur_buffer_size) > 5) { // Tolerance needed for dummy driver... + printf("!!! ERROR !!! Buffer size has not been changed !\n"); + printf("!!! Maybe jack was compiled without the '--enable-resize' flag...\n"); + } else { diff --git a/pkgs/misc/jackaudio/darwin-cf.patch b/pkgs/misc/jackaudio/darwin-cf.patch new file mode 100644 index 00000000000000..0fc0902a0c480b --- /dev/null +++ b/pkgs/misc/jackaudio/darwin-cf.patch @@ -0,0 +1,49 @@ +diff --git a/common/Jackdmp.cpp b/common/Jackdmp.cpp +index 7eea281..4b8d75d 100644 +--- a/common/Jackdmp.cpp ++++ b/common/Jackdmp.cpp +@@ -50,43 +50,11 @@ are "hard-coded" in the source. A much better approach would be to use the contr + - get available drivers and their possible parameters, then prepare to parse them. + */ + +-#ifdef __APPLE__ +-#include +-#include +- +-static void notify_server_start(const char* server_name) +-{ +- // Send notification to be used in the JackRouter plugin +- CFStringRef ref = CFStringCreateWithCString(NULL, server_name, kCFStringEncodingMacRoman); +- CFNotificationCenterPostNotificationWithOptions(CFNotificationCenterGetDistributedCenter(), +- CFSTR("com.grame.jackserver.start"), +- ref, +- NULL, +- kCFNotificationDeliverImmediately | kCFNotificationPostToAllSessions); +- CFRelease(ref); +-} +- +-static void notify_server_stop(const char* server_name) +-{ +- // Send notification to be used in the JackRouter plugin +- CFStringRef ref1 = CFStringCreateWithCString(NULL, server_name, kCFStringEncodingMacRoman); +- CFNotificationCenterPostNotificationWithOptions(CFNotificationCenterGetDistributedCenter(), +- CFSTR("com.grame.jackserver.stop"), +- ref1, +- NULL, +- kCFNotificationDeliverImmediately | kCFNotificationPostToAllSessions); +- CFRelease(ref1); +-} +- +-#else +- + static void notify_server_start(const char* server_name) + {} + static void notify_server_stop(const char* server_name) + {} + +-#endif +- + static void copyright(FILE* file) + { + fprintf(file, "jackdmp " VERSION "\n" + diff --git a/pkgs/misc/jackaudio/default.nix b/pkgs/misc/jackaudio/default.nix index 52f288deba339c..20da91efede8d1 100644 --- a/pkgs/misc/jackaudio/default.nix +++ b/pkgs/misc/jackaudio/default.nix @@ -1,9 +1,12 @@ { stdenv, fetchFromGitHub, pkgconfig, python2Packages, makeWrapper , bash, libsamplerate, libsndfile, readline, eigen, celt +# Darwin Dependencies +, aften, AudioToolbox, CoreAudio, CoreFoundation # Optional Dependencies , dbus ? null, libffado ? null, alsaLib ? null , libopus ? null +, darwin # Extra options , prefix ? "" @@ -16,7 +19,7 @@ let libOnly = prefix == "lib"; - optDbus = shouldUsePkg dbus; + optDbus = if stdenv.isDarwin then null else shouldUsePkg dbus; optPythonDBus = if libOnly then null else shouldUsePkg dbus-python; optLibffado = if libOnly then null else shouldUsePkg libffado; optAlsaLib = if libOnly then null else shouldUsePkg alsaLib; @@ -34,21 +37,36 @@ stdenv.mkDerivation rec { }; nativeBuildInputs = [ pkgconfig python makeWrapper ]; - buildInputs = [ python libsamplerate libsndfile readline eigen celt + buildInputs = [ libsamplerate libsndfile readline eigen celt optDbus optPythonDBus optLibffado optAlsaLib optLibopus - ]; + ] ++ stdenv.lib.optionals stdenv.isDarwin [ aften AudioToolbox CoreAudio CoreFoundation ]; - patchPhase = '' - substituteInPlace svnversion_regenerate.sh --replace /bin/bash ${bash}/bin/bash + # CoreFoundation 10.10 doesn't include CFNotificationCenter.h yet. + patches = stdenv.lib.optionals stdenv.isDarwin [ ./clang.patch ./darwin-cf.patch ]; + + prePatch = '' + substituteInPlace svnversion_regenerate.sh \ + --replace /bin/bash ${bash}/bin/bash + ''; + + # It looks like one of the frameworks depends on + # since frameworks are impure we also have to use the impure CoreFoundation here. + # FIXME: remove when CoreFoundation is updated to 10.11 + preConfigure = stdenv.lib.optionalString stdenv.isDarwin '' + export NIX_CFLAGS_COMPILE="-F${CoreFoundation}/Library/Frameworks $NIX_CFLAGS_COMPILE" ''; configurePhase = '' + runHook preConfigure + python waf configure --prefix=$out \ ${optionalString (optDbus != null) "--dbus"} \ --classic \ ${optionalString (optLibffado != null) "--firewire"} \ ${optionalString (optAlsaLib != null) "--alsa"} \ --autostart=${if (optDbus != null) then "dbus" else "classic"} \ + + runHook postConfigure ''; buildPhase = '' diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index d9d6e00eeb954f..9eb309a66ec953 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -18793,6 +18793,7 @@ with pkgs; jack2Full = callPackage ../misc/jackaudio { libopus = libopus.override { withCustomModes = true; }; + inherit (darwin.apple_sdk.frameworks) AudioToolbox CoreAudio CoreFoundation; }; libjack2 = jack2Full.override { prefix = "lib"; };