libre: Add Axoloti patcher.
[software/guix-rekado.git] / libre / custom / packages / axoloti.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2016 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
19 (define-module (custom packages axoloti)
20 #:use-module (guix utils)
21 #:use-module (guix packages)
22 #:use-module (guix download)
23 #:use-module (guix svn-download)
24 #:use-module (guix git-download)
25 #:use-module ((guix licenses) #:prefix license:)
26 #:use-module (guix build-system gnu)
27 #:use-module (gnu packages)
28 #:use-module (gnu packages base)
29 #:use-module (gnu packages cross-base)
30 #:use-module (gnu packages embedded)
31 #:use-module (gnu packages flashing-tools)
32 #:use-module (gnu packages java)
33 #:use-module (gnu packages libusb)
34 #:use-module (gnu packages pkg-config)
35 #:use-module (gnu packages zip))
36
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
46 (define dfu-util-for-axoloti
47 (package (inherit dfu-util)
48 (name "axoloti-dfu-util")
49 (version "0.8")
50 (source
51 (origin
52 (method url-fetch)
53 (uri (string-append "http://dfu-util.sourceforge.net/releases/"
54 "dfu-util-" version ".tar.gz"))
55 (sha256
56 (base32
57 "0n7h08avlzin04j93m6hkq9id6hxjiiix7ff9gc2n89aw6dxxjsm"))))
58 (inputs
59 `(("libusb" ,libusb-for-axoloti)))))
60
61 (define-public axoloti
62 (package
63 (name "axoloti")
64 (version "1.0.11")
65 (source (origin
66 (method url-fetch)
67 (uri (string-append "https://github.com/axoloti/axoloti/"
68 "archive/" version ".tar.gz"))
69 (file-name (string-append name "-" version ".tar.gz"))
70 (sha256
71 (base32
72 "1k78f7pmya3yy7l2d7lbjizivkj6mz6v2758dmy372yks3sl6d6w"))))
73 (build-system gnu-build-system)
74 (arguments
75 `(#:tests? #f ; no check target
76 #:phases
77 (modify-phases %standard-phases
78 (add-after 'unpack 'patch-paths
79 (lambda* (#:key inputs #:allow-other-keys)
80 ;; prepare ChibiOS
81 (and
82 (zero? (system* "unzip" "-o" (assoc-ref inputs "chibios")))
83 (zero? (system* "mv" "ChibiOS_2.6.9" "chibios"))
84 (with-directory-excursion "chibios/ext"
85 (zero? (system* "unzip" "-o" "fatfs-0.9-patched.zip"))))
86 ;; Remove source of non-determinism in ChibiOS
87 (substitute* "chibios/os/various/shell.c"
88 (("#ifdef __DATE__") "#if 0"))
89 ;; Patch shell paths
90 (substitute* '("src/main/java/qcmds/QCmdCompileFirmware.java"
91 "src/main/java/qcmds/QCmdCompilePatch.java"
92 "src/main/java/qcmds/QCmdFlashDFU.java")
93 (("/bin/sh") (which "sh")))
94 ;; Override cross compiler base name
95 (substitute* "firmware/Makefile.patch"
96 (("arm-none-eabi-(gcc|g\\+\\+|objcopy|objdump)" tool)
97 (which tool)))
98 ;; Hardcode full path to compiler tools
99 (substitute* '("firmware/Makefile"
100 "firmware/flasher/Makefile"
101 "firmware/mounter/Makefile")
102 (("(CP|OD|SZ) = \\$\\(TRGT\\)(objcopy|objdump|size)" _ pre post)
103 (string-append pre " = "
104 (which (string-append "arm-none-eabi-" post))))
105 (("TRGT =.*")
106 (string-append "TRGT = "
107 (assoc-ref inputs "xgcc")
108 "/bin/arm-none-eabi-\n")))
109 ;; Hardcode path to "make"
110 (substitute* '("firmware/compile_firmware_linux.sh"
111 "firmware/compile_patch_linux.sh")
112 (("make") (which "make")))
113 ;; Hardcode dfu-util path
114 (substitute* "platform_linux/upload_fw_dfu.sh"
115 (("-f \"\\$\\{platformdir\\}/bin/dfu-util\"") "-z \"\"")
116 (("\\./dfu-util") (which "dfu-util")))
117 #t))
118 (delete 'configure)
119 (replace 'build
120 (lambda* (#:key inputs outputs #:allow-other-keys)
121 (setenv "JAVA_HOME" (assoc-ref inputs "icedtea"))
122 (setenv "CROSS_CPATH"
123 (string-append (assoc-ref inputs "xlibc")
124 "/arm-none-eabi/include"))
125 (setenv "CROSS_LIBRARY_PATH"
126 (string-append (assoc-ref inputs "xlibc")
127 "/arm-none-eabi/lib"))
128 (and
129 ;; Build Axoloti firmware with cross-compiler
130 (with-directory-excursion "platform_linux"
131 (zero? (system* "sh" "compile_firmware.sh")))
132 ;; build Java application
133 ;; TODO: repackage jar for determinism; fix javadoc
134 (zero? (system* "ant"
135 "-Dbuild.runtime=true"
136 (string-append "-Dtag.short.version="
137 ,version))))))
138 (replace 'install
139 (lambda* (#:key inputs outputs #:allow-other-keys)
140 (let* ((out (assoc-ref outputs "out"))
141 (share (string-append out "/share/axoloti/"))
142 (doc (string-append share "doc")))
143 (for-each (lambda (dir)
144 (copy-recursively dir (string-append share dir)))
145 ;; TODO: restrict to these files:
146 ;; <include name="doc/*"/>
147 ;; <include name="patches/**/*"/>
148 ;; <include name="objects/**/*"/>
149 ;; <include name="firmware/*" />
150 ;; <include name="firmware/STM*/**/*" />
151 ;; <include name="firmware/samples/*" />
152 ;; <include name="firmware/build/*.bin" />
153 ;; <include name="firmware/build/*.elf" />
154 ;; <include name="firmware/flasher/*" />
155 ;; <include name="firmware/flasher/flasher_build/*.bin" />
156 ;; <include name="firmware/flasher/flasher_build/*.elf" />
157 ;; <include name="firmware/mounter/*" />
158 ;; <include name="firmware/mounter/mounter_build/*.bin" />
159 ;; <include name="firmware/mounter/mounter_build/*.elf" />
160 ;; <include name="chibios/*"/>
161 ;; <include name="chibios/boards/ST_STM32F4_DISCOVERY/*"/>
162 ;; <include name="chibios/ext/**/*"/>
163 ;; <include name="chibios/os/**/*"/>
164 ;; <include name="chibios/docs/**/*"/>
165 ;; <include name="CMSIS/**/*"/>
166 ;; <include name="patch/**/*"/>
167 ;; <include name="*.txt"/>
168
169 '("objects" "patches" "CMSIS"
170 "firmware" "chibios" "platform_linux"))
171 (copy-recursively "dist/javadoc" doc)
172 (install-file "dist/Axoloti.jar" share)
173 ;; create wrapper script
174 (mkdir (string-append out "/bin"))
175 (let ((target (string-append out "/bin/Axoloti")))
176 (with-output-to-file target
177 (lambda ()
178 (let ((path (string-append (assoc-ref outputs "out")
179 "/share/axoloti")))
180 (display
181 (string-append "#!" (which "sh") "\n"
182 "export CROSS_CPATH="
183 (assoc-ref inputs "xlibc")
184 "/arm-none-eabi/include" "\n"
185 "export CROSS_LIBRARY_PATH="
186 (assoc-ref inputs "xlibc")
187 "/arm-none-eabi/lib" "\n"
188 (which "java")
189 " -Daxoloti_release=" path
190 " -Daxoloti_runtime=" path
191 " -jar " path "/Axoloti.jar")))))
192 (chmod target #o555))
193 #t))))))
194 (inputs
195 `(("icedtea" ,icedtea "jdk")
196 ;; for the firmware
197 ("chibios"
198 ,(origin
199 (method url-fetch)
200 (uri "mirror://sourceforge/chibios/ChibiOS_RT%20stable/Version%202.6.9/ChibiOS_2.6.9.zip")
201 (sha256
202 (base32
203 "0lb5s8pkj80mqhsy47mmq0lqk34s2a2m3xagzihalvabwd0frhlj"))))
204 ;; for compiling patches
205 ("make" ,gnu-make)
206 ;; for compiling firmware
207 ("xgcc" ,gcc-arm-none-eabi-4.9)
208 ("xbinutils" ,(cross-binutils "arm-none-eabi"))
209 ("xlibc" ,newlib-nano-arm-none-eabi)
210 ;; for uploading compiled patches and firmware
211 ("dfu-util" ,dfu-util-for-axoloti)))
212 (native-inputs
213 `(("ant" ,ant)
214 ("unzip" ,unzip)))
215 (home-page "http://axoloti.com")
216 (synopsis "Audio development environment for the Axoloti core board")
217 (description
218 "The Axoloti patcher offers a “patcher” environment similar to Pure Data
219 for sketching digital audio algorithms. The patches run on a standalone
220 powerful microcontroller board: Axoloti Core.")
221 (license license:gpl3+)))