From patchwork Tue Sep 26 19:04:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxim Cournoyer X-Patchwork-Id: 54326 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id C362027BBE2; Tue, 26 Sep 2023 20:39:42 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI, SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 79D5B27BBEA for ; Tue, 26 Sep 2023 20:39:40 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qlDtV-0006fG-QA; Tue, 26 Sep 2023 15:38:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qlDtS-0006eL-G2 for guix-patches@gnu.org; Tue, 26 Sep 2023 15:38:50 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qlDtQ-0006M5-Iv for guix-patches@gnu.org; Tue, 26 Sep 2023 15:38:50 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qlDtd-00010h-Ml for guix-patches@gnu.org; Tue, 26 Sep 2023 15:39:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#66217] [PATCH 01/22] gnu: make-avr-toolchain: Add a #:xgcc argument. Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 26 Sep 2023 19:39:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66217 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 66217@debbugs.gnu.org Cc: Maxim Cournoyer Received: via spool by 66217-submit@debbugs.gnu.org id=B66217.16957570913552 (code B ref 66217); Tue, 26 Sep 2023 19:39:01 +0000 Received: (at 66217) by debbugs.gnu.org; 26 Sep 2023 19:38:11 +0000 Received: from localhost ([127.0.0.1]:49794 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qlDso-0000v2-MF for submit@debbugs.gnu.org; Tue, 26 Sep 2023 15:38:11 -0400 Received: from mail-oo1-xc33.google.com ([2607:f8b0:4864:20::c33]:58867) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qlDsm-0000uj-DP for 66217@debbugs.gnu.org; Tue, 26 Sep 2023 15:38:09 -0400 Received: by mail-oo1-xc33.google.com with SMTP id 006d021491bc7-573912a7b14so5002457eaf.1 for <66217@debbugs.gnu.org>; Tue, 26 Sep 2023 12:37:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695757069; x=1696361869; darn=debbugs.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/vcVm38Tirl1qtmriBb6kD/2JGsuP+DYWn5slrGOxYU=; b=iovcxoRny8NXLuq+Kc3QyPaBGbhqh9qkbiz53lha0apS12b5mR6jDGVnvp+GNaM/lc IGUyDjXEsKMFp4aW9wAUVsFOkhHmagPSprNR+M+19cAtaanib/sJpVBXFovfjBjNroMY 0N7JldOzvHVIsTDAOBULxyrx2TdyQ9F3Ai6r6MySS1vTZ6R15srTiM88MwGco4S+232b AoRotXqACutF/QmQkVTI2L1idTK9HRl9V2STXQ8BLR/g6gQ/lMJrttpzvdqs6C1u0oDN V4Do22EA3GSPIUwakUS0YR1/fhgOefiZ6ihjc04+rdG0MmVKR1m6FuSPSfZ0tGySBAmY 47jA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695757069; x=1696361869; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/vcVm38Tirl1qtmriBb6kD/2JGsuP+DYWn5slrGOxYU=; b=Icdpz9mzuQU0r5NAsKtr01GN/f23+ymEfpMSbMYCto9MhpA3XYtz3Zzp8B44Z6vQ43 D1f2zednxBnOe3umjR0pCRbL+n1F3pzeI17BnALx1OLChD5REypNk2fvU7FOZaGH57W2 zaZT+7oUvdaFOUvBP+SNh6Vu3PXS0ZLeYNoKQ2SoZdWae9n6NGnEQQw/CqTsIbf9ovfC h5YMUervQpLWO8vtKwc4S+xdAbovJftVPrHMVW+SEpXqo+lrkF/3prL3+Ik4/Y5iLwFN RfTmneqSpTEUN5iQyJ1rBzhvylsQ1f/iS4zY40Ch6WJEp/F/Eud2efmB3xtbIGdc2PRL Qxjw== X-Gm-Message-State: AOJu0YydYrsRfvmSAmaXd6sP5IywddTDiy+TYxVi6xwevq8wmalwJZW6 mz0TXwrdbOh//3QylVuQ3dWVNu8fJHQ= X-Google-Smtp-Source: AGHT+IGC9N1x5RUI2bLyanEx57YSfnvUbQd7qtOr9gyow06JTTgXzeo25SdqTP3qT0oGHAkH8eEXHA== X-Received: by 2002:a05:6870:179f:b0:1b0:3d61:553e with SMTP id r31-20020a056870179f00b001b03d61553emr12541682oae.15.1695757069141; Tue, 26 Sep 2023 12:37:49 -0700 (PDT) Received: from localhost.localdomain (dsl-10-130-229.b2b2c.ca. [72.10.130.229]) by smtp.gmail.com with ESMTPSA id a13-20020a05620a16cd00b0076cbcf8ad3bsm2887595qkn.55.2023.09.26.12.37.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 12:37:48 -0700 (PDT) From: Maxim Cournoyer Date: Tue, 26 Sep 2023 15:04:24 -0400 Message-ID: <33c37ede82d69e5976cb50367ed8d4835a6d4ae4.1695754731.git.maxim.cournoyer@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches This allows generating an AVR toolchain for any version of GCC. * gnu/packages/avr.scm (make-avr-gcc): Add a #:xgcc argument; use memoize instead of mlambda. (make-avr-libc): Likewise. Provide it to the 'make-avr-gcc' call. (make-avr-toolchain): Add a #:xgcc argument; use memoize instead of mlambda. Provide the xgcc argument to the 'make-avr-libc' and 'make-avr-gcc' procedures. --- gnu/packages/avr.scm | 212 ++++++++++++++++++++++--------------------- 1 file changed, 110 insertions(+), 102 deletions(-) diff --git a/gnu/packages/avr.scm b/gnu/packages/avr.scm index bc583ddff3b..a66abbbd3ad 100644 --- a/gnu/packages/avr.scm +++ b/gnu/packages/avr.scm @@ -6,6 +6,7 @@ ;;; Copyright © 2018 Tobias Geerinckx-Rice ;;; Copyright © 2020 Marius Bakke ;;; Copyright © 2020 Arun Isaac +;;; Copyright © 2023 Maxim Cournoyer ;;; ;;; This file is part of GNU Guix. ;;; @@ -58,115 +59,122 @@ (define make-avr-binutils (inherit (cross-binutils "avr")) (name "avr-binutils")))) -(define make-avr-gcc - (mlambda () - (let ((xgcc (cross-gcc "avr" #:xbinutils (make-avr-binutils)))) - (package - (inherit xgcc) - (name "avr-gcc") - (arguments - (substitute-keyword-arguments (package-arguments xgcc) - ((#:phases phases) - #~(modify-phases #$phases - (add-after 'set-paths 'augment-CPLUS_INCLUDE_PATH - (lambda* (#:key inputs #:allow-other-keys) - (let ((gcc (assoc-ref inputs "gcc"))) - ;; Remove the default compiler from CPLUS_INCLUDE_PATH - ;; to prevent header conflict with the GCC from - ;; native-inputs. - (setenv "CPLUS_INCLUDE_PATH" - (string-join - (delete (string-append gcc "/include/c++") - (string-split (getenv "CPLUS_INCLUDE_PATH") - #\:)) - ":")) - (format #t - "environment variable `CPLUS_INCLUDE_PATH' \ +(define* (make-avr-gcc/implementation #:key (xgcc gcc)) + "Return a XGCC-base cross-compiler for the AVR target." + (let ((xgcc (cross-gcc "avr" #:xgcc xgcc #:xbinutils (make-avr-binutils)))) + (package + (inherit xgcc) + (name "avr-gcc") + (arguments + (substitute-keyword-arguments (package-arguments xgcc) + ((#:phases phases) + #~(modify-phases #$phases + (add-after 'set-paths 'augment-CPLUS_INCLUDE_PATH + (lambda* (#:key inputs #:allow-other-keys) + (let ((gcc (assoc-ref inputs "gcc"))) + ;; Remove the default compiler from CPLUS_INCLUDE_PATH + ;; to prevent header conflict with the GCC from + ;; native-inputs. + (setenv "CPLUS_INCLUDE_PATH" + (string-join + (delete (string-append gcc "/include/c++") + (string-split (getenv "CPLUS_INCLUDE_PATH") + #\:)) + ":")) + (format #t + "environment variable `CPLUS_INCLUDE_PATH' \ changed to ~a~%" - (getenv "CPLUS_INCLUDE_PATH"))))) - ;; Without a working multilib build, the resulting GCC lacks - ;; support for nearly every AVR chip. - (add-after 'unpack 'fix-genmultilib - (lambda _ - ;; patch-shebang doesn't work here because there are - ;; actually several scripts inside this script, each with - ;; a #!/bin/sh that needs patching. - (substitute* "gcc/genmultilib" - (("#!/bin/sh") (string-append "#!" (which "sh")))))))) - ((#:configure-flags flags) - #~(delete "--disable-multilib" #$flags)))) - (native-search-paths - (list (search-path-specification - (variable "CROSS_C_INCLUDE_PATH") - (files '("avr/include"))) - (search-path-specification - (variable "CROSS_CPLUS_INCLUDE_PATH") - (files '("avr/include"))) - (search-path-specification - (variable "CROSS_OBJC_INCLUDE_PATH") - (files '("avr/include"))) - (search-path-specification - (variable "CROSS_OBJCPLUS_INCLUDE_PATH") - (files '("avr/include"))) - (search-path-specification - (variable "CROSS_LIBRARY_PATH") - (files '("avr/lib"))))) - (native-inputs - `(("gcc" ,gcc) - ,@(package-native-inputs xgcc))))))) + (getenv "CPLUS_INCLUDE_PATH"))))) + ;; Without a working multilib build, the resulting GCC lacks + ;; support for nearly every AVR chip. + (add-after 'unpack 'fix-genmultilib + (lambda _ + ;; patch-shebang doesn't work here because there are + ;; actually several scripts inside this script, each with + ;; a #!/bin/sh that needs patching. + (substitute* "gcc/genmultilib" + (("#!/bin/sh") (string-append "#!" (which "sh")))))))) + ((#:configure-flags flags) + #~(delete "--disable-multilib" #$flags)))) + (native-search-paths + (list (search-path-specification + (variable "CROSS_C_INCLUDE_PATH") + (files '("avr/include"))) + (search-path-specification + (variable "CROSS_CPLUS_INCLUDE_PATH") + (files '("avr/include"))) + (search-path-specification + (variable "CROSS_OBJC_INCLUDE_PATH") + (files '("avr/include"))) + (search-path-specification + (variable "CROSS_OBJCPLUS_INCLUDE_PATH") + (files '("avr/include"))) + (search-path-specification + (variable "CROSS_LIBRARY_PATH") + (files '("avr/lib"))))) + (native-inputs + `(("gcc" ,gcc) + ,@(package-native-inputs xgcc)))))) + +(define make-avr-gcc + (memoize make-avr-gcc/implementation)) + +(define* (make-avr-libc/implementation #:key (xgcc gcc)) + (package + (name "avr-libc") + (version "2.0.0") + (source (origin + (method url-fetch) + (uri (string-append "mirror://savannah//avr-libc/avr-libc-" + version ".tar.bz2")) + (sha256 + (base32 + "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)))) + (home-page "https://www.nongnu.org/avr-libc/") + (synopsis "The AVR C Library") + (description + "AVR Libc is a project whose goal is to provide a high quality C library +for use with GCC on Atmel AVR microcontrollers.") + (license + (license:non-copyleft "http://www.nongnu.org/avr-libc/LICENSE.txt")))) (define make-avr-libc - (mlambda () - (package - (name "avr-libc") - (version "2.0.0") - (source (origin - (method url-fetch) - (uri (string-append "mirror://savannah//avr-libc/avr-libc-" - version ".tar.bz2")) - (sha256 - (base32 - "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)))) - (home-page "https://www.nongnu.org/avr-libc/") - (synopsis "The AVR C Library") - (description - "AVR Libc is a project whose goal is to provide a high quality C -library for use with GCC on Atmel AVR microcontrollers.") - (license - (license:non-copyleft "http://www.nongnu.org/avr-libc/LICENSE.txt"))))) + (memoize make-avr-libc/implementation)) -(define make-avr-toolchain - (mlambda () - (let ((avr-binutils (make-avr-binutils)) - (avr-libc (make-avr-libc)) - (avr-gcc (make-avr-gcc))) - ;; 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 - ;; etc if we didn't use the corret avr-gcc. - (package - (name "avr-toolchain") - (version (package-version avr-gcc)) - (source #f) - (build-system trivial-build-system) - (arguments '(#:builder (begin (mkdir %output) #t))) - (propagated-inputs - `(("avrdude" ,avrdude) - ("binutils" ,avr-binutils) - ("gcc" ,avr-gcc) - ("libc" ,avr-libc))) - (synopsis "Complete GCC tool chain for AVR microcontroller development") - (description "This package provides a complete GCC tool chain for AVR +(define* (make-avr-toolchain/implementation #:key (xgcc gcc)) + (let ((avr-binutils (make-avr-binutils)) + (avr-libc (make-avr-libc #: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 + ;; etc if we didn't use the corret avr-gcc. + (package + (name "avr-toolchain") + (version (package-version avr-gcc)) + (source #f) + (build-system trivial-build-system) + (arguments '(#:builder (begin (mkdir %output) #t))) + (propagated-inputs + `(("avrdude" ,avrdude) + ("binutils" ,avr-binutils) + ("gcc" ,avr-gcc) + ("libc" ,avr-libc))) + (synopsis "Complete GCC tool chain for AVR microcontroller development") + (description "This package provides a complete GCC tool chain for AVR microcontroller development. This includes the GCC AVR cross compiler and avrdude for firmware flashing. The supported programming languages are C and C++.") - (home-page (package-home-page avr-libc)) - (license (package-license avr-gcc)))))) + (home-page (package-home-page avr-libc)) + (license (package-license avr-gcc))))) + +(define make-avr-toolchain + (memoize make-avr-toolchain/implementation)) (define-public microscheme (package