diff --git a/pkgs/development/libraries/libsvm/default.nix b/pkgs/development/libraries/libsvm/default.nix index fbc9bc4d33143..e1f1830b134a7 100644 --- a/pkgs/development/libraries/libsvm/default.nix +++ b/pkgs/development/libraries/libsvm/default.nix @@ -1,33 +1,49 @@ -{lib, stdenv, fetchurl}: +{ lib +, stdenv +, fetchurl +, fixDarwinDylibNames +, llvmPackages +, withOpenMP ? true +}: stdenv.mkDerivation rec { pname = "libsvm"; - version = "3.25"; + version = "3.31"; src = fetchurl { url = "https://www.csie.ntu.edu.tw/~cjlin/libsvm/libsvm-${version}.tar.gz"; - sha256 = "sha256-UjUOiqdAsXbh13Pp3AjxNAIYw34BvsN6uQ2wEn5LteU="; + sha256 = "sha256-AKtWH0jfX8kqhCCa2P5Rmery5Rmzwnm6z8k1l4p1zx8="; }; - buildPhase = '' - make - make lib - ''; - - installPhase = let - libSuff = stdenv.hostPlatform.extensions.sharedLibrary; - in '' - install -D libsvm.so.2 $out/lib/libsvm.2${libSuff} - ln -s $out/lib/libsvm.2${libSuff} $out/lib/libsvm${libSuff} - install -Dt $out/bin/ svm-scale svm-train svm-predict - install -Dm644 -t $out/include svm.h - mkdir $out/include/libsvm - ln -s $out/include/svm.h $out/include/libsvm/svm.h - ''; - - postFixup = lib.optionalString stdenv.isDarwin '' - install_name_tool -id libsvm.2.dylib $out/lib/libsvm.2.dylib; - ''; + patches = lib.optionals withOpenMP [ ./openmp.patch ]; + + buildInputs = lib.optionals (stdenv.cc.isClang && withOpenMP) [ llvmPackages.openmp ]; + + buildFlags = [ "lib" "all" ]; + + outputs = [ "out" "bin" "dev" ]; + + nativeBuildInputs = lib.optionals stdenv.isDarwin [ fixDarwinDylibNames ]; + + installPhase = + let + libSuff = stdenv.hostPlatform.extensions.sharedLibrary; + soVersion = "3"; + in + '' + runHook preInstall + + install -D libsvm.so.${soVersion} $out/lib/libsvm.${soVersion}${libSuff} + ln -s $out/lib/libsvm.${soVersion}${libSuff} $out/lib/libsvm${libSuff} + + install -Dt $bin/bin/ svm-scale svm-train svm-predict + + install -Dm644 -t $dev/include svm.h + mkdir $dev/include/libsvm + ln -s $dev/include/svm.h $dev/include/libsvm/svm.h + + runHook postInstall + ''; meta = with lib; { description = "A library for support vector machines"; diff --git a/pkgs/development/libraries/libsvm/openmp.patch b/pkgs/development/libraries/libsvm/openmp.patch new file mode 100644 index 0000000000000..b48fbae1f43fa --- /dev/null +++ b/pkgs/development/libraries/libsvm/openmp.patch @@ -0,0 +1,13 @@ +--- /Makefile 1970-01-01 01:00:01.000000000 +0100 ++++ /Makefile 1970-01-01 01:00:01.000000000 +0100 +@@ -9,8 +9,8 @@ + endif + + # Uncomment the following lines to enable parallelization with OpenMP +-# CFLAGS += -fopenmp +-# SHARED_LIB_FLAG += -fopenmp ++CFLAGS += -fopenmp ++SHARED_LIB_FLAG += -fopenmp + + all: svm-train svm-predict svm-scale +