summaryrefslogtreecommitdiff
path: root/guix
diff options
context:
space:
mode:
authorRicardo Wurmus <rekado@elephly.net>2023-02-17 22:25:27 +0100
committerRicardo Wurmus <rekado@elephly.net>2023-02-18 19:56:30 +0100
commit049cff91acd3ace275c3f2af97755812af023c6b (patch)
tree2ebb1546b018836582513fe5aa37aa735db7f7e4 /guix
parent271c0bfcf2dcea967f9baf02baf179677d179190 (diff)
import/cran: Add generic way to detect needed libraries.
* guix/import/cran.scm (needed-libraries-in-directory): New procedure. (libraries-pattern, packages-for-matches): New variables.
Diffstat (limited to 'guix')
-rw-r--r--guix/import/cran.scm45
1 files changed, 45 insertions, 0 deletions
diff --git a/guix/import/cran.scm b/guix/import/cran.scm
index ebd340ecfa..75caecb620 100644
--- a/guix/import/cran.scm
+++ b/guix/import/cran.scm
@@ -55,6 +55,7 @@
#:use-module (guix ui)
#:use-module (guix upstream)
#:use-module (guix packages)
+ #:use-module (guix sets)
#:use-module (gnu packages)
#:export (%input-style
@@ -475,6 +476,50 @@ the given REGEXP."
zlib linker flag."
(files-match-pattern? dir "-lz" "(Makevars.*|configure.*)"))
+(define packages-for-matches
+ '(("-lcrypto" . "openssl")
+ ("-lcurl" . "curl")
+ ("-lgit2" . "libgit2")
+ ("-lpcre" . "pcre2")
+ ("-lssh" . "openssh")
+ ("-lssl" . "openssl")
+ ("-ltbb" . "tbb")
+ ("-lz" . "zlib")
+ ("gsl-config" . "gsl")
+ ("xml2-config" . "libxml2")
+ ("CURL_LIBS" . "curl")))
+
+(define libraries-pattern
+ (make-regexp
+ (string-append "("
+ (string-join
+ (map (compose regexp-quote first) packages-for-matches) "|")
+ ")")))
+
+(define (needed-libraries-in-directory dir)
+ "Return a list of package names that correspond to libraries that are
+referenced in build system files."
+ (set->list
+ (fold
+ (lambda (file packages)
+ (call-with-input-file file
+ (lambda (port)
+ (let loop ((packages packages))
+ (let ((line (read-line port)))
+ (cond
+ ((eof-object? line) packages)
+ (else
+ (loop
+ (fold (lambda (match acc)
+ (or (and=> (assoc-ref packages-for-matches
+ (match:substring match))
+ (cut set-insert <> acc))
+ acc))
+ packages
+ (list-matches libraries-pattern line))))))))))
+ (set)
+ (find-files dir "(Makevars.in*|configure.*)"))))
+
(define (directory-needs-pkg-config? dir)
"Return #T if any of the Makevars files in the src directory DIR reference
the pkg-config tool."