;;; Copyright © 2020 Denis Carikli ;;; ;;; 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 . ;;; 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" ,libressl))) (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" ,libressl) ("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))