about summary refs log tree commit diff
path: root/nixpkgs/pkgs/applications/networking/pjsip/default.nix
blob: 1943a395bd7b7a9bb3b5261305803b22814d7a5f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
{ lib
, testers
, stdenv
, fetchFromGitHub
, openssl
, libsamplerate
, swig
, alsa-lib
, AppKit
, CoreFoundation
, Security
, python3
, pythonSupport ? true
, runCommand
}:
stdenv.mkDerivation (finalAttrs: {
  pname = "pjsip";
  version = "2.14";

  src = fetchFromGitHub {
    owner = finalAttrs.pname;
    repo = "pjproject";
    rev = "refs/tags/${finalAttrs.version}";
    hash = "sha256-PWCeIvnBAOqbcNYPhIY7hykdvLzoD9lssSViCCPNT68=";
  };

  patches = [
    ./fix-aarch64.patch
  ];

  nativeBuildInputs =
    lib.optionals pythonSupport [ swig python3 ];

  buildInputs = [ openssl libsamplerate ]
    ++ lib.optional stdenv.isLinux alsa-lib
    ++ lib.optionals stdenv.isDarwin [ AppKit CoreFoundation Security ];

  env = lib.optionalAttrs (stdenv.cc.libcxx != null) {
    # work around https://github.com/NixOS/nixpkgs/issues/166205
    NIX_LDFLAGS = "-l${stdenv.cc.libcxx.cxxabi.libName}";
  } // lib.optionalAttrs stdenv.cc.isClang {
    CXXFLAGS = "-std=c++11";
  } // lib.optionalAttrs stdenv.isDarwin {
    NIX_CFLAGS_LINK = "-headerpad_max_install_names";
  };

  preConfigure = ''
    export LD=$CC
  '';

  postBuild = lib.optionalString pythonSupport ''
    make -C pjsip-apps/src/swig/python
  '';

  configureFlags = [ "--enable-shared" ];

  outputs = [ "out" ]
    ++ lib.optional pythonSupport "py";

  postInstall = ''
    mkdir -p $out/bin
    cp pjsip-apps/bin/pjsua-* $out/bin/pjsua
    mkdir -p $out/share/${finalAttrs.pname}-${finalAttrs.version}/samples
    cp pjsip-apps/bin/samples/*/* $out/share/${finalAttrs.pname}-${finalAttrs.version}/samples
  '' + lib.optionalString pythonSupport ''
    (cd pjsip-apps/src/swig/python && \
      python setup.py install --prefix=$py
    )
  '' + lib.optionalString stdenv.isDarwin ''
    # On MacOS relative paths are used to refer to libraries. All libraries use
    # a relative path like ../lib/*.dylib or ../../lib/*.dylib. We need to
    # rewrite these to use absolute ones.

    # First, find all libraries (and their symlinks) in our outputs to define
    # the install_name_tool -change arguments we should pass.
    readarray -t libraries < <(
      for outputName in $(getAllOutputNames); do
        find "''${!outputName}" \( -name '*.dylib*' -o -name '*.so*' \)
      done
    )

    # Determine the install_name_tool -change arguments that are going to be
    # applied to all libraries.
    change_args=()
    for lib in "''${libraries[@]}"; do
      lib_name="$(basename $lib)"
      change_args+=(-change ../lib/$lib_name $lib)
      change_args+=(-change ../../lib/$lib_name $lib)
    done

    # Rewrite id and library refences for all non-symlinked libraries.
    for lib in "''${libraries[@]}"; do
      if [ -f "$lib" ]; then
        install_name_tool -id $lib "''${change_args[@]}" $lib
      fi
    done

    # Rewrite library references for all executables.
    find "$out" -executable -type f | while read executable; do
      install_name_tool "''${change_args[@]}" "$executable"
    done
  '';

  # We need the libgcc_s.so.1 loadable (for pthread_cancel to work)
  dontPatchELF = true;

  passthru.tests.version = testers.testVersion {
    package = finalAttrs.finalPackage;
    command = "pjsua --version";
  };

  passthru.tests.pkg-config = testers.hasPkgConfigModules {
    package = finalAttrs.finalPackage;
  };

  passthru.tests.python-pjsua2 = runCommand "python-pjsua2" { } ''
    ${(python3.withPackages (pkgs: [ pkgs.pjsua2 ])).interpreter} -c "import pjsua2" > $out
  '';

  meta = with lib; {
    description = "A multimedia communication library written in C, implementing standard based protocols such as SIP, SDP, RTP, STUN, TURN, and ICE";
    homepage = "https://pjsip.org/";
    license = licenses.gpl2Plus;
    maintainers = with maintainers; [ olynch ];
    mainProgram = "pjsua";
    platforms = platforms.linux ++ platforms.darwin;
    pkgConfigModules = [
      "libpjproject"
    ];
  };
})