glib-or-gtk.scm 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2013, 2014, 2015, 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2013 Cyril Roelandt <tipecaml@gmail.com>
  4. ;;; Copyright © 2014 Federico Beffa <beffa@fbengineering.ch>
  5. ;;;
  6. ;;; This file is part of GNU Guix.
  7. ;;;
  8. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  9. ;;; under the terms of the GNU General Public License as published by
  10. ;;; the Free Software Foundation; either version 3 of the License, or (at
  11. ;;; your option) any later version.
  12. ;;;
  13. ;;; GNU Guix is distributed in the hope that it will be useful, but
  14. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;;; GNU General Public License for more details.
  17. ;;;
  18. ;;; You should have received a copy of the GNU General Public License
  19. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  20. (define-module (guix build-system glib-or-gtk)
  21. #:use-module (guix store)
  22. #:use-module (guix utils)
  23. #:use-module (guix gexp)
  24. #:use-module (guix monads)
  25. #:use-module (guix derivations)
  26. #:use-module (guix search-paths)
  27. #:use-module (guix build-system)
  28. #:use-module (guix build-system gnu)
  29. #:use-module (guix packages)
  30. #:use-module (ice-9 match)
  31. #:export (%glib-or-gtk-build-system-modules
  32. glib-or-gtk-build
  33. glib-or-gtk-build-system))
  34. ;; Commentary:
  35. ;;
  36. ;; This build system is an extension of the 'gnu-build-system'. It
  37. ;; accomodates the needs of applications making use of glib or gtk+ (with "or"
  38. ;; to be interpreted in the mathematical sense). This is achieved by adding
  39. ;; two phases run after the 'install' phase:
  40. ;;
  41. ;; 'glib-or-gtk-wrap' phase:
  42. ;;
  43. ;; a) This phase looks for GSettings schemas, GIO modules and theming data.
  44. ;; If any of these is found in any input package, then all programs in
  45. ;; "out/bin" are wrapped in scripts defining the nedessary environment
  46. ;; variables.
  47. ;;
  48. ;; b) Looks for the existence of "libdir/gtk-3.0" directories in all input
  49. ;; packages. If any is found, then the environment variable "GTK_PATH" is
  50. ;; suitably set and added to the wrappers. The variable "GTK_PATH" has been
  51. ;; preferred over "GTK_EXE_PREFIX" because the latter can only point to a
  52. ;; single directory, while we may need to point to several ones.
  53. ;;
  54. ;; 'glib-or-gtk-compile-schemas' phase:
  55. ;;
  56. ;; Looks for the presence of "out/share/glib-2.0/schemas". If that directory
  57. ;; exists and does not include a file named "gschemas.compiled", then
  58. ;; "glib-compile-schemas" is run in that directory.
  59. ;;
  60. ;; Code:
  61. (define %default-modules
  62. ;; Build-side modules made available in the build environment.
  63. '((guix build glib-or-gtk-build-system)
  64. (guix build utils)))
  65. (define %glib-or-gtk-build-system-modules
  66. ;; Build-side modules imported and used by default.
  67. `((guix build glib-or-gtk-build-system)
  68. ,@%gnu-build-system-modules))
  69. (define (default-glib)
  70. "Return the default glib package from which we use
  71. \"glib-compile-schemas\"."
  72. ;; Do not use `@' to avoid introducing circular dependencies.
  73. (let ((module (resolve-interface '(gnu packages glib))))
  74. (module-ref module 'glib)))
  75. (define* (lower name
  76. #:key source inputs native-inputs outputs system target
  77. (glib (default-glib))
  78. (implicit-inputs? #t)
  79. (strip-binaries? #t)
  80. #:allow-other-keys
  81. #:rest arguments)
  82. "Return a bag for NAME."
  83. (define private-keywords
  84. '(#:target #:glib #:inputs #:native-inputs
  85. #:outputs #:implicit-inputs?))
  86. (and (not target) ;XXX: no cross-compilation
  87. (bag
  88. (name name)
  89. (system system)
  90. (host-inputs (if source
  91. `(("source" ,source))
  92. '()))
  93. (build-inputs `(,@native-inputs
  94. ,@inputs
  95. ("glib:bin" ,glib "bin") ; to compile schemas
  96. ,@(if implicit-inputs?
  97. (standard-packages)
  98. '())))
  99. (outputs outputs)
  100. (build glib-or-gtk-build)
  101. (arguments (strip-keyword-arguments private-keywords arguments)))))
  102. (define* (glib-or-gtk-build name inputs
  103. #:key guile source
  104. (outputs '("out"))
  105. (search-paths '())
  106. (configure-flags ''())
  107. ;; Disable icon theme cache generation.
  108. (make-flags ''("gtk_update_icon_cache=true"))
  109. (out-of-source? #f)
  110. (tests? #t)
  111. (test-target "check")
  112. (parallel-build? #t)
  113. (parallel-tests? #t)
  114. (validate-runpath? #t)
  115. (patch-shebangs? #t)
  116. (strip-binaries? #t)
  117. (strip-flags ''("--strip-debug"))
  118. (strip-directories ''("lib" "lib64" "libexec"
  119. "bin" "sbin"))
  120. (phases '(@ (guix build glib-or-gtk-build-system)
  121. %standard-phases))
  122. (glib-or-gtk-wrap-excluded-outputs ''())
  123. (system (%current-system))
  124. (imported-modules %glib-or-gtk-build-system-modules)
  125. (modules %default-modules)
  126. allowed-references
  127. disallowed-references)
  128. "Build SOURCE with INPUTS. See GNU-BUILD for more details."
  129. (define build
  130. (with-imported-modules imported-modules
  131. #~(begin
  132. (use-modules #$@(sexp->gexp modules))
  133. #$(with-build-variables inputs outputs
  134. #~(glib-or-gtk-build #:source #+source
  135. #:system #$system
  136. #:outputs %outputs
  137. #:inputs %build-inputs
  138. #:search-paths '#$(sexp->gexp
  139. (map search-path-specification->sexp
  140. search-paths))
  141. #:phases #$(if (pair? phases)
  142. (sexp->gexp phases)
  143. phases)
  144. #:glib-or-gtk-wrap-excluded-outputs
  145. #$glib-or-gtk-wrap-excluded-outputs
  146. #:configure-flags #$configure-flags
  147. #:make-flags #$make-flags
  148. #:out-of-source? #$out-of-source?
  149. #:tests? #$tests?
  150. #:test-target #$test-target
  151. #:parallel-build? #$parallel-build?
  152. #:parallel-tests? #$parallel-tests?
  153. #:validate-runpath? #$validate-runpath?
  154. #:patch-shebangs? #$patch-shebangs?
  155. #:strip-binaries? #$strip-binaries?
  156. #:strip-flags #$(sexp->gexp strip-flags)
  157. #:strip-directories
  158. #$(sexp->gexp strip-directories))))))
  159. (mlet %store-monad ((guile (package->derivation (or guile (default-guile))
  160. system #:graft? #f)))
  161. (gexp->derivation name build
  162. #:system system
  163. #:target #f
  164. #:allowed-references allowed-references
  165. #:disallowed-references disallowed-references
  166. #:guile-for-build guile)))
  167. (define glib-or-gtk-build-system
  168. (build-system
  169. (name 'glib-or-gtk)
  170. (description
  171. "The GNU Build System—i.e., ./configure && make && make install,
  172. augmented with definition of suitable environment variables for glib and gtk+
  173. in program wrappers.")
  174. (lower lower)))