linux-module-build-system.scm 3.7 KB

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