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