linux-module-build-system.scm 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. #:export (%standard-phases
  24. linux-module-build))
  25. ;; Commentary:
  26. ;;
  27. ;; Builder-side code of linux-module build.
  28. ;;
  29. ;; Code:
  30. ;; Similar to make-linux-libre's "configure" phase.
  31. (define* (configure #:key inputs target arch #:allow-other-keys)
  32. (setenv "KCONFIG_NOTIMESTAMP" "1")
  33. (setenv "KBUILD_BUILD_TIMESTAMP" (getenv "SOURCE_DATE_EPOCH"))
  34. (setenv "ARCH" arch)
  35. (format #t "`ARCH' set to `~a'~%" (getenv "ARCH"))
  36. (when target
  37. ;; TODO? (setenv "EXTRA_VERSION" ,extra-version)
  38. ;; TODO? kernel ".config".
  39. (setenv "CROSS_COMPILE" (string-append target "-"))
  40. (format #t "`CROSS_COMPILE' set to `~a'~%"
  41. (getenv "CROSS_COMPILE"))))
  42. (define* (build #:key (make-flags '()) (parallel-build? #t)
  43. (source-directory ".")
  44. inputs
  45. #:allow-other-keys)
  46. (apply invoke "make" "-C"
  47. (string-append (assoc-ref inputs "linux-module-builder")
  48. "/lib/modules/build")
  49. (string-append "M=" (canonicalize-path source-directory))
  50. `(,@(if parallel-build?
  51. `("-j" ,(number->string (parallel-job-count)))
  52. '())
  53. ,@make-flags)))
  54. ;; Similar to the "modules_install" part of make-linux-libre.
  55. (define* (install #:key (make-flags '()) (parallel-build? #t)
  56. (source-directory ".")
  57. inputs native-inputs outputs
  58. #:allow-other-keys)
  59. (let* ((out (assoc-ref outputs "out"))
  60. (moddir (string-append out "/lib/modules")))
  61. ;; Install kernel modules
  62. (mkdir-p moddir)
  63. (apply invoke "make" "-C"
  64. (string-append (assoc-ref inputs "linux-module-builder")
  65. "/lib/modules/build")
  66. (string-append "M=" (canonicalize-path source-directory))
  67. ;; Disable depmod because the Guix system's module directory
  68. ;; is an union of potentially multiple packages. It is not
  69. ;; possible to use depmod to usefully calculate a dependency
  70. ;; graph while building only one of those packages.
  71. "DEPMOD=true"
  72. (string-append "MODULE_DIR=" moddir)
  73. (string-append "INSTALL_PATH=" out)
  74. (string-append "INSTALL_MOD_PATH=" out)
  75. "INSTALL_MOD_STRIP=1"
  76. "modules_install"
  77. `(,@(if parallel-build?
  78. `("-j" ,(number->string (parallel-job-count)))
  79. '())
  80. ,@make-flags))))
  81. (define %standard-phases
  82. (modify-phases gnu:%standard-phases
  83. (replace 'configure configure)
  84. (replace 'build build)
  85. (replace 'install install)))
  86. (define* (linux-module-build #:key inputs
  87. (phases %standard-phases)
  88. #:allow-other-keys #:rest args)
  89. "Build the given package, applying all of PHASES in order, with a Linux
  90. kernel in attendance."
  91. (apply gnu:gnu-build
  92. #:inputs inputs #:phases phases
  93. args))
  94. ;;; linux-module-build-system.scm ends here