;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2016 Ricardo Wurmus ;;; ;;; 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 . (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: ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; '("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+)))