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 | ;;; |
7 | ;;; This file is part of GNU Guix. |
8 | ;;; |
9 | ;;; GNU Guix is free software; you can redistribute it and/or modify it |
10 | ;;; under the terms of the GNU General Public License as published by |
11 | ;;; the Free Software Foundation; either version 3 of the License, or (at |
12 | ;;; your option) any later version. |
13 | ;;; |
14 | ;;; GNU Guix is distributed in the hope that it will be useful, but |
15 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | ;;; GNU General Public License for more details. |
18 | ;;; |
19 | ;;; You should have received a copy of the GNU General Public License |
20 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. |
21 | |
22 | (define-module (more packages android) |
23 | #:use-module (guix packages) |
24 | #:use-module (guix git-download) |
25 | #:use-module (guix build-system gnu) |
26 | #:use-module ((guix licenses) #:prefix license:) |
27 | #:use-module (gnu packages) |
28 | #:use-module (gnu packages tls)) |
29 | |
30 | ;; The Makefiles that we add are largely based on the Debian |
31 | ;; packages. They are licensed under GPL-2 and have copyright: |
32 | ;; 2012, Stefan Handschuh <handschuh.stefan@googlemail.com> |
33 | ;; 2015, Kai-Chung Yan <seamlikok@gmail.com> |
34 | ;; Big thanks to them for laying the groundwork. |
35 | |
36 | ;; The version tag is consistent between all repositories. |
37 | (define (android-platform-version) "7.1.2_r6") |
38 | |
39 | (define (android-platform-system-core version) |
40 | (origin |
41 | (method git-fetch) |
42 | (uri (git-reference |
43 | (url "https://android.googlesource.com/platform/system/core") |
44 | (commit (string-append "android-" version)))) |
45 | (file-name (string-append "android-platform-system-core-" |
46 | version "-checkout")) |
47 | (sha256 |
48 | (base32 |
49 | "0xc2n7jxrf1iw9cc278pijdfjix2fkiig5ws27f6rwp40zg5mrgg")))) |
50 | |
51 | (define liblog |
52 | (package |
53 | (name "liblog") |
54 | (version (android-platform-version)) |
55 | (source (android-platform-system-core version)) |
56 | (build-system gnu-build-system) |
57 | (arguments |
58 | `(#:tests? #f ; TODO. |
59 | #:make-flags '("CC=gcc") |
60 | #:phases |
61 | (modify-phases %standard-phases |
62 | (add-after 'unpack 'enter-source |
63 | (lambda _ (chdir "liblog") #t)) |
64 | (add-after 'enter-source 'create-Makefile |
65 | (lambda _ |
66 | ;; No useful makefile is shipped, so we create one. |
67 | (with-output-to-file "Makefile" |
68 | (lambda _ |
69 | (display |
70 | (string-append |
71 | "NAME = liblog\n" |
72 | "SOURCES = log_event_list.c log_event_write.c" |
73 | " logger_write.c config_write.c logger_name.c" |
74 | " logger_lock.c fake_log_device.c fake_writer.c" |
75 | " event_tag_map.c\n" |
76 | |
77 | "CFLAGS += -fvisibility=hidden -fPIC\n" |
78 | "CPPFLAGS += -I../include -DFAKE_LOG_DEVICE=1" |
79 | ;; Keep these two in sync with "liblog/Android.bp". |
80 | " -DLIBLOG_LOG_TAG=1005" |
81 | " -DSNET_EVENT_LOG_TAG=1397638484\n" |
82 | "LDFLAGS += -shared -Wl,-soname,$(NAME).so.0 -lpthread\n" |
83 | |
84 | "build: $(SOURCES)\n" |
85 | " $(CC) $^ -o $(NAME).so.0 $(CFLAGS) $(CPPFLAGS) $(LDFLAGS)\n")))))) |
86 | (delete 'configure) |
87 | (replace 'install |
88 | (lambda* (#:key outputs #:allow-other-keys) |
89 | (let* ((out (assoc-ref outputs "out")) |
90 | (lib (string-append out "/lib"))) |
91 | (install-file "liblog.so.0" lib) |
92 | (with-directory-excursion lib |
93 | (symlink "liblog.so.0" "liblog.so")) |
94 | #t)))))) |
95 | (home-page "https://developer.android.com/") |
96 | (synopsis "Logging library from the Android platform.") |
97 | (description "@code{liblog} represents an interface to the volatile Android |
98 | Logging system for NDK (Native) applications and libraries and contain |
99 | interfaces for either writing or reading logs. The log buffers are divided up |
100 | in Main, System, Radio and Events sub-logs.") |
101 | (license license:asl2.0))) |
102 | |
103 | (define libbase |
104 | (package |
105 | (name "libbase") |
106 | (version (android-platform-version)) |
107 | (source (origin |
108 | (inherit (android-platform-system-core version)) |
109 | (patches |
110 | (search-patches "libbase-use-own-logging.patch" |
111 | "libbase-fix-includes.patch")))) |
112 | (build-system gnu-build-system) |
113 | (arguments |
114 | `(#:tests? #f ; TODO. |
115 | #:phases |
116 | (modify-phases %standard-phases |
117 | (add-after 'unpack 'enter-source |
118 | (lambda _ (chdir "base") #t)) |
119 | (add-after 'enter-source 'create-Makefile |
120 | (lambda _ |
121 | ;; No useful makefile is shipped, so we create one. |
122 | (with-output-to-file "Makefile" |
123 | (lambda _ |
124 | (display |
125 | (string-append |
126 | "NAME = libbase\n" |
127 | "SOURCES = file.cpp logging.cpp parsenetaddress.cpp" |
128 | " stringprintf.cpp strings.cpp errors_unix.cpp\n" |
129 | |
130 | "CXXFLAGS += -std=gnu++11 -fPIC\n" |
131 | "CPPFLAGS += -Iinclude -I../include\n" |
132 | "LDFLAGS += -shared -Wl,-soname,$(NAME).so.0" |
133 | " -L.. -llog\n" |
134 | |
135 | "build: $(SOURCES)\n" |
136 | " $(CXX) $^ -o $(NAME).so.0 $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS)\n" |
137 | )))))) |
138 | (delete 'configure) |
139 | (replace 'install |
140 | (lambda* (#:key outputs #:allow-other-keys) |
141 | (let* ((out (assoc-ref outputs "out")) |
142 | (lib (string-append out "/lib"))) |
143 | (install-file "libbase.so.0" lib) |
144 | (with-directory-excursion lib |
145 | (symlink "libbase.so.0" "libbase.so")) |
146 | (copy-recursively "include" out) |
147 | #t)))))) |
148 | (inputs `(("liblog" ,liblog))) |
149 | (home-page "https://developer.android.com/") |
150 | (synopsis "Android platform base library") |
151 | (description "@code{libbase} is a library in common use by the |
152 | various Android core host applications.") |
153 | (license license:asl2.0))) |
154 | |
155 | (define libcutils |
156 | (package |
157 | (name "libcutils") |
158 | (version (android-platform-version)) |
159 | (source (android-platform-system-core version)) |
160 | (build-system gnu-build-system) |
161 | (arguments |
162 | `(#:tests? #f ; TODO. |
163 | #:phases |
164 | (modify-phases %standard-phases |
165 | (add-after 'unpack 'enter-source |
166 | (lambda _ (chdir "libcutils") #t)) |
167 | (add-after 'enter-source 'create-Makefile |
168 | (lambda _ |
169 | ;; No useful makefile is shipped, so we create one. |
170 | (with-output-to-file "Makefile" |
171 | (lambda _ |
172 | (display |
173 | (string-append |
174 | "NAME = libcutils\n" |
175 | "SOURCES = load_file.o socket_local_client_unix.o" |
176 | " socket_loopback_client_unix.o socket_network_client_unix.o" |
177 | " socket_loopback_server_unix.o socket_local_server_unix.o" |
178 | " sockets_unix.o socket_inaddr_any_server_unix.o" |
179 | " sockets.o\n" |
180 | "CC = gcc\n" |
181 | |
182 | "CFLAGS += -fPIC\n" |
183 | "CXXFLAGS += -std=gnu++11 -fPIC\n" |
184 | "CPPFLAGS += -Iinclude -I../include\n" |
185 | "LDFLAGS += -shared -Wl,-soname,$(NAME).so.0\n" |
186 | |
187 | "build: $(SOURCES)\n" |
188 | " $(CXX) $^ -o $(NAME).so.0 $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS)\n" |
189 | )))))) |
190 | (delete 'configure) |
191 | (replace 'install |
192 | (lambda* (#:key outputs #:allow-other-keys) |
193 | (let* ((out (assoc-ref outputs "out")) |
194 | (lib (string-append out "/lib"))) |
195 | (install-file "libcutils.so.0" lib) |
196 | (with-directory-excursion lib |
197 | (symlink "libcutils.so.0" "libcutils.so")) |
198 | #t)))))) |
199 | (home-page "https://developer.android.com/") |
200 | (synopsis "Android platform c utils library") |
201 | (description "@code{libcutils} is a library in common use by the |
202 | various Android core host applications.") |
203 | (license license:asl2.0))) |
204 | |
205 | (define-public adb |
206 | (package |
207 | (name "adb") |
208 | (version (android-platform-version)) |
209 | (source (origin |
210 | (inherit (android-platform-system-core version)) |
211 | (patches |
212 | (search-patches "libbase-use-own-logging.patch" |
213 | "libbase-fix-includes.patch")))) |
214 | (build-system gnu-build-system) |
215 | (arguments |
216 | `(#:phases |
217 | (modify-phases %standard-phases |
218 | (add-after 'unpack 'enter-source |
219 | (lambda _ (chdir "adb") #t)) |
220 | (add-before 'build 'fix-clang |
221 | (lambda _ |
222 | (substitute* "adb_client.h" |
223 | (("_Nonnull") "") |
224 | (("_Nullable") "")))) |
225 | (add-before 'build 'fix-main |
226 | (lambda _ |
227 | (copy-file "client/main.cpp" "adb_main.cpp"))) |
228 | (add-after 'enter-source 'create-Makefile |
229 | (lambda* (#:key outputs #:allow-other-keys) |
230 | ;; No useful makefile is shipped, so we create one. |
231 | (with-output-to-file "Makefile" |
232 | (lambda _ |
233 | (display |
234 | (string-append |
235 | ;; Common for all components. |
236 | "CXXFLAGS += -std=gnu++14 -fpermissive\n" |
237 | "CPPFLAGS += -I../include -I../base/include -I. -DADB_HOST=1 " |
238 | "-DADB_REVISION='\"" ,version "\"' -fPIC\n" |
239 | "LDFLAGS += -lcrypto -lpthread -lbase -lcutils -L. -ladb\n" |
240 | |
241 | ;; Libadb specifics. |
242 | "LIBADB_SOURCES = adb.cpp adb_auth.cpp adb_io.cpp " |
243 | "adb_listeners.cpp adb_trace.cpp adb_utils.cpp fdevent.cpp " |
244 | "sockets.cpp transport.cpp transport_local.cpp transport_usb.cpp " |
245 | "get_my_path_linux.cpp sysdeps_unix.cpp usb_linux.cpp " |
246 | "adb_auth_host.cpp diagnose_usb.cpp services.cpp " |
247 | "shell_service_protocol.cpp bugreport.cpp line_printer.cpp\n" |
248 | |
249 | "LIBADB_LDFLAGS += -shared -Wl,-soname,libadb.so.0 " |
250 | "-lcrypto -lpthread -lbase\n" |
251 | |
252 | ;; Adb specifics. |
253 | "ADB_SOURCES = adb_main.cpp console.cpp commandline.cpp " |
254 | "adb_client.cpp file_sync_client.cpp\n" |
255 | "ADB_LDFLAGS += -Wl,-rpath=" (assoc-ref outputs "out") "/lib\n" |
256 | |
257 | "build: libadb $(ADB_SOURCES)\n" |
258 | " $(CXX) $(ADB_SOURCES) -o adb $(CXXFLAGS) $(CPPFLAGS) " |
259 | "$(ADB_LDFLAGS) $(LDFLAGS)\n" |
260 | |
261 | "libadb: $(LIBADB_SOURCES)\n" |
262 | " $(CXX) $^ -o libadb.so.0 $(CXXFLAGS) $(CPPFLAGS) " |
263 | "$(LIBADB_LDFLAGS)\n" |
264 | " ln -sv libadb.so.0 libadb.so\n" |
265 | )))))) |
266 | (delete 'configure) |
267 | (replace 'install |
268 | (lambda* (#:key outputs #:allow-other-keys) |
269 | (let* ((out (assoc-ref outputs "out")) |
270 | (lib (string-append out "/lib")) |
271 | (bin (string-append out "/bin"))) |
272 | (install-file "libadb.so.0" lib) |
273 | (install-file "adb" bin) |
274 | (with-directory-excursion lib |
275 | (symlink "libadb.so.0" "libadb.so")) |
276 | #t)))) |
277 | ;; Test suite must be run with attached devices |
278 | #:tests? #f)) |
279 | (inputs |
280 | `(("libbase" ,libbase) |
281 | ("libcutils" ,libcutils) |
282 | ("openssl" ,openssl))) |
283 | (home-page "https://developer.android.com/studio/command-line/adb.html") |
284 | (synopsis "Android Debug Bridge") |
285 | (description |
286 | "@command{adb} is a versatile command line tool that lets you communicate |
287 | with an emulator instance or connected Android device. It facilitates a variety |
288 | of device actions, such as installing and debugging apps, and it provides access |
289 | to a Unix shell that can run commands on the connected device or emulator.") |
290 | (license license:asl2.0))) |
291 |