nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 testers,
4 stdenv,
5 fetchFromGitHub,
6 openssl,
7 libsamplerate,
8 swig,
9 alsa-lib,
10 python3,
11 pythonSupport ? true,
12 runCommand,
13}:
14stdenv.mkDerivation (finalAttrs: {
15 pname = "pjsip";
16 version = "2.15.1";
17
18 src = fetchFromGitHub {
19 owner = "pjsip";
20 repo = "pjproject";
21 tag = finalAttrs.version;
22 hash = "sha256-9WzOIKWGy71OMzaPOp1P8/pvhHio2rDJOkH1VaNItjU=";
23 };
24
25 postPatch = ''
26 substituteInPlace \
27 pjsip-apps/src/py_pjsua/setup.py \
28 pjsip-apps/src/swig/python/setup.py \
29 pjsip-apps/src/python/setup.py \
30 pjsip-apps/src/python/setup-vc.py \
31 --replace-fail "distutils.core" "setuptools"
32 '';
33
34 nativeBuildInputs = lib.optionals pythonSupport [
35 swig
36 python3
37 python3.pkgs.build
38 python3.pkgs.installer
39 python3.pkgs.setuptools
40 python3.pkgs.wheel
41 ];
42
43 buildInputs = [
44 openssl
45 libsamplerate
46 ]
47 ++ lib.optional stdenv.hostPlatform.isLinux alsa-lib;
48
49 env = {
50 NIX_LDFLAGS = if stdenv.hostPlatform.isDarwin then "-lc++" else "-lstdc++";
51 }
52 // lib.optionalAttrs stdenv.cc.isClang { CXXFLAGS = "-std=c++11"; }
53 // lib.optionalAttrs stdenv.hostPlatform.isDarwin {
54 NIX_CFLAGS_LINK = "-headerpad_max_install_names";
55 };
56
57 preConfigure = ''
58 export LD=$CC
59 '';
60
61 postBuild = lib.optionalString pythonSupport ''
62 make -C pjsip-apps/src/swig/python
63 '';
64
65 configureFlags = [ "--enable-shared" ];
66
67 outputs = [ "out" ] ++ lib.optional pythonSupport "py";
68
69 postInstall = ''
70 mkdir -p $out/bin
71 cp pjsip-apps/bin/pjsua-* $out/bin/pjsua
72 mkdir -p $out/share/${finalAttrs.pname}-${finalAttrs.version}/samples
73 cp pjsip-apps/bin/samples/*/* $out/share/${finalAttrs.pname}-${finalAttrs.version}/samples
74 ''
75 + lib.optionalString pythonSupport ''
76 (cd pjsip-apps/src/swig/python && \
77 python -m build --no-isolation --outdir dist/ --wheel
78 python -m installer --prefix $py dist/*.whl
79 )
80 ''
81 + lib.optionalString stdenv.hostPlatform.isDarwin ''
82 # On MacOS relative paths are used to refer to libraries. All libraries use
83 # a relative path like ../lib/*.dylib or ../../lib/*.dylib. We need to
84 # rewrite these to use absolute ones.
85
86 # First, find all libraries (and their symlinks) in our outputs to define
87 # the install_name_tool -change arguments we should pass.
88 readarray -t libraries < <(
89 for outputName in $(getAllOutputNames); do
90 find "''${!outputName}" \( -name '*.dylib*' -o -name '*.so*' \)
91 done
92 )
93
94 # Determine the install_name_tool -change arguments that are going to be
95 # applied to all libraries.
96 change_args=()
97 for lib in "''${libraries[@]}"; do
98 lib_name="$(basename $lib)"
99 change_args+=(-change ../lib/$lib_name $lib)
100 change_args+=(-change ../../lib/$lib_name $lib)
101 done
102
103 # Rewrite id and library refences for all non-symlinked libraries.
104 for lib in "''${libraries[@]}"; do
105 if [ -f "$lib" ]; then
106 install_name_tool -id $lib "''${change_args[@]}" $lib
107 fi
108 done
109
110 # Rewrite library references for all executables.
111 find "$out" -type f -executable -path "*/bin/*" -o -type f -executable -path "*/share/*/samples/*" \
112 | while read executable; do
113 if isMachO "$executable"; then
114 install_name_tool "''${change_args[@]}" "$executable"
115 fi
116 done
117 '';
118
119 # We need the libgcc_s.so.1 loadable (for pthread_cancel to work)
120 dontPatchELF = true;
121
122 passthru.tests.version = testers.testVersion {
123 package = finalAttrs.finalPackage;
124 command = "pjsua --version";
125 };
126
127 passthru.tests.pkg-config = testers.hasPkgConfigModules { package = finalAttrs.finalPackage; };
128
129 passthru.tests.python-pjsua2 = runCommand "python-pjsua2" { } ''
130 ${(python3.withPackages (pkgs: [ pkgs.pjsua2 ])).interpreter} -c "import pjsua2" > $out
131 '';
132
133 meta = with lib; {
134 description = "Multimedia communication library written in C, implementing standard based protocols such as SIP, SDP, RTP, STUN, TURN, and ICE";
135 homepage = "https://pjsip.org/";
136 license = licenses.gpl2Plus;
137 maintainers = with maintainers; [ olynch ];
138 mainProgram = "pjsua";
139 platforms = platforms.linux ++ platforms.darwin;
140 pkgConfigModules = [ "libpjproject" ];
141 };
142})