Subject: [bug#66263] [PATCH v1 09/22] gnu: cross-libc: Add AVR Libc support.

From: Jean-Pierre De Jesus DIAZ <[email-masked]>
Date: Tue, 28 Nov 2023 12:34:52 +0100

* gnu/packages/avr.scm (make-avr-libc/implementation)
  <arguments>: Add avr target parameter and disable implicit cross inputs.
  <native-inputs>: Rename avr-gcc and avr-binutils to cross-gcc
  and cross-binutils to keep consistency with gnu-build-system.
* gnu/packages/cross-base.scm (cross-libc) [target-avr?]: Return AVR
  Libc package from `make-avr-libc`.

Change-Id: I6b087946d1287a82fac61c48c513e7f2d2184794
---
 gnu/packages/avr.scm        | 21 ++++++++++++++-------
 gnu/packages/cross-base.scm |  4 ++++
 2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/gnu/packages/avr.scm b/gnu/packages/avr.scm
index ac09b799f3..fc87e4ea13 100644
--- a/gnu/packages/avr.scm
+++ b/gnu/packages/avr.scm
@@ -40,7 +40,8 @@ (define-module (gnu packages avr)
   #:use-module (gnu packages gcc)
   #:use-module (gnu packages llvm)
   #:use-module (gnu packages vim)
-  #:export (make-avr-toolchain))
+  #:export (make-avr-libc
+            make-avr-toolchain))
 
 ;;; Commentary:
 ;;;
@@ -108,7 +109,10 @@ (define* (make-avr-gcc/implementation #:key (xgcc gcc))
 (define make-avr-gcc
   (memoize make-avr-gcc/implementation))
 
-(define* (make-avr-libc/implementation #:key (xgcc gcc))
+(define* (make-avr-libc/implementation #:key
+                                       (xbinutils (cross-binutils "avr"))
+                                       (xgcc (cross-gcc "avr"
+                                                        #:xbinutils xbinutils)))
   (package
     (name "avr-libc")
     (version "2.0.0")
@@ -121,10 +125,13 @@ (define* (make-avr-libc/implementation #:key (xgcc gcc))
                 "15svr2fx8j6prql2il2fc0ppwlv50rpmyckaxx38d3gxxv97zpdj"))))
     (build-system gnu-build-system)
     (arguments
-     '(#:out-of-source? #t
-       #:configure-flags '("--host=avr")))
-    (native-inputs `(("avr-binutils" ,(make-avr-binutils))
-                     ("avr-gcc" ,(make-avr-gcc #:xgcc xgcc))))
+     '(#:target "avr"
+       #:out-of-source? #t
+       ;; Avoid including itself as this package is a target input and cannot
+       ;; use the normal cross compilation inputs.
+       #:implicit-cross-inputs? #f))
+    (native-inputs `(("cross-binutils" ,xbinutils)
+                     ("cross-gcc" ,xgcc)))
     (home-page "https://www.nongnu.org/avr-libc/")
     (synopsis "AVR C Library")
     (description
@@ -138,7 +145,7 @@ (define make-avr-libc
 
 (define* (make-avr-toolchain/implementation #:key (xgcc gcc))
   (let ((avr-binutils (make-avr-binutils))
-        (avr-libc (make-avr-libc #:xgcc xgcc))
+        (avr-libc (make-avr-libc #:xgcc (cross-gcc "avr" #:xgcc xgcc)))
         (avr-gcc (make-avr-gcc #:xgcc xgcc)))
     ;; avr-libc checks the compiler version and passes "--enable-device-lib"
     ;; for avr-gcc > 5.1.0.  It wouldn't install the library for atmega32u4
diff --git a/gnu/packages/cross-base.scm b/gnu/packages/cross-base.scm
index fe33770c2a..d4a0de6f90 100644
--- a/gnu/packages/cross-base.scm
+++ b/gnu/packages/cross-base.scm
@@ -28,6 +28,7 @@
 
 (define-module (gnu packages cross-base)
   #:use-module (gnu packages)
+  #:use-module (gnu packages avr)
   #:use-module (gnu packages gcc)
   #:use-module (gnu packages base)
   #:use-module (gnu packages linux)
@@ -699,6 +700,9 @@ (define* (cross-libc* target
                                 '())
                           ,@(package-inputs libc) ;FIXME: static-bash
                           ,@(package-native-inputs libc)))))
+   ((? target-avr?)
+    (make-avr-libc #:xbinutils xbinutils
+                   #:xgcc xgcc))
    (else #f)))
 
 
-- 
2.41.0