axoloti.scm 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2016, 2017, 2019 Ricardo Wurmus <rekado@elephly.net>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  6. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; GNU Guix is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (gnu packages axoloti)
  19. #:use-module (guix utils)
  20. #:use-module (guix packages)
  21. #:use-module (guix download)
  22. #:use-module ((guix licenses) #:prefix license:)
  23. #:use-module (guix build-system gnu)
  24. #:use-module (guix build-system ant)
  25. #:use-module (gnu packages)
  26. #:use-module (gnu packages base)
  27. #:use-module (gnu packages compression)
  28. #:use-module (gnu packages cross-base)
  29. #:use-module (gnu packages embedded)
  30. #:use-module (gnu packages flashing-tools)
  31. #:use-module (gnu packages java)
  32. #:use-module (gnu packages libusb)
  33. #:use-module (gnu packages pkg-config)
  34. #:use-module (gnu packages textutils)
  35. #:use-module (gnu packages version-control)
  36. #:use-module (gnu packages xml))
  37. (define libusb-for-axoloti
  38. (package (inherit libusb)
  39. (name "axoloti-libusb")
  40. (version (package-version libusb))
  41. (source
  42. (origin
  43. (inherit (package-source libusb))
  44. (patches (list (search-patch "libusb-for-axoloti.patch")))))))
  45. (define dfu-util-for-axoloti
  46. (package (inherit dfu-util)
  47. (name "axoloti-dfu-util")
  48. (version "0.8")
  49. (source
  50. (origin
  51. (method url-fetch)
  52. (uri (string-append "http://dfu-util.sourceforge.net/releases/"
  53. "dfu-util-" version ".tar.gz"))
  54. (sha256
  55. (base32
  56. "0n7h08avlzin04j93m6hkq9id6hxjiiix7ff9gc2n89aw6dxxjsm"))))
  57. (inputs
  58. `(("libusb" ,libusb-for-axoloti)))))
  59. (define-public axoloti-runtime
  60. (package
  61. (name "axoloti-runtime")
  62. (version "1.0.12")
  63. (source (origin
  64. (method url-fetch)
  65. (uri (string-append "https://github.com/axoloti/axoloti/"
  66. "archive/" version ".tar.gz"))
  67. (file-name (string-append name "-" version ".tar.gz"))
  68. (sha256
  69. (base32
  70. "1dynk6h0nixp4zihpirpqa4vi8fq1lhm443jsmvhk135ykhf364p"))
  71. (modules '((guix build utils)))
  72. (snippet
  73. '(begin
  74. ;; Remove pre-built Java binaries.
  75. (delete-file-recursively "lib/")
  76. #t))))
  77. (build-system gnu-build-system)
  78. (arguments
  79. `(#:tests? #f ; no check target
  80. #:modules ((guix build gnu-build-system)
  81. (guix build utils)
  82. (srfi srfi-1)
  83. (srfi srfi-26)
  84. (ice-9 match)
  85. (ice-9 regex))
  86. #:imported-modules ((guix build syscalls)
  87. ,@%gnu-build-system-modules)
  88. #:phases
  89. (modify-phases %standard-phases
  90. (add-after 'unpack 'patch-paths
  91. (lambda* (#:key inputs #:allow-other-keys)
  92. ;; prepare ChibiOS
  93. (invoke "unzip" "-o" (assoc-ref inputs "chibios"))
  94. (invoke "mv" "ChibiOS_2.6.9" "chibios")
  95. (with-directory-excursion "chibios/ext"
  96. (invoke "unzip" "-o" "fatfs-0.9-patched.zip"))
  97. ;; Remove source of non-determinism in ChibiOS
  98. (substitute* "chibios/os/various/shell.c"
  99. (("#ifdef __DATE__") "#if 0"))
  100. ;; Patch shell paths
  101. (substitute* '("src/main/java/qcmds/QCmdCompileFirmware.java"
  102. "src/main/java/qcmds/QCmdCompilePatch.java"
  103. "src/main/java/qcmds/QCmdFlashDFU.java")
  104. (("/bin/sh") (which "sh")))
  105. ;; Override cross compiler base name
  106. (substitute* "firmware/Makefile.patch"
  107. (("arm-none-eabi-(gcc|g\\+\\+|objcopy|objdump)" tool)
  108. (which tool)))
  109. ;; Hardcode full path to compiler tools
  110. (substitute* '("firmware/Makefile"
  111. "firmware/flasher/Makefile"
  112. "firmware/mounter/Makefile")
  113. (("TRGT =.*")
  114. (string-append "TRGT = "
  115. (assoc-ref inputs "cross-toolchain")
  116. "/bin/arm-none-eabi-\n")))
  117. ;; Hardcode path to "make"
  118. (substitute* '("firmware/compile_firmware_linux.sh"
  119. "firmware/compile_patch_linux.sh")
  120. (("make") (which "make")))
  121. ;; Hardcode path to "dfu-util"
  122. (substitute* "platform_linux/upload_fw_dfu.sh"
  123. (("-f \"\\$\\{platformdir\\}/bin/dfu-util\"") "-z \"\"")
  124. (("\\./dfu-util") (which "dfu-util")))
  125. #t))
  126. (delete 'configure)
  127. (replace 'build
  128. ;; Build Axoloti firmware with cross-compiler
  129. (lambda* (#:key inputs #:allow-other-keys)
  130. (let* ((toolchain (assoc-ref inputs "cross-toolchain"))
  131. (headers (string-append
  132. toolchain
  133. "/arm-none-eabi/include:"
  134. toolchain
  135. "/arm-none-eabi/include/arm-none-eabi/armv7e-m")))
  136. (setenv "CROSS_CPATH" headers)
  137. (setenv "CROSS_CPLUS_INCLUDE_PATH" headers)
  138. (setenv "CROSS_LIBRARY_PATH"
  139. (string-append toolchain
  140. "/arm-none-eabi/lib")))
  141. (with-directory-excursion "platform_linux"
  142. (invoke "sh" "compile_firmware.sh"))))
  143. (replace 'install
  144. (lambda* (#:key inputs outputs #:allow-other-keys)
  145. (let* ((out (assoc-ref outputs "out"))
  146. (share (string-append out "/share/axoloti/"))
  147. (doc (string-append share "doc"))
  148. (dir (getcwd))
  149. (pats '("/doc/[^/]+$"
  150. "/patches/[^/]+/[^/]+$"
  151. "/objects/[^/]+/[^/]+$"
  152. "/firmware/.+"
  153. "/chibios/[^/]+$"
  154. "/chibios/boards/ST_STM32F4_DISCOVERY/[^/]+$"
  155. "/chibios/(ext|os|docs)/.+"
  156. "/CMSIS/[^/]+/[^/]+$"
  157. "/patch/[^/]+/[^/]+$"
  158. "/[^/]+\\.txt$"))
  159. (pattern (string-append
  160. "(" (string-join
  161. (map (cut string-append dir <>)
  162. pats)
  163. "|") ")"))
  164. (files (find-files dir
  165. (lambda (file stat)
  166. (and (eq? 'regular (stat:type stat))
  167. (string-match pattern file))))))
  168. (for-each (lambda (file)
  169. (install-file file
  170. (string-append
  171. share
  172. (regexp-substitute
  173. #f
  174. (string-match dir (dirname file))
  175. 'pre 'post))))
  176. files)
  177. #t))))))
  178. (inputs
  179. `(("chibios"
  180. ,(origin
  181. (method url-fetch)
  182. (uri "mirror://sourceforge/chibios/ChibiOS%20GPL3/Version%202.6.9/ChibiOS_2.6.9.zip")
  183. (sha256
  184. (base32
  185. "0lb5s8pkj80mqhsy47mmq0lqk34s2a2m3xagzihalvabwd0frhlj"))))
  186. ;; for compiling patches
  187. ("make" ,gnu-make)
  188. ;; for compiling firmware
  189. ("cross-toolchain" ,arm-none-eabi-nano-toolchain-4.9)
  190. ;; for uploading compiled patches and firmware
  191. ("dfu-util" ,dfu-util-for-axoloti)))
  192. (native-inputs
  193. `(("unzip" ,unzip)))
  194. (home-page "http://www.axoloti.com/")
  195. (synopsis "Audio development environment for the Axoloti core board")
  196. (description
  197. "The Axoloti patcher offers a “patcher” environment similar to Pure Data
  198. for sketching digital audio algorithms. The patches run on a standalone
  199. powerful microcontroller board: Axoloti Core. This package provides the
  200. runtime.")
  201. (license license:gpl3+)))
  202. (define-public axoloti-patcher
  203. (package (inherit axoloti-runtime)
  204. (name "axoloti-patcher")
  205. (version (package-version axoloti-runtime))
  206. (arguments
  207. `(#:tests? #f ; no check target
  208. #:modules ((guix build gnu-build-system)
  209. ((guix build ant-build-system) #:prefix ant:)
  210. (guix build utils)
  211. (srfi srfi-1)
  212. (srfi srfi-26)
  213. (ice-9 match)
  214. (ice-9 regex)
  215. (sxml simple)
  216. (sxml xpath)
  217. (sxml transform))
  218. #:imported-modules ((guix build ant-build-system)
  219. (guix build syscalls)
  220. ,@%gnu-build-system-modules)
  221. #:phases
  222. (modify-phases %standard-phases
  223. (delete 'configure)
  224. (replace 'build
  225. (lambda* (#:key inputs #:allow-other-keys)
  226. (setenv "JAVA_HOME" (assoc-ref inputs "icedtea"))
  227. ;; We want to use our own jar files instead of the pre-built
  228. ;; stuff in lib. So we replace the zipfileset tags in the
  229. ;; build.xml with new ones that reference our jars.
  230. (let* ((build.xml (with-input-from-file "build.xml"
  231. (lambda _
  232. (xml->sxml #:trim-whitespace? #t))))
  233. (jars (append-map (match-lambda
  234. (((? (cut string-prefix? "java-" <>)
  235. label) . directory)
  236. (find-files directory "\\.jar$"))
  237. (_ '()))
  238. inputs))
  239. (classpath (string-join jars ":"))
  240. (fileset (map (lambda (jar)
  241. `(zipfileset (@ (excludes "META-INF/*.SF")
  242. (src ,jar))))
  243. jars)))
  244. (call-with-output-file "build.xml"
  245. (lambda (port)
  246. (sxml->xml
  247. (pre-post-order
  248. build.xml
  249. `(;; Remove all zipfileset tags from the "jar" tree and
  250. ;; inject our own tags.
  251. (jar . ,(lambda (tag . kids)
  252. `(jar ,@(append-map
  253. (filter (lambda (e)
  254. (not (eq? 'zipfileset (car e)))))
  255. kids)
  256. ,@fileset)))
  257. ;; Skip the "bundle" target (and the "-post-jar" target
  258. ;; that depends on it), because we don't need it and it
  259. ;; confuses sxml->xml.
  260. (target . ,(lambda (tag . kids)
  261. (let ((name ((sxpath '(name *text*))
  262. (car kids))))
  263. (if (or (member "bundle" name)
  264. (member "-post-jar" name))
  265. '() ; skip
  266. `(,tag ,@kids)))))
  267. (*default* . ,(lambda (tag . kids) `(,tag ,@kids)))
  268. (*text* . ,(lambda (_ txt)
  269. (match txt
  270. ;; Remove timestamp.
  271. ("${TODAY}" "(unknown)")
  272. (_ txt))))))
  273. port)))
  274. ;; Build it!
  275. (invoke "ant"
  276. (string-append "-Djavac.classpath=" classpath)
  277. "-Dbuild.runtime=true"
  278. "-Dbuild.time=01/01/1970 00:00:00"
  279. "-Djavac.source=1.7"
  280. "-Djavac.target=1.7"
  281. (string-append "-Dtag.short.version="
  282. ,version)))))
  283. (replace 'install
  284. (lambda* (#:key inputs outputs #:allow-other-keys)
  285. (let* ((out (assoc-ref outputs "out"))
  286. (share (string-append out "/share/axoloti/")))
  287. (install-file "dist/Axoloti.jar" share)
  288. ;; We do this to ensure that this package retains references to
  289. ;; other Java packages' jar files.
  290. (install-file "build.xml" share)
  291. ;; Create a launcher script
  292. (mkdir (string-append out "/bin"))
  293. (let ((target (string-append out "/bin/Axoloti")))
  294. (with-output-to-file target
  295. (lambda ()
  296. (let* ((dir (string-append (assoc-ref outputs "out")
  297. "/share/axoloti"))
  298. (runtime (string-append (assoc-ref inputs "axoloti-runtime")
  299. "/share/axoloti"))
  300. (toolchain (assoc-ref inputs "cross-toolchain"))
  301. (includes (string-append
  302. toolchain
  303. "/arm-none-eabi/include:"
  304. toolchain
  305. "/arm-none-eabi/include/arm-none-eabi/armv7e-m")))
  306. (display
  307. (string-append "#!" (which "sh") "\n"
  308. "export CROSS_CPATH=" includes "\n"
  309. "export CROSS_CPLUS_INCLUDE_PATH=" includes "\n"
  310. "export CROSS_LIBRARY_PATH="
  311. toolchain "/arm-none-eabi/lib" "\n"
  312. (which "java")
  313. " -Daxoloti_release=" runtime
  314. " -Daxoloti_runtime=" runtime
  315. " -jar " dir "/Axoloti.jar")))))
  316. (chmod target #o555))
  317. #t)))
  318. (add-after 'install 'strip-jar-timestamps
  319. (assoc-ref ant:%standard-phases 'strip-jar-timestamps)))))
  320. (inputs
  321. `(("icedtea" ,icedtea "jdk")
  322. ("cross-toolchain" ,arm-none-eabi-nano-toolchain-4.9)
  323. ("java-simple-xml" ,java-simple-xml)
  324. ("java-rsyntaxtextarea" ,java-rsyntaxtextarea)
  325. ("java-usb4java" ,java-usb4java)
  326. ("java-jsch" ,java-jsch)
  327. ("java-slf4j-api" ,java-slf4j-api)
  328. ("java-jgit" ,java-jgit-4.2)
  329. ("axoloti-runtime" ,axoloti-runtime)))
  330. (native-inputs
  331. `(("ant" ,ant)
  332. ("zip" ,zip) ; for repacking the jar
  333. ("unzip" ,unzip)))
  334. (description
  335. "The Axoloti patcher offers a “patcher” environment similar to Pure Data
  336. for sketching digital audio algorithms. The patches run on a standalone
  337. powerful microcontroller board: Axoloti Core. This package provides the
  338. patcher application.")))