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 java-graphics)
36 #:use-module (gnu packages libusb)
37 #:use-module (gnu packages pkg-config)
38 #:use-module (gnu packages textutils)
39 #:use-module (gnu packages version-control)
40 #:use-module (gnu packages xml))
42 (define libusb-for-axoloti
43 (package (inherit libusb)
44 (name "axoloti-libusb")
45 (version (package-version libusb))
48 (inherit (package-source libusb))
49 (patches (list (search-patch "libusb-for-axoloti.patch")))))))
51 (define dfu-util-for-axoloti
52 (package (inherit dfu-util)
53 (name "axoloti-dfu-util")
58 (uri (string-append "http://dfu-util.sourceforge.net/releases/"
59 "dfu-util-" version ".tar.gz"))
62 "0n7h08avlzin04j93m6hkq9id6hxjiiix7ff9gc2n89aw6dxxjsm"))))
64 `(("libusb" ,libusb-for-axoloti)))))
66 (define-public axoloti-runtime
68 (name "axoloti-runtime")
74 (url "https://github.com/axoloti/axoloti.git")
76 (file-name (git-file-name name version))
78 (base32 "1qffis277wshldr3i939b0r2x3a2mlr53samxqmr2nk1sfm2b4w9"))
79 (modules '((guix build utils)))
82 ;; Remove pre-built Java binaries.
83 (delete-file-recursively "lib/")
85 (build-system gnu-build-system)
87 `(#:tests? #f ; no check target
88 #:modules ((guix build gnu-build-system)
94 #:imported-modules ((guix build syscalls)
95 ,@%gnu-build-system-modules)
97 (modify-phases %standard-phases
98 (add-after 'unpack 'patch-paths
99 (lambda* (#:key inputs #:allow-other-keys)
101 (invoke "unzip" "-o" (assoc-ref inputs "chibios"))
102 (invoke "mv" "ChibiOS_2.6.9" "chibios")
103 (with-directory-excursion "chibios/ext"
104 (invoke "unzip" "-o" "fatfs-0.9-patched.zip"))
106 ;; Remove source of non-determinism in ChibiOS
107 (substitute* "chibios/os/various/shell.c"
108 (("#ifdef __DATE__") "#if 0"))
111 (substitute* '("src/main/java/qcmds/QCmdCompileFirmware.java"
112 "src/main/java/qcmds/QCmdCompilePatch.java"
113 "src/main/java/qcmds/QCmdFlashDFU.java")
114 (("/bin/sh") (which "sh")))
116 ;; Override cross compiler base name
117 (substitute* "firmware/Makefile.patch"
118 (("arm-none-eabi-(gcc|g\\+\\+|objcopy|objdump)" tool)
121 ;; Hardcode full path to compiler tools
122 (substitute* '("firmware/Makefile"
123 "firmware/flasher/Makefile"
124 "firmware/mounter/Makefile")
126 (string-append "TRGT = "
127 (assoc-ref inputs "cross-toolchain")
128 "/bin/arm-none-eabi-\n")))
130 ;; Hardcode path to "make"
131 (substitute* '("firmware/compile_firmware_linux.sh"
132 "firmware/compile_patch_linux.sh")
133 (("make") (which "make")))
135 ;; Hardcode path to "dfu-util"
136 (substitute* "platform_linux/upload_fw_dfu.sh"
137 (("-f \"\\$\\{platformdir\\}/bin/dfu-util\"") "-z \"\"")
138 (("\\./dfu-util") (which "dfu-util")))
142 ;; Build Axoloti firmware with cross-compiler
143 (lambda* (#:key inputs #:allow-other-keys)
144 (let* ((toolchain (assoc-ref inputs "cross-toolchain"))
145 (headers (string-append
147 "/arm-none-eabi/include:"
149 "/arm-none-eabi/include/arm-none-eabi/armv7e-m")))
150 (setenv "CROSS_CPATH" headers)
151 (setenv "CROSS_CPLUS_INCLUDE_PATH" headers)
152 (setenv "CROSS_LIBRARY_PATH"
153 (string-append toolchain
154 "/arm-none-eabi/lib")))
155 (with-directory-excursion "platform_linux"
156 (invoke "sh" "compile_firmware.sh"))))
158 (lambda* (#:key inputs outputs #:allow-other-keys)
159 (let* ((out (assoc-ref outputs "out"))
160 (share (string-append out "/share/axoloti/"))
161 (doc (string-append share "doc"))
163 (pats '("/doc/[^/]+$"
164 "/patches/[^/]+/[^/]+$"
165 "/objects/[^/]+/[^/]+$"
168 "/chibios/boards/ST_STM32F4_DISCOVERY/[^/]+$"
169 "/chibios/(ext|os|docs)/.+"
170 "/CMSIS/[^/]+/[^/]+$"
171 "/patch/[^/]+/[^/]+$"
173 (pattern (string-append
175 (map (cut string-append dir <>)
178 (files (find-files dir
180 (and (eq? 'regular (stat:type stat))
181 (string-match pattern file))))))
182 (for-each (lambda (file)
188 (string-match dir (dirname file))
196 (uri "mirror://sourceforge/chibios/ChibiOS%20GPL3/Version%202.6.9/ChibiOS_2.6.9.zip")
199 "0lb5s8pkj80mqhsy47mmq0lqk34s2a2m3xagzihalvabwd0frhlj"))))
200 ;; for compiling patches
202 ;; for compiling firmware
203 ("cross-toolchain" ,arm-none-eabi-nano-toolchain-4.9)
204 ;; for uploading compiled patches and firmware
205 ("dfu-util" ,dfu-util-for-axoloti)))
208 (home-page "http://www.axoloti.com/")
209 (synopsis "Audio development environment for the Axoloti core board")
211 "The Axoloti patcher offers a “patcher” environment similar to Pure Data
212 for sketching digital audio algorithms. The patches run on a standalone
213 powerful microcontroller board: Axoloti Core. This package provides the
215 (license license:gpl3+)))
217 (define-public axoloti-patcher
218 (package (inherit axoloti-runtime)
219 (name "axoloti-patcher")
220 (version (package-version axoloti-runtime))
222 `(#:tests? #f ; no check target
223 #:modules ((guix build gnu-build-system)
224 ((guix build ant-build-system) #:prefix ant:)
233 #:imported-modules ((guix build ant-build-system)
234 (guix build syscalls)
235 ,@%gnu-build-system-modules)
237 (modify-phases %standard-phases
238 (add-after 'unpack 'make-git-checkout-writable
240 (for-each make-file-writable (find-files "."))
244 (lambda* (#:key inputs #:allow-other-keys)
245 (setenv "JAVA_HOME" (assoc-ref inputs "icedtea"))
246 ;; We want to use our own jar files instead of the pre-built
247 ;; stuff in lib. So we replace the zipfileset tags in the
248 ;; build.xml with new ones that reference our jars.
249 (let* ((build.xml (with-input-from-file "build.xml"
251 (xml->sxml #:trim-whitespace? #t))))
252 (jars (append-map (match-lambda
253 (((? (cut string-prefix? "java-" <>)
255 (find-files directory "\\.jar$"))
258 (classpath (string-join jars ":"))
259 (fileset (map (lambda (jar)
260 `(zipfileset (@ (excludes "META-INF/*.SF")
263 (call-with-output-file "build.xml"
268 `(;; Remove all zipfileset tags from the "jar" tree and
269 ;; inject our own tags.
270 (jar . ,(lambda (tag . kids)
273 (not (eq? 'zipfileset (car e)))))
276 ;; Skip the "bundle" target (and the "-post-jar" target
277 ;; that depends on it), because we don't need it and it
278 ;; confuses sxml->xml.
279 (target . ,(lambda (tag . kids)
280 (let ((name ((sxpath '(name *text*))
282 (if (or (member "bundle" name)
283 (member "-post-jar" name))
286 (*default* . ,(lambda (tag . kids) `(,tag ,@kids)))
287 (*text* . ,(lambda (_ txt)
290 ("${TODAY}" "(unknown)")
296 (string-append "-Djavac.classpath=" classpath)
297 "-Dbuild.runtime=true"
298 "-Dbuild.time=01/01/1970 00:00:00"
301 (string-append "-Dtag.short.version="
304 (lambda* (#:key inputs outputs #:allow-other-keys)
305 (let* ((out (assoc-ref outputs "out"))
306 (share (string-append out "/share/axoloti/")))
307 (install-file "dist/Axoloti.jar" share)
309 ;; We do this to ensure that this package retains references to
310 ;; other Java packages' jar files.
311 (install-file "build.xml" share)
313 ;; Create a launcher script
314 (mkdir (string-append out "/bin"))
315 (let ((target (string-append out "/bin/Axoloti")))
316 (with-output-to-file target
318 (let* ((dir (string-append (assoc-ref outputs "out")
320 (runtime (string-append (assoc-ref inputs "axoloti-runtime")
322 (toolchain (assoc-ref inputs "cross-toolchain"))
323 (includes (string-append
325 "/arm-none-eabi/include:"
327 "/arm-none-eabi/include/arm-none-eabi/armv7e-m")))
329 (string-append "#!" (which "sh") "\n"
330 "export CROSS_CPATH=" includes "\n"
331 "export CROSS_CPLUS_INCLUDE_PATH=" includes "\n"
332 "export CROSS_LIBRARY_PATH="
333 toolchain "/arm-none-eabi/lib" "\n"
335 " -Daxoloti_release=" runtime
336 " -Daxoloti_runtime=" runtime
337 " -jar " dir "/Axoloti.jar")))))
338 (chmod target #o555))
340 (add-after 'install 'strip-jar-timestamps
341 (assoc-ref ant:%standard-phases 'strip-jar-timestamps)))))
343 `(("icedtea" ,icedtea "jdk")
344 ("cross-toolchain" ,arm-none-eabi-nano-toolchain-4.9)
345 ("java-simple-xml" ,java-simple-xml)
346 ("java-rsyntaxtextarea" ,java-rsyntaxtextarea)
347 ("java-usb4java" ,java-usb4java)
348 ("java-jsch" ,java-jsch)
349 ("java-slf4j-api" ,java-slf4j-api)
350 ("java-jgit" ,java-jgit-4.2)
351 ("axoloti-runtime" ,axoloti-runtime)))
354 ("zip" ,zip) ; for repacking the jar
357 "The Axoloti patcher offers a “patcher” environment similar to Pure Data
358 for sketching digital audio algorithms. The patches run on a standalone
359 powerful microcontroller board: Axoloti Core. This package provides the
360 patcher application.")))
362 (define-public axoloti-patcher-next
364 (name "axoloti-patcher-next")
370 (url "https://github.com/axoloti/axoloti.git")
372 (file-name (git-file-name name version))
374 (base32 "022p993wf9l9mp6vg94x592vfqd1k1sjrq5f6x45h5r16qy6bdzh"))
375 (modules '((guix build utils)))
378 ;; Remove pre-built Java binaries.
379 (delete-file-recursively "lib/")
381 (build-system gnu-build-system)
383 `(#:tests? #f ; there's a Java test which is run as part of the Java build.
384 #:modules ((guix build gnu-build-system)
385 ((guix build ant-build-system) #:prefix ant:)
394 #:imported-modules ((guix build ant-build-system)
395 (guix build syscalls)
396 ,@%gnu-build-system-modules)
398 (modify-phases %standard-phases
399 (add-after 'unpack 'make-git-checkout-writable
400 (lambda* (#:key inputs #:allow-other-keys)
401 (copy-recursively (assoc-ref inputs "elfloader")
402 "firmware/elfloader")
403 (for-each make-file-writable (find-files "."))
405 (add-after 'unpack 'patch-paths
406 (lambda* (#:key inputs #:allow-other-keys)
408 (invoke "7z" "x" (assoc-ref inputs "chibios"))
409 (with-directory-excursion "ChibiOS_19.1.3/ext"
410 (invoke "7z" "x" "fatfs-0.13_patched.7z"))
412 ;; Hardcode full path to compiler tools
414 '("ChibiOS_19.1.3/os/common/startup/ARMCMx/compilers/GCC/mk/arm-none-eabi.mk"
415 "env/arm-none-eabi.mk")
417 (string-append "TRGT = "
418 (assoc-ref inputs "cross-toolchain")
419 "/bin/arm-none-eabi-\n")))
421 ;; Hardcode path to "make"
422 (substitute* "src/main/java/axoloti/shell/ShellTask.java"
424 (string-append "return \"" (which "make") "\"")))
426 ;; Hardcode path to "dfu-util"
427 (substitute* "src/main/java/axoloti/shell/UploadFirmwareDFU.java"
428 (("Axoloti.getReleaseDir\\(\\) \\+ \"/platform_.+/bin/dfu-util\"")
429 (string-append "\"" (which "dfu-util") "\"")))
433 ;; Build Axoloti firmware with cross-compiler
434 (lambda* (#:key inputs #:allow-other-keys)
435 (let* ((toolchain (assoc-ref inputs "cross-toolchain"))
436 (headers (string-append
438 "/arm-none-eabi/include:"
440 "/arm-none-eabi/include/arm-none-eabi/armv7e-m")))
441 (setenv "CROSS_CPATH" headers)
442 (setenv "CROSS_CPLUS_INCLUDE_PATH" headers)
443 (setenv "CROSS_LIBRARY_PATH"
444 (string-append toolchain
445 "/arm-none-eabi/lib")))
446 (with-directory-excursion "platform_linux"
447 (invoke "sh" "compile_firmware.sh"))))
448 (add-after 'build 'build-patcher
449 (lambda* (#:key inputs outputs #:allow-other-keys)
450 (setenv "JAVA_HOME" (assoc-ref inputs "jdk"))
451 ;; We want to use our own jar files instead of the pre-built
452 ;; stuff in lib. So we replace the zipfileset tags in the
453 ;; build.xml with new ones that reference our jars.
454 (let* ((build.xml (with-input-from-file "build.xml"
456 (xml->sxml #:trim-whitespace? #t))))
457 (jars (append-map (match-lambda
458 (((? (cut string-prefix? "java-" <>)
460 (find-files directory "\\.jar$"))
463 (classpath (string-join jars ":"))
464 (fileset (map (lambda (jar)
465 `(zipfileset (@ (excludes "META-INF/*.SF")
468 (call-with-output-file "build.xml"
473 `( ;; Remove all zipfileset tags from the "jar" tree and
474 ;; inject our own tags.
475 (jar . ,(lambda (tag . kids)
478 (not (eq? 'zipfileset (car e)))))
481 ;; Skip the "bundle" target (and the "-post-jar" target
482 ;; that depends on it), because we don't need it and it
483 ;; confuses sxml->xml.
484 (target . ,(lambda (tag . kids)
485 (let ((name ((sxpath '(name *text*))
487 (if (or (member "bundle" name)
488 (member "-post-jar" name))
491 (*default* . ,(lambda (tag . kids) `(,tag ,@kids)))
492 (*text* . ,(lambda (_ txt)
495 ("${TODAY}" "(unknown)")
501 (string-append "-Djavac.classpath=" classpath)
503 "-Dbuild.time=01/01/1970 00:00:00"
506 (string-append "-Dshort.version="
508 ;; TODO: this is the output of:
509 ;; git describe --long --tags --dirty --always
510 (string-append "-Dbuild.version="
511 ,version "-0-g88b60feb")))))
513 (lambda* (#:key inputs outputs #:allow-other-keys)
514 (let* ((out (assoc-ref outputs "out"))
515 (share (string-append out "/share/axoloti/")))
517 ;; TODO: don't copy *everything* from these directories.
518 (for-each (lambda (dir)
519 (copy-recursively dir (string-append share "/" dir)))
527 (install-file "dist/Axoloti.jar" share)
529 ;; Install old firmware
530 (let ((target (string-append share "/old_firmware/"))
532 (string-append (assoc-ref inputs "axoloti-runtime")
533 "/share/axoloti/firmware/")))
535 (install-file (string-append old-firmware
536 "flasher/flasher_build/flasher.bin")
538 ;; TODO: the old file differs from the file that is included
539 ;; in this repository as the old firmware.
540 (install-file (string-append old-firmware
544 ;; We do this to ensure that this package retains references to
545 ;; other Java packages' jar files.
546 (install-file "build.xml" share)
548 ;; Create a launcher script
549 (mkdir (string-append out "/bin"))
550 (let ((target (string-append out "/bin/Axoloti")))
551 (with-output-to-file target
553 (let* ((dir (string-append (assoc-ref outputs "out")
555 (toolchain (assoc-ref inputs "cross-toolchain"))
556 (includes (string-append
558 "/arm-none-eabi/include:"
560 "/arm-none-eabi/include/arm-none-eabi/armv7e-m")))
562 (string-append "#!" (which "sh") "\n"
563 "export CROSS_CPATH=" includes "\n"
564 "export CROSS_CPLUS_INCLUDE_PATH=" includes "\n"
565 "export CROSS_LIBRARY_PATH="
566 toolchain "/arm-none-eabi/lib" "\n"
569 ;; Renderer arguments
570 " -Xbootclasspath/a:"
571 (assoc-ref inputs "java-marlin-renderer")
573 " -Dsun.java2d.renderer=org.marlin.pisces.MarlinRenderingEngine"
574 " -Daxoloti_release=" share
575 " -jar " dir "/Axoloti.jar")))))
576 (chmod target #o555))
578 (add-after 'install 'strip-jar-timestamps
579 (assoc-ref ant:%standard-phases 'strip-jar-timestamps)))))
581 `(("jdk" ,icedtea "jdk")
582 ("cross-toolchain" ,arm-none-eabi-nano-toolchain-7-2018-q2-update)
583 ;; for compiling patches
585 ;; for uploading compiled patches and firmware
586 ("dfu-util" ,dfu-util-for-axoloti)
587 ;; for org/apache/commons/lang3/tuple/ImmutablePair
588 ("java-commons-lang3" ,java-commons-lang3)
589 ("java-jgit" ,java-jgit-4.2)
590 ("java-jsch" ,java-jsch)
591 ("java-marlin-renderer" ,java-marlin-renderer)
592 ("java-piccolo2d-core" ,java-piccolo2d-core)
593 ("java-piccolo2d-extras" ,java-piccolo2d-extras)
594 ("java-rsyntaxtextarea" ,java-rsyntaxtextarea)
595 ("java-simple-xml" ,java-simple-xml)
596 ("java-slf4j-api" ,java-slf4j-api)
597 ("java-usb4java" ,java-usb4java)))
600 ("axoloti-runtime" ,axoloti-runtime) ; for old firmware
601 ("java-junit" ,java-junit)
602 ("java-hamcrest-core" ,java-hamcrest-core)
604 ("zip" ,zip) ; for repacking the jar
606 ,(let ((commit "d0f93acac6577a069b8739bf42c9500e9a862988"))
610 (url "https://github.com/JohannesTaelman/elfloader.git")
612 (file-name (git-file-name "elfloader" commit))
615 "0zsy6w784amfq4vr1qnx8xvy70v33gvffz1vljllwppdc8s3khmn")))))
619 (uri "http://rwthaachen.dl.osdn.jp/chibios/70739/ChibiOS_19.1.3.7z")
622 "1090alqp1z1bhj1z8ls04a350kbs8hsjcpkfddbprds73zbnnpk9"))))))
623 (home-page "http://www.axoloti.com/")
624 (synopsis "Audio development environment for the Axoloti core board")
626 "The Axoloti patcher offers a “patcher” environment similar to Pure Data
627 for sketching digital audio algorithms. The patches run on a standalone
628 powerful microcontroller board: Axoloti Core.")
629 (license (list license:gpl3+ ; the whole project and GUI
630 license:bsd-3)))) ; the elfloader