Commit | Line | Data |
---|---|---|
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) | |
26 | #:use-module (guix download) | |
27 | #:use-module (guix utils) | |
28 | #:use-module (guix git-download) | |
29 | #:use-module (guix build-system gnu)) | |
30 | ||
31 | (define (ardupilot-type->tag type) | |
32 | (case type | |
33 | ((copter) "Copter") | |
34 | ((plane) "ArduPlane") | |
35 | ((rover) "Rover") | |
36 | (else #f))) | |
37 | ||
38 | (define (ardupilot-type->waf-cmd type) | |
39 | (symbol->string type)) | |
40 | ||
41 | (define* (make-ardupilot-firmware #:key name version base32 type board target) | |
42 | (package | |
43 | (name (string-append name "-" board)) | |
44 | (version version) | |
45 | (source | |
46 | (origin | |
47 | (method git-fetch) | |
48 | (uri (git-reference | |
49 | (url "https://github.com/ArduPilot/ardupilot") | |
50 | (commit (string-append | |
51 | (ardupilot-type->tag type) "-" version)) | |
52 | ;; XXX: Ardupilot includes several git submodules. They should be | |
53 | ;; avoided but as this is not supported upstream, and not trivial | |
54 | ;; to fix, keep it this way for now. | |
55 | (recursive? #t))) | |
56 | (file-name (git-file-name name version)) | |
57 | (sha256 base32))) | |
58 | ||
59 | ;; Could also be waf-build-system but every phase has to be rewritten | |
60 | ;; anyway. | |
61 | (build-system gnu-build-system) | |
62 | (arguments | |
63 | `(#:imported-modules ((gnu build cross-toolchain) | |
64 | ,@%gnu-build-system-modules) | |
65 | #:phases | |
66 | (modify-phases %standard-phases | |
67 | (delete 'bootstrap) | |
68 | ||
69 | ;; Remove the root waf script that relies on waf git submodule. | |
70 | (add-before 'configure 'setup-waf | |
71 | (lambda* (#:key native-inputs inputs #:allow-other-keys) | |
72 | (let ((waf (assoc-ref (or native-inputs inputs) "waf"))) | |
73 | (delete-file "waf") | |
74 | (copy-file (string-append waf "/bin/waf") "waf")) | |
75 | #t)) | |
76 | ||
77 | ;; When cross-compiling, we do not want to use the default gnu | |
78 | ;; cross-compiler, so set CROSS_CPATH and CROSS_LIBRARY_PATH | |
79 | ;; variables ourselves instead. | |
80 | (delete 'set-cross-path) | |
81 | (add-before 'configure 'set-custom-cross-cpath | |
82 | (lambda* (#:key native-inputs inputs #:allow-other-keys) | |
83 | ((@@ (gnu build cross-toolchain) set-cross-path) | |
84 | #:inputs | |
85 | `(("libc" . ,(assoc-ref (or native-inputs inputs) | |
86 | "ardupilot-cross-libc")) | |
87 | ("xkernel-headers" . | |
88 | ,(assoc-ref (or native-inputs inputs) | |
89 | "ardupilot-cross-kernel-headers")))) | |
90 | ;; We need to produce a static binary, so that it can works on | |
91 | ;; other systems than Guix System. Add a static version of the | |
92 | ;; cross libc to CROSS_LIBRARY_PATH variable. | |
93 | (setenv "CROSS_LIBRARY_PATH" | |
94 | (string-append | |
95 | (getenv "CROSS_LIBRARY_PATH") ":" | |
96 | (assoc-ref (or native-inputs inputs) | |
97 | "ardupilot-cross-libc-static") "/lib")) | |
98 | #t)) | |
99 | ||
100 | ;; Remove dependencies to 'git'. | |
101 | (add-before 'configure 'remove-git | |
102 | (lambda* (#:key inputs #:allow-other-keys) | |
103 | (substitute* "wscript" | |
104 | (("^.*cfg\\.load\\('git_submodule.*$") | |
105 | "")) | |
106 | (substitute* "Tools/ardupilotwaf/boards.py" | |
107 | (("^.*GIT_VERSION.*$") | |
108 | "")) | |
109 | #t)) | |
110 | ||
111 | ;; Configure for the given BOARD, and force a static build for | |
112 | ;; reasons exposed above. | |
113 | (replace 'configure | |
114 | (lambda* (#:key outputs #:allow-other-keys) | |
115 | (invoke "./waf" "configure" "--board" ,board "--static") | |
116 | #t)) | |
117 | ||
118 | (replace 'build | |
119 | (lambda* (#:key outputs #:allow-other-keys) | |
120 | (invoke "./waf" ,(ardupilot-type->waf-cmd type)) | |
121 | #t)) | |
122 | ||
123 | ;; Do not run tests as we are always cross-compiling. | |
124 | (delete 'check) | |
125 | ||
126 | ;; Install the produced firmware. | |
127 | (replace 'install | |
128 | (lambda* (#:key outputs #:allow-other-keys) | |
129 | (let* ((out (assoc-ref outputs "out")) | |
130 | (bin (string-append out "/bin"))) | |
131 | (mkdir-p bin) | |
132 | (copy-recursively | |
133 | (string-append "build/" ,board "/bin") bin)) | |
134 | #t))))) | |
135 | (native-inputs | |
136 | `(("waf" ,python-waf) | |
137 | ("python" ,python) | |
138 | ("python-future" ,python-future) | |
139 | ("python-lxml" ,python-lxml) | |
140 | ||
141 | ;; Packages needed for cross-compiling the firmware. | |
142 | ("ardupilot-cross-gcc" ,(cross-gcc target | |
143 | #:xbinutils | |
144 | (cross-binutils target) | |
145 | #:libc | |
146 | (cross-libc target))) | |
147 | ("ardupilot-cross-libc" ,(cross-libc target)) | |
148 | ("ardupilot-cross-libc-static" ,(cross-libc target) "static") | |
149 | ("ardupilot-cross-kernel-headers" | |
150 | ,@(assoc-ref (package-propagated-inputs | |
151 | (cross-libc target)) | |
152 | "kernel-headers")) | |
153 | ("ardupilot-cross-binutils" ,(cross-binutils target)) | |
154 | ("ardupilot-cross-pkg-config" ,(parameterize ((%current-target-system | |
155 | target)) | |
156 | pkg-config)))) | |
157 | (home-page "https://ardupilot.org/") | |
158 | (synopsis "Unmanned vehicle autopilot software suite") | |
159 | (description "@code{ardupilot} is an unmanned vehicle autopilot software | |
160 | suite capable of controlling autonomous: | |
161 | @itemize | |
162 | @item multirotor drones | |
163 | @item fixed-wing and vtol aircraft | |
164 | @item helicopters | |
165 | @item ground rovers | |
166 | @item boats | |
167 | @item submarines | |
168 | @item antenna trackers | |
169 | @end itemize") | |
170 | (license gpl3+))) | |
171 | ||
172 | (define (make-arducopter-firmware board target) | |
173 | (make-ardupilot-firmware | |
174 | #:name "arducopter" | |
175 | #:version "3.6.11" | |
176 | #:base32 (base32 "1zkr2nhkksmrriirs2dnp8a0gcf9rfqw1x86pzhh6w4ciqwpidqn") | |
177 | #:type 'copter | |
178 | #:board board | |
179 | #:target target)) | |
180 | ||
181 | (define (make-arduplane-firmware board target) | |
182 | (make-ardupilot-firmware | |
183 | #:name "arduplane" | |
184 | #:version "4.0.1" | |
185 | #:base32 (base32 "0awafvrppg4ilwpbhw88r5xkbgqrmqypsn6lbzyi6bz0zy5cfhb5") | |
186 | #:type 'plane | |
187 | #:board board | |
188 | #:target target)) | |
189 | ||
190 | (define-public arducopter-bbbmini | |
191 | (make-arducopter-firmware "bbbmini" "arm-linux-gnueabihf")) | |
192 | ||
193 | (define-public arduplane-bbbmini | |
194 | (make-arduplane-firmware "bbbmini" "arm-linux-gnueabihf")) | |
195 | ||
196 | ;; Firmware for Bebop and Bebop2 drones. | |
197 | (define-public arducopter-bebop | |
198 | (make-arducopter-firmware "bebop" "arm-linux-gnueabihf")) |