@@ -60,6 +60,7 @@ (define-module (guix transformations)
tunable-package?
tuned-package
+ multituned-package
show-transformation-options-help
transformation-option-key?
@@ -634,6 +635,80 @@ (define (tuned-package p micro-architecture)
;; call 'tuned-package' again on this one.
,@(alist-delete 'tunable? (package-properties p))))))
+(define (package-tuned-for-psabi p psabi)
+ (let ((base (tuned-package p psabi)))
+ (package/inherit base
+ (name (string-append (package-name base) "-" psabi))
+ (arguments
+ (substitute-keyword-arguments (package-arguments base)
+ ((#:configure-flags flags #~'())
+ #~(append
+ (list
+ #$@(if (eq? (build-system-name (package-build-system p)) ; not base
+ (quote cmake-build-system))
+ #~((string-append "-DCMAKE_INSTALL_LIBDIR=lib/glibc-hwcaps/"
+ #$psabi))
+ #~((string-append "--libdir=" #$output
+ "/lib/glibc-hwcaps/" #$psabi))))
+ #$flags))
+ ((#:phases phases #~%standard-phases)
+ #~(modify-phases #$phases
+ (add-after 'install 'remove-extra-files
+ (lambda _
+ (for-each (lambda (dir)
+ (when (file-exists? (string-append #$output dir))
+ (delete-file-recursively
+ (string-append #$output dir))))
+ (list (string-append "/lib/glibc-hwcaps/"
+ #$psabi "/cmake")
+ (string-append "/lib/glibc-hwcaps/"
+ #$psabi "/pkgconfig")
+ "/bin" "/etc" "/include" "/libexec"
+ "/sbin" "/share" "/var")))))))))))
+
+(define (multituned-package p)
+ (package/inherit p
+ (arguments
+ (substitute-keyword-arguments (package-arguments p)
+ ((#:phases phases #~%standard-phases)
+ (if (or (target-x86-64?)
+ (target-ppc64le?))
+ #~(modify-phases #$phases
+ (add-after 'install 'install-optimized-libraries
+ (lambda* (#:key inputs outputs #:allow-other-keys)
+ (let ((hwcaps "/lib/glibc-hwcaps/"))
+ (for-each
+ (lambda (psabi)
+ (copy-recursively
+ (string-append
+ (assoc-ref inputs (string-append
+ #$(package-name p) "-" psabi))
+ hwcaps psabi)
+ (string-append #$output hwcaps psabi)))
+ #$(cond ((target-x86-64?)
+ #~(list "x86-64-v2" "x86-64-v3" "x86-64-v4"))
+ ((target-ppc64le?)
+ #~(list "power9" "power10"))
+ (#t #~'())))))))
+ phases))))
+ (inputs
+ (cond ((target-x86-64?)
+ (modify-inputs (package-inputs p)
+ (append (package-tuned-for-psabi p "x86-64-v2")
+ (package-tuned-for-psabi p "x86-64-v3")
+ (package-tuned-for-psabi p "x86-64-v4"))))
+ ((target-ppc64le?)
+ (modify-inputs (package-inputs p)
+ (append (package-tuned-for-psabi p "power9")
+ (package-tuned-for-psabi p "power10"))))
+ (#t (package-inputs p))))
+ ;; With the addition of the psABIs this package should not be tuned.
+ (properties
+ (if (or (target-x86-64?)
+ (target-ppc64le?))
+ '((alist-delete 'tunable? (package-properties p)))
+ (package-properties p)))))
+
(define (tunable-package? package)
"Return true if package PACKAGE is \"tunable\"--i.e., if tuning it for the
host CPU is worthwhile."