linux-module-build-system.scm 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 #: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))
  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 inputs native-inputs outputs
  55. #:allow-other-keys)
  56. (let* ((out (assoc-ref outputs "out"))
  57. (moddir (string-append out "/lib/modules")))
  58. ;; Install kernel modules
  59. (mkdir-p moddir)
  60. (apply invoke "make" "-C"
  61. (string-append (assoc-ref inputs "linux-module-builder")
  62. "/lib/modules/build")
  63. (string-append "M=" (getcwd))
  64. ;; Disable depmod because the Guix system's module directory
  65. ;; is an union of potentially multiple packages. It is not
  66. ;; possible to use depmod to usefully calculate a dependency
  67. ;; graph while building only one of those packages.
  68. "DEPMOD=true"
  69. (string-append "MODULE_DIR=" moddir)
  70. (string-append "INSTALL_PATH=" out)
  71. (string-append "INSTALL_MOD_PATH=" out)
  72. "INSTALL_MOD_STRIP=1"
  73. "modules_install"
  74. (or make-flags '()))))
  75. (define %standard-phases
  76. (modify-phases gnu:%standard-phases
  77. (replace 'configure configure)
  78. (replace 'build build)
  79. (replace 'install install)))
  80. (define* (linux-module-build #:key inputs
  81. (phases %standard-phases)
  82. #:allow-other-keys #:rest args)
  83. "Build the given package, applying all of PHASES in order, with a Linux
  84. kernel in attendance."
  85. (apply gnu:gnu-build
  86. #:inputs inputs #:phases phases
  87. args))
  88. ;;; linux-module-build-system.scm ends here