1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2016, 2017, 2019, 2020, 2021 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 ;; XXX The patch does not apply to libusb 1.0.24.
43 ;; See https://github.com/axoloti/axoloti/issues/464
44 (define libusb-for-axoloti
51 (uri (string-append "https://github.com/libusb/libusb/"
52 "releases/download/v" version
53 "/libusb-" version ".tar.bz2"))
55 (base32 "13dd2a9x290d1q8nb1lqiaf36grcvns5ripk5k2xm0lajmpc04fv"))
56 (patches (list (search-patch "libusb-for-axoloti.patch")))))))
58 (define dfu-util-for-axoloti
59 (package (inherit dfu-util)
60 (name "axoloti-dfu-util")
65 (uri (string-append "http://dfu-util.sourceforge.net/releases/"
66 "dfu-util-" version ".tar.gz"))
69 "0n7h08avlzin04j93m6hkq9id6hxjiiix7ff9gc2n89aw6dxxjsm"))))
71 `(("libusb" ,libusb-for-axoloti)))))
73 (define-public axoloti-runtime
75 (name "axoloti-runtime")
81 (url "https://github.com/axoloti/axoloti")
83 (file-name (git-file-name name version))
85 (base32 "1qffis277wshldr3i939b0r2x3a2mlr53samxqmr2nk1sfm2b4w9"))
86 (modules '((guix build utils)))
89 ;; Remove pre-built Java binaries.
90 (delete-file-recursively "lib/")
92 (build-system gnu-build-system)
94 `(#:tests? #f ; no check target
95 #:modules ((guix build gnu-build-system)
101 #:imported-modules ((guix build syscalls)
102 ,@%gnu-build-system-modules)
104 (modify-phases %standard-phases
105 (add-after 'unpack 'patch-paths
106 (lambda* (#:key inputs #:allow-other-keys)
108 (invoke "unzip" "-o" (assoc-ref inputs "chibios"))
109 (invoke "mv" "ChibiOS_2.6.9" "chibios")
110 (with-directory-excursion "chibios/ext"
111 (invoke "unzip" "-o" "fatfs-0.9-patched.zip"))
113 ;; Remove source of non-determinism in ChibiOS
114 (substitute* "chibios/os/various/shell.c"
115 (("#ifdef __DATE__") "#if 0"))
118 (substitute* '("src/main/java/qcmds/QCmdCompileFirmware.java"
119 "src/main/java/qcmds/QCmdCompilePatch.java"
120 "src/main/java/qcmds/QCmdFlashDFU.java")
121 (("/bin/sh") (which "sh")))
123 ;; Override cross compiler base name
124 (substitute* "firmware/Makefile.patch"
125 (("arm-none-eabi-(gcc|g\\+\\+|objcopy|objdump)" tool)
128 ;; XXX: for some reason the whitespace substitution does not
129 ;; work, so we disable it.
130 (substitute* "firmware/Makefile.patch"
131 (("^BDIR=.*") "BDIR=${axoloti_home}/build\n"))
133 ;; Hardcode full path to compiler tools
134 (substitute* '("firmware/Makefile"
135 "firmware/flasher/Makefile"
136 "firmware/mounter/Makefile")
138 (string-append "TRGT = "
139 (assoc-ref inputs "cross-toolchain")
140 "/bin/arm-none-eabi-\n")))
142 ;; Hardcode path to "make"
143 (substitute* '("firmware/compile_firmware_linux.sh"
144 "firmware/compile_patch_linux.sh")
145 (("make") (which "make")))
147 ;; Hardcode path to "dfu-util"
148 (substitute* "platform_linux/upload_fw_dfu.sh"
149 (("-f \"\\$\\{platformdir\\}/bin/dfu-util\"") "-z \"\"")
150 (("\\./dfu-util") (which "dfu-util")))
154 ;; Build Axoloti firmware with cross-compiler
156 (with-directory-excursion "platform_linux"
157 (invoke "sh" "compile_firmware.sh"))))
159 (lambda* (#:key inputs outputs #:allow-other-keys)
160 (let* ((out (assoc-ref outputs "out"))
161 (share (string-append out "/share/axoloti/"))
162 (doc (string-append share "doc"))
164 (pats '("/doc/[^/]+$"
165 "/patches/[^/]+/[^/]+$"
166 "/objects/[^/]+/[^/]+$"
169 "/chibios/boards/ST_STM32F4_DISCOVERY/[^/]+$"
170 "/chibios/(ext|os|docs)/.+"
171 "/CMSIS/[^/]+/[^/]+$"
172 "/patch/[^/]+/[^/]+$"
174 (pattern (string-append
176 (map (cut string-append dir <>)
179 (files (find-files dir
181 (and (eq? 'regular (stat:type stat))
182 (string-match pattern file))))))
183 (for-each (lambda (file)
189 (string-match dir (dirname file))
197 (uri "mirror://sourceforge/chibios/ChibiOS%20GPL3/Version%202.6.9/ChibiOS_2.6.9.zip")
200 "0lb5s8pkj80mqhsy47mmq0lqk34s2a2m3xagzihalvabwd0frhlj"))))
201 ;; for compiling patches
203 ;; for compiling firmware
204 ("cross-toolchain" ,arm-none-eabi-nano-toolchain-4.9)
205 ;; for uploading compiled patches and firmware
206 ("dfu-util" ,dfu-util-for-axoloti)))
209 (home-page "http://www.axoloti.com/")
210 (synopsis "Audio development environment for the Axoloti core board")
212 "The Axoloti patcher offers a “patcher” environment similar to Pure Data
213 for sketching digital audio algorithms. The patches run on a standalone
214 powerful microcontroller board: Axoloti Core. This package provides the
216 (license license:gpl3+)))
218 (define-public axoloti-patcher
219 (package (inherit axoloti-runtime)
220 (name "axoloti-patcher")
221 (version (package-version axoloti-runtime))
223 `(#:tests? #f ; no check target
224 #:modules ((guix build gnu-build-system)
225 ((guix build ant-build-system) #:prefix ant:)
234 #:imported-modules ((guix build ant-build-system)
235 (guix build syscalls)
236 ,@%gnu-build-system-modules)
238 (modify-phases %standard-phases
239 (add-after 'unpack 'make-git-checkout-writable
241 (for-each make-file-writable (find-files "."))
245 (lambda* (#:key inputs #:allow-other-keys)
246 (setenv "JAVA_HOME" (assoc-ref inputs "icedtea"))
247 ;; We want to use our own jar files instead of the pre-built
248 ;; stuff in lib. So we replace the zipfileset tags in the
249 ;; build.xml with new ones that reference our jars.
250 (let* ((build.xml (with-input-from-file "build.xml"
252 (xml->sxml #:trim-whitespace? #t))))
253 (jars (append-map (match-lambda
254 (((? (cut string-prefix? "java-" <>)
256 (find-files directory "\\.jar$"))
259 (classpath (string-join jars ":"))
260 (fileset (map (lambda (jar)
261 `(zipfileset (@ (excludes "META-INF/*.SF")
264 (call-with-output-file "build.xml"
269 `(;; Remove all zipfileset tags from the "jar" tree and
270 ;; inject our own tags.
271 (jar . ,(lambda (tag . kids)
274 (not (eq? 'zipfileset (car e)))))
277 ;; Skip the "bundle" target (and the "-post-jar" target
278 ;; that depends on it), because we don't need it and it
279 ;; confuses sxml->xml.
280 (target . ,(lambda (tag . kids)
281 (let ((name ((sxpath '(name *text*))
283 (if (or (member "bundle" name)
284 (member "-post-jar" name))
287 (*default* . ,(lambda (tag . kids) `(,tag ,@kids)))
288 (*text* . ,(lambda (_ txt)
291 ("${TODAY}" "(unknown)")
297 (string-append "-Djavac.classpath=" classpath)
298 "-Dbuild.runtime=true"
299 "-Dbuild.time=01/01/1970 00:00:00"
302 (string-append "-Dtag.short.version="
305 (lambda* (#:key inputs outputs #:allow-other-keys)
306 (let* ((out (assoc-ref outputs "out"))
307 (share (string-append out "/share/axoloti/")))
308 (install-file "dist/Axoloti.jar" share)
310 ;; We do this to ensure that this package retains references to
311 ;; other Java packages' jar files.
312 (install-file "build.xml" share)
314 ;; Create a launcher script
315 (mkdir (string-append out "/bin"))
316 (let ((target (string-append out "/bin/Axoloti")))
317 (with-output-to-file target
319 (let* ((dir (string-append (assoc-ref outputs "out")
321 (runtime (search-input-directory inputs
323 (toolchain (assoc-ref inputs "cross-toolchain"))
324 (includes (string-append
326 "/arm-none-eabi/include:"
328 "/arm-none-eabi/include/arm-none-eabi/armv7e-m")))
330 (string-append "#!" (which "sh") "\n"
331 "export CROSS_CPATH=" includes "\n"
332 "export CROSS_CPLUS_INCLUDE_PATH=" includes "\n"
333 "export CROSS_LIBRARY_PATH="
334 toolchain "/arm-none-eabi/lib" "\n"
336 " -Daxoloti_release=" runtime
337 " -Daxoloti_runtime=" runtime
338 " -jar " dir "/Axoloti.jar")))))
339 (chmod target #o555))
341 (add-after 'install 'strip-jar-timestamps
342 (assoc-ref ant:%standard-phases 'strip-jar-timestamps)))))
344 `(("icedtea" ,icedtea "jdk")
345 ("cross-toolchain" ,arm-none-eabi-nano-toolchain-4.9)
346 ("java-simple-xml" ,java-simple-xml)
347 ("java-rsyntaxtextarea" ,java-rsyntaxtextarea)
348 ("java-usb4java" ,java-usb4java)
349 ("java-jsch" ,java-jsch)
350 ("java-slf4j-api" ,java-slf4j-api)
351 ("java-jgit" ,java-jgit-4.2)
352 ("axoloti-runtime" ,axoloti-runtime)))
354 (list ant 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")
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/firmware-1.0.12"))
532 (search-input-directory inputs
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/thumb/v7e-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")
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