aboutsummaryrefslogtreecommitdiffstats
path: root/gnu/packages/replicant.scm
blob: d6c8b125e727f9de7db7fa7f385324c96755269d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
;;; Copyright © 2020 Denis Carikli <GNUtoo@cyberdimension.org>
;;;
;;; This file is not part of GNU Guix (yet).
;;;
;;; This file is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; This file is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (gnu packages replicant)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix packages)
  #:use-module (guix git-download)
  #:use-module (guix build-system android-ndk)
  #:use-module (guix build-system gnu)
  #:use-module (gnu packages android)
  #:use-module (gnu packages autotools)
  #:use-module (gnu packages linux)
  #:use-module (gnu packages llvm)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages tls)
  )

(define-public libsamsung-ipc
  (package
    (name "libsamsung-ipc")
    (version "0.1")
    (source
     (origin
       (method git-fetch)
       (uri (git-reference
             (url "https://git.replicant.us/replicant/hardware_replicant_libsamsung-ipc.git")
             (commit "73aa86f31bb004c48c5250ea43cca9ed9d51cb17")))
       (file-name (git-file-name name version))
       (sha256 (base32 "1wkvkgbckb7cif6lrd8rivh6s4886qa4dw2s433l28h2lh3zmqkb"))
       )
     )
    (build-system gnu-build-system)

    (native-inputs
     `(("autoreconf" ,autoconf)
       ("aclocal" ,automake)
       ("libtool" ,libtool)
       ("pkgconfig" ,pkg-config)
       ))

    (inputs
     `(("openssl" ,openssl)))

    (synopsis "libsamsung-ipc is a free software implementation of the Samsung IPC modem protocol")
    (description
     "libsamsung-ipc is a free software implementation of the Samsung IPC modem protocol,
found in many Samsung smartphones and tablets.")
    (home-page "https://www.replicant.us")
    (license license:gpl2+)
    )
  )

;; This package is meant to be a working example of how to use Guix's Android
;; build system. As libsamsung-ipc can also be built with the autotools build
;; system, another package named libsamsung-ipc uses that instead.
;; It's better to use the libsamsung-ipc package as a depdency as the Android
;; build system is more fragile and lacks some very basic features such as the
;; ability to do library versioning.
;; TODO: For some reasons it only build the libsamsung-ipc target (and not any
;; of the tools)
(define-public android-libsamsung-ipc
  (package
   (inherit libsamsung-ipc)
    (name "android-libsamsung-ipc")
    (build-system android-ndk-build-system)

    (inputs
     `(("android-libutils" ,android-libutils)
       ("libcrypto" ,openssl)))
    (native-inputs '())

    (arguments
     `(#:phases
       (modify-phases %standard-phases
         (delete 'bootstrap)
         (add-before 'build 'patch-host
           (lambda _
             ;; TODO: Cross-compile.
             (substitute* "Android.mk"
               (("BUILD_SHARED_LIBRARY") "BUILD_HOST_SHARED_LIBRARY")
               (("BUILD_STATIC_LIBRARY") "BUILD_HOST_STATIC_LIBRARY")
               (("BUILD_STATIC_EXECUTABLE") "BUILD_HOST_STATIC_EXECUTABLE"))
             #t)))))))

(define-public replicant-libhardware_legacy
  (package
    (name "replicant-libhardware_legacy")
    (version "6.0-0003")
    (source
     (origin
       (method git-fetch)
       (uri
        (git-reference
         (url
          "https://git.replicant.us/replicant/hardware_libhardware_legacy.git")
         (commit "0a29b8547b892115003c46ae17eae4b609aa9a87")))
       (file-name (git-file-name name version))
       (sha256 (base32 "1m8ip09pqw9gjrcqvsj3c7l2mxpaprp3z92sqq7qvp018ayqg1nv"))
       )
     )
    (build-system android-ndk-build-system)

    (inputs
     `(("android-libcutils" ,android-libcutils)
       ("android-liblog" ,android-liblog)
       ("libnl" ,libnl)
       ))

    (native-inputs
     `(
       ("android-core" ,(android-platform-system-core
                         (android-platform-version)))))
    (arguments
     `(
       #:make-flags (list (string-append "CFLAGS= "
                                         ;; TODO: see the comment below about
                                         ;; unpacking android-core tarball.
                                         ;; Uncomment the following lines and
                                         ;; remove -I ../core/include when
                                         ;; this is fixed:
                                         ;; "-I " (assoc-ref %build-inputs "android-core")
                                         ;; "/include "
                                         "-I core/include "
					 ))

                    #:phases
                    (modify-phases %standard-phases
                      ;; Hack: android.scm does that too in android-ext4-utils however it might
                      ;; be a good idea to instead package the android-code source code as-is
                      ;; instead of just downloading it as a tarball
                      (add-after 'unpack 'unpack-core
                        (lambda* (#:key inputs #:allow-other-keys)
                          (mkdir-p "core")
                          (with-directory-excursion "core"
                            (invoke "tar" "axf" (assoc-ref inputs "android-core")
                                    "--strip-components=1"))
                          #t))

                      (delete 'bootstrap)
                      (add-before 'build 'patch-host
                        (lambda _
                          ;; TODO: Cross-compile.
                          (substitute* "Android.mk"
                            (("BUILD_SHARED_LIBRARY") "BUILD_HOST_SHARED_LIBRARY")
                            (("BUILD_STATIC_LIBRARY") "BUILD_HOST_STATIC_LIBRARY")
                            (("BUILD_STATIC_EXECUTABLE") "BUILD_HOST_STATIC_EXECUTABLE"))
                          #t))
                      )))

    (synopsis
     "replicant-libhardware_legacy is Replicant's fork of Android's legacy HAL (Hardware Abstraction Layer)"
     )
    (description
     "replicant-libhardware_legacy is Replicant's fork of Android's legacy HAL (Hardware Abstraction Layer).
At the beginning of Android, breaking the kernel API to support (new) hardware faster was a common practice.
This was handled by the use of an hardware abstraction in userspace between the (highly modified) Linux kernel
and the Android framework that the Android applications interact with. In addition that abstraction layer also
supported userspace drivers for things that are not typically handled by the kernel like modem or GPS protocols.")
    (home-page "https://www.replicant.us")
    (license license:asl2.0)
    )
  )

;; TODO: For now we only package the headers as the repository contains multiple
;; projects with their own Android.mk with inter dependencies between them. So
;; they should each be packaged separately
(define-public replicant-hardware_ril-headers
  (package
    (name "replicant-hardware_ril-headers")
    (version "6.0-0003")
    (source
     (origin
       (method git-fetch)
       (uri
        (git-reference
         (url
          "https://git.replicant.us/mirrors/LineageOS/android_hardware_ril.git")
         (commit "f29d36b6b5430d3974b1857f8438d924c2f16a86")))
       (file-name (git-file-name name version))
       (sha256 (base32 "1inaz3lyqx3bmn6421yvxpkyj0v8vkslpl8ymxng2s3jm5xwi39g"))
       )
     )
    (build-system android-ndk-build-system)

    (arguments
     `(
       #:phases
       (modify-phases %standard-phases
         (delete 'bootstrap)
         (delete 'configure)
         ;; TODO: We only want to packages the headers for now
         (replace 'install
	   (lambda* (#:key outputs #:allow-other-keys)
             (let* ((out (assoc-ref outputs "out"))
                    (include (string-append out "/include")))
               (copy-recursively "include" (string-append out "/include"))
               #t))
	   )
	 )))

    (synopsis
     "Headers of the RIL used by Replicant."
     )
    (description
     "The Radio Interface Layer (RIL) is a daemon that is used to abstracts the
 modem protocols. It typically loads a libril counterpart that actually
 implement that protocol, while the RIL itself handles the interface with the
 Android framework")
    (home-page "https://www.replicant.us")
    (license license:asl2.0)
    )
  )

;; TODO: Without passing LOCAL_MODULE=libsamsung-ril, it only build the
;; libsrs-client target (and not the libsamsung-ril target nor any of the other
;; tools).
(define-public libsamsung-ril
  (let ((commit "77155778b245f600cbf7b43445cb51282d8a2664")
	(revision "1"))
    (package
     (name "libsamsung-ril")
     (version (git-version "replicant-6.0-0004-rc2" revision commit))
     (source
      (origin
       (method git-fetch)
       (uri
        (git-reference
         (url
          "https://git.replicant.us/replicant/hardware_replicant_libsamsung-ril.git"
          )
         (commit commit)))
       (file-name (git-file-name name version))
       (sha256 (base32 "1wszqg3y43jhfgck16mr7n55z3iylang60cshqyg5rl8akv9scah"))
       )
      )
     (build-system android-ndk-build-system)

     (inputs
      `(("android-libcutils" ,android-libcutils)
	("android-liblog" ,android-liblog)
	("android-libutils" ,android-libutils)
	("clang" ,clang-10)
	("libcrypto" ,openssl)
	("libsamsung-ipc" ,libsamsung-ipc)
	("replicant-libhardware_legacy" ,replicant-libhardware_legacy)
	)
      )

     (native-inputs
      `(
	("android-core" ,(android-platform-system-core
			  (android-platform-version)))
	("replicant-hardware_ril-headers" ,replicant-hardware_ril-headers)))

     (arguments
      `(
	#:make-flags (list (string-append "CFLAGS=-W -Wall -Wno-unused "
					  ;; From commonGlobalCflags in build/soong/cc/config/global.go:
					  "-DANDROID "
					  "-fmessage-length=0 "
					  "-W "
					  "-Wall "
					  "-Wno-unused "
					  "-Winit-self "
					  "-Wpointer-arith "
					  "-no-canonical-prefixes "
					  ;; For some reason clang doesn't accept the -fno-canonical-system-headers argument:
					  ;; : error: unknown argument: '-fno-canonical-system-headers'
					  ;; "-fno-canonical-system-headers "
					  "-DNDEBUG "
					  "-UDEBUG "
					  "-fno-exceptions "
					  "-Wno-multichar "
					  "-O2 "
					  "-g "
					  "-fno-strict-aliasing "
					  "-fdiagnostics-color "
					  ;; From deviceGlobalCflags in build/soong/cc/config/global.go:
					  "-ffunction-sections "
					  "-fdata-sections "
					  "-fno-short-enums "
					  "-funwind-tables "
					  "-fstack-protector-strong "
					  "-Wa,--noexecstack "
					  "-D_FORTIFY_SOURCE=2 "
					  "-Wstrict-aliasing=2 "
					  "-Werror=return-type "
					  "-Werror=non-virtual-dtor "
					  "-Werror=address "
					  "-Werror=sequence-point "
					  "-Werror=date-time "
					  "-Werror=format-security "
					  ;;
					  "-I core/include "
					  "-I " (assoc-ref %build-inputs "libsamsung-ipc")
					  "/include/samsung-ipc "
					  "-I " (assoc-ref %build-inputs "replicant-libhardware_legacy")
					  "/include "
					  "-I " (assoc-ref %build-inputs "replicant-hardware_ril-headers")
					  "/include "
					  )
			   "LOCAL_MODULE=libsamsung-ril")
		     #:phases
		     (modify-phases %standard-phases

				    ;; Hack: android.scm does that too in android-ext4-utils however it might
				    ;; be a good idea to instead package the android-code source code as-is
				    ;; instead of just downloading it as a tarball
				    (add-after 'unpack 'unpack-core
					       (lambda* (#:key inputs #:allow-other-keys)
						 (mkdir-p "core")
						 (with-directory-excursion "core"
									   (invoke "tar" "axf" (assoc-ref inputs "android-core")
										   "--strip-components=1"))
						 #t))

				    (delete 'bootstrap)
				    (add-before 'build 'patch-host
						(lambda _
						  ;; TODO: Cross-compile.
						  (substitute* "Android.mk"
							       (("BUILD_SHARED_LIBRARY") "BUILD_HOST_SHARED_LIBRARY")
							       (("BUILD_STATIC_LIBRARY") "BUILD_HOST_STATIC_LIBRARY")
							       (("BUILD_STATIC_EXECUTABLE") "BUILD_HOST_STATIC_EXECUTABLE"))
						  #t))

				    ;; For clang builds
				    (add-after 'patch-host 'prepare-build-environment
					       (lambda* (#:key inputs #:allow-other-keys)
						 (setenv "CC" "clang")
						 #t))))
      )

     (synopsis
      "libsamsung-ipc is a free software implementation of the Samsung IPC modem protocol")
     (description
      "libril implementation for the Samsung IPC modem protocol, found in many Samsung smartphones and tablets.")
     (home-page "https://www.replicant.us")
     (license license:gpl2+)
     )
    )
  )