avr.scm 7.6 KB

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