1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2016, 2017, 2019 Ricardo Wurmus <rekado@elephly.net>
3 ;;; Copyright © 2019 Tobias Geerinckx-Rice <me@tobias.gr>
5 ;;; This file is part of GNU Guix.
7 ;;; GNU Guix is free software; you can redistribute it and/or modify it
8 ;;; under the terms of the GNU General Public License as published by
9 ;;; the Free Software Foundation; either version 3 of the License, or (at
10 ;;; your option) any later version.
12 ;;; GNU Guix is distributed in the hope that it will be useful, but
13 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;;; GNU General Public License for more details.
17 ;;; You should have received a copy of the GNU General Public License
18 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20 (define-module (gnu packages axoloti)
21 #:use-module (guix utils)
22 #:use-module (guix packages)
23 #:use-module (guix download)
24 #:use-module (guix git-download)
25 #:use-module ((guix licenses) #:prefix license:)
26 #:use-module (guix build-system gnu)
27 #:use-module (guix build-system ant)
28 #:use-module (gnu packages)
29 #:use-module (gnu packages base)
30 #:use-module (gnu packages compression)
31 #:use-module (gnu packages cross-base)
32 #:use-module (gnu packages embedded)
33 #:use-module (gnu packages flashing-tools)
34 #:use-module (gnu packages java)
35 #:use-module (gnu packages libusb)
36 #:use-module (gnu packages pkg-config)
37 #:use-module (gnu packages textutils)
38 #:use-module (gnu packages version-control)
39 #:use-module (gnu packages xml))
41 (define libusb-for-axoloti
42 (package (inherit libusb)
43 (name "axoloti-libusb")
44 (version (package-version libusb))
47 (inherit (package-source libusb))
48 (patches (list (search-patch "libusb-for-axoloti.patch")))))))
50 (define dfu-util-for-axoloti
51 (package (inherit dfu-util)
52 (name "axoloti-dfu-util")
57 (uri (string-append "http://dfu-util.sourceforge.net/releases/"
58 "dfu-util-" version ".tar.gz"))
61 "0n7h08avlzin04j93m6hkq9id6hxjiiix7ff9gc2n89aw6dxxjsm"))))
63 `(("libusb" ,libusb-for-axoloti)))))
65 (define-public axoloti-runtime
67 (name "axoloti-runtime")
73 (url "https://github.com/axoloti/axoloti.git")
75 (file-name (git-file-name name version))
77 (base32 "1qffis277wshldr3i939b0r2x3a2mlr53samxqmr2nk1sfm2b4w9"))
78 (modules '((guix build utils)))
81 ;; Remove pre-built Java binaries.
82 (delete-file-recursively "lib/")
84 (build-system gnu-build-system)
86 `(#:tests? #f ; no check target
87 #:modules ((guix build gnu-build-system)
93 #:imported-modules ((guix build syscalls)
94 ,@%gnu-build-system-modules)
96 (modify-phases %standard-phases
97 (add-after 'unpack 'patch-paths
98 (lambda* (#:key inputs #:allow-other-keys)
100 (invoke "unzip" "-o" (assoc-ref inputs "chibios"))
101 (invoke "mv" "ChibiOS_2.6.9" "chibios")
102 (with-directory-excursion "chibios/ext"
103 (invoke "unzip" "-o" "fatfs-0.9-patched.zip"))
105 ;; Remove source of non-determinism in ChibiOS
106 (substitute* "chibios/os/various/shell.c"
107 (("#ifdef __DATE__") "#if 0"))
110 (substitute* '("src/main/java/qcmds/QCmdCompileFirmware.java"
111 "src/main/java/qcmds/QCmdCompilePatch.java"
112 "src/main/java/qcmds/QCmdFlashDFU.java")
113 (("/bin/sh") (which "sh")))
115 ;; Override cross compiler base name
116 (substitute* "firmware/Makefile.patch"
117 (("arm-none-eabi-(gcc|g\\+\\+|objcopy|objdump)" tool)
120 ;; Hardcode full path to compiler tools
121 (substitute* '("firmware/Makefile"
122 "firmware/flasher/Makefile"
123 "firmware/mounter/Makefile")
125 (string-append "TRGT = "
126 (assoc-ref inputs "cross-toolchain")
127 "/bin/arm-none-eabi-\n")))
129 ;; Hardcode path to "make"
130 (substitute* '("firmware/compile_firmware_linux.sh"
131 "firmware/compile_patch_linux.sh")
132 (("make") (which "make")))
134 ;; Hardcode path to "dfu-util"
135 (substitute* "platform_linux/upload_fw_dfu.sh"
136 (("-f \"\\$\\{platformdir\\}/bin/dfu-util\"") "-z \"\"")
137 (("\\./dfu-util") (which "dfu-util")))
141 ;; Build Axoloti firmware with cross-compiler
142 (lambda* (#:key inputs #:allow-other-keys)
143 (let* ((toolchain (assoc-ref inputs "cross-toolchain"))
144 (headers (string-append
146 "/arm-none-eabi/include:"
148 "/arm-none-eabi/include/arm-none-eabi/armv7e-m")))
149 (setenv "CROSS_CPATH" headers)
150 (setenv "CROSS_CPLUS_INCLUDE_PATH" headers)
151 (setenv "CROSS_LIBRARY_PATH"
152 (string-append toolchain
153 "/arm-none-eabi/lib")))
154 (with-directory-excursion "platform_linux"
155 (invoke "sh" "compile_firmware.sh"))))
157 (lambda* (#:key inputs outputs #:allow-other-keys)
158 (let* ((out (assoc-ref outputs "out"))
159 (share (string-append out "/share/axoloti/"))
160 (doc (string-append share "doc"))
162 (pats '("/doc/[^/]+$"
163 "/patches/[^/]+/[^/]+$"
164 "/objects/[^/]+/[^/]+$"
167 "/chibios/boards/ST_STM32F4_DISCOVERY/[^/]+$"
168 "/chibios/(ext|os|docs)/.+"
169 "/CMSIS/[^/]+/[^/]+$"
170 "/patch/[^/]+/[^/]+$"
172 (pattern (string-append
174 (map (cut string-append dir <>)
177 (files (find-files dir
179 (and (eq? 'regular (stat:type stat))
180 (string-match pattern file))))))
181 (for-each (lambda (file)
187 (string-match dir (dirname file))
195 (uri "mirror://sourceforge/chibios/ChibiOS%20GPL3/Version%202.6.9/ChibiOS_2.6.9.zip")
198 "0lb5s8pkj80mqhsy47mmq0lqk34s2a2m3xagzihalvabwd0frhlj"))))
199 ;; for compiling patches
201 ;; for compiling firmware
202 ("cross-toolchain" ,arm-none-eabi-nano-toolchain-4.9)
203 ;; for uploading compiled patches and firmware
204 ("dfu-util" ,dfu-util-for-axoloti)))
207 (home-page "http://www.axoloti.com/")
208 (synopsis "Audio development environment for the Axoloti core board")
210 "The Axoloti patcher offers a “patcher” environment similar to Pure Data
211 for sketching digital audio algorithms. The patches run on a standalone
212 powerful microcontroller board: Axoloti Core. This package provides the
214 (license license:gpl3+)))
216 (define-public axoloti-patcher
217 (package (inherit axoloti-runtime)
218 (name "axoloti-patcher")
219 (version (package-version axoloti-runtime))
221 `(#:tests? #f ; no check target
222 #:modules ((guix build gnu-build-system)
223 ((guix build ant-build-system) #:prefix ant:)
232 #:imported-modules ((guix build ant-build-system)
233 (guix build syscalls)
234 ,@%gnu-build-system-modules)
236 (modify-phases %standard-phases
237 (add-after 'unpack 'make-git-checkout-writable
239 (for-each make-file-writable (find-files "."))
243 (lambda* (#:key inputs #:allow-other-keys)
244 (setenv "JAVA_HOME" (assoc-ref inputs "icedtea"))
245 ;; We want to use our own jar files instead of the pre-built
246 ;; stuff in lib. So we replace the zipfileset tags in the
247 ;; build.xml with new ones that reference our jars.
248 (let* ((build.xml (with-input-from-file "build.xml"
250 (xml->sxml #:trim-whitespace? #t))))
251 (jars (append-map (match-lambda
252 (((? (cut string-prefix? "java-" <>)
254 (find-files directory "\\.jar$"))
257 (classpath (string-join jars ":"))
258 (fileset (map (lambda (jar)
259 `(zipfileset (@ (excludes "META-INF/*.SF")
262 (call-with-output-file "build.xml"
267 `(;; Remove all zipfileset tags from the "jar" tree and
268 ;; inject our own tags.
269 (jar . ,(lambda (tag . kids)
272 (not (eq? 'zipfileset (car e)))))
275 ;; Skip the "bundle" target (and the "-post-jar" target
276 ;; that depends on it), because we don't need it and it
277 ;; confuses sxml->xml.
278 (target . ,(lambda (tag . kids)
279 (let ((name ((sxpath '(name *text*))
281 (if (or (member "bundle" name)
282 (member "-post-jar" name))
285 (*default* . ,(lambda (tag . kids) `(,tag ,@kids)))
286 (*text* . ,(lambda (_ txt)
289 ("${TODAY}" "(unknown)")
295 (string-append "-Djavac.classpath=" classpath)
296 "-Dbuild.runtime=true"
297 "-Dbuild.time=01/01/1970 00:00:00"
300 (string-append "-Dtag.short.version="
303 (lambda* (#:key inputs outputs #:allow-other-keys)
304 (let* ((out (assoc-ref outputs "out"))
305 (share (string-append out "/share/axoloti/")))
306 (install-file "dist/Axoloti.jar" share)
308 ;; We do this to ensure that this package retains references to
309 ;; other Java packages' jar files.
310 (install-file "build.xml" share)
312 ;; Create a launcher script
313 (mkdir (string-append out "/bin"))
314 (let ((target (string-append out "/bin/Axoloti")))
315 (with-output-to-file target
317 (let* ((dir (string-append (assoc-ref outputs "out")
319 (runtime (string-append (assoc-ref inputs "axoloti-runtime")
321 (toolchain (assoc-ref inputs "cross-toolchain"))
322 (includes (string-append
324 "/arm-none-eabi/include:"
326 "/arm-none-eabi/include/arm-none-eabi/armv7e-m")))
328 (string-append "#!" (which "sh") "\n"
329 "export CROSS_CPATH=" includes "\n"
330 "export CROSS_CPLUS_INCLUDE_PATH=" includes "\n"
331 "export CROSS_LIBRARY_PATH="
332 toolchain "/arm-none-eabi/lib" "\n"
334 " -Daxoloti_release=" runtime
335 " -Daxoloti_runtime=" runtime
336 " -jar " dir "/Axoloti.jar")))))
337 (chmod target #o555))
339 (add-after 'install 'strip-jar-timestamps
340 (assoc-ref ant:%standard-phases 'strip-jar-timestamps)))))
342 `(("icedtea" ,icedtea "jdk")
343 ("cross-toolchain" ,arm-none-eabi-nano-toolchain-4.9)
344 ("java-simple-xml" ,java-simple-xml)
345 ("java-rsyntaxtextarea" ,java-rsyntaxtextarea)
346 ("java-usb4java" ,java-usb4java)
347 ("java-jsch" ,java-jsch)
348 ("java-slf4j-api" ,java-slf4j-api)
349 ("java-jgit" ,java-jgit-4.2)
350 ("axoloti-runtime" ,axoloti-runtime)))
353 ("zip" ,zip) ; for repacking the jar
356 "The Axoloti patcher offers a “patcher” environment similar to Pure Data
357 for sketching digital audio algorithms. The patches run on a standalone
358 powerful microcontroller board: Axoloti Core. This package provides the
359 patcher application.")))