meson-configuration.scm 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be>
  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 meson-configuration)
  19. #:use-module (ice-9 match)
  20. #:export (write-section-header write-assignment
  21. write-assignments make-machine-alist
  22. configuration-port))
  23. ;; Commentary:
  24. ;;
  25. ;; Utilities for generating a ‘Cross build definition file’ for
  26. ;; the Meson build system. Configuration values are currently
  27. ;; never escaped. In practice this is unlikely to be a problem
  28. ;; in the build environment.
  29. ;;
  30. ;; Code:
  31. (define configuration-port
  32. (fluid->parameter (make-unbound-fluid)))
  33. (define (write-section-header section-name)
  34. "Write a section header for section named SECTION-NAME
  35. to the configuration port."
  36. (format (configuration-port) "[~a]~%" section-name))
  37. (define (write-assignment key value)
  38. "Write an assignment of VALUE to KEY to the configuration
  39. port. VALUE must be a string (without any special characters
  40. such as quotes), a boolean or an integer. Lists are currently
  41. not supported"
  42. (define port (configuration-port))
  43. (match value
  44. ((? string?)
  45. (format port "~a = '~a'~%" key value))
  46. ((? integer?)
  47. (format port "~a = ~a~%" key value))
  48. (#f
  49. (format port "~a = true~%" key))
  50. (#t
  51. (format port "~a = false~%" key))))
  52. (define* (write-assignments alist)
  53. "Write the assignments in ALIST, an association list,
  54. to the configuration port."
  55. (for-each (match-lambda
  56. ((key . value)
  57. (write-assignment key value)))
  58. alist))
  59. (define* (make-machine-alist #:key system cpu-family cpu endian)
  60. "Make an association list for the [host_machine] section."
  61. `((system . ,system)
  62. (cpu-family . ,cpu-family)
  63. (cpu . ,cpu)
  64. (endian . ,endian)))