scons.scm 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2017 Arun Isaac <arunisaac@systemreboot.net>
  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 scons)
  19. #:use-module (guix utils)
  20. #:use-module (guix packages)
  21. #:use-module (guix derivations)
  22. #:use-module (guix search-paths)
  23. #:use-module (guix build-system)
  24. #:use-module (guix build-system gnu)
  25. #:use-module (ice-9 match)
  26. #:export (%scons-build-system-modules
  27. scons-build
  28. scons-build-system))
  29. ;; Commentary:
  30. ;;
  31. ;; Standard build procedure for applications using SCons. This is implemented
  32. ;; as an extension of 'gnu-build-system'.
  33. ;;
  34. ;; Code:
  35. (define %scons-build-system-modules
  36. ;; Build-side modules imported by default.
  37. `((guix build scons-build-system)
  38. ,@%gnu-build-system-modules))
  39. (define (default-scons)
  40. "Return the default SCons package."
  41. ;; Lazily resolve the binding to avoid a circular dependency.
  42. (let ((python (resolve-interface '(gnu packages python-xyz))))
  43. (module-ref python 'scons)))
  44. (define* (lower name
  45. #:key source inputs native-inputs outputs system target
  46. (scons (default-scons))
  47. #:allow-other-keys
  48. #:rest arguments)
  49. "Return a bag for NAME."
  50. (define private-keywords
  51. '(#:source #:target #:scons #:inputs #:native-inputs))
  52. (and (not target) ;XXX: no cross-compilation
  53. (bag
  54. (name name)
  55. (system system)
  56. (host-inputs `(,@(if source
  57. `(("source" ,source))
  58. '())
  59. ,@inputs
  60. ;; Keep the standard inputs of 'gnu-build-system'.
  61. ,@(standard-packages)))
  62. (build-inputs `(("scons" ,scons)
  63. ,@native-inputs))
  64. (outputs outputs)
  65. (build scons-build)
  66. (arguments (strip-keyword-arguments private-keywords arguments)))))
  67. (define* (scons-build store name inputs
  68. #:key
  69. (tests? #t)
  70. (scons-flags ''())
  71. (build-targets ''())
  72. (test-target "test")
  73. (install-targets ''("install"))
  74. (phases '(@ (guix build scons-build-system)
  75. %standard-phases))
  76. (outputs '("out"))
  77. (search-paths '())
  78. (system (%current-system))
  79. (guile #f)
  80. (imported-modules %scons-build-system-modules)
  81. (modules '((guix build scons-build-system)
  82. (guix build utils))))
  83. "Build SOURCE using SCons, and with INPUTS. This assumes that SOURCE
  84. provides a 'SConstruct' file as its build system."
  85. (define builder
  86. `(begin
  87. (use-modules ,@modules)
  88. (scons-build #:name ,name
  89. #:source ,(match (assoc-ref inputs "source")
  90. (((? derivation? source))
  91. (derivation->output-path source))
  92. ((source)
  93. source)
  94. (source
  95. source))
  96. #:scons-flags ,scons-flags
  97. #:system ,system
  98. #:build-targets ,build-targets
  99. #:test-target ,test-target
  100. #:tests? ,tests?
  101. #:install-targets ,install-targets
  102. #:phases ,phases
  103. #:outputs %outputs
  104. #:search-paths ',(map search-path-specification->sexp
  105. search-paths)
  106. #:inputs %build-inputs)))
  107. (define guile-for-build
  108. (match guile
  109. ((? package?)
  110. (package-derivation store guile system #:graft? #f))
  111. (#f ; the default
  112. (let* ((distro (resolve-interface '(gnu packages commencement)))
  113. (guile (module-ref distro 'guile-final)))
  114. (package-derivation store guile system #:graft? #f)))))
  115. (build-expression->derivation store name builder
  116. #:inputs inputs
  117. #:system system
  118. #:modules imported-modules
  119. #:outputs outputs
  120. #:guile-for-build guile-for-build))
  121. (define scons-build-system
  122. (build-system
  123. (name 'scons)
  124. (description "The standard SCons build system")
  125. (lower lower)))
  126. ;;; scons.scm ends here