Commit | Line | Data |
---|---|---|
d991b056 | 1 | ;;; GNU Guix --- Functional package management for GNU |
1ae04a2a | 2 | ;;; Copyright © 2016, 2017, 2019 Ricardo Wurmus <rekado@elephly.net> |
07c1a10e | 3 | ;;; Copyright © 2019 Tobias Geerinckx-Rice <me@tobias.gr> |
d991b056 RW |
4 | ;;; |
5 | ;;; This file is part of GNU Guix. | |
6 | ;;; | |
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. | |
11 | ;;; | |
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. | |
16 | ;;; | |
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/>. | |
19 | ||
20 | (define-module (gnu packages axoloti) | |
21 | #:use-module (guix utils) | |
22 | #:use-module (guix packages) | |
23 | #:use-module (guix download) | |
07c1a10e | 24 | #:use-module (guix git-download) |
d991b056 RW |
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)) | |
40 | ||
41 | (define libusb-for-axoloti | |
42 | (package (inherit libusb) | |
43 | (name "axoloti-libusb") | |
44 | (version (package-version libusb)) | |
45 | (source | |
46 | (origin | |
47 | (inherit (package-source libusb)) | |
48 | (patches (list (search-patch "libusb-for-axoloti.patch"))))))) | |
49 | ||
50 | (define dfu-util-for-axoloti | |
51 | (package (inherit dfu-util) | |
52 | (name "axoloti-dfu-util") | |
53 | (version "0.8") | |
54 | (source | |
55 | (origin | |
56 | (method url-fetch) | |
57 | (uri (string-append "http://dfu-util.sourceforge.net/releases/" | |
58 | "dfu-util-" version ".tar.gz")) | |
59 | (sha256 | |
60 | (base32 | |
61 | "0n7h08avlzin04j93m6hkq9id6hxjiiix7ff9gc2n89aw6dxxjsm")))) | |
62 | (inputs | |
63 | `(("libusb" ,libusb-for-axoloti))))) | |
64 | ||
65 | (define-public axoloti-runtime | |
66 | (package | |
67 | (name "axoloti-runtime") | |
68 | (version "1.0.12") | |
07c1a10e TGR |
69 | (source |
70 | (origin | |
71 | (method git-fetch) | |
72 | (uri (git-reference | |
73 | (url "https://github.com/axoloti/axoloti.git") | |
74 | (commit version))) | |
75 | (file-name (git-file-name name version)) | |
76 | (sha256 | |
77 | (base32 "05hyr9qx9dplp0gkx4v34i17972b3f512qndnarzy4wzfpnp0s3b")) | |
78 | (modules '((guix build utils))) | |
79 | (snippet | |
80 | '(begin | |
81 | ;; Remove pre-built Java binaries. | |
82 | (delete-file-recursively "lib/") | |
83 | #t)))) | |
d991b056 RW |
84 | (build-system gnu-build-system) |
85 | (arguments | |
86 | `(#:tests? #f ; no check target | |
87 | #:modules ((guix build gnu-build-system) | |
88 | (guix build utils) | |
89 | (srfi srfi-1) | |
90 | (srfi srfi-26) | |
91 | (ice-9 match) | |
92 | (ice-9 regex)) | |
93 | #:imported-modules ((guix build syscalls) | |
94 | ,@%gnu-build-system-modules) | |
95 | #:phases | |
96 | (modify-phases %standard-phases | |
97 | (add-after 'unpack 'patch-paths | |
98 | (lambda* (#:key inputs #:allow-other-keys) | |
99 | ;; prepare ChibiOS | |
1ae04a2a RW |
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")) | |
d991b056 RW |
104 | |
105 | ;; Remove source of non-determinism in ChibiOS | |
106 | (substitute* "chibios/os/various/shell.c" | |
107 | (("#ifdef __DATE__") "#if 0")) | |
108 | ||
109 | ;; Patch shell paths | |
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"))) | |
114 | ||
115 | ;; Override cross compiler base name | |
116 | (substitute* "firmware/Makefile.patch" | |
117 | (("arm-none-eabi-(gcc|g\\+\\+|objcopy|objdump)" tool) | |
118 | (which tool))) | |
119 | ||
120 | ;; Hardcode full path to compiler tools | |
121 | (substitute* '("firmware/Makefile" | |
122 | "firmware/flasher/Makefile" | |
123 | "firmware/mounter/Makefile") | |
124 | (("TRGT =.*") | |
125 | (string-append "TRGT = " | |
126 | (assoc-ref inputs "cross-toolchain") | |
127 | "/bin/arm-none-eabi-\n"))) | |
128 | ||
129 | ;; Hardcode path to "make" | |
130 | (substitute* '("firmware/compile_firmware_linux.sh" | |
131 | "firmware/compile_patch_linux.sh") | |
132 | (("make") (which "make"))) | |
133 | ||
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"))) | |
138 | #t)) | |
139 | (delete 'configure) | |
140 | (replace 'build | |
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 | |
145 | toolchain | |
146 | "/arm-none-eabi/include:" | |
147 | toolchain | |
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" | |
1ae04a2a | 155 | (invoke "sh" "compile_firmware.sh")))) |
d991b056 RW |
156 | (replace 'install |
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")) | |
161 | (dir (getcwd)) | |
162 | (pats '("/doc/[^/]+$" | |
163 | "/patches/[^/]+/[^/]+$" | |
164 | "/objects/[^/]+/[^/]+$" | |
165 | "/firmware/.+" | |
166 | "/chibios/[^/]+$" | |
167 | "/chibios/boards/ST_STM32F4_DISCOVERY/[^/]+$" | |
168 | "/chibios/(ext|os|docs)/.+" | |
169 | "/CMSIS/[^/]+/[^/]+$" | |
170 | "/patch/[^/]+/[^/]+$" | |
171 | "/[^/]+\\.txt$")) | |
172 | (pattern (string-append | |
173 | "(" (string-join | |
174 | (map (cut string-append dir <>) | |
175 | pats) | |
176 | "|") ")")) | |
177 | (files (find-files dir | |
178 | (lambda (file stat) | |
179 | (and (eq? 'regular (stat:type stat)) | |
180 | (string-match pattern file)))))) | |
181 | (for-each (lambda (file) | |
182 | (install-file file | |
183 | (string-append | |
184 | share | |
185 | (regexp-substitute | |
186 | #f | |
187 | (string-match dir (dirname file)) | |
188 | 'pre 'post)))) | |
189 | files) | |
190 | #t)))))) | |
191 | (inputs | |
192 | `(("chibios" | |
193 | ,(origin | |
194 | (method url-fetch) | |
341bddb3 | 195 | (uri "mirror://sourceforge/chibios/ChibiOS%20GPL3/Version%202.6.9/ChibiOS_2.6.9.zip") |
d991b056 RW |
196 | (sha256 |
197 | (base32 | |
198 | "0lb5s8pkj80mqhsy47mmq0lqk34s2a2m3xagzihalvabwd0frhlj")))) | |
199 | ;; for compiling patches | |
200 | ("make" ,gnu-make) | |
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))) | |
205 | (native-inputs | |
206 | `(("unzip" ,unzip))) | |
94b55ace | 207 | (home-page "http://www.axoloti.com/") |
d991b056 RW |
208 | (synopsis "Audio development environment for the Axoloti core board") |
209 | (description | |
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 | |
213 | runtime.") | |
214 | (license license:gpl3+))) | |
215 | ||
216 | (define-public axoloti-patcher | |
217 | (package (inherit axoloti-runtime) | |
218 | (name "axoloti-patcher") | |
219 | (version (package-version axoloti-runtime)) | |
220 | (arguments | |
221 | `(#:tests? #f ; no check target | |
222 | #:modules ((guix build gnu-build-system) | |
223 | ((guix build ant-build-system) #:prefix ant:) | |
224 | (guix build utils) | |
225 | (srfi srfi-1) | |
226 | (srfi srfi-26) | |
227 | (ice-9 match) | |
228 | (ice-9 regex) | |
229 | (sxml simple) | |
230 | (sxml xpath) | |
231 | (sxml transform)) | |
232 | #:imported-modules ((guix build ant-build-system) | |
233 | (guix build syscalls) | |
234 | ,@%gnu-build-system-modules) | |
235 | #:phases | |
236 | (modify-phases %standard-phases | |
07c1a10e TGR |
237 | (add-after 'unpack 'make-git-checkout-writable |
238 | (lambda _ | |
239 | (for-each make-file-writable (find-files ".")) | |
240 | #t)) | |
d991b056 RW |
241 | (delete 'configure) |
242 | (replace 'build | |
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" | |
249 | (lambda _ | |
250 | (xml->sxml #:trim-whitespace? #t)))) | |
251 | (jars (append-map (match-lambda | |
252 | (((? (cut string-prefix? "java-" <>) | |
253 | label) . directory) | |
254 | (find-files directory "\\.jar$")) | |
255 | (_ '())) | |
256 | inputs)) | |
257 | (classpath (string-join jars ":")) | |
258 | (fileset (map (lambda (jar) | |
259 | `(zipfileset (@ (excludes "META-INF/*.SF") | |
260 | (src ,jar)))) | |
261 | jars))) | |
262 | (call-with-output-file "build.xml" | |
263 | (lambda (port) | |
264 | (sxml->xml | |
265 | (pre-post-order | |
266 | build.xml | |
267 | `(;; Remove all zipfileset tags from the "jar" tree and | |
268 | ;; inject our own tags. | |
269 | (jar . ,(lambda (tag . kids) | |
270 | `(jar ,@(append-map | |
271 | (filter (lambda (e) | |
272 | (not (eq? 'zipfileset (car e))))) | |
273 | kids) | |
274 | ,@fileset))) | |
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*)) | |
280 | (car kids)))) | |
281 | (if (or (member "bundle" name) | |
282 | (member "-post-jar" name)) | |
283 | '() ; skip | |
284 | `(,tag ,@kids))))) | |
285 | (*default* . ,(lambda (tag . kids) `(,tag ,@kids))) | |
286 | (*text* . ,(lambda (_ txt) | |
287 | (match txt | |
288 | ;; Remove timestamp. | |
289 | ("${TODAY}" "(unknown)") | |
290 | (_ txt)))))) | |
291 | port))) | |
292 | ||
293 | ;; Build it! | |
c28bf42f RW |
294 | (invoke "ant" |
295 | (string-append "-Djavac.classpath=" classpath) | |
296 | "-Dbuild.runtime=true" | |
297 | "-Dbuild.time=01/01/1970 00:00:00" | |
298 | "-Djavac.source=1.7" | |
299 | "-Djavac.target=1.7" | |
300 | (string-append "-Dtag.short.version=" | |
301 | ,version))))) | |
d991b056 RW |
302 | (replace 'install |
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) | |
307 | ||
308 | ;; We do this to ensure that this package retains references to | |
309 | ;; other Java packages' jar files. | |
310 | (install-file "build.xml" share) | |
311 | ||
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 | |
316 | (lambda () | |
317 | (let* ((dir (string-append (assoc-ref outputs "out") | |
318 | "/share/axoloti")) | |
319 | (runtime (string-append (assoc-ref inputs "axoloti-runtime") | |
320 | "/share/axoloti")) | |
321 | (toolchain (assoc-ref inputs "cross-toolchain")) | |
322 | (includes (string-append | |
323 | toolchain | |
324 | "/arm-none-eabi/include:" | |
325 | toolchain | |
326 | "/arm-none-eabi/include/arm-none-eabi/armv7e-m"))) | |
327 | (display | |
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" | |
333 | (which "java") | |
334 | " -Daxoloti_release=" runtime | |
335 | " -Daxoloti_runtime=" runtime | |
336 | " -jar " dir "/Axoloti.jar"))))) | |
337 | (chmod target #o555)) | |
338 | #t))) | |
339 | (add-after 'install 'strip-jar-timestamps | |
340 | (assoc-ref ant:%standard-phases 'strip-jar-timestamps))))) | |
341 | (inputs | |
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))) | |
351 | (native-inputs | |
352 | `(("ant" ,ant) | |
353 | ("zip" ,zip) ; for repacking the jar | |
354 | ("unzip" ,unzip))) | |
355 | (description | |
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."))) |