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 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))
43 (define-public android-make-stub
47 (name "android-make-stub")
53 (url "https://github.com/daym/android-make-stub.git")
55 (file-name (string-append "android-make-stub-"
59 "1ni4szpcx2clf3lpzrybabwk7bgvsl6ynng7xxfc49y4jkdkk4sh"))))
60 (build-system gnu-build-system)
62 `(#:tests? #f ; None exist.
64 (modify-phases %standard-phases
68 (lambda* (#:key outputs #:allow-other-keys)
69 (let* ((out (assoc-ref outputs "out")))
70 (invoke "make" (string-append "prefix=" out) "install")
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))))
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.
85 ;; The version tag is consistent between all repositories.
86 (define (android-platform-version) "7.1.2_r6")
88 (define (android-platform-system-core version)
92 (url "https://android.googlesource.com/platform/system/core")
93 (commit (string-append "android-" version))))
94 (file-name (string-append "android-platform-system-core-"
98 "0xc2n7jxrf1iw9cc278pijdfjix2fkiig5ws27f6rwp40zg5mrgg"))))
103 (version (android-platform-version))
104 (source (android-platform-system-core version))
105 (build-system android-ndk-build-system)
107 `(#:tests? #f ; TODO.
108 #:make-flags '("CC=gcc")
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)))
124 (version (android-platform-version))
126 (inherit (android-platform-system-core version))
128 (search-patches "libbase-use-own-logging.patch"
129 "libbase-fix-includes.patch"))))
130 (build-system android-ndk-build-system)
132 `(#:tests? #f ; TODO.
133 #:make-flags '("CXXFLAGS=-std=gnu++11")
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)))
148 (version (android-platform-version))
149 (source (android-platform-system-core version))
150 (build-system gnu-build-system)
152 `(#:tests? #f ; TODO.
154 (modify-phases %standard-phases
155 (add-after 'unpack 'enter-source
156 (lambda _ (chdir "libcutils") #t))
157 (add-after 'enter-source 'create-Makefile
159 ;; No useful makefile is shipped, so we create one.
160 (with-output-to-file "Makefile"
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"
173 "CXXFLAGS += -std=gnu++11 -fPIC\n"
174 "CPPFLAGS += -Iinclude -I../include\n"
175 "LDFLAGS += -shared -Wl,-soname,$(NAME).so.0\n"
177 "build: $(SOURCES)\n"
178 " $(CXX) $^ -o $(NAME).so.0 $(CXXFLAGS) $(CPPFLAGS)"
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"))
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)))
199 (version (android-platform-version))
201 (inherit (android-platform-system-core version))
203 (search-patches "libbase-use-own-logging.patch"
204 "libbase-fix-includes.patch"))))
205 (build-system gnu-build-system)
208 (modify-phases %standard-phases
209 (add-after 'unpack 'enter-source
210 (lambda _ (chdir "adb") #t))
211 (add-before 'build 'fix-clang
213 ;; adb_client.h contains _Nonnull and _Nullable attributes, that
214 ;; are not understood by gcc.
215 (substitute* "adb_client.h"
219 (add-before 'build 'fix-main
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")
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"
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"
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"
247 "LIBADB_LDFLAGS += -shared -Wl,-soname,libadb.so.0 "
248 "-lcrypto -lpthread -lbase\n"
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"
255 "build: libadb $(ADB_SOURCES)\n"
256 " $(CXX) $(ADB_SOURCES) -o adb $(CXXFLAGS) $(CPPFLAGS) "
257 "$(ADB_LDFLAGS) $(LDFLAGS)\n"
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"))
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"))
275 ;; Test suite must be run with attached devices
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")
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)))
290 (define-public mkbootimg
293 (version (android-platform-version))
295 (inherit (android-platform-system-core version))))
296 (build-system python-build-system)
300 (modify-phases %standard-phases
301 (add-after 'unpack 'enter-source
302 (lambda _ (chdir "mkbootimg") #t))
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)
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
315 (license license:asl2.0)))
317 (define-public android-udev-rules
319 (name "android-udev-rules")
325 (url "https://github.com/M0Rf30/android-udev-rules")
327 (file-name (string-append name "-" version "-checkout"))
329 (base32 "13gj79nnd04szqlrrzzkdr6wi1fky08pi7x8xfbg0jj3d3v0giah"))))
330 (build-system trivial-build-system)
331 (native-inputs `(("source" ,source)))
333 '(#:modules ((guix build utils))
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
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+)))
353 (define-public git-repo
361 (url "https://gerrit.googlesource.com/git-repo")
362 (commit (string-append "v" version))))
363 (file-name (string-append "git-repo-" version "-checkout"))
365 (base32 "0qp7jqhblv7xblfgpcq4n18dyjdv8shz7r60c3vnjxx2fngkj2jd"))))
366 (build-system python-build-system)
368 `(#:python ,python-2 ; code says: "Python 3 support is … experimental."
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")
379 (string-append "GIT = '" git "/bin/git' ")))
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',")))
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)))
392 (("^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'
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)
406 curdir = os.path.dirname(curdir)
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"))
416 (delete 'build) ; nothing to build
419 (zero? (system* "python" "-m" "nose"))))
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)))
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"))
433 ;; TODO: Add git-remote-persistent-https once it is available in guix
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)))
448 (define-public abootimg
455 (uri (string-append "http://http.debian.net/debian/pool/main/a/abootimg/"
456 "abootimg_" version ".orig.tar.gz"))
458 (base32 "0sfc2k011l1ymv97821w89391gnqdh8pp0haz4sdcm5hx0axv2ba"))))
459 (build-system gnu-build-system)
463 (modify-phases %standard-phases
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)
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+)))