build-system.scm 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2012, 2013, 2014, 2020 Ludovic Courtès <ludo@gnu.org>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  6. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; GNU Guix is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (guix build-system)
  19. #:use-module (guix records)
  20. #:use-module (srfi srfi-1)
  21. #:use-module (ice-9 match)
  22. #:export (build-system
  23. build-system?
  24. build-system-name
  25. build-system-description
  26. build-system-lower
  27. bag
  28. bag?
  29. bag-name
  30. bag-system
  31. bag-target
  32. bag-build-inputs
  33. bag-host-inputs
  34. bag-target-inputs
  35. bag-outputs
  36. bag-arguments
  37. bag-build
  38. make-bag
  39. build-system-with-c-toolchain))
  40. (define-record-type* <build-system> build-system make-build-system
  41. build-system?
  42. (name build-system-name) ; symbol
  43. (description build-system-description) ; short description
  44. (lower build-system-lower)) ; args ... -> bags
  45. ;; "Bags" are low-level representations of "packages". The system and target
  46. ;; of a bag is fixed when it's created. This is because build systems may
  47. ;; choose inputs as a function of the system and target.
  48. (define-record-type* <bag> bag %make-bag
  49. bag?
  50. (name bag-name) ;string
  51. (system bag-system) ;string
  52. (target bag-target ;string | #f
  53. (default #f))
  54. ;; Here we use build/host/target in the sense of the GNU tool chain (info
  55. ;; "(autoconf) Specifying Target Triplets").
  56. (build-inputs bag-build-inputs ;list of packages
  57. (default '()))
  58. (host-inputs bag-host-inputs ;list of packages
  59. (default '()))
  60. ;; "Target inputs" are packages that are built natively, but that are used
  61. ;; by target programs in a cross-compilation environment. Thus, they act
  62. ;; like 'inputs' as far as search paths are concerned. The only example of
  63. ;; that is the cross-libc: it is an input of 'cross-gcc', thus built
  64. ;; natively; yet, we want it to be considered as a target input for the
  65. ;; purposes of $CPATH, $LIBRARY_PATH, etc.
  66. (target-inputs bag-target-inputs
  67. (default '()))
  68. (outputs bag-outputs ;list of strings
  69. (default '("out")))
  70. (arguments bag-arguments ;list
  71. (default '()))
  72. (build bag-build)) ;bag -> derivation
  73. (define* (make-bag build-system name
  74. #:key source (inputs '()) (native-inputs '())
  75. (outputs '()) (arguments '())
  76. system target)
  77. "Ask BUILD-SYSTEM to return a 'bag' for NAME, with the given SOURCE,
  78. INPUTS, NATIVE-INPUTS, OUTPUTS, and additional ARGUMENTS. If TARGET is not
  79. #f, it must be a string with the GNU triplet of a cross-compilation target.
  80. This is the mechanism by which a package is \"lowered\" to a bag, which is the
  81. intermediate representation just above derivations."
  82. (match build-system
  83. (($ <build-system> _ description lower)
  84. (apply lower name
  85. #:system system
  86. #:source source
  87. #:inputs inputs
  88. #:native-inputs native-inputs
  89. #:outputs outputs
  90. #:target target
  91. arguments))))
  92. (define (build-system-with-c-toolchain bs toolchain)
  93. "Return a variant of BS, a build system, that uses TOOLCHAIN instead of the
  94. default GNU C/C++ toolchain. TOOLCHAIN must be a list of
  95. inputs (label/package tuples) providing equivalent functionality, such as the
  96. 'gcc-toolchain' package."
  97. (define lower
  98. (build-system-lower bs))
  99. (define toolchain-packages
  100. ;; These are the GNU toolchain packages pulled in by GNU-BUILD-SYSTEM and
  101. ;; all the build systems that inherit from it. Keep the list in sync with
  102. ;; 'standard-packages' in (guix build-system gnu).
  103. '("gcc" "binutils" "libc" "libc:static" "ld-wrapper"))
  104. (define (lower* . args)
  105. (let ((lowered (apply lower args)))
  106. (bag
  107. (inherit lowered)
  108. (build-inputs
  109. (append (fold alist-delete
  110. (bag-build-inputs lowered)
  111. toolchain-packages)
  112. toolchain)))))
  113. (build-system
  114. (inherit bs)
  115. (lower lower*)))