scons.scm 4.9 KB

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