gnu: libretro-lowresnx: Update to 1.2.
[jackhill/guix/guix.git] / gnu / packages / drones.scm
CommitLineData
8e077257
MO
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2019 Mathieu Othacehe <m.othacehe@gmail.com>
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 (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)
55e1475c 26 #:use-module (gnu packages xml)
8e077257
MO
27 #:use-module (guix download)
28 #:use-module (guix utils)
29 #:use-module (guix git-download)
30 #:use-module (guix build-system gnu))
31
32(define (ardupilot-type->tag type)
33 (case type
34 ((copter) "Copter")
35 ((plane) "ArduPlane")
36 ((rover) "Rover")
37 (else #f)))
38
39(define (ardupilot-type->waf-cmd type)
40 (symbol->string type))
41
42(define* (make-ardupilot-firmware #:key name version base32 type board target)
43 (package
44 (name (string-append name "-" board))
45 (version version)
46 (source
47 (origin
48 (method git-fetch)
49 (uri (git-reference
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.
56 (recursive? #t)))
57 (file-name (git-file-name name version))
58 (sha256 base32)))
59
60 ;; Could also be waf-build-system but every phase has to be rewritten
61 ;; anyway.
62 (build-system gnu-build-system)
63 (arguments
64 `(#:imported-modules ((gnu build cross-toolchain)
65 ,@%gnu-build-system-modules)
66 #:phases
67 (modify-phases %standard-phases
68 (delete 'bootstrap)
69
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")))
74 (delete-file "waf")
75 (copy-file (string-append waf "/bin/waf") "waf"))
76 #t))
77
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)
85 #:inputs
86 `(("libc" . ,(assoc-ref (or native-inputs inputs)
87 "ardupilot-cross-libc"))
88 ("xkernel-headers" .
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"
95 (string-append
96 (getenv "CROSS_LIBRARY_PATH") ":"
97 (assoc-ref (or native-inputs inputs)
98 "ardupilot-cross-libc-static") "/lib"))
99 #t))
100
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.*$")
106 ""))
107 (substitute* "Tools/ardupilotwaf/boards.py"
108 (("^.*GIT_VERSION.*$")
109 ""))
110 #t))
111
112 ;; Configure for the given BOARD, and force a static build for
113 ;; reasons exposed above.
114 (replace 'configure
115 (lambda* (#:key outputs #:allow-other-keys)
116 (invoke "./waf" "configure" "--board" ,board "--static")
117 #t))
118
119 (replace 'build
120 (lambda* (#:key outputs #:allow-other-keys)
121 (invoke "./waf" ,(ardupilot-type->waf-cmd type))
122 #t))
123
124 ;; Do not run tests as we are always cross-compiling.
125 (delete 'check)
126
127 ;; Install the produced firmware.
128 (replace 'install
129 (lambda* (#:key outputs #:allow-other-keys)
130 (let* ((out (assoc-ref outputs "out"))
131 (bin (string-append out "/bin")))
132 (mkdir-p bin)
133 (copy-recursively
134 (string-append "build/" ,board "/bin") bin))
135 #t)))))
136 (native-inputs
137 `(("waf" ,python-waf)
138 ("python" ,python)
139 ("python-future" ,python-future)
140 ("python-lxml" ,python-lxml)
141
142 ;; Packages needed for cross-compiling the firmware.
143 ("ardupilot-cross-gcc" ,(cross-gcc target
144 #:xbinutils
145 (cross-binutils target)
146 #:libc
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
152 (cross-libc target))
153 "kernel-headers"))
154 ("ardupilot-cross-binutils" ,(cross-binutils target))
155 ("ardupilot-cross-pkg-config" ,(parameterize ((%current-target-system
156 target))
157 pkg-config))))
158 (home-page "https://ardupilot.org/")
159 (synopsis "Unmanned vehicle autopilot software suite")
160 (description "@code{ardupilot} is an unmanned vehicle autopilot software
161suite capable of controlling autonomous:
162@itemize
163@item multirotor drones
164@item fixed-wing and vtol aircraft
165@item helicopters
166@item ground rovers
167@item boats
168@item submarines
169@item antenna trackers
170@end itemize")
171 (license gpl3+)))
172
173(define (make-arducopter-firmware board target)
174 (make-ardupilot-firmware
175 #:name "arducopter"
176 #:version "3.6.11"
177 #:base32 (base32 "1zkr2nhkksmrriirs2dnp8a0gcf9rfqw1x86pzhh6w4ciqwpidqn")
178 #:type 'copter
179 #:board board
180 #:target target))
181
182(define (make-arduplane-firmware board target)
183 (make-ardupilot-firmware
184 #:name "arduplane"
185 #:version "4.0.1"
186 #:base32 (base32 "0awafvrppg4ilwpbhw88r5xkbgqrmqypsn6lbzyi6bz0zy5cfhb5")
187 #:type 'plane
188 #:board board
189 #:target target))
190
191(define-public arducopter-bbbmini
192 (make-arducopter-firmware "bbbmini" "arm-linux-gnueabihf"))
193
194(define-public arduplane-bbbmini
195 (make-arduplane-firmware "bbbmini" "arm-linux-gnueabihf"))
196
197;; Firmware for Bebop and Bebop2 drones.
198(define-public arducopter-bebop
199 (make-arducopter-firmware "bebop" "arm-linux-gnueabihf"))