summaryrefslogtreecommitdiff
path: root/libre/custom/packages/axoloti.scm
blob: 433860b690c51a977bf0c5b7d5737aa656c17452 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2016 Ricardo Wurmus <rekado@elephly.net>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (custom packages axoloti)
  #:use-module (guix utils)
  #:use-module (guix packages)
  #:use-module (guix download)
  #:use-module (guix svn-download)
  #:use-module (guix git-download)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix build-system gnu)
  #:use-module (gnu packages)
  #:use-module (gnu packages base)
  #:use-module (gnu packages cross-base)
  #:use-module (gnu packages embedded)
  #:use-module (gnu packages flashing-tools)
  #:use-module (gnu packages java)
  #:use-module (gnu packages libusb)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages zip))

(define libusb-for-axoloti
  (package (inherit libusb)
    (name "axoloti-libusb")
    (version (package-version libusb))
    (source
     (origin
       (inherit (package-source libusb))
       (patches (list (search-patch "libusb-for-axoloti.patch")))))))

(define dfu-util-for-axoloti
  (package (inherit dfu-util)
    (name "axoloti-dfu-util")
    (version "0.8")
    (source
     (origin
       (method url-fetch)
       (uri (string-append "http://dfu-util.sourceforge.net/releases/"
                           "dfu-util-" version ".tar.gz"))
       (sha256
        (base32
         "0n7h08avlzin04j93m6hkq9id6hxjiiix7ff9gc2n89aw6dxxjsm"))))
    (inputs
     `(("libusb" ,libusb-for-axoloti)))))

(define-public axoloti
  (package
    (name "axoloti")
    (version "1.0.11")
    (source (origin
              (method url-fetch)
              (uri (string-append "https://github.com/axoloti/axoloti/"
                                  "archive/" version ".tar.gz"))
              (file-name (string-append name "-" version ".tar.gz"))
              (sha256
               (base32
                "1k78f7pmya3yy7l2d7lbjizivkj6mz6v2758dmy372yks3sl6d6w"))))
    (build-system gnu-build-system)
    (arguments
     `(#:tests? #f  ; no check target
       #:phases
       (modify-phases %standard-phases
         (add-after 'unpack 'patch-paths
           (lambda* (#:key inputs #:allow-other-keys)
             ;; prepare ChibiOS
             (and
              (zero? (system* "unzip" "-o" (assoc-ref inputs "chibios")))
              (zero? (system* "mv" "ChibiOS_2.6.9" "chibios"))
              (with-directory-excursion "chibios/ext"
                (zero? (system* "unzip" "-o" "fatfs-0.9-patched.zip"))))
             ;; Remove source of non-determinism in ChibiOS
             (substitute* "chibios/os/various/shell.c"
               (("#ifdef __DATE__") "#if 0"))
             ;; Patch shell paths
             (substitute* '("src/main/java/qcmds/QCmdCompileFirmware.java"
                            "src/main/java/qcmds/QCmdCompilePatch.java"
                            "src/main/java/qcmds/QCmdFlashDFU.java")
               (("/bin/sh") (which "sh")))
             ;; Override cross compiler base name
             (substitute* "firmware/Makefile.patch"
               (("arm-none-eabi-(gcc|g\\+\\+|objcopy|objdump)" tool)
                (which tool)))
             ;; Hardcode full path to compiler tools
             (substitute* '("firmware/Makefile"
                            "firmware/flasher/Makefile"
                            "firmware/mounter/Makefile")
               (("(CP|OD|SZ)   = \\$\\(TRGT\\)(objcopy|objdump|size)" _ pre post)
                (string-append pre " = "
                               (which (string-append "arm-none-eabi-" post))))
               (("TRGT =.*")
                (string-append "TRGT = "
                               (assoc-ref inputs "xgcc")
                               "/bin/arm-none-eabi-\n")))
             ;; Hardcode path to "make"
             (substitute* '("firmware/compile_firmware_linux.sh"
                            "firmware/compile_patch_linux.sh")
               (("make") (which "make")))
             ;; Hardcode dfu-util path
             (substitute* "platform_linux/upload_fw_dfu.sh"
               (("-f \"\\$\\{platformdir\\}/bin/dfu-util\"") "-z \"\"")
               (("\\./dfu-util") (which "dfu-util")))
             #t))
         (delete 'configure)
         (replace 'build
           (lambda* (#:key inputs outputs #:allow-other-keys)
             (setenv "JAVA_HOME" (assoc-ref inputs "icedtea"))
             (setenv "CROSS_CPATH"
                     (string-append (assoc-ref inputs "xlibc")
                                    "/arm-none-eabi/include"))
             (setenv "CROSS_LIBRARY_PATH"
                     (string-append (assoc-ref inputs "xlibc")
                                    "/arm-none-eabi/lib"))
             (and
              ;; Build Axoloti firmware with cross-compiler
              (with-directory-excursion "platform_linux"
                (zero? (system* "sh" "compile_firmware.sh")))
              ;; build Java application
              ;; TODO: repackage jar for determinism; fix javadoc
              (zero? (system* "ant"
                              "-Dbuild.runtime=true"
                              (string-append "-Dtag.short.version="
                                             ,version))))))
         (replace 'install
           (lambda* (#:key inputs outputs #:allow-other-keys)
             (let* ((out   (assoc-ref outputs "out"))
                    (share (string-append out "/share/axoloti/"))
                    (doc   (string-append share "doc")))
               (for-each (lambda (dir)
                           (copy-recursively dir (string-append share dir)))
                         ;; TODO: restrict to these files:
                         ;; <include name="doc/*"/>
                         ;; <include name="patches/**/*"/>
                         ;; <include name="objects/**/*"/>
                         ;; <include name="firmware/*" />
                         ;; <include name="firmware/STM*/**/*" />
                         ;; <include name="firmware/samples/*" />
                         ;; <include name="firmware/build/*.bin" />
                         ;; <include name="firmware/build/*.elf" />
                         ;; <include name="firmware/flasher/*" />
                         ;; <include name="firmware/flasher/flasher_build/*.bin" />
                         ;; <include name="firmware/flasher/flasher_build/*.elf" />
                         ;; <include name="firmware/mounter/*" />
                         ;; <include name="firmware/mounter/mounter_build/*.bin" />
                         ;; <include name="firmware/mounter/mounter_build/*.elf" />
                         ;; <include name="chibios/*"/>
                         ;; <include name="chibios/boards/ST_STM32F4_DISCOVERY/*"/>
                         ;; <include name="chibios/ext/**/*"/>
                         ;; <include name="chibios/os/**/*"/>
                         ;; <include name="chibios/docs/**/*"/>
                         ;; <include name="CMSIS/**/*"/>
                         ;; <include name="patch/**/*"/>
                         ;; <include name="*.txt"/>

                         '("objects" "patches" "CMSIS"
                           "firmware" "chibios" "platform_linux"))
               (copy-recursively "dist/javadoc" doc)
               (install-file "dist/Axoloti.jar" share)
               ;; create wrapper script
               (mkdir (string-append out "/bin"))
               (let ((target (string-append out "/bin/Axoloti")))
                 (with-output-to-file target
                   (lambda ()
                     (let ((path (string-append (assoc-ref outputs "out")
                                                "/share/axoloti")))
                       (display
                        (string-append "#!" (which "sh") "\n"
                                       "export CROSS_CPATH="
                                       (assoc-ref inputs "xlibc")
                                       "/arm-none-eabi/include" "\n"
                                       "export CROSS_LIBRARY_PATH="
                                       (assoc-ref inputs "xlibc")
                                       "/arm-none-eabi/lib" "\n"
                                       (which "java")
                                       " -Daxoloti_release=" path
                                       " -Daxoloti_runtime=" path
                                       " -jar " path "/Axoloti.jar")))))
                 (chmod target #o555))
               #t))))))
    (inputs
     `(("icedtea" ,icedtea "jdk")
       ;; for the firmware
       ("chibios"
        ,(origin
           (method url-fetch)
           (uri "mirror://sourceforge/chibios/ChibiOS_RT%20stable/Version%202.6.9/ChibiOS_2.6.9.zip")
           (sha256
            (base32
             "0lb5s8pkj80mqhsy47mmq0lqk34s2a2m3xagzihalvabwd0frhlj"))))
       ;; for compiling patches
       ("make" ,gnu-make)
       ;; for compiling firmware
       ("xgcc" ,gcc-arm-none-eabi-4.9)
       ("xbinutils" ,(cross-binutils "arm-none-eabi"))
       ("xlibc" ,newlib-nano-arm-none-eabi)
       ;; for uploading compiled patches and firmware
       ("dfu-util" ,dfu-util-for-axoloti)))
    (native-inputs
     `(("ant" ,ant)
       ("unzip" ,unzip)))
    (home-page "http://axoloti.com")
    (synopsis "Audio development environment for the Axoloti core board")
    (description
     "The Axoloti patcher offers a “patcher” environment similar to Pure Data
for sketching digital audio algorithms.  The patches run on a standalone
powerful microcontroller board: Axoloti Core.")
    (license license:gpl3+)))