glib-or-gtk.scm 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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. ;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be>
  6. ;;;
  7. ;;; This file is part of GNU Guix.
  8. ;;;
  9. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  10. ;;; under the terms of the GNU General Public License as published by
  11. ;;; the Free Software Foundation; either version 3 of the License, or (at
  12. ;;; your option) any later version.
  13. ;;;
  14. ;;; GNU Guix is distributed in the hope that it will be useful, but
  15. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;;; GNU General Public License for more details.
  18. ;;;
  19. ;;; You should have received a copy of the GNU General Public License
  20. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  21. (define-module (guix build-system glib-or-gtk)
  22. #:use-module (guix store)
  23. #:use-module (guix utils)
  24. #:use-module (guix gexp)
  25. #:use-module (guix monads)
  26. #:use-module (guix derivations)
  27. #:use-module (guix search-paths)
  28. #:use-module ((guix build glib-or-gtk-build-system)
  29. #:select (%gdk-pixbuf-loaders-cache-file))
  30. #:use-module (guix build-system)
  31. #:use-module (guix build-system gnu)
  32. #:use-module (guix packages)
  33. #:use-module (ice-9 match)
  34. #:export (%glib-or-gtk-build-system-modules
  35. glib-or-gtk-build
  36. glib-or-gtk-cross-build
  37. glib-or-gtk-build-system)
  38. #:re-export (%gdk-pixbuf-loaders-cache-file)) ;for convenience
  39. ;; Commentary:
  40. ;;
  41. ;; This build system is an extension of the 'gnu-build-system'. It
  42. ;; accomodates the needs of applications making use of glib or gtk+ (with "or"
  43. ;; to be interpreted in the mathematical sense). This is achieved by adding
  44. ;; two phases run after the 'install' phase:
  45. ;;
  46. ;; 'glib-or-gtk-wrap' phase:
  47. ;;
  48. ;; a) This phase looks for GSettings schemas, GIO modules and theming data.
  49. ;; If any of these is found in any input package, then all programs in
  50. ;; "out/bin" are wrapped in scripts defining the nedessary environment
  51. ;; variables.
  52. ;;
  53. ;; b) Looks for the existence of "libdir/gtk-3.0" directories in all input
  54. ;; packages. If any is found, then the environment variable "GTK_PATH" is
  55. ;; suitably set and added to the wrappers. The variable "GTK_PATH" has been
  56. ;; preferred over "GTK_EXE_PREFIX" because the latter can only point to a
  57. ;; single directory, while we may need to point to several ones.
  58. ;;
  59. ;; 'glib-or-gtk-compile-schemas' phase:
  60. ;;
  61. ;; Looks for the presence of "out/share/glib-2.0/schemas". If that directory
  62. ;; exists and does not include a file named "gschemas.compiled", then
  63. ;; "glib-compile-schemas" is run in that directory.
  64. ;;
  65. ;; Code:
  66. (define %default-modules
  67. ;; Build-side modules made available in the build environment.
  68. '((guix build glib-or-gtk-build-system)
  69. (guix build utils)))
  70. (define %glib-or-gtk-build-system-modules
  71. ;; Build-side modules imported and used by default.
  72. `((guix build glib-or-gtk-build-system)
  73. ,@%gnu-build-system-modules))
  74. (define (default-glib)
  75. "Return the default glib package from which we use
  76. \"glib-compile-schemas\"."
  77. ;; Do not use `@' to avoid introducing circular dependencies.
  78. (let ((module (resolve-interface '(gnu packages glib))))
  79. (module-ref module 'glib)))
  80. (define* (lower name
  81. #:key source inputs native-inputs outputs system target
  82. (glib (default-glib))
  83. (implicit-inputs? #t)
  84. (implicit-cross-inputs? #t)
  85. (strip-binaries? #t)
  86. #:allow-other-keys
  87. #:rest arguments)
  88. "Return a bag for NAME."
  89. (define private-keywords
  90. `(#:glib #:inputs #:native-inputs
  91. #:outputs #:implicit-inputs? #:implicit-cross-inputs?
  92. ,@(if target '() '(#:target))))
  93. (bag
  94. (name name)
  95. (system system) (target target)
  96. (host-inputs `(,@(if source
  97. `(("source" ,source))
  98. '())
  99. ,@(if target
  100. inputs
  101. '())))
  102. (build-inputs `(,@native-inputs
  103. ,@(if target '() inputs)
  104. ("glib:bin" ,glib "bin") ; to compile schemas
  105. ;; Keep standard inputs of gnu-build-system.
  106. ,@(if (and target implicit-cross-inputs?)
  107. (standard-cross-packages target 'host)
  108. '())
  109. ,@(if implicit-inputs?
  110. (standard-packages)
  111. '())))
  112. ;; Keep standard inputs of 'gnu-build-system'.
  113. (target-inputs (if (and target implicit-cross-inputs?)
  114. (standard-cross-packages target 'target)
  115. '()))
  116. (outputs outputs)
  117. (build (if target glib-or-gtk-cross-build glib-or-gtk-build))
  118. (arguments (strip-keyword-arguments private-keywords arguments))))
  119. (define* (glib-or-gtk-build name inputs
  120. #:key guile source
  121. (outputs '("out"))
  122. (search-paths '())
  123. (configure-flags ''())
  124. ;; Disable icon theme cache generation.
  125. (make-flags ''("gtk_update_icon_cache=true"))
  126. (out-of-source? #f)
  127. (tests? #t)
  128. (test-target "check")
  129. (parallel-build? #t)
  130. (parallel-tests? #t)
  131. (validate-runpath? #t)
  132. (patch-shebangs? #t)
  133. (strip-binaries? #t)
  134. (strip-flags ''("--strip-debug"))
  135. (strip-directories ''("lib" "lib64" "libexec"
  136. "bin" "sbin"))
  137. (phases '(@ (guix build glib-or-gtk-build-system)
  138. %standard-phases))
  139. (glib-or-gtk-wrap-excluded-outputs ''())
  140. (system (%current-system))
  141. (imported-modules %glib-or-gtk-build-system-modules)
  142. (modules %default-modules)
  143. allowed-references
  144. disallowed-references)
  145. "Build SOURCE with INPUTS. See GNU-BUILD for more details."
  146. (define build
  147. (with-imported-modules imported-modules
  148. #~(begin
  149. (use-modules #$@(sexp->gexp modules))
  150. #$(with-build-variables inputs outputs
  151. #~(glib-or-gtk-build #:source #+source
  152. #:system #$system
  153. #:outputs %outputs
  154. #:inputs %build-inputs
  155. #:search-paths '#$(sexp->gexp
  156. (map search-path-specification->sexp
  157. search-paths))
  158. #:phases #$(if (pair? phases)
  159. (sexp->gexp phases)
  160. phases)
  161. #:glib-or-gtk-wrap-excluded-outputs
  162. #$glib-or-gtk-wrap-excluded-outputs
  163. #:configure-flags #$configure-flags
  164. #:make-flags #$make-flags
  165. #:out-of-source? #$out-of-source?
  166. #:tests? #$tests?
  167. #:test-target #$test-target
  168. #:parallel-build? #$parallel-build?
  169. #:parallel-tests? #$parallel-tests?
  170. #:validate-runpath? #$validate-runpath?
  171. #:patch-shebangs? #$patch-shebangs?
  172. #:strip-binaries? #$strip-binaries?
  173. #:strip-flags #$(sexp->gexp strip-flags)
  174. #:strip-directories
  175. #$(sexp->gexp strip-directories))))))
  176. (mlet %store-monad ((guile (package->derivation (or guile (default-guile))
  177. system #:graft? #f)))
  178. (gexp->derivation name build
  179. #:system system
  180. #:target #f
  181. #:graft? #f
  182. #:allowed-references allowed-references
  183. #:disallowed-references disallowed-references
  184. #:guile-for-build guile)))
  185. (define* (glib-or-gtk-cross-build name
  186. #:key
  187. target
  188. build-inputs target-inputs host-inputs
  189. guile source
  190. (outputs '("out"))
  191. (search-paths '())
  192. (native-search-paths '())
  193. (configure-flags ''())
  194. ;; Disable icon theme cache generation.
  195. (make-flags ''("gtk_update_icon_cache=true"))
  196. (out-of-source? #f)
  197. (tests? #f)
  198. (test-target "check")
  199. (parallel-build? #t)
  200. (parallel-tests? #t)
  201. (validate-runpath? #t)
  202. (make-dynamic-linker-cache? #f)
  203. (patch-shebangs? #t)
  204. (strip-binaries? #t)
  205. (strip-flags ''("--strip-debug"))
  206. (strip-directories ''("lib" "lib64" "libexec"
  207. "bin" "sbin"))
  208. (phases '(@ (guix build glib-or-gtk-build-system)
  209. %standard-phases))
  210. (glib-or-gtk-wrap-excluded-outputs ''())
  211. (system (%current-system))
  212. (build (nix-system->gnu-triplet system))
  213. (imported-modules %glib-or-gtk-build-system-modules)
  214. (modules %default-modules)
  215. allowed-references
  216. disallowed-references)
  217. "Cross-build SOURCE with INPUTS. See GNU-BUILD for more details."
  218. (define builder
  219. #~(begin
  220. (use-modules #$@(sexp->gexp modules))
  221. (define %build-host-inputs
  222. #+(input-tuples->gexp build-inputs))
  223. (define %build-target-inputs
  224. (append #$(input-tuples->gexp host-inputs)
  225. #+(input-tuples->gexp target-inputs)))
  226. (define %build-inputs
  227. (append %build-host-inputs %build-target-inputs))
  228. (define %outputs
  229. #$(outputs->gexp outputs))
  230. (glib-or-gtk-build #:source #+source
  231. #:system #$system
  232. #:build #$build
  233. #:target #$target
  234. #:outputs %outputs
  235. #:inputs %build-target-inputs
  236. #:native-inputs %build-host-inputs
  237. #:search-paths '#$(sexp->gexp
  238. (map search-path-specification->sexp
  239. search-paths))
  240. #:native-search-paths '#$(sexp->gexp
  241. (map search-path-specification->sexp
  242. native-search-paths))
  243. #:phases #$(if (pair? phases)
  244. (sexp->gexp phases)
  245. phases)
  246. #:glib-or-gtk-wrap-excluded-outputs
  247. #$glib-or-gtk-wrap-excluded-outputs
  248. #:configure-flags #$configure-flags
  249. #:make-flags #$make-flags
  250. #:out-of-source? #$out-of-source?
  251. #:tests? #$tests?
  252. #:test-target #$test-target
  253. #:parallel-build? #$parallel-build?
  254. #:parallel-tests? #$parallel-tests?
  255. #:validate-runpath? #$validate-runpath?
  256. #:make-dynamic-linker-cache? #$make-dynamic-linker-cache?
  257. #:patch-shebangs? #$patch-shebangs?
  258. #:strip-binaries? #$strip-binaries?
  259. #:strip-flags #$(sexp->gexp strip-flags)
  260. #:strip-directories
  261. #$(sexp->gexp strip-directories))))
  262. (mlet %store-monad ((guile (package->derivation (or guile (default-guile))
  263. system #:graft? #f)))
  264. (gexp->derivation name builder
  265. #:system system
  266. #:target target
  267. #:graft? #f
  268. #:modules imported-modules
  269. #:allowed-references allowed-references
  270. #:disallowed-references disallowed-references
  271. #:guile-for-build guile)))
  272. (define glib-or-gtk-build-system
  273. (build-system
  274. (name 'glib-or-gtk)
  275. (description
  276. "The GNU Build System—i.e., ./configure && make && make install,
  277. augmented with definition of suitable environment variables for glib and gtk+
  278. in program wrappers.")
  279. (lower lower)))