1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014, 2016 Manolis Fragkiskos Ragkousis <manolis837@gmail.com>
3 ;;; Copyright © 2015, 2017 Ricardo Wurmus <rekado@elephly.net>
4 ;;; Copyright © 2016 David Thompson <davet@gnu.org>
5 ;;; Copyright © 2016 Efraim Flashner <efraim@flashner.co.il>
6 ;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
7 ;;; Copyright © 2020 Marius Bakke <mbakke@fastmail.com>
9 ;;; This file is part of GNU Guix.
11 ;;; GNU Guix is free software; you can redistribute it and/or modify it
12 ;;; under the terms of the GNU General Public License as published by
13 ;;; the Free Software Foundation; either version 3 of the License, or (at
14 ;;; your option) any later version.
16 ;;; GNU Guix is distributed in the hope that it will be useful, but
17 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;;; GNU General Public License for more details.
21 ;;; You should have received a copy of the GNU General Public License
22 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
24 (define-module (gnu packages avr)
25 #:use-module ((guix licenses) #:prefix license:)
26 #:use-module (guix utils)
27 #:use-module (guix download)
28 #:use-module (guix git-download)
29 #:use-module (guix packages)
30 #:use-module (guix build-system gnu)
31 #:use-module (guix build-system trivial)
32 #:use-module (gnu packages)
33 #:use-module (gnu packages compression)
34 #:use-module (gnu packages cross-base)
35 #:use-module (gnu packages flashing-tools)
36 #:use-module (gnu packages gcc)
37 #:use-module (gnu packages vim))
39 (define-public avr-binutils
41 (inherit (cross-binutils "avr"))
42 (name "avr-binutils")))
44 (define-public avr-gcc-4.9
45 (let ((xgcc (cross-gcc "avr" #:xgcc gcc-4.9 #:xbinutils avr-binutils)))
50 (substitute-keyword-arguments (package-arguments xgcc)
52 `(modify-phases ,phases
53 (add-after 'set-paths 'augment-CPLUS_INCLUDE_PATH
54 (lambda* (#:key inputs #:allow-other-keys)
55 (let ((gcc (assoc-ref inputs "gcc")))
56 ;; Remove the default compiler from CPLUS_INCLUDE_PATH to
57 ;; prevent header conflict with the GCC from native-inputs.
58 (setenv "CPLUS_INCLUDE_PATH"
60 (delete (string-append gcc "/include/c++")
61 (string-split (getenv "CPLUS_INCLUDE_PATH")
65 "environment variable `CPLUS_INCLUDE_PATH' changed to ~a~%"
66 (getenv "CPLUS_INCLUDE_PATH"))
68 ;; Without a working multilib build, the resulting GCC lacks
69 ;; support for nearly every AVR chip.
70 (add-after 'unpack 'fix-genmultilib
72 ;; patch-shebang doesn't work here because there are actually
73 ;; several scripts inside this script, each with a #!/bin/sh
74 ;; that needs patching.
75 (substitute* "gcc/genmultilib"
76 (("#!/bin/sh") (string-append "#!" (which "sh"))))
78 ((#:configure-flags flags)
79 `(delete "--disable-multilib" ,flags))))
81 (list (search-path-specification
82 (variable "CROSS_C_INCLUDE_PATH")
83 (files '("avr/include")))
84 (search-path-specification
85 (variable "CROSS_CPLUS_INCLUDE_PATH")
86 (files '("avr/include")))
87 (search-path-specification
88 (variable "CROSS_OBJC_INCLUDE_PATH")
89 (files '("avr/include")))
90 (search-path-specification
91 (variable "CROSS_OBJCPLUS_INCLUDE_PATH")
92 (files '("avr/include")))
93 (search-path-specification
94 (variable "CROSS_LIBRARY_PATH")
95 (files '("avr/lib")))))
98 ,@(package-native-inputs xgcc))))))
100 (define-public avr-gcc-5
102 (inherit avr-gcc-4.9)
103 (version (package-version gcc-5))
105 (inherit (package-source gcc-5))
106 (patches (append (origin-patches (package-source gcc-5))
107 (search-patches "gcc-cross-environment-variables.patch")))))))
109 (define (avr-libc avr-gcc)
115 (uri (string-append "mirror://savannah//avr-libc/avr-libc-"
119 "15svr2fx8j6prql2il2fc0ppwlv50rpmyckaxx38d3gxxv97zpdj"))))
120 (build-system gnu-build-system)
122 '(#:out-of-source? #t
123 #:configure-flags '("--host=avr")
125 (modify-phases %standard-phases
126 (add-before 'unpack 'fix-cpath
128 ;; C_INCLUDE_PATH and CPATH pose issues for cross-building,
129 ;; leading to failures when building avr-libc on 64-bit systems.
130 ;; Simply unsetting them allows the build to succeed because it
131 ;; doesn't try to use any of the native system's headers.
132 (unsetenv "C_INCLUDE_PATH")
135 (native-inputs `(("avr-binutils" ,avr-binutils)
136 ("avr-gcc" ,avr-gcc)))
137 (home-page "https://www.nongnu.org/avr-libc/")
138 (synopsis "The AVR C Library")
140 "AVR Libc is a project whose goal is to provide a high quality C library
141 for use with GCC on Atmel AVR microcontrollers.")
143 (license:non-copyleft "http://www.nongnu.org/avr-libc/LICENSE.txt"))))
145 (define (avr-toolchain avr-gcc)
146 ;; avr-libc checks the compiler version and passes "--enable-device-lib" for avr-gcc > 5.1.0.
147 ;; It wouldn't install the library for atmega32u4 etc if we didn't use the corret avr-gcc.
148 (let ((avr-libc (avr-libc avr-gcc)))
150 (name "avr-toolchain")
151 (version (package-version avr-gcc))
153 (build-system trivial-build-system)
154 (arguments '(#:builder (begin (mkdir %output) #t)))
156 `(("avrdude" ,avrdude)
157 ("binutils" ,avr-binutils)
160 (synopsis "Complete GCC tool chain for AVR microcontroller development")
161 (description "This package provides a complete GCC tool chain for AVR
162 microcontroller development. This includes the GCC AVR cross compiler and
163 avrdude for firmware flashing. The supported programming languages are C and
165 (home-page (package-home-page avr-libc))
166 (license (package-license avr-gcc)))))
168 (define-public avr-toolchain-4.9 (avr-toolchain avr-gcc-4.9))
169 (define-public avr-toolchain-5 (avr-toolchain avr-gcc-5))
171 (define-public microscheme
179 (url "https://github.com/ryansuchocki/microscheme")
180 (commit (string-append "v" version))))
182 (base32 "1r3ng4pw1s9yy1h5rafra1rq19d3vmb5pzbpcz1913wz22qdd976"))
183 (file-name (git-file-name name version))))
184 (build-system gnu-build-system)
186 `(#:parallel-build? #f ; fails to build otherwise
187 #:tests? #f ; no tests
189 (modify-phases %standard-phases
192 (list (string-append "PREFIX=" (assoc-ref %outputs "out")))))
196 (home-page "https://github.com/ryansuchocki/microscheme/")
197 (synopsis "Scheme subset for Atmel microcontrollers")
199 "Microscheme, or @code{(ms)} for short, is a functional programming
200 language for the Arduino, and for Atmel 8-bit AVR microcontrollers in general.
201 Microscheme is a subset of Scheme, in the sense that every valid @code{(ms)}
202 program is also a valid Scheme program (with the exception of Arduino
203 hardware-specific primitives). The @code{(ms)} compiler performs function
204 inlining, and features an aggressive tree-shaker, eliminating unused top-level
205 definitions. Microscheme has a robust @dfn{Foreign Function Interface} (FFI)
206 meaning that C code may be invoked directly from (ms) programs.")
207 (license license:expat)))