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