linux-module-build-system.scm 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2019 Danny Milosavljevic <dannym@scratchpost.org>
  3. ;;; Copyright © 2020 Mathieu Othacehe <m.othacehe@gmail.com>
  4. ;;; Copyright © 2021 Tobias Geerinckx-Rice <me@tobias.gr>
  5. ;;;
  6. ;;; This file is part of GNU Guix.
  7. ;;;
  8. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  9. ;;; under the terms of the GNU General Public License as published by
  10. ;;; the Free Software Foundation; either version 3 of the License, or (at
  11. ;;; your option) any later version.
  12. ;;;
  13. ;;; GNU Guix is distributed in the hope that it will be useful, but
  14. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;;; GNU General Public License for more details.
  17. ;;;
  18. ;;; You should have received a copy of the GNU General Public License
  19. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  20. (define-module (guix build linux-module-build-system)
  21. #:use-module ((guix build gnu-build-system) #:prefix gnu:)
  22. #:use-module (guix build utils)
  23. #:use-module (ice-9 ftw)
  24. #:use-module (ice-9 match)
  25. #:use-module (srfi srfi-1)
  26. #:use-module (srfi srfi-26)
  27. #:export (%standard-phases
  28. linux-module-build))
  29. ;; Commentary:
  30. ;;
  31. ;; Builder-side code of linux-module build.
  32. ;;
  33. ;; Code:
  34. ;; Similar to make-linux-libre's "configure" phase.
  35. (define* (configure #:key inputs target arch #:allow-other-keys)
  36. (setenv "KCONFIG_NOTIMESTAMP" "1")
  37. (setenv "KBUILD_BUILD_TIMESTAMP" (getenv "SOURCE_DATE_EPOCH"))
  38. (setenv "ARCH" arch)
  39. (format #t "`ARCH' set to `~a'~%" (getenv "ARCH"))
  40. (when target
  41. ;; TODO? (setenv "EXTRA_VERSION" ,extra-version)
  42. ;; TODO? kernel ".config".
  43. (setenv "CROSS_COMPILE" (string-append target "-"))
  44. (format #t "`CROSS_COMPILE' set to `~a'~%"
  45. (getenv "CROSS_COMPILE"))))
  46. (define* (build #:key (make-flags '()) (parallel-build? #t)
  47. (source-directory ".")
  48. inputs
  49. #:allow-other-keys)
  50. (apply invoke "make" "-C"
  51. (string-append (assoc-ref inputs "linux-module-builder")
  52. "/lib/modules/build")
  53. (string-append "M=" (canonicalize-path source-directory))
  54. `(,@(if parallel-build?
  55. `("-j" ,(number->string (parallel-job-count)))
  56. '())
  57. ,@make-flags)))
  58. ;; Similar to the "modules_install" part of make-linux-libre.
  59. (define* (install #:key (make-flags '()) (parallel-build? #t)
  60. (source-directory ".")
  61. inputs native-inputs outputs
  62. #:allow-other-keys)
  63. (let* ((out (assoc-ref outputs "out"))
  64. (moddir (string-append out "/lib/modules")))
  65. ;; Install kernel modules
  66. (mkdir-p moddir)
  67. (apply invoke "make" "-C"
  68. (string-append (assoc-ref inputs "linux-module-builder")
  69. "/lib/modules/build")
  70. (string-append "M=" (canonicalize-path source-directory))
  71. ;; Disable depmod because the Guix system's module directory
  72. ;; is an union of potentially multiple packages. It is not
  73. ;; possible to use depmod to usefully calculate a dependency
  74. ;; graph while building only one of those packages.
  75. "DEPMOD=true"
  76. (string-append "MODULE_DIR=" moddir)
  77. (string-append "INSTALL_PATH=" out)
  78. (string-append "INSTALL_MOD_PATH=" out)
  79. "INSTALL_MOD_STRIP=1"
  80. "modules_install"
  81. `(,@(if parallel-build?
  82. `("-j" ,(number->string (parallel-job-count)))
  83. '())
  84. ,@make-flags))))
  85. (define %standard-phases
  86. (modify-phases gnu:%standard-phases
  87. (replace 'configure configure)
  88. (replace 'build build)
  89. (replace 'install install)))
  90. (define* (linux-module-build #:key inputs
  91. (phases %standard-phases)
  92. #:allow-other-keys #:rest args)
  93. "Build the given package, applying all of PHASES in order, with a Linux
  94. kernel in attendance."
  95. (apply gnu:gnu-build
  96. #:inputs inputs #:phases phases
  97. args))
  98. ;;; linux-module-build-system.scm ends here