Merge branch 'staging' into core-updates
[jackhill/guix/guix.git] / gnu / packages / avr.scm
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 ;;;
8 ;;; This file is part of GNU Guix.
9 ;;;
10 ;;; GNU Guix is free software; you can redistribute it and/or modify it
11 ;;; under the terms of the GNU General Public License as published by
12 ;;; the Free Software Foundation; either version 3 of the License, or (at
13 ;;; your option) any later version.
14 ;;;
15 ;;; GNU Guix is distributed in the hope that it will be useful, but
16 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;;; GNU General Public License for more details.
19 ;;;
20 ;;; You should have received a copy of the GNU General Public License
21 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
22
23 (define-module (gnu packages avr)
24 #:use-module ((guix licenses) #:prefix license:)
25 #:use-module (guix utils)
26 #:use-module (guix download)
27 #:use-module (guix git-download)
28 #:use-module (guix packages)
29 #:use-module (guix build-system gnu)
30 #:use-module (guix build-system trivial)
31 #:use-module (gnu packages)
32 #:use-module (gnu packages compression)
33 #:use-module (gnu packages cross-base)
34 #:use-module (gnu packages flashing-tools)
35 #:use-module (gnu packages gcc)
36 #:use-module (gnu packages vim))
37
38 (define-public avr-binutils
39 (package
40 (inherit (cross-binutils "avr"))
41 (name "avr-binutils")))
42
43 (define-public avr-gcc-4.9
44 (let ((xgcc (cross-gcc "avr" #:xgcc gcc-4.9 #:xbinutils avr-binutils)))
45 (package
46 (inherit xgcc)
47 (name "avr-gcc")
48 (arguments
49 (substitute-keyword-arguments (package-arguments xgcc)
50 ((#:phases phases)
51 `(modify-phases ,phases
52 ;; Without a working multilib build, the resulting GCC lacks
53 ;; support for nearly every AVR chip.
54 (add-after 'unpack 'fix-genmultilib
55 (lambda _
56 ;; patch-shebang doesn't work here because there are actually
57 ;; several scripts inside this script, each with a #!/bin/sh
58 ;; that needs patching.
59 (substitute* "gcc/genmultilib"
60 (("#!/bin/sh") (string-append "#!" (which "sh"))))
61 #t))))
62 ((#:configure-flags flags)
63 `(delete "--disable-multilib" ,flags))))
64 (native-search-paths
65 (list (search-path-specification
66 (variable "CROSS_CPATH")
67 (files '("avr/include")))
68 (search-path-specification
69 (variable "CROSS_LIBRARY_PATH")
70 (files '("avr/lib")))))
71 (native-inputs
72 `(("gcc" ,gcc-5)
73 ,@(package-native-inputs xgcc))))))
74
75 (define-public avr-gcc-5
76 (package
77 (inherit avr-gcc-4.9)
78 (version (package-version gcc-5))
79 (source (package-source gcc-5))))
80
81 (define (avr-libc avr-gcc)
82 (package
83 (name "avr-libc")
84 (version "2.0.0")
85 (source (origin
86 (method url-fetch)
87 (uri (string-append "mirror://savannah//avr-libc/avr-libc-"
88 version ".tar.bz2"))
89 (sha256
90 (base32
91 "15svr2fx8j6prql2il2fc0ppwlv50rpmyckaxx38d3gxxv97zpdj"))))
92 (build-system gnu-build-system)
93 (arguments
94 '(#:out-of-source? #t
95 #:configure-flags '("--host=avr")
96 #:phases
97 (modify-phases %standard-phases
98 (add-before 'unpack 'fix-cpath
99 (lambda _
100 ;; C_INCLUDE_PATH and CPATH pose issues for cross-building,
101 ;; leading to failures when building avr-libc on 64-bit systems.
102 ;; Simply unsetting them allows the build to succeed because it
103 ;; doesn't try to use any of the native system's headers.
104 (unsetenv "C_INCLUDE_PATH")
105 (unsetenv "CPATH")
106 #t)))))
107 (native-inputs `(("avr-binutils" ,avr-binutils)
108 ("avr-gcc" ,avr-gcc)))
109 (home-page "https://www.nongnu.org/avr-libc/")
110 (synopsis "The AVR C Library")
111 (description
112 "AVR Libc is a project whose goal is to provide a high quality C library
113 for use with GCC on Atmel AVR microcontrollers.")
114 (license
115 (license:non-copyleft "http://www.nongnu.org/avr-libc/LICENSE.txt"))))
116
117 (define (avr-toolchain avr-gcc)
118 ;; avr-libc checks the compiler version and passes "--enable-device-lib" for avr-gcc > 5.1.0.
119 ;; It wouldn't install the library for atmega32u4 etc if we didn't use the corret avr-gcc.
120 (let ((avr-libc (avr-libc avr-gcc)))
121 (package
122 (name "avr-toolchain")
123 (version (package-version avr-gcc))
124 (source #f)
125 (build-system trivial-build-system)
126 (arguments '(#:builder (begin (mkdir %output) #t)))
127 (propagated-inputs
128 `(("avrdude" ,avrdude)
129 ("binutils" ,avr-binutils)
130 ("gcc" ,avr-gcc)
131 ("libc" ,avr-libc)))
132 (synopsis "Complete GCC tool chain for AVR microcontroller development")
133 (description "This package provides a complete GCC tool chain for AVR
134 microcontroller development. This includes the GCC AVR cross compiler and
135 avrdude for firmware flashing. The supported programming languages are C and
136 C++.")
137 (home-page (package-home-page avr-libc))
138 (license (package-license avr-gcc)))))
139
140 (define-public avr-toolchain-4.9 (avr-toolchain avr-gcc-4.9))
141 (define-public avr-toolchain-5 (avr-toolchain avr-gcc-5))
142
143 (define-public microscheme
144 (package
145 (name "microscheme")
146 (version "0.9.3")
147 (source
148 (origin
149 (method git-fetch)
150 (uri (git-reference
151 (url "https://github.com/ryansuchocki/microscheme.git")
152 (commit (string-append "v" version))))
153 (sha256
154 (base32 "1r3ng4pw1s9yy1h5rafra1rq19d3vmb5pzbpcz1913wz22qdd976"))
155 (file-name (git-file-name name version))))
156 (build-system gnu-build-system)
157 (arguments
158 `(#:parallel-build? #f ; fails to build otherwise
159 #:tests? #f ; no tests
160 #:phases
161 (modify-phases %standard-phases
162 (delete 'configure))
163 #:make-flags
164 (list (string-append "PREFIX=" (assoc-ref %outputs "out")))))
165 (native-inputs
166 `(("unzip" ,unzip)
167 ("xxd" ,xxd)))
168 (home-page "https://github.com/ryansuchocki/microscheme/")
169 (synopsis "Scheme subset for Atmel microcontrollers")
170 (description
171 "Microscheme, or @code{(ms)} for short, is a functional programming
172 language for the Arduino, and for Atmel 8-bit AVR microcontrollers in general.
173 Microscheme is a subset of Scheme, in the sense that every valid @code{(ms)}
174 program is also a valid Scheme program (with the exception of Arduino
175 hardware-specific primitives). The @code{(ms)} compiler performs function
176 inlining, and features an aggressive tree-shaker, eliminating unused top-level
177 definitions. Microscheme has a robust @dfn{Foreign Function Interface} (FFI)
178 meaning that C code may be invoked directly from (ms) programs.")
179 (license license:expat)))