at master 88 lines 2.3 kB view raw
1{ 2 lib, 3 testers, 4 stdenv, 5 buildPackages, 6 fetchFromGitHub, 7 cmake, 8 freedvSupport ? false, 9 lpcnet, 10}: 11 12stdenv.mkDerivation (finalAttrs: { 13 pname = "codec2"; 14 version = "1.2.0"; 15 16 src = fetchFromGitHub { 17 owner = "drowe67"; 18 repo = "codec2"; 19 rev = finalAttrs.version; 20 hash = "sha256-69Mp4o3MgV98Fqfai4txv5jQw2WpoPuoWcwHsNAFPQM="; 21 }; 22 23 patches = [ 24 # Fix nix-store path dupliucations 25 ./fix-pkg-config.patch 26 ]; 27 28 outputs = [ 29 "out" 30 "lib" 31 "dev" 32 ]; 33 34 nativeBuildInputs = [ 35 cmake 36 buildPackages.stdenv.cc # needs to build a C program to run at build time 37 ]; 38 39 buildInputs = lib.optionals freedvSupport [ 40 lpcnet 41 ]; 42 43 # we need to unset these variables from stdenv here and then set their equivalents in the cmake flags 44 # otherwise it will pass the same compiler to the native and cross phases and crash trying to execute 45 # host binaries (generate_codebook) on the build system. 46 preConfigure = '' 47 unset CC 48 unset CXX 49 ''; 50 51 postInstall = '' 52 install -Dm0755 src/{c2enc,c2dec,c2sim,freedv_rx,freedv_tx,cohpsk_*,fdmdv_*,fsk_*,ldpc_*,ofdm_*} -t $out/bin/ 53 ''; 54 55 postFixup = 56 # Swap keyword order to satisfy SWIG parser 57 '' 58 sed -r -i 's/(\<_Complex)(\s+)(float|double)/\3\2\1/' $dev/include/$pname/freedv_api.h 59 '' 60 + 61 # generated cmake module is not compatible with multiple outputs 62 '' 63 substituteInPlace $dev/lib/cmake/codec2/codec2-config.cmake --replace-fail \ 64 '"''${_IMPORT_PREFIX}/include/codec2' \ 65 "\"$dev/include/codec2" 66 ''; 67 68 cmakeFlags = [ 69 # RPATH of binary /nix/store/.../bin/freedv_rx contains a forbidden reference to /build/ 70 "-DCMAKE_SKIP_BUILD_RPATH=ON" 71 "-DCMAKE_C_COMPILER=${stdenv.cc.targetPrefix}cc" 72 "-DCMAKE_CXX_COMPILER=${stdenv.cc.targetPrefix}c++" 73 ] 74 ++ lib.optionals freedvSupport [ 75 "-DLPCNET=ON" 76 ]; 77 78 passthru.tests.pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage; 79 80 meta = with lib; { 81 description = "Speech codec designed for communications quality speech at low data rates"; 82 homepage = "https://www.rowetel.com/codec2.html"; 83 license = licenses.lgpl21Only; 84 platforms = platforms.unix; 85 maintainers = with maintainers; [ markuskowa ]; 86 pkgConfigModules = [ "codec2" ]; 87 }; 88})