diff mbox series

[bug#66263,07/23] gnu: Add AVR phases to cross-gcc-build-phases.

Message ID 20230929091627.7820-7-jean@foundationdevices.com
State New
Headers show
Series guix: Add avr as a platform. | expand

Commit Message

Jean-Pierre De Jesus DIAZ Sept. 29, 2023, 9:16 a.m. UTC
* gnu/build/cross-toolchain.scm (set-cross-path/avr): New procedure.

* gnu/build/cross-toolchain.scm (cross-gcc-build-phases): Add case for
  AVR target.
---
 gnu/build/cross-toolchain.scm | 41 +++++++++++++++++++++++++++++------
 1 file changed, 34 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/gnu/build/cross-toolchain.scm b/gnu/build/cross-toolchain.scm
index 9746be3e50..8de62be593 100644
--- a/gnu/build/cross-toolchain.scm
+++ b/gnu/build/cross-toolchain.scm
@@ -97,6 +97,31 @@  (define (cross? x)
      ;; We're building the sans-libc cross-compiler, so nothing to do.
      #t)))
 
+(define* (set-cross-path/avr #:key inputs #:allow-other-keys)
+  (match (assoc-ref inputs "libc")
+    ((? string? libc)
+     (define (cross? x)
+       ;; Return #t if X is a cross-libc.
+       (string-prefix? libc x))
+
+     (let ((cpath (string-append libc "/avr/include")))
+       (for-each (cut setenv <> cpath)
+                 %gcc-cross-include-paths))
+
+     (setenv "CROSS_LIBRARY_PATH"
+             (string-append libc "/avr/lib"))
+
+     (for-each (lambda (var)
+                   (and=> (getenv var)
+                          (lambda (value)
+                            (let* ((path (search-path-as-string->list value))
+                                   (native-path (list->search-path-as-string
+                                                 (remove cross? path) ":")))
+                              (setenv var native-path)))))
+                 (cons "LIBRARY_PATH" %gcc-include-paths)))
+    ;; AVR sans-libc cross-compiler.
+    (else #t)))
+
 (define* (set-cross-path/mingw #:key inputs target #:allow-other-keys)
   "Add the cross MinGW headers to CROSS_C_*_INCLUDE_PATH, and remove them from
 C_*INCLUDE_PATH."
@@ -174,13 +199,15 @@  (define* (cross-gcc-build-phases target
 a target triplet."
   (modify-phases phases
     (add-before 'configure 'set-cross-path
-      ;; This mingw32 target checking logic should match that of target-mingw?
-      ;; in (guix utils), but (guix utils) is too large too copy over to the
-      ;; build side entirely and for now we have no way to select variables to
-      ;; copy over. See (gnu packages cross-base) for more details.
-      (if (string-suffix? "-mingw32" target)
-          (cut set-cross-path/mingw #:target target <...>)
-          set-cross-path))
+      (cond
+        ;; This mingw32 target checking logic should match that of target-mingw?
+        ;; in (guix utils), but (guix utils) is too large too copy over to the
+        ;; build side entirely and for now we have no way to select variables to
+        ;; copy over. See (gnu packages cross-base) for more details.
+        ((string-suffix? "-mingw32" target)
+         (cut set-cross-path/mingw #:target target <...>))
+        ((string-prefix? "avr" target) set-cross-path/avr)
+        (else set-cross-path)))
     (add-after 'install 'make-cross-binutils-visible
       (cut make-cross-binutils-visible #:target target <...>))
     (replace 'install install-strip)))