Unverified Commit 39f464d7 authored by h7x4's avatar h7x4 Committed by GitHub
Browse files

codec2: fix cross compilation (#384418)

parents 90e4a261 b290d10a
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
{
  lib,
  stdenv,
  buildPackages,
  fetchFromGitHub,
  cmake,
  freedvSupport ? false,
@@ -18,12 +19,23 @@ stdenv.mkDerivation rec {
    hash = "sha256-69Mp4o3MgV98Fqfai4txv5jQw2WpoPuoWcwHsNAFPQM=";
  };

  nativeBuildInputs = [ cmake ];
  nativeBuildInputs = [
    cmake
    buildPackages.stdenv.cc # needs to build a C program to run at build time
  ];

  buildInputs = lib.optionals freedvSupport [
    lpcnetfreedv
  ];

  # we need to unset these variables from stdenv here and then set their equivalents in the cmake flags
  # otherwise it will pass the same compiler to the native and cross phases and crash trying to execute
  # host binaries (generate_codebook) on the build system.
  preConfigure = ''
    unset CC
    unset CXX
  '';

  postInstall = ''
    install -Dm0755 src/{c2enc,c2sim,freedv_rx,freedv_tx,cohpsk_*,fdmdv_*,fsk_*,ldpc_*,ofdm_*} -t $out/bin/
  '';
@@ -37,6 +49,8 @@ stdenv.mkDerivation rec {
    [
      # RPATH of binary /nix/store/.../bin/freedv_rx contains a forbidden reference to /build/
      "-DCMAKE_SKIP_BUILD_RPATH=ON"
      "-DCMAKE_C_COMPILER=${stdenv.cc.targetPrefix}cc"
      "-DCMAKE_CXX_COMPILER=${stdenv.cc.targetPrefix}c++"
    ]
    ++ lib.optionals freedvSupport [
      "-DLPCNET=ON"