gnu: libbase: Use android-ndk-build-system.
[jackhill/guix/guix.git] / gnu / packages / android.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012 Stefan Handschuh <handschuh.stefan@googlemail.com>
3 ;;; Copyright © 2015 Kai-Chung Yan <seamlikok@gmail.com>
4 ;;; Copyright © 2016 Marius Bakke <mbakke@fastmail.com>
5 ;;; Copyright © 2017 Julien Lepiller <julien@lepiller.eu>
6 ;;; Copyright © 2017 Hartmut Goebel <h.goebel@crazy-compilers.com>
7 ;;; Copyright © 2017 Maxim Cournoyer <maxim.cournoyer@gmail.com>
8 ;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
9 ;;;
10 ;;; This file is part of GNU Guix.
11 ;;;
12 ;;; GNU Guix is free software; you can redistribute it and/or modify it
13 ;;; under the terms of the GNU General Public License as published by
14 ;;; the Free Software Foundation; either version 3 of the License, or (at
15 ;;; your option) any later version.
16 ;;;
17 ;;; GNU Guix is distributed in the hope that it will be useful, but
18 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;;; GNU General Public License for more details.
21 ;;;
22 ;;; You should have received a copy of the GNU General Public License
23 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
24
25 (define-module (gnu packages android)
26 #:use-module (guix packages)
27 #:use-module (guix download)
28 #:use-module (guix git-download)
29 #:use-module (guix build-system gnu)
30 #:use-module (guix build-system android-ndk)
31 #:use-module (guix build-system python)
32 #:use-module (guix build-system trivial)
33 #:use-module ((guix licenses) #:prefix license:)
34 #:use-module (gnu packages)
35 #:use-module (gnu packages check)
36 #:use-module (gnu packages gnupg)
37 #:use-module (gnu packages python)
38 #:use-module (gnu packages ssh)
39 #:use-module (gnu packages version-control)
40 #:use-module (gnu packages tls)
41 #:use-module (gnu packages linux))
42
43 (define-public android-make-stub
44 (let ((commit "v0.1")
45 (revision "21"))
46 (package
47 (name "android-make-stub")
48 (version "0.1")
49 (source
50 (origin
51 (method git-fetch)
52 (uri (git-reference
53 (url "https://github.com/daym/android-make-stub.git")
54 (commit commit)))
55 (file-name (string-append "android-make-stub-"
56 version "-checkout"))
57 (sha256
58 (base32
59 "1ni4szpcx2clf3lpzrybabwk7bgvsl6ynng7xxfc49y4jkdkk4sh"))))
60 (build-system gnu-build-system)
61 (arguments
62 `(#:tests? #f ; None exist.
63 #:phases
64 (modify-phases %standard-phases
65 (delete 'configure)
66 (delete 'build)
67 (replace 'install
68 (lambda* (#:key outputs #:allow-other-keys)
69 (let* ((out (assoc-ref outputs "out")))
70 (invoke "make" (string-append "prefix=" out) "install")
71 #t))))))
72 (home-page "https://github.com/daym/android-make-stub")
73 (synopsis "Stubs for the @command{make} system of the Android platform")
74 (description "@code{android-make-stub} provides stubs for the
75 @command{make} system of the Android platform. This allows us to
76 use their packages mostly unmodified in our Android NDK build system.")
77 (license license:asl2.0))))
78
79 ;; The Makefiles that we add are largely based on the Debian
80 ;; packages. They are licensed under GPL-2 and have copyright:
81 ;; 2012, Stefan Handschuh <handschuh.stefan@googlemail.com>
82 ;; 2015, Kai-Chung Yan <seamlikok@gmail.com>
83 ;; Big thanks to them for laying the groundwork.
84
85 ;; The version tag is consistent between all repositories.
86 (define (android-platform-version) "7.1.2_r6")
87
88 (define (android-platform-system-core version)
89 (origin
90 (method git-fetch)
91 (uri (git-reference
92 (url "https://android.googlesource.com/platform/system/core")
93 (commit (string-append "android-" version))))
94 (file-name (string-append "android-platform-system-core-"
95 version "-checkout"))
96 (sha256
97 (base32
98 "0xc2n7jxrf1iw9cc278pijdfjix2fkiig5ws27f6rwp40zg5mrgg"))))
99
100 (define liblog
101 (package
102 (name "liblog")
103 (version (android-platform-version))
104 (source (android-platform-system-core version))
105 (build-system android-ndk-build-system)
106 (arguments
107 `(#:tests? #f ; TODO.
108 #:make-flags '("CC=gcc")
109 #:phases
110 (modify-phases %standard-phases
111 (add-after 'unpack 'enter-source
112 (lambda _ (chdir "liblog") #t)))))
113 (home-page "https://developer.android.com/")
114 (synopsis "Logging library from the Android platform.")
115 (description "@code{liblog} represents an interface to the volatile Android
116 Logging system for NDK (Native) applications and libraries and contain
117 interfaces for either writing or reading logs. The log buffers are divided up
118 in Main, System, Radio and Events sub-logs.")
119 (license license:asl2.0)))
120
121 (define libbase
122 (package
123 (name "libbase")
124 (version (android-platform-version))
125 (source (origin
126 (inherit (android-platform-system-core version))
127 (patches
128 (search-patches "libbase-use-own-logging.patch"
129 "libbase-fix-includes.patch"))))
130 (build-system android-ndk-build-system)
131 (arguments
132 `(#:tests? #f ; TODO.
133 #:make-flags '("CXXFLAGS=-std=gnu++11")
134 #:phases
135 (modify-phases %standard-phases
136 (add-after 'unpack 'enter-source
137 (lambda _ (chdir "base") #t)))))
138 (inputs `(("liblog" ,liblog)))
139 (home-page "https://developer.android.com/")
140 (synopsis "Android platform base library")
141 (description "@code{libbase} is a library in common use by the
142 various Android core host applications.")
143 (license license:asl2.0)))
144
145 (define libcutils
146 (package
147 (name "libcutils")
148 (version (android-platform-version))
149 (source (android-platform-system-core version))
150 (build-system gnu-build-system)
151 (arguments
152 `(#:tests? #f ; TODO.
153 #:phases
154 (modify-phases %standard-phases
155 (add-after 'unpack 'enter-source
156 (lambda _ (chdir "libcutils") #t))
157 (add-after 'enter-source 'create-Makefile
158 (lambda _
159 ;; No useful makefile is shipped, so we create one.
160 (with-output-to-file "Makefile"
161 (lambda _
162 (display
163 (string-append
164 "NAME = libcutils\n"
165 "SOURCES = load_file.o socket_local_client_unix.o"
166 " socket_loopback_client_unix.o socket_network_client_unix.o"
167 " socket_loopback_server_unix.o socket_local_server_unix.o"
168 " sockets_unix.o socket_inaddr_any_server_unix.o"
169 " sockets.o\n"
170 "CC = gcc\n"
171
172 "CFLAGS += -fPIC\n"
173 "CXXFLAGS += -std=gnu++11 -fPIC\n"
174 "CPPFLAGS += -Iinclude -I../include\n"
175 "LDFLAGS += -shared -Wl,-soname,$(NAME).so.0\n"
176
177 "build: $(SOURCES)\n"
178 " $(CXX) $^ -o $(NAME).so.0 $(CXXFLAGS) $(CPPFLAGS)"
179 " $(LDFLAGS)\n"))
180 #t))))
181 (delete 'configure)
182 (replace 'install
183 (lambda* (#:key outputs #:allow-other-keys)
184 (let* ((out (assoc-ref outputs "out"))
185 (lib (string-append out "/lib")))
186 (install-file "libcutils.so.0" lib)
187 (with-directory-excursion lib
188 (symlink "libcutils.so.0" "libcutils.so"))
189 #t))))))
190 (home-page "https://developer.android.com/")
191 (synopsis "Android platform c utils library")
192 (description "@code{libcutils} is a library in common use by the
193 various Android core host applications.")
194 (license license:asl2.0)))
195
196 (define-public adb
197 (package
198 (name "adb")
199 (version (android-platform-version))
200 (source (origin
201 (inherit (android-platform-system-core version))
202 (patches
203 (search-patches "libbase-use-own-logging.patch"
204 "libbase-fix-includes.patch"))))
205 (build-system gnu-build-system)
206 (arguments
207 `(#:phases
208 (modify-phases %standard-phases
209 (add-after 'unpack 'enter-source
210 (lambda _ (chdir "adb") #t))
211 (add-before 'build 'fix-clang
212 (lambda _
213 ;; adb_client.h contains _Nonnull and _Nullable attributes, that
214 ;; are not understood by gcc.
215 (substitute* "adb_client.h"
216 (("_Nonnull") "")
217 (("_Nullable") ""))
218 #t))
219 (add-before 'build 'fix-main
220 (lambda _
221 ;; main.cpp used to be adb_main.cpp in the current directory
222 ;; rather than in its own subdirectory, but it was not fixed.
223 ;; This leads to some header files not being found anymore.
224 (copy-file "client/main.cpp" "adb_main.cpp")
225 #t))
226 (add-after 'enter-source 'create-Makefile
227 (lambda* (#:key outputs #:allow-other-keys)
228 ;; No useful makefile is shipped, so we create one.
229 (with-output-to-file "Makefile"
230 (lambda _
231 (display
232 (string-append
233 ;; Common for all components.
234 "CXXFLAGS += -std=gnu++14 -fpermissive\n"
235 "CPPFLAGS += -I../include -I../base/include -I. -DADB_HOST=1 "
236 "-DADB_REVISION='\"" ,version "\"' -fPIC\n"
237 "LDFLAGS += -lcrypto -lpthread -lbase -lcutils -L. -ladb\n"
238
239 ;; Libadb specifics.
240 "LIBADB_SOURCES = adb.cpp adb_auth.cpp adb_io.cpp "
241 "adb_listeners.cpp adb_trace.cpp adb_utils.cpp fdevent.cpp "
242 "sockets.cpp transport.cpp transport_local.cpp transport_usb.cpp "
243 "get_my_path_linux.cpp sysdeps_unix.cpp usb_linux.cpp "
244 "adb_auth_host.cpp diagnose_usb.cpp services.cpp "
245 "shell_service_protocol.cpp bugreport.cpp line_printer.cpp\n"
246
247 "LIBADB_LDFLAGS += -shared -Wl,-soname,libadb.so.0 "
248 "-lcrypto -lpthread -lbase\n"
249
250 ;; Adb specifics.
251 "ADB_SOURCES = adb_main.cpp console.cpp commandline.cpp "
252 "adb_client.cpp file_sync_client.cpp\n"
253 "ADB_LDFLAGS += -Wl,-rpath=" (assoc-ref outputs "out") "/lib\n"
254
255 "build: libadb $(ADB_SOURCES)\n"
256 " $(CXX) $(ADB_SOURCES) -o adb $(CXXFLAGS) $(CPPFLAGS) "
257 "$(ADB_LDFLAGS) $(LDFLAGS)\n"
258
259 "libadb: $(LIBADB_SOURCES)\n"
260 " $(CXX) $^ -o libadb.so.0 $(CXXFLAGS) $(CPPFLAGS) "
261 "$(LIBADB_LDFLAGS)\n"
262 " ln -sv libadb.so.0 libadb.so\n"))
263 #t))))
264 (delete 'configure)
265 (replace 'install
266 (lambda* (#:key outputs #:allow-other-keys)
267 (let* ((out (assoc-ref outputs "out"))
268 (lib (string-append out "/lib"))
269 (bin (string-append out "/bin")))
270 (install-file "libadb.so.0" lib)
271 (install-file "adb" bin)
272 (with-directory-excursion lib
273 (symlink "libadb.so.0" "libadb.so"))
274 #t))))
275 ;; Test suite must be run with attached devices
276 #:tests? #f))
277 (inputs
278 `(("libbase" ,libbase)
279 ("libcutils" ,libcutils)
280 ("openssl" ,openssl)))
281 (home-page "https://developer.android.com/studio/command-line/adb.html")
282 (synopsis "Android Debug Bridge")
283 (description
284 "@command{adb} is a versatile command line tool that lets you communicate
285 with an emulator instance or connected Android device. It facilitates a variety
286 of device actions, such as installing and debugging apps, and it provides access
287 to a Unix shell that can run commands on the connected device or emulator.")
288 (license license:asl2.0)))
289
290 (define-public mkbootimg
291 (package
292 (name "mkbootimg")
293 (version (android-platform-version))
294 (source (origin
295 (inherit (android-platform-system-core version))))
296 (build-system python-build-system)
297 (arguments
298 `(#:tests? #f
299 #:phases
300 (modify-phases %standard-phases
301 (add-after 'unpack 'enter-source
302 (lambda _ (chdir "mkbootimg") #t))
303 (delete 'configure)
304 (delete 'build)
305 (replace 'install
306 (lambda* (#:key outputs #:allow-other-keys)
307 (let* ((out (assoc-ref outputs "out"))
308 (bin (string-append out "/bin")))
309 (install-file "mkbootimg" bin)
310 #t))))))
311 (home-page "https://developer.android.com/studio/command-line/adb.html")
312 (synopsis "Tool to create Android boot images")
313 (description "This package provides a tool to create Android Boot
314 Images.")
315 (license license:asl2.0)))
316
317 (define-public android-udev-rules
318 (package
319 (name "android-udev-rules")
320 (version "20180112")
321 (source
322 (origin
323 (method git-fetch)
324 (uri (git-reference
325 (url "https://github.com/M0Rf30/android-udev-rules")
326 (commit version)))
327 (file-name (string-append name "-" version "-checkout"))
328 (sha256
329 (base32 "13gj79nnd04szqlrrzzkdr6wi1fky08pi7x8xfbg0jj3d3v0giah"))))
330 (build-system trivial-build-system)
331 (native-inputs `(("source" ,source)))
332 (arguments
333 '(#:modules ((guix build utils))
334 #:builder
335 (begin
336 (use-modules (guix build utils))
337 (let ((source (assoc-ref %build-inputs "source")))
338 (install-file (string-append source "/51-android.rules")
339 (string-append %output "/lib/udev/rules.d"))))))
340 (home-page "https://github.com/M0Rf30/android-udev-rules")
341 (synopsis "udev rules for Android devices")
342 (description "Provides a set of udev rules to allow using Android devices
343 with tools such as @command{adb} and @command{fastboot} without root
344 privileges. This package is intended to be added as a rule to the
345 @code{udev-service-type} in your @code{operating-system} configuration.
346 Additionally, an @code{adbusers} group must be defined and your user added to
347 it.
348
349 @emph{Simply installing this package will not have any effect.} It is meant
350 to be passed to the @code{udev} service.")
351 (license license:gpl3+)))
352
353 (define-public git-repo
354 (package
355 (name "git-repo")
356 (version "1.12.37")
357 (source
358 (origin
359 (method git-fetch)
360 (uri (git-reference
361 (url "https://gerrit.googlesource.com/git-repo")
362 (commit (string-append "v" version))))
363 (file-name (string-append "git-repo-" version "-checkout"))
364 (sha256
365 (base32 "0qp7jqhblv7xblfgpcq4n18dyjdv8shz7r60c3vnjxx2fngkj2jd"))))
366 (build-system python-build-system)
367 (arguments
368 `(#:python ,python-2 ; code says: "Python 3 support is … experimental."
369 #:phases
370 (modify-phases %standard-phases
371 (add-before 'build 'set-executable-paths
372 (lambda* (#:key inputs outputs #:allow-other-keys)
373 (let* ((out (assoc-ref outputs "out"))
374 (git (assoc-ref inputs "git"))
375 (gpg (assoc-ref inputs "gnupg"))
376 (ssh (assoc-ref inputs "ssh")))
377 (substitute* '("repo" "git_command.py")
378 (("^GIT = 'git' ")
379 (string-append "GIT = '" git "/bin/git' ")))
380 (substitute* "repo"
381 ((" cmd = \\['gpg',")
382 (string-append " cmd = ['" gpg "/bin/gpg',")))
383 (substitute* "git_config.py"
384 ((" command_base = \\['ssh',")
385 (string-append " command_base = ['" ssh "/bin/ssh',")))
386 #t)))
387 (add-before 'build 'do-not-clone-this-source
388 (lambda* (#:key outputs #:allow-other-keys)
389 (let* ((out (assoc-ref outputs "out"))
390 (repo-dir (string-append out "/share/" ,name)))
391 (substitute* "repo"
392 (("^def _FindRepo\\(\\):.*")
393 (format #f "
394 def _FindRepo():
395 '''Look for a repo installation, starting at the current directory.'''
396 # Use the installed version of git-repo.
397 repo_main = '~a/main.py'
398 curdir = os.getcwd()
399 olddir = None
400 while curdir != '/' and curdir != olddir:
401 dot_repo = os.path.join(curdir, repodir)
402 if os.path.isdir(dot_repo):
403 return (repo_main, dot_repo)
404 else:
405 olddir = curdir
406 curdir = os.path.dirname(curdir)
407 return None, ''
408
409 # The remaining of this function is dead code. It was used to
410 # find a git-checked-out version in the local project.\n" repo-dir))
411 ;; Neither clone, check out, nor verify the git repository
412 (("(^\\s+)_Clone\\(.*\\)") "")
413 (("(^\\s+)_Checkout\\(.*\\)") "")
414 ((" rev = _Verify\\(.*\\)") " rev = None"))
415 #t)))
416 (delete 'build) ; nothing to build
417 (replace 'check
418 (lambda _
419 (zero? (system* "python" "-m" "nose"))))
420 (replace 'install
421 (lambda* (#:key outputs #:allow-other-keys)
422 (let* ((out (assoc-ref outputs "out"))
423 (bin-dir (string-append out "/bin"))
424 (repo-dir (string-append out "/share/" ,name)))
425 (mkdir-p bin-dir)
426 (mkdir-p repo-dir)
427 (copy-recursively "." repo-dir)
428 (delete-file-recursively (string-append repo-dir "/tests"))
429 (symlink (string-append repo-dir "/repo")
430 (string-append bin-dir "/repo"))
431 #t))))))
432 (inputs
433 ;; TODO: Add git-remote-persistent-https once it is available in guix
434 `(("git" ,git)
435 ("gnupg" ,gnupg)
436 ("ssh" ,openssh)))
437 (native-inputs
438 `(("nose" ,python2-nose)))
439 (home-page "https://code.google.com/p/git-repo/")
440 (synopsis "Helps to manage many Git repositories.")
441 (description "Repo is a tool built on top of Git. Repo helps manage many
442 Git repositories, does the uploads to revision control systems, and automates
443 parts of the development workflow. Repo is not meant to replace Git, only to
444 make it easier to work with Git. The repo command is an executable Python
445 script that you can put anywhere in your path.")
446 (license license:asl2.0)))
447
448 (define-public abootimg
449 (package
450 (name "abootimg")
451 (version "0.6")
452 (source
453 (origin
454 (method url-fetch)
455 (uri (string-append "http://http.debian.net/debian/pool/main/a/abootimg/"
456 "abootimg_" version ".orig.tar.gz"))
457 (sha256
458 (base32 "0sfc2k011l1ymv97821w89391gnqdh8pp0haz4sdcm5hx0axv2ba"))))
459 (build-system gnu-build-system)
460 (arguments
461 `(#:tests? #f
462 #:phases
463 (modify-phases %standard-phases
464 (replace 'configure
465 (lambda _
466 (setenv "CC" "gcc")
467 #t))
468 (replace 'install
469 (lambda* (#:key outputs #:allow-other-keys)
470 (let* ((out (assoc-ref outputs "out"))
471 (bin (string-append out "/bin")))
472 (install-file "abootimg" bin)
473 #t))))))
474 (inputs
475 `(("libblkid" ,util-linux)))
476 (home-page "https://ac100.grandou.net/abootimg")
477 (synopsis "Tool for manipulating Android Boot Images")
478 (description "This package provides a tool for manipulating old Android
479 Boot Images. @code{abootimg} can work directly on block devices, or, the
480 safest way, on a file image.")
481 (license license:gpl2+)))