glib-or-gtk.scm 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2013, 2014, 2015, 2019, 2020 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 derivations)
  24. #:use-module (guix search-paths)
  25. #:use-module (guix build-system)
  26. #:use-module (guix build-system gnu)
  27. #:use-module (guix packages)
  28. #:use-module (ice-9 match)
  29. #:export (%glib-or-gtk-build-system-modules
  30. glib-or-gtk-build
  31. glib-or-gtk-build-system))
  32. ;; Commentary:
  33. ;;
  34. ;; This build system is an extension of the 'gnu-build-system'. It
  35. ;; accomodates the needs of applications making use of glib or gtk+ (with "or"
  36. ;; to be interpreted in the mathematical sense). This is achieved by adding
  37. ;; two phases run after the 'install' phase:
  38. ;;
  39. ;; 'glib-or-gtk-wrap' phase:
  40. ;;
  41. ;; a) This phase looks for GSettings schemas, GIO modules and theming data.
  42. ;; If any of these is found in any input package, then all programs in
  43. ;; "out/bin" are wrapped in scripts defining the nedessary environment
  44. ;; variables.
  45. ;;
  46. ;; b) Looks for the existence of "libdir/gtk-3.0" directories in all input
  47. ;; packages. If any is found, then the environment variable "GTK_PATH" is
  48. ;; suitably set and added to the wrappers. The variable "GTK_PATH" has been
  49. ;; preferred over "GTK_EXE_PREFIX" because the latter can only point to a
  50. ;; single directory, while we may need to point to several ones.
  51. ;;
  52. ;; 'glib-or-gtk-compile-schemas' phase:
  53. ;;
  54. ;; Looks for the presence of "out/share/glib-2.0/schemas". If that directory
  55. ;; exists and does not include a file named "gschemas.compiled", then
  56. ;; "glib-compile-schemas" is run in that directory.
  57. ;;
  58. ;; Code:
  59. (define %default-modules
  60. ;; Build-side modules made available in the build environment.
  61. '((guix build glib-or-gtk-build-system)
  62. (guix build utils)))
  63. (define %glib-or-gtk-build-system-modules
  64. ;; Build-side modules imported and used by default.
  65. `((guix build glib-or-gtk-build-system)
  66. ,@%gnu-build-system-modules))
  67. (define (default-glib)
  68. "Return the default glib package from which we use
  69. \"glib-compile-schemas\"."
  70. ;; Do not use `@' to avoid introducing circular dependencies.
  71. (let ((module (resolve-interface '(gnu packages glib))))
  72. (module-ref module 'glib)))
  73. (define* (lower name
  74. #:key source inputs native-inputs outputs system target
  75. (glib (default-glib))
  76. (implicit-inputs? #t)
  77. (strip-binaries? #t)
  78. #:allow-other-keys
  79. #:rest arguments)
  80. "Return a bag for NAME."
  81. (define private-keywords
  82. '(#:source #:target #:glib #:inputs #:native-inputs
  83. #:outputs #:implicit-inputs?))
  84. (and (not target) ;XXX: no cross-compilation
  85. (bag
  86. (name name)
  87. (system system)
  88. (host-inputs (if source
  89. `(("source" ,source))
  90. '()))
  91. (build-inputs `(,@native-inputs
  92. ,@inputs
  93. ("glib:bin" ,glib "bin") ; to compile schemas
  94. ,@(if implicit-inputs?
  95. (standard-packages)
  96. '())))
  97. (outputs outputs)
  98. (build glib-or-gtk-build)
  99. (arguments (strip-keyword-arguments private-keywords arguments)))))
  100. (define* (glib-or-gtk-build store name inputs
  101. #:key (guile #f)
  102. (outputs '("out"))
  103. (search-paths '())
  104. (configure-flags ''())
  105. ;; Disable icon theme cache generation.
  106. (make-flags ''("gtk_update_icon_cache=true"))
  107. (out-of-source? #f)
  108. (tests? #t)
  109. (test-target "check")
  110. (parallel-build? #t)
  111. (parallel-tests? #t)
  112. (validate-runpath? #t)
  113. (patch-shebangs? #t)
  114. (strip-binaries? #t)
  115. (strip-flags ''("--strip-debug"))
  116. (strip-directories ''("lib" "lib64" "libexec"
  117. "bin" "sbin"))
  118. (phases '(@ (guix build glib-or-gtk-build-system)
  119. %standard-phases))
  120. (glib-or-gtk-wrap-excluded-outputs ''())
  121. (system (%current-system))
  122. (imported-modules %glib-or-gtk-build-system-modules)
  123. (modules %default-modules)
  124. allowed-references
  125. disallowed-references)
  126. "Build SOURCE with INPUTS. See GNU-BUILD for more details."
  127. (define canonicalize-reference
  128. (match-lambda
  129. ((? package? p)
  130. (derivation->output-path (package-derivation store p system)))
  131. (((? package? p) output)
  132. (derivation->output-path (package-derivation store p system)
  133. output))
  134. ((? string? output)
  135. output)))
  136. (define builder
  137. `(begin
  138. (use-modules ,@modules)
  139. (glib-or-gtk-build #:source ,(match (assoc-ref inputs "source")
  140. (((? derivation? source))
  141. (derivation->output-path source))
  142. ((source)
  143. source)
  144. (source
  145. source))
  146. #:system ,system
  147. #:outputs %outputs
  148. #:inputs %build-inputs
  149. #:search-paths ',(map search-path-specification->sexp
  150. search-paths)
  151. #:phases ,phases
  152. #:glib-or-gtk-wrap-excluded-outputs
  153. ,glib-or-gtk-wrap-excluded-outputs
  154. #:configure-flags ,configure-flags
  155. #:make-flags ,make-flags
  156. #:out-of-source? ,out-of-source?
  157. #:tests? ,tests?
  158. #:test-target ,test-target
  159. #:parallel-build? ,parallel-build?
  160. #:parallel-tests? ,parallel-tests?
  161. #:validate-runpath? ,validate-runpath?
  162. #:patch-shebangs? ,patch-shebangs?
  163. #:strip-binaries? ,strip-binaries?
  164. #:strip-flags ,strip-flags
  165. #:strip-directories ,strip-directories)))
  166. (define guile-for-build
  167. (match guile
  168. ((? package?)
  169. (package-derivation store guile system #:graft? #f))
  170. (#f ; the default
  171. (let* ((distro (resolve-interface '(gnu packages commencement)))
  172. (guile (module-ref distro 'guile-final)))
  173. (package-derivation store guile system #:graft? #f)))))
  174. (build-expression->derivation store name builder
  175. #:system system
  176. #:inputs inputs
  177. #:modules imported-modules
  178. #:outputs outputs
  179. #:allowed-references
  180. (and allowed-references
  181. (map canonicalize-reference
  182. allowed-references))
  183. #:disallowed-references
  184. (and disallowed-references
  185. (map canonicalize-reference
  186. disallowed-references))
  187. #:guile-for-build guile-for-build))
  188. (define glib-or-gtk-build-system
  189. (build-system
  190. (name 'glib-or-gtk)
  191. (description
  192. "The GNU Build System—i.e., ./configure && make && make install,
  193. augmented with definition of suitable environment variables for glib and gtk+
  194. in program wrappers.")
  195. (lower lower)))