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>
10 ;;; This file is part of GNU Guix.
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.
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.
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/>.
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 python)
31 #:use-module (guix build-system trivial)
32 #:use-module ((guix licenses) #:prefix license:)
33 #:use-module (gnu packages)
34 #:use-module (gnu packages check)
35 #:use-module (gnu packages gnupg)
36 #:use-module (gnu packages python)
37 #:use-module (gnu packages ssh)
38 #:use-module (gnu packages version-control)
39 #:use-module (gnu packages tls)
40 #:use-module (gnu packages linux))
42 ;; The Makefiles that we add are largely based on the Debian
43 ;; packages. They are licensed under GPL-2 and have copyright:
44 ;; 2012, Stefan Handschuh <handschuh.stefan@googlemail.com>
45 ;; 2015, Kai-Chung Yan <seamlikok@gmail.com>
46 ;; Big thanks to them for laying the groundwork.
48 ;; The version tag is consistent between all repositories.
49 (define (android-platform-version) "7.1.2_r6")
51 (define (android-platform-system-core version)
55 (url "https://android.googlesource.com/platform/system/core")
56 (commit (string-append "android-" version))))
57 (file-name (string-append "android-platform-system-core-"
61 "0xc2n7jxrf1iw9cc278pijdfjix2fkiig5ws27f6rwp40zg5mrgg"))))
66 (version (android-platform-version))
67 (source (android-platform-system-core version))
68 (build-system gnu-build-system)
71 #:make-flags '("CC=gcc")
73 (modify-phases %standard-phases
74 (add-after 'unpack 'enter-source
75 (lambda _ (chdir "liblog") #t))
76 (add-after 'enter-source 'create-Makefile
78 ;; No useful makefile is shipped, so we create one.
79 (with-output-to-file "Makefile"
84 "SOURCES = log_event_list.c log_event_write.c"
85 " logger_write.c config_write.c logger_name.c"
86 " logger_lock.c fake_log_device.c fake_writer.c"
89 "CFLAGS += -fvisibility=hidden -fPIC\n"
90 "CPPFLAGS += -I../include -DFAKE_LOG_DEVICE=1"
91 ;; Keep these two in sync with "liblog/Android.bp".
92 " -DLIBLOG_LOG_TAG=1005"
93 " -DSNET_EVENT_LOG_TAG=1397638484\n"
94 "LDFLAGS += -shared -Wl,-soname,$(NAME).so.0 -lpthread\n"
97 " $(CC) $^ -o $(NAME).so.0 $(CFLAGS) $(CPPFLAGS) $(LDFLAGS)\n"))
101 (lambda* (#:key outputs #:allow-other-keys)
102 (let* ((out (assoc-ref outputs "out"))
103 (lib (string-append out "/lib")))
104 (install-file "liblog.so.0" lib)
105 (with-directory-excursion lib
106 (symlink "liblog.so.0" "liblog.so"))
108 (home-page "https://developer.android.com/")
109 (synopsis "Logging library from the Android platform.")
110 (description "@code{liblog} represents an interface to the volatile Android
111 Logging system for NDK (Native) applications and libraries and contain
112 interfaces for either writing or reading logs. The log buffers are divided up
113 in Main, System, Radio and Events sub-logs.")
114 (license license:asl2.0)))
119 (version (android-platform-version))
121 (inherit (android-platform-system-core version))
123 (search-patches "libbase-use-own-logging.patch"
124 "libbase-fix-includes.patch"))))
125 (build-system gnu-build-system)
127 `(#:tests? #f ; TODO.
129 (modify-phases %standard-phases
130 (add-after 'unpack 'enter-source
131 (lambda _ (chdir "base") #t))
132 (add-after 'enter-source 'create-Makefile
134 ;; No useful makefile is shipped, so we create one.
135 (with-output-to-file "Makefile"
140 "SOURCES = file.cpp logging.cpp parsenetaddress.cpp"
141 " stringprintf.cpp strings.cpp errors_unix.cpp\n"
143 "CXXFLAGS += -std=gnu++11 -fPIC\n"
144 "CPPFLAGS += -Iinclude -I../include\n"
145 "LDFLAGS += -shared -Wl,-soname,$(NAME).so.0"
148 "build: $(SOURCES)\n"
149 " $(CXX) $^ -o $(NAME).so.0 $(CXXFLAGS) $(CPPFLAGS)"
154 (lambda* (#:key outputs #:allow-other-keys)
155 (let* ((out (assoc-ref outputs "out"))
156 (lib (string-append out "/lib")))
157 (install-file "libbase.so.0" lib)
158 (with-directory-excursion lib
159 (symlink "libbase.so.0" "libbase.so"))
160 (copy-recursively "include" out)
162 (inputs `(("liblog" ,liblog)))
163 (home-page "https://developer.android.com/")
164 (synopsis "Android platform base library")
165 (description "@code{libbase} is a library in common use by the
166 various Android core host applications.")
167 (license license:asl2.0)))
172 (version (android-platform-version))
173 (source (android-platform-system-core version))
174 (build-system gnu-build-system)
176 `(#:tests? #f ; TODO.
178 (modify-phases %standard-phases
179 (add-after 'unpack 'enter-source
180 (lambda _ (chdir "libcutils") #t))
181 (add-after 'enter-source 'create-Makefile
183 ;; No useful makefile is shipped, so we create one.
184 (with-output-to-file "Makefile"
189 "SOURCES = load_file.o socket_local_client_unix.o"
190 " socket_loopback_client_unix.o socket_network_client_unix.o"
191 " socket_loopback_server_unix.o socket_local_server_unix.o"
192 " sockets_unix.o socket_inaddr_any_server_unix.o"
197 "CXXFLAGS += -std=gnu++11 -fPIC\n"
198 "CPPFLAGS += -Iinclude -I../include\n"
199 "LDFLAGS += -shared -Wl,-soname,$(NAME).so.0\n"
201 "build: $(SOURCES)\n"
202 " $(CXX) $^ -o $(NAME).so.0 $(CXXFLAGS) $(CPPFLAGS)"
207 (lambda* (#:key outputs #:allow-other-keys)
208 (let* ((out (assoc-ref outputs "out"))
209 (lib (string-append out "/lib")))
210 (install-file "libcutils.so.0" lib)
211 (with-directory-excursion lib
212 (symlink "libcutils.so.0" "libcutils.so"))
214 (home-page "https://developer.android.com/")
215 (synopsis "Android platform c utils library")
216 (description "@code{libcutils} is a library in common use by the
217 various Android core host applications.")
218 (license license:asl2.0)))
223 (version (android-platform-version))
225 (inherit (android-platform-system-core version))
227 (search-patches "libbase-use-own-logging.patch"
228 "libbase-fix-includes.patch"))))
229 (build-system gnu-build-system)
232 (modify-phases %standard-phases
233 (add-after 'unpack 'enter-source
234 (lambda _ (chdir "adb") #t))
235 (add-before 'build 'fix-clang
237 ;; adb_client.h contains _Nonnull and _Nullable attributes, that
238 ;; are not understood by gcc.
239 (substitute* "adb_client.h"
243 (add-before 'build 'fix-main
245 ;; main.cpp used to be adb_main.cpp in the current directory
246 ;; rather than in its own subdirectory, but it was not fixed.
247 ;; This leads to some header files not being found anymore.
248 (copy-file "client/main.cpp" "adb_main.cpp")
250 (add-after 'enter-source 'create-Makefile
251 (lambda* (#:key outputs #:allow-other-keys)
252 ;; No useful makefile is shipped, so we create one.
253 (with-output-to-file "Makefile"
257 ;; Common for all components.
258 "CXXFLAGS += -std=gnu++14 -fpermissive\n"
259 "CPPFLAGS += -I../include -I../base/include -I. -DADB_HOST=1 "
260 "-DADB_REVISION='\"" ,version "\"' -fPIC\n"
261 "LDFLAGS += -lcrypto -lpthread -lbase -lcutils -L. -ladb\n"
264 "LIBADB_SOURCES = adb.cpp adb_auth.cpp adb_io.cpp "
265 "adb_listeners.cpp adb_trace.cpp adb_utils.cpp fdevent.cpp "
266 "sockets.cpp transport.cpp transport_local.cpp transport_usb.cpp "
267 "get_my_path_linux.cpp sysdeps_unix.cpp usb_linux.cpp "
268 "adb_auth_host.cpp diagnose_usb.cpp services.cpp "
269 "shell_service_protocol.cpp bugreport.cpp line_printer.cpp\n"
271 "LIBADB_LDFLAGS += -shared -Wl,-soname,libadb.so.0 "
272 "-lcrypto -lpthread -lbase\n"
275 "ADB_SOURCES = adb_main.cpp console.cpp commandline.cpp "
276 "adb_client.cpp file_sync_client.cpp\n"
277 "ADB_LDFLAGS += -Wl,-rpath=" (assoc-ref outputs "out") "/lib\n"
279 "build: libadb $(ADB_SOURCES)\n"
280 " $(CXX) $(ADB_SOURCES) -o adb $(CXXFLAGS) $(CPPFLAGS) "
281 "$(ADB_LDFLAGS) $(LDFLAGS)\n"
283 "libadb: $(LIBADB_SOURCES)\n"
284 " $(CXX) $^ -o libadb.so.0 $(CXXFLAGS) $(CPPFLAGS) "
285 "$(LIBADB_LDFLAGS)\n"
286 " ln -sv libadb.so.0 libadb.so\n"))
290 (lambda* (#:key outputs #:allow-other-keys)
291 (let* ((out (assoc-ref outputs "out"))
292 (lib (string-append out "/lib"))
293 (bin (string-append out "/bin")))
294 (install-file "libadb.so.0" lib)
295 (install-file "adb" bin)
296 (with-directory-excursion lib
297 (symlink "libadb.so.0" "libadb.so"))
299 ;; Test suite must be run with attached devices
302 `(("libbase" ,libbase)
303 ("libcutils" ,libcutils)
304 ("openssl" ,openssl)))
305 (home-page "https://developer.android.com/studio/command-line/adb.html")
306 (synopsis "Android Debug Bridge")
308 "@command{adb} is a versatile command line tool that lets you communicate
309 with an emulator instance or connected Android device. It facilitates a variety
310 of device actions, such as installing and debugging apps, and it provides access
311 to a Unix shell that can run commands on the connected device or emulator.")
312 (license license:asl2.0)))
314 (define-public mkbootimg
317 (version (android-platform-version))
319 (inherit (android-platform-system-core version))))
320 (build-system python-build-system)
324 (modify-phases %standard-phases
325 (add-after 'unpack 'enter-source
326 (lambda _ (chdir "mkbootimg") #t))
330 (lambda* (#:key outputs #:allow-other-keys)
331 (let* ((out (assoc-ref outputs "out"))
332 (bin (string-append out "/bin")))
333 (install-file "mkbootimg" bin)
335 (home-page "https://developer.android.com/studio/command-line/adb.html")
336 (synopsis "Tool to create Android boot images")
337 (description "This package provides a tool to create Android Boot
339 (license license:asl2.0)))
341 (define-public android-udev-rules
343 (name "android-udev-rules")
349 (url "https://github.com/M0Rf30/android-udev-rules")
351 (file-name (string-append name "-" version "-checkout"))
353 (base32 "11gcnk6wjc2sw05hwi4xphvx9ksmkpvsdziaczymqxkaads3f1dy"))))
354 (build-system trivial-build-system)
355 (native-inputs `(("source" ,source)))
357 '(#:modules ((guix build utils))
360 (use-modules (guix build utils))
361 (let ((source (assoc-ref %build-inputs "source")))
362 (install-file (string-append source "/51-android.rules")
363 (string-append %output "/lib/udev/rules.d"))))))
364 (home-page "https://github.com/M0Rf30/android-udev-rules")
365 (synopsis "udev rules for Android devices")
366 (description "Provides a set of udev rules to allow using Android devices
367 with tools such as @command{adb} and @command{fastboot} without root
368 privileges. This package is intended to be added as a rule to the
369 @code{udev-service-type} in your @code{operating-system} configuration.
370 Additionally, an @code{adbusers} group must be defined and your user added to
373 @emph{Simply installing this package will not have any effect.} It is meant
374 to be passed to the @code{udev} service.")
375 (license license:gpl3+)))
377 (define-public git-repo
385 (url "https://gerrit.googlesource.com/git-repo")
386 (commit (string-append "v" version))))
387 (file-name (string-append "git-repo-" version "-checkout"))
389 (base32 "0qp7jqhblv7xblfgpcq4n18dyjdv8shz7r60c3vnjxx2fngkj2jd"))))
390 (build-system python-build-system)
392 `(#:python ,python-2 ; code says: "Python 3 support is … experimental."
394 (modify-phases %standard-phases
395 (add-before 'build 'set-executable-paths
396 (lambda* (#:key inputs outputs #:allow-other-keys)
397 (let* ((out (assoc-ref outputs "out"))
398 (git (assoc-ref inputs "git"))
399 (gpg (assoc-ref inputs "gnupg"))
400 (ssh (assoc-ref inputs "ssh")))
401 (substitute* '("repo" "git_command.py")
403 (string-append "GIT = '" git "/bin/git' ")))
405 ((" cmd = \\['gpg',")
406 (string-append " cmd = ['" gpg "/bin/gpg',")))
407 (substitute* "git_config.py"
408 ((" command_base = \\['ssh',")
409 (string-append " command_base = ['" ssh "/bin/ssh',")))
411 (add-before 'build 'do-not-clone-this-source
412 (lambda* (#:key outputs #:allow-other-keys)
413 (let* ((out (assoc-ref outputs "out"))
414 (repo-dir (string-append out "/share/" ,name)))
416 (("^def _FindRepo\\(\\):.*")
419 '''Look for a repo installation, starting at the current directory.'''
420 # Use the installed version of git-repo.
421 repo_main = '~a/main.py'
424 while curdir != '/' and curdir != olddir:
425 dot_repo = os.path.join(curdir, repodir)
426 if os.path.isdir(dot_repo):
427 return (repo_main, dot_repo)
430 curdir = os.path.dirname(curdir)
433 # The remaining of this function is dead code. It was used to
434 # find a git-checked-out version in the local project.\n" repo-dir))
435 ;; Neither clone, check out, nor verify the git repository
436 (("(^\\s+)_Clone\\(.*\\)") "")
437 (("(^\\s+)_Checkout\\(.*\\)") "")
438 ((" rev = _Verify\\(.*\\)") " rev = None"))
440 (delete 'build) ; nothing to build
443 (zero? (system* "python" "-m" "nose"))))
445 (lambda* (#:key outputs #:allow-other-keys)
446 (let* ((out (assoc-ref outputs "out"))
447 (bin-dir (string-append out "/bin"))
448 (repo-dir (string-append out "/share/" ,name)))
451 (copy-recursively "." repo-dir)
452 (delete-file-recursively (string-append repo-dir "/tests"))
453 (symlink (string-append repo-dir "/repo")
454 (string-append bin-dir "/repo"))
457 ;; TODO: Add git-remote-persistent-https once it is available in guix
462 `(("nose" ,python2-nose)))
463 (home-page "https://code.google.com/p/git-repo/")
464 (synopsis "Helps to manage many Git repositories.")
465 (description "Repo is a tool built on top of Git. Repo helps manage many
466 Git repositories, does the uploads to revision control systems, and automates
467 parts of the development workflow. Repo is not meant to replace Git, only to
468 make it easier to work with Git. The repo command is an executable Python
469 script that you can put anywhere in your path.")
470 (license license:asl2.0)))
472 (define-public abootimg
479 (uri (string-append "http://http.debian.net/debian/pool/main/a/abootimg/"
480 "abootimg_" version ".orig.tar.gz"))
482 (base32 "0sfc2k011l1ymv97821w89391gnqdh8pp0haz4sdcm5hx0axv2ba"))))
483 (build-system gnu-build-system)
487 (modify-phases %standard-phases
493 (lambda* (#:key outputs #:allow-other-keys)
494 (let* ((out (assoc-ref outputs "out"))
495 (bin (string-append out "/bin")))
496 (install-file "abootimg" bin)
499 `(("libblkid" ,util-linux)))
500 (home-page "https://ac100.grandou.net/abootimg")
501 (synopsis "Tool for manipulating Android Boot Images")
502 (description "This package provides a tool for manipulating old Android
503 Boot Images. @code{abootimg} can work directly on block devices, or, the
504 safest way, on a file image.")
505 (license license:gpl2+)))