1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2019 Mathieu Othacehe <m.othacehe@gmail.com>
4 ;;; This file is part of GNU Guix.
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.
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.
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/>.
19 (define-module (gnu packages drones)
20 #:use-module (guix licenses)
21 #:use-module (guix packages)
22 #:use-module (gnu packages cross-base)
23 #:use-module (gnu packages pkg-config)
24 #:use-module (gnu packages python)
25 #:use-module (gnu packages python-xyz)
26 #:use-module (gnu packages xml)
27 #:use-module (guix download)
28 #:use-module (guix utils)
29 #:use-module (guix git-download)
30 #:use-module (guix build-system gnu))
32 (define (ardupilot-type->tag type)
39 (define (ardupilot-type->waf-cmd type)
40 (symbol->string type))
42 (define* (make-ardupilot-firmware #:key name version base32 type board target)
44 (name (string-append name "-" board))
50 (url "https://github.com/ArduPilot/ardupilot")
51 (commit (string-append
52 (ardupilot-type->tag type) "-" version))
53 ;; XXX: Ardupilot includes several git submodules. They should be
54 ;; avoided but as this is not supported upstream, and not trivial
55 ;; to fix, keep it this way for now.
57 (file-name (git-file-name name version))
60 ;; Could also be waf-build-system but every phase has to be rewritten
62 (build-system gnu-build-system)
64 `(#:imported-modules ((gnu build cross-toolchain)
65 ,@%gnu-build-system-modules)
67 (modify-phases %standard-phases
70 ;; Remove the root waf script that relies on waf git submodule.
71 (add-before 'configure 'setup-waf
72 (lambda* (#:key native-inputs inputs #:allow-other-keys)
73 (let ((waf (assoc-ref (or native-inputs inputs) "waf")))
75 (copy-file (string-append waf "/bin/waf") "waf"))
78 ;; When cross-compiling, we do not want to use the default gnu
79 ;; cross-compiler, so set CROSS_CPATH and CROSS_LIBRARY_PATH
80 ;; variables ourselves instead.
81 (delete 'set-cross-path)
82 (add-before 'configure 'set-custom-cross-cpath
83 (lambda* (#:key native-inputs inputs #:allow-other-keys)
84 ((@@ (gnu build cross-toolchain) set-cross-path)
86 `(("libc" . ,(assoc-ref (or native-inputs inputs)
87 "ardupilot-cross-libc"))
89 ,(assoc-ref (or native-inputs inputs)
90 "ardupilot-cross-kernel-headers"))))
91 ;; We need to produce a static binary, so that it can works on
92 ;; other systems than Guix System. Add a static version of the
93 ;; cross libc to CROSS_LIBRARY_PATH variable.
94 (setenv "CROSS_LIBRARY_PATH"
96 (getenv "CROSS_LIBRARY_PATH") ":"
97 (assoc-ref (or native-inputs inputs)
98 "ardupilot-cross-libc-static") "/lib"))
101 ;; Remove dependencies to 'git'.
102 (add-before 'configure 'remove-git
103 (lambda* (#:key inputs #:allow-other-keys)
104 (substitute* "wscript"
105 (("^.*cfg\\.load\\('git_submodule.*$")
107 (substitute* "Tools/ardupilotwaf/boards.py"
108 (("^.*GIT_VERSION.*$")
112 ;; Configure for the given BOARD, and force a static build for
113 ;; reasons exposed above.
115 (lambda* (#:key outputs #:allow-other-keys)
116 (invoke "./waf" "configure" "--board" ,board "--static")
120 (lambda* (#:key outputs #:allow-other-keys)
121 (invoke "./waf" ,(ardupilot-type->waf-cmd type))
124 ;; Do not run tests as we are always cross-compiling.
127 ;; Install the produced firmware.
129 (lambda* (#:key outputs #:allow-other-keys)
130 (let* ((out (assoc-ref outputs "out"))
131 (bin (string-append out "/bin")))
134 (string-append "build/" ,board "/bin") bin))
137 `(("waf" ,python-waf)
139 ("python-future" ,python-future)
140 ("python-lxml" ,python-lxml)
142 ;; Packages needed for cross-compiling the firmware.
143 ("ardupilot-cross-gcc" ,(cross-gcc target
145 (cross-binutils target)
147 (cross-libc target)))
148 ("ardupilot-cross-libc" ,(cross-libc target))
149 ("ardupilot-cross-libc-static" ,(cross-libc target) "static")
150 ("ardupilot-cross-kernel-headers"
151 ,@(assoc-ref (package-propagated-inputs
154 ("ardupilot-cross-binutils" ,(cross-binutils target))
155 ("ardupilot-cross-pkg-config" ,(parameterize ((%current-target-system
158 (home-page "https://ardupilot.org/")
159 (synopsis "Unmanned vehicle autopilot software suite")
160 (description "@code{ardupilot} is an unmanned vehicle autopilot software
161 suite capable of controlling autonomous:
163 @item multirotor drones
164 @item fixed-wing and vtol aircraft
169 @item antenna trackers
173 (define (make-arducopter-firmware board target)
174 (make-ardupilot-firmware
177 #:base32 (base32 "1zkr2nhkksmrriirs2dnp8a0gcf9rfqw1x86pzhh6w4ciqwpidqn")
182 (define (make-arduplane-firmware board target)
183 (make-ardupilot-firmware
186 #:base32 (base32 "0awafvrppg4ilwpbhw88r5xkbgqrmqypsn6lbzyi6bz0zy5cfhb5")
191 (define-public arducopter-bbbmini
192 (make-arducopter-firmware "bbbmini" "arm-linux-gnueabihf"))
194 (define-public arduplane-bbbmini
195 (make-arduplane-firmware "bbbmini" "arm-linux-gnueabihf"))
197 ;; Firmware for Bebop and Bebop2 drones.
198 (define-public arducopter-bebop
199 (make-arducopter-firmware "bebop" "arm-linux-gnueabihf"))