summaryrefslogtreecommitdiffstats
path: root/scripts/guix.scm
blob: 9bc117e9f0066afcdc1a29c7c698ba2df5818ebd (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
;;; Copyright © 2020 Denis Carikli <GNUtoo@cyberdimension.org>
;;;
;;; 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/>.
;;; The guix.scm file is a convention: A file named guix.scm is
;;; found in several project source code, either in the top
;;; directory or in sub-directories like contrib for instance.

;;; The guix.scm files typically contain package definitions that
;;; are not meant to be used as regular packages but are meant for
;;; testing or developing on the given project.
;;;
;;; Here it enables to build libsamsung-ril under GNU/Linux from the
;;; files currently present in this repository: Guix first copies all
;;; the files in this repository as-is and builds them. So if there
;;; are some local changes that aren't even committed in git yet, they
;;; will also be picked up and built by Guix. This is very useful to
;;; do fast compilation tests.
;;;
;;; Because of that it's also not adapted to be used as a regular package
;;; as distributions would typically need to use a given git revision or
;;; released tarballs instead of potentially locally modified code.
;;;
;;; Once you have Guix installed, to build libsamsung-ril with this
;;; guix.scm file, you can use the 'guix build --file=scripts/guix.scm'
;;; command.

(use-modules
 (ice-9 popen)
 (ice-9 rdelim)
 (sxml ssax input-parse)
 ((guix licenses) #:prefix license:)
 (guix build-system android-ndk)
 (guix build-system gnu)
 (guix gexp)
 (guix git-download)
 (guix packages)
 (guix transformations)
 (gnu packages)
 (gnu packages android)
 (gnu packages autotools)
 (gnu packages disk)
 (gnu packages linux)
 (gnu packages llvm)
 (gnu packages pkg-config)
 (gnu packages python)
 (gnu packages python-xyz)
 (gnu packages tls))

(define %strict-cflags "CFLAGS=-Werror -W -Wall -Wunused -Wunused-function")

(define %libsamsung-ril-commit
  (let* ((port (open-input-pipe
                "git --no-pager log --oneline HEAD -1 --format='%H'"))
         (str  (read-line port)))
    (close-pipe port)
    str))

(define %local-source
  (local-file
   (dirname (dirname (current-filename)))
   #:recursive? #t))

;; We just need libsamsung-ipc to build libsamsung-ril.
;; Using the Android.mk instead of Autotools can help spot more issues.
;; For instance if libsamsung-ril depends on libsamsung-ipc code that is only
;; built by the Autotools, using the Android.mk might spot that.
;; Forgetting to update the Android.mk seems more frequent than forgetting
;; to update the Autotools, because the code is often build tested with the
;; Autotools while writing it.
(define-public libsamsung-ipc
  (package
   (name "libsamsung-ipc")
   ;; Note that the hash is ignored here because we use transformations
   ;; to get the latest git version
   (version (git-version "0.0" "HEAD"
                         "73b26ca046c7dc2a3de89079203159a0cae83807"))
   (source
    (origin
     (method git-fetch)
     (uri
      (git-reference
       (url
        "https://git.replicant.us/replicant/hardware_replicant_libsamsung-ipc")
       ;; Note that the hashes are ignored here because we use transformations
       ;; to get the latest git version
       (commit "73b26ca046c7dc2a3de89079203159a0cae83807")))
     (sha256 (base32 "0icrc6b8hsjvzr6wjhvylq8fkn9s8snm6qf6yvz0lnlnxv0xifgp"))
     ))
   (build-system android-ndk-build-system)
   (inputs
    `(("android-libutils" ,android-libutils)
      ("libcrypto" ,openssl)))
   (arguments
    `(#:phases
      (modify-phases
       %standard-phases
       (delete 'bootstrap)
       (add-before
        'build 'patch-host
        (lambda _
          (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)))
      #:make-flags (list ,%strict-cflags)))
   (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+)))

(define-public replicant-6-hardware_ril-headers
  (package
   (name "replicant-6-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)
       ;; 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 6.0")
   (description
    "Headers of the The Radio Interface Layer (RIL) used by Replicant 6.0
 The Radio Interface Layer (RIL) daemon is used to abstracts the modem
 protocols in Android. It typically loads a libril counterpart that actually
 implement a specific modem protocol, while the RIL daemon itself handles the
 interface with the Android framework")
   (home-page "https://www.replicant.us")
   (license license:asl2.0)))

(define-public replicant-6-libhardware_legacy
  (package
   (name "replicant-6-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
                      ;; copying the android-core source code.
                      ;; When this is fixed:
                      ;; - Change the make flag (list above to ,#~(list
                      ;; - Uncomment the following lines:
                      ;;   "-I " #$(this-package-native-input "android-core")
                      ;;   "/include "
                      ;; - remove the -I ../core/include below:
                      "-I core/include "))
      #:phases
      (modify-phases
       %standard-phases
       ;; TODO: Guix's 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 and refer to it instead of just copyring it locally
       (add-after
        'unpack 'unpack-core
        (lambda* (#:key inputs #:allow-other-keys)
                 (mkdir-p "core")
                 (copy-recursively (assoc-ref inputs "android-core")
                                   "core")
                 #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-6-libhardware_legacy is Replicant 6.0's fork of Android's legacy
 HAL (Hardware Abstraction Layer)")
   (description
    "replicant-6-libhardware_legacy is Replicant 6.0'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)))

(define-public libsamsung-ril
  (package
   (name "libsamsung-ril")
   (version (git-version "0.0" "HEAD" %libsamsung-ril-commit))
   (source %local-source)
   (build-system android-ndk-build-system)
   (inputs
    `(("android-libcutils" ,android-libcutils)
      ("android-liblog" ,android-liblog)
      ("android-libutils" ,android-libutils)
      ("clang" ,clang)
      ("libcrypto" ,openssl)
      ("libsamsung-ipc" ,libsamsung-ipc)
      ("replicant-6-libhardware_legacy" ,replicant-6-libhardware_legacy)))
   (native-inputs
    `(("android-core" ,(android-platform-system-core
                        (android-platform-version)))
      ("replicant-6-hardware_ril-headers" ,replicant-6-hardware_ril-headers)))
   (arguments
    `(#:make-flags
      ,#~(list
          (string-append
           "CFLAGS=-W -Wall -Wno-unused "
           "-DANDROID "
           "-I core/include "
           "-I " #$(this-package-input "libsamsung-ipc")
           "/include/samsung-ipc "
           "-I " #$(this-package-input "replicant-6-libhardware_legacy")
           "/include "
           "-I " #$(this-package-native-input "replicant-6-hardware_ril-headers")
           "/include ")
          ;; We need to pass it LOCAL_MODULE=libsamsung-ril, else it only builds
          ;; the libsrs-client target (and not the libsamsung-ril target nor any of
          ;; the other tools).
          ;; TODO: Build all the tools as well
          "LOCAL_MODULE=libsamsung-ril")
      #:phases (modify-phases
                %standard-phases
                (add-after
                 'unpack 'unpack-core
                 (lambda*
                  (#:key inputs #:allow-other-keys)
                  (mkdir-p "core")
                  (copy-recursively (assoc-ref inputs "android-core")
                                    "core")
                  #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))
                (add-after
                 'patch-host
                 'prepare-build-environment
                 (lambda* (#:key inputs #:allow-other-keys)
                          (setenv "CC" "clang")
                          #t)))))
   (synopsis
    "libsamsung-ril is RIL library that uses libsamsung-ipc to implementation
 the Samsung IPC modem protocol")
   (description
    "The Radio Interface Layer (RIL) daemon is used to abstracts the modem
 protocols in Android. It typically loads a libril counterpart that actually
 implement a specific modem protocol, while the RIL daemon itself handles the
 interface with the Android framework. libsamsung-ril is libril library
 that uses libsamsung-ipc to implementation the Samsung IPC modem protocol,
 found in many Samsung smartphones and tablets.")
   (home-page "https://www.replicant.us")
   (license license:gpl2+)))

(define use-libsamsung-ipc-master
  (options->transformation
   '((with-branch . "libsamsung-ipc=master"))))

(list (use-libsamsung-ipc-master libsamsung-ril))