pjsip: format

This commit is contained in:
linsui 2024-07-09 20:40:54 +08:00 committed by linsui
parent 3c2e182677
commit af3f6ca5ff

View File

@ -1,17 +1,18 @@
{ lib {
, testers lib,
, stdenv testers,
, fetchFromGitHub stdenv,
, openssl fetchFromGitHub,
, libsamplerate openssl,
, swig libsamplerate,
, alsa-lib swig,
, AppKit alsa-lib,
, CoreFoundation AppKit,
, Security CoreFoundation,
, python3 Security,
, pythonSupport ? true python3,
, runCommand pythonSupport ? true,
runCommand,
}: }:
stdenv.mkDerivation (finalAttrs: { stdenv.mkDerivation (finalAttrs: {
pname = "pjsip"; pname = "pjsip";
@ -24,22 +25,28 @@ stdenv.mkDerivation (finalAttrs: {
hash = "sha256-LDA3o1QMrAxcGuOi/YRoMzXmw/wFkfDs2wweZuIJ2RY="; hash = "sha256-LDA3o1QMrAxcGuOi/YRoMzXmw/wFkfDs2wweZuIJ2RY=";
}; };
patches = [ patches = [ ./fix-aarch64.patch ];
./fix-aarch64.patch
nativeBuildInputs = lib.optionals pythonSupport [
swig
python3
]; ];
nativeBuildInputs = buildInputs =
lib.optionals pythonSupport [ swig python3 ]; [
openssl
buildInputs = [ openssl libsamplerate ] libsamplerate
]
++ lib.optional stdenv.isLinux alsa-lib ++ lib.optional stdenv.isLinux alsa-lib
++ lib.optionals stdenv.isDarwin [ AppKit CoreFoundation Security ]; ++ lib.optionals stdenv.isDarwin [
AppKit
CoreFoundation
Security
];
env = lib.optionalAttrs stdenv.cc.isClang { env =
CXXFLAGS = "-std=c++11"; lib.optionalAttrs stdenv.cc.isClang { CXXFLAGS = "-std=c++11"; }
} // lib.optionalAttrs stdenv.isDarwin { // lib.optionalAttrs stdenv.isDarwin { NIX_CFLAGS_LINK = "-headerpad_max_install_names"; };
NIX_CFLAGS_LINK = "-headerpad_max_install_names";
};
preConfigure = '' preConfigure = ''
export LD=$CC export LD=$CC
@ -51,52 +58,54 @@ stdenv.mkDerivation (finalAttrs: {
configureFlags = [ "--enable-shared" ]; configureFlags = [ "--enable-shared" ];
outputs = [ "out" ] outputs = [ "out" ] ++ lib.optional pythonSupport "py";
++ lib.optional pythonSupport "py";
postInstall = '' postInstall =
mkdir -p $out/bin ''
cp pjsip-apps/bin/pjsua-* $out/bin/pjsua mkdir -p $out/bin
mkdir -p $out/share/${finalAttrs.pname}-${finalAttrs.version}/samples cp pjsip-apps/bin/pjsua-* $out/bin/pjsua
cp pjsip-apps/bin/samples/*/* $out/share/${finalAttrs.pname}-${finalAttrs.version}/samples mkdir -p $out/share/${finalAttrs.pname}-${finalAttrs.version}/samples
'' + lib.optionalString pythonSupport '' cp pjsip-apps/bin/samples/*/* $out/share/${finalAttrs.pname}-${finalAttrs.version}/samples
(cd pjsip-apps/src/swig/python && \ ''
python setup.py install --prefix=$py + lib.optionalString pythonSupport ''
) (cd pjsip-apps/src/swig/python && \
'' + lib.optionalString stdenv.isDarwin '' python setup.py install --prefix=$py
# 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. + 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 # First, find all libraries (and their symlinks) in our outputs to define
# the install_name_tool -change arguments we should pass. # the install_name_tool -change arguments we should pass.
readarray -t libraries < <( readarray -t libraries < <(
for outputName in $(getAllOutputNames); do for outputName in $(getAllOutputNames); do
find "''${!outputName}" \( -name '*.dylib*' -o -name '*.so*' \) 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 done
)
# Determine the install_name_tool -change arguments that are going to be # Rewrite id and library refences for all non-symlinked libraries.
# applied to all libraries. for lib in "''${libraries[@]}"; do
change_args=() if [ -f "$lib" ]; then
for lib in "''${libraries[@]}"; do install_name_tool -id $lib "''${change_args[@]}" $lib
lib_name="$(basename $lib)" fi
change_args+=(-change ../lib/$lib_name $lib) done
change_args+=(-change ../../lib/$lib_name $lib)
done
# Rewrite id and library refences for all non-symlinked libraries. # Rewrite library references for all executables.
for lib in "''${libraries[@]}"; do find "$out" -executable -type f | while read executable; do
if [ -f "$lib" ]; then install_name_tool "''${change_args[@]}" "$executable"
install_name_tool -id $lib "''${change_args[@]}" $lib done
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) # We need the libgcc_s.so.1 loadable (for pthread_cancel to work)
dontPatchELF = true; dontPatchELF = true;
@ -106,9 +115,7 @@ stdenv.mkDerivation (finalAttrs: {
command = "pjsua --version"; command = "pjsua --version";
}; };
passthru.tests.pkg-config = testers.hasPkgConfigModules { passthru.tests.pkg-config = testers.hasPkgConfigModules { package = finalAttrs.finalPackage; };
package = finalAttrs.finalPackage;
};
passthru.tests.python-pjsua2 = runCommand "python-pjsua2" { } '' passthru.tests.python-pjsua2 = runCommand "python-pjsua2" { } ''
${(python3.withPackages (pkgs: [ pkgs.pjsua2 ])).interpreter} -c "import pjsua2" > $out ${(python3.withPackages (pkgs: [ pkgs.pjsua2 ])).interpreter} -c "import pjsua2" > $out
@ -121,8 +128,6 @@ stdenv.mkDerivation (finalAttrs: {
maintainers = with maintainers; [ olynch ]; maintainers = with maintainers; [ olynch ];
mainProgram = "pjsua"; mainProgram = "pjsua";
platforms = platforms.linux ++ platforms.darwin; platforms = platforms.linux ++ platforms.darwin;
pkgConfigModules = [ pkgConfigModules = [ "libpjproject" ];
"libpjproject"
];
}; };
}) })