gnu: r-qtl2: Move to (gnu packages cran).
[jackhill/guix/guix.git] / guix / build / linux-module-build-system.scm
CommitLineData
ce631299
DM
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2019 Danny Milosavljevic <dannym@scratchpost.org>
c086c5af 3;;; Copyright © 2020 Mathieu Othacehe <m.othacehe@gmail.com>
ce631299
DM
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
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
30;; Commentary:
31;;
32;; Builder-side code of linux-module build.
33;;
34;; Code:
35
0b30a1a0 36;; Copied from make-linux-libre's "configure" phase.
c086c5af 37(define* (configure #:key inputs target arch #:allow-other-keys)
0b30a1a0
DM
38 (setenv "KCONFIG_NOTIMESTAMP" "1")
39 (setenv "KBUILD_BUILD_TIMESTAMP" (getenv "SOURCE_DATE_EPOCH"))
c086c5af
MO
40
41 (setenv "ARCH" arch)
42 (format #t "`ARCH' set to `~a'~%" (getenv "ARCH"))
43
0b30a1a0
DM
44 (when target
45 (setenv "CROSS_COMPILE" (string-append target "-"))
46 (format #t "`CROSS_COMPILE' set to `~a'~%"
47 (getenv "CROSS_COMPILE")))
48 ; TODO: (setenv "EXTRA_VERSION" ,extra-version)
49 ; TODO: kernel ".config".
50 #t)
51
ce631299
DM
52(define* (build #:key inputs make-flags #:allow-other-keys)
53 (apply invoke "make" "-C"
54 (string-append (assoc-ref inputs "linux-module-builder")
55 "/lib/modules/build")
56 (string-append "M=" (getcwd))
57 (or make-flags '())))
58
59;; This block was copied from make-linux-libre--only took the "modules_install"
60;; part.
f51fd97e
DM
61(define* (install #:key make-flags inputs native-inputs outputs
62 #:allow-other-keys)
ce631299 63 (let* ((out (assoc-ref outputs "out"))
12f0aefd 64 (moddir (string-append out "/lib/modules")))
ce631299
DM
65 ;; Install kernel modules
66 (mkdir-p moddir)
f51fd97e 67 (apply invoke "make" "-C"
ce631299
DM
68 (string-append (assoc-ref inputs "linux-module-builder")
69 "/lib/modules/build")
70 (string-append "M=" (getcwd))
12f0aefd
DM
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"
ce631299
DM
76 (string-append "MODULE_DIR=" moddir)
77 (string-append "INSTALL_PATH=" out)
78 (string-append "INSTALL_MOD_PATH=" out)
79 "INSTALL_MOD_STRIP=1"
f51fd97e
DM
80 "modules_install"
81 (or make-flags '()))))
ce631299
DM
82
83(define %standard-phases
84 (modify-phases gnu:%standard-phases
0b30a1a0 85 (replace 'configure configure)
ce631299
DM
86 (replace 'build build)
87 (replace 'install install)))
88
f51fd97e
DM
89(define* (linux-module-build #:key inputs
90 (phases %standard-phases)
c086c5af
MO
91 #:allow-other-keys #:rest args)
92 "Build the given package, applying all of PHASES in order, with a Linux
93kernel in attendance."
ce631299
DM
94 (apply gnu:gnu-build
95 #:inputs inputs #:phases phases
96 args))
97
98;;; linux-module-build-system.scm ends here